[System transplantation] uboot loads the root file system through NFS (2) – modify the environment variables bootcmd, bootargs

The network environment has been configured in the previous part. We need to modify the environment variables to ensure that the development board can start normally. The more important environment variables in the uboot environment variables are bootcmd and bootargs

Directory

1. Modify the self-starting command – bootcmd

2. Modify the self-starting parameters – bootargs

(1) root=/dev/nfs rw

(2) nfsroot

(3) ip=xxx::eth0:off

(4) console=ttymxc0,115200

3. Modify the version supported by NFS (take v2 version as an example)

4. Possible errors Kernel panic – not syncing: VFS: xxx


1. Modify the self-start command – bootcmd

The self-start command is the command that will run when the development board is powered on. When the development board is powered on, it will first obtain uboot, and then uboot will guide the development board to read the linux image file, device tree file, and root file system rootfs. Therefore, the role of bootcmd is actually to tell uboot where to find the above files during the self-starting link.

Load kernel image, device tree file from SD card

=> set setenv \
> mmc dev 0; \
> fatload mmc 0:1 80800000 zImage; \
> fatload mmc 0:1 83000000; \
> bootz 80800000 - 83000000;
Command Analysis
mmc dev 0 mmc dev means switch device, 0 means SD card, 1 means EMMC
fatload mmc 0:1 80800000 zImage

fatload file for loading vfat filesystem

mmc means external memory (indicates to load from external memory)

0:1 indicates the first partition on the SD card (0 in the former is the device number, 1 in the latter represents the partition)

80800000: indicates where to load to DDR

zImage: indicates which file in the partition to load (the file name must be the same as the file name saved in the SD card)

fatload mmc 0:1 83000000 imx6null.dtb Load the imx6null.dtb file of the first partition in the SD card and save it to the location 0x83000000 of DDR
bootz 80800000 – 83000000

bootz and bootm:

· bootz means to run the zImage kernel file,

· indicates to run the uImage file

The original format is “bootz kernel root file system device tree”, but the root file system is loaded in other ways, so use “-” to fill

2. Modify self-starting parameters – bootargs

Generally written are the parameters to be passed to the kernel. Reference link: Detailed explanation of bootargs parameters

=> setenv bootargs \
> root=/dev/nfs rw \
> nfsroot=169.254.162.189:/usr/local/nfsd/rootfs,v2,tcp \
> ip=169.254.162.163:169.254.162.189:169.254.162.1:255.255.0.0::eth0:off \
> console=ttymxc0,115200

(1) root=/dev/nfs rw

root means to specify the source of the root file system, nfs means to get it from the nfs server, mmcblk0p2 means to get it from the second partition of the SD card.

rw specifies the permission to operate the network file system.

(2) nfsroot

root Now that the source of the root file system has been specified as nfs, you need to tell the kernel where your nfs server is located and what is the working directory of nfs. The basic format is:

# If your nfs server is on a virtual machine, the IP address here refers to the IP address of your virtual machine
nfsroot=[IP address]:[nfs working directory]

Note 1: If your nfs server is on a virtual machine, the nfs working directory you wrote here must be added to the /etc/exports file in the specified format. For the adding method, please refer to: nfs environment construction

Note 2: In addition, the uboot of imx6ull uses the NFS-V2 protocol by default. You need to check whether your NFS server supports the v2 version. Check the command as follows:

 sudo cat /proc/fs/nfsd/versions

Negative numbers indicate no support, positive numbers indicate support. -2 means v2 version is not supported, + 3 means v3 version is supported. For how to modify, please refer to the third part of this article “Modify the version supported by NFS”.

Note 3: We can see that there is a v2, tcp at the end, v2 means to instruct NFS to use the v2 protocol, tcp means to use the tcp protocol, we can use the virtual machine command line Enter netstat -a | grep nfs, as can be seen from the results, in fact nfs supports both tcp and udp

(3) ip=xxx::eth0:off

Here is to pass the IP address of the development board and server to the kernel, and specify which network port to use. The basic format is as follows:

ip=[development board IP]:[server IP]:[gateway]:[subnet mask]::[network card name]:off

The reason for specifying the network card name here is that there may be multiple network cards (network ports) on a development board, for example, there are two network ports on imx6ull, so it is necessary to specify which network port to use to obtain the root file system.

(4) console=ttymxc0,115200

Indicates that the console information is output through the serial port, the name of the serial port is ttymxc0, and the baud rate is 115200

3. Modify the version supported by NFS (take v2 version as an example)

Modify the default configuration file of nfs /etc/default/nfs-kernel-server

sudo vim /etc/default/nfs-kernel-server

Modify the three places indicated in the figure in turn

Restart the NFS server

sudo /etc/init.d/nfs-kernel-server restart

View the protocols (versions) supported by the nfs server

4. Possible errors Kernel panic – not syncing: VFS: xxx

In reality, it may not be so smooth sailing. There may be several reasons for this situation:

  • The NFS version supported by uboot is v2, but the NFS side on your virtual machine does not support v2
  • The name of the network card is not specified at the end of ip, because there may be multiple network ports on a development board, and imx6ull has two network ports, so it is actually necessary to specify which network port to use. ip=xxx::eth0:off means specifying the eth0 network port
  • Check whether the IP address in nfsroot is wrong and whether the working directory is added to the /etc/exports file
[ 103.266737] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(2,0)
[ 103.275015] ---[ end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(2,0)
[ 117.173625] random: nonblocking pool is initialized