U-Boot allows to store commands or command sequences in a plain text file.
Using the
mkimage
tool you can then convert this file into a
script image
which can be executed using U-Boot's
source
command.
For example, assume that you will have to run the following sequence of commands
on many boards, so you store them in a text file, say
"setenv-commands"
:
bash$ cat setenv-commands
setenv loadaddr 00200000
echo ===== U-Boot settings =====
setenv u-boot /tftpboot/TQM860L/u-boot.bin
setenv u-boot_addr 40000000
setenv load_u-boot 'tftp ${loadaddr} ${u-boot}'
setenv install_u-boot 'protect off ${u-boot_addr} +${filesize};era ${u-boot_addr} +${filesize};cp.b ${loadaddr} ${u-boot_addr} ${filesize};saveenv'
setenv update_u-boot run load_u-boot install_u-boot
echo ===== Linux Kernel settings =====
setenv bootfile /tftpboot/TQM860L/uImage
setenv kernel_addr 40040000
setenv load_kernel 'tftp ${loadaddr} ${bootfile};'
setenv install_kernel 'era ${kernel_addr} +${filesize};cp.b ${loadaddr} ${kernel_addr} ${filesize}'
setenv update_kernel run load_kernel install_kernel
echo ===== Ramdisk settings =====
setenv ramdisk /tftpboot/TQM860L/uRamdisk
setenv ramdisk_addr 40100000
setenv load_ramdisk 'tftp ${loadaddr} ${ramdisk};'
setenv install_ramdisk 'era ${ramdisk_addr} +${filesize};cp.b ${loadaddr} ${ramdisk_addr} ${filesize}'
setenv update_ramdisk run load_ramdisk install_ramdisk
echo ===== Save new definitions =====
saveenv
bash$
To convert the text file into a script image for U-Boot,
you have to use the
mkimage
tool as follows:
bash$ mkimage -T script -C none -n 'Demo Script File' -d setenv-commands setenv.img
Image Name: Demo Script File
Created: Mon Jun 6 13:33:14 2005
Image Type: PowerPC Linux Script (uncompressed)
Data Size: 1147 Bytes = 1.12 kB = 0.00 MB
Load Address: 0x00000000
Entry Point: 0x00000000
Contents:
Image 0: 1139 Bytes = 1 kB = 0 MB
bash$
On the target, you can download this image as usual (for example, using the
"tftp"
command).
Use the
"source"
command to execute it:
=> tftp 100000 /tftpboot/TQM860L/setenv.img
Using FEC ETHERNET device
TFTP from server 192.168.3.1; our IP address is 192.168.3.80
Filename '/tftpboot/TQM860L/setenv.img'.
Load address: 0x100000
Loading: #
done
Bytes transferred = 1211 (4bb hex)
=> imi 100000
## Checking Image at 00100000 ...
Image Name: Demo Script File
Created: 2005-06-06 11:33:14 UTC
Image Type: PowerPC Linux Script (uncompressed)
Data Size: 1147 Bytes = 1.1 kB
Load Address: 00000000
Entry Point: 00000000
Verifying Checksum ... OK
=> source 100000
## Executing script at 00100000
===== U-Boot settings =====
===== Linux Kernel settings =====
===== Ramdisk settings =====
===== Save new definitions =====
Saving Environment to Flash...
Un-Protected 1 sectors
Un-Protected 1 sectors
Erasing Flash...
. done
Erased 1 sectors
Writing to Flash... done
Protected 1 sectors
Protected 1 sectors
=>

Hint: maximum flexibility can be achieved if you are using the
Hush shell as command interpreter in U-Boot; see section
14.2.17. How the Command Line Parsing Works