Uboot 中的hush shell

来源:互联网 发布:linux私房菜在线阅读 编辑:程序博客网 时间:2024/06/06 19:33

今天有一个要求,要在uboot启动后不断的执行一些命令。方法记录一下:

1.直接改代码,比较麻烦。

2.制作uboot的执行脚本,用mkimage命令,然后通过tftp下载到内存,然后通过source命令来执行。这个也挺麻烦的。

3.还有一个方法是使用hush shell,uboot中定义了CONFIG_SYS_HUSH_PARSE就可以支持,

网上有资料说uboot中的hush shell是从busybox移植来的,进行了一些精简。但是查找hush shell的使用资料没有找到,直接把好用的命令记下来吧

setenv loopping while true\; do ping 192.168.1.1\; done\;

run loopping


这里是实现不停的执行ping命令。

下面贴一下资料,供参考和进一步研究

Hush shell:

  • similar to Bourne shell, with control structures like if...then...else...fifor...do...donewhile...do...doneuntil...do...done, ...
  • supports environment ("global") variables (through setenv / saveenv commands) and local shell variables (through standard shell syntax name=value ); only environment variables can be used with the run command, especially as the variable to run (i. e. the first argument).
  • In the current implementation, the local variables space and global environment variables space are separated. Local variables are those you define by simply typing like name=value. To access a local variable later on, you have to write '$name' or '${name}'; to execute the contents of a variable directly you can type '$name' at the command prompt. Note that local variables can only be used for simple commands, not for compound commands etc.
  • Global environment variables are those you can set and print using setenv and printenv. To run a command stored in such a variable, you need to use the run command, and you must not use the '$' sign to access them.
  • To store commands and special characters in a variable, use single quotation marks surrounding the whole text of the variable, instead of the backslashes before semicolons and special symbols.
  • Be careful when using the hash ('#') character - like with a "real" Bourne shell it is the comment character, so you have to escape it when you use it in the value of a variable.

Examples:

        setenv bootcmd bootm \$address        setenv addip 'setenv bootargs $bootargs ip=$ipaddr:$serverip:$gatewayip:$netmask:$hostname:$netdev:off'