Don't erase the flash. That would reset the counter and cause uaage of the bad block again.
You can see UBI as a protective logical layer smoothing over the HW errors.
I created this part of the add-on to help people with bad flash memories.
I'm no way an expert in the area, so I advice you to google and ask around.
Here is some basic info though:
MTD (Memory Technology Devices) are NAND/NOR-based flash memory chips
used for storing non-volatile data like boot images and configurations.
MTD devices are for data storage, they differ from hard disks and RAM
in several aspects.
The biggest difference is that while hard disk sectors are rewritable,
MTD device sectors must be erased before rewriting —
which is why they are more commonly called erase-blocks.
Second, hard disk sectors can be rewritten several times without wearing out the hardware,
but MTD device sectors have a limited life and are not usable after about
1000-100,000 erase operations. (1000 for MLC NAND - 100000 for NOR, SLC NAND )
The worn out erase-blocks are called bad blocks and the software must
take care not to use such blocks.
There is an extremely simple FTL layer in Linux MTD subsystem - mtdblock.
It emulates block devices over MTD devices
UBI is a volume management system for raw flash devices which manages multiple
logical volumes on a single physical flash device and spreads the I/O load
(i.e, wear-leveling) across whole flash chip.
https://bootlin.com/blog/managing-flash-storage-with-linux/
http://www.linux-mtd.infradead.org/faq/general.html
http://www.linux-mtd.infradead.org/doc/ubi.html#L_usptools
https://opensourceforu.com/2012/01/working-with-mtd-devices/
https://openwrt.org/docs/techref/flash.layout