How to erase flash and preserve erase counters?
Use the ubiformat utility. Example: $ ubiformat /dev/mtd0 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 104 ubiformat: bad eraseblocks: 13, 666 ubiformat: formatting eraseblock 4095 — 100 % complete Note, this section has some hints for those who implement an UBI flasher program.