u-boot sets tftp boot kernel and nfs root file system

First of all, the server needs to be configured with nfs and tftp, which have a lot of information on the Internet and are omitted here. In this example, my server address is, and the nfs and file system directory is: / home/ubuntu/disk-2/nfs_rootfs, tftp directory is: / home/ubuntu/disk-2/tftpboot. Kernel zImage and device tree file LKF have been placed in tftp directory_ am335x. dtb.
Set the development board address after entering the command line:

setenv ipaddr

After setting the ip, you can test whether the server can be ping ed normally:


Returning "host xx.xx.xx.xx is alive" indicates that my server has been accessed normally.
Next, set the server ip and the nfs directory on the server:

setenv serverip
setenv rootpath /home/ubuntu/disk-2/nfs_rootfs

Set the device tree file name fdtfile (in fact, uboot was originally set in this step, but I didn't write it here when I made uboot, so I have to set it myself):

setenv fdtfile lkf_am335x.dtb

Set network kernel startup parameters:

setenv netargs setenv bootargs console=ttyO0,115200n8 ${optargs} root=/dev/nfs nfsroot=${serverip}:${rootpath},nolock rw ip=

This netargs actually sets a bootargs, which is the parameter to be finally passed to the kernel. Console = ttyo0115200n8 indicates the information output port during kernel startup. root=/dev/nfs and file system location are nfs, nfsroot=${serverip}:${rootpath},nolock rw ip= Where ${serverip} is the server ip set earlier, and ${rootpath} is the nfs directory / home / Ubuntu / disk-2 / nfs on the server we set earlier_ rootfs. ip=, where the first field is the static ip address after kernel startup, the second field is the ip address of the server, is the gateway and is the mask.
Next, download the kernel

tftp ${loadaddr} ${bootfile}

This statement downloads the zImage file from the tftp directory of the server. Where ${loadaddr} is the address of the kernel in memory, here is 0x82000000, and ${bootfile} is zImage in my environment variable, so this statement is actually tftp 0x82000000 zImage.

The figure above shows that zImage has been downloaded normally.
Next, download the device tree file:

tftp ${fdtaddr} ${fdtfile} 

Like downloading the kernel, ${fdtaddr} is the address of the device tree. Here I am 0x88 million, ${fdtfile} is the device tree file and here I am lkf_am335x.dtb, so this statement is equivalent to tftp 0x88000000 lkf_am335x.dtb.
Next, set the kernel startup parameters. We have already set the environment variables. Here we only need a short statement:

run netargs

Finally, start the kernel:

bootz ${loadaddr} - ${fdtaddr}

Where ${loadaddr} is the kernel address downloaded earlier, and ${fdtaddr} is the device tree address. Here are some key screenshots of kernel startup:

In order to set it to start automatically in nfs mode after startup, we can save the above settings to the environment variable. I'll put the previous code together below:

setenv ipaddr
setenv serverip
setenv rootpath /home/ubuntu/disk-2/nfs_rootfs
setenv fdtfile lkf_am335x.dtb
setenv netloadimage  tftp ${loadaddr} ${bootfile}
setenv netloadfdt tftp ${fdtaddr} ${fdtfile}
setenv netargs setenv bootargs console=ttyO0,115200n8 ${optargs} root=/dev/nfs nfsroot=${serverip}:${rootpath},nolock rw ip=
setenv netboot echo Booting from network ...\; run netloadimage\; run netloadfdt\; run netargs\; bootz ${loadaddr} - ${fdtaddr}
setenv bootcmd run netboot

Let's look at the above code backwards. bootcmd is a command that uboot will execute automatically if it does not enter the command line after uboot starts. It actually calls run netboot, and netboot does the following things: download the kernel, download the device tree, set kernel startup parameters, and start the kernel.
In fact, many of the above environment variables have been set up. You can check how to use them with print.

Keywords: Linux Embedded system kernel uboot U-boot

Added by Whetto on Sat, 19 Feb 2022 04:20:30 +0200