U-boot standalone hello_world Banana Pi M1

Making u-boot standalone run sample works on banana pi m1

After digging around and dont find anything related to banana pi running u-boot standalone hello_world sample, and do lots of tries to understand how to make the sample code run, finaly I got it working.. more or less.

This is the first tutorial on the subject.

Take note of the load address / entry point

# get go / bootm address
nm examples/standalone/hello_world | grep hello_world
#42000000 T hello_world

The first part, the u-boot spl and the card preparation is needed for the optional parts: bin files our image files, we may choose one.

The img files are better, because may handle cache informations, and are used to load kernels.

Making u-boot spl and prepare the card

# u-boot
git clone git://git.denx.de/u-boot.git u-boot/
cd u-boot
make distclean
make Bananapi_config
make all

# prepare boot partition
mkfs.vfat /dev/sda1
dd if=/dev/zero of=/dev/sda bs=1k count=1023 seek=1
dd if=u-boot-sunxi-with-spl.bin of=/dev/sda bs=1024 seek=8

Using bin files

# mount boot partition
mkdir mnt
mount /dev/sda1 mnt

#copy binary
cp examples/standalone/hello_world.bin mnt

vi mnt/boot.cmd
fatload mmc 0 0x42000000 hello_world.bin
go 0x42000000

mkimage -C none -A arm -T script -d mnt/boot.cmd mnt/boot.scr

umount mnt
rmdir mnt

 

Boot serial log (partial)

Hit any key to stop autoboot: 0
switch to partitions #0, OK
mmc0 is current device
Scanning mmc 0:1…
Found U-Boot script /boot.scr
reading /boot.scr
128 bytes read in 18 ms (6.8 KiB/s)
## Executing script at 43100000
reading hello_world.bin
630 bytes read in 23 ms (26.4 KiB/s)
## Starting application at 0x42000000 …
Example expects ABI version 9
Actual U-Boot ABI version 9
Hello World
argc = 1
argv[0] = “0x42000000”

Crash… should print more…
And in the end (key pressed) should show:
## Application terminated, rc = 0x0

Using img files

#create image
mkimage -A arm -O u-boot -T standalone -C none -a 42000000 -n “Hello World” -d examples/standalone/hello_world.bin examples/standalone/hello_world.img

note: add -e 42000440 if need to set another entrypoint

# mount boot partition
mkdir mnt
mount /dev/sda1 mnt

#copy binary
cp examples/standalone/hello_world.img mnt

Using go the *.img created dos not run, must use bootm 0X42000000

vi mnt/boot.cmd
fatload mmc 0 0x42000000 hello_world.img
bootm 0x42000000

mkimage -C none -A arm -T script -d mnt/boot.cmd mnt/boot.scr

umount mnt
rmdir mnt

 

Boot serial log (partial)

## Executing script at 43100000
reading hello_world.img
694 bytes read in 23 ms (29.3 KiB/s)
## Booting kernel from Legacy Image at 42000000 …
Image Name: Hello World
Image Type: ARM U-Boot Standalone Program (uncompressed)
Data Size: 630 Bytes = 630 Bytes
Load Address: 42000000
Entry Point: 42000000
Verifying Checksum … OK
Loading Standalone Program … OK
Example expects ABI version 9
Actual U-Boot ABI version 9
Hello World
argc = 1
argv[0] = “0x42000000”
argv[1] = “<NULL>”

 

extra: disable ttySo login on console host (remote, not the bb)

systemctl mask serial-getty@ttyS0.service


 

Using lemaker u-boot

 

# prepare the sdcard to new boot software

mkfs.vfat /dev/sda1

dd if=/dev/zero of=/dev/sda bs=1k count=1023 seek=1

 

# copy uboot spl

dd if=/root/hw/bananapi/bootloader/u-boot-sunxi-with-spl.bin of=/dev/sda bs=1024 seek=8

 

# configure the boot
mount /dev/sda1 mnt

vi mnt/uEnv.txt

 

bootargs=console=ttyS0,115200 disp.screen0_output_mode=EDID:1024x768p50 hdmi.audio=EDID:0 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
aload_script=fatload mmc 0 0x43000000 script.bin;
aload_kernel=fatload mmc 0 0x8000 myosa.bin; go 0x8000;
uenvcmd=run aload_script aload_kernel

cp /root/hw/bananapi/kernel/script.bin mnt

cp git/myosa.bin mnt

umount mnt

 

mkimage -C none -A arm -T script -d mnt/boot.cmd mnt/boot.scr

 

setenv bootargs console=ttyS0,115200 noinitrd disp.screen0_output_mode=EDID:1280x720p50 init=/init root=/dev/mmcblk0p2 rootwait panic=10 ${extra}
fatload mmc 0 0x43000000 script.bin
fatload mmc 0 0x8000 myosa.bin
go 0x8000


More info

http://dl.linux-sunxi.org/A20/A20%20User%20Manual%202013-03-22.pdfhttp://dl.linux-sunxi.org/A20/A20%20User%20Manual%202013-03-22.pdfhttp://dl.linux-sunxi.org/A20/A20%20Brief%202013-04-07.pdfhttps://github.com/OLIMEX/OLINUXINO/blob/master/HARDWARE/A20-PDFs/A20%20Datasheet%20v1.0%2020130227.pdf
http://mirror.lemaker.org/Banana%20Pro%20&%20Pi%20User%20Manual-V1.0.pdf

A20 User’s manual says “After power on, the system will try to boot from SDC0, NAND, SDC2, SPI0, and USB, respectively. In Banana Pi, there is no NAND and the default boot device is SD0.    According to BROM, linux-sunxi-org, the boot sequence of A20 (probably A10, A13, A31 as well) is as follows:
BROM(FEL, 0xffff0000) -> BROM(0xffff4000, magic eGON.BRM at 0xffff4004) -> boot0 -> boot1 -> uboot

Note that according to here, linux-sunxi u-boot is fully SPL enabled which means it supports booting directly on the bare metal with no help from the Allwinner bootloaders. U-Boot SPL fully replaces Allwinner boot0 & boot1.
[BROM]    BROM in A20 is at the address 0xFFFF0000, After power up, arm core will fetch the first instruction at 0xFFFF0000 and execute it. The BROM is actually split up into two parts. FEL mode and eGON.BRM. FEL mode is at the start, at 0xffff0000 followed by eGON.BRM at 0xffff4000.
At 0xffff0000 is the reset vector which jumps to 0xffff0028. There it loads 0xffff4000 into the program counter to be executed next.
The extraction of BROM and diassemble can be found at github.
[SD]      Load 4k data from sdcard slot 0 beginning at offset 8k to the internal sram, check if the data has a magic string(eGON.BT0), if so, it’s a boot0 head. Get boot0 size from the boot0 head, and load the whole boot0. If the checksum of boot0 is ok, will jump to boot0. Any of above is wrong, will jump to FEL.

 

SD Card Layout
start size usage0 8KB Unused, available for partition table etc.8 24KB Initial SPL loader32 512KB u-boot544 128KB environment672 352KB reserved1024 – Free for partitions