Please enable javascript, or click here to visit my ecommerce web site powered by Shopify.
Jump to: navigation, search

Rockpi4/dev/u-boot/pxe

< Rockpi4‎ | dev‎ | u-boot
    ROCK Pi 4 >  Development >  U-boot >  PXE BOOT

PXE boot, Preboot eXecution Environment is a specification describes a standardized client-server environment that boots a software assembly, retrieved from a network. U-boot of ROCK Pi 4 supports PXE boot and it's enabled by default. This page describe how to use PXE boot on ROCK Pi 4.

Server setting

this document is used tftp server to test pxe boot to ramdisk,next,we will instruct on installing and configuring the tftp server in ubuntu 16.04LTS,and preparing some boot files.

Step 1: Install TFTP and TFTP server

 sudo apt-get install tftp-hpa tftpd-hpa

Step 2: Configure TFTP server

1.Create a folder,like this:

 mkdir /data/tftp_server

2.modify configuration file,like this:

 $ cat /etc/default/tftpd-hpa 
 # /etc/default/tftpd-hpa
 
 TFTP_USERNAME="tftp"
 TFTP_DIRECTORY="/data/tftp_server"
 TFTP_ADDRESS="0.0.0.0:69"
 TFTP_OPTIONS="-l -c -s"

Step 3: Restart tftp

 service tftpd-hpa restart

Step 4:Preparing boot file

copy all files from debian os boot partition,as follows:

 #:/data/tftp_server$ tree
 .
 ├── config-4.4.154-88-rockchip-00030-g90239a6      //copy from debian
 ├── dtbs                                           //.dtb file,we need rockpi-4b-linux.dtb,copy from debian
 │   └── 4.4.154-88-rockchip-00030-g90239a6
 │       └── rockchip
 │           ├── ficus-linux.dtb
 │           ├── px30-evb-ddr3-lvds-v10.dtb
   .
   .
   .
 │           └── rockpi-4b-linux.dtb
 ├── extlinux                                            //copy from debian
 │   ├── extlinux.conf
 ├── hw_intfc.conf                                       //copy from debian                          
 ├── initrd.img-4.4.154-88-rockchip-00030-g90239a6       //ramdisk,copy from debian
 ├── overlays                                            //.dtbo files,copy from debian
 │   ├── at24c02.dtbo
 │   ├── console-on-ttyS2.dtbo
 │   ├── console-on-ttyS4.dtbo
   .
   .
   .
 │   ├── spi1-waveshare35c.dtbo
 │   └── two-color-led.dtbo
 ├── pxelinux.cfg                                    //this folder is important,you can make the folder by yourself
 │   ├── 01-be-73-e6-4e-04-2b                        //named it by env ethaddr of uboot.i will introduce this file
 │   └── extlinux.conf
 └── vmlinuz-4.4.154-88-rockchip-00030-g90239a6      //this is a kernel image,copy from debian or build by yourself

Pxelinux.cfg

named pxe configaration file,run to uboot and print ethaddr:

 ...
   hclk_perilp1 100000 KHz                                                                                                                 
   pclk_perilp1 50000 KHz                                                                                                                  
 Net:   eth0: ethernet@fe300000                                                                                                            
 Hit key to stop autoboot('CTRL+C'):  0                                                                                                    
 => print ethaddr                                                                                                                          
 ethaddr=be:73:e6:4e:04:2b

so i named my pxe configaration file 01-be-73-e6-4e-04-2b,or you can named it default

 :/data/tftp_server/pxelinux.cfg$ cat 01-be-73-e6-4e-04-2b
 label kernel-4.4.154-88-rockchip-00030-g90239a6
     kernel /vmlinuz-4.4.154-88-rockchip-00030-g90239a6           //choose your kernel image
     devicetreedir /dtbs/4.4.154-88-rockchip-00030-g90239a6      //choose your dtb folder
     initrd initrd.img-4.4.154-88-rockchip-00030-g90239a6       //choose your ramdisk
     append earlycon=uart8250,mmio32,0xff1a0000 swiotlb=1 coherent_pool=1m earlyprintk console=ttyFIQ0,1500000n8 rw root=PARTUUID=b921b045-1d   rootfstype=ext4 init=/sbin/init rootwait        //this is bootargs for kernel

Rock Pi 4

we must install uboot on spi flash or emmc or microSD,this document is used spi flash,so please see spi-install to install uboot in spi flash

Step 1: Configure ip addr

enter uboot,and set some env:

 => setenv ipaddr xx.xx.xx.xx         //set rockpi4 ip
 => setenv serverip xx.xx.xx.xx        //set ip of tftp

Step 2: run pxe boot cammand

when you run pxe cammand,uboot will get some boot files from your tftp server.as follows:

 =>pxe get  
 missing environment variable: pxeuuid                                                                                                     
 missing environment variable: bootfile                                                                                                    
 Retrieving file: pxelinux.cfg/01-be-73-e6-4e-04-2b                                                                                        
 Speed: 1000, full duplex                                                                                                                  
 Using ethernet@fe300000 device                                                                                                            
 TFTP from server 192.168.2.140; our IP address is 192.168.2.205                                                                           
 Filename 'pxelinux.cfg/01-be-73-e6-4e-04-2b'.                                                                                             
 Load address: 0x600000                                                                                                                    
 Loading: #                                                                                                                                
          391.6 KiB/s                                                                                                                      
 done                                                                                                                                      
 Bytes transferred = 401 (191 hex)                                                                                                         
 Config file found
 =>pxe boot                                                                                                                                                                                                                                          
 missing environment variable: bootfile                                                                                                    
 Retrieving file: /hw_intfc.conf                                                                                                           
 Speed: 1000, full duplex                                                                                                                  
 Using ethernet@fe300000 device                                                                                                            
 TFTP from server 192.168.2.140; our IP address is 192.168.2.205                                                                           
 Filename '/hw_intfc.conf'.                                                                                                                
 Load address: 0x700000                                                                                                                    
 Loading: #                                                                                                                                
          840.8 KiB/s                                                                                                                      
 done                                                                                                                                      
 Bytes transferred = 1722 (6ba hex)                                                                                                        
 dtoverlay number: 0, name:/overlays/console-on-ttyS2.dtbo                                                                                 
 hw_conf.valid = 1                                                                                                                         
 hw_conf.pwm0 = 0                                                                                                                          
 hw_conf.pwm1 = 0                                                                                                                          
 hw_conf.uart2 = 0                                                                                                                         
 hw_conf.uart4 = 0                                                                                                                         
 hw_conf.spi1 = 0                                                                                                                          
 hw_conf.spi2 = 0                                                                                                                          
 hw_conf.i2c2 = 0                                                                                                                          
 hw_conf.i2c6 = 0                                                                                                                          
 hw_conf.i2c7 = 0                                                                                                                          
 hw_conf.dts_overlay_count = 1                                                                                                             
 hw_conf.dts_overlay[0] = /overlays/console-on-ttyS2.dtbo                                                                                  
 1:      kernel-4.4.154-88-rockchip-00030-g90239a6                                                                                         
 missing environment variable: bootfile                                                                                                    
 Retrieving file: initrd.img-4.4.154-88-rockchip-00030-g90239a6                                                                            
 Speed: 1000, full duplex                                                                                                                  
 Using ethernet@fe300000 device                                                                                                            
 TFTP from server 192.168.2.140; our IP address is 192.168.2.205                                                                           
 Filename 'initrd.img-4.4.154-88-rockchip-00030-g90239a6'.                                                                                 
 Load address: 0xa200000                                                                                                                   
 Loading: ########......                                                                                                                        
          ##################                                                                                                               
          5.2 MiB/s                                                                                                                        
 done                                                                                                                                      
 Bytes transferred = 4072215 (3e2317 hex)                                                                                                  
 missing environment variable: bootfile                                                                                                    
 Retrieving file: /vmlinuz-4.4.154-88-rockchip-00030-g90239a6                                                                              
 Speed: 1000, full duplex                                                                                                                  
 Using ethernet@fe300000 device                                                                                                            
 TFTP from server 192.168.2.140; our IP address is 192.168.2.205                                                                           
 Filename '/vmlinuz-4.4.154-88-rockchip-00030-g90239a6'.                                                                                   
 Load address: 0x280000                                                                                                                    
 Loading: ################# ......                                                    
          ########################                                                                                                         
        5 MiB/s                                                                                                                          
 done                                                                                                                                      
 Bytes transferred = 19427336 (1287008 hex)                                                                                                
 append: earlycon=uart8250,mmio32,0xff1a0000 swiotlb=1 coherent_pool=1m earlyprintk console=ttyFIQ0,1500000n8 rw root=PARTUUID=b921b045-1dt
 missing environment variable: bootfile                                                                                                    
 Retrieving file: /dtbs/4.4.154-88-rockchip-00030-g90239a6/rockchip/rockpi-4b-linux.dtb                                                    
 Speed: 1000, full duplex                                                                                                                  
 Using ethernet@fe300000 device                                                                                                            
 TFTP from server 192.168.2.140; our IP address is 192.168.2.205                                                                           
 Filename '/dtbs/4.4.154-88-rockchip-00030-g90239a6/rockchip/rockpi-4b-linux.dtb'.                                                         
 Load address: 0x8300000                                                                                                                   
 Loading: #######                                                                                                                          
          5 MiB/s                                                                                                                          
 done                                                                                                                                      
 Bytes transferred = 93561 (16d79 hex)                                                                                                     
 fdt addr 0000000008300000                                                                                                                 
 fdt magic number edfe0dd0                                                                                                                 
 fdt size 1048576                                                                                                                          
 merge_dts_overlay                                                                                                                         
 missing environment variable: bootfile                                                                                                    
 Retrieving file: /overlays/console-on-ttyS2.dtbo                                                                                          
 Speed: 1000, full duplex                                                                                                                  
 Using ethernet@fe300000 device                                                                                                            
 TFTP from server 192.168.2.140; our IP address is 192.168.2.205                                                                           
 Filename '/overlays/console-on-ttyS2.dtbo'.                                                                                               
 Load address: 0x8200000                                                                                                                   
 Loading: #                                                                                                                                
          755.9 KiB/s                                                                                                                      
 done                                                                                                                                      
 Bytes transferred = 774 (306 hex)                                                                                                         
 overlay dtb(0x0000000008200000) is valid                                                                                                  
 fdt_overlay_apply 0000000008300000 0000000008200000                                                                                       
 ## Flattened Device Tree blob at 08300000                                                                                                 
    Booting using the fdt blob at 0x8300000                                                                                                
    Loading Ramdisk to e99e3000, end e9dc5317 ... OK                                                                                       
    Loading Device Tree to 00000000e98e0000, end 00000000e99e2fff ... OK                                                                   
 Adding bank: 0x00200000 - 0xf8000000 (size: 0xf7e00000)                                                                                   
 Total: 717296.593 ms                                                                                                                      
                                                                                                                                           
 Starting kernel ...                                                                                                                       
                                                                                                                                           
                                                                                                                                           
 [    0.000000] Booting Linux on physical CPU 0x0                                                                                          
 [    0.000000] Initializing cgroup subsys cpuset

and now,your kernel is booting up

Diskless start

Diskless startup means that the operating system can be started without a disk (EMMC or sdcard or nvme). Diskless startup usually uses the DHCP, TFTP and NFS functions of uboot, This time, we will use another way to realize diskless startup. We will combine PXE of network card with NFS of uboot to realize diskless startup.

You nead to prepare

  • 1. rockpi4;
  • 2. server host (ubuntu);
  • 3. Ethernet Cable;
  • 4. Serial port line;


How to do

1. Download uboot to SPI flash on rockpi4;
2. Install TFTP and NFS server on the server host(PC):
(1). NFS server installation:

xxx@xxx:~$ sudo apt-get install nfs-kernel-server
xxx@xxx:~$ mkdir -p /home/xxx/nfs_rootfs
xxx@xxx:~$ sudo vim /etc/exports
/home/xxx/nfs_rootfs  *(rw,nohide,insecure,no_subtree_check,async,no_root_squash)
xxx@xxx:~$ sudo service nfs-kernel-server restart	#Restart service
xxx@xxx:~$ sudo  mount  -t  nfs  127.0.0.1:/home/xxx/nfs_rootfs  /mnt	#Test services for NFS

(2). TFTP server installation:

xxx@xxx:~$ sudo apt-get install tftp-hpa tftpd-hpa
xxx@xxx:~$ mkdir -p /home/xxx/tftpboot
xxx@xxx:~$ chmod 777 /home/xxx/tftpboot
xxx@xxx:~$ sudo vim /etc/default/tftpd-hpa
TFTP_DIRECTORY="/home/xxx/tftpboot"
TFTP_OPTIONS="-l -c -s"
xxx@xxx:~$ sudo service tftpd-hpa restart	#Restart service	

3. Put the kernel and DTB in the TFT directory, and extract the root file system to the NFS directory. The operation is as follows:
(1). Update the kernel in Debian of rockpi4:

root@linaro-alip:~# apt-get update
root@linaro-alip:~# apt install linux-4.4-latest -y
...
Setting up linux-headers-4.4.154-110-rockchip-gcef30e88a9f5 (4.4.154-110-rockchip) ...
Setting up linux-4.4-latest (4.4.154-110-rockchip) ...
root@linaro-alip:~#

(2). Copy the latest kernel and other files in the boot directory of Debian (you need to update the kernel to version 110):

root@linaro-alip:/boot# cp * /media/linaro/1877-4F6E/boot/ -r    #This is my U stick

(3). In the server (PC), copy all files in the boot directory of the U disk to the **TFTP Directory**:

xxx@xxx:/data/tftp_server$ cp /media/yulingle/1877-4F6E/boot/* . -r

(4). Create a configuration file for PXE to read:

xxx@xxx:/data/tftp_server$ mkdir pxelinux.cfg
xxx@xxx:/data/tftp_server$ cd pxelinux.cfg/
xxx@xxx:/data/tftp_server/pxelinux.cfg$ cp ../extlinux/extlinux.conf .
xxx@xxx:/data/tftp_server/pxelinux.cfg$ vim 01-d2-13-dc-b9-d4-10   #The physical address of the network card can be obtained by entering **print ehaddr** in the command line of **uboot**
timeout 10
menu title select kernel
	 
label kernel-4.4.154-110-rockchip-gcef30e88a9f5
kernel /vmlinuz-4.4.154-110-rockchip-gcef30e88a9f5
devicetreedir /dtbs/4.4.154-110-rockchip-gcef30e88a9f5
initrd initrd.img-4.4.154-110-rockchip-gcef30e88a9f5
append earlyprintk console=ttyFIQ0,1500000n8 init=/sbin/init root=/dev/nfs rw nfsroot=192.168.2.181:/home/xxx/nfs_rootfs,v3 ip=192.168.2.244:192.168.2.181:192.168.2.1:255.255.255.0:xxx::off 
rootwait
#The contant of 01-d2-13-dc-b9-d4-10 file can copy from pxelinux.cfg/extlinux.conf
#192.168.2.181 is IP of server.
#/home/xxx/nfs_rootfs is the directory where the root file system resides.
#v3 is version number of nfs.
#xxx is hostname of your server host.
#192.168.2.1 is gateway.

(5). Next, unzip the root file system to the NFS directory:
Unzip the file system:

$ tar -xzf linaro-stretch-alip-20200623-1.tar.gz -C /home/xxx/  #After unzipping, you will get the binary folder.
$ mv binary nfs_rootfs  #nfs_rootfs is the directory name specified in the /etc/exports file.

linaro-stretch-alip-20200623-1.tar.gz The creation of the root file system can refer to here.

4、Start rockpi4, enter the uboot command line, and set IP:

=> setenv ipaddr xx.xx.xx.xx
=> setenv serverip xx.xx.xx.xx	#The IP address of rockpi4 and server must be in the same network segment.

Using PXE

=> pxe get
=> pxe boot


5、When the kernel is started successfully and the NFS file system is mounted, the following is displayed:

Starting Update UTMP about System Runlevel Changes...
[  OK  ] Started Update UTMP about System Runlevel Changes.
[   27.195702] tty_port_close_start: tty->count = 1 port count = 2.

Debian GNU/Linux 9 linaro-alip ttyFIQ0

linaro-alip login: root (automatic login)

Linux linaro-alip 4.4.154-110-rockchip-gcef30e88a9f5 #1 SMP Mon Jun 22 07:37:10 UTC 2020 aarch64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
root@linaro-alip:~# 
root@linaro-alip:~# 
root@linaro-alip:~# 
root@linaro-alip:~#