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.

AM1808: ubiattach -> UBI error: ubi_io_write: error -5 while writing 512 bytes to PEB 4053:512, written 0 bytes



Hi all,

1) First of all, my system details:
HW: AM1808-EVM from LogicPD rev.A
sdk: 05.03.02.00
psp: 03.21.00.04
mtd-utils: 1.4.9

2) Kernel enabled/disabled support for UBIFS:
CONFIG_MTD_UBI=y
CONFIG_MTD_UBI_WL_THRESHOLD=4096
CONFIG_MTD_UBI_BEB_RESERVE=1
# CONFIG_MTD_UBI_GLUEBI is not set
# UBI debugging options
# CONFIG_MTD_UBI_DEBUG is not set
CONFIG_UBIFS_FS=y
# CONFIG_UBIFS_FS_XATTR is not set
# CONFIG_UBIFS_FS_ADVANCED_COMPR is not set
CONFIG_UBIFS_FS_LZO=y
CONFIG_UBIFS_FS_ZLIB=y
# CONFIG_UBIFS_FS_DEBUG is not set

3) Here are the steps I followed on the NFS-booted target in order to create the ubifs image from a rootfs directory
and write it to nand:

target$ mkfs.ubifs -r rootfs -m 2048 -e 129024 -c 4096 ubifs.img

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

target$ ubinize -o rootfs.ubifs.img -m 2048 -p 128KiB -s 512 ubinize.cfg

target$ ubiformat /dev/mtd4 -s 512 -f rootfs.ubifs.img
ubiformat: mtd4 (nand), size 531890176 bytes (507.2 MiB), 4058 eraseblocks of 131072 bytes (128.0 KiB), min. I/O size 2048                                                                           bytes
libscan: scanning eraseblock 4057 -- 100 % complete
ubiformat: 4051 eraseblocks have valid erase counter, mean value is 0
ubiformat: 7 bad eraseblocks found, numbers: 1531, 2871, 3022, 4054, 4055, 4056, 4057
ubiformat: flashing eraseblock 149 -- 100 % complete
ubiformat: formatting eraseblock 4057 -- 100 % complete

target$ ubiattach /dev/ubi_ctrl -m 4
UBI: attaching mtd4 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: max. sequence number:       0
UBI error: ubi_io_write: error -5 while writing 512 bytes to PEB 4053:512, written 0 bytes
UBI warning: ubi_eba_write_leb: failed to write VID header to LEB 2147479551:0, PEB 4053
UBI: try another PEB
UBI error: ubi_io_write: error -5 while writing 512 bytes to PEB 4052:512, written 0 bytes
UBI warning: ubi_eba_write_leb: failed to write VID header to LEB 2147479551:0, PEB 4052
UBI: try another PEB
UBI error: ubi_io_write: error -5 while writing 512 bytes to PEB 4051:512, written 0 bytes
UBI warning: ubi_eba_write_leb: failed to write VID header to LEB 2147479551:0, PEB 4051
UBI: try another PEB
UBI error: ubi_io_write: error -5 while writing 512 bytes to PEB 4050:512, written 0 bytes
UBI warning: ubi_eba_write_leb: failed to write VID header to LEB 2147479551:0, PEB 4050
UBI warning: ubi_ro_mode: switch to read-only mode
UBI error: autoresize: cannot auto-resize volume 0
ubiattach: error!: cannot attach mtd4
           error 30 (Read-only file system)


Please, can anyone help me ?

  • Hi,

    For UBIFS image creation I followed this procedure:

    host$ mkfs.ubifs –r rootfs –m 2048 –e 126976 –c 950 -o rootfs.ubifs
    host$ ubinize -o rootfs.ubi -m 2048 -p 128KiB -s 2048 ubinize.cfg

    ubinize.cfg file content:
    [ubifs]
    mode=ubi
    image=rootfs.ubifs
    vol_id=0
    vol_size=256MiB
    vol_type=dynamic
    vol_name=rootfs
    vol_flags=autoresize

    With these images I had some progress in UBI attach/detach and UBIFS mount/unmount
    from linux.
    Now the main problem is to write the correct image to NAND from within u-boot.
    Can anyone tell me the basic steps involved in this process ?
    This is what I'm doing:

    2) For NAND flashing UBI image I run this command:
      tftp c2000000 rootfs.ubi; nand erase 4c0000 1fb40000; nand write.trimffs c2000000 rootfs ${filesize};

    3) For booting I use:
       bootargs: noinitrd root=ubi0:rootfs rw rootfstype=ubifs ubi.mtd=4 rootwait=1 console=ttyS2,115200n8 mtdparts=davinci_nand.1:128k(u-boot_env),128k(ubl),512k(u-boot),4M(kernel),-(rootfs) mem=128M
       bootcmd: nand read c0700000 kernel 400000; bootm c0700000

    However during boot I have:
    ...
    5 cmdlinepart partitions found on MTD device davinci_nand.1
    Creating 5 MTD partitions on "davinci_nand.1":
    0x000000000000-0x000000020000 : "u-boot_env"
    0x000000020000-0x000000040000 : "ubl"
    0x000000040000-0x0000000c0000 : "u-boot"
    0x0000000c0000-0x0000004c0000 : "kernel"
    0x0000004c0000-0x000020000000 : "rootfs"
    davinci_nand davinci_nand.1: controller rev. 2.5
    UBI: attaching mtd4 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
    ...

    What's wrong in this sequence ?

    Regards,
    Gabriele

  • Let's add -O 512 to ubinize process
    At boot:
    ...
    Creating 5 MTD partitions on "davinci_nand.1":
    0x000000000000-0x000000020000 : "u-boot_env"
    0x000000020000-0x000000040000 : "ubl"
    0x000000040000-0x0000000c0000 : "u-boot"
    0x0000000c0000-0x0000004c0000 : "kernel"
    0x0000004c0000-0x000020000000 : "rootfs"
    davinci_nand davinci_nand.1: controller rev. 2.5
    UBI: attaching mtd4 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: ubi_io_read: error -74 (ECC error) while reading 64 bytes from PEB 4052:0, read 64 bytes
    Backtrace:
    [<c00344e4>] (dump_backtrace+0x0/0x110) from [<c036b2a0>] (dump_stack+0x18/0x1c)
     r6:c78ee000 r5:00000040 r4:ffffffb6 r3:00000002
    ...

    help.

  • With a little help from myself, everithings is working good!
    Thanks a lot, Gabriele

  • Hi Filosofi,

    I 'm also facing same issue,

    but still i can't able to solve it.

    So what i need to do , get the file system?

    Regards,

    santosh vastrad

  • Hi Vastrad.
    I just can tell you what made things good in my case.
    Let's suppose your filesystem is the file <rootfs> in your host.

    1. Create the ubifs image

    host $ mkfs.ubifs –r <rootfs> –m 2048 –e 126976 –c 947 -F –x lzo -o rootfs.ubifs

    2. Create a UBI ini-file ubinize.cfg (the volume's descriptor) with the following content:

    host $ cat ubinize.cfg
    [ubifs]
    mode=ubi
    image=rootfs.ubifs
    vol_id=0
    vol_size=120246272
    vol_type=dynamic
    vol_name=rootfs
    vol_flags=autoresize

    3. Create the UBI image

    host $ ubinize -o rootfs.ubi -m 2048 -p 128KiB -s 2048 –O 2048 ubinize.cfg

    The UBI image (rootfs.ubi) is now ready to be copyed into the proper MTD partition.
    You can do it either directly from u-boot or from linux (by using an intermediate filesystem like NFS or ram-disk)

    I hope this helps

    Gabriele

  • Thanks for the reply:

    I will try out what you sent for creating an ubi image!

    Before that, i want to clarify one more thing, that's

    Is there any relation in creating an ubi image with nand flash size we are using?

    Because,

    1st nand 512MB for booting ,

    2nd nand 2GiB for storage purpose.

    If i create the image  and flashed in nand,

    it should mount form both nand flashes,

    I want clearification please?

    Regards,

    santosh vastrad

  • Hi,

    In order to create the UBI image you have to know the following flash parameters

    • MTD partition size
    • Physical Erase Block (PEB) size
    • Minimum I/O unit size
    • Sub-page size

    As you can see the total capacity doesn't matter.
    At boot time the kernel can mount the UBIFS image as a root filesystem from whatever nand flash you desire.
    The important thing is that the kernel knows which is the nand and which is the
    specific MTD partition containing the UBI image.

    In my case the nand is a 512MB 8-bit NAND flash (4096 blocks, 128KB each).
    In my case the MTD partition for the NAND is not statically defined in the kernel board source but it is
    defined in u-boot and passed to the kernel at boot time via bootargs command line.
    During the kernel boot is it possible to see this table via the console:

    Creating 8 MTD partitions on "davinci_nand.1":
    0x000000000000-0x000000020000 : "u-boot_env"
    0x000000020000-0x000000040000 : "ubl"
    0x000000040000-0x000000080000 : "spare"
    0x000000080000-0x000000100000 : "u-boot"
    0x000000100000-0x000000500000 : "kernel"
    0x000000500000-0x000007d00000 : "rootfs"
    0x000007d00000-0x00000f500000 : "rootfs_a"
    0x00000f500000-0x000020000000 : "rest"


    By the way, it is worth to mention the kernel configuration options I had to enable:

    a. Select
    FileSystems->Miscellaneous Fileystems->UBIFS file system support
    DeviceDrivers->MTD Support->Enable UBI
    DeviceDrivers->MTD Support->NAND Device Support->Support NAND on DaVinci SoC

    b. Deselect
    DeviceDrivers->MTD Support->NAND Device Support->Verify NAND page writes

    Finally, you can fin more info on UBI and UBIFS into the attached files.

    I hope this helps,

    Gabriele

    ubifs.zip