Difference between revisions of "Loading Images with U-Boot"

From wiki.emacinc.com
Jump to: navigation, search
m (Added note.)
Line 1: Line 1:
{{todo|Finish and polish(12.16.13-01:25->MD-)|Michael Welling|project=oe 4,oe 5,mw,Buggy,md}}
+
{{todo|Review(12.16.13-01:25->MD-);(12.31.13-11:02->MW)|Michael Welling|project=oe 4,oe 5,mw,Review,md,ky,mg}}
 
 
'''NOTE: This page never specifically mentions anything about loading kernels versus loading filesystems.  This will likely lead to some confusion with our customers, especially when they're referred to this page by the Loading Linux Kernels Onto a Board page.'''
 
  
 
While U-Boot is used to load and execute the OS after initial programming, it can also be used to program the OS images to the local flash. This page describes the process of using U-Boot to load Linux kernel and filesystem images from a TFTP server and save them to the local flash for use during the boot process. Review the [[U-Boot Overview]] page for an introduction to U-Boot before continuing.
 
While U-Boot is used to load and execute the OS after initial programming, it can also be used to program the OS images to the local flash. This page describes the process of using U-Boot to load Linux kernel and filesystem images from a TFTP server and save them to the local flash for use during the boot process. Review the [[U-Boot Overview]] page for an introduction to U-Boot before continuing.
Line 41: Line 39:
 
{{mbox | type = warning | text = Before transferring a file to the system, make sure that it does not exceed the size of the available RAM. }}
 
{{mbox | type = warning | text = Before transferring a file to the system, make sure that it does not exceed the size of the available RAM. }}
  
The <code>tftp</code> U-Boot command is used to transfer files to the system. The command requires two arguments: the address to load the file to and the filename of the image on the TFTP server. The example below demonstrates loading an image named <code>uImage-2.6.30</code> to RAM on an SoM-9G45M.
+
The <code>tftp</code> U-Boot command is used to transfer files to the system. The command requires two arguments: the address to load the file to and the filename of the image on the TFTP server. The example below demonstrates loading a kernel image named <code>uImage-2.6.30</code> to RAM on an SoM-9G45M.
 
  U-Boot> tftp 0x70000000 uImage-2.6.30
 
  U-Boot> tftp 0x70000000 uImage-2.6.30
 
  macb0: link up, 100Mbps full-duplex (lpa: 0x45e1)
 
  macb0: link up, 100Mbps full-duplex (lpa: 0x45e1)
Line 60: Line 58:
 
{{mbox | type = notice | text = Note that the <code>filesize</code> variable has been automatically updated to the size of the file that was loaded.}}
 
{{mbox | type = notice | text = Note that the <code>filesize</code> variable has been automatically updated to the size of the file that was loaded.}}
  
== Executing from RAM ==
+
== Executing kernel from RAM ==
 
In some situations, it is advantageous to execute the image directly from RAM after loading with TFTP rather than saving to flash. This is especially helpful when testing new Linux kernel images. Furthermore, the boot command can be set such that the image is automatically downloaded and executed on each boot, making testing more efficient.
 
In some situations, it is advantageous to execute the image directly from RAM after loading with TFTP rather than saving to flash. This is especially helpful when testing new Linux kernel images. Furthermore, the boot command can be set such that the image is automatically downloaded and executed on each boot, making testing more efficient.
  

Revision as of 12:04, 31 December 2013

TODO: {{#todo:Review(12.16.13-01:25->MD-);(12.31.13-11:02->MW)|Michael Welling|oe 4,oe 5,mw,Review,md,ky,mg}}

While U-Boot is used to load and execute the OS after initial programming, it can also be used to program the OS images to the local flash. This page describes the process of using U-Boot to load Linux kernel and filesystem images from a TFTP server and save them to the local flash for use during the boot process. Review the U-Boot Overview page for an introduction to U-Boot before continuing.

Requirements

A TFTP server must be accessible on the local network. The specific details of TFTP server setup and configuration can be found on the Installing TFTP server page.

Configuration

In order to load a file using TFTP, U-Boot must be configured to access the local network. Static networking configuration is recommended, although DHCP can be used on some systems. Typically, the IP address of the board and the IP address of the TFTP server are the only settings that need to be defined. The network mask and broadcast address will be determined automatically from these settings, and no default gateway setting is required if the server is on the same subnetwork as the board. Before continuing, determine a valid static network address for your local network; contact your IT department for more information on what address to use if required. The example below shows how to set the IP address of the board to 192.168.2.2 and the TFTP server IP address to 192.168.2.1:

U-Boot> setenv ipaddr 192.168.2.2
U-Boot> setenv serverip 192.168.2.1
U-Boot> saveenv
Saving Environment to dataflash...
U-Boot> reset

Once the network settings have been configured, attempt to ping the TFTP server to test the network connection as illustrated below:

U-Boot> ping 192.168.2.1
macb0: link up, 100Mbps full-duplex (lpa: 0x45e1)
Using macb0 device
host 192.168.2.1 is alive

Loading Images to RAM

Files are loaded directly into RAM from through TFTP. In order to load the image, you must know the physical address of the RAM device on the system. Refer to the documentation for your target board if you are unsure what value to use. The standard addresses for some common EMAC systems are shown in Table 1 below.

Table 1: Physical RAM Addresses
Product RAM Start Address
SoM-9260M 0x20000000
SoM-9G20M 0x20000000
SoM-9G45M 0x70000000
SoM-9M10M 0x70000000

The tftp U-Boot command is used to transfer files to the system. The command requires two arguments: the address to load the file to and the filename of the image on the TFTP server. The example below demonstrates loading a kernel image named uImage-2.6.30 to RAM on an SoM-9G45M.

U-Boot> tftp 0x70000000 uImage-2.6.30
macb0: link up, 100Mbps full-duplex (lpa: 0x45e1)
Using macb0 device
TFTP from server 192.168.2.1; our IP address is 192.168.2.2
Filename 'uImage-2.6.30'.
Load address: 0x70000000
Loading: #################################################################
         #################################################################
         #################################################################
         #################################################################
         ############################
done
Bytes transferred = 1472456 (1677c8 hex)
U-Boot> printenv filesize
filesize=1677C8

Executing kernel from RAM

In some situations, it is advantageous to execute the image directly from RAM after loading with TFTP rather than saving to flash. This is especially helpful when testing new Linux kernel images. Furthermore, the boot command can be set such that the image is automatically downloaded and executed on each boot, making testing more efficient.

After loading a bootable image to RAM, you can execute it directly using the bootm command. For example, after loading the kernel image above, running bootm 0x70000000 would boot the board using the new image without making any changes to the images stored on the flash.

To update the bootcmd variable to download the image on each boot, simply replace the command used to load the image from flash with the TFTP download command. The following example illustrates this process on an SoM-9G45M module.

U-Boot> printenv bootcmd
bootcmd=cp.b 0xC0042000 0x70000000 0x210000; bootm 0x70000000
U-Boot> setenv bootcmd 'tftp 0x70000000 uImage-2.6.30; bootm 0x70000000'
U-Boot> saveenv
Saving Environment to dataflash...

Copying to Flash

The process of copying an image from RAM to flash memory differs depending on what type of flash storage devices are available on the system. Many systems have more than one device, such as serial DataFlash and NAND flash. This section explains the process of storing an image to non-volatile storage.

NOR Flash

A combination of the erase and cp commands are used to program an image to a NOR flash device. NOR flash is directly memory-mapped to the system at a physical address. Also, each image (U-Boot, bootstrap, kernel, filesystem) must be stored at the correct offset for the system to operate correctly. Refer to the documentation for your hardware for more information on the correct address ranges to use. The flinfo command can be used to display the addressing of available flash devices on the system.

After loading the image to RAM, the flash device should be erased followed by copying the image to the appropriate offset in the flash. The example below illustrates the commands used to program a new kernel image to a SoM-9260M module. Note the use of the protect off all command, which is required to unlock the flash on some systems.

U-Boot> protect off all
U-Boot> tftp 0x20000000 ${kernel_name}
U-Boot> erase 0x10100000 0x103fffff
U-Boot> cp.b 0x20000000 0x10100000 ${filesize}

Serial DataFlash

Serial DataFlash is an SPI-based NOR flash device that is used on many systems that employ NAND flash as the primary storage device. On these systems, low-level boot code such as the bootstrap, U-Boot, and OS kernel are typically stored on the DataFlash device. As with NOR flash, the flinfo command can be used to determine the memory addressing layout of the DataFlash device. The erase command does not support the DataFlash devices and should not be used before programming an image. The cp command is capable of copying an image from RAM to DataFlash.

The example below illustrates the commands used to copy a kernel image to the DataFlash device on a SoM-9G45M module.

U-Boot> tftpboot 0x70000000 ${kernel_name}
U-Boot> cp.b 0x70000000 0xC0042000 ${filesize}

NAND Flash

Generally, NAND flash is used to store only the root filesystem and auxiliary storage partitions of the OS. Storing an image to NAND flash under U-Boot uses a different set of commands than NOR or DataFlash devices. See help nand for more information on the available commands for examining and manipulating NAND flash devices. To gain information on what NAND devices are available on the system, use the command nand info. In general, programming a NAND flash device is much faster than programming NOR or DataFlash devices.

The example below illustrates the process of loading the root JFFS2 filesystem onto an SoM-9G45M device. Note that the device is erased prior to programming it.

U-Boot> nand erase
U-Boot> tftp 0x70000000 ${rootfs_name}
U-Boot> nand write.jffs2 0x70000000 0x0 ${filesize}

Scripting

U-Boot also includes a scripting feature that allows a script file with U-Boot commands to be loaded and executed. This can make the task of programming multiple systems much more efficient. The mkimage utility is required on a Linux development system in order to create a valid U-Boot image from a script. This section gives a brief example of a U-Boot script for programming a Linux kernel and filesystem.

Creating a text file with all of the desired commands is the first step in creating a U-Boot script. The example below is a script file used by EMAC to program SoM-9260M modules:

echo ===== Setting Environment =====
setenv bootdelay 1
setenv rev sl013-aon-30010
setenv bootargs 'console=ttyS3,115200 root=/dev/mtdblock3 rootfstype=jffs2'
setenv kernel_name ${rev}-uImage
setenv rootfs_name sl013-aon-emac-image-SOM9260M.jffs2
saveenv
echo ===== Loading Kernel =====
protect off all
tftpboot 0x20000000 ${kernel_name}
erase 0x10100000 0x103fffff
cp.b 0x20000000 0x10100000 ${filesize}
setenv kernelsize ${filesize}
echo ===== Loading Root Filesystem =====
tftpboot 0x20000000 ${rootfs_name}
erase 0x10400000 0x11ffffff
cp.b 0x20000000 0x10400000 ${filesize}
setenv bootcmd 'protect off all;cp.b 0x10100000 0x20000000 ${kernelsize};bootm 0x20000000'
saveenv
echo ===== DONE! =====

Once the file has been created and saved, the mkimage utility must be used to create a U-Boot script image. A shell script such as the one shown below may be used to aid in this process:

#!/bin/sh
 
if [ ! -f "$1" ] || [ $# -lt 2 ]
then
        echo "Usage: $0 SCRIPTNAME OUTPUTNAME"
        exit 1
fi
 
mkimage -T script -C none -A arm -n 'SoM9260 Load Script' -d $1 $2

Note that the script assumes that mkimage is installed in the user's PATH. The script should be run with the name of the existing file as the first argument and the desired output filename as the second argument:

./script_mkimage.sh sl013-aon-30010-flash-script sl013-aon-30010-flash-script.img

Once an image file has been created, it can be transferred to the board and executed as illustrated below:

U-Boot> tftp 0x20000000 sl013-aon-30010-flash-script.img
U-Boot> source 0x20000000

U-Boot will execute all commands in the script line-by-line until the script has finished, at which point the U-boot prompt will be returned to the user.