This post is a supplement to [BPI-R4] How to use frank-w u-boot to boot from Nvme on BPI-R4.
Because NAND u-boot does not support uEnv.txt.
If we want to modify u-boot menu, we need to recompile u-boot and flash it to NAND Flash.
Environmental Information:
Hardware: BananaPi R4 8GB RAM
eMMC: OpenWRT u-boot & OpenWRT
SD: frank-w u-boot & frank-w Debian
NAND(Target): frank-w u-boot
Nvme: Nvme SSD 128GB on M.2 KeyM slot
Compile Host: x86 Debian 12
Partition:
SD Partition:
/dev/sda5 vfat BPI-BOOT
/dev/sda6 ext4 BPI-ROOT
Nvme Partition:
/dev/nvmen1p0 vfat
/dev/nvmen1p1 ext4
After the u-boot is compiled, it will generate u-boot.bin.
But BPI-R4 requires two files, bl2.img and fip.bin, so we need to convert u-boot.bin into bl2.img and fip.bin.
We need to download 2 packages of code to compile frank-w u-boot.
First, download 2025-01-bpi Release u-boot Source Code.
Second, git u-boot branch mtk-atf-2025.
u-boot Source Code:
u-boot-CI-BUILD-2025-01-bpi-2025.01-2025-04-26_0808
mtk-atf-2025:
u-boot
We divide the process into 2 stages, the first stage is to Compile u-boot, and the second stage is to Flash NAND Flash.
There are two goals for compiling u-boot.
The first goal is to set up compilation for BPI-R4, NAND and 8Gb RAM.
The second goal is to adjust the boot menu, specify the default boot number as Nvme and specify the Kernel Name.
Compile u-boot:
- Modify build.conf for BPI-R4, NAND and 8Gb RAM
board=bpi-r4 |
- Modify uEnv_r4.txt for Nvme boot
bootmenu_default=3 => Base 0, option 4 set number to 3
askbootnvme=run usenvme; if test “$device” = “nvme”; then setenv fit ${fit};run newboot;fi
- Build u-boot
bash ./build.sh importconfig |
-
Copy u-boot image to mtk-atf-2025
cp u-boot-r4_2025.01–arm64-spi-nand.bin …/u-boot/u-boot.bin.xz => Here is .bin.xz -
Modify build.conf in mtk-atf-2025
board=bpi-r4 |
-
Convert u-boot.bin to bl2.img and fip.bin
bash ./build.sh build
-
Copy bl2.img and fip.bin to SD
The two files bl2.img and fip.bin will be generated in build/mt7988/release/.
We put bl2.img and fip.bin to SD vfat Partition, /dev/sda5/.
Flash NAND Flash:
We plug a USB SD card reader into the BPI-R4 USB and use the USB SD card reader as the file source.
- Switch to eMMC Boot and boot into u-boot menu
- Enable USB
usb start
- Flash u-boot from USB Partition 5
mtd erase spi-nand0 |
- Switch boot from NAND
Check RAM Size
EMI: DDR4 4BG mode
EMI: Detected DRAM size: 8192 MB
Check bootmenu
- Reset and use NAND to boot into Nvme