May 27, 2018

Orange Pi PC - U-boot on an SD card to network boot Kyu

This is a quick "cookbook" style description of how to put U-boot onto an SD card for an Orange Pi PC and have it do a network boot via DHCP and TFTP. If you want more details, you can find them on two of my other writeups.

I do all this using the serial console.

Recent changes

I used to load and run my images at 0x42000000, but later decided that there was no reason not to load and run them at 0x40000000. However, this requires changing some of the U-Boot setup as described below. I did this:
setenv loadaddr 0x40000000
setenv bootaddr 0x40000000
setenv boot_kyu echo Booting Kyu via dhcp/tftp\; dhcp\; go \${bootaddr}
setenv bootcmd run boot_kyu
saveenv
This seemed to do the trick. Given that the SD card in my PC unit is now epoxied in place, it is handy to be able to just configure these things in the U-Boot shell.

Build U-boot

In case you don't want to do this yourself, I offer you the binary file I use: To build this, I obtained recent U-boot sources (v2016.11) and applied the Armbian patches. Then I did this:
cd u-boot
export CROSS_COMPILE=arm-linux-gnu-
make distclean
make orangepi_pc_plus_defconfig
make all
Yes indeed I built this for the PC Plus, but it works just fine on the PC. The main difference between the two is that the PC Plus allows for two emmc devices (the SD card and the onboard eMMC), but it works just fine if there is only one (the SD card).

Copy U-boot to the SD card

To do this you will need a blank SD card (or one that you are willing to erase and dedicate to this purpose).

I use my Fedora linux machine and a USB to SD card gizmo to put U-boot on the SD card. On my system the SD card appears as device /dev/sdc. You must be sure to get this right. The risk in getting this wrong is that you will send the dd output to one of the hard drives on your system and have serious data loss, not to mention not being able to boot and run your linux system. You have been warned!

dd if=/dev/zero of=/dev/sdc bs=1024 count=2048
dd if=u-boot-sunxi-with-spl.bin of=/dev/sdc bs=1024 seek=8
sync
447+1 records in
447+1 records out
458738 bytes (459 kB) copied, 0.0609168 s, 7.5 MB/s
Plug the SD card into your Orange Pi, and apply power ....

Configure U-boot

Interrupt U-boot by typing any character as suggested. This will give the U-boot interactive prompt. Then the version command should give this:
=> version
U-Boot 2016.11-g29e0cfb-dirty (Jan 09 2017 - 11:19:55 -0700) Allwinner Technology
arm-linux-gnu-gcc (GCC) 6.1.1 20160621 (Red Hat Cross 6.1.1-2)
GNU ld version 2.27-3.fc24
Then issue the following commands (you may as well cut and paste them from here):
setenv loadaddr 0x40000000
setenv bootaddr 0x40000000
setenv boot_kyu echo Booting Kyu via dhcp/tftp\; dhcp\; go \${bootaddr}
setenv bootcmd run boot_kyu
saveenv
Before you hit reset, use the following command to get the MAC address.
=> env print ethaddr
ethaddr=02:20:7f:9b:xx:yy

Set up your DHCP (and TFTP) servers

I already have these set up on my system, so I just need to add an entry for this new board (and this is why we fetched the MAC address) On my Fedora 24 system, I add the following to /etc/dhcpd/dhcpd.conf
    host orangepiplus2 {
	hardware ethernet 02:20:7f:9b:xx:yy;
	fixed-address 192.168.0.61;
	option host-name "orangepiplus2";
	server-name "trona";
	filename "orange.bin";
    }
Then I do this:
systemctl restart  dhcpd.service
After this type "boot" to the U-boot prompt (or else hit reset or power cycle). It will boot the file "orange.bin" from your tftp directory (in my case /var/lib/tftpboot).

Works great. Being able to save the U-boot environment on MMC is fantastic!


Have any comments? Questions? Drop me a line!

Tom's electronics pages / tom@mmto.org