How to boot the A10 or A20 over the network

Prerequisites
You'll need a Linux box, a microSD card, a card reader and a serial console adapter for this tutorial.


 * Build U-Boot
 * Prepare an SD Card
 * For network booting it is enough to copy only the U-Boot to the SD card, so follow instructions in Bootable_SD_card and Bootable SD card.


 * Linux Kernel, you can use either legacy but featurefull sunxi-3.4, or mainline kernel which has basic support only.
 * Root file system, or rootfs.

Settin up network boot
SD Card is now ready to take for a spin. Put it into your board and connect your serial console and fire up a terminal on your host PC so you can interact with u-boot. Now power on the board. After booting you should see something like this:

U-Boot SPL 2013.01-05621-gb7b6374 (Jan 18 2013 - 23:01:07) Board: Cubieboard DRAM: 1024MB SUNXI SD/MMC: 0 U-Boot 2013.01-05621-gb7b6374 (Jan 18 2013 - 23:01:07) Allwinner Technology CPU:  SUNXI Family Board: Cubieboard I2C:  ready DRAM: 1 GiB MMC:  SUNXI SD/MMC: 0 In:   serial Out:  serial Err:  serial Net:  wemac Hit any key to stop autoboot: 0 sun4i# The autoboot is stopped because we don't have any partitions on the SD card yet so it'll not succeed booting.

Network configuration

 * Let's bring up the ethernet interface.
 * We must set the ethaddr variable to the MAC address of the NIC on the board. For testing purposes you can use something dummy like this:

sun4i# setenv ethaddr 12:34:56:78:99:aa
 * but please don't do this in production environment. Next you can choose between manual or automatic setup.

Manual
sun4i# setenv netmask sun4i# setenv dnsip sun4i# setenv gatewayip sun4i# setenv ipaddr 

Automatic

 * It is needed to also issue

sun4i# setenv autoload no
 * because by default once you execute the next 'dhcp' command and autoload is enabled it will automatically try to load an image from TFTP, named as the IP address in hex followed by .img, which is not what is wanted.

sun4i# dhcp

Now you're ready to try out TFTP or NFS. In either case you first need to set the IP of the server sun4i# setenv serverip  Also it is recommended to save your environment to the MMC card, so later or if something goes wrong with booting, you will not need to retype any of the previous commands. sun4i# saveenv

TFTP booting

 * Let's say you now have a TFTP server running on the IP address set above and serving files and have a kernel named 'uImage' and '.dtb' in the server file system. Type

tftp 0x46000000 uImage tftp 0x49000000 .dtb env set fdt_high ffffffff bootm 0x46000000 - 0x49000000

To boot sunxi-3.4 kernel the instructions above will be slightly different.

Booting from an NFS share

 * You have to compile a custom kernel because you have to enable root NFS support to work with NFS mounted root filesystems. Follow the build instructions described here: http://linux-sunxi.org/Linux#Building but before executing the second build command modify .config file in the kernel's source directory to contain the following lines:

CONFIG_IP_PNP=y CONFIG_ROOT_NFS=y
 * You might get some question from the next build command but you just have to say yes when it asks for the values above. You'll find the built kernel at arch/boot/uImage if you did everything right.


 * Prepare NFS share

Ubuntu 10.04

 * You have to install the required package

apt-get install nfs-kernel-server
 * Create a share directory.

mkdir -p /var/nfsexport/arch/
 * Edit /etc/exports to include this directory. Put the following line to the end:

/var/nfsexport *(rw,sync,no_root_squash,no_subtree_check)
 * Finally restart the daemon

/etc/init.d/nfs-kernel-server restart
 * Copy required files
 * Copy uImage from the first step to /var/nfsexport/arch/
 * We have to build a script.bin file for the kernel to work properly. Clone the https://github.com/linux-sunxi/sunxi-boards and https://github.com/linux-sunxi/sunxi-tools repository and compile sunxi tools (make). After that you have to convert your boards fex file with the fex2bin you've just built. In my case:

./sunxi-tools/fex2bin sunxi-boards/sys_config/a10/cubieboard.fex > script.bin
 * Copy script.bin next to the kernel
 * Download and extract Arch rootfs image. I'm using the MeleA100 image from the Arch ARM Linux site. Extract it to the NFS export folder:

wget http://archlinuxarm.org/os/ArchLinuxARM-sun4i-latest.tar.gz  tar xzf ArchLinuxARM-sun4i-latest.tar.gz -C /var/nfsexport/arch/
 * Configure U-Boot
 * Boot into U-Boot with the serial console attached and halt autoboot by pressing a key, then

sun4i# setenv nfsroot ${serverip}:/var/nfsexport/arch sun4i# setenv bootcmd "nfs 0x43000000 ${nfsroot}/script.bin; nfs 0x48000000 ${nfsroot}/uImage; bootm 0x48000000" sun4i# setenv bootargs "console=ttyS0,115200 root=/dev/nfs nfsroot=${nfsroot} ip=${ipaddr}:${serverip}:${gatewayip}:${netmask}:${hostname}:eth0" saveenv
 * Reset the board


 * Known bugs if using Arch Linux rootfs:
 * Reboot is not working; network interface is stopped but Arch wants to write something to the NFS mount which can't be done after that.
 * No output on HDMI but you can interact with Arch through the serial console or by using an SSH client and connect to the IP you've specified in uboot.

Web resources

 * This wiki page is quite useful for explaining the kernel booting with U-Boot: http://processors.wiki.ti.com/index.php/Booting_Linux_kernel_using_U-Boot


 * You can read more about mkimage's usage here: http://www.linuxfordevices.com/c/a/Linux-For-Devices-Articles/Introduction-to-Das-UBoot-the-universal-open-source-bootloader/


 * You can follow this tutorial to get a TFTP server in Ubuntu: http://www.davidsudjiman.info/2006/03/27/installing-and-setting-tftpd-in-ubuntu/ It can be installed to VM and set Virtualbox to bridge the internal NIC adapter directly to my local network where the Cubieboard is also connected. This way you can have a straight VM to Cubieboard development environment.