Bananapi BPI-R3 bootloader

Hi Ladies and Gentlemen :slight_smile:

I worked on a sbc clearfog pro before.

After making the u-boot.bin and compile atf, i had a flash-image.bin for this sbc.

It allowed me to do this command Line : dd if=flash-image.bin of=/dev/sdb BS=512.

I looked on thé wiki for the bootloader. After compile the atf, there is no flash-image.bin

Is it possible to use this method for bananapi r3? I am e newbie with bananapi ^^

Thanks by advance

Doudoo Tiana.

You should use the way designed for r3 as every sbc has own offsets where bootrom looks for data.

R3 uses partitions for bl2 and fip which makes it easier to flash and not struggling with offsets.

Just look into my uboot-repo for 2022-07-r3 and r3-atf branch. This is my last working state (except boot0 is booted by default instead of the bootcmd).

Hy @frank-w,

Thank you to answer me so quickly :slight_smile:

I have compile u-boot and atf and i see bl2.bin and fip.bin :slight_smile:

I will search how to apply and adapt these for buildroot

Thanks again

Atf branch has gpt bary files which have to be flashed first at offset 0x0. The you have the 2 partitions for bl2+fip. Buildroot can be loaded via uboot as initrd.

You need linux kernel fit and rootfs.cpio.xz (or other compression) when you have booted till uboot. My uboot has some functions in environment which handle initrd by defining “initrd” and “fit” variable and running “newboot”

1 Like

bpi-r64-storage

Hy, Thanks to answer me again :slight_smile:

I will follow these instructions when receive my R3 :slight_smile:

this image is for bpi-r64. r3 has gpt file in the r3-atf branch which creates partitions for bl2 and fip

Hy, thank again for your Answers :slight_smile:

I have compiled kernel, uboot and atf.

The gpt file you mentioned is called “bpi-r3.gpt” in the atf folder ?

I have put the image for bpi-r64 thinking the address of each files were the same for r3.

I have tried to adapt my buildroot with all you say and the files i have.

i have written a new genimage.cfg like this :

image boot.vfat {
  name = "boot"
  vfat {
    label = "boot"
    files = {
      "/diagbox_r3/diagos/buildroot/board/boot/extlinux/dtb-alpha.dtb",
      "/diagbox_r3/diagos/buildroot/board/boot/extlinux/dtb-beta.dtb",
	  "/diagbox_r3/diagos/buildroot/board/boot/extlinux/Image-alpha",
	  "/diagbox_r3/diagos/buildroot/board/boot/extlinux/Image-beta",
	  "/diagbox_r3/diagos/buildroot/board/boot/extlinux/extlinux.conf",
	  "/diagbox_r3/diagos/buildroot/board/boot/extlinux/extlinux-alpha.conf",
	  "/diagbox_r3/diagos/buildroot/board/boot/extlinux/extlinux-beta.conf",
	  "/diagbox_r3/diagos/buildroot/board/boot/extlinux/alpha-release",
	  "/diagbox_r3/diagos/buildroot/board/boot/extlinux/beta-release",
    }
  }
  size =90M
}

image data.ext4 {
  name = "data"
  ext4 {
    label = "data"
  }
  size = 800M
  mountpoint = "/data"
}

image sdcard.img {
	hdimage {
	}
	partition gpt {
		in-partition-table = "no"
		image = "bpi-r3.gpt"
		offset = 0x0
	}
	partition bl2 {
		in-partition-table = "no"
		image = "bl2.bin"
		offset = 1024
	}
	partition bl2 {
		in-partition-table = "no"
		image = "fip.bin"
		offset = 2048
	}
	partition boot {
		partition-type = 0xC
		bootable = "true"
		image = "boot.vfat"
	}
	
	partition rootfs {
		partition-type = 0x83
		image = "rootfs.ext4"
	}
		
	partition rootfs-beta {
		partition-type = 0x83
		image = "rootfs-beta.ext2"
	}
	
	partition data.ext4 {
		partition-type = 0x83
		image  = "data.ext4"
	}	
		
}

When i receive my board, i will try :slight_smile: Thank again to take time to answer me

sorry, noticed i had not pushed r3-atf branch to my u-boot-repo after copy it from the r3-bsp repo

have now pushed

bpi-r3.gpt is afair the old gpt with 32MB boot and 100M root partition…have recreated gpt with 100MB boot and 6G rootfs:

https://github.com/frank-w/u-boot/blob/r3-atf/gpt_sdmmc_100m6g.img

i’m not sure whats the config-file you have created and with which dtbs…you have to use the bpi-r3 dtb for sd first and a kernel image having all drivers needed for r3, current way is to use a fit image

1 Like

Hy, I have change for the new gpt you mentioned.

For dtb and kernel, i have use the kernel’s source in your repo (5.19-r3). I have just adapted the name of the dtbs for my project. :slight_smile:

you should use 6.0-r3 as this supports both sfp slots

1 Like

thank for the advice. I will change my kernel for this version :slight_smile:

What do you try to make with this config?

Imho the second partition needs to be named fip and the n-partition-table needs to be set to yes and offset dropped.

I don’t know if this works as expected as the partition table needs to be read again after the gpt file is written

1 Like

Hy, I try to implant the BL2 and the FIP with buildroot.

I have change the configuration with your Suggestions and it ends with no error :slight_smile:

image sdcard.img {
	hdimage {
	}

	partition gpt {
		in-partition-table = "true"
		image = "gpt.img"
	}

	partition bl2 {
		in-partition-table = "true"
		image = "bl2.bin"
	}

	partition fip {
		in-partition-table = "true"
		image = "fip.bin"
	}

	partition boot {
		partition-type = 0xC
		bootable = "true"
		image = "boot.vfat"
	}
	
	partition rootfs {
		partition-type = 0x83
		image = "rootfs.ext4"
	}
		
	partition data.ext4 {
		partition-type = 0x83
		image  = "data.ext4"
	}	
		
}

Now, i will wait the arrival of my R3, i hope next week to try my sdcard.img

Thank again for your help

gpt is directly on disk at offset 0, so leave this as you had it…but i guess it will fail because the gpt is not reloaded after writing the gpt-binary

my current way is to build a basic image by flashing the gpt+bl2+fip, put linux fit and buildroot initrd to boot-partition and load them using my builtin environment functions

And afair you need to use bl2.img (with mtk headers)…not bl2.bin

1 Like

Hy ^^ I will try when i receive the R3. Thanks again for all your help.

Hy. I have received my r3 :slight_smile: I have tried with openwet, to be sure that thé board works. All fine ^^

I have tried with my OS, it doesn’t work like you think ^^

I will work on it

I forgotten the error code : BL2 failed to laod image id 3 (-2)

look if you have a fip-partition and flash fip to it, if it does not work try rebuilding uboot/fip

Hy :slight_smile:

When i checked the partitions of my SDcard ( fdisk -l), i have :

/    dev/sdb1                 34     424      391 195,5K  0 Vide  ==> BL2

    /dev/sdb2                425    1676     1252   626K  0 Vide ==>fip

    /dev/sdb3    *          1677  185996   184320    90M  c W95 FAT32 (LBA) ==> boot

    /dev/sdb4             185997 2541198  2355202   1,1G  f Étendue W95 (LBA) 
    /dev/sdb5             185998  902797   716800   350M 83 Linux ==>rootfs (buildroot)

    /dev/sdb6             902799 2541198  1638400   800M 83 Linux ==>Partition i created for Storage

Hy again ^^

I have tried to install manually.

first, thank to this link, i have done another gpt.

python mtk_gpt.py --i example/mt7986-sd.json --o gpt.gpt

In the mt7986-sd.json there is :

{
	"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" : 82943,
		"uuid" : "{971f7556-ef1a-44cd-8b28-0cf8100b9c7e}"
	},

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

dd if=gpt.gpt of=/dev/sdb ==> ton install the gpt dd if=bl2.img of=/dev/sdb1 ==> for the bl2 dd if=fip.bin of=/dev/sdb4 ===> for the fip dd if=boot.vfat of=/dev/sdb5 ==> for partition with kernel, extlinux files dd if=rootfs.ext4 of=/dev/sdb6 ==> for partition rootfs

But i don’t know what i must put for : u-boot-env and factory. Can i delete the partition factory?