[U-Boot] [nand] [ubi] Discrepancy Between U-Boot and Linux NAND PEBs

Ken Sloat KSloat at aampglobal.com
Thu Jun 20 12:55:45 UTC 2019


Hello All,

I have been working on a system using a NAND flash along with U-Boot 2018.07 and Linux Kernel 4.14. This is an Atmel based system FYI so it uses the Atmel NAND driver. I create a UBI image with 3 separate volumes - 2 of these are a specified fixed size and the third is specified as the minimum needed to hold the current files with the auto resize flag set. As a note, before the first run auto resize operation, there is over 200 MiB of unused space in the NAND - meaning there should be plenty of free space available for UBI to leave overhead when auto-resizing for bad block handling. Another point of note, is that I use UBI within U-Boot as well in order to read the kernel image and dtb out of the UBIFS.

I have noticed warnings in Linux when attaching UBI regarding not having enough reserved PEBs for bad block handling (it's short by 2). Upon further investigation into the issue, it appears as though there is a discrepancy between what U-Boot and Linux see in terms of the number of bad blocks:

U-Boot:
ubi0: good PEBs: 4093, bad PEBs: 3, corrupted PEBs: 0
ubi0: user volume: 3, internal volumes: 1, max. volumes count: 128

Linux:
ubi0 warning: ubi_eba_init: cannot reserve enough PEBs for bad PEB handling, reserved 71, need 73
......
ubi0: good PEBs: 4089, bad PEBs: 7, corrupted PEBs: 0
ubi0: user volume: 3, internal volumes: 1, max. volumes count: 128

After production flashing of a UBI image to NAND (with a "dumb" non UBI aware flasher), U-Boot will be the program to mount UBI. What this means is that it will complete the one time re-size operation. I used a Linux ramdisk image to flash from Linux and mount UBI in Linux for the first time to allow it to complete the auto-resize operation instead and compared:

U-Boot:
ubi0: attaching mtd1
ubi0: scanning is finished
ubi0: volume 1 ("rootfs") re-sized from 1501 to 3385 LEBs
ubi0: attached mtd1 (name "mtd=0", size 512 MiB)
ubi0: PEB size: 131072 bytes (128 KiB), LEB size: 126976 bytes
ubi0: min./max. I/O unit sizes: 2048/2048, sub-page size 2048
ubi0: VID header offset: 2048 (aligned 2048), data offset: 4096
ubi0: good PEBs: 4093, bad PEBs: 3, corrupted PEBs: 0

Linux:
ubi0: attaching mtd6
ubi0: scanning is finished
ubi0: volume 1 ("rootfs") re-sized from 1501 to 3383 LEBs
ubi0: attached mtd6 (name "atmel_nand", size 512 MiB)
ubi0: PEB size: 131072 bytes (128 KiB), LEB size: 126976 bytes
ubi0: min./max. I/O unit sizes: 2048/2048, sub-page size 2048
ubi0: VID header offset: 2048 (aligned 2048), data offset: 4096
ubi0: good PEBs: 4089, bad PEBs: 7, corrupted PEBs: 0

As you can see, U-Boot resizes the image to 3385 blocks while Linux only 3383 - hence the 2 blocks that Linux would complain about had U-Boot resized the volume.

I am not sure exactly what is causing this discrepancy as I just figured this out - but thought I would reach out and discuss it here. Obviously there are ways around this issue (program and mount UBI from Linux initially, don't use autoresize and specify all volume sizes, etc) but was wondering if there is some underlying problem. I noticed an older mailing discussion from several years ago where someone reported a similar issue regarding number of bad PEBs and seems the issue was chalked up to a potential driver problem on one side:
https://lists.denx.de/pipermail/u-boot/2015-June/216482.html

Any insight would be helpful.

Thanks,
Ken Sloat


More information about the U-Boot mailing list