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.

Does anybody try to use ubifsload to load a kernel image from NAND file system?

Hi,

I use  AM335x EVM board to develop my system. I did bootup the system from NAND flash following the procedure posted on-line.

Now I like to load the kernel image from the ubi NAND file system where I saved a kernel Image after the system is up.

I find there is command ubifsload in u-boot, does anybody know how to enable it and use it for AM335x EVM?

Thank you!

Jin

  • Can somebody answer my question?

    I try to enable the ubi, ubifs in u-boot. I did manage to build a u-boot.img with it. but when I issue command ubi failed.

    U-Boot# mtdparts

    device nand0 <nand>, # parts = 5
     #: name                size            offset          mask_flags
     0: x-loader            0x00080000      0x00000000      0
     1: u-boot              0x001e0000      0x00080000      0
     2: u-boot-env          0x00020000      0x00260000      0
     3: kernel              0x00700000      0x00280000      0
     4: fs                  0x0f680000      0x00980000      0

    active partition: nand0,0 - (x-loader) 0x00080000 @ 0x00000000

    defaults:
    mtdids  : nand0=nand
    mtdparts: mtdparts=nand:512k(x-loader),1920k(u-boot),128k(u-boot-env),4m(kernel),-(fs)
    U-Boot# ubi part fs
    Creating 1 MTD partitions on "nand0":
    0x000000980000-0x000010000000 : "mtd=4"
    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 error: validate_ec_hdr: bad VID header offset 2048, expected 512
    UBI error: validate_ec_hdr: bad EC header
    UBI error: ubi_io_read_ec_hdr: validation failed for PEB 0
    UBI error: ubi_init: cannot attach mtd1
    UBI error: ubi_init: UBI error: cannot initialize UBI, error -22
    UBI init error 22
    U-Boot#

    Any idea?

  • Jin,

    1. Which is the ECC algorithm selected?

    2. What is your bootargs?

  • Hi, Renjith:

    I use nandecc hw 2

    I still in the u-boot, my bootargs is not used yet.

    I made some progress, but still have error.

    What I did like this

    u-boot#nandecc hw 2

    U-Boot# mtdpart

    device nand0 <nand>, # parts = 5
     #: name                size            offset          mask_flags
     0: x-loader            0x00080000      0x00000000      0
     1: u-boot              0x001e0000      0x00080000      0
     2: u-boot-env          0x00020000      0x00260000      0
     3: kernel              0x00700000      0x00280000      0
     4: fs                  0x0f680000      0x00980000      0

    active partition: nand0,0 - (x-loader) 0x00080000 @ 0x00000000

    defaults:
    mtdids  : nand0=nand
    mtdparts: mtdparts=nand:512k(x-loader),1920k(u-boot),128k(u-boot-env),4m(kernel),-(fs)
    U-Boot# printenv
    autoload=yes
    baudrate=115200
    bootargs_defaults=setenv bootargs console=${console} ${optargs}
    bootcmd=if mmc rescan; then echo SD/MMC found on device ${mmc_dev};if run loadbootenv; then echo Loaded environment from ${bootenv};run importbootenv;fi;if test -n $uenvcmd; then echo Running uenvcmd ...;run uenvcmd;fi;if run mmc_load_uimage; then run mmc_args;bootm ${kloadaddr};fi;fi;run nand_boot;
    bootdelay=3
    bootenv=uEnv.txt
    bootfile=uImage
    console=ttyO0,115200n8
    ethact=cpsw
    ethaddr=d4:94:a1:52:47:04
    gatewayip=192.168.12.1
    importbootenv=echo Importing environment from mmc ...; env import -t $loadaddr $filesize
    ip_method=none
    ipaddr=192.168.12.30
    kloadaddr=0x82000000
    loadaddr=0x82000000
    loadbootenv=fatload mmc ${mmc_dev} ${loadaddr} ${bootenv}
    mmc_args=run bootargs_defaults;setenv bootargs ${bootargs} ${runlevel}
    mmc_boot=run mmc_args; run mmc_load_uimage; bootm ${kloadaddr}
    mmc_dev=0
    mmc_load_uimage=fatload mmc ${mmc_dev} ${kloadaddr} ${bootfile}
    mmc_root=/dev/mmcblk0p2 rw
    mmc_root_fs_type=ext3 rootwait
    mtddevname=x-loader
    mtddevnum=0
    mtdids=nand0=nand
    mtdparts=mtdparts=nand:512k(x-loader),1920k(u-boot),128k(u-boot-env),7m(kernel),-(fs)
    nand_args=run bootargs_defaults;setenv bootargs ${bootargs} root=${nand_root} noinitrd rootfstype=${nand_root_fs_type} ip=${ip_method}
    nand_boot=echo Booting from nand ...; run nand_args; nandecc hw 2; nand read.i ${kloadaddr} ${nand_src_addr} ${nand_img_siz}; bootm ${kloadaddr}
    nand_img_siz=0x700000
    nand_img_size=0x700000
    nand_root=ubi0:rootfs rw ubi.mtd=7,2048
    nand_root_fs_type=ubifs rootwait=1
    nand_src_addr=0x280000
    net_args=run bootargs_defaults;setenv bootargs ${bootargs} root=/dev/nfs nfsroot=${serverip}:${rootpath},${nfsopts} rw ip=dhcp
    net_boot=echo Booting from network ...; setenv autoload no; dhcp; tftp ${kloadaddr} ${bootfile}; run net_args; bootm ${kloadaddr}
    netmask=255.255.255.0
    nfsopts=nolock
    nor_args=run bootargs_defaults;setenv bootargs ${bootargs} root={nor_root} rootfstype=${nor_root_fs_type} ip=${ip_method}
    nor_boot=echo Booting from NOR ...; run nor_args; cp.b ${0x08080000} ${kloadaddr} ${nor_img_siz}; bootm ${kloadaddr}
    nor_img_siz=0x280000
    nor_root=/dev/mtdblock3 rw
    nor_root_fs_type=jffs2
    nor_src_addr=0x08080000
    partition=nand0,0
    rootpath=/export/rootfs
    runlevel=2
    script_addr=0x81900000
    serverip=192.168.17.90
    spi_args=run bootargs_defaults;setenv bootargs ${bootargs} root=${spi_root} rootfstype=${spi_root_fs_type} ip=${ip_method}
    spi_boot=echo Booting from spi ...; run spi_args; sf probe ${spi_bus_no}:0; sf read ${kloadaddr} ${spi_src_addr} ${spi_img_siz}; bootm ${kloadaddr}
    spi_bus_no=0
    spi_img_siz=0x380000
    spi_root=/dev/mtdblock4 rw
    spi_root_fs_type=jffs2
    spi_src_addr=0x62000
    static_ip=${ipaddr}:${serverip}:${gatewayip}:${netmask}:${hostname}::off
    stderr=serial
    stdin=serial
    stdout=serial

    U-Boot# nand erase 980000 f680000

    NAND erase: device 0 offset 0x980000, size 0xf680000
    Erasing at 0xffe0000 -- 100% complete.
    OK

    U-Boot# tftp ubi.img
    link up on port 0, speed 100, full duplex
    Using cpsw device
    TFTP from server 192.168.17.90; our IP address is 192.168.12.30; sending through gateway 192.168.12.1
    Filename 'ubi.img'.
    Load address: 0x82000000
    Loading: #################################################################
             #################################################################
             #################################################################
             #################################################################
             #################################################################
             #################################################################
             ####################
    done
    Bytes transferred = 2097152 (200000 hex)
    U-Boot# nand erase 980000 fc0000

    NAND erase: device 0 offset 0x980000, size 0xfc0000
    Erasing at 0x1920000 -- 100% complete.
    OK
    U-Boot# nand write 82000000 980000 fc0000

    NAND write: device 0 offset 0x980000, size 0xfc0000
     16515072 bytes written: OK

    U-Boot# ubi part fs
    Creating 1 MTD partitions on "nand0":
    0x000000980000-0x000010000000 : "mtd=4"
    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 warning: ubi_eba_init_scan: cannot reserve enough PEBs for bad PEB handling, reserved 17, need 19
    UBI: volume 0 ("ubi0") re-sized from 1951 to 1951 LEBs
    UBI: attached mtd1 to ubi0
    UBI: MTD device name:            "mtd=4"
    UBI: MTD device size:            246 MiB
    UBI: number of good PEBs:        1972
    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:     1
    UBI: available PEBs:             0
    UBI: total number of reserved PEBs: 1972
    UBI: number of PEBs reserved for bad PEB handling: 17
    UBI: max/mean erase counter: 1/0

    U-Boot# ubi create ubi0
    No size specified -> Using max size (0)
    No space left in UBI device!
    verify_mkvol_req failed 12
    U-Boot# ubifsmount ubi0
    Error reading superblock on volume 'ubi:ubi0'!
    U-Boot# ubifsls
    UBIFS not mounted, use ubifsmount to mount volume first!

    The way I create the file image is

    sudo mkfs.ubifs -q -r flash -m 2048 -e 129024 -c 1949 -o ubifs.img

    [ubifs]

    mode=ubi

    image=ubifs.img

    vol_id=0

    vol_size=240MiB

    vol_type=dynamic

    vol_name=ubi0

    vol_flags=autoresize

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

    My problem is

    I try to mount the ubi0 in u-boot, it complains. the error is error reading superpage

  • Hi Jin,

    Have you tried creating UBI volume from kernel itself? I'm not really sure about u-boot here, but there are issues with BCH8 implementation. 

  • Hi Renjith:

    I haven't try to create the UBI colume from kernel yet, I need port the ubi utility to my file system. I will let you know the result?

    Regarding the issue with BCH8, can you tell me in a little more details. can you recommand what ECC I should use in u-boot and kernel?

    Do you know if anybody try to boot the kernel from the flash file system in u-boot?

    Thank you!

    Jin 

  • I also noticed in the u-boot

    the logical eraseblock size is 129024 in u-boot,

    but the document from TI talk about the size is different. it is 126976 when we create the ubifs.img

    How can I make this two consistant?

     

  • Jin,

    I could successfully boot up UBIFS after flashing from u-boot. But those were not on AM335x platforms. So, I need you to try out few things to debug where exactly is the problem. I have faced issues in u-boot as well as kernel. We need to isolate first the issues in kernel and then let's try to debug kernel. Could you please try to create UBI volume from kernel and then solve the issues there, and then later proceed with u-boot. 

    As of now you can try with 1-bit hamming code u-boot and kernel. 

  • I attach my result here, I have teh ti-sdk kernel, only thing I did not do here is set ECC 1-bit hamming code.

    Can you tell me whick file I need to modify to set the hamming code correct?

    Thank you!

    Jin

    root@am335x-evm:/flash# ubiformat /dev/mtd7 -f /flash/ubi.img -s 512 -O 2048
    ubiformat: mtd7 (nand), size 258473984 bytes (246.5 MiB), 1972 eraseblocks of 131072 bytes (128.0 KiB), min. I/O size 2048 bytes
    libscan: scanning eraseblock 1971 -- 100 % complete
    ubiformat: 1972 eraseblocks are supposedly empty
    ubiformat: flashing eraseblock 15 -- 100 % complete
    ubiformat: formatting eraseblock 1971 -- 100 % complete
    root@am335x-evm:/flash# ubiattach /dev/ubi_ctrl -m 7 -o 2048
    ubiattach: invalid option -- 'o'
    Use -h for help
    root@am335x-evm:/flash# ubiattach /dev/ubi_ctrl -m 7 -O 2048
    [  256.557708] UBI: attaching mtd7 to ubi0
    [  256.561798] UBI: physical eraseblock size:   131072 bytes (128 KiB)
    [  256.568359] UBI: logical eraseblock size:    126976 bytes
    [  256.573974] UBI: smallest flash I/O unit:    2048
    [  256.578887] UBI: sub-page size:              512
    [  256.583709] UBI: VID header offset:          2048 (aligned 2048)
    [  256.589965] UBI: data offset:                4096
    [  256.596527] UBI error: validate_ec_hdr: bad VID header offset 512, expected 2048
    [  256.604248] UBI error: validate_ec_hdr: bad EC header
    [  256.609527] UBI error: ubi_io_read_ec_hdr: validation failed for PEB 0
    [  256.616363] Unable to handle kernel paging request at virtual address 00100104
    [  256.623901] pgd = cedd0000
    [  256.626739] [00100104] *pgd=8fac5831, *pte=00000000, *ppte=00000000
    [  256.633300] Internal error: Oops: 817 [#1]
    [  256.637542] Modules linked in:
    [  256.640747] CPU: 0    Not tainted  (3.2.0 #3)
    [  256.645294] PC is at kmem_cache_destroy+0x58/0xfc
    [  256.650207] LR is at kmem_cache_destroy+0x3c/0xfc
    [  256.655120] pc : [<c00a1910>]    lr : [<c00a18f4>]    psr: 60000013
    [  256.655120] sp : cfab1dc0  ip : 00100100  fp : cfab1dd4
    [  256.667083] r10: ce437754  r9 : 00000800  r8 : c0638d1c
    [  256.672546] r7 : ffffffea  r6 : ce43774c  r5 : ce437740  r4 : cf9b43c0
    [  256.679351] r3 : 00200200  r2 : 00100100  r1 : 00200200  r0 : cf9b43c0
    [  256.686157] Flags: nZCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment user
    [  256.693603] Control: 10c5387d  Table: 8edd0019  DAC: 00000015
    [  256.699584] Process ubiattach (pid: 2060, stack limit = 0xcfab02f0)
    [  256.706115] Stack: (0xcfab1dc0 to 0xcfab2000)
    [  256.710662] 1dc0: 00000000 ce437740 cfab1dfc cfab1dd8 c026dd60 c00a18c4 cfb5b200 00000000
    [  256.719207] 1de0: ce437740 ced14800 ffffffea c0638d1c cfab1e6c cfab1e00 c026e0a0 c026db00
    [  256.727722] 1e00: 00000000 c00a1b1c 00000010 ce4379c0 00000005 ce437754 cf3c5800 00000000
    [  256.736267] 1e20: ced14800 cf3c5800 ced14cf8 ce43775c ce43774c ce437744 000000d2 0000024f
    [  256.744781] 1e40: ffffffff fffff800 cf3c5800 00000000 ced14800 cf3c5800 00000800 00000000
    [  256.753326] 1e60: cfab1eb4 cfab1e70 c0265d60 c026dd78 00000001 000007ff 00000200 cfab0000
    [  256.761840] 1e80: cfab1ea4 cfab1e90 00000000 be8ddb60 cf3c5800 40186f40 00000003 00000000
    [  256.770385] 1ea0: cfab0000 00000000 cfab1eec cfab1eb8 c0266660 c026595c ffffffff 00000007
    [  256.778900] 1ec0: 00000800 00000000 00000000 00000000 00000041 ce4030e8 be8ddb60 40186f40
    [  256.787445] 1ee0: cfab1f74 cfab1ef0 c00b36b8 c0266590 cf484d18 ce4030e8 00000101 00000004
    [  256.795959] 1f00: 00000000 00000000 00000000 cf810c80 cf840348 00000001 00020000 00000000
    [  256.804504] 1f20: 00000000 00000000 c00bbcd8 cecfe000 cf840340 00000003 c05ba254 cecfe000
    [  256.813049] 1f40: cf840340 00000003 cfab1f94 cfab1f58 cf840340 be8ddb60 40186f40 00000003
    [  256.821563] 1f60: 00000000 cfab0000 cfab1fa4 cfab1f78 c00b3bd8 c00b363c be8ddb60 00000000
    [  256.830108] 1f80: c00142a8 00000003 be8ddea9 be8ddb60 00000036 c00142a8 00000000 cfab1fa8
    [  256.838623] 1fa0: c0014100 c00b3b6c 00000003 be8ddea9 00000003 40186f40 be8ddb60 00000000
    [  256.847167] 1fc0: 00000003 be8ddea9 be8ddb60 00000036 000151bc 00000000 ffffffff 00000000
    [  256.855682] 1fe0: ffffffff be8ddb48 00009a44 402411cc 60000010 00000003 00000000 00000000
    [  256.864196] Backtrace:
    [  256.866790] [<c00a18b8>] (kmem_cache_destroy+0x0/0xfc) from [<c026dd60>] (ubi_scan_destroy_si+0x26c/0x278)
    [  256.876831]  r4:ce437740 r3:00000000
    [  256.880584] [<c026daf4>] (ubi_scan_destroy_si+0x0/0x278) from [<c026e0a0>] (ubi_scan+0x334/0xa08)
    [  256.889831]  r8:c0638d1c r7:ffffffea r6:ced14800 r5:ce437740 r4:00000000
    [  256.896667] r3:cfb5b200
    [  256.899414] [<c026dd6c>] (ubi_scan+0x0/0xa08) from [<c0265d60>] (ubi_attach_mtd_dev+0x410/0xa6c)
    [  256.908569] [<c0265950>] (ubi_attach_mtd_dev+0x0/0xa6c) from [<c0266660>] (ctrl_cdev_ioctl+0xdc/0x16c)
    [  256.918304] [<c0266584>] (ctrl_cdev_ioctl+0x0/0x16c) from [<c00b36b8>] (do_vfs_ioctl+0x88/0x530)
    [  256.927459]  r6:40186f40 r5:be8ddb60 r4:ce4030e8
    [  256.932281] [<c00b3630>] (do_vfs_ioctl+0x0/0x530) from [<c00b3bd8>] (sys_ioctl+0x78/0x80)
    [  256.940795]  r9:cfab0000 r8:00000000 r7:00000003 r6:40186f40 r5:be8ddb60
    [  256.947631] r4:cf840340
    [  256.950378] [<c00b3b60>] (sys_ioctl+0x0/0x80) from [<c0014100>] (ret_fast_syscall+0x0/0x30)
    [  256.959075]  r8:c00142a8 r7:00000036 r6:be8ddb60 r5:be8ddea9 r4:00000003
    [  256.966094] Code: e3a03c02 e3402010 e3403020 e1a00004 (e58c1004)
    [  256.972503] ---[ end trace 8b5bb973da2d0d61 ]---
    Segmentation fault
    root@am335x-evm:/flash#

  • Jin,

    Can you send me the list of files given below to my mail renjith.thomas@pathpartnertech.com

    arch/arm/mach-omap2/board-am335xevm.c
    arch/arm/mach-omap2/board-flash.c
    arch/arm/mach-omap2/gpmc.c
    drivers/mtd/nand/nand_base.c
    drivers/mtd/nand/omap2.c

  • Jin Yu1 said:

    I also noticed in the u-boot

    the logical eraseblock size is 129024 in u-boot,

    but the document from TI talk about the size is different. it is 126976 when we create the ubifs.img

    How can I make this two consistant?

     

    Jin, 

    This comes from UBIFS data block structure. I read the details about UBIFS carefully so I know what I'm doing a bit better ;-).

    In a nutshell, the basic unit of measurement for NAND data transfers is the physical eraseable block size (PEB) and this is dictated by the memory chip manufacturer, but is 128Kb typically. I/O access within a PEB  is done as smaller memory blocks, typically of 2Kb size. Some chips allow even smaller, sub-page access (512 bytes).

    Now, within each PEB, UBI driver reserves two pages for NAND storage management: one for volume information about the block and one for error detection/correction, thus reducing PEB useful space for data. This reduced size is called LEB (Logical Eraseable Block in the litterature).

    So why do we have to care about all those details? They put constraints to mkfs.ubifs, ubinize and ubiformat application arguments: 

    1. If sub-paging is allowed, then the overhead of only one page so the LEB size is (128 - 2) = 126 Kb
    2. If sub-paging is not allowed, then the overhead is two pages so LEB size is now (128 -2*2) = 124 kb

    TI wiki authors took the second option and that explains why their LEB size is smaller (I did it too - no luck for me :-( ). 

    I hope that all of this is correct and meaningful to you,

    Yves

  • Jin,

    One quick thing you can try to move further is to modify the command like this.

    ubiformat /dev/mtd7 -f /flash/ubi.img -s 2048 -O 2048