Banana Pi R3 - How to flash NOR, NAND or eMMC from the SD Card's Bootmenu

Banana Pi R3 - How to flash NOR, NAND or eMMC from the SD Card

  • (Step by step guide for beginners and hobbyists alike)

System Info

  • Banana Pi-R3 (Board v1.1) (BPiR3v1.1)
  • OpenWRT version: 23.05.5
  • uBoot version: 2023.07.02-OpenWrt-r24106-10cc5
  • OWRT v23.05.0 & later supports BPiR3 (Sept 2024 & later)
  • Requirements:
    • USB (Min 4GB)
    • Compatible USB to UART adapter (CP1202, CH340 or FDTI’s )
    • Working UART (serial) connection to BPi-R3 console via Putty (Windows / Ubuntu)
    • Working installation of Ubuntu (Optional but recommended for formatting & compiling)

Notes

  • For those new to working with BPiR3, I highly recommend reading “Things I wish I knew before I started” at the end of this post
  • This process will overwrite any existing installations & install uBoot, OWRT, & recovery OWRT
  • We are connecting to the BPi-R3 via the UART adapter and Putty

Process Overview - Steps to Flash NOR, NAND or eMMC

  1. Format a USB drive as EXT4 format (I used the uBuntu terminal)

  2. Generate OpenWRT firmware from “OpenWRT firmware selector website” (or compile your own from source)

  3. Copy generated images to USB (I used WinSCP for Windows, uBuntu terminal/GUI works as well)

  4. Flash SDCARD.IMG.GZ to an SD Card via Balena etcher (Etcher supports uBuntu & Windows)

  5. Set Bootloader (BL) switches to 1111 (Boot from SD with SPI bus connected to NAND)

  6. Insert USB & SD Card, Power up , Pan arrow to halt at SD Card’s boot menu

  7. For flashing (Boot Memory / SPI Memory) :

    • NOR / NOR - Select Option 7, after flashing complete, set BL switch to 0000, reboot (or)

    • NAND / NAND - Select Option 8, after flashing complete, set BL switch to 1010, reboot (or)

    • eMMC / NAND - From NAND uBoot, Select option 9, after flashing, set BL switch to 0110, reboot

  8. BPiR3 Should reboot to the BL selected memory’s uboot firmware/OWRT image

  9. Repeat step 7 to flash the other Memory

  10. Continue with optional steps to expand the OWRT partitions to the full memory size.

    • TO BE ADDED SOON


Start of detailed instructions - (for us newbies and hobbyists alike)


Prepare OpenWRT Images - (Flashing NOR, NAND or eMMC)

1. Format a USB drive as EXT4 format (I used fdisk & mkfs from uBuntu Terminal)

# Delete all partitions and create one new one. From terminal:
   sudo su              # Enter superuser mode
   disk -l              # List USB devices, note sdXX partition of the usb (listed at the end)
   fdisk /dev/sdXX      # Format USB drive
   d                    # Delete partiion
   1             		# Select partition to delete
   p                    # Print partition table to verify deleted (might not need this)
  # Repeat for other partitions on USB
   n                    # Create a New Partition
   1                    # Assign Partition number to New Partition
   Enter                # Use Default sector
   Enter                # Use Default Sector
   w                    # Write/commit all changes to disk
   umount /dev/sdXX     # Might not be mounted 

# Format USB as EXT4 format with mkfs
#   Syntax:  mkfs.ext4 [options] /dev/sdXX 
#   [options]
#     -L 	# specifies the label for the partition
#     -m    # sets the reserved blocks percentage, which is 1 (1%) in this case
#     -b 	# specifies the block size, which we’ve set to 4096 bytes
# 
    mkfs.ext4 -L EXT4 -m 1 -b 4096 /dev/sdb2

2. Generate firmware from OpenWRT (OWRT) firmware selector website:

  • OpenWRT Firmware Selector Website (Or google “openwrt firmware selector”)

  • Download all the following generated images (or compile your own images, different post):

    • EMMC-BL21-UBOOT.FIP
    • EMMC-PRELOADER.BIN
    • KERNEL
    • NOR-BL31-UBOOT.FIP
    • NOR-PRELOADER.BIN
    • SDCARD.IMG.GZ
    • SNAND-BL31-UBOOT.FIP
    • SNAND-PRELOADER.BIN
    • SYSUPGRADE

3. Copy all images to the EXT4 formatted USB (I used WinSCP (sftp), or use Ubuntu)

4. Flash SDCARD.IMG.GZ to SD via Balena etcher (do not need to decompress .GZ (in windows) & is supported by both Windows/Ubuntu).

5. Insert SD & USB into BPiR3 & move on to the option below that corresponds to desired memory you’re flashing

6. Repeat options below to flash other memory on the BPiR3


Option A - Flashing NOR Memory (32MB)

   (Using the same USB that has all the images on it and inserted into BPiR3)

  1. Set Bootloader Switches to Boot from SD Card, SPI set to NOR (SPI-NOR)(1101)
  2. Power up, Pan arrow key to halt at the SD uBoot Boot Menu
  3. Select option: “7. Install, bootloader, recovery and production to NOR,” flashing will begin
  4. After installation, set Bootloader switches to NOR/NOR(0000 or 0001), reboot
  5. Should boot to the NOR uboot firmware/OWRT and there should be a bootable recovery partition in uboot menu
  6. Continue to Option B to Flash NAND Memory

Option B - Flashing NAND Memory (128MB)

   (Using the same USB that has all the images on it and inserted into BPiR3:)

  1. Set Bootloader Switches to Boot from SD Card, SPI set to NAND (SPI-NAND)(1111)
  2. Power up, Pan arrow key to halt at the SD uBoot Firmware Boot Menu
  3. Select option “8. Install, bootloader, recovery and production to NAND,” flashing will begin
  4. After installation, set Bootloader switches to NAND/NAND (1010 or 1011), reboot
  5. Should boot to the NAND uboot firmware/OWRT and there should be a bootable recovery partition in uboot menu
  • Optional steps
  1. Exapnd NAND OWRT partition to the full memory size - (Only 128MB, not much to expand)
  2. Continue to Option C to Flash eMMC Memory

Option C - Flashing eMMC Memory (8GB)

   Note: If you don’t have a working NAND OWRT installation, complete Option B prior to C

   (Using the same USB that has all the images on it and inserted into BPiR3:)

  1. Set Bootloader Switches to Boot from NAND with SPI bus connected to (SPI-NAND) (1010), power up. Note: BL Setting (1011) doesn’t let you flash to eMMC.
  2. Pan arrow key to halt at the NAND uBoot Firmware boot menu
  3. Select option “9. Install, bootloader, recovery and production to NAND,” flashing will begin
  4. After installtion, set Bootloader switches to eMMC/NAND (0110 or 0111), reboot
  5. Should boot to the NAND uboot firmware/OWRT and be redirected to eMMC start address to load OWRT
  • Optional steps
  1. Exapnd eMMC OWRT partition to the a larger memory size - TO BE ADDED SOON


Things I wish I knew before I started

1. Starting with OpenWRT 23.05.0 (Sept 2024)

  • Banana Pi-R3 is now supported by OWRT and is listed as a “Target” in OWRT “menuconfig” allowing us to compile uBoot with OpenWRT from the OWRT source code. Prior to this we had to compile uboot & OWRT separately (possibly flash them separately too, anyone?)
  • We can now also use the OpenWRT Firmware selector website to generate the builds to flash directly to the BPi-R3, through uBoot “Boot menu”
  • Pay attention to dates when reading forums, some of the steps mentioned have been eliminated with OWRT v23.05.0 support/functionality

2. Board design notes for NOR/NAND & SD/eMMC & Firmware

  • NOR & NAND can’t be accessed at the same time because they share the same SPI bus

  • SD & eMMC can’t be accessed at the same time because they share the same data bus

  • NOR uBoot firmware can’t write to NAND or eMMC

  • NAND uBoot firmware can’t write to NOR

  • eMMC uBoot firmware can’t write to NAND or NOR

  • eMMC installation uses the NAND uBoot firmware to call the OS on eMMC (is this correct, anyone?)

  • NVMe installation uses the NAND uBoot firmware to call the OS on NVMe (similar to eMMC, anyone?)

  • NOR, NAND, eMMC, SD have independent uBoot firmware, OS & recovery partitions once flashed and can each have completely different uBoot versions and OS.

  • The board should come preloaded with OpenWRT loaded into NOR and NAND, eMMC empty

  • Firmware: The *.*BL31-UBOOT.FIP file contains both bl2 (uBoot) and bl3 (OWRT).

    Firmware: (Edit added per Profile - frank-w - banana pi single board computer open source project official forum BPI team) “FIP” is uboot.bin (BL33) packed into ATF (BL31). BL2 is separate and loaded before loading BL31. BL2 points to the FIP image on BL31 which load/runs ATF (BL31). ATF (BL31) then points/loads to BL33 (uBoot). BL33 (uBoot) points to the OWRT/OS memory start address.

    • “ATF” is BL31 (Arm Trusted Firmware bootloader version 31)
    • “.FIP” is an image file that has BL33 (uboot.bin) packed into to BL31-ATF
    • Starting with OWRT v23.05.0, OpenWRT source code will compile the “.FIP” file
  • Booting: Loads BL1 (Hard coded boot code, cannot be changed) which calls BL2 (uBoot Firmware) then calls BL3 (OpenWRT/OS)

    Bootloader Booting Order: (Edit added per hackpascal): The system loads in the following order:

    1. BL1 - Loads the hard-coded HW Bootloader (BL1) boot code (cannot be altered), then calls
    2. BL2 - Runs pre-loader, initializes CPU/DRAM/PLL and other basic peripherals, then calls
    3. BL3 - Loads xxBL31-UBOOT.FIP (which contains both ATF-BL31 & BL33(u-Boot)), then calls
    4. OWRT / OS - Loads the OWRT / OS image from NOR, NAND, eMMC, NVMe, or other.

    Note: OpenWRT is not part of BL1, BL2, BLxx-ATF or BLxx-UBOOT.FIP.

  • OpenWRT Partition Size: The flashed OpenWRT installation has a small partition that is not expand to the full size of the storage device. It’s not necessary to expand the partition but many choose to expand their devices to ~ 2GB (at least) and partition the remaining memory for hosting config files (helps with upgrading the system) or other versions of OWRT / Ubuntu, etc).


  • Available Flash Options from uBoot Firmware Boot Menu

    BL/SPI (SW1) uBoot Flash Option (Partially listed, see actual boot menu)
    NOR/NOR (0000) [SPI-NOR] Allows: “Loading via TFTP then write to NOR flash” only
    NAND/NAND(1010) [SPI-NAND] Allows: “TFTP flashing to NAND” & “Install to eMMC” only
    NAND/NAND(1011) [SPI-NAND] (Same as SPI-NAND above but no flashing to eMMC)
    SD/NAND (1111) [SD CARD] Allows: “Flashing from USB to NOR or NAND”, & flashing “TFTP to SD” only
    SD/NOR (1101) [SD CARD] (Loads the same uBoot firmware off SD)
    eMMC/NAND(1110) [eMMC] Allows TFTP flashing to eMMC only
    NOR/NAND (0010) - System halt after bl1 runs, no bl2 to call
    NAND/NOR (1000) - System halt after bl1 runs, no bl2 to call
    NAND/NOR (1001) - System Halt after bl1 runs, no bl2 to call

Resourceful Links

Banana Pi R3

OpenWRT

Mediatek / Arm7986a

Software


Message from the Author

After many hours of reading through forums and trial/error, I thought it would only be right to give back to the community with my personal notes & experiences developing BPi-R3 with OWRT, especially now that it’s supported by OWRT. I hope this info helps others and supports this community as a whole.

I’m sure there’s plenty of other more efficient ways to do some of this but this is what worked for me and these are my notes from hours of tinkering around.

Please message with edit recommendations.

Special thanks to Frank W and the Banana Pi community as a whole for all their feedback.


This is not correct.

BL2: preloader, initializes CPU/DRAM/PLL and other basic peripherals then loads BL31 (trusted firmware) and BL33 (u-boot)

openwrt/os is not part of BLx

1 Like

FIP is uboot.bin packed into bl31 Atf…bl2 is separate and loaded before and then pointing to fip as next step

1 Like

Please do not hijack threads with different questions…this thread is about general bootup (till uboot/kernel)

Rootfs expansion is asked many times so please use one of these threads.