U-Boot

From Gumstix User Wiki
Revision as of 11:19, 12 March 2010 by Ashcharles (Talk | contribs)

Jump to: navigation, search

boot.scr

On boot, U-Boot looks for a file called boot.scr which it will try to run. Users can create such a script to do boot time configuration of the board, do low-level testing, or set up the U-Boot environment. A common use case is to do a one-time configuration and reflash of boards to be deployed without microSD cards.

Example Script

For example, the script below flashes a new x-load, U-Boot, and kernel image to an Overo board. If it is mounted on an expansion board with LEDs, the blue one will light up if the script completes successfully or a red one will light up if the script fails.

setenv success 1
setenv loadaddr 0x82000000
setenv ext new
# clear daughter card LEDs (GPIO21 and GPIO22)
mw 48310034 ff9fffff
mw 48310094 00600000

# Two notes:
# 1. FAT file-systems handle letter case strangely---we should use
#    lower-case only
# 2. x-load should be copied first to the microSD card otherwise U-Boot
#    doesn't see it.

if mmc init; then
  echo "Flashing uimage${ext}..."
  nandecc sw
  nand erase
  if fatload mmc 1 ${loadaddr} uimage${ext}; then
     nand write ${loadaddr} 0x00280000 0x00200000
  else
    echo "ERROR: couldn\'t find uimage${ext}..."
    setenv success 0
  fi

  echo "Flashing u-boot${ext}.bin..."
  if fatload mmc 1 ${loadaddr} u-boot${ext}.bin; then
    nand write ${loadaddr} 0x00080000 0x001c0000
  else
    echo "ERROR: couldn\'t find u-boot${ext}.bin..."
    setenv success 0
  fi

  echo "Flashing x-load${ext}..."
  if fatload mmc 1 ${loadaddr} x-load${ext}; then
    nandecc hw
    nand write ${loadaddr} 0x00000000 0x00080000
  else
    echo "ERROR: couldn\'t find x-load${ext}..."
    setenv success 0
  fi
else
  echo "Please insert a microSD and reboot the board"
  setenv success 0
fi

# display error condition
if test $success -eq 1; then
  # SUCCESS: light up LED on GPIO22
  mw 48310090 00400000
  echo "COMPLETED SUCCESSFULLY"
else
  # ERROR: light up LED on GPIO21
  mw 48310090 00200000
  echo "COMPLETED WITH ERRORS"
fi

Note, this script uses a NAND flash layout similar to this:

root@overo:~# cat /proc/mtd 
dev:    size   erasesize  name
mtd0: 00080000 00020000 "xloader"
mtd1: 001c0000 00020000 "uboot"
mtd2: 00040000 00020000 "uboot environment"
mtd3: 00400000 00020000 "linux"
mtd4: 0f980000 00020000 "rootfs"

More sample scripts can be found in the recipes/angstrom/angstrom-uboot-scripts/ directory. This script does nothing when it finishes but many people will want to call boot, saveenv or reset depending on the application.

Usage

To use a script like this, it is necessary to convert this script file (e.g. myscript.cmd) to a U-Boot readable script. We use the U-Boot mkimage command to add the required header:

$ mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n "myscript" -d myscript.cmd boot.scr

Or simple copy myscript.cmd to the recipes/angstrom/angstrom-uboot-scripts/ directory, and do a bitbake

$ bitbake angstrom-uboot-scripts

This will generate a boot.scr file (or a myscript.cmd.scr file by the second method).

The following files should be loaded onto the FAT partition of a bootable microSD card (taking care to copy over x-load first):

  • x-load-new --- your new x-load
  • mlo --- a current bootloader
  • u-boot--- a current U-Boot
  • u-boot-new --- your new U-Boot
  • uimage-new --- your new ima

Unmount the microSD card from the host machine, load it onto your Gumstix COM, and boot the board. The boot.scr file should be run once x-load (MLO) has passed control to U-Boot.

Links