Possible to flash R3 ubuntu image into eMMC/NAND?

As I found banana official ubuntu-22.04 image downloadable for SD card (and eMMC?) from the below link, I am able to flash and boot it from SD card by following the provided instruction https://docs.banana-pi.org/en/BPI-R3/GettingStarted_BPI-R3#_install_image_to_sd_card.

https://docs.banana-pi.org/en/BPI-R3/BananaPi_BPI-R3#_ubuntu

How can I also flash the pre-built R3 ubuntu image into eMMC? Instead, that should be an instruction for installing Openwrt pre-built eMMC images in https://docs.banana-pi.org/en/BPI-R3/GettingStarted_BPI-R3#_install_image_to_emmc, not ubuntu I think?

In addition, are there handy ways to install ubuntu image into the R3 NAND (128 MB)?

Thanks,

Bruce

Emmc should work, on R3 and R4 you have only to flash and activate the emmc bl2 in boot0 and replace fip (for uboot devicetree) after flashing image to emmc user partition.

On older boards (R2,R64) you have ro change mmc controller number in uboot and /etc/fstab to target the right device.

This is not needed on R3/R4 because there is only one mmc controller and uboot should apply the right settings through devicetree overlay. This is done in my image and i guess also on bpi image.

As i said in other thread ubuntu in nand could be tricky because of filesystem and size (nand is only 128mb,ubuntu base install is afair 600mb).

Like Frank said, it is too small. However it is large enough for U-Boot + kernel + initrd-image, so it can contain a linux rescue system. From this you can for example chroot into the normal system rootfs (on nvme or emmc) and fix it. The U-Boot on nand is also needed to boot a rootfs on nvme (and could possibly also boot rootfs on emmc, but that is not needed, as U-Boot can be on emmc).

In order to flash the R3 ubuntu image into eMMC in practice, do you mean that I have to 1. Install the official Openwrt eMMC image (following https://docs.banana-pi.org/en/BPI-R3/GettingStarted_BPI-R3#_install_image_to_emmc) then 2. Replace the bl2 in boot0 (mmcblk0boot0?) and fip by Frank’s pre-built R3 ubuntu images https://forum.banana-pi.org/t/bpi-r3-ubuntu-22-04-image/14956?

Do not mix openwrt and my image. You can bootup my image from sdcard and install to nand like described in my wiki,bootup from nand with initrd and install to emmc.

Or use the full openwrt way (sd-nand-emmc)

I suppose to have a SD card with official R3 ubuntu image installed. And I want to flash the customized u-boot and kernel (will build from your Github repo) into NAND then eMMC, as said the way SD → NAND → eMMC.

Do the spi-nand bl2 and fip refer to bl2.img and fip.bin built from your Uboot repo?

Do I need to enable emmc and usb support from your Uboot repo manually?

How to put those files into the SD card with ubuntu installed as mentioned?

Thanks.

Bl2 are different versions like with ubi support and 8gb,so you have to choose the right file here. Fip should only be one.

My uboot have basic usb,network and pcie/nvme support. But to boot system you may have to set variables to let my builtin scripts know which file from which source to load. Emmc is also supported in the nand fip,but you have no access to sdmmc from there as only one can be targeted in dts.

May I ask what is the captured part doing?

Is it the SD ubuntu image containing .itb fip bl2 files by default, and flashing them into NAND?

No, sdcard image does only contain sd related parts. Bit you can download the needed files from releases on my u-boot repo

The commands in screenshot only listing files and show the nand/mtd information.

If this is complicated, there are different ways to do this:

Booting from my archlinuxarm sd-image, with only 1 command you can setup a rescue linux initrd on nand. Then boot from nand and easily connect to the internet easily. From there most common linux commands are available to setup any linux distro (Ubuntu) using different ways. You can use debootstrap or any tool you prefer. Only add linux kernel and devicetree (and optionally initrd).

Also you will have a distroboot-uboot version on nand, that means that anywhere on emmc or nvme you can format a partition (fat32 or btrfs), set the bootflag and add (/boot)/extlinux/extlinux.conf file. So you leave the switches to boot nand and there is no need to worry about atf/bl2/bl31/u-boot anymore, since you can keep using the bootchain on nand.

Not to add to the confusion, this is different from what Frank is writing, but to let you know there are more options to do this.

@frank-w @ericwoud

Those operations would be complicated for me without the exact commands to follow since I am a beginner for Linux system.

My plan and imagination:
I have a SD card with R3 ubuntu image installed, and have already built Linux from Frank’s R3 Linux repo but no further actions.
Next step I’m thinking is to see which the meaningful output files are, what their usages are and prepare to build u-boot from Frank’s R3 u-boot repo. (Btw I found Frank’s wiki and README are hard to follow for beginners like me.)

Little Goal:
My little goal is to boot up with SD card and flash the NAND with customized u-boot and Linux (so I would like to build them from Frank’s repo by myself first). And the next will be flashing eMMC with customized u-boot and Linux from NAND boot.

Uncertainty:

  • My R3 board currently has bootable Openwrt images installed in NOR, NAND and eMMC. As I want to replace them with my customized u-boot and Linux, can I just flash them in-place (e.g. boot NAND and flash NAND, boot eMMC and flash eMMC)? If so, may I have your instructions and commands? I am trying hard to follow Frank’s wiki and README.
  • Could you advise on my plan and goal? I guess there are easier ways to achieve. It would be nice to have the your commands for me to follow.

Thanks.

Booting from my nand image, you can run

bpir-build

It is menu driven and can install a slightly customised Ubuntu as well and could install directly on emmc.

Building U-Boot and bl2 etc all takes place in building packages, which you can do yourself on archlinux.

Can’t make it easier than that…

Basicly you can use sdcard image first without need to compile ecerything

Once booted into uboot you can follow this to flash nand bl2 and fip:

https://www.fw-web.de/dokuwiki/doku.php?id=en:bpi-r3:uboot#nand_flash

BPI-R3> mtd erase spi-nand0
Erasing 0x00000000 ... 0x07ffffff (1024 eraseblock(s))
BPI-R3> fatload mmc 0:5 $loadaddr bl2_nand.img
217712 bytes read in 24 ms (8.7 MiB/s)
BPI-R3> mtd write spi-nand0 $loadaddr 0x0 0x100000
Writing 1048576 byte(s) (512 page(s)) at offset 0x00000000

BPI-R3> fatload mmc 0:5 $loadaddr fip_nand.bin
579401 bytes read in 60 ms (9.2 MiB/s)
BPI-R3> mtd write spi-nand0 $loadaddr 0x380000 0x200000
Writing 2097152 byte(s) (1024 page(s)) at offset 0x00380000

The bl2_nand.img and fip_nand.bin are ony uboot releases page with more detailed name (bpi-r3_spim-nand_bl2.img and bpi-r3_spim-nand_fip.bin).

Just copy it to a fat formatted usb drive and use this

usb start
fatload usb 0:1 $loadaddr bpi-r3_spim-nand_bl2.img
...
fatload usb 0:1 $loadaddr bpi-r3_spim-nand_fip.bin

Instead of the mmc lines…or copy them to the BPI-BOOT partition on the card and use commands above with changed filenames.

Have you done this you should be able to boot from nand.

Then we can go further (use initrd to flash emmc)

So my understanding is that:

  • SD card contains the default ubuntu bl2_nand.img and fip_nand.bin for NAND. It should be able to flash them to NAND then it will also become bootable ubuntu u-boot and kernel.

  • There are pre-built bpi-r3_spim-nand_bl2.img and bpi-r3_spim-nand_fip.bin released on https://github.com/frank-w/u-boot/releases. So it is allowed to copy them into a FAT32 formatted USB device, boot SD card along with the USB-stick inserted and flash the NAND bl2 and fip by those 2 files from USB rather than SD card.

  • Other than that, the bpi-r3_spim-nand_bl2.img and bpi-r3_spim-nand_fip.bin can be built and generated (for customization) from Frank’s u-boot repo. If so, I can build them by myself and flash to NAND bl2 and fip through the USB way (like the above point).

Flash NAND bl2 and fip with SD card built-in files:

mtd erase spi-nand0
fatload mmc 0:5 $loadaddr bl2_nand.img
mtd write spi-nand0 $loadaddr 0x0 0x100000
fatload mmc 0:5 $loadaddr fip_nand.bin
mtd write spi-nand0 $loadaddr 0x380000 0x200000

Flash NAND bl2 and fip with USB pre-built files:

usb start
mtd erase spi-nand0
fatload usb 0:1 $loadaddr bpi-r3_spim-nand_bl2.img
mtd write spi-nand0 $loadaddr 0x0 0x100000
fatload usb 0:1 $loadaddr bpi-r3_spim-nand_fip.bin
mtd write spi-nand0 $loadaddr 0x380000 0x200000
  • After things are done, the NAND has bootable ubuntu u-boot and kernel.

Is this correct?

Sdcard contains only sd related parts…bl2 and fip for other devices can be downloaded from my uboot repo in releases for all devices. Put it on your sdcard to continue like described in my wiki. Or use the usb way…does not need to remove sdcard from board,but basicly same only usb have to be initialized first and use changed subsystem and partition (0:1 is first device first partition).

How to load the bl2_nand.img and fip_nand.bin into SD card with ubuntu installed? According to the #nand_flash section of wiki, which seems like the files already exist in the ubuntu image of SD card.

Or do you mean even the card has ubuntu installed, it can still be storing files via computer access like how I put files in USB device?

Instead of downloading the bl2 and fip from your u-boot releases section, can I just build them by using your u-boot repo, so I could customize the code by needs? (I’m considering the possibility of u-boot and kernel customization)

I also copied the files to sdcard bpi-boot partition…ist is not part of image,but image contains 2 visible partitions (bpi-boot with kernel and ubootconfig and bpi-root with ubuntu/debian rootfs and kernel modules,firmware).

Building uboot is more complex than just flash the existing files.

Are you running any linux on your PC/laptop? Usually you would build from source on that, although it is possible to do it on bpi-board, but not recommend.

@frank-w @ericwoud

My laptop is running in Windows11. In WSL, I followed Frank’s Linux repo and compiled once in the provided docker container:

ubuntu@afe0fd51a26a:/srv$ ll
total 20
drwxrwxrwx  1 root   root   4096 Sep 19 09:44 ./
drwxr-xr-x  1 root   root   4096 Sep 19 09:34 ../
drwxr-xr-x  4 ubuntu ubuntu 4096 Sep 19 10:17 SD/
drwxr-xr-x  2 ubuntu ubuntu 4096 Sep 19 09:44 build/
drwxr-xr-x 30 ubuntu ubuntu 4096 Sep 19 10:07 code/
ubuntu@afe0fd51a26a:/srv$ 
ubuntu@afe0fd51a26a:/srv$ ll SD/*
-rw-r--r-- 1 ubuntu ubuntu 99280305 Sep 19 10:17 SD/bpi-r3_6.12.47-main.tar.gz
-rw-r--r-- 1 ubuntu ubuntu       61 Sep 19 10:17 SD/bpi-r3_6.12.47-main.tar.gz.md5

SD/BPI-BOOT:
total 34876
drwxr-xr-x 2 ubuntu ubuntu     4096 Sep 19 10:17 ./
drwxr-xr-x 4 ubuntu ubuntu     4096 Sep 19 10:17 ../
-rw-r--r-- 1 ubuntu ubuntu    22925 Sep 19 10:17 bpi-r3.dtb
-rw-r--r-- 1 ubuntu ubuntu  9518204 Sep 19 10:17 bpi-r3.itb
-rw-r--r-- 1 ubuntu ubuntu 26157632 Sep 19 10:17 uImage_nodt

SD/BPI-ROOT:
total 16
drwxr-xr-x 4 ubuntu ubuntu 4096 Sep 19 10:17 ./
drwxr-xr-x 4 ubuntu ubuntu 4096 Sep 19 10:17 ../
drwxr-xr-x 4 ubuntu ubuntu 4096 Sep 19 10:17 etc/
drwxr-xr-x 4 ubuntu ubuntu 4096 Sep 19 10:17 lib/
ubuntu@afe0fd51a26a:/srv$ 

I’ve also built Frank’s u-boot repo in the same docker container:

ubuntu@afe0fd51a26a:~/u-boot$ ll u-boot*
-rwxr-xr-x 1 ubuntu ubuntu 4425204 Sep 22 07:20 u-boot*
-rw-r--r-- 1 ubuntu ubuntu  452336 Sep 22 07:20 u-boot-dtb.bin
-rw-r--r-- 1 ubuntu ubuntu  452848 Sep 22 07:20 u-boot-mtk.bin
-rwxr-xr-x 1 ubuntu ubuntu  437928 Sep 22 07:20 u-boot-nodtb.bin*
-rw-r--r-- 1 ubuntu ubuntu  452336 Sep 22 07:20 u-boot.bin
-rw-r--r-- 1 ubuntu ubuntu   11874 Sep 22 07:20 u-boot.cfg
-rw-r--r-- 1 ubuntu ubuntu   14408 Sep 22 07:20 u-boot.dtb
-rw-r--r-- 1 ubuntu ubuntu    1393 Sep 22 07:20 u-boot.lds
-rw-r--r-- 1 ubuntu ubuntu  888849 Sep 22 07:20 u-boot.map
-rwxr-xr-x 1 ubuntu ubuntu 1313922 Sep 22 07:20 u-boot.srec*
-rw-r--r-- 1 ubuntu ubuntu  192117 Sep 22 07:20 u-boot.sym
ubuntu@afe0fd51a26a:~/u-boot$ 
ubuntu@afe0fd51a26a:~/u-boot$ ./build.sh install
ver:2025.04,ubranch:bpi
bpi-r64/bpi-r3 with new ATF needs uboot packed into fip!
ubuntu@afe0fd51a26a:~/u-boot$ 

How to make use of these output files? I am considering to generate u-boot and kernel images but not to install files to SD card.

I just figured out how to put and flash bl2 and fip from SD card to NAND. However it cannot boot the NAND kernel directly. Do you know how to fix this?

Partitions:

MT7986> ls mmc 0:5
            bananapi/
            System Volume Information/
   209616   bpi-r3_spim-nand_bl2.img
   279581   bpi-r3_spim-nand_fip.bin

2 file(s), 2 dir(s)

MT7986> mtd list
spi-nand: spi_nand spi_nand@1: Winbond SPI NAND was found.
spi-nand: spi_nand spi_nand@1: 128 MiB, block size: 128 KiB, page size: 2048, OOB size: 64
jedec_spi_nor spi_nor@0: unrecognized JEDEC id bytes: 00, ef, aa
List of MTD devices:
* spi-nand0
  - device: spi_nand@1
  - parent: spi@1100a000
  - driver: spi_nand
  - path: /spi@1100a000/spi_nand@1
  - type: NAND flash
  - block size: 0x20000 bytes
  - min I/O: 0x800 bytes
  - OOB size: 64 bytes
  - OOB available: 24 bytes
  - 0x000000000000-0x000008000000 : "spi-nand0"
          - 0x000000000000-0x000000080000 : "bl2"
          - 0x000000080000-0x000000380000 : "factory"
          - 0x000000380000-0x000000580000 : "fip"
          - 0x000000580000-0x000008000000 : "ubi"
MT7986>

Flashing:

MT7986> mtd erase spi-nand0
jedec_spi_nor spi_nor@0: unrecognized JEDEC id bytes: ff, ef, aa
Erasing 0x00000000 ... 0x07ffffff (1024 eraseblock(s))
MT7986> pri loadaddr
loadaddr=0x46000000
MT7986> fatload mmc 0:5 $loadaddr bpi-r3_spim-nand_bl2.img
209616 bytes read in 15 ms (13.3 MiB/s)
MT7986> mtd write spi-nand0 $loadaddr 0x0 0x80000
jedec_spi_nor spi_nor@0: unrecognized JEDEC id bytes: ff, ef, aa
Writing 524288 byte(s) (256 page(s)) at offset 0x00000000
MT7986> fatload mmc 0:5 $loadaddr bpi-r3_spim-nand_fip.bin
279581 bytes read in 19 ms (14 MiB/s)
MT7986> mtd write spi-nand0 $loadaddr 0x380000 0x200000
jedec_spi_nor spi_nor@0: unrecognized JEDEC id bytes: ff, ef, aa
Writing 2097152 byte(s) (1024 page(s)) at offset 0x00380000
MT7986>

NAND boot failed:

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 0210 [010F]
Jump to BL

NOTICE:  BL2: v2.12.0(release):a385740df-bpi-r3-spim-nand
NOTICE:  BL2: Built : 10:52:22, Aug 20 2025
NOTICE:  WDT: [40000000] Software reset (reboot)
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:  BL2: Booting BL31
NOTICE:  BL31: v2.12.0(release):a385740df-bpi-r3-spim-nand
NOTICE:  BL31: Built : 10:52:24, Aug 20 2025


U-Boot 2025.07-bpi-geacd36c56c9c-dirty (Aug 20 2025 - 10:51:56 +0000)

CPU:   MediaTek MT7986
Model: BananaPi BPi-R3
DRAM:  2 GiB
Core:  48 devices, 22 uclasses, devicetree: separate
MMC:   mmc@11230000: 0
Loading Environment from nowhere... OK
In:    serial@11002000
Out:   serial@11002000
Err:   serial@11002000
=> board_late_init...
Net:   MediaTek MT7531

Warning: ethernet@15100000 (eth0) using random MAC address - fa:13:ab:09:86:d0
eth0: ethernet@15100000
Hit any key to stop autoboot:  0


  *** U-Boot Boot Menu ***

      1. Enter kernel-name to boot from SD/EMMC.
      2. Boot kernel from TFTP.
      3. Boot from SD/EMMC.
      4. Boot kernel from NVME.
      Exit


  Press UP/DOWN to move, ENTER to select, ESC to quit



## Error: "initrd" not defined
PARTITION_CONFIG only exists on eMMC
sd available
jedec_spi_nor spi_nor@0: unrecognized JEDEC id bytes: ff, ef, aa
Failed to initialize SPI flash at 0:0 (error -2)
NAND available
sd nand
fit=bpi-r3.itb
Failed to load 'bpi-r3.itb'
BPI-R3>