Bananapi BPI-R3 bootloader

Ok,but strange that it does not work from linux…

maybe my command line was wrong with dd, i must pass more option or use another command than dd

One question please ^^ :slight_smile:

From u-boot, i can see th SD card ( mmc info).

But when i remove this one, to check if i can see emmc, nothing :

BPI-R3> mmc info
Card did not respond to voltage select! : -110  

I try to boot from nand and after for the kernel (fit files) and the rootfs :

If a SD card is introduced go on the SD card else go into the emmc.

The check is not yet complete in my uboot

You have to change switch on board from sd to emmc to see emmc…you cannot access both at same time as mt7986 only has 1 mmc controller

I read the wiki to get more informations. Le last switch board is for emmc or sd card, like you say 1 mmc controler.

Same for spi…uboot can detect nand/nor with 1 dts,linux needs different devicetrees as it cannot recognize 2 devices with same (0) address.

Hy :slight_smile: Little Question please :slight_smile:

In the uEnv_r3.txt found in the Kernel’s Folder i saw this line :
#bootconf="#conf-2"

Is it to select the conf in the fip? If we use several Kernel, DTS?

Thank you

Yes this variable is used to select the configuration in the fit by newboot command. But this is an example and disabled in builtin environment. My latest uboot (2022-10-r3) has detection for right dtb and overlay, currently only via manual call

Needs fit with matching configurations

Hy thank you again and again :slight_smile:

I followed your Recommendations and i keep adapting to my system.

One mroe Question about nand memory.

There are 4 Partitions : ubi,bl2,fip and reserved. Which Partition is dedicated for the rootfs (like mmcblk0p6 for sd card).

Thank again a lot for your help

Nand should not be used as a “normal” rootfs,but ubi is defined for kernel which can include a initrd (rootfs in ram).

1 Like

Read more about UBI here: http://linux-mtd.infradead.org/doc/ubi.html

From a user point of view UBI is something like LVM2: You dedicate an amount of flash storage to it which you can then manage and dedicate shares of it to virtual volumes.

If you want an x86-like experience you can create just a single UBIFS virtual volume and use that as rootfs, and have the bootloader load the kernel from the /boot/ folder in there.

2 Likes

Hy ^^ Thanks you to answer me.

If i have understood, i juste need an initrd for thé rootfs (Like you say in the ram). Just transfer thé initrd file in the ubi, am i juste? Same for the fit(kernel,dtb)?

Hy Thanks you to answer me :slight_smile:

I will study thé link you put and thé informations you gave me in the weekend.

Fit can contain an initrd so you have only 1 file which is maybe better for single kernel use. If you have more than 1 kernel it is better to have separate initrd

I will try thank you :slight_smile:

Another option i can use is the rootfs in USB storage.

I tried to modify the uEnv.txt for uboot to start usb automatically and after to load the fit.

To start i writed this command in uenv.Txt :

usb_start=usb start; echo “usb starting”;

Here a part of the uenv.Txt

board=bpi-r3
device=usb
partition=0:1
bootenv=uEnv.txt
bootdevice=sd

fit=diagbox.itb
#bootconf="#conf-2"
#initrd=rootfs.cpio.zst

loadaddr=0x46000000
kaddr=0x46000000
rdaddr=0x48000000

tt=usb start; echo "usb starting";

root=/dev/mmcblk0p6 rootfstype=ext4 rootwait
console=ttyS0,115200n1 earlycon=uart8250,mmio32,0x11002000
bootopts=debug=7

checkenv=test -e ${device} ${partition} ${bootenv}
loadenvfile=if fatload ${device} ${partition} ${loadaddr} ${bootenv};then env import -t ${loadaddr} ${filesize};else echo "fatload (${bootenv}) failed";fi
loadenv=if run checkenv;then run loadenvfile;fi
resetenv=env default -a;printenv;

loadkernel=fatload $device $partition $kaddr ${kernel}
buildargs=setenv bootargs "board=${board} earlycon=uart8250,mmio32,0x11002000 ${bootopts} root=${root}"
#console=${console}

useusb=if usb info; then usb reset;else usb start;fi; setenv device usb;setenv partition 0:1;ls ${device} ${partition}

useinitrd=setenv root "/dev/ram0 rw";setenv bootopts "${bootopts} initrd=${rdaddr},20M";fatload ${device} ${partition} ${rdaddr} ${initrd};
checkrd=if printenv initrd;then run useinitrd;fi

newboot=run checkrd; run buildargs;if printenv fit;then setenv kernel ${fit};if run loadkernel; then bootm ${kaddr}${bootconf}; fi;fi;

checkmmc=if mmc partconf 0; then echo "emmc available";mmcdev="emmc";else echo "sd available";mmcdev="sd";fi
checkspi=if sf probe; then echo "NOR available";spidev="nor";else echo "NAND available";spidev="nand";fi

setbootconf=run checkmmc checkspi;echo $mmcdev $spidev;setenv bootconf "#conf-$mmcdev-$spidev"

wrspimnand=if printenv bl2file;then if fatload $device $partition $loadaddr $bl2file;then mtd erase spi-nand0 0x0 0x100000;mtd write spi-nand0 $loadaddr 0x0 0x100000;else echo "loading bl2 $bl2file failed";fi;else echo "bl2file not defined";fi;if printenv fipfile;then if fatload $device $partition $loadaddr $fipfile;then mtd erase spi-nand0 0x380000 0x200000;mtd write spi-nand0 $loadaddr 0x380000 0x200000;else echo "loading fip $fipfile failed";fi;else echo "fipfile not defined";fi
wremmc=if printenv bl2file;then mmc partconf 0 1 1 1;if fatload $device $partition $loadaddr $bl2file;then mmc erase 0x0 0x400;mmc write ${loadaddr} 0x0 0x400;else echo "loading bl2 $bl2file failed";fi;else echo "bl2file not defined";fi;mmc partconf 0 1 1 0;if printenv fipfile;then if fatload $device $partition $loadaddr $fipfile;then mmc erase 0x3400 0x1000;mmc write ${loadaddr} 0x3400 0x1000;else echo "loading fip $fipfile failed";fi;else echo "fipfile not defined";fi

bootdelay=0
bootcmd=setenv bootdelay 3; run loadenv;bootmenu;

But i have this error :slight_smile: can’t find the partition usb 0:1

I tried to adapter your uenv.txt but i ahve a lot to learn in uboot :slight_smile:

To do something automaticly you have to change builtin env not uenv.txt except you change the bootmenu

And before doing something automatic try to do it manually

run useusb
ls $device $partition
run newboot
1 Like

It is also possible to start GRUB aarch64 EFI binary (using bootefi in U-Boot) or even implement UEFI standard boot (you can build U-Boot with options for that). When booting off block devices (eMMC, SD card or USB) this would be way to support practically all general purpose distributions and even stuff like memtest86 :wink:

1 Like

Hy, thank you for your message :slight_smile:

Hy, I have worked on your uEnv.txt and i managed.

First time, start usb. Looking for a initrd and fit in the usb key. If none found or no key, continue to boot on SD/emmc.

#Constantes
board=DiagBox
bootenv=uEnv.txt
fit=diagbox.itb

loadaddr=0x46000000
kaddr=0x46000000
rdaddr=0x48000000

console=ttyS0,115200n1 earlycon=uart8250,mmio32,0x11002000
bootopts=debug=7

#Variables;
device-diagos=mmc
partition-diagos=0:5
initrd-diagos=$INITRD_OS

device-rescueos=usb
partition-rescueos=0:1
initrd-rescueos=rootfs_rescueos.cpio.gz

#Commandes
usbstart=usb start

test-rescueos=test -e ${device-rescueos} ${partition-rescueos} ${initrd-rescueos}

test-diagos=test -e ${device-diagos} ${partition-diagos} ${bootenv}

loadenvfile=if fatload ${device-diagos} ${partition-diagos} ${loadaddr} ${bootenv};then env import -t ${loadaddr} ${filesize};else echo "fatload (${bootenv}) failed";fi
loadenv=if run test-rescueos;then echo 'uenv.txt nand';else echo 'uenv.txt sur support sd ou emmc';run loadenvfile;fi

buildargs=setenv bootargs "board=${board} earlycon=uart8250,mmio32,0x11002000 ${bootopts}"
useinitrd=setenv root "/dev/ram0 rw";setenv bootopts "${bootopts} initrd=${rdaddr},550M";fatload ${device} ${partition} ${rdaddr} ${initrd};

checkmmc=if mmc partconf 0; then echo "Support : emmc";mmcdev="emmc";else echo "Support : sd";mmcdev="sd";fi
checkspi=if sf probe; then echo "Flash : NOR";spidev="nor";else echo "Flash : NAND";spidev="nand";fi
setbootconf=run checkmmc checkspi;setenv bootconf "#conf-$mmcdev-$spidev"

loadkernel=fatload $device $partition $kaddr ${kernel}

newboot-cmd=run setbootconf;run useinitrd;run buildargs;if printenv fit;then setenv kernel ${fit};if run loadkernel; then bootm ${kaddr}${bootconf};fi;fi;
newboot-env=if run test-rescueos;then echo 'RescueOS';partition=${partition-rescueos};device=${device-rescueos};initrd=${initrd-rescueos};else echo 'DiagOS';partition=${partition-diagos};device=${device-diagos};initrd=${initrd-diagos};fi
newboot=run newboot-env; run newboot-cmd;

wrspimnand=if printenv bl2file;then if fatload $device $partition $loadaddr $bl2file;then mtd erase spi-nand0 0x0 0x100000;mtd write spi-nand0 $loadaddr 0x0 0x100000;else echo "loading bl2 $bl2file failed";fi;else echo "bl2file not defined";fi;if printenv fipfile;then if fatload $device $partition $loadaddr $fipfile;then mtd erase spi-nand0 0x380000 0x200000;mtd write spi-nand0 $loadaddr 0x380000 0x200000;else echo "loading fip $fipfile failed";fi;else echo "fipfile not defined";fi
wremmc=if printenv bl2file;then mmc partconf 0 1 1 1;if fatload $device $partition $loadaddr $bl2file;then mmc erase 0x0 0x400;mmc write ${loadaddr} 0x0 0x400;else echo "loading bl2 $bl2file failed";fi;else echo "bl2file not defined";fi;mmc partconf 0 1 1 0;if printenv fipfile;then if fatload $device $partition $loadaddr $fipfile;then mmc erase 0x3400 0x1000;mmc write ${loadaddr} 0x3400 0x1000;else echo "loading fip $fipfile failed";fi;else echo "fipfile not defined";fi

#Menu
bootdelay=0
bootcmd=setenv bootdelay 2; run loadenv;bootmenu;


boot1=run usbstart;run newboot;

bootmenu_0=1. Demarrer OS.=run boot1
bootmenu_default=0