Efficient Deployment of Forlinx OK62xx-C Development Board Firmware on Linux via NFS and TFTP

Overview

This article introduces how to update the image over the network using NFS and TFTP on the OK62xx-C series development boards. Please refer to the document for the operations.

Application Scope

This article is mainly applicable to the Linux 6.1.33 operating system on the Forlinx OK62xx-C platform. Other platforms can also refer to it, but there will be differences between different platforms. Please make modifications according to the actual conditions.

1. Updating the Image over the Network using NFS and TFTP

NFS (Network File System) is a distributed file-sharing protocol that allows a computer to transparently access a remote file system over the network. It is commonly used to mount the root file system in embedded development.

1.1 NFS Service Setup

1). The method to set up an NFS server on Ubuntu is as follows:

Software Download and Installation

forlinx@ubuntu:~# sudo apt-get install nfs-kernel-server nfs-common portmap

Create an NFS Directory and Extract the File System (Take the rootfs.tar.bz2 file system as an example, and the current directory is the root directory)

forlinx@ubuntu:~# cd /
forlinx@ubuntu:/# sudo mkdir nfs_rootfs
forlinx@ubuntu:/# sudo tar -xvf rootfs.tar.bz2 -C /nfs_rootfs/

Modify the configuration file

forlinx@ubuntu:/# sudo vim /etc/exports

Add the following configuration to the file:

/nfs_rootfs *(rw,sync,no_root_squash,no_subtree_check)

Restart profiles and services

forlinx@ubuntu:/# sudo exportfs -rv
forlinx@ubuntu:/# sudo /etc/init.d/rpcbind restart
forlinx@ubuntu:/# sudo /etc/init.d/nfs-kernel-server restart

2) Verify the NFS server on the development board. After executing the following command, mount the NFS server to the /mnt directory of the development board:

root@imx6ulevk:~# mount -t nfs4 -o vers=4 192.168.0.57:/nfs_rootfs /mnt

After the successful mounting, check the /mnt directory, and you will see the file system that was just extracted.

root@imx6ulevk:~# ls /mnt/

Note: 192.168.0.57 is the IP address of the Ubuntu host of the NFS server. The network of Ubuntu needs to be set to the bridged mode and be in the same network segment as the development board. Copy the contents of /OK62xx - linux - fs/rootfs in the source code to /nfs_rootfs.

As shown in the figure:

Test NFS in the U-Boot stage of the development board.

Set the environment variables:

=> setenv ipaddr 172.16.0.141 //Development board ip
=> setenv serverip 172.16.0.142 //Server ip
=> nfs /home/forlinx/nfs_rootfs/bin/tar.tar //Download the file via NFS (absolute path here)
link up on port 1, speed 1000, full duplex
Using ethernet@8000000 device
File transfer via NFS from server 172.16.0.141; our IP address is 172.16.0.142
Filename '/nfs_rootfs/bin/tar.tar'.
Load address: 0x82000000
Loading: #################################################################
##############################
done
Bytes transferred = 482272 (75be0 hex)

1.2 TFTP Service Setup

TFTP (Trivial File Transfer Protocol) is a lightweight UDP - based file transfer protocol, mainly used for booting diskless devices or quickly transferring small files such as kernel images in embedded systems.

1)Install the server, client, and daemon process.

forlinx@ubuntu:~$ sudo apt-get install tftp-hpa tftpd-hpa xinetd

2)Server configuration

First, create a tftpboot directory in the root directory and change its attributes to allow any user to read and write:

forlinx@ubuntu:~$ cd / 
forlinx@ubuntu:~ sudo mkdir nfs_rootfs  
forlinx@ubuntu:~$ sudo chmod 777 tftpboot 

Then, enter the directory/etc/xinetd. d/, create a new file TFTP in it, and add the specified content to the TFTP file:

forlinx@ubuntu:~$ cd /etc/xinetd.d/ 
forlinx@ubuntu:~$ sudo vim tftp 

Add the following to the TFTP file:

service tftp 
{ 
disable = no 138 
socket_type = dgram 
protocol = udp 
wait = yes 
user = root 
server = /usr/sbin/in.tftpd 
server_args = -s /tftpboot -c 
per_source = 11 
cps = 100 2 
} 

Finally, modify the configuration file/etc/default/tftpd-hpa

forlinx@ubuntu:~$ sudo vim /etc/default/tftpd-hpa

Modify to

TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/tftpboot"
TFTP_ADDRESS="0.0.0.0:69"
TFTP_OPTIONS="--secure -l -c -s"

Note change the TFTP _ DIRECTORY "to the path where the new tftpboot directory is created.

3)Restart the service

forlinx@ubuntu:~$ sudo /etc/init.d/xinetd reload 
forlinx@ubuntu:~$ sudo /etc/init.d/xinetd restart
forlinx@ubuntu:~$ sudo /etc/init.d/tftpd-hpa restart

4)Test the server

To test it, create a new file in the/tftpboot folder

forlinx@ubuntu:/tftpboot$ sudo touch abc 

Go to another folder

forlinx@ubuntu:/tftpboot$ cd /home/
forlinx@ubuntu:/home$ sudo tftp 192.168.2.51 	//192.168.2.51 is the local IP
tftp> get abc 
tftp> quit
forlinx@ubuntu:/home$ ls
abc

If the download is successful, it indicates that the server has been installed correctly. After connecting the development board to the PC via an Ethernet cable, the TFTP can be used to download files. Then, put the AM6254 image Image and OK6254 - C.dtb into the tftpboot folder.

Test TFTP in the U - Boot stage of the development board.

Set the environment variables:

=> setenv ipaddr 172.16.0.141 //Development board ip
=> setenv serverip 172.16.0.142 //Server ip
=> tftpboot Image //Download files via TFTP
link up on port 1, speed 1000, full duplex
Using ethernet@8000000 device
TFTP from server 172.16.0.141; our IP address is 172.16.0.142
Filename 'Image'.
Load address: 0x82000000
Loading: #################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################T 
#################################################################
#################################################################
#################################################################
#################################################################
############
1.7 MiB/s
done
Bytes transferred = 20206080 (1345200 hex)

2. Network Boot File System

=> setenv ipaddr 172.16.0.142 //Development board ip
=> setenv serverip 172.16.0.141 //Server ipsetenv 
=> setenv image Image
=> setenv fdt_file OK6254-C.dtb
=> setenv netargs "setenv bootargs console=ttyS2,115200 root=/dev/nfs rw ip=172.16.0.142:172.16.0.141:172.16.0.1:255.255.255.0::eth0:off nfsroot=172.16.0.141:/nfs_rootfs,v3,tcp"
=> setenv netboot "run netargs; tftpboot ${loadaddr} ${image}; tftpboot ${fdtaddr} ${fdt_file}; booti ${loadaddr} - ${fdtaddr}"
=> saveenv
Saving Environment to MMC... Writing to MMC(0)... OK
=> run netboot

3. Kernel Image, Device Tree, and U-Boot Image Update

After the network boot is completed, copy the files in the network file system to mmcblk0p1 and mmcblk0p2 using the following commands:

cp /boot/Image /run/media/mmcblk0p2/boot/       			//Update the kernel image
cp /boot/OK6254-C.dtb /run/media/mmcblk0p2/boot/      //Update the device tree
cp /boot/u-boot.img /run/media/mmcblk0p1/     			 	//Update the U-Boot image
sync

Note: After the network boot, the file system of the development board is the same as the one placed in the virtual machine. The original file system in the eMMC of the development board is located at /run/media/mmcblk0p2/. Therefore, you only need to copy the images in the network file system to the corresponding positions of the images in the eMMC file system to update the images.




Dear friends, we have created an exclusive embedded technical exchange group on Facebook, where our experts share the latest technological trends and practical skills. Join us and grow together!