0

I am working on an embedded Linux system (kernel-5.24) and the development host is running WSL2 in Windows.

There is a NAND FLASH of 128MB in the embedded system (PEB is 128KiB, page size is 4096 bytes, and there are 1024 PEBs). Now I want to create a UBIFS volume on the MTD2 which is the last MTD partition, whose size is 0x7700000 (119MiB) with ubinize.

Here is ubinize.cfg I am using,

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

The command is as follows,

ubinize -m 2048 -p 128KiB -s 512 -O 2048 ./ubinize.cfg -v -o ubi.img

Then I deployed the generated ubi.img, the system booted up with error as follows,

[    2.138286] ubi0: attaching mtd2
[    2.315180] ubi0: scanning is finished
[    2.322753] ubi0 error: vtbl_check: too large reserved_pebs 983, good PEBs 952
[    2.330258] ubi0 error: vtbl_check: volume table check failed: record 0, error 9
[    2.337904] Volume table record 0 dump:
[    2.341878]  reserved_pebs   983
[    2.345202]  alignment       1
[    2.348354]  data_pad        0
[    2.351515]  vol_type        1
[    2.354663]  upd_marker      0
[    2.357812]  name_len        6
[    2.360976]  name            rootfs
[    2.364572]  crc             0xd6e9ec58
[    2.368727] ubi0 error: ubi_attach_mtd_dev: failed to attach mtd2, error -22
[    2.376054] UBI error: cannot attach mtd2

So by checking the internet, to make use of the whole MTD2 partition, I changed the ubinize.cfg without setting vol_size as follows,

[ubifs]
mode=ubi
image=system.ubifs
vol_id=0
vol_type=dynamic
vol_alignment=1
vol_name=rootfs
vol_flags=autoresize

With this, kernel can bootup and rootfs can be mounted correctly, and ubinfo showed followings,

# ubinfo -a
UBI version:                    1
Count of UBI devices:           1
UBI control device major/minor: 10:63
Present UBI devices:            ubi0

ubi0
Volumes count:                           1
Logical eraseblock size:                 126976 bytes, 124.0 KiB
Total amount of logical eraseblocks:     952 (120881152 bytes, 115.2 MiB)
Amount of available logical eraseblocks: 0 (0 bytes)
Maximum count of volumes                 128
Count of bad physical eraseblocks:       0
Count of reserved physical eraseblocks:  20
Current maximum erase counter value:     2
Minimum input/output unit size:          2048 bytes
Character device major/minor:            248:0
Present volumes:                         0

Volume ID:   0 (on ubi0)
Type:        dynamic
Alignment:   1
Size:        928 LEBs (117833728 bytes, 112.3 MiB)
State:       OK
Name:        rootfs
Character device major/minor: 248:1

I have following questions: There are totally 952 LEBs, but ubinfo -a shows 928 LEBs are used. Does it use up the whole partition of size of 119MB?
What is the maximum number of LEBs can be used in this configuration?
How to plan the UBIFS size in this NAND configuration (1024 PEBs, maximum bad block is 20, and considering wear leveling)?

1 Answer 1

0

By reading FLASH space overhead and tests and trials, I figured out the meaning of the numbers and the settings in ubinize.cfg as follows.

Firstly, the vol_size in ubinize.cfg specifies the size of real data LEBs for the UBI volume. It does NOT count in the overhead of 4 PEBs(LEBs). So specifying vol_size=119MiB is wrong since it is over the size of data LEBs.

In my case, there are totally 952 PEBs remained for the rootfs, and with 20 PEBs reserved for bad blocks, and 4 PEBs of the overhead, so there are only 928 PEBs remained for the real data blocks (LEBs), so the real size should be 928*126976=117833728, this matches the result of ubinfo -a.

Secondly, the autoresize=1 in ubinize does auto-resize the UBI volume if I set the vol_size=106MiB and I can get the same size as above (928 LEBs). Without autoresize=1, the result is shown below, which is different with above.

# ubinfo -a
UBI version:                    1
Count of UBI devices:           1
UBI control device major/minor: 10:63
Present UBI devices:            ubi0

ubi0
Volumes count:                           1
Logical eraseblock size:                 126976 bytes, 124.0 KiB
Total amount of logical eraseblocks:     952 (120881152 bytes, 115.2 MiB)
Amount of available logical eraseblocks: 52 (6602752 bytes, 6.2 MiB)
Maximum count of volumes                 128
Count of bad physical eraseblocks:       0
Count of reserved physical eraseblocks:  20
Current maximum erase counter value:     2
Minimum input/output unit size:          2048 bytes
Character device major/minor:            248:0
Present volumes:                         0

Volume ID:   0 (on ubi0)
Type:        dynamic
Alignment:   1
Size:        876 LEBs (111230976 bytes, 106.0 MiB)
State:       OK

106MiB is consisted of 876 LEBs, which matches the math I did above.

At last, the unit of vol_size can also be in KiB, which is very useful to do finer tuning/planning of the size of UBI volume.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .