Network Boot

The phyCORE-i.MX7 development kit can be operated as a diskless system by hosting its kernel, device tree and root filesystem on a server. This is convenient while in development because you can quickly deploy and test changes without having to update onboard flash or external media like an SD card. Since bootloader changes are infrequent there is not a method to load U-Boot over network and this guide assumes it is stored on an SD card. The table below describes the images, preferred server, and advantages to speeding up your development:

BSP Components

Image

File Name

Boot Location

Description

Bootloader (U-Boot)

u-boot.img

SD Card

Infrequent changes

Kernel and Device Tree (zImage)

zImage and oftree

TFTP Server

Useful if you are making frequent modifications to the kernel such as pinmuxing, enabling or disabling interfaces, or testing a new board configuration

Filesystem

Directory on Linux PC

NFS Server

The target filesystem is mounted from a location on your Linux Host PC

Enables you to quickly test applications and copy files target board

Kernel Setup

TFTP is a “trivial” file transfer protocol used to transfer individual files across a network. Setting up a TFTP server on your Linux Host PC will allow you to exchange files with the target board. This is especially useful when modifying and doing development directly on the Linux kernel as it eliminates some time consuming steps such as formatting an SD card.

  • Ensure that your Host Machine has TFTP support:

    Host (Ubuntu)
    sudo apt-get update
    sudo apt-get install tftpd-hpa
    
  • Lets setup that server:

    Host (Ubuntu)
    mkdir /tftpboot
    sudo chmod 777 /tftpboot
    sudo chown nobody /tftpboot
    sudo vim /etc/default/tftpd-hpa
    

That last command will open the TFTP server configuration file in a Vim Text Editor.

  • Edit the contents of the config file such that it reflects the following before saving and closing the file:

    Tip

    The Vim Text Editor begins in “Command Mode” and you must first hit the ‘i’ key in order to enter “Insert Mode”. Using the arrow keys to navigate, make the necessary changes and then hit ESC to go back to “Command mode”. Now enter “:wq” to write the file and quit.

    Pro Tip: Use the right click on your mouse to paste. This will only work if you are in “Insert Mode” first.

/etc/default/tftpd-hpa
# /etc/default/tftpd-hpa

TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/tftpboot"
TFTP_ADDRESS=":69"
TFTP_OPTIONS="--secure --create"
  • Open the access port associated with this server:

    Host (Ubuntu)
    firewall-cmd --add-port=69/udp
    

    Warning

    If you get an error about firewall-cmd being an unrecognized command then you will have to install it before executing the above step. You can skip this if you didn’t have trouble running that last step:

    Host (Ubuntu)
    sudo apt-get install firewalld
    
  • Now restart the server:

    Host (Ubuntu)
    sudo systemctl restart tftpd-hpa
    

The server is all setup for file sharing, all it needs now is the files it will hold.

  • Download both the kernel and device tree to your Ubuntu Host Machine.

  • Transfer the downloaded kernel and device tree to the root of your new TFTP server:

    Host (Ubuntu)
    cp ~/Downloads/zImage /tftpboot/zImage
    cp ~/Downloads/zImage-imx7d-phyboard-zeta-004.dtb /tftpboot/oftree
    sync
    

    Notice that we have to name the device tree “oftree” since this is the name U-Boot expects it to be called.

Rootfs Setup

A Network Filesystem Server (NFS) gives other systems the ability to mount a filesystem stored on the Host PC which is exported over the network. Setting up an NFS server on your Linux Host PC gives you access to the target boards root filesystem which will allow you to quickly test applications and evaluate different filesystem setups for the target board.

  • Ensure that your Host Machine has NFS support:

    Host (Ubuntu)
    sudo apt-get install nfs-kernel-server
    
  • Lets setup that server:

    Host (Ubuntu)
    mkdir /nfsroot
    sudo chmod 777 /nfsroot
    sudo chown nobody /nfsroot
    sudo vim /etc/exports
    

That last command will open the NFS server export table in a Vim Text Editor.

  • Add the following to the end of the file before saving and closing:

    Host (Ubuntu)
    /nfsroot        *(rw,insecure,no_subtree_check,async,no_root_squash)
    
  • Open the access port associated with this server:

    Host (Ubuntu)
    firewall-cmd --add-port=2049/tcp
    
  • Now restart the server:

    Host (Ubuntu)
    sudo systemctl restart nfs-kernel-server
    

    The server is all setup for file sharing, all it needs now is the filesystem we will be mounting.

  • Download the compressed root filesystem to your Ubuntu Host Machine.

  • Extract the filesystem to the root of our NFS server:

    Host (Ubuntu)
    sudo tar -xvjf fsl-image-validation-imx-imx7d-phyboard-zeta-004.tar.bz2 -C /nfsroot && sync
    

Booting the Board

  • Before we can boot the board we will need the IPv4 address of our Host Machine so that we can specify the location of our servers. Use the following command to get the IP address:

    Host (Ubuntu)
    ifconfig
    

Make note of that IP address as we will need it shortly.

  • Insert a bootable SD Card into the phyCORE-i.MX7 development kit and ensure that the boot switches are set to boot the system from SD Card.

    Note

    All you really need is the first FAT32 partition containing the U-Boot image on the SD Card. Alternatively, you could use the eMMC to hold the U-Boot image in order to free up the SD Card slot. This would require the boot switches to be set accordingly.

  • Connect an Ethernet cable to the ETH1 RJ45 Jack. See :ref: eth-7 for more details.

  • Power on the kit and stop in U-Boot when prompted.

  • Enter the following commands to set booting over a network as the default (replace the X’s with your Host Machine’s IPv4 address from earlier):

    Target (U-Boot)
    setenv netload 'setenv autoload no; dhcp; setenv serverip XXX.XXX.XXX.XXX; tftp $loadaddr $serverip:$image; tftp $fdt_addr $serverip:$fdt_file'
    setenv netargs 'setenv bootargs console=${console},${baudrate} root=/dev/nfs ip=dhcp rw nfsroot=${serverip}:/nfsroot,vers=4,tcp'
    setenv bootcmd 'run netload; run netargs; bootz ${loadaddr} - ${fdt_addr}'
    saveenv
    boot
    

    And there we have it, you should be booted into Linux! Now your phyCORE-i.MX7 will also attempt to boot from your network automatically (stopping in U-Boot again is no longer necessary).

Reverting back to booting from SD Card

  • Initiate a reboot:

    Target (Linux)
    reboot
    
  • Stop in U-Boot when prompted.

  • Enter the following to revert back to the original U-Boot settings:

    Target (U-Boot)
    env default -f -a
    saveenv
    boot