Thank you, will try that as the second option, right now I think I succeeded marking bad block, works so far, let's see for how long. I took most of the info from here: https://stackoverflow.com/questions/58083109/u-boot-nand-markbad-has-no-effect
and my flash chip datasheet: https://datasheet.lcsc.com/lcsc/2105241807_GigaDevice-Semicon-Beijing-GD5F1GQ5UEYIGR_C2829047.pdf
I learned that bad block (or better to say page?) marker is stored in the first byte (or 2 bytes?) of OOB area following each NAND page. Page size for my flash chip is 2048 bytes, OOB size is 112 bytes. If the marker is 0xFF it means the page is good, 0x00 - the page is bad.
My version of UBoot does not mark bad blocks (even though it says it does), so I marked it manually with UBoot low-level nand read/write functions:
nand read.raw 0x41000000 0x17C0000 1
0x41000000 is the address of RAM area that seems to be unused, 0x17C0000 is the address of the bad page, 1 is number of pages to read.
Show the page contents:
md 0x41000000 0x21C
0x21C = (2048+112)/4 is the number of 4-byte words to display
OOB starts at 0x41000800, the first byte shows 0xFF, I need to change it to 0x00:
mm 0x41000800
, type 0
, Enter, 'q', Enter
write modified page back to flash:
nand write.raw 0x41000000 0x17C0000 1
Then I repeated first two commands (nand read.raw and md) to verify that address 0x17C0800 actually changed to 0x00000000, and verified again with
MT7622> nand bad
Device 0 bad blocks:
Bad block detected at 0xec00, oob_buf[0] is 0x0
Bad block detected at 0xec00, oob_buf[0] is 0x0
I have yet to understand the meaning of address 0xec00 and how it is related to my address 0x17C0000 and why it shows this messages twice, but I'm quite sure it refers to the right NAND page.
The next thing I learned is that preserving bad page mark is a challenge. Every time stock firmware or openwrt firmware is installed, it erases flash along with OOB data and the mark is gone. So I repeated the procedure right after the first boot of the openwrt firmware, rebooted several times - and the bad page is still there!
Here is how to confirm it from within openwrt:
root@OpenWrt:/# dmesg | grep PEB
[ 2.163126] ubi0: PEB size: 131072 bytes (128 KiB), LEB size: 126976 bytes
[ 2.183743] ubi0: good PEBs: 887, bad PEBs: 1, corrupted PEBs: 0
[ 2.206097] ubi0: available PEBs: 0, total reserved PEBs: 887, PEBs reserved for bad PEB handling: 18
or with nand-utils:
root@OpenWrt:/# nanddump /dev/mtd9
ECC failed: 0
ECC corrected: 0
Number of bad blocks: 1
Number of bbt blocks: 0
Now let's see if this works in the long run.