Beaglebone Black Network boot

Beaglebone Black Network boot

Having the Beaglebone Black Network boot can be beneficial in many ways. First, since the file system is no longer on MMC media, you have to worry less about wearing out the media. Secondly, it can make development much quicker, and easier since you no longer have to remove the media from one device to another, and vice versa. Not to mention that files can be added / removed from the host ( server ) system. Thirdly read/write speeds can be greatly improved, depending on the previously used media. Lastly, and definitely not least. Maintenance, such as backups, and reinstating previously made backups can be done with the Beaglebone Black running live.

Do also keep in mind that this is not 100% purely diskless. uEnv.txt, MLO, and u-boot.img must still remain on the boot media. However, because our kernel, and rootfs are both mounted over a network. we can make any changes to either without having to make changes to the SD card, or eMMC. So let us get started.

Requirements

These instructions are required to achieve the end goal of this article. In order listed. Make sure you have a working / booting sd card with Debian on it as instructed by Robert C. Nelson’s instructions. Once that is achieved, follow the instructions to setup NFS root on the Beaglebone Black.

Preparing the boot files

cd ~/debian/linux-dev/deploy/
ls -al

Here we’re looking for the zImage file we built when we last followed Robert C. Nelsons instructions. In my own case the proper zImage file is 3.8.13-bone21.zImage. Also, in the example above ~/debian is the base working directory where I installed all my build tools, and sources on my cross dev support system.

sudo cp 3.8.13-bone21.zImage ~/rootfs/boot/
mkdir ~/tmp
sudo tar xofv 3.8.13-bone21-dtbs.tar.gz -C ~/tmp
sudo cp ~/tmp/am335x-boneblack.dtb ~/rootfs/boot/
rm -rf ~/tmp

sudo cp 3.8.13-bone21.zImage ~/rootfs/boot/ copies the zImage file we found to the ~/rootfs/boot( /home/username/rootfs/boot ) directory. The remaining steps we need to extract am335x-boneblack.dtb from the tarball archive, and finally we copy the file over to ~/rootfs/boot/, and remove the tmp directory. If you’re new to Linux, be very careful with the -rf parameters while using the command rm. The reason is simple. The two parameters instruct rm to forcibly, and recursively remove the target. What this means, is that once the command is issued, it will not prompt for confirmation, and anything in, and including that path will be gone. Forever.

cd ~/rootfs/boot/
sudo mkimage -A arm -O linux -T kernel -C none -a 0×80008000 -e 0×80008000 -n “Linux” -d ./3.8.13-bone21.zImage ./uImage

uboot expects a kernel loaded over the network to be a uImage file. So here we’re converting the zImage file to a uImage file.

sudo rm 3.8.13-bone21.zImage

We no longer need the zImage file, so delete it.

Installing, and configuring TFTP

cd ~
sudo apt-get install tftp-hpa tftpd-hpa
sudo nano /etc/default/tftpd-hpa

Install tftpd-hpa, and tftp-hpa.

# /etc/default/tftpd-hpa

TFTP_USERNAME=”tftp”
TFTP_DIRECTORY=”/home/username/rootfs”
TFTP_ADDRESS=”0.0.0.0:69″
TFTP_OPTIONS=”–secure”

Again username is the normal username you created when installing Debian.

NFS shared directory ownership, and permissions

sudo chown nobody\: /home/username/rootfs
sudo chmod 777 /home/username/rootfs

We need to change the ownership, and permissions for the NFS share directory so TFTP can do its job properly.

Restart the TFTPD service, and test.

sudo service tftpd-hpa restart
cd ~
tftp 127.0.0.1

Do make sure to issue the command cd ~ to properly test TFTP.

>get /boot/am335x-boneblack.dtb
>quit
ls

make sure am335x-boneblack.dtb exist in current working directory. Then remove am335x-boneblack.dtb.

rm am335x-boneblack.dtb

Beaglebone Black – uEnv.txt

Now for a lean, and mean uEnv.txt. Explanation of specific parameters will be detailed below the text listing. Now on the beaglebone black as root:

nano /boot/uboot/uEnv.txt

First make a backup of uEnv.txt if need be. Delete the entire contents of uEnv.txt, and paste in the following text below. Make adjustments based on parameter descriptions below.

bootdelay=1
ipaddr=xxx.xxx.xxx.xxx
serverip=xxx.xxx.xxx.xxx
static_ip=xxx.xxx.xxx.xxx:xxx.xxx.xxx.xxx:xxx.xxx.xxx.xxx:255.255.255.0:arm
rootpath=/home/username/rootfs,rsize=16384,wsize=16384
console=ttyO0,115200n8

loadtftp=tftpboot 0×80200000 /boot/uImage; tftpboot 0x815f0000 /boot/am335x-boneblack.dtb
netargs=setenv bootargs console=${console} ${optargs} root=/dev/nfs nfsroot=${serverip}:${rootpath},vers=3 rw ip=${static_ip}
uenvcmd=setenv autoload no; run loadtftp; run netargs; bootm 0×80200000 – 0x815f0000

Detailed description of each parameter needing changes below.

bootdelay=1
ipaddr=xxx.xxx.xxx.xxx
serverip=xxx.xxx.xxx.xxx

Technically bootdelay=1 is not needed. ipaddr=xxx.xxx.xxx.xxx, and serverip=xxx.xxx.xxx.xxx are needed so uboot knows where to look for the Linux image, and device tree blob for the Beaglebone Black. If these parameters are omitted, the Beaglebone Black will hang with 3 USR LEDs lit solid shortly after starting the boot process.

static_ip=xxx.xxx.xxx.xxx:xxx.xxx.xxx.xxx:xxx.xxx.xxx.xxx:255.255.255.0:arm

Translates to:

static_ip=ipaddr:serverip:gatewayip:netmask:hostname

All of these parameters with the exception of hostname are necessary with uEnv.txt in its current configuration. This lets uboot know where to find the /root file system. Or more correctly, these parameters are passed to the kernel through ${optargs}.

rootpath=/home/username/rootfs,rsize=16384,wsize=16384

rootpath=/home/username/rootfs is the directory shared through NFS on the server. This is necessary so the kernel ( again through ${optargs} ) knows where to find the root file system. rsize=16384,wsize=16384 is not necessary, but can improve read / write speeds from the client to the host( server ). On our network, these settings make a tremendous difference.

Finally we need to make one more adjustment before rebooting our Beaglebone black.

nano /etc/network/interfaces

Peviously I had instructed that we needed a static ip. This was wrong. The problem is that uboot, and Debian do not seem to play well( with one another ) on the network, and as such have name resolution issues. Honestly though, I do know a decent bit about networking, but am not an expert. So this could in fact be my own failing. In either case we need to adjust /etc/network/interfaces accordingly. Make sure to remove any static IP refferences.

# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp

It should now be safe to reboot your Beaglebone Black. Once it comes back up, the Beaglebone Black’s IP may show up diferently on your network, but whatever IP you set in uEnv.txt will be the IP you need to connect to using ssh. Once logged in you can confirm by issuing the command ifconfig