title: UBI error: ubi_io_read: error -74 (ECC error)
body: <p>I'm struggling with writing the Linux root file system to a NAND device (MT29F2G08ABAEAH4-IT:E).</p>
  
  <p>I have a UBI image created by Yocto as follows:</p>
  
  <pre><code>mkfs.ubifs -r /path/to/rootfs -o /path/to/output/rootfs.ubifs -m 2048 -e 129024 -c 1600 -F
  ubinize -o /path/to/output/rootfs.ubi -m 2048 -p 128KiB -s 512 ubinize.cfg
  </code></pre>
  
  <p>ubinize.cfg:</p>
  
  <pre><code>[ubifs]
  mode=ubi
  image=/path/to/output/rootfs.ubifs
  vol_id=0
  vol_type=dynamic
  vol_name=ddcu-rootfs
  vol_flags=autoresize
  </code></pre>
  
  <p>I'm able to successfully write the filesystem with the following commands from a "manufacturing" Linux:</p>
  
  <pre><code>mount /dev/mmcblk0p3 /mnt/data/
  ubiformat /dev/mtd8 -f /mnt/data/rootfs.ubi
  ubiattach /dev/ubi_ctrl -m 8
  mount -t ubifs ubi0_0 /mnt/rfs
  </code></pre>
  
  <p>This solution works but is tedious, as I first need to boot the temporary "manufacturing" Linux to prepare RFS for the production Linux. So I want to flash it directly from u-boot. I've read multiple sources (e.g. <a href="http://www.linux-mtd.infradead.org/faq/ubifs.html" rel="nofollow">http://www.linux-mtd.infradead.org/faq/ubifs.html</a>) and notes (e.g. <a href="http://lists.denx.de/pipermail/u-boot/2011-September/102740.html" rel="nofollow">http://lists.denx.de/pipermail/u-boot/2011-September/102740.html</a>), yet I must still do something wrong or there must be a bug somewhere.</p>
  
  <h2>1. nand write</h2>
  
  <p>I tried to use the <code>nand write</code> command in u-boot <em>2011.12</em> and <em>2016.01</em>:</p>
  
  <pre><code>nand scrub.part -y mtd_rootfs
  fatload mmc 0:3 ${loadaddr} rootfs.ubi
  nand write ${loadaddr} mtd_rootfs ${filesize}
  </code></pre>
  
  <p>Booting Linux now leads to</p>
  
  <pre><code>UBI: attaching mtd8 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
  uncorrectable error : 
  uncorrectable error : 
  uncorrectable error : 
  uncorrectable error : 
  UBI error: ubi_io_read: error -74 (ECC error) while reading 64 bytes from PEB 0:0, read 64 bytes
  uncorrectable error : 
  uncorrectable error : 
  uncorrectable error : 
  uncorrectable error : 
  uncorrectable error : 
  uncorrectable error : 
  uncorrectable error : 
  uncorrectable error : 
  UBI error: ubi_io_read: error -74 (ECC error) while reading 512 bytes from PEB 0:512, read 512 bytes
  uncorrectable error : 
  uncorrectable error : 
  </code></pre>
  
  <h2>2. ubi</h2>
  
  <p>Another attend was using the <em>ubi</em> u-boot 2016.01 commands:</p>
  
  <pre><code>nand scrub.part -y mtd_rootfs
  ext4load mmc 0:2 ${loadaddr} rootfs.ubi
  ubi part mtd_rootfs
  ubi create ddcu-rootfs
  ubi write ${loadaddr} my-rootfs ${filesize}
  </code></pre>
  
  <p>Trying to mount the volume in u-boot by <code>ubifsmount my-rootfs</code> fails:</p>
  
  <pre><code>Error reading superblock on volume 'my-rootfs' errno=-22!
  </code></pre>
  
  <p>Trying to boot Linux leads to:</p>
  
  <pre><code>UBI: attaching mtd8 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
  uncorrectable error : 
  uncorrectable error : 
  uncorrectable error : 
  uncorrectable error : 
  UBI error: ubi_io_read: error -74 (ECC error) while reading 64 bytes from PEB 0:0, read 64 bytes
  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 mtd8
  </code></pre>
  
  <hr>
  
  <p>Of course I tried more variants, but it always ends up with the <strong>error -74</strong>. Can anyone see what I'm doing wrong, or share their working solution, please?</p>