How to create a NFS debugging environment for Libre Computer boards

Linux kernel developers need a way to rapidly test kernel changes. Compiling on ARM-based SBCs can take a long time so most developers cross-compile. This guide illustrates how to create a network boot environment. We assume a Debian host but you can use any distribution for the compile machine / NFS host.

Automated Method

git clone https://github.com/libre-computer-project/libretech-os-on-nfs.git
cd libretech-os-on-nfs
cp config.ini.example config.ini
# make edits to config.ini
./setup.sh
# create MicroSD card with libretech flash tool based on the instructions
# move the boot switch to boot from MMC instead of SPI NOR

libretech-wiring-tool is pre-installed in the /root directory

cd libretech-wiring-tool
./ldto list
./ldto enable OVERLAY # temporary until reboot
./ldto merge OVERLAY # permanent until reset + reboot

Manual Method

Setup NFS server:

sudo apt install nfs-kernel-server
sudo mkdir /srv/sbc-nfs
echo "/srv/sbc-nfs 192.168.1.0/24(rw,sync,no_root_squash,no_subtree_check)" | sudo tee -a /etc/exports
# change 192.168.1.0/24 to the network and subnet you want to provide access to
# anyone in this IP range will be able to access and write to this directory!
# we recommend that you tighten this by assigning static IP to the SBC's MAC
# and restricting this range to that specific IP so that only the SBC can access.
sudo systemctl reload nfs-kernel-server

Setup TFTP server:

sudo apt install tftpd-hpa

Setup Debian rootfs:

sudo apt install mmdebstrap
sudo mmdebstrap --variant standard --components="main contrib non-free non-free-firmware" --include=git,build-essential,device-tree-compiler --dpkgopt='force-unsafe-io' --arch=arm64 bookworm /srv/sbc-nfs
# you can use an apt caching proxy by adding --aptopt='Acquire::http { Proxy "http://127.0.0.1:3142"; }'
# remember to remove the apt cache option: sudo rm /srv/sbc-nfs/etc/apt/apt.conf.d/99mmdebstrap
# you can chroot into /srv/sbc-nfs to make additional modifications to the nfs root
sudo chroot /srv/sbc-nfs passwd #set password for root
echo "sbc" | sudo tee /srv/sbc-nfs/etc/hostname
echo "127.0.1.1 sbc" | sudo tee -a /srv/sbc-nfs/etc/hosts
sudo ln -sfn /proc/net/pnp "/srv/sbc-nfs/etc/resolv.conf" # use the kernel dhcp resolv.conf
sudo mkdir /srv/sbc-nfs/boot/efi
echo "/dev/mmcblk1p1  /boot/efi       vfat    umask=0077      0       1" | sudo tee /srv/sbc-nfs/etc/fstab

Cross-compile the kernel and directly install into the NFS share:

sudo ln -sfn /dev/null /srv/sbc-nfs/vmlinuz
sudo apt install gcc-aarch64-linux-gnu
git clone --single-branch --depth=1 https://github.com/libre-computer-project/libretech-linux.git
cd libretech-linux
cat <<EOF > build.sh
#!/bin/bash
export ARCH=arm64
export CROSS_COMPILE=aarch64-linux-gnu-
export INSTALL_PATH=/srv/sbc-nfs
export INSTALL_MOD_PATH=/srv/sbc-nfs
echo "make -j \`nproc\` \$@
EOF
chmod +x build.sh
./build.sh defconfig
sed -i "s/\(CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT=\).*/\\1n/" .config
sed -i "s/\(CONFIG_DEBUG_INFO_BTF=\).*/\\1n/" .config
./build.sh
sudo ./build.sh install modules_install
sudo cp "/srv/sbc-nfs/vmlinuz" /srv/tftp/vmlinuz
# to rebuild and reinstall the kernel, simply run the last three commands again
# tftpd-hpa chroots so symlinks do not work, the last copy command is necessary

Bootable MicroSD Card

Create a MicroSD card with bootloader and FAT/EFI partition for storing u-boot env and device tree:

git clone https://github.com/libre-computer-project/libretech-flash-tool.git
cd libretech-flash-tool
sudo ./lft.sh bl-flash [BOARD] [DEVICE] # eg. aml-a311d-cc-nfs sdc
# move the boot switch away from the edge of the board to boot from MMC instead of SPI NOR

Set u-boot Environment to Boot NFS

env set bootargs 'root=/dev/nfs nfsroot=192.168.1.1:/srv/sbc-nfs,vers=4 rw ip=dhcp nfsrootdebug'
env set bootcmd 'dhcp; tftpboot; if load mmc 1 \$fdt_addr_r dtb/\$fdtfile; then bootefi \$loadaddr \$fdt_addr_r; else bootefi \$loadaddr; fi'
env set bootdelay 0
env set bootfile 'vmlinuz'
env save # this will save these variables to the MicroSD card and boot via NFS in the future
boot
1 Like