Running a Script in U-boot

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Running a Script in U-boot

Running a Script in U-boot

Pre-requisites:

  • 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}'

saveenv

reset


That is all you need to do.


Enjoy U-booting!

Comments

I have a custom made board of i.MX6, i have to add a script which test RAM working, for that i have to copy my script in SD/MMC(8GB) card,this testing will be done in uboot, now i need some help on this i have  created script file using mkimage. for this where i can copy and how to run that script at what address location. NOTE: i can't use tftp/dhcp because this board doesn't have tftp/dhcp support.

%3CLINGO-SUB%20id%3D%22lingo-sub-1111494%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERunning%20a%20Script%20in%20U-boot%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1111494%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%22%3EPre-requisites%3A%20%3C%2FSPAN%3E%3C%2FP%3E%3CUL%3E%3CLI%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%22%3EAn%20TFTP%20server%3C%2FSPAN%3E%3C%2FLI%3E%3CLI%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%22%3EU-boot%20with%20TFTP%20capabilities%3C%2FSPAN%3E%3C%2FLI%3E%3C%2FUL%3E%3CP%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%22%3EIf%20you%20need%20to%20run%20a%20script%20(for%20example%2C%20running%20multiple%20setenv's%20commands)%20in%20U-boot%20for%20many%20boards%2C%20you%20can%20instead%20create%20a%20U-boot%20script%20(called%20script%20image)%2C%20place%20it%20into%20your%20tftp%20folder%2C%20then%20ask%20U-boot%20to%20fetch%20it%20and%20run%20it.%20For%20example%2C%20you%20want%20to%20run%20the%20following%20setenv%20instructions%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%22%3E%3CEM%3Esetenv%20loadaddr%200x10800000%3C%2FEM%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%22%3E%3CEM%3Esetenv%20bootargs_base%20'setenv%20bootargs%20console%3Dttymxc0%2C115200'%3C%2FEM%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%22%3E%3CEM%3Esetenv%20bootargs_mmc%20'setenv%20bootargs%20%24%7Bbootargs%7D%20root%3D%2Fdev%2Fmmcblk0p1%20rootwait%20rw%20video%3Dmxcfb0%3Adev%3Dldb%2CLDB-XGA%2Cif%3DRGB666'%3C%2FEM%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%22%3E%3CEM%20style%3D%22color%3A%20black%3B%22%3E%3CEM%3E%3CEM%3Esetenv%20bootcmd_mmc%20'run%20bootargs_base%20bootargs_mmc%3Bmmc%20dev%203%3Bmmc%20read%20%24%7Bloadaddr%7D%200x800%200x2000%3Bbootm'%3C%2FEM%3E%3C%2FEM%3E%3C%2FEM%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%22%3E%3CEM%3E%3CEM%3E%3CSPAN%20style%3D%22color%3A%20black%3B%22%3Erun%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22color%3A%20black%3B%22%3Ebootcmd_mmc%3C%2FSPAN%3E%3C%2FEM%3E%3C%2FEM%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%22%3E%3CEM%3E%3CBR%20%2F%3E%3C%2FEM%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%22%3Esave%20it%20into%20a%20file%2C%20I%20choose%20the%20name%20'%3CEM%3Emyscript%3C%2FEM%3E'%3B%20under%20your%20%3CEM%3E%3CU-BOOT%20folder%3D%22%22%3E%2Ftools%3C%2FU-BOOT%3E%3C%2FEM%3E%2C%20execute%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%22%3E%3CEM%3E%24%20mkimage%20-T%20script%20-C%20none%20-n%20'My%20Script'%20-d%20myscript%20myscript.img%3C%2FEM%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%22%3Eand%20copy%20%3CEM%3Emyscript.img%3C%2FEM%3E%20file%20into%20your%20TFTP%20folder.%20%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%22%3EOn%20the%20target%2C%20set%20the%20following%20two%20variables%20(%3CEM%3Eserverip%3C%2FEM%3E%20and%20%3CEM%3Ebootcmd%3C%2FEM%3E)%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%22%3E%23%20Set%20the%20Server%20IP%2C%20where%20the%20TFTP%20server%20is%20running%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%22%3E%3CEM%3Esetenv%20serverip%20%3CTHE%20server%3D%22%22%20ip%3D%22%22%3E%20%23%20In%20case%20the%20server%20IP%20is%20static%2C%20you%20can%20place%20this%20line%20into%20the%20U-boot%20script%3C%2FTHE%3E%3C%2FEM%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%22%3E%3CEM%3Esetenv%20scriptaddr%20%3CEM%3E0x10700000%3C%2FEM%3E%3C%2FEM%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%22%3E%3CEM%3Esetenv%20scriptname%20myscript.img%3C%2FEM%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%22%3E%3CEM%3E%3CBR%20%2F%3E%3C%2FEM%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%22%3E%3CEM%3E%23%20You%20can%20use%20either%20TFTP%20or%20DHCP%3C%2FEM%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%22%3E%3CEM%3Esetenv%20tftpcmd%20tftp%20%23%20or%20'dhcp'%26nbsp%3B%20%3C%2FEM%3E%3CEM%3E%3CEM%3Ein%20case%20you%20want%20to%20use%20dhcp%20U-boot%20command%3C%2FEM%3E%3C%2FEM%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%22%3E%3CEM%3E%3CEM%3E%3CBR%20%2F%3E%3C%2FEM%3E%3C%2FEM%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%22%3E%3CEM%3E%23%20Not%20needed%20for%20dhcp%3CBR%20%2F%3E%3C%2FEM%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%22%3E%3CEM%3Esetenv%20ipaddr%20%3CTHE%20target%3D%22%22%20ip%3D%22%22%3E%20%23%20needed%20in%20case%20the%20command%20tftp%20is%20used%3C%2FTHE%3E%3C%2FEM%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%22%3E%3CEM%3Esetenv%20gatewayip%20%3CTHE%20gateway%3D%22%22%20ip%3D%22%22%3E%20%3CEM%3E%23%20needed%20in%20case%20the%20command%20tftp%20is%20used%3C%2FEM%3E%3CBR%20%2F%3E%3C%2FTHE%3E%3C%2FEM%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%22%3E%3CEM%3Esetenv%20bootcmd%20'%24%7Btftpcmd%7D%20%24%7Bscriptaddr%7D%20%24%7Bscriptname%7D%3B%20source%20%24%7Bscriptaddr%7D'%3C%2FEM%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%22%3E%3CEM%3Esaveenv%3C%2FEM%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%22%3E%3CEM%3Ereset%3CBR%20%2F%3E%3C%2FEM%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%22%3E%3CEM%3E%3CBR%20%2F%3E%3C%2FEM%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%22%3E%3CEM%3EThat%20is%20all%20you%20need%20to%20do.%3CBR%20%2F%3E%3C%2FEM%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%22%3E%3CEM%3E%3CBR%20%2F%3E%3C%2FEM%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%22%3EEnjoy%20U-booting!%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1111495%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20Running%20a%20Script%20in%20U-boot%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1111495%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EI%20have%20a%20custom%20made%20board%20of%20i.MX6%2C%20i%20have%20to%20add%20a%20script%20which%20test%20RAM%20working%2C%20for%20that%20i%20have%20to%20copy%20my%20script%20in%20SD%2FMMC(8GB)%20card%2Cthis%20testing%20will%20be%20done%20in%20uboot%2C%20now%20i%20need%20some%20help%20on%20this%20i%20have%26nbsp%3B%20created%20script%20file%20using%20mkimage.%20for%20this%20where%20i%20can%20copy%20and%20how%20to%20run%20that%20script%20at%20what%20address%20location.%20NOTE%3A%20i%20can't%20use%20tftp%2Fdhcp%20because%20this%20board%20doesn't%20have%20tftp%2Fdhcp%20support.%3C%2FP%3E%3C%2FLINGO-BODY%3E
No ratings
Version history
Last update:
‎10-15-2012 12:25 PM
Updated by: