How to flash UBI images and preserve erase counters?
Use the ubiformat utility. Example: $ ubiformat /dev/mtd0 -f ubi.img ubiformat: mtd0 (NAND), size 536870912 bytes (512.0 MiB), 131072 eraseblocks of 131072 bytes (128.0 KiB), min. I/O size 2048 bytes libscan: scanning eraseblock 4095 — 100 % complete ubiformat: 4094 eraseblocks have valid erase counter, mean value is 105 ubiformat: bad eraseblocks: 13, 666 ubiformat: flashing eraseblock 50 — 100 % complete ubiformat: formatting eraseblock 4095 — 100 % complete Note, this has some hints for those who implement a flasher program.