Bananapi BPI-R3 bootloader

i have this error :

fit=bpi-r3.itb
failed to load 'bpi-r3.itb :frowning:

Yes,my uboot tries to load this file from boot partitition by default. Please do not delete any partitions.

That means uboot (fip) is correctly loaded.

See uEnv_r3.txt for more
starting from bootcmd variable. It tries to load uEnv.txt from boot partition first to overwrite builtin variables and then show bootmenu.

You can disable the bootcmd (with # before) in the builtin environment (need recompile/reflash) or exit the menu while booting to uboot console. Or you overwrite bootmenu_default and/or the bootmenu entries. The fit variable is picked by newboot and device/partition defines where to load it

uboot-env is if uboot writes his environment direct to mmc (not via file).this is afaik (if not done via offset in any header by vendor) not yet configured in my uboot. Please only touch last 2 partitions,not the first 4.

Factory is imho for firmware or a recovery system. Currently unused.

1 Like

Hy,

I only touche the two last partitions, like you advise me.

I have tried with bootcmd :

MMC:   mmc@11230000: 0
Loading Environment from MMC... unable to read ssr
unable to read ssr
*** Warning - bad CRC, using default environment

In:    serial@11002000
Out:   serial@11002000
Err:   serial@11002000
Net:
Warning: ethernet@15100000 (eth0) using random MAC address - 32:6a:16:0b:54:f7
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 from SD/EMMC.
      U-Boot console


  Press UP/DOWN to move, ENTER to select, ESC/CTRL+C to quit
            extlinux/

0 file(s), 1 dir(s)

enter kernel name: Image-rescue
kernelinput=Image-rescue
## Error: "initrd" not defined
fit=Image-rescue
Failed to load 'Image-rescue'
RescueOS>

You have a file named Image-rescue on the boot-partition ( 0:5 )? In your putput i see only a folder extlinux
if Your file is located there you have to add this in front to your filename

E.g. extlinux/Image-rescue

It needs to be a fit. To load image.gz and dtb separately you have to change newboot function

If you want to use distroboot,you have to change config and drop my environment

1 Like

Thank you to answer me :slight_smile:

Yes the kernel image is : extlinux/Image-rescue ( the Name is for my project).

I use Image for kernel, note image.gz,is it possible? If not, i have image.gz so i can adapt.

I search to load Image and dtb separately.

I wll search in the config where i must modify to enable it. Configuration of uboot?

Thank again

you have to do fatload for Image(.gz) and dtb separately

Why don’t you want to use fit?

as i said, if you want to use distroboot, you have to enable it and disable default environment file.

but i have not tested distroboot yet, as with environment we can do some tricks like sd/emmc and nand/nor detection in uboot to load the right dt-overlay. afaik this is not possible in distroboot

hy :slight_smile:

I need to load separately dtb and Image, for the management of my board ( various rootfs with various kernel and dtb).

I have tried to modify the configuration of uboot : here the defconfig

Now i have the error distro_bootcmd

it’s going step by step :slight_smile:

i think i have a clue

https://github.com/lexa2/u-boot/commit/9167ee7db6f2a640bd40d2feb495a6aaf0b61fb6

i think i must adapt this patch for mt7986, what do you think?

Looks good,i’ve seen distroboot on r2pro uboot (and still use it on this board). And noticed that it needs some environment vars which are set in code and overridden by default env file which i use on mtk boards.

Hy;

Finally, i wil ltry with system fit ( by searching, i have found how to do the fit and i can put script in for select the rootfs )

But when i boot, i have an error : new format image overwritten - must reset the board to recover

here the config of the fit :

/dts-v1/;

 

/ {

description = "Simple image with single Linux kernel and FDT blob for GLMF";

#address-cells = <1>;

 

images {

kernel {

description = "Kernel";

data = /incbin/("Image-rescue");

type = "kernel";

arch = "arm64";

os = "linux";

compression = "none";

load = <0x46000000>;

entry = <0x46000000>;


};

fdt-1 {

description = "Flattened Device Tree blob";

data = /incbin/("dtb-rescue.dtb");

type = "flat_dt";

arch = "arm64";

compression = "none";

};

};

 

configurations {

default = "conf-1";

conf-1 {

description = "configuration 1 (Kernel & dtb)";

kernel = "kernel";

fdt = "fdt-1";

};

};

};

And here the config for the gpt editor :

	{
	"bl2" : {
		"start": 1024,
		"end" : 8191,
		"attributes": 4,
		"uuid" : "{19a4763a-6b19-4a4b-a0c4-8cc34f4c2b8a}"
	},

	"u-boot-env" : {
		"start": 8192,
		"end" : 9215,
		"uuid" : "{19a4763a-6b19-4a4b-a0c4-8cc34f4c2ab9}"
	},

	"factory" : {
		"start": 9216,
		"end" : 13311,
		"uuid" : "{8142c1b2-1697-41d9-b1bf-a88d76c7213f}"
	},

	"fip": {
		"start": 13312,
		"end" : 17407,
		"uuid" : "{18de6587-4f17-4e08-a6c9-d9d3d424f4c5}"
	},

	"kernel" : {
		"start": 17408,
		"end" : 201728,
		"uuid" : "{971f7556-ef1a-44cd-8b28-0cf8100b9c7e}"
	},

	"rootfs" : {
		"start": 201729,
		"end" : 1018929,
		"uuid" : "{309a3e76-270b-41b2-b5d5-ed8154e7542b}"
	}
}

Why not use my bpi-r3.its? It builds in the dto too.

You can fully compile all with my build.sh (or look there how i do it)

But i’m not sure distroboot can handle fit and how. R2pro used Image+fdt. It’s your choice.

As far as your uboot gets loaded your partition table is right. You have to tell uboot where (mmc 0:5 points to your/our kernel partition on first and only mmc controller) next stage (linux kernel) is located and which files should get loaded (filenames and type).

1 Like

Hy :slight_smile:First, thank you.

Thanks to your help, i succeeded to do my fit img (for kernel and dtb). When i flash the rootfs directly in the partition 6, it boots and it works :slight_smile: :slight_smile:

Curious as i am , i tried to include the rootfs (rootfs.cpio.gz) in the fit , it fails

## Error: "initrd" not defined
fit=diagbox.itb
75427660 bytes read in 7556 ms (9.5 MiB/s)
## Loading kernel from FIT Image at 46000000 ...
   Using 'conf-1' configuration
   Trying 'kernel' kernel subimage
     Description:  Kernel
     Type:         Kernel Image
     Compression:  gzip compressed
     Data Start:   0x460000c0
     Data Size:    9023926 Bytes = 8.6 MiB
     Architecture: AArch64
     OS:           Linux
     Load Address: 0x44000000
     Entry Point:  0x44000000
     Hash algo:    sha1
     Hash value:   db19bf77644b49dd92e368d44d550ee7622c4975
   Verifying Hash Integrity ... sha1+ OK
## Loading ramdisk from FIT Image at 46000000 ...
   Using 'conf-1' configuration
   Trying 'ramdisk' ramdisk subimage
     Description:  ramdisk
     Type:         RAMDisk Image
     Compression:  gzip compressed
     Data Start:   0x4689fec8
     Data Size:    66382645 Bytes = 63.3 MiB
     Architecture: AArch64
     OS:           Linux
     Load Address: unavailable
     Entry Point:  unavailable
     Hash algo:    sha1
     Hash value:   ae12420ae644183a5c56ce63f35ded3fcc38ee29
   Verifying Hash Integrity ... sha1+ OK
WARNING: 'compression' nodes for ramdisks are deprecated, please fix your .its file!
## Loading fdt from FIT Image at 46000000 ...
   Using 'conf-1' configuration
   Trying 'fdt' fdt subimage
     Description:  Flattened Device Tree blob
     Type:         Flat Device Tree
     Compression:  uncompressed
     Data Start:   0x4689b36c
     Data Size:    19100 Bytes = 18.7 KiB
     Architecture: AArch64
     Load Address: 0x47000000
     Hash algo:    sha1
     Hash value:   2fba374f801b81c839aa55c2f3c7182b44d4a4f3
   Verifying Hash Integrity ... sha1+ OK
Error: fdt overwritten
Could not find a valid device tree
RescueOS>

Here,the config for create the fit ( i have worked thanks to yours) :slight_smile:

/dts-v1/;
/ {
	description = "Kernel et dtb pour RescueOS";

	#address-cells = <1>;
	images {
		kernel {
			description = "Kernel";
			data = /incbin/("Image.gz");
			type = "kernel";
			arch = "arm64";
			os = "linux";
			compression = "gzip";
			load = <0x44000000>;
			entry = <0x44000000>;
			hash-1 {
				algo = "sha1";
			};
		};
		fdt {
			description = "Flattened Device Tree blob";
			data = /incbin/("diagbox.dtb");
			type = "flat_dt";
			arch = "arm64";
			load = <0x47000000>;
			compression = "none";
			hash-1 {
				algo = "sha1";
			};
		};
		ramdisk {
			description = "ramdisk";
			data = /incbin/("rootfs.cpio.gz");
			type = "ramdisk";
			arch = "arm64";
			os = "linux";
			compression = "gzip";
			hash-1 {
				algo = "sha1";
			};
		};
	};
 
	configurations {
		default = "conf-1";
		conf-1 {
			description = "Configuration";
			kernel = "kernel";
			fdt = "fdt";
			ramdisk = "ramdisk";
			hash-1 {
				algo = "sha1";
			};
		};
	};
};

And here,the config for the gpt :

{
	"bl2" : {
		"start": 1024,
		"end" : 8191,
		"attributes": 4,
		"uuid" : "{19a4763a-6b19-4a4b-a0c4-8cc34f4c2b8a}"
	},

	"u-boot-env" : {
		"start": 8192,
		"end" : 9215,
		"uuid" : "{19a4763a-6b19-4a4b-a0c4-8cc34f4c2ab9}"
	},

	"factory" : {
		"start": 9216,
		"end" : 13311,
		"uuid" : "{8142c1b2-1697-41d9-b1bf-a88d76c7213f}"
	},

	"fip": {
		"start": 13312,
		"end" : 17407,
		"uuid" : "{18de6587-4f17-4e08-a6c9-d9d3d424f4c5}"
	},

	"kernel" : {
		"start": 17408,
		"end" : 293888,
		"uuid" : "{971f7556-ef1a-44cd-8b28-0cf8100b9c7e}"
	},

	"rootfs" : {
		"start": 293889,
		"end" : 1342465,
		"uuid" : "{309a3e76-270b-41b2-b5d5-ed8154e7542b}"
	},

	"data" : {
		"start": 1342466,
		"end" : 6585346,
		"uuid" : "{309a3e76-270b-41b2-b5d5-ed8154e7542b}"
	}
}

Thanks again for all your help

maybe you have to relocate the initrd when using in fit
i changed position of fdt to apply the dtbo’s for nor/nand.but you can use standalone initrd by defining the initrd variable and calling newboot
you can take out the initrd address from there as it was working also after the relocation of base fdt

1 Like

Hy I succeeded ^^ I have delete the Line with adresse load for the dts, in the config of the fit.

My r3 boots with my custom Linux.

A lot thanks you for your help.

At least when you need the dtoverlays you need to add it again and relocate ramdisk to another position (see setinitrd variable)

My uboot uses 0x48000000 as rdaddr

In my opinion inird should not be included in fit as it grows the fit and with multiole fit you have redundant data. So i decided to load initrd separately.

1 Like

Hy Frank.

I test the initrd in the fit and will test the initrd separately, this weekend, to get an idea of ​​the advantages and disadvantages for each methods.

:slight_smile:

Hy again me :slight_smile:

I have some question :.

1- I dont see the nor flash when i do a fdisk -l : For my dtb, i use the dts mt7986a-bananapi-bpi-r3.dts. I try to include to add this Line : :#include “mt7986a-bananapi-bpi-r3-nor.dts”

Must i copy the content directly in mt7986a-bananapi-bpi-r3.dts?

2-to boots in emmc, i see thé tutorial on thé wiki. So, first Time must to boot on nand or nor flash.

About Uboot, which defconfig of R3 use sd, emmc or mt7986_spim_nor_rfb_defconfig?

For atf, just change BOOT_DEVICE for nor instead sdmmc.

Thanks by advance

The nor and nand dts are device tree overlays. These are compuled separately (see my build.sh) and the binaries added to fit. From uboot you can set bootconf to e.g. “#conf-sd-nor” before calling newboot. I’m trying to add automatic selection/generation of bootconf. Nor had some annoying messages which i wanted to fix first.

And you will not see them with fdisk. They are mapped to mtd partitions
you should see them with cat /proc/partitions and a message of the driver in dmesg

Hy again me ^^.

Thank you for nand/nor. I use nand thanks to your help.

Like i said, i tried to put rottfs in the fit (it’s the best way for my project i think).

The problem :

When i let the line load = <0x47000000>; on the fit config, i have this error :

  Press UP/DOWN to move, ENTER to select, ESC/CTRL+C to quit
## Error: "initrd" not defined
fit=diagbox.itb
75430704 bytes read in 7555 ms (9.5 MiB/s)
## Loading kernel from FIT Image at 46000000 ...
   Using 'conf-1' configuration
   Trying 'kernel' kernel subimage
     Description:  Kernel
     Type:         Kernel Image
     Compression:  gzip compressed
     Data Start:   0x460000c0
     Data Size:    9023926 Bytes = 8.6 MiB
     Architecture: AArch64
     OS:           Linux
     Load Address: 0x44000000
     Entry Point:  0x44000000
     Hash algo:    sha1
     Hash value:   db19bf77644b49dd92e368d44d550ee7622c4975
   Verifying Hash Integrity ... sha1+ OK
## Loading fdt from FIT Image at 46000000 ...
   Using 'conf-1' configuration
   Trying 'fdt' fdt subimage
     Description:  Flattened Device Tree blob
     Type:         Flat Device Tree
     Compression:  uncompressed
     Data Start:   0x4689b36c
     Data Size:    19100 Bytes = 18.7 KiB
     Architecture: AArch64
     Load Address: 0x47000000
     Hash algo:    sha1
     Hash value:   2fba374f801b81c839aa55c2f3c7182b44d4a4f3
   Verifying Hash Integrity ... sha1+ OK
Error: fdt overwritten
Could not find a valid device tree
RescueOS>

When i delete the line `load = <0x47000000>; it boots randomly, sometimes it’s ok and sometime no.

Here the uEnv_r3.txt of uboot

board=bpi-r3
device=mmc
partition=0:5
bootenv=uEnv.txt
bootdevice=sd

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

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

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;

And here the fit configuration :

/dts-v1/;
/ {
	description = "Kernel et dtb pour RescueOS";

	#address-cells = <1>;
	images {
		kernel {
			description = "Kernel";
			data = /incbin/("Image.gz");
			type = "kernel";
			arch = "arm64";
			os = "linux";
			compression = "gzip";
			load = <0x44000000>;
			entry = <0x44000000>;
			hash-1 {
				algo = "sha1";
			};
		};
		fdt {
			description = "Flattened Device Tree blob";
			data = /incbin/("diagbox.dtb");
			type = "flat_dt";
			arch = "arm64";
			load = <0x47000000>;
			compression = "none";
			hash-1 {
				algo = "sha1";
			};
		};
		fdt-nand{
			data = /incbin/("diagbox-nand.dtbo");
			type = "flat_dt";
			arch = "arm64";
		};
	};

	ramdisk {
			description = "ramdisk";
			data = /incbin/("rootfs.cpio.gz");
			type = "ramdisk";
			arch = "arm64";
			os = "linux";
			compression = "gzip";
			hash-1 {
				algo = "sha1";
			};
		};

	configurations {
		default = "conf-1";
		conf-1 {
			description = "Configuration";
			kernel = "kernel";
			fdt = "fdt", "fdt-nand";
			ramdisk = "ramdisk";
			hash-1 {
				algo = "sha1";
			};
		};
	};
};

I think it’s a problem of load address.

Have you an Idea?

Thank by advance

Loadaddr for fdt is needed when applying dto,so let it in.

Try adding loadaddr to ramdisk with value 0x48000000 ( rdaddr from my env)