Close

Step 5 (option B): Configure buildroot

A project log for Orange Pi Zero native network boot

Tutorial describing steps to make Orange Pi Zero boot natively from network

andriymalyshenkoandriy.malyshenko 08/13/2021 at 09:340 Comments

In the last step we're use Armbian distribution to take snapshot of the root filesystem, as well as boot artifacts.

Alternatively to that we can generate root filesystem as well as boot artifacts using [buildroot](https://github.com/buildroot/buildroot)

In short this is a set of tools and scripts that allows you to generate and build small yet extremely powerfull (and very much configurable) linux distribution. It will build u-boot (we don't need that), kernel and root filesystem specifically for our Orange Pi.

Execute following step on the dev machine

$ cd ~/pi-boot/
$ git clone https://github.com/anabolyc/buildroot-orange-pi-zero && cd buildroot-orange-pi-zero
$ git submodule update --init
$ cd buildroot
$ make orangepi_zero_defconfig
# optional, but you might want to configure root password, host name or something else to your taste
$ make menuconfig
$ make

This will take a while, and in the end it will output

[...]

INFO: vfat(boot.vfat): cmd: "dd if=/dev/zero of="/media/dronische/storage/buildroot-orange-pi-zero/buildroot/output/images/boot.vfat" seek=10485760 count=0 bs=1 2>/dev/null" (stderr):
INFO: vfat(boot.vfat): cmd: "mkdosfs   '/media/dronische/storage/buildroot-orange-pi-zero/buildroot/output/images/boot.vfat'" (stderr):
INFO: vfat(boot.vfat): adding file 'zImage' as 'zImage' ...
INFO: vfat(boot.vfat): cmd: "MTOOLS_SKIP_CHECK=1 mcopy -bsp -i '/media/dronische/storage/buildroot-orange-pi-zero/buildroot/output/images/boot.vfat' '/media/dronische/storage/buildroot-orange-pi-zero/buildroot/output/images/zImage' '::'" (stderr):
INFO: vfat(boot.vfat): adding file 'sun8i-h2-plus-orangepi-zero.dtb' as 'sun8i-h2-plus-orangepi-zero.dtb' ...
INFO: vfat(boot.vfat): cmd: "MTOOLS_SKIP_CHECK=1 mcopy -bsp -i '/media/dronische/storage/buildroot-orange-pi-zero/buildroot/output/images/boot.vfat' '/media/dronische/storage/buildroot-orange-pi-zero/buildroot/output/images/sun8i-h2-plus-orangepi-zero.dtb' '::'" (stderr):
INFO: vfat(boot.vfat): adding file 'boot.scr' as 'boot.scr' ...
INFO: vfat(boot.vfat): cmd: "MTOOLS_SKIP_CHECK=1 mcopy -bsp -i '/media/dronische/storage/buildroot-orange-pi-zero/buildroot/output/images/boot.vfat' '/media/dronische/storage/buildroot-orange-pi-zero/buildroot/output/images/boot.scr' '::'" (stderr):
INFO: hdimage(sdcard.img): adding partition 'u-boot' from 'u-boot-sunxi-with-spl.bin' ...
INFO: hdimage(sdcard.img): adding partition 'boot' (in MBR) from 'boot.vfat' ...
INFO: hdimage(sdcard.img): adding partition 'rootfs' (in MBR) from 'rootfs.ext4' ...
INFO: hdimage(sdcard.img): writing MBR

Now we have everything we need locally, just need to copy that to both NFS and TFTP servers

$ mkdir -p ~/pi-boot/mnt/{sdc,nfs} && cd ~/pi-boot
$ sudo mount 192.168.1.3:/srv/exports mnt/nfs
$ sudo mkdir mnt/nfs/01-02-42-94-b4-99-28-buildroot
$ ls -la mnt/nfs
total 16
drwxr-xr-x  4 root      root      4096 sie 13 10:25 .
drwxrwxr-x  4 dronische dronische 4096 sie 13 08:52 ..
drwxr-xr-x 18 root      root      4096 sie 13 09:54 01-02-42-94-b4-99-28
drwxr-xr-x 16 root      root      4096 sie 12 21:10 01-02-42-94-b4-99-28-buildroot

$ sudo rsync -va ~/pi-boot/buildroot-orange-pi-zero/buildroot/output/staging/ mnt/nfs/01-02-42-94-b4-99-28-buildroot

Next lets copy kernel and device tree to TFTP share

$ scp ~/pi-boot/buildroot-orange-pi-zero/buildroot/output/images/{zImage,sun8i-h2-plus-orangepi-zero.dtb} 192.168.1.2:/srv/tftp

And edit boot config (from TFTP server now)

$ cd /srv/tftp
$ sudo mkdir dtb-buildroot && mv sun8i-h2-plus-orangepi-zero.dtb ./dtb-buildroot
$ sudo nano pxelinux.cfg/01-02-42-94-b4-99-28

 Content of the file

LABEL linux
KERNEL vmlinuz-5.10.43-sunxi
FDTDIR dtb-5.10.43-sunxi
APPEND root=/dev/nfs initrd=uInitrd-5.10.43-sunxi nfsroot=192.168.1.3:/srv/exports/01-02-42-94-b4-99-28 ip=dhcp rw

LABEL buildroot
KERNEL zImage
FDTDIR dtb-buildroot
APPEND root=/dev/nfs nfsroot=192.168.1.3:/srv/exports/01-02-42-94-b4-99-28-buildroot,vers=4 ip=dhcp rw

DEFAULT buildroot

Now let's reboot our PI

U-Boot SPL 2020.10-armbian (Aug 08 2021 - 16:21:05 +0200)
DRAM: 256 MiB
Trying to boot from sunxi SPI


U-Boot 2020.10-armbian (Aug 08 2021 - 16:21:05 +0200) Allwinner Technology

CPU:   Allwinner H3 (SUN8I 1680)
Model: Xunlong Orange Pi Zero
DRAM:  256 MiB
MMC:   mmc@1c0f000: 0, mmc@1c10000: 1
Loading Environment from FAT... MMC: no card present
In:    serial
Out:   serial
Err:   serial
Net:   phy interface0
eth0: ethernet@1c30000
starting USB...
Bus usb@1c1a000: USB EHCI 1.00
Bus usb@1c1a400: USB OHCI 1.0
Bus usb@1c1b000: USB EHCI 1.00
Bus usb@1c1b400: USB OHCI 1.0
Bus usb@1c1c000: USB EHCI 1.00
Bus usb@1c1c400: USB OHCI 1.0
scanning bus usb@1c1a000 for devices... 1 USB Device(s) found
scanning bus usb@1c1a400 for devices... 1 USB Device(s) found
scanning bus usb@1c1b000 for devices... 1 USB Device(s) found
scanning bus usb@1c1b400 for devices... 1 USB Device(s) found
scanning bus usb@1c1c000 for devices... 1 USB Device(s) found
scanning bus usb@1c1c400 for devices... 1 USB Device(s) found
       scanning usb for storage devices... 0 Storage Device(s) found
Autoboot in 1 seconds
MMC: no card present

Device 0: unknown device
ethernet@1c30000 Waiting for PHY auto negotiation to complete. done
BOOTP broadcast 1
DHCP client bound to address 192.168.1.49 (9 ms)
Using ethernet@1c30000 device
TFTP from server 192.168.1.2; our IP address is 192.168.1.49
Filename '/pxelinux.0'.
Load address: 0x42000000
Loading: *
TFTP error: 'File not found' (1)
Not retrying...
missing environment variable: pxeuuid
Retrieving file: /pxelinux.cfg/01-02-42-94-b4-99-28
Using ethernet@1c30000 device
TFTP from server 192.168.1.2; our IP address is 192.168.1.49
Filename '/pxelinux.cfg/01-02-42-94-b4-99-28'.
Load address: 0x43200000
Loading: #
         113.3 KiB/s
done
Bytes transferred = 348 (15c hex)
Config file found
2:      buildroot
Retrieving file: /zImage
Using ethernet@1c30000 device
TFTP from server 192.168.1.2; our IP address is 192.168.1.49
Filename '/zImage'.
Load address: 0x42000000
Loading: #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #####################################
         1.5 MiB/s
done
Bytes transferred = 5304176 (50ef70 hex)
append: root=/dev/nfs nfsroot=192.168.1.3:/srv/exports/01-02-42-94-b4-99-28-buildroot ip=dhcp rw
Retrieving file: /dtb-buildroot/sun8i-h2-plus-orangepi-zero.dtb
Using ethernet@1c30000 device
TFTP from server 192.168.1.2; our IP address is 192.168.1.49
Filename '/dtb-buildroot/sun8i-h2-plus-orangepi-zero.dtb'.
Load address: 0x43000000
Loading: ##
         1.3 MiB/s
done
Bytes transferred = 23221 (5ab5 hex)
## Flattened Device Tree blob at 43000000
   Booting using the fdt blob at 0x43000000
EHCI failed to shut down host controller.
   Loading Device Tree to 49ff7000, end 49fffab4 ... OK

Starting kernel ...

[    0.000000] Booting Linux on physical CPU 0x0
[    0.000000] Linux version 5.12.2 (dronische@dronische-desktop) (arm-buildroot-linux-uclibcgnueabihf-gcc.br_real (Buildroot 2021.08-rc1-92-ge2d2cd94e0) 10.3.0, GNU ld (GNU Binutils) 2.36.1) #1 SMP Thu Aug 12 21:29:13 CEST 2021

[...]

[ 9.945333] random: crng init done
Starting sshd: OK

Welcome to Buildroot for the Orange Pi Zero
opi-z45 login:

And there is your login screen.

Discussions