Network boot
TFTP
- On your PC, install a tftp server
apt-get install tftpd-hpa
- Copy rootfs contents inside the tftp server root
(
/var/lib/tftpboot
on debian/ubuntu systems). You can play with the access rights to allow your user to copy files directly (chown -R user:user /var/lib/tftpboot/
).echo "hello" > /var/lib/tftpboot/hello.txt cp arch/arm/boot/zImage /var/lib/tftpboot/ cp $DTB /var/lib/tftpboot/
- Set up your network interface (to a static ip address, say 192.168.11.1)
- Setup u-boot and load the kernel and device tree from network
- On raspberry we need to start the usb subsystem, because the network card is
connected through usb:
usb start
- Test it:
setenv ipaddr 192.168.11.2 setenv serverip 192.168.11.1 tftp $loadaddr /hello.txt md.b $loadaddr 5
- Now load & boot:
tftp $loadaddr zImage tftp $fdt_addr_r $fdtfile setenv bootargs .... bootz $loadaddr - $fdt_addr_r
- On raspberry we need to start the usb subsystem, because the network card is
connected through usb:
NFS
- Install nfs server utilities (the server implementation is
actually in-kernel):
apt-get install nfs-kernel-server
- Setup export
cat /etc/exports /home/nfsroot 192.168.11.2(rw,no_root_squash,no_subtree_check) mkdir /home/nfsroot chown yoyo:yoyo /home/nfsroot cp hi /home/nfsroot /etc/init.d/nfs-kernel-server restart
-
Boot the kernel from tftp as before, but instruct it to mount root
filesystem from the network via nfs:
-
root=/dev/nfs
: this is a "special" device that tells kernel, we are using nfs. -
nfsroot=SERVER:MOUNT
: tell kernel what to actually mount. -
ip=addr:[netmask]:[gateway]:[???]:[???]:[interface]
: configure the ip stack.
setenv bootargs=console=ttyAMA0,115200 root=/dev/nfs nfsroot=192.168.11.1:/home/nfsroot ip=192.168.11.2:::::eth0
-
Let's automate it
You can use the U-Boot environment variables to automate things with the run
command:
U-Boot> echo ahoj ahoj U-Boot> setenv x hi U-Boot> setenv y 'echo ${x}' U-Boot> run y hi U-Boot> setenv x hello U-Boot> run y hello
Note that we used '
so that the variable x
wasn't expanded when we executed the setenv
command, but only expanded later, when run
was interpreting the contents of that variable.
At startup, if not interrupted, U-Boot will "run" the contents of the bootcmd
variable. You can use this to set up your default boot. (Note: bootcmd is already set to some default value that usually tries to boot from first available boot source).
To keep things a bit modular, we will set our netboot
and netargs
variables that will contain everything needed to boot from tftp/nfs.
- Set up the boot command sequence:
setenv ipaddr 192.168.11.2 setenv serverip 192.168.11.1 setenv netboot 'usb start ; tftp ${kernel_addr_r} zImage ; tftp ${fdt_addr_r} ${fdtfile} ; setenv bootargs ${netargs} ; bootz ${kernel_addr_r} - ${fdt_addr_r}' setenv netargs 'console=ttyAMA0,115200 root=/dev/nfs nfsroot=192.168.11.1:/home/nfsroot ip=192.168.11.2:::::eth0'
-
Now, set up
bootcmd
to run ournetboot
command:setenv bootcmd 'run netboot'
- And now save the environment, so it persists between boots:
saveenv