SAMA5D4 - Creating and using MTD / UBI partitions

Discussion around products based on ARM Cortex-A5 core.

Moderator: nferre

brian_
Posts: 15
Joined: Mon Jan 09, 2017 11:59 am

SAMA5D4 - Creating and using MTD / UBI partitions

Fri Jan 13, 2017 7:24 pm

Hopefully this is the correct place to ask these questions.

I am trying to create UBI partitions on the nand flash of the SAMA5D4 Xplained dev board.

I believe this flash has the following properties:
Logical erase block size = 248KiB
Physical erase block size = 256KiB



I am running the following commands:
mkfs.ubifs -r folder -o output.ubifs -e 0x3e000 -c 260 -m 0x1000 -x lzo -v
ubinize -o output.ubi -m 0x1000 -p 0x40000 ubinize.cfg -vv

The -c 260 option I believe translates to 260 * 248KiB = 62.96875MiB, meaning that it can be used on a volume up to the size.

The ubinize.cfg file has a single volume with the following size: vol_size = 80MiB

I then flash the ubi file to a 120MiB mtd partition

On boot, I attach the partition and get the following:
ubi0: attached mtd1 (name "mtd=6", size 120 MiB)<CR><LF>
ubi0: PEB size: 262144 bytes (256 KiB), LEB size: 253952 bytes<CR><LF>
ubi0: min./max. I/O unit sizes: 4096/4096, sub-page size 4096<CR><LF>
ubi0: VID header offset: 4096 (aligned 4096), data offset: 8192<CR><LF>
ubi0: good PEBs: 480, bad PEBs: 0, corrupted PEBs: 0<CR><LF>
ubi0: user volume: 1, internal volumes: 1, max. volumes count: 128<CR><LF>
ubi0: max/mean erase counter: 1/0, WL threshold: 4096, image sequence number: 1958496669<CR><LF>
ubi0: available PEBs: 105, total reserved PEBs: 375, PEBs reserved for bad PEB handling: 40<CR><LF>

From My calculations, I get:
Good PEBs = 480 => 480 * 256KiB = 120MiB
Available PEBs = 105 => 105 * 256KiB = 26.25MiB
total reserved PEBs = 375 => 375 * 256KiB = 93.75MiB
PEBs reserved = 40 => 40 * 256KiB = 10Mb


Questions:

Does the -c option in the mkfs.ubifs step relate to the vol_size parameter inside the ubinize.cfg file in the ubinize step? i.e. the -c should be the same or smaller that the vol_size?

Is the total reserved PEBs an indication of how much file space is in use, including all overhead? Does this include the 40 PEBs for bad PEB handling? Is the "Available PEBs" the free space?

I have read that I should keep blocks aside for bad PEB handling. As I mentioned before, I see that this is happening and that there are 40 - how do I control this number? I seem to be able to manipulate it by either 1) Changing the mtd partition size or 2) Changing the vol_size parameter in the ubinize.cfg file, however I cannot seem to reconcile the numbers - how do I calculate how many PEBs will be left for bad PEB handling?

Thanks in advance.
blue_z
Location: USA
Posts: 1508
Joined: Thu Apr 19, 2007 10:15 pm

Re: SAMA5D4 - Creating and using MTD / UBI partitions

Tue Jan 17, 2017 1:08 am

brian_ wrote:Hopefully this is the correct place to ask these questions.
Not really. It's not specific to the SoC.
brian_ wrote:I am trying to create UBI partitions on the nand flash of the SAMA5D4 Xplained dev board.
It's MTD partitions and UBI volumes.
brian_ wrote:On boot, I attach the partition and get the following:
The ubinfo command will produce a little more intomation in slightly more readable format.

Code: Select all

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

ubi0
Volumes count:                           1
Logical eraseblock size:                 253952 bytes, 248.0 KiB
Total amount of logical eraseblocks:     2012 (510951424 bytes, 487.3 MiB)
Amount of available logical eraseblocks: 2 (507904 bytes, 496.0 KiB)
Maximum count of volumes                 128
Count of bad physical eraseblocks:       4
Count of reserved physical eraseblocks:  36
Current maximum erase counter value:     2
Minimum input/output unit size:          4096 bytes
Character device major/minor:            250:0
Present volumes:                         0

Volume ID:   0 (on ubi0)
Type:        dynamic
Alignment:   1
Size:        1970 LEBs (500285440 bytes, 477.1 MiB)
State:       OK
Name:        rootfs
Character device major/minor: 250:1
#
brian_ wrote:Is the total reserved PEBs an indication of how much file space is in use, including all overhead? Does this include the 40 PEBs for bad PEB handling? Is the "Available PEBs" the free space?
You're mixing apples with oranges.
The blocks of the UBI volume manager is a layer below the sectors/blocks manged by a filesystem.
brian_ wrote:As I mentioned before, I see that this is happening and that there are 40 - how do I control this number?
The UBI FAQ mentions that it can be configured into the kernel, and "adjusted by a kernel parameter or an ubiattach parameter (since kernel 3.7)".
brian_ wrote:I seem to be able to manipulate it by either 1) Changing the mtd partition size or 2) Changing the vol_size parameter in the ubinize.cfg file, however I cannot seem to reconcile the numbers - how do I calculate how many PEBs will be left for bad PEB handling?
The last time I looked at such stuff, the recommendation was that 2% of the PEBs should be set aside.
At the time, U-Boot 2014.01 was coded to allocate only 1% of the good PEB count to the reserve. I ended up patching the code to reserve the 2% for bad block handling.

Regards
brian_
Posts: 15
Joined: Mon Jan 09, 2017 11:59 am

Re: SAMA5D4 - Creating and using MTD / UBI partitions

Tue Jan 17, 2017 12:36 pm

Thanks for the response.

If I understand correctly, the reserved eraseblocks count is not calculated at the time of the .ubi file creation, but rather at mount time.

I think I now understand where my 40 reserved erase blocks are coming from for bad PEB handling:

Total flash size = 512MiB
PEB size = 256KiB
Total number of PEB = 512MiB / 256KiB = 2048 Blocks
2% of 2048 = 40.96 = 40 blocks (rounded down integer).


Looking at ubiattach, I see that you can specifiy the number, or use the kernel number by default. It seems that no matter what the size of mtd partition you make, and no matter what ubi volume sizes you have, the kernel number of reserved PEBs will always calculate based on the total size of the flash. So if you have multiple mtd partitions, each with a single ubi volume, they will each have 40 blocks reserved (in my case). Is this correct?

I initially thought that this number would be proportional - e.g if you have 2 mtd partitions at 256MiB each, with each partition holding a single ubi volume then each would have 20 blocks reserved (in my case), however this does not seem to be how it works. I think I read that it is better to have multiple UBI volumes on a single MTD partition so that wear levelling can occur across multiple volumes, so perhaps this reinforces that route.

Code: Select all

ubiattach version 1.5.2 - a tool to attach MTD device to UBI.

Usage: ubiattach [<UBI control device node file name>]
<HT>	[-m <MTD device number>] [-d <UBI device number>] [-p <path to device>]
<HT>	[--mtdn=<MTD device number>] [--devn=<UBI device number>]
<HT>	[--dev-path=<path to device>]
<HT>	[--max-beb-per1024=<maximum bad block number per 1024 blocks>]
UBI control device defaults to /dev/ubi_ctrl if not supplied.
Example 1: ubiattach -p /dev/mtd0 - attach /dev/mtd0 to UBI
Example 2: ubiattach -m 0 - attach MTD device 0 (mtd0) to UBI
Example 3: ubiattach -m 0 -d 3 - attach MTD device 0 (mtd0) to UBI
           and create UBI device number 3 (ubi3)
Example 4: ubiattach -m 1 -b 25 - attach /dev/mtd1 to UBI and reserve
           25*C/1024 eraseblocks for bad block handling, where C is the flash
           is total flash chip eraseblocks count, that is flash chip size in
           eraseblocks (including bad eraseblocks). E.g., if the flash chip
           has 4096 PEBs, 100 will be reserved.

-d, --devn=<number>   the number to assign to the newly created UBI device
                      (assigned automatically if this is not specified)
-p, --dev-path=<path> path to MTD device node to attach
-m, --mtdn=<number>   MTD device number to attach (alternative method, e.g
                      if the character device node does not exist)
-O, --vid-hdr-offset  VID header offset (do not specify this unless you really
                      know what you are doing, the default should be optimal)
-b, --max-beb-per1024 maximum expected bad block number per 1024 eraseblock.
                      The default value is correct for most NAND devices.
                      Allowed range is 0-768, 0 means the default kernel value.
-h, --help            print help message
-V, --version         print program version
blue_z
Location: USA
Posts: 1508
Joined: Thu Apr 19, 2007 10:15 pm

Re: SAMA5D4 - Creating and using MTD / UBI partitions

Wed Jan 18, 2017 8:58 pm

brian_ wrote:If I understand correctly, the reserved eraseblocks count is not calculated at the time of the .ubi file creation, but rather at mount time.
No.
The number of reserved PEBs is an intrinsic property of the volume, established at time of creation.
This number can be (temporarily?) changed when the volume is opened.

UBI volumes are not "mounted". Filesystems are mounted.
Volumes are treated like devices.
In fact the code that implements UBI is located at drivers/mtd/ubi.

Regards

Return to “SAMA5D Cortex-A5 MPU”

Who is online

Users browsing this forum: No registered users and 1 guest