Running a Script in U-boot

Document created by Leonardo Sandoval Gonzalez Employee on Oct 15, 2012Last modified by Jodi Paul on Apr 19, 2013
Version 1Show Document
  • View in full screen mode


  • An TFTP server
  • U-boot with TFTP capabilities


If you need to run a script (for example, running multiple setenv's commands) in U-boot for many boards, you can instead create a U-boot script (called script image), place it into your tftp folder, then ask U-boot to fetch it and run it. For example, you want to run the following setenv instructions


setenv loadaddr 0x10800000

setenv bootargs_base 'setenv bootargs console=ttymxc0,115200'

setenv bootargs_mmc 'setenv bootargs ${bootargs} root=/dev/mmcblk0p1 rootwait rw video=mxcfb0:dev=ldb,LDB-XGA,if=RGB666'

setenv bootcmd_mmc 'run bootargs_base bootargs_mmc;mmc dev 3;mmc read ${loadaddr} 0x800 0x2000;bootm'

run bootcmd_mmc


save it into a file, I choose the name 'myscript'; under your <U-boot folder>/tools, execute


$ mkimage -T script -C none -n 'My Script' -d myscript myscript.img


and copy myscript.img file into your TFTP folder.


On the target, set the following two variables (serverip and bootcmd)


# Set the Server IP, where the TFTP server is running

setenv serverip <the server IP> # In case the server IP is static, you can place this line into the U-boot script

setenv scriptaddr 0x10700000

setenv scriptname myscript.img


# You can use either TFTP or DHCP

setenv tftpcmd tftp # or 'dhcp'  in case you want to use dhcp U-boot command

# Not needed for dhcp

setenv ipaddr <the target IP> # needed in case the command tftp is used

setenv gatewayip <the Gateway IP> # needed in case the command tftp is used


setenv bootcmd '${tftpcmd} ${scriptaddr} ${scriptname}; source ${scriptaddr}'



That is all you need to do.

Enjoy U-booting!