Why does ubiattach on a freshly formatted device fail with “Invalid argument”?
On NAND devices that support sub-page accesses, ubiformat may choose a different location for the VID header to the kernel UBI driver This can result in the following error when attaching to a UBI device: $ ubiformat /dev/mtd0 ubiformat: mtd0 (NAND), size 260046848 bytes (248.0 MiB), 131072 eraseblocks of 131072 bytes (128.0 KiB), min. I/O size 2048 bytes […] $ ubiattach /dev/ubi_ctrl -m 0 ubiattach: error!: cannot attach mtd0 error 22 (Invalid argument) and in dmesg you will see: 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 This happens because ubiformat assumes the flash does not support sub-pages, because the kernel does not expose sub-page information to user-space (which should be fixed when sysfs support is added to MTD). However, the kernel UBI driver assumes sub-pages are supported and sub-page size is 512 bytes in our example. To fix this, you should o