Loading Images with U-Boot

From wiki.emacinc.com
Revision as of 18:12, 6 May 2013 by Tstratman (talk | contribs) (added executing from RAM section)
Jump to: navigation, search

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 are beyond the scope of this document. EMAC recommends the tftpd package for use on Debian or Ubuntu Linux systems. For Windows, the Tftpd32 server works well.

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 an 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 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...