[BPI-R4] Boot from NAND fails

I also encountered this problem。I can’t find a solution

[    4.173195] Rebooting in 1 seconds..

F0: 102B 0000
FA: 1042 0000
FA: 1042 0000 [0200]
F9: 0000 0000
V0: 0000 0000 [0001]
00: 0000 0000
BP: 0600 0041 [0000]
G0: 1190 0000
EC: 0000 0000 [1000]
MK: 0000 0000 [0000]
T0: 0000 01A0 [0101]
Jump to BL

NOTICE:  BL2: v2.9(release):
NOTICE:  BL2: Built : 18:12:03, Oct 13 2023
NOTICE:  WDT: [40000000] Software reset (reboot)
NOTICE:  CPU: MT7988
NOTICE:  EMI: Using DDR unknown settings
NOTICE:  EMI: Detected DRAM size: 4096 MB
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:  BL2: Booting BL31
NOTICE:  BL31: v2.9(release):
NOTICE:  BL31: Built : 18:12:07, Oct 13 2023


U-Boot 2023.10-rc4 (Oct 13 2023 - 18:09:57 +0800)

CPU:   MediaTek MT7988
Model: mt7988-rfb
       (mediatek,mt7988-spim-nand-rfb)
DRAM:  4 GiB
Core:  43 devices, 12 uclasses, devicetree: separate

Initializing NMBM ...
spi-nand: spi_nand spi_nand@0: Winbond SPI NAND was found.
spi-nand: spi_nand spi_nand@0: 128 MiB, block size: 128 KiB, page size: 2048, OOB size: 64
Could not find a valid device for nmbm0
Signature found at block 1023 [0x07fe0000]
First info table with writecount 2 found in block 960
Second info table with writecount 2 found in block 963
NMBM has been successfully attached 

Loading Environment from MTD... *** Warning - bad CRC, using default environment

In:    serial@11000000
Out:   serial@11000000
Err:   serial@11000000
Net:   
Warning: ethernet@15100000 (eth0) using random MAC address - 02:a6:af:0c:d9:0f
eth0: ethernet@15100000


  *** U-Boot Boot Menu ***

      1. Startup system (Default)
      2. Upgrade firmware
      3. Upgrade ATF BL2
      4. Upgrade ATF FIP
      5.   Upgrade ATF BL31 only
      6.   Upgrade bootloader only
      7. Upgrade single image
      8. Load image
      9. Start Web failsafe
      0. U-Boot console


  Press UP/DOWN to move, ENTER to select, ESC to quit
ubi0: attaching mtd6
ubi0: scanning is finished
ubi0: attached mtd6 (name "ubi", size 112 MiB)
ubi0: PEB size: 131072 bytes (128 KiB), LEB size: 126976 bytes
ubi0: min./max. I/O unit sizes: 2048/2048, sub-page size 2048
ubi0: VID header offset: 2048 (aligned 2048), data offset: 4096
ubi0: good PEBs: 900, bad PEBs: 0, corrupted PEBs: 0
ubi0: user volume: 3, internal volumes: 1, max. volumes count: 128
ubi0: max/mean erase counter: 1/0, WL threshold: 4096, image sequence number: 1697192243
ubi0: available PEBs: 0, total reserved PEBs: 900, PEBs reserved for bad PEB handling: 19
No size specified -> Using max size (4190208)
Read 4190208 bytes from volume kernel to 0000000046000000
## Loading kernel from FIT Image at 46000000 ...
   Using 'config-1' configuration
   Trying 'kernel-1' kernel subimage
     Description:  ARM64 OpenWrt Linux-5.4.246
     Type:         Kernel Image
     Compression:  lzma compressed
     Data Start:   0x460000e8
     Data Size:    4060807 Bytes = 3.9 MiB
     Architecture: AArch64
     OS:           Linux
     Load Address: 0x48080000
     Entry Point:  0x48080000
     Hash algo:    crc32
     Hash value:   cacd2182
     Hash algo:    sha1
     Hash value:   8cb587f5cb585cabfca1142602360b63aff9440f
   Verifying Hash Integrity ... crc32+ sha1+ OK
## Loading fdt from FIT Image at 46000000 ...
   Using 'config-1' configuration
   Trying 'fdt-1' fdt subimage
     Description:  ARM64 OpenWrt BPI-R4-NAND device tree blob
     Type:         Flat Device Tree
     Compression:  uncompressed
     Data Start:   0x463df8ac
     Data Size:    34547 Bytes = 33.7 KiB
     Architecture: AArch64
     Hash algo:    crc32
     Hash value:   dab10d5e
     Hash algo:    sha1
     Hash value:   ac75d9bde8766c8cfbecee360a488f7bd89b5108
   Verifying Hash Integrity ... crc32+ sha1+ OK
   Booting using the fdt blob at 0x463df8ac
Working FDT set to 463df8ac
   Uncompressing Kernel Image
   Loading Device Tree to 00000000ff7ec000, end 00000000ff7f76f2 ... OK
Working FDT set to ff7ec000
Add 'ramoops@42ff0000' node failed: FDT_ERR_EXISTS

Starting kernel ...

[    0.000000] Booting Linux on physical CPU 0x0000000000 [0x411fd090]
[    0.000000] Linux version 5.4.246 ([email protected]) (gcc version 8.4.0 (OpenWrt GCC 8.4.0 unknown)) #0 SMP Fri Oct 13 10:17:23 2023
[    0.000000] Machine model: Bananapi BPI-R4
[    0.000000] earlycon: uart8250 at MMIO32 0x0000000011000000 (options '')
[    0.000000] printk: bootconsole [uart8250] enabled
[    0.000000] On node 0 totalpages: 1045952
[    0.000000]   DMA32 zone: 12288 pages used for memmap
[    0.000000]   DMA32 zone: 0 pages reserved
[    0.000000]   DMA32 zone: 783808 pages, LIFO batch:63
[    0.000000]   Normal zone: 4096 pages used for memmap
[    0.000000]   Normal zone: 262144 pages, LIFO batch:63
[    0.000000] psci: probing for conduit method from DT.
[    0.000000] psci: PSCIv1.1 detected in firmware.
[    0.000000] psci: Using standard PSCI v0.2 function IDs
[    0.000000] psci: MIGRATE_INFO_TYPE not supported.

When I erase the mtd, there are some bad blocks

root@OpenWrt:/# mtd erase /dev/mtd0
Unlocking /dev/mtd0 ...
Erasing /dev/mtd0 ...

Skipping bad block at 0x3260000   
Skipping bad block at 0x3280000   
Skipping bad block at 0x32a0000   root@OpenWrt:/# 

Even if I burn the image from USB flash drive to NAND again, it still cannot solve the problem

I have given up on NAND for now. I even exchanged my BPI-R4 for a new one because of the bad block and the problems that came with it. Now I have two bad blocks on the new board.

Although I still don’t understand why the problems occur, because the bad blocks a after the end of the downloadable NAND image from Sinovoip.

You could try to reduce spi speed on the controller for nand in devicetree…maybe different chips are used and not all support max speed of controller

I don’t know how to do that. Is it possible to extract the infomation for a compiled (or booted) kernel?

After flashing the NAND image from Sinovoip via a booted OpenWRT-image from Sinovoip from SD card, the NAND works fine. So both of these kernels can handle the NAND memory without any problems.

It’s just when booting the self compiled kernel for the Debian image that it messes with the NAND flash and makes it unbootable. So this kernel must do something different. Either because it has no UBI module compiled in (OpenWRT) or the NAND is in use and Linux does not try to “fix” it because it is busy. Or it really is a speed issue, but I think it’s weird that it’s so repeatable. But who knows.

Afaik SinoVoip image uses downstream/proprietary NMBM from MediaTek, and their bootloader and ARM TrustedFrimware-A will also expect that. If you use vanilla (OpenWrt or Debian or anything built on upstream Linux and not downstream MediaTek SDK) you will also need to replace TF-A and U-Boot with vanilla builds without NMBM (and use UBI instead).

I use ubuntu image with new loader which can do recovery for NAND But still not help. It seems the bad block issue

'spi-nand0' is now active device
* spi-nand0
  - device: spi_nand@0
  - parent: spi@1100a000
  - driver: spi_nand
  - type: NAND flash
  - block size:        0x20000 bytes
  - page size:         0x800 bytes
  - OOB size:          64 bytes
  - OOB available:     24 bytes
  - 0x000000000000-0x000008000000 : "spi-nand0"
	  - 0x000000000000-0x000000200000 : "bl2"
	  - 0x000000200000-0x000008000000 : "ubi"
Erasing 0x00000000 ... 0x07dfffff (1008 eraseblock(s))
Skipping bad block at 0x05700000
ubi0: default fastmap pool size: 50
ubi0: default fastmap WL pool size: 25
ubi0: attaching mtd2
ubi0 warning: ubi_io_read: error -74 (ECC error) while reading 64 bytes from PEB 695:0, read only 64 bytes, retry
ubi0 warning: ubi_io_read: error -74 (ECC error) while reading 64 bytes from PEB 695:0, read only 64 bytes, retry
ubi0 warning: ubi_io_read: error -74 (ECC error) while reading 64 bytes from PEB 695:0, read only 64 bytes, retry
ubi0 error: ubi_io_read: error -74 (ECC error) while reading 64 bytes from PEB 695:0, read 64 bytes
ubi0 warning: ubi_io_read: error -74 (ECC error) while reading 2048 bytes from PEB 695:2048, read only 2048 bytes, retry
ubi0 warning: ubi_io_read: error -74 (ECC error) while reading 2048 bytes from PEB 695:2048, read only 2048 bytes, retry
ubi0 warning: ubi_io_read: error -74 (ECC error) while reading 2048 bytes from PEB 695:2048, read only 2048 bytes, retry
ubi0 error: ubi_io_read: error -74 (ECC error) while reading 2048 bytes from PEB 695:2048, read 2048 bytes
ubi0: scanning is finished
ubi0: empty MTD device detected
ubi0 warning: do_sync_erase: error -5 while erasing PEB 695, retry
ubi0 warning: do_sync_erase: error -5 while erasing PEB 695, retry
ubi0 warning: do_sync_erase: error -5 while erasing PEB 695, retry
ubi0 error: do_sync_erase: cannot erase PEB 695, error -5
ubi0 warning: do_sync_erase: error -5 while erasing PEB 695, retry
ubi0 warning: do_sync_erase: error -5 while erasing PEB 695, retry
ubi0 warning: do_sync_erase: error -5 while erasing PEB 695, retry
ubi0 error: do_sync_erase: cannot erase PEB 695, error -5
ubi0: attached mtd2 (name "ubi", size 126 MiB)
ubi0: PEB size: 131072 bytes (128 KiB), LEB size: 126976 bytes
ubi0: min./max. I/O unit sizes: 2048/2048, sub-page size 2048
ubi0: VID header offset: 2048 (aligned 2048), data offset: 4096
ubi0: good PEBs: 1007, bad PEBs: 1, corrupted PEBs: 0
ubi0: user volume: 0, internal volumes: 1, max. volumes count: 128
ubi0: max/mean erase counter: 0/0, WL threshold: 4096, image sequence number: 0
ubi0: available PEBs: 982, total reserved PEBs: 25, PEBs reserved for bad PEB handling: 19
ubi0 warning: do_sync_erase: error -5 while erasing PEB 695, retry
ubi0 warning: do_sync_erase: error -5 while erasing PEB 695, retry
ubi0 warning: do_sync_erase: error -5 while erasing PEB 695, retry
ubi0 error: do_sync_erase: cannot erase PEB 695, error -5
ubi0 error: erase_worker: failed to erase PEB 695, error -5
ubi0: mark PEB 695 as bad
ubi0: 18 PEBs left in the reserve
Press ENTER to return to menu 

Maybe spi frequency is too fast, where did you get this image? Bootmenu looks like openwrt

How to change spi frequency ? The default NAND booting well when I first received the board in its default state. After some operations, the NAND partition was accidentally corrupted, then I can’t recover it.

New Debian / Ubuntu Image can be found in their wiki which including new version of loader

Mhm,if you know that nand partition is really corrupted then spi frequency change will not solve this…

Then all parts need to be instructed to search next data on alternative offsets which is no easy part and may break in future

ubuntu Booting from emmc fails with the following message:

F0: 102B 0000 FA: 1042 0000 FA: 1042 0000 [0200] F9: 1041 0000 F3: 1006 0033 [0200] F3: 4001 00E0 [0200] F3: 0000 0000 V0: 0000 0000 [0001] 00: 0000 0000 BP: 0600 0041 [0000] G0: 1190 0000 EC: 0000 0000 [2000] MK: 0000 0000 [0000] T0: 0000 019A [0101] Jump to BL

NOTICE: WDT: Cold boot NOTICE: WDT: disabled NOTICE: Unexpected CPU frequency measured NOTICE: CPU: MT7988 (1500MHz) NOTICE: EMI: Using DDR unknown settings NOTICE: EMI: Detected DRAM size: 4096 MB NOTICE: EMI: complex R/W mem test passed NOTICE: BL2: v2.9(release): NOTICE: BL2: Built : 09:52:16, Jun 9 2023 ERROR: BL2: Failed to load image id 3 (-2)

mmc@11230000: 0 Loading Environment from MMC… Card did not respond to voltage select! : -110 mmc_init: -95, time 17

Can you help me analyze it

Please open new topic. This is for booting from nand…and add exact image filename you use…

Make sure you have replaced fip with emmc variant…wonder about your errors…you have bl2 error loading fip and then mmc error from fip :thinking:

Having up to 3 bad-blocks on a new flash memory is actually quite common and within spec. Installation should work fine anyway.