[BPI-R3] bootflow

Hello all.

Could please someone kindly point me to some resource which describes the bootflow of R3:

Something similar to:

http://www.fw-web.de/dokuwiki/doku.php?id=en:bpi-r2:storage

or

Some of questions:

  • Does it uses a spl->uboot or preloeder->uboot scheme?
  • Are there any major differences between SD/MMC/NAND/NOR boot except MTK_bootheader?
  • Where can i find these headers (e.g. R2 has a git repo with preloaders wich i cant find for R3)?

P.S. I’ve found the en:bpi-r3:start [FW-WEB Wiki] partition layout

and the BPI-R3-bsp/tools/mediatek/gpt_editor at r3-atf · frank-w/BPI-R3-bsp · GitHub

But it’s still not very clear about headers and binaries.

Thank a lot!

Basicly bootrom calls bl2 (first part of atf) from bl2 partition (mmc) or offset 0x0 (spi nand/nor). This bl2 calls bl31 (second part of atf) which is packed with uboot into a fip (fip-partition on mmc or special offsets on nand/nor). Bl31 starts the uboot.

Bl2 (img file) contains the typical sdmmc_boot/emmc_boot header.

Ok, thanks!

Also in the OpenWrt binaries i see some kind of bootheaders different for EMMC and NAND e.g:

  • openwrt-mediatek-filogic-bananapi_bpi-r3-emmc-preloader.bin
  • openwrt-mediatek-filogic-bananapi_bpi-r3-snand-preloader.bin

these files are started with EMMC_BOOT and SPINAND! respectively.

And the last question, did i get it right: the openwrt-mediatek-filogic-bananapi_bpi-r3-device-preloader.bin is a bl2; and the openwrt-mediatek-filogic-bananapi_bpi-r3-emmc-device-bl31-uboot.fip is a bl31+uboot in a single file.

Yes these bootheaders are added by build-process to the bl2.bin to get the bl2.img

And yes fip is u-boot.bin packed into bl31

Thats why my wiki says first build uboot (.bin),change branch to the r3-atf and the build this for the same device

1 Like

And also i see: for the SD the boot header starts with the 0x00004400 address. Should it be the same for EMMC/NAND/NOR?

Afair emmc is similar (but not verified yet). Nand/nor are different as there is no mbr/gpt before.

Sd and emmc gpt have i created with gpt-tool i’ve got from mtk. But daniel creates gpt in openwrt directly,have not yet took a deeper look into it (but i guess i need to do to avoid the issue in my image completely instead of fixing it afterwards).

On spi devices bl2 starts at offset 0x0

Imho only r2pro uses a spl uboot (with raminit blob), mtk do raminit and basic setup in bl2 without uboot and then calls “full” uboot with bl31. @dangowrt pls correct me if i’m wrong

Most magic is done here:

Afaik daniel has newer source of atf which does not use propritary bromimage tool from mtk

mhm…compared the json from mtk gpt-tool…and it looks like emmc has no bl2 partition…yes, bl2 needs to be on boot0 hardware partition…else there is no difference (except a dummy-partition from 0 to 33 to block the gpt itself which is present on emmc, but disabled for sdmmc)

1 Like

Thanks Frank!

The boot process became much more clear for me :slight_smile:

Is it a publicly available tool?

I’ve briefly looked into the code. @frank-w and @dangowrt, would you please confirm or disprove the next concept:

bl2_boot_{devtype}.c are a parts of the implementations of the bl2-loader, responsible for loading the bl31 and the exact methon/device type is selected according to the boot header? (i.e bl2_boot_mmc.c - is for the EMMC_BOOT header; bl2_boot_snand.c is for the SPINAND! header; etc)

And therefore EMMC_BOOT uses the same method as the SDMMC_BOOT?

Thanks in advance!

Yes the bl2_boot* is the bl2 as suggested by the name which loads the fip as next stage.

Spi devices from bpi-r3 are the spim-nand/nor.

Afair bootheader (e.g. sdmmc_boot) are only picked by bootrom and not from bl2 (it is header before bl2 afair added by bromimage tool to bl2.bin to get bl2.img).

Part of my r3-atf branch in u-boot-repo

But i look for a way to create gpt without it as the tool depends on python2 (no py3 support) and it seems to cause the gpt issue i fixed with the sgdisk export+import.

But i need to create the partitions to same offsets (at least bl2 and fip) to not break bootchain. I know a way with parted which i use for bpi-r2pro,but i want a way without installing additional tools (ok (s)gdisk needs to be installed too)

1 Like

Found it: https://github.com/dangowrt/arm-trusted-firmware/commit/88a275da145111afd19cb6006af70daa773e948d

1 Like

The change I’ve added to support using U-Boot’s mkimage instead of the binary-only bromimage tool was merged in @hackpascal’s TF-A sources on github as well:

So just use those, that’s also what we are doing for OpenWrt by now:

1 Like

Hi, I am looking for a little clarification. If I start from a BPI-R3 where one has wiped the SPI-NOR, SPI-NAND, eMMC with all zeros. Put the dip switches in boot from SD card mode. Will it boot? Or, does the boot process first need to read a small boot loader from SPI-NOR or SPI-NAND or eMMC before it can boot the SD Card?

R3 (and others) has bootrum which checks all bootable devices for the bl2 header…there is a page of output when it does not found it,if it found that header on the selected device it load it,then bl2 loads the fip (bl31+uboot)

Dip switches on r3 are bit tricky as c and d are important. One sets the spi chipselect,the other switches sd or emmc to mmc controller