ubi filesystem doc

ubi

space-fixup

Why do I have to use ubiformat

make ubi filesystem

How do I create an UBIFS image

$ mkfs.ubifs -F -q -r root-fs -m 2048 -e 129024 -c 2047 -o ubifs.img
$ ubinize -o ubi.img -m 2048 -p 128KiB -s 512 ubinize.cfg
where ubinize.cfg contains:

$ cat ubinize.cfg
[ubifs]
mode=ubi
image=ubifs.img
vol_id=0
vol_size=200MiB
vol_type=dynamic
vol_name=rootfs
vol_flags=autoresize

mkfs.ubifs需要很多flash的参数,这些参数可以通过mtdinfo命令查到。

-F参数表示需要fixup-free space, 这是个很重要的参数

another example:

# 20是预留多少个块用于处理坏块。 -c 1301 is calcute by: (peb - 20),while peb is 1321, peb  is calcute by: ((partiton size) / (126976))
mkfs.ubifs -F -r ./rootfs_lcd_sd_new_print/ -m 2048 -e 126976 -c 1235 -o ubifs.img
ubinize -o ubi.img -m 2048 -p 128KiB -s 2048 -O 2048 ubinize.cfg

[ubifs]
mode=ubi
image=ubifs.img
vol_id=0
vol_size=150MiB
vol_type=dynamic
vol_name=rootfs
vol_flags=autoresize
vol_alignment=1

遇到的问题

Kernel oops when remounting ubifs as read/write

ubi第一次是只读挂载,之后remount为rw时会报crc校验错误。按照上面的说法应该是内核的bug,经过验证,改为rw挂载之后再remount为ro就不会报错了。

flash中有一些块是预留的块,所以在计算-c参数时要减掉它。

Reserved blocks for bad block handling confusion UBI overhead and volume size calculations

Reserved blocks for bad block handling (only for NAND chips)
It is well-known that NAND chips have some amount of physical eraseblocks marked as bad by the manufacturer. During the lifetime of the NAND device, other bad blocks may appear. Nonetheless, manufacturers usually guarantee that the first few physical eraseblocks are not bad and that the total number of bad PEBs will not exceed certain number. For example, a 256MiB (2048 128KiB PEBs) Samsung OneNAND chip is guaranteed to have not more than 40 128KiB PEBs during its endurance lifetime. This is a very common value for NAND devices: 20/1024 PEB, which is about 2% of flash size.

This ratio of 20/1024 is the default number of blocks that UBI reserves for a UBI device. This means that if there are 2 UBI devices on a 4096 PEB NAND, 80 PEB for each UBI device will be reserved. This may appear to be a waste of space, but, given that bad blocks can appear anywhere on the NAND flash, and are not equally distributed on the whole device, it's the safer way. So instead of using several UBI devices on a NAND flash, it's more space-efficient to use only one UBI device which contains several UBI volumes.

The default value of 20 PEB reserved per 1024 PEB is a kernel config option. For each UBI device, this value can be adjusted via a kernel parameter or an ubiattach parameter (since kernel 3.7).