This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AM335x UBIFS Problem (u-boot-2013.01.01-psp06.00.00.00)

Hello,

I've spent a lot of time searching through the answer and finally decided to post it here because I'm pretty sure my that I haven't found the solution to my problem in any previous post in the forum.

So, I'm trying to make an UBIFS partition on a custom board that uses the AM335x processor and the latest version of the AM335x EVM SDK (ti-sdk-am335x-evm-06.00.00.00-Linux-x86).

I already compiled the mtd-utils so that I could use the -F option when I call the mkfs.ubifs command. I also checked that every step I'm posting below but so far my Kernel fails to mount the UBI partition.

First things first, in the u-boot I enable the following:

#define CONFIG_CMD_UBI
#define CONFIG_CMD_UBIFS
#define CONFIG_RBTREE
#define CONFIG_MTD_PARTITIONS
#define CONFIG_CMD_MTDPARTS
#define CONFIG_LZO
#define CONFIG_MTD_DEVICE
#define CONFIG_CMD_NAND_TRIMFFS

And I set bootargs=console=ttyO0,115200n8 root=ubi0:rootfs rw ubi.mtd=7 rootfstype=ubifs noinitrd

For further reference, here is what the mtdparts prints:

 

U-Boot# mtdparts

device nand0 <omap2-nand.0>, # parts = 8
#: name size offset mask_flags
0: SPL 0x00020000 0x00000000 0
1: SPL.backup1 0x00020000 0x00020000 0
2: SPL.backup2 0x00020000 0x00040000 0
3: SPL.backup3 0x00020000 0x00060000 0
4: u-boot 0x001e0000 0x00080000 0
5: u-boot-env 0x00020000 0x00260000 0
6: kernel 0x00500000 0x00280000 0
7: rootfs 0x07880000 0x00780000 0

active partition: nand0,0 - (SPL) 0x00020000 @ 0x00000000

defaults:
mtdids : nand0=omap2-nand.0
mtdparts: mtdparts=omap2-nand.0:128k(SPL),128k(SPL.backup1),128k(SPL.backup2),128k(SPL.backup3),1920k(u-boot),128k(u-boot-env),5m(kernel),-(rootfs)

 

Then I create the images I try to flash into the NAND:

 

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

$ ~/mtd/install/sbin/mkfs.ubifs -F -r rootfs/ -o ubifs.img -m 2048 -e 129024 -c 951

$ ~/mtd/install/sbin/ubinize -o rootfs.img -m 2048 -p 128KiB -O 2048 ubinize.cfg

 

This way I have found two ways to flash the file system (both inside the u-boot):

1) using ubifs.img with the command ubi write;

2) using rootfs.img with the command nand write (or nand write.trimffs).

 

Now things starts to get a little messy. None of the options works.

When I try writing the file ubinize generates, here is what I get:

U-Boot console:

usb reset
fatload usb 0 0x81000000 rootfs.img
nand erase 0x00780000 0x7880000
nand write 0x81000000 0x00780000 ${filesize}
run nand_boot

Kernel log:

[ 1.255527] UBI: attaching mtd7 to ubi0
[ 1.259688] UBI: physical eraseblock size: 131072 bytes (128 KiB)
[ 1.266330] UBI: logical eraseblock size: 126976 bytes
[ 1.272078] UBI: smallest flash I/O unit: 2048
[ 1.277082] UBI: VID header offset: 2048 (aligned 2048)
[ 1.283472] UBI: data offset: 4096
[ 2.340558] UBI: max. sequence number: 0
[ 2.364127] UBI error: vtbl_check: volume table check failed: record 0, error 9
[ 2.372605] UBI error: ubi_init: cannot attach mtd7

Now, if I try to flash the raw image:

usb reset
fatload usb 0 0x81000000 ubifs.img
nand erase 0x00780000 0x7880000
ubi part rootfs && ubi create rootfs
ubi write 0x81000000 rootfs ${filesize}
run nand_boot

Kernel log:

[ 1.255442] UBI: attaching mtd7 to ubi0
[ 1.259601] UBI: physical eraseblock size: 131072 bytes (128 KiB)
[ 1.266250] UBI: logical eraseblock size: 126976 bytes
[ 1.272005] UBI: smallest flash I/O unit: 2048
[ 1.277001] UBI: VID header offset: 2048 (aligned 2048)
[ 1.283388] UBI: data offset: 4096
[ 1.293766] UBI error: ubi_io_read: error -74 (ECC error) while reading 64 bytes from PEB 0:0, read 64 bytes
[ 1.304260] UBI error: validate_ec_hdr: bad VID header offset 512, expected 2048
[ 1.312131] UBI error: validate_ec_hdr: bad EC header
[ 1.317496] UBI error: ubi_io_read_ec_hdr: validation failed for PEB 0
[ 1.324586] UBI error: ubi_init: cannot attach mtd7

 

Besides that, if I use there is another problem I observe: if I reset the u-boot, I'm not able to use ubi part to access the rootfs anymore (from u-boot). Here is what heppens:

usb reset
fatload usb 0 0x81000000 ubifs.img
nand erase 0x00780000 0x7880000
ubi part rootfs && ubi create rootfs
ubi write 0x81000000 rootfs ${filesize}

Output:

(Re)start USB...
USB0: scanning bus 0 for devices... 1 USB Device(s) found
scanning usb for storage devices... 1 Storage Device(s) found
reading ubifs.img
22321152 bytes read in 18731 ms (1.1 MiB/s)

NAND erase: device 0 offset 0x780000, size 0x7880000
Erasing at 0x7fe0000 -- 100% complete.
OK
Creating 1 MTD partitions on "nand0":
0x000000780000-0x000008000000 : "mtd=7"
UBI: attaching mtd1 to ubi0
UBI: physical eraseblock size: 131072 bytes (128 KiB)
UBI: logical eraseblock size: 129024 bytes
UBI: smallest flash I/O unit: 2048
UBI: sub-page size: 512
UBI: VID header offset: 512 (aligned 512)
UBI: data offset: 2048
UBI: empty MTD device detected
UBI: create volume table (copy #1)
UBI: create volume table (copy #2)
UBI: attached mtd1 to ubi0
UBI: MTD device name: "mtd=7"
UBI: MTD device size: 120 MiB
UBI: number of good PEBs: 964
UBI: number of bad PEBs: 0
UBI: max. allowed volumes: 128
UBI: wear-leveling threshold: 4096
UBI: number of internal volumes: 1
UBI: number of user volumes: 0
UBI: available PEBs: 951
UBI: total number of reserved PEBs: 13
UBI: number of PEBs reserved for bad PEB handling: 9
UBI: max/mean erase counter: 1/0
No size specified -> Using max size (122701824)
Creating dynamic volume rootfs of size 122701824
22321152 bytes written to volume rootfs

Now I try

U-Boot@UCC3# ubifsmount rootfs
UBIFS: mounted UBI device 0, volume 0, name "rootfs"
UBIFS: mounted read-only
UBIFS: file system size: 121282560 bytes (118440 KiB, 115 MiB, 940 LEBs)
UBIFS: journal size: 9033728 bytes (8822 KiB, 8 MiB, 71 LEBs)
UBIFS: media format: w4/r0 (latest is w4/r0)
UBIFS: default compressor: LZO
UBIFS: reserved for root: 0 bytes (0 KiB)

U-Boot# reset

U-Boot@UCC3# ubi part rootfs
Creating 1 MTD partitions on "nand0":
0x000000780000-0x000008000000 : "mtd=7"
UBI: attaching mtd1 to ubi0
UBI: physical eraseblock size: 131072 bytes (128 KiB)
UBI: logical eraseblock size: 129024 bytes
UBI: smallest flash I/O unit: 2048
UBI: sub-page size: 512
UBI: VID header offset: 512 (aligned 512)
UBI: data offset: 2048
ECC: uncorrectable.
ECC: uncorrectable.
UBI error: ubi_io_read: error -74 while reading 64 bytes from PEB 0:0, read 64 bytes
ECC: uncorrectable.
ECC: uncorrectable.
UBI error: ubi_io_read: error -74 while reading 512 bytes from PEB 0:512, read 512 bytes

So, I'm still trying to understand what I did wrong. There is a comment in the wiki that says "On flashing UBIFS image from U-Boot, make sure that ECC selected is in sync with Linux" but this u-boot does NOT have the nandecc command anymore...

I could go on a little more, but I think it enough to get a picture of what is going on.

Anyone has any thoughts?

Thanks in advance!

DAVI

 

  • Hi Davi,

    I see you have been following this guide: http://processors.wiki.ti.com/index.php/UBIFS_Support

    What seems odd is your calculated LEB size. It should be:

    LEB = PEB - 2*(min I/O) = 128K - 2*2K = 124K = 126976

    and I can see that you have passed -e 129024 to the mkfs.ubifs command when creating the image.

    If you have used the wrong LEB size when calculating the UBI overhead later, then the other calculations are wrong as well. Please make sure the values are correct before creating the UBI image.

    Davi Evangelista said:
    this u-boot does NOT have the nandecc command anymore...

    Since a few SDK versions ago, the default ecc scheme in U-Boot is BCH8 and you don't need to change that.

    Best regards,
    Miroslav

  • Well, 129024 is the value u-boot prints when ubi part rootfs is used after nand erase. The command also prints the available PEBs and the total number of reserved PEBs based on 129024, so I was using the available PEBs for the -c option in mkfs.ubifs. You can see this at the end of my first post.

    Anyhow, I changed the value to 129676 and it didn't work either. Another complication is the -c option: now I don't know how much space should be left out.

    There are 2 new scenarios now and I will change their color to separate them. They all use the images I get from

    $ ~/mtd/install/sbin/mkfs.ubifs -F -r rootfs/ -o ubifs.img -m 2048 -e 129676 -c 950
    $ ~/mtd/install/sbin/ubinize -o rootfs.img -m 2048 -p 128KiB -O 2048 ubinize.cfg

    usb reset
    fatload usb 0 0x81000000 rootfs.img
    nand erase 0x00780000 0x7880000
    nand write 0x81000000 0x00780000 ${filesize}
    run nand_boot

    Kernel log:

    [ 1.255674] UBI: attaching mtd7 to ubi0
    [ 1.259833] UBI: physical eraseblock size: 131072 bytes (128 KiB)
    [ 1.266497] UBI: logical eraseblock size: 126976 bytes
    [ 1.272248] UBI: smallest flash I/O unit: 2048
    [ 1.277248] UBI: VID header offset: 2048 (aligned 2048)
    [ 1.283651] UBI: data offset: 4096
    [ 2.381407] UBI: max. sequence number: 0
    [ 2.404985] UBI error: vtbl_check: volume table check failed: record 0, error 9
    [ 2.413475] UBI error: ubi_init: cannot attach mtd7

    usb reset
    fatload usb 0 0x81000000 ubifs.img
    nand erase 0x00780000 0x7880000
    ubi part rootfs
    ubi create rootfs
    ubi write 0x81000000 rootfs ${filesize}

    U-Boot output:

    (Re)start USB...
    USB0: scanning bus 0 for devices... 1 USB Device(s) found
    scanning usb for storage devices... 1 Storage Device(s) found
    reading ubifs.img
    22347776 bytes read in 18756 ms (1.1 MiB/s)

    NAND erase: device 0 offset 0x780000, size 0x7880000
    Erasing at 0x7fe0000 -- 100% complete.
    OK
    Creating 1 MTD partitions on "nand0":
    0x000000780000-0x000008000000 : "mtd=7"
    UBI: attaching mtd1 to ubi0
    UBI: physical eraseblock size: 131072 bytes (128 KiB)
    UBI: logical eraseblock size: 129024 bytes
    UBI: smallest flash I/O unit: 2048
    UBI: sub-page size: 512
    UBI: VID header offset: 512 (aligned 512)
    UBI: data offset: 2048
    UBI: empty MTD device detected
    UBI: create volume table (copy #1)
    UBI: create volume table (copy #2)
    UBI: attached mtd1 to ubi0
    UBI: MTD device name: "mtd=7"
    UBI: MTD device size: 120 MiB
    UBI: number of good PEBs: 964
    UBI: number of bad PEBs: 0
    UBI: max. allowed volumes: 128
    UBI: wear-leveling threshold: 4096
    UBI: number of internal volumes: 1
    UBI: number of user volumes: 0
    UBI: available PEBs: 951
    UBI: total number of reserved PEBs: 13
    UBI: number of PEBs reserved for bad PEB handling: 9
    UBI: max/mean erase counter: 1/0
    No size specified -> Using max size (122701824)
    Creating dynamic volume rootfs of size 122701824
    22347776 bytes written to volume rootfs

    U-Boot# ubifsmount rootfs
    UBIFS error (pid 0): validate_sb: LEB size mismatch: 126976 in superblock, 129024 real
    UBIFS error (pid 0): validate_sb: bad superblock, error 1
    UBIFS error (pid 0): ubifs_mount: Error reading superblock on volume 'ubi:rootfs' errno=-22!

    ubifsmount - mount UBIFS volume

    Kernel log:

    [ 1.255728] UBI: attaching mtd7 to ubi0
    [ 1.259886] UBI: physical eraseblock size: 131072 bytes (128 KiB)
    [ 1.266548] UBI: logical eraseblock size: 126976 bytes
    [ 1.272300] UBI: smallest flash I/O unit: 2048
    [ 1.277297] UBI: VID header offset: 2048 (aligned 2048)
    [ 1.283697] UBI: data offset: 4096
    [ 1.294095] UBI error: ubi_io_read: error -74 (ECC error) while reading 64 bytes from PEB 0:0, read 64 bytes
    [ 1.304597] UBI error: validate_ec_hdr: bad VID header offset 512, expected 2048
    [ 1.312489] UBI error: validate_ec_hdr: bad EC header
    [ 1.317856] UBI error: ubi_io_read_ec_hdr: validation failed for PEB 0
    [ 1.324941] UBI error: ubi_init: cannot attach mtd

    This problem with ubi write and ubifsmount is specially bad because I would like to load uImage via an UBIFS partition and see if ubifsload is faster that nand read.

    First things first, I still can't boot my Linux with the image ubinize creates (blue text above)... How do I get the number that should be used in the -c option when mkfs.ubifs is called? I think maybe that is what's wrong with it, alongside the configuration file used in ubinize...

    DAVI

  • Here is why u-boot uses 129024 instead of 129676:

    In the file drivers/mtd/ubi/build.c, line 620, LEB_size is calculated as follows:

    ubi->leb_size = ubi->peb_size - ubi->leb_start;

    So I changed this line to

    ubi->leb_size = ubi->peb_size-(2*ubi->min_io_size);

    And now u-boot is able to guess the correct LEB_size and ubifsmount works again, everything with LEB_size = 124K.

    The Kernel still gives the same error messages, including the ECC error, though...

    DAVI

  • What NAND part are you using? I've done some ubifs work last year and I can try to help out.

    Steve K.

  • Thanks. I'm still gathering hardware to test with. I did see something strange in your logs. From u-boot I see

    UBI: sub-page size: 512
    UBI: VID header offset: 512 (aligned 512)

    But from the wiki,

    • subpage-size should set same as page-size
    • offset-of-vid-header should also be set same as page-size

    Can you use -s 2048 and -O 2048 when you ubinize?

    Steve K.

  • There is another winner: again, in drivers/mtd/ubi/build.c, line 546, there was this line:

    ubi->hdrs_min_io_size = ubi->mtd->writesize >> ubi->mtd->subpage_sft;

    That I changed to

    ubi->hdrs_min_io_size = ubi->min_io_size;

    And now we have u-boot printing the following;

    UBI: attaching mtd1 to ubi0
    UBI: physical eraseblock size: 131072 bytes (128 KiB)
    UBI: logical eraseblock size: 126976 bytes
    UBI: smallest flash I/O unit: 2048
    UBI: VID header offset: 2048 (aligned 2048)
    UBI: data offset: 4096

  • Anyway, I got the ubinized image to boot.

    The problem was the line vol_size in the configuration file I use in ubinize. Reducing the partition size from 120MiB to 100Mib with the following commands

    $ echo "[ubifs]
    mode=ubi
    image=ubifs.img
    vol_id=0
    vol_size=100MiB
    vol_type=dynamic
    vol_name=rootfs
    vol_flags=autoresize" | tee ubinize.cfg > /dev/null
    $ ~/mtd/install/sbin/mkfs.ubifs -F -r rootfs/ -o ubifs.img -m 2048 -e 126976 -c 800
    $ ~/mtd/install/sbin/ubinize -o rootfs.img -m 2048 -p 128KiB -O 2048 ubinize.cfg

    gives me an image that nand write is able to flash into the chip and the Kernel stops complaining.

    Now I lost 20MiB, but I have a partition that boots...

    I'm still trying to solve this new issue.

    In the other side of things, I still can't use the UBIFS image and flash it via ubi write. Right after I use ubi part to set up the kernel partition, ubi create to create the volume name and ubi write to write the kernel (inside a UBIFS image) I'm able to use ubifsmount. Once I reset the board, I can't mount it anymore. Here is what's happening:

    usb reset
    fatload usb 0 0x81000000 uImage.img
    nand erase 0x280000 0x500000
    ubi part kernel
    ubi create kernel
    ubi write 0x81000000 kernel ${filesize}

    Output:

    USB0: scanning bus 0 for devices... 1 USB Device(s) found
    scanning usb for storage devices... 1 Storage Device(s) found
    reading uImage.img
    4063232 bytes read in 3441 ms (1.1 MiB/s)

    NAND erase: device 0 offset 0x280000, size 0x500000
    Erasing at 0x760000 -- 100% complete.
    OK
    Creating 1 MTD partitions on "nand0":
    0x000000280000-0x000000780000 : "mtd=6"
    UBI: attaching mtd1 to ubi0
    UBI: physical eraseblock size: 131072 bytes (128 KiB)
    UBI: logical eraseblock size: 126976 bytes
    UBI: smallest flash I/O unit: 2048
    UBI: VID header offset: 2048 (aligned 2048)
    UBI: data offset: 4096
    UBI: empty MTD device detected
    UBI: create volume table (copy #1)
    UBI: create volume table (copy #2)
    UBI: attached mtd1 to ubi0
    UBI: MTD device name: "mtd=6"
    UBI: MTD device size: 5 MiB
    UBI: number of good PEBs: 40
    UBI: number of bad PEBs: 0
    UBI: max. allowed volumes: 128
    UBI: wear-leveling threshold: 4096
    UBI: number of internal volumes: 1
    UBI: number of user volumes: 0
    UBI: available PEBs: 34
    UBI: total number of reserved PEBs: 6
    UBI: number of PEBs reserved for bad PEB handling: 2
    UBI: max/mean erase counter: 1/0
    No size specified -> Using max size (4317184)
    Creating dynamic volume kernel of size 4317184
    4063232 bytes written to volume kernel

    U-Boot# ubifsmount kernel
    UBIFS: mounted UBI device 0, volume 0, name "kernel"
    UBIFS: mounted read-only
    UBIFS: file system size: 3047424 bytes (2976 KiB, 2 MiB, 24 LEBs)
    UBIFS: journal size: 1142785 bytes (1116 KiB, 1 MiB, 8 LEBs)
    UBIFS: media format: w4/r0 (latest is w4/r0)
    UBIFS: default compressor: LZO
    UBIFS: reserved for root: 0 bytes (0 KiB)

    U-Boot# reset

    U-Boot# ubifsmount kernel
    UBIFS error (pid 0): ubifs_get_sb: cannot open "ubi:kernel", error -19
    UBIFS error (pid 0): ubifs_mount: Error reading superblock on volume 'ubi:kernel' errno=-19!

    ubifsmount - mount UBIFS volume

    So, why doesn't u-boot keep the partition working after a reset?

    DAVI

  • Well, turns out that even if I inform a smaller size in vol_size, if I set the -c option in mkfs.ubifs accordingly, the autoresize is able to occupy the whole partition. So I'm using the maximum number of PEBs as shown below:

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

    $ ~/mtd/install/sbin/mkfs.ubifs -F -r rootfs/ -o ubifs.img -m 2048 -e 126976 -c 964
    $ ~/mtd/install/sbin/ubinize -o rootfs.img -m 2048 -p 128KiB -O 2048 ubinize.cfg

    I still don't have a clue why I can't use vol_size=120MiB, but anyway, I'm not losing any memory space anymore.

    Thank you for the help!

     

    PS: no clue about the u-boot issue so far

     

    DAVI