Specifications

The advantage of this mechanism is that you don't have to spend precious system memory (RAM and flash)
for network configuration tools like ifconfig or route - especially in Embedded Systems where you
seldom have to change the network configuration while the system is running.
We can use U-Boot environment variables to store all necessary configuration parameters:
=> setenv ipaddr 192.168.20.38
=> setenv serverip 192.168.1.1
=> setenv netmask 255.255.0.0
=> setenv hostname m28
=> setenv rootpath /opt/eldk-5.2/armv5te/rootfs
=> saveenv
Then you can use these variables to build the boot arguments to be passed to the Linux kernel:
=> setenv nfsargs 'root=/dev/nfs rw nfsroot=${serverip}:${rootpath}'
Note how apostrophes are used to delay the substitution of the referenced environment variables. This way,
the current values of these variables get inserted when assigning values to the "bootargs" variable itself
later, i. e. when it gets assembled from the given parts before passing it to the kernel. This allows us to simply
redefine any of the variables (say, the value of "ipaddr" if it has to be changed), and the changes will
automatically propagate to the Linux kernel.
Note: You cannot use this method directly to define for example the "bootargs" environment variable,
as the implicit usage of this variable by the "bootm" command will not trigger variable expansion - this
happens only when using the "setenv" command.
In the next step, this can be used for a flexible method to define the "bootargs" environment variable by
using a function-like approach to build the boot arguments step by step:
=> setenv ramargs setenv bootargs root=/dev/ram rw
=> setenv nfsargs 'setenv bootargs root=/dev/nfs rw nfsroot=${serverip}:${rootpath}'
=> setenv addip 'setenv bootargs ${bootargs} ip=${ipaddr}:${serverip}:${gatewayip}:${netmask}:${hostname}::off'
=> setenv ram_root 'run ramargs addip;bootm ${kernel_addr} ${ramdisk_addr} ${fdt_addr} '
=> setenv nfs_root 'run nfsargs addip;bootm ${kernel_addr} - ${fdt_addr} '
In this setup we define two variables, ram_root and nfs_root, to boot with root filesystem from a
ramdisk image or over NFS, respecively. The variables can be executed using U-Boot's run command. These
variables make use of the run command itself:
First, either run ramargs or run nfsargs is used to initialize the bootargs environment
variable as needed to boot with ramdisk image or with root over NFS.
Then, in both cases, run addip is used to append the ip parameter to use the Linux kernel IP
autoconfiguration mechanism for configuration of the network settings.
Finally, the bootm command is used with three resp. two address arguments to boot the Linux kernel
image with resp. without a ramdisk image. (We assume here that the variables kernel_addr ,
ramdisk_addr and fdt_addr have already been set.)
This method can be easily extended to add more customization options when needed.
If you have used U-Boot's network commands before (and/or read the documentation), you will probably have
recognized that the names of the U-Boot environment variables we used in the examples above are exactly the
same as those used with the U-Boot commands to boot over a network using DHCP or BOOTP. That means
that, instead of manually setting network configuration parameters like IP address, etc., these variables will be
set automatically to the values retrieved with the network boot protocols. This is explained in detail in the
7.4. Boot Arguments Unleashed 89