U-Boot Scripts

From Utilite Wiki

Jump to: navigation, search

U-Boot commands can be run as precompiled scripts. This article describes the syntax and capabilities of U-Boot scripts, as well as the steps necessary to create and run script images.

Contents

Basic syntax

U-Boot scripting facilities support all the commands that are reported by U-Boot help command, as well as some flow control constructs:

if <list>; then <command list>; [ elif <list>; then <list>; ] ... [ else <list>; ] fi
while <list> ; do <list> ; done
until <list> ; do <list> ; done
for <name> in <word list> ; do <list> ; done

Values of variables are obtained using the following syntax:

 ${variable_name}

Supported command delimiters

; - a simple delimiter. All of the following commands will execute:

true; false; echo "hello world!"

&& - logical AND delimiter. The delimited commands will execute until one of them fails. For example:

echo "this will be printed" && echo "this will also be printed" && false && echo "this will not be printed"

|| - logical OR delimiter. The delimited commands will execute until one of them succeeds. For example:

false || false || echo "this will be printed" || echo "this will not be printed"

Tests and return values

When a command executes successfully, it returns 0. Otherwise, it returns 1.

Tests and comparisons are done using the test and itest commands. The test command can be used to compare environment variables, and supports the following syntax:

Expression Evaluated to TRUE if ...
 ! EXPRESSION EXPRESSION is false
EXPRESSION1 -a EXPRESSION2 both EXPRESSION1 and EXPRESSION2 are true
EXPRESSION1 -o EXPRESSION2 either EXPRESSION1 or EXPRESSION2 is true
-n STRING the length of STRING is non-zero
-z STRING the length of STRING is zero
STRING1 = STRING2 the strings are equal
STRING1 != STRING2 the strings are not equal
INTEGER1 -eq INTEGER2 INTEGER1 is equal to INTEGER2
INTEGER1 -ge INTEGER2 INTEGER1 is greater than or equal to INTEGER2
INTEGER1 -gt INTEGER2 INTEGER1 is greater than INTEGER2
INTEGER1 -le INTEGER2 INTEGER1 is less than or equal to INTEGER2
INTEGER1 -lt INTEGER2 INTEGER1 is less than INTEGER2
INTEGER1 -ne INTEGER2 INTEGER1 is not equal to INTEGER2

The command itest can be used to compare values in memory. The syntax for itest is:

itest[.b,.w,.l,.s] [*]value1 <op> [*]value2

Where the optional suffix means: .b byte .w short .l long (default) .s string

value1 and value2 can be a constant or address if preceded by a *.

<op> can be one of:

-lt	<		Less than
-gt	>		Greater than
-eq	==		Equal to
-ne	!=	<>	not Equal to
-ge	>=		Greater than or Equal to
-le	<=		Less than or Equal to

Using script images

Before a script can be run, it must be made into a script image. To do this, run the following command on your workstation:

mkimage -T script -C none -n 'My Script File' -d script_file.txt myscript.img

To run myscript.img, load it to a memory address, and execute

source <memory address>
Personal tools