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: U-boot and kernel UBIFS not compatible

Hi!

I am working on BeagleBone varian board using Ångström distribution.  Main difference is that NAND flash is installed on board.

Short story:

UBIFS partition/volume formatted/created in Linux does not work in U-Boot. Ubi part command in U-boot fails and corrupts this UBIFS volume. Later on Linux finds this UBIFS corrupted. I don't have any problems if this UBIFS is accessed pure from Linux. I have made nand flash additions from am335x-evm.dts to BeagleBone device tree. I have tried with ti,nand-ecc-opt = "bch8" (with kernel options CONFIG_MTD_NAND_OMAP_BCH and
OMAP_ECC_BCH8_CODE_HW) and without. In the latter case those kernel options were not active.

Longer store = operations and results:

======================================
BOOT => Linux

root@beaglebone:~# cat /proc/mtd
ddev:    size   erasesize  name
mtd0: 00020000 00020000 "SPL1"
mtd1: 00020000 00020000 "SPL2"
mtd2: 00020000 00020000 "SPL3"
mtd3: 00020000 00020000 "SPL4"
mtd4: 001e0000 00020000 "U-boot"
mtd5: 00020000 00020000 "environment"
mtd6: 00500000 00020000 "Kernel"
mtd7: 0f880000 00020000 "File-System"


root@beaglebone:~# mtdinfo /dev/mtd7
mtd7
Name:                           File-System
Type:                           nand
Eraseblock size:                131072 bytes, 128.0 KiB
Amount of eraseblocks:          1988 (260571136 bytes, 248.5 MiB)
Minimum input/output unit size: 2048 bytes
Sub-page size:                  512 bytes
OOB size:                       64 bytes
Character device major/minor:   90:14
Bad blocks are allowed:         true
Device is writable:             true


root@beaglebone:~# ubiformat /dev/mtd7
ubiformat: mtd7 (nand), size 260571136 bytes (248.5 MiB), 1988 eraseblocks of 131072 bytes (128.0 KiB), min. I/O size 2048 bytes
libscan: scanning eraseblock 1987 -- 100 % complete
ubiformat: 1980 eraseblocks have valid erase counter, mean value is 2
ubiformat: 8 bad eraseblocks found, numbers: 70, 281, 310, 964, 1590, 1900, 1920, 1977
ubiformat: formatting eraseblock 1987 -- 100 % complete


root@beaglebone:~# ubiattach -m 7
[  615.304815] UBI: default fastmap pool size: 95
[  615.309712] UBI: default fastmap WL pool size: 25
[  615.314727] UBI: attaching mtd7 to ubi0
[  616.065041] UBI: scanning is finished
[  616.092241] UBI: attached mtd7 (name "File-System", size 248 MiB) to ubi0
[  616.099551] UBI: PEB size: 131072 bytes (128 KiB), LEB size: 129024 bytes
[  616.106760] UBI: min./max. I/O unit sizes: 2048/2048, sub-page size 512
[  616.113780] UBI: VID header offset: 512 (aligned 512), data offset: 2048
[  616.120891] UBI: good PEBs: 1980, bad PEBs: 8, corrupted PEBs: 0
[  616.127267] UBI: user volume: 0, internal volumes: 1, max. volumes count: 128
[  616.134839] UBI: max/mean erase counter: 4/3, WL threshold: 4096, image sequence number: 1266322069
[  616.144425] UBI: available PEBs: 1942, total reserved PEBs: 38, PEBs reserved for bad PEB handling: 32
[  616.154993] UBI: background thread "ubi_bgt0d" started, PID 266
UBI device number 0, total 1980 LEBs (255467520 bytes, 243.6 MiB), available 1942 LEBs (250564608 bytes, 239.0 MiB), LEB size 129024 bytes (126.0 KiB)

root@beaglebone:~# ubimkvol /dev/ubi0 -N rootfs -m
Set volume size to 250564608
Volume ID 0, size 1942 LEBs (250564608 bytes, 239.0 MiB), LEB size 129024 bytes (126.0 KiB), dynamic, name "rootfs", alignment 1

root@beaglebone:~# mkdir /mnt/rootfs

root@beaglebone:~# mount -t ubifs ubi0:rootfs /mnt/rootfs
[ 1246.100061] UBIFS: default file-system created
[ 1246.129559] UBIFS: background thread "ubifs_bgt0_0" started, PID 279
[ 1246.181635] UBIFS: mounted UBI device 0, volume 0, name "rootfs"(null)
[ 1246.188687] UBIFS: LEB size: 129024 bytes (126 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 1246.198379] UBIFS: FS size: 248887296 bytes (237 MiB, 1929 LEBs), journal size 12515328 bytes (11 MiB, 97 LEBs)
[ 1246.209066] UBIFS: reserved for root: 4952683 bytes (4836 KiB)
[ 1246.215270] UBIFS: media format: w4/r0 (latest is w4/r0), UUID BBB7B485-B786-43D4-9EF7-F237AF6C707B, small LPT model

root@beaglebone:~# cd /mnt/rootfs
root@beaglebone:/mnt/rootfs# mkdir testdir
root@beaglebone:/mnt/rootfs# cd testdir
root@beaglebone:/mnt/rootfs/testdir# echo testdata > testfile.txt
root@beaglebone:/mnt/rootfs/testdir# cat testfile.txt
testdata


root@beaglebone:/mnt/rootfs/testdir# sync
root@beaglebone:/mnt/rootfs/testdir# cd
root@beaglebone:~# umount /mnt/rootfs
[ 1774.802970] UBIFS: un-mount UBI device 0, volume 0
[ 1774.812940] UBIFS: background thread "ubifs_bgt0_0" stops
root@beaglebone:~# shutdown -h now  


======================================
BOOT => U-Boot



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              0x0f880000      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)


U-Boot# ubi part rootfs
...... looooong list of following two lines
UBI error: ubi_io_read: error -74 while reading 512 bytes from PEB 1975:512, read 512 bytes
ECC: uncorrectable.

......then quite menay of following lines
ECC: uncorrectable.
ECC: uncorrectable.
ECC: uncorrectable.
ECC: uncorrectable.

...... then rest of messages
UBI error: ubi_io_read: error -74 while reading 129024 bytes from PEB 518:2048, read 129024 bytes
UBI warning: ubi_eba_copy_leb: error -74 while reading data from PEB 518
UBI error: wear_leveling_worker: error -74 while moving PEB 518 to PEB 1
UBI warning: ubi_ro_mode: switch to read-only mode
UBI error: do_work: work failed with error code -74
UBI: attached mtd1 to ubi0
UBI: MTD device name:            "mtd=7"
UBI: MTD device size:            248 MiB
UBI: number of good PEBs:        1980
UBI: number of bad PEBs:         8
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:             15
UBI: total number of reserved PEBs: 1965
UBI: number of PEBs reserved for bad PEB handling: 19
UBI: max/mean erase counter: 6/3
U-Boot#


======================================
BOOT => Linux

ubiattach -m t

=>
.... exhaustive list of following blocks:
[  184.135917] UBI warning: ubi_io_read: error -74 (ECC error) while reading 64 bytes from PEB 268:0, read only 64 bytes, retry
[  184.148291] uncorrectable error :
[  184.151767] UBI warning: ubi_io_read: error -74 (ECC error) while reading 64 bytes from PEB 268:0, read only 64 bytes, retry
[  184.163943] uncorrectable error :
[  184.167396] UBI warning: ubi_io_read: error -74 (ECC error) while reading 64 bytes from PEB 268:0, read only 64 bytes, retry
[  184.179564] uncorrectable error :
[  184.183016] UBI error: ubi_io_read: error -74 (ECC error) while reading 64 bytes from PEB 268:0, read 64 bytes
[  184.193837] [<c001051d>] (unwind_backtrace+0x1/0x8c) from [<c022ca67>] (ubi_io_read+0x14f/0x1ec)
[  184.203171] [<c022ca67>] (ubi_io_read+0x14f/0x1ec) from [<c022cc73>] (ubi_io_read_ec_hdr+0x47/0x12c)
[  184.212870] [<c022cc73>] (ubi_io_read_ec_hdr+0x47/0x12c) from [<c022fc3b>] (scan_peb.part.4+0x1b/0x408)
[  184.222843] [<c022fc3b>] (scan_peb.part.4+0x1b/0x408) from [<c0230095>] (scan_all+0x6d/0x73c)
[  184.231895] [<c0230095>] (scan_all+0x6d/0x73c) from [<c0230a45>] (ubi_attach+0x169/0x244)
[  184.240591] [<c0230a45>] (ubi_attach+0x169/0x244) from [<c0229373>] (ubi_attach_mtd_dev+0x4ff/0x980)
[  184.250291] [<c0229373>] (ubi_attach_mtd_dev+0x4ff/0x980) from [<c0229997>] (ctrl_cdev_ioctl+0x7f/0x104)
[  184.260357] [<c0229997>] (ctrl_cdev_ioctl+0x7f/0x104) from [<c009d6b1>] (vfs_ioctl+0x15/0x20)
[  184.269412] [<c009d6b1>] (vfs_ioctl+0x15/0x20) from [<c009de57>] (do_vfs_ioctl+0x3ad/0x3e2)
[  184.278281] [<c009de57>] (do_vfs_ioctl+0x3ad/0x3e2) from [<c009debd>] (sys_ioctl+0x31/0x4c)
[  184.287157] [<c009debd>] (sys_ioctl+0x31/0x4c) from [<c000c641>] (ret_fast_syscall+0x1/0x46)
[  184.296279] uncorrectable error :
[  184.299721] uncorrectable error : [  184.303366] UBI warning: ubi_io_read: error -74 (ECC error) while reading 512 bytes from PEB 268:512, read only 512 bytes, retry
[  184.315740] uncorrectable error :
[  184.319180] uncorrectable error : [  184.322821] UBI warning: ubi_io_read: error -74 (ECC error) while reading 512 bytes from PEB 268:512, read only 512 bytes, retry
[  184.335193] uncorrectable error :
[  184.338631] uncorrectable error : [  184.342272] UBI warning: ubi_io_read: error -74 (ECC error) while reading 512 bytes from PEB 268:512, read only 512 bytes, retry
[  184.354643] uncorrectable error :
[  184.358082] uncorrectable error : [  184.361723] UBI error: ubi_io_read: error -74 (ECC error) while reading 512 bytes from PEB 268:512, read 512 bytes
[  184.372704] [<c001051d>] (unwind_backtrace+0x1/0x8c) from [<c022ca67>] (ubi_io_read+0x14f/0x1ec)
[  184.382032] [<c022ca67>] (ubi_io_read+0x14f/0x1ec) from [<c022cda7>] (ubi_io_read_vid_hdr+0x4f/0x134)
[  184.391821] [<c022cda7>] (ubi_io_read_vid_hdr+0x4f/0x134) from [<c022fd29>] (scan_peb.part.4+0x109/0x408)
[  184.401973] [<c022fd29>] (scan_peb.part.4+0x109/0x408) from [<c0230095>] (scan_all+0x6d/0x73c)
[  184.411116] [<c0230095>] (scan_all+0x6d/0x73c) from [<c0230a45>] (ubi_attach+0x169/0x244)
[  184.419804] [<c0230a45>] (ubi_attach+0x169/0x244) from [<c0229373>] (ubi_attach_mtd_dev+0x4ff/0x980)
[  184.429503] [<c0229373>] (ubi_attach_mtd_dev+0x4ff/0x980) from [<c0229997>] (ctrl_cdev_ioctl+0x7f/0x104)
[  184.439565] [<c0229997>] (ctrl_cdev_ioctl+0x7f/0x104) from [<c009d6b1>] (vfs_ioctl+0x15/0x20)
[  184.448616] [<c009d6b1>] (vfs_ioctl+0x15/0x20) from [<c009de57>] (do_vfs_ioctl+0x3ad/0x3e2)
[  184.457487] [<c009de57>] (do_vfs_ioctl+0x3ad/0x3e2) from [<c009debd>] (sys_ioctl+0x31/0x4c)
[  184.466358] [<c009debd>] (sys_ioctl+0x31/0x4c) from [<c000c641>] (ret_fast_syscall+0x1/0x46)
[  184.494290] uncorrectable error :

I hope you can find solution for this problem.

Thanks,
Matti

  • Hi Matti,
     
    The Angstrom build is supported on the Beagleboard site: http://www.beagleboard.org/Community/Forums
  • Does it cover BeagleBone "variants", too? Beagle bone does not have NAND flash. BeagleBoneBlack does have eMMC flash, but that is quite dirrerent story.

  • Should in my opinion. There is a NAND cape for Beaglebone.
  • Hi Biser!

    It is VERY silent in beaglebone community with this issue. No responses on Angstrom side, too. However, I found this:

    http://e2e.ti.com/support/dsp/davinci_digital_media_processors/f/717/t/159068.aspx

    That has very similar problem. I did not find proper resolution for it. Is there any?

    I found some things slightly different in Linux:
    CCBYTES=52 and they are tail aligned at positions 12..63.

    U-boot side seem the same, so:
    CCBYTES=56 and they are mapped to 2..57.

    This worries me, because, it seems, that Kernel has changed this BCH operation and seems not to be compatible with u-boot that is most likely compatible with the older kernel. For instance that u-boot ecc layout has oobfree field that is not mapped in the beginning of OOB area.

    Note that this ECCBYTES difference seems to come from the fact that somewhere in Linux info->nand.ecc.bytes has been defined with value 13. Also there seems to be definition (in omap2.c) for steps variable:
    steps = mtd->writesize/info->nand.ecc.size. This is after all used for defining fnal ECCBYTES (=layout->eccbytes).

    This same is defined in on u-boot side for instance in am335x_evm.h as follows:
    #define CONFIG_SYS_NAND_ECCBYTES    14
    #define CONFIG_SYS_NAND_ECCSTEPS    4
    #define    CONFIG_SYS_NAND_ECCTOTAL    (CONFIG_SYS_NAND_ECCBYTES * \
                            CONFIG_SYS_NAND_ECCSTEPS)

    This gives CONFIG_SYS_NAND_ECCTOTAL=56
    This is also compatible with the set-ups found from omap_gpmc.h:
    #define GPMC_NAND_HW_BCH8_ECC_LAYOUT {\
        .eccbytes = 56,\
        .eccpos = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,\
                    16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,\
                    28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,\
                    40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,\
                    52, 53, 54, 55, 56, 57},\
        .oobfree = {\
            {.offset = 58,\
             .length = 6 } } \
    }
    That eccpos field is compatible with
    #define CONFIG_SYS_NAND_ECCPOS        { 2, 3, 4, 5, 6, 7, 8, 9, \
                         10, 11, 12, 13, 14, 15, 16, 17, \
                         18, 19, 20, 21, 22, 23, 24, 25, \
                         26, 27, 28, 29, 30, 31, 32, 33, \
                         34, 35, 36, 37, 38, 39, 40, 41, \
                         42, 43, 44, 45, 46, 47, 48, 49, \
                         50, 51, 52, 53, 54, 55, 56, 57, }
    also found from am335x_evm.h.

    There was one suggestion for patching two files. First one is clear to me, whereas the other one is not. Most likely that omap2.c is quite different than what I have in hands.

    On the other hand, that suggestion was not found functional.

    I really feel that this is TI responsibility to maintain this am335x_evm.h master copy and most likely also omap_gpmc.h considering the text I found from u-boot documentation that they are copied from from your's stuff..

    So, my question are:
    1) Is there any resolution for this issue?
    2) Have anyone managed to access ubifs both on u-boot and Linux without corrupting ubifs on the other side?
    3) What settings are needed to carry this out?
    4) Do you have compatible u-boot settings for Linux kernel 3.8.13?

    Regards,
    Matti

  • I found one notice from U-boot README.omap3 with following message:
    * CONFIG_SYS_NAND_ECCBYTES must be 13 for this BCH8 setup
    On the other hand they also claim that
     * CONFIG_SYS_NAND_ECCPOS (must be the same as .eccpos in
       GPMC_NAND_HW_BCH8_ECC_LAYOUT defined in
       arch/arm/include/asm/arch-omap3/omap_gpmc.h).

    This strikes a bit odd, as GPMC_NAND_HW_BCH8_ECC_LAYOUT seems to use 14 instead of 13 for CONFIG_SYS_NAND_ECCBYTES compatible size as
    .eccbytes = 56 = 14 * 4.

    -Matti




  • There was a mistake in my mail prior to previous mail.

    I was referring a wrong file in that mail. File README.omap3 refers to is:
    arch/arm/include/asm/arch-omap3/omap_gpmc.h
    Whereas file I had been quoting was:
    arch/arm/include/asm/arch-am33x/omap_gpmc.h

    However, there was one mistake also in that correct file.  Definition found in that file has wrong .eccbytes value.

    #define GPMC_NAND_HW_BCH8_ECC_LAYOUT {\
        .eccbytes = 56,\
        .eccpos = {12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,\

                23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,\
                37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,\
                51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63},\
        .oobfree = {\
            {.offset = 2,\
             .length = 10 } } \
    }
    Unfortunately fixing that to correct value 52 did not help either.

    -Matti

  • Hi,

    I have the same issue of mismatch in bch8.
    Did anyone resolve this issue ?

    Regards,
    Ran
  • I'm afraid this is coming far too late, but I have not had ubifs problems with newer u-boot versions since u-boot 2013.10. Current version is 2016.05. I found two issues with u-boot-ti-staging 2016.05. I used am335x-evm as u-boot base for my board. It turned out (after clearing my own mistakes) that there is one error in am335x-evm.h file that prevents am335x-evm board nand boot.

    There is BOOTENV_DEV_NAND macro (below) that produces wrong boot command symbol ( "bootcmd_nand").

    #define BOOTENV_DEV_NAND(devtypeu, devtypel, instance) \
        "bootcmd_" #devtypel "=" \
        "run nandboot\0"


    Correct nand boot command symbol should be "bootcmd_nand0". So, above macro should be modified for example as follows:

    #define BOOTENV_DEV_NAND(devtypeu, devtypel, instance) \
        "bootcmd_" #devtypel #instance "=" \
        "run nandboot\0"

    Another issue is that boot parameter this am335x-evm.h provides is not quite compatible with Linux side default ubiformat command (executed without switches).

    Original parameter below.

    "nandroot=ubi0:rootfs rw ubi.mtd=NAND.file-system,2048\0" \

    Parameter working with default ubiformat:

    "nandroot=ubi0:rootfs rw ubi.mtd=NAND.file-system\0" \

    Regards,

    Matti