December 29, 2021

Orange Pi 4 (Rockchip 3399) U-Boot setup for network booting

The first thing I want to do with my unit is to run some "bare metal" code experiments. Once I have some success with those, I will want to boot and run my "Kyu" real time operating system.

What I have found to be a wonderful way to do this is to set up the OrangePi to do diskless booting via TFTP.

Note that I have already set up my linux system to run dhcp and tftp along with adjusting firewall rules for those services. I have notes on that elsewhere.

Find out the MAC address and configure the DHCP server

Once you can get to the U-Boot console, it is trivial to learn the MAC address by using printenv:
=> printenv ethaddr
ethaddr=ca:61:5c:2b:c0:a8
I add an entry to my /etc/dhcp/dhcpd.conf file like this:
    # Entry for the Orange Pi 4 (RK3399) with eMMC
            host rock {
                    hardware ethernet ca:61:5c:2b:c0:a8;
                    fixed-address 192.168.0.34;
                    option host-name "rock";
                    server-name "trona";
                    filename "rock.bin";
            }
I also add the hostname "rock" with the IP number shown above to my /etc/hosts file.
Then I do this:
/bin/systemctl restart dhcpd.service

Make changes to the U-Boot setup

Nicely enough, I find the following line in the debian U-Boot setup:
bootcmd=run distro_bootcmd
This means that one I define my own "kyu_bootcmd", I can switch back to booting debian easily by just changing the bootcmd variable. I add the following to the U-Boot setup:
setenv bootaddr 0x02000000
setenv kyu_bootcmd "echo Booting Kyu via dhcp ; dhcp ${bootaddr}; go ${bootaddr}"
setenv bootcmd "run kyu_bootcmd"
saveenv
I have no idea at this point whether this "bootaddr" is appropriate, it is simply a first guess.

A quick side note. If you somehow create a U-Boot environment variable you don't want, you can delete it by simply using setenv with no value given, as:

setenv xyz

Put something in the tftpboot directory

On my fedora linux system this is /var/lib/tftpboot. I keep this directory owned by root to avoid mischief, but allow specific files within it to be written by myself (tom). So I do the following:
su
cd /var/lib/tftpboot
cp fire3.bin rock.bin
chown tom:tom rock.bin
The file "fire3.bin" was just something handy from a prior project. It clearly will not work on the RockPi hardware, but I just wanted some file there in order to test the tftp booting setup.

Try it out

I press the reset button on the underside of the board. I see the following, which looks exactly like what I might expect given my inappropriate content in rock.bin. The file "rock.bin" is 166616 bytes in size, so the following looks just right:
U-Boot 2020.04-orangepi (Mar 04 2021 - 09:49:58 +0800)

Model: OrangePi 4 AI board
DRAM:  3.9 GiB
PMIC:  RK808
MMC:   dwmmc@fe320000: 1, sdhci@fe330000: 0
Loading Environment from MMC... OK
In:    serial@ff1a0000
Out:   serial@ff1a0000
Err:   serial@ff1a0000
Model: OrangePi 4 AI board
Net:   eth0: ethernet@fe300000
Hit any key to stop autoboot:  0
Booting Kyu via dhcp
ethernet@fe300000 Waiting for PHY auto negotiation to complete........ done
Speed: 1000, full duplex
BOOTP broadcast 1
DHCP client bound to address 192.168.0.34 (6 ms)
Using ethernet@fe300000 device
TFTP from server 192.168.0.5; our IP address is 192.168.0.34
Filename 'rock.bin'.
Load address: 0x2000000
Loading: ############
	 5 MiB/s
done
Bytes transferred = 166616 (28ad8 hex)
## Starting application at 0x02000000 ...


Have any comments? Questions? Drop me a line!

Tom's electronics pages / tom@mmto.org