BPI-R3 Mini NAND Restore

Are there any chance to restore original firmware to NAND? For the moment I do have working system on emmc and heve issues with OS on NAND.

# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00200000 00020000 "bl2"
mtd1: 07e00000 00020000 "ubi"
# cat /proc/partitions
major minor  #blocks  name
  31        0       2048 mtdblock0
  31        1     129024 mtdblock1
 179        0    7634944 mmcblk0
 179        1        512 mmcblk0p1
 179        2       2048 mmcblk0p2
 179        3       4096 mmcblk0p3
 179        4      32768 mmcblk0p4
 179        5     307200 mmcblk0p5
 259        0       4079 mmcblk0p128
 179        8       4096 mmcblk0boot0
 179       16       4096 mmcblk0boot1
 259        1       8444 fit0
 259        2     291252 fitrw
 254        0      44764 ubiblock0_1

Official manual is telling us that we can use single image to restore NANS content

mtd erase /dev/mtd0
dd if=mtk-bpi-r3mini-NAND-20230719-single-image.bin of=/dev/mtdblock0

but the problem is that /dev/mtdblock0 is RO. Only using USB2TTL nand cam be resorted?

1 Like

Why not install up2date openwrt on nand?

What is that? Im not a big expert in OpenWrt and have a huge gap in knowledge … I just need somehow to have working OS that can start from Nand.

I thought emmc uboot has nand install commands,but it does not seems to

But you can try to do like it is defined in nand environment

https://git.openwrt.org/?p=openwrt/openwrt.git;a=blob;f=package/boot/uboot-mediatek/patches/442-add-bpi-r3-mini.patch;h=5409f7fa0de71ed406727c1d53cc5a1e733afdeb;hb=HEAD#l456

I’m no expert in openwrt too…but if there is a newer system i do not want to install an older one :stuck_out_tongue:

Were able to reinstall to NAND. Here is what I did to do that

#
insmod mtd-rw.ko i_want_a_brick=1

#
mtd erase bl2 && mtd write openwrt-mediatek-filogic-bananapi_bpi-r3-mini-snand-preloader.bin bl2

#
umount /mnt/ubi0* 2> /dev/null
ubidetach -p /dev/mtd1 2> /dev/null
mtd erase ubi

#
ubiformat -y /dev/mtd1
ubiattach -p /dev/mtd1

#
ubimkvol /dev/ubi0 -n 0 -N ubootenv -s 128KiB
ubimkvol /dev/ubi0 -n 1 -N ubootenv2 -s 128KiB

# Install uboot
volsize=$(wc -c < openwrt-mediatek-filogic-bananapi_bpi-r3-mini-snand-bl31-uboot.fip)
ubimkvol /dev/ubi0 -N fip -n 2 -s $volsize -t static && \
ubiupdatevol /dev/ubi0_2 openwrt-mediatek-filogic-bananapi_bpi-r3-mini-snand-bl31-uboot.fip

# Install en8811h-fw
cat /lib/firmware/airoha/EthMD32.dm.bin /lib/firmware/airoha/EthMD32.DSP.bin > ./en8811h-fw.bin
volsize=$(wc -c < openwrt-mediatek-filogic-bananapi_bpi-r3-mini-snand-bl31-uboot.fip)
ubimkvol /dev/ubi0 -N en8811h-fw -n 3 -s $volsize -t static && \
ubiupdatevol /dev/ubi0_3 /tmp/en8811h-fw.bin

# Install recovery
volsize=$(wc -c < openwrt-mediatek-filogic-bananapi_bpi-r3-mini-initramfs-recovery.itb)
ubimkvol /dev/ubi0 -n 4 -N recovery -s $volsize && \
ubiupdatevol /dev/ubi0_4 openwrt-mediatek-filogic-bananapi_bpi-r3-mini-initramfs-recovery.itb

# Install system
volsize=$(wc -c < openwrt-mediatek-filogic-bananapi_bpi-r3-mini-squashfs-sysupgrade.itb)
ubimkvol /dev/ubi0 -n 5 -N fit -s $volsize && \
ubiupdatevol /dev/ubi0_5 openwrt-mediatek-filogic-bananapi_bpi-r3-mini-squashfs-sysupgrade.itb

# Create rootfs_data partition
ubimkvol /dev/ubi0 -n 6 -N rootfs_data -m
1 Like

Have you used UART-USB in your solution to this problem?

Nope. I did this from emmc OS as it was alive

Guys, where do you get initramfs ? I downloaded files from OpenWRT’s selector page, but there is no initramfs image to download.

Have you tried compiling yourself? i guess it is created but not uploaded to firmware-selector.

You mean have I tried to build it using firmware-selector? Yes, but there was no initramfs :frowning:

I mean building openwrt from source,not the firmware-selector…it seems not getting the file you want from build-pipeline

1 Like

The error that I got when I had to go searching was:

[93705.974989] block ubiblock0_5: created from ubi0:5(fit)

F0: 102B 0000
FA: 1040 0000
FA: 1040 0000 [0200]
F9: 0000 0000
V0: 0000 0000 [0001]
00: 0000 0000
BP: 2400 0041 [0000]
G0: 1190 0000
EC: 0000 0000 [1000]
T0: 0000 021E [010F]
Jump to BL

NOTICE:  BL2: v2.6(release):
NOTICE:  BL2: Built : 20:18:14, May  7 2023
NOTICE:  WDT: disabled
NOTICE:  CPU: MT7986 (2000MHz)
NOTICE:  EMI: Using DDR4 settings
NOTICE:  EMI: Detected DRAM size: 2048MB
NOTICE:  EMI: complex R/W mem test passed
NOTICE:  SPI_NAND parses attributes from parameter page.
NOTICE:  SPI_NAND Detected ID 0xef
NOTICE:  Page size 2048, Block size 131072, size 134217728
NOTICE:  Initializing NMBM ...
NOTICE:  NMBM management region starts at block 960 [0x07800000]
NOTICE:  NMBM has been initialized in read-only mode
ERROR:   BL2: Failed to load image id 3 (-2)

Wrong partition layout, /dev/mmcblk0p4 is too small.

I had missed the MTD not being writable when running the install commands I found on the SNAND openwrt wiki instructions [OpenWrt Wiki] Sinovoip BananaPi BPi-R3 mini

Here’s the steps for alpine openwrt and also some added checks


# 0. Alpine install the kernel module mtd-rw
apk add kmod-mtd-rw
insmod mtd-rw.ko i_want_a_brick=1

# 1. MTD erase and write preloader to bl2
mtd erase bl2 && mtd write openwrt-mediatek-filogic-bananapi_bpi-r3-mini-snand-preloader.bin bl2

# 2. Clean and prepare UBI
umount /mnt/ubi0* 2> /dev/null
ubidetach -p /dev/mtd1 2> /dev/null
mtd erase ubi
ubiformat -y /dev/mtd1
ubiattach -p /dev/mtd1

# 3. Create volumes in order:
ubimkvol /dev/ubi0 -n 0 -N ubootenv -s 128KiB     # uboot env
ubimkvol /dev/ubi0 -n 1 -N ubootenv2 -s 128KiB    # uboot env backup

# 4. Install uboot
volsize=$(wc -c < openwrt-mediatek-filogic-bananapi_bpi-r3-mini-snand-bl31-uboot.fip)
ubimkvol /dev/ubi0 -N fip -n 2 -s $volsize -t static
ubiupdatevol /dev/ubi0_2 openwrt-mediatek-filogic-bananapi_bpi-r3-mini-snand-bl31-uboot.fip

# 5. Install en8811h firmware
cat /lib/firmware/airoha/EthMD32.dm.bin /lib/firmware/airoha/EthMD32.DSP.bin > ./en8811h-fw.bin
ubimkvol /dev/ubi0 -N en8811h-fw -n 3 -s $volsize -t static
ubiupdatevol /dev/ubi0_3 /tmp/en8811h-fw.bin

# 6. Install recovery
volsize=$(wc -c < openwrt-mediatek-filogic-bananapi_bpi-r3-mini-initramfs-recovery.itb)
ubimkvol /dev/ubi0 -n 4 -N recovery -s $volsize
ubiupdatevol /dev/ubi0_4 openwrt-mediatek-filogic-bananapi_bpi-r3-mini-initramfs-recovery.itb

# 7. Install system
volsize=$(wc -c < openwrt-mediatek-filogic-bananapi_bpi-r3-mini-squashfs-sysupgrade.itb)
ubimkvol /dev/ubi0 -n 5 -N fit -s $volsize
ubiupdatevol /dev/ubi0_5 openwrt-mediatek-filogic-bananapi_bpi-r3-mini-squashfs-sysupgrade.itb

# 8. Create rootfs_data partition
ubimkvol /dev/ubi0 -n 6 -N rootfs_data -m

# 9. Check overall UBI info
ubinfo /dev/ubi0

# 10. List all volumes
ubinfo -a

# 11. Check each volume specifically
for i in 0 1 2 3 4 5 6; do
    echo "=== Checking volume $i ==="
    ubinfo /dev/ubi0_$i
done