November 6, 2018

Orange Pi PC 2 - network booting

My desire is to get one of these boards set up to network boot via TFTP. This is what I have done with other ARM boards, like the H3 based Orange Pi PC. The usual method is to set up a linux SD card, then interrupt U-Boot, change some environment variable settings, and voila!

I do this with an SD card holding Ubuntu Server (Ubuntu Xenial). To my surprise (and dismay) the U-Boot on this card has no networking configured. So I will have to either build U-boot from source or get lucky with some other SD card image. This card runs U-Boot 2014.07, built Nov 09, 2016. Once it boots, it announces itself as "Ubuntu 16.04.1 LTS Orangepi ttyS0".

Try a Raspbian image

On this page, I find the file Raspbian_server_For_PC2_H5_V0_1.rar. Nothing like using offbeat archive tools. I install the "unrar" package on my machine and do this:
unrar l *.rar
unrar e *.rar
unxz Raspbian_server_For_PC2_H5_V0_1.img.xz
md5sum Raspbian_server_For_PC2_H5_V0_1.img
cat *.md5sum
su
dd if=Raspbian_server_For_PC2_H5_V0_1.img of=/dev/sdf bs=128k
exit
This verifies (visually) the md5sum, then puts the image onto a brand new 16G microSD card I have handy. The image itself is just over 1G, so there is a lot of wasted room on the card, but that is OK. Insert the card into the PC 2, connect power and interrupt the boot sequence by typing.
U-Boot 2014.07-g486bfb4 (Mar 27 2017 - 14:27:38) Allwinner Technology
Typing "help" shows no network commands configured here either, so no luck. Typing "boot" continues the boot, and it eventually announces itself as
Raspbian GNU/Linux 8 OrangePI ttyS0
uname -a
Linux OrangePI 3.10.65 #3 SMP PREEMPT Tue Nov 15 09:46:50 CST 2016 aarch64 GNU/Linux
cat /proc/cpuinfo
cat /proc/cpuinfo
Processor	: AArch64 Processor rev 4 (aarch64)
processor	: 0
processor	: 1
processor	: 2
processor	: 3
Features	: fp asimd aes pmull sha1 sha2 crc32 wp half thumb fastmult vfp edsp neon vfpv3 tlsi vfpv4 idiva idivt
CPU implementer	: 0x41
CPU architecture: 8
CPU variant	: 0x0
CPU part	: 0xd03
CPU revision	: 4
Hardware	: sun50iw2
Serial		: 44005035c120103e078c
You login as root, password "orangepi".

Orange Pi Build (github)

I cloned the above and began following the instructions. When you launch the build script (the clone just gives you a bundle of bash scripts) the first thing it does is to prompt and ask you for your root password. Does anyone else see a problem with this? Obvious security concerns aside, is there any reason building a linux image should require root permissions? I don't think so, and I hope you don't either. This may be worth dissecting and neutering the root permission business (not to mention auditing the whole mess), but I don't have time now and am not going to mess with this.

Build U-boot from source

You have two choices. You can grab one of the mainstream U-Boot releases or you can clone the sunxi fork. Allegedly all of the Allwinner code has been pushed upstream to the mainline and they sort of encourage you to use that (although none of their distributed linux images do). I decided to try the mainstream approach and grabbed the 2018.09 distribution from Denx.

I needed to install several python related packages on my Fedora system first:

su
dnf install swig
dnf install python-devel python3-devel
After this I edited the Makefile, adding the following near the top. I prefer this to setting an environment variable, because I am lazy, and typically I have to build U-Boot many times before I get what I want and need.
CROSS_COMPILE=aarch64-linux-gnu-
After this:
cd u-boot-2018.09
make orangepi_pc2_defconfig
make
That rattles along nicely, but ultimately gives me a warning like this:
WARNING: BL31 file bl31.bin NOT found, resulting binary is non-functional
Please read the section on ARM Trusted Firmware (ATF) in board/sunxi/README.sunxi64

Building the trusted firmware thing

The README.sunxi64 file has a lot of great information. A bonus is that it tells me how I can place U-Boot into the 2M of NOR flash that is on the PC 2, which I am eager to do someday. First though we need to figure out this bl31.bin file thing. I follow instructions in the README file:
git clone https://github.com/apritzel/arm-trusted-firmware.git
git checkout allwinner
export CROSS_COMPILE=aarch64-linux-gnu-
make PLAT=sun50iw1p1 DEBUG=1 bl31
There are many branches (use "git branch -a" to take a look). This builds beautifully without errors or warnings and concludes with the following message:
Built build/sun50iw1p1/debug/bl31.bin successfully
The instructions then state: "The resulting binary is build/sun50iw1p1/debug/bl31.bin. Either put the location of this file into the BL31 environment variable or copy this to the root of your U-Boot build directory (or create a symbolic link)." I copied the file to the U-boot root, then repeated the U-Boot build via:
make clean
make
As far as I am concerned, the final product is u-boot-sunxi-with-spl.bin. I grab a 16G microSD card that I previously put Raspbian on. Looking at it with fdisk, I see:
Command (m for help): p
Disk /dev/sdf: 14.9 GiB, 15931539456 bytes, 31116288 sectors

Device     Boot  Start     End Sectors Size Id Type
/dev/sdf1        40960  172031  131072  64M  b W95 FAT32
/dev/sdf2       172032 2365440 2193409   1G 83 Linux
I don't care about this (though I am curious), so I do:
su
dd if=/dev/zero of=/dev/sdf bs=64k count=100
dd if=u-boot-sunxi-with-spl.bin of=/dev/sdx bs=8k seek=1
78+1 records in
78+1 records out
639712 bytes (640 kB, 625 KiB) copied, 0.000664059 s, 963 MB/s
sync
I insert this into the PC 2, apply power, and absolutely nothing happens. It is a dead as a doornail. Hmmm.

Try the sunxi U-Boot branch

They even say: "allows booting from SD, over USB and over ethernet".
git clone -b sunxi https://github.com/linux-sunxi/u-boot-sunxi.git
cd u-boot-sunxi
grep sunxi boards.cfg | awk '{print $7}'
This looks like a truly ancient U-Boot. No configs directory.

The above is supposed to yield a list of possible targets, however there is nothing that looks even remotely like an H5 or an Orange Pi. Also there is no genboardscfg.py file anywhere as per the instructions.

They say this is unmaintained, and brother, you better believe it.

Try an older U-Boot

They claim that orangepi_pc2_defconfig has been supported since v2017.05, so I am going to have a whirl at downloading that U-boot source and seeing if it will build. This does not need bl31.bin to build.
cd u-boot-2017.05
Add to Makefile: CROSS_COMPILE=aarch64-linux-gnu-
make orangepi_pc2_defconfig
make
This builds nicely with some warnings about syntax in a DTS file, as well as warnings about macros being redefined in some Python header file. Hopefully these can be ignored, because I am ignoring them.

The file board/sunxi/README.pine64 is worth reading and does mention bl31.bin along with something called boot0.img. The upshot of all this is that as of 2017.05 no SPL was being built and tools from pine64 including a binary blob from Allwinner called boot0.img is needed to produce a bootable disk. I could pursue all of this, but before I do I want to investigate more recent U-Boot distributions since by 2018.09 an SPL was being offered.

U-Boot Hell

Since this is turning into a major research project, I am going to start generating separate pages for all subsequent work.


Have any comments? Questions? Drop me a line!

Tom's electronics pages / tom@mmto.org