[BPI-R64] [BPI-R3] [BPI-R4] Restore bad nand

One thing I’ve added to my bpir-toolbox is this:

#!/bin/bash

[[ "$(tr -d '\0' 2>/dev/null </proc/device-tree/compatible)" != "bananapi,"* ]] && exit 1
ubinr=$(cat /proc/mtd | grep '"ubi"' | cut -d':' -f1 | tr -d [:alpha:])
ubidetach -p /dev/mtd${ubinr} 2>/dev/null
echo Y >/sys/kernel/debug/mtd/expert_analysis_mode
for i in $(cat /proc/mtd | tail -n+2 | cut -d' ' -f1 | tr -d ':'); do
  flash_erase --noskipbad "/dev/$i" 0 0
done
echo N >/sys/kernel/debug/mtd/expert_analysis_mode

It erases all nand blocks, even the ones that are marked bad. Results in all blocks erased and not marked as bad.

This has saved me several times, when fidling with settings, drivers, etc