August 23, 2020

Setting up an Armbian SD card for Uboot TFTP booting

This is what I have always done for my Kyu RTOS hacking. I wanted to document how to do this starting with a modern Armbian distribution.

I am working with my H5 chip based "Orange Pi PC 2".

Make the SD card

I began with the 4G Armbian buster distribution and an 8G micro-SD card.
su
dd bs=64M if=Armbian_20.05.2_Orangepipc2_buster_current_5.4.43_desktop.img of=/dev/sdf
That is easy enough. This boots with the following U-Boot greeting.
U-Boot 2020.04-armbian (Jun 03 2020 - 07:47:47 +0200) Allwinner Technology

Fiddle with the U-Boot boot script

Interestingly enough, a fairly complex script governs how U-Boot boots linux. This script is in /boot/boot.scr in the linux filesystem. Alongside it is /boot/boot.cmd, which is the plain text of the above. In the midst of the boot messages, you will see:
Found U-Boot script /boot/boot.scr
3033 bytes read in 3 ms (987.3 KiB/s)
The "scr" file is a U-Boot "uImage", as follows:
file boot.*
boot.cmd: ASCII text
boot.scr: u-boot legacy uImage, , Linux/ARM, Script File (Not compressed), 2969 bytes, Mon Jun  8 16:47:26 2020, Load Address: 0x00000000, Entry Point: 0x00000000, Header CRC: 0xFE309142, Data CRC: 0x4D3837E4
The scr file is generated from the cmd file via the command:
mkimage -C none -A arm -T script -d boot.cmd boot.scr

Replace this with something that will boot Kyu

My usual scheme looks like this:
setenv bootaddr 0x40000000
setenv boot_kyu "echo Booting Kyu via dhcp ; dhcp ${bootaddr}; go ${bootaddr}"
setenv bootcmd "run boot_kyu"
I renamed the existing boot.cmd and .scr to be:
ORIG_boot.cmd
ORIG_boot.scr
Then I hacked this into the start of boot.cmd
# TJT -- edits for Kyu booting

setenv bootaddr 0x40000000
#setenv boot_kyu "echo Booting Kyu via dhcp ; dhcp ${bootaddr}; go ${bootaddr}"
#setenv bootcmd "run boot_kyu"

echo Booting Kyu via dhcp
dhcp ${bootaddr}
go ${bootaddr}
I ran the mkimage command, rebooted, and it booted Kyu via tftp just as it should.

Of course you can't boot Armbian any longer. To put things back the way they were, you have to pull the SD card, put it into a card reader and mount it on your linux desktop, then copy ORIG_boot.scr back to boot.scr.

This is quick and easy.


Have any comments? Questions? Drop me a line!

Tom's electronics pages / tom@mmto.org