U-Boot Script

Overview

When using U-Boot, there is a set of configurable parameters stored in U-Boot that affect how the CPU will be initialized.  U-Boot parameters can be set using the U-Boot command line, but instead of manually setting the parameters at the command line, we are going to add the U-Boot commands to a script and compile the script.  The resulting file will then be loaded at start up and the commands will be executed as they appear in the script.  So if you can configure U-Boot from the command line, why would you take the time to compile a U-Boot script?   Most U-Boot environments have a large number of environment variables.  In fact, many environment variables are nested within other environment variables.  The results is that a seemingly minor change in a single environment variable can lead to problems in the boot loader and result in a system that does not boot.  Using a compiled script is a more systematic approach that allows us to better manage changes to the default environment and roll back any changes that resulted in unwanted results.

TFTP booting

In order to understand some of the motivation behind compiling a U-Boot script, you will develop a U-Boot script that will give you the option to TFTP boot the DE1-SoC.  TFTP booing the DE1-SoC board allows you to build new FPGA images and program the FPGA without having to remove the microSD card from the DE1-SoC itself.  After you have built a new FPGA image, all you have to do is restart the DE1-SoC and U-Boot will automatically download the new image.

TFTP SetUp

Before we get to writing a U-Boot script to TFTP boot the DE1-SoC, we will need to make use of the U-Boot command prompt.

  1. Plug in a working SD card into the DE1-SoC
  2. Plug in your micro USB cable to the Serial Debug port
  3. Plug in an Ethernet cable to your DE1-SoC.
  4. Open up Tera Term/Putty/Moba Xter/or your favorite serial terminal program.
  5. Turn on the DE1-SoC
  6. Stop the boot process before Linux begins to boot. You can do this by pressing enter in the serial terminal.
  7. Set the MAC address of your DE1-SoC to the value printed on your DE1-SoC. This is a unique value, so make sure you use the value on YOUR board!  You can set this environment variable using the following command (where XX is the value found on your board):

Note:  If you are not in ECE453, then your board will not have a MAC address printed on it.  The DE1-SoC does not have a dedicated MAC address assigned to its ethernet port.  You will need to arbitrarily pick a MAC address that is going to be unique on your network.

setenv ethaddr xx:xx:xx:xx:xx:xx
saveenv
reset

setenv_ethaddr

8. After resetting the board, allow it to boot into Linux

9. After logging in, determine the IPV4 address that was assigned to your DE1-SoC.  You can do this by running the ifconfig command and looking at the address returned in the blue box below.  Be sure to write the IP address down.

ifconfig

10. In ECE453, we will be using a TFTP server  running on your lab PC.  In order for the DE1-SoC to download the correct RBF file from the TFTP server, we need to know the IP address of your lab PC.  Type the command ipconfig from a command prompt.  Find the IPV4 address of the host machine by scrolling near to the top of the command prompt window.

ipconfig

 

U-Boot TFTP Script

Now that we have the network information about the DE1-SoC and the TFTP server, let’s write a U-Boot script that will allow you to optionally boot the DE1-SoC using an RBF file found on the SD card or download the RBF file from the TFTP server.  Copy the contents of the script below into a text editor on your Linux development environment.

In the script below, you will need to substitute DE1-SoC’s MAC address in for xx:xx:xx:xx:xx:xx when setting the ethaddr environment variable.  You will also need to replace yy:yy:yy:yy:yy with the IPV4 address assigned to the DE1-SoC when setting the ipaddr environment variable.  The value for the hostname will be determined by your DNS name server.

The serverip environment variable should be set to the IP address of your TFTP server.

echo -- Setting MAC address --
setenv ethaddr xx:xx:xx:xx:xx:xx

echo -- Setting IP Address -- 
setenv ipaddr yy.yy.yy.yy

echo -- Setting up host name --
setenv hostname ECE453-xx.ece.wisc.edu

echo -- Setting TFTP Server IP --
setenv serverip zz.zz.zz.zz

if test -n $net_boot; 
then 
  if itest $net_boot == 1; 
  then 
    echo !!!!!!!!!!!!!!!!!!!!!!!!!!;
    echo ! Booting from TFTP      !;
    echo !!!!!!!!!!!!!!!!!!!!!!!!!!;
    tftp $fpgadata soc_system.rbf;
  else 
    echo !!!!!!!!!!!!!!!!!!!!!!!!!!;
    echo ! Booting from SD        !;
    echo !!!!!!!!!!!!!!!!!!!!!!!!!!;
    fatload mmc 0:1 $fpgadata soc_system.rbf;
  fi
else 
    echo !!!!!!!!!!!!!!!!!!!!!!!!!!;
    echo  Booting from SD         !; 
    echo !!!!!!!!!!!!!!!!!!!!!!!!!!;
    fatload mmc 0:1 $fpgadata soc_system.rbf;
fi

fpga load 0 $fpgadata $filesize;
setenv fdtimage soc_system.dtb;
run bridge_enable_handoff;
run mmcload;
run mmcboot;

The script essentially looks to see if there is an environment variable named net_boot.  If net_boot is either not found or set to a 0, then U-Boot will use the RBF found on the SD card when configuring the SoC.  If net_boot is set to a 1, then U-Boot will download a file named soc_system.rbf from the TFTP server.  The remainder of the commands load the RBF into memory, initialize the programmable logic, and begin the Linux boot process.

When you have edited the script, save a copy of the file as ece453_boot.script.

Compiling the U-Boot Script

Once that is done, you can compile the script using the following commands.  Make sure that you start the Intel Embedded Command Shell.  Without it, the script will not compile.

~/intelFPGA_lite/18.0/embedded/embedded_command_shell.sh
mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n "ECE453 Boot Script" -d ece453_boot.script u-boot.scr

mkimage

Adding U-Boot Script to your SD Card

If you have not done so, halt Linux on the DE1-SoC (sudo halt).   Connect the SD card to your Linux development environment.  You will place the u-boot.scr file in the first partition on the SD card.

cp u-boot.scr /media/ece453/SOC

 Complete TFTP Boot Configuration

Now that the script has been added to the SD card, all that is left to do is set the net_boot environment variable from the U-Boot command line.

1. Insert the SD card into the DE1-SoC and power up the board.

2. Stop the boot process at the U-boot Command line.

3. Now you will set the net_boot environment variable so U-Boot will download the soc_system.rbf from TFTP server

setenv net_boot 1
saveenv

setenv_net_boot

4. On your Windows Host, Open Tftpd64.  Tftpd64 is a Trivial FTP service that will run on your Windows PC.  U-Boot will download the soc_system.rbf file from your PC and then program the FPGA

5. In Tftpd64, select the source directory of the TFTP server to be the directory that contains your soc_system.rbf file.  You will also want to select the server interface to be the IP address of your Windows PC.

tftpd64

6. Type ‘reset’ at the U-Boot command prompt.  If configured correctly, you should see the DE1-SoC reboot and download a copy of the soc_system.rbf from your Windows PC.

tftp_boot