uboot自定认命令学习笔记

 

================================================================================================
    uboot的命令实现
================================================================================================
按照步骤烧写uboot到开发板
测试命令
#显示环境变量
MINI6410 # print
bootargs=root=/dev/mtdblock2 rootfstype=yaffs2 init=/linuxrc console=ttySAC0,115200 androidboot.console=s3c2410_serial0
bootcmd=nand read.i c0008000 80000 500000;bootm c0008000
bootdelay=1
baudrate=115200
ethaddr=08:90:90:90:90:90
ipaddr=192.168.1.230
serverip=192.168.1.88
gatewayip=192.168.1.1
netmask=255.255.255.0
stdin=serial
stdout=serial
stderr=serial
#打印内个存地址的内容
MINI6410 # md.w 0
00000000: 002b ea00 0006 ea00 000b ea00 0010 ea00    +...............
00000010: 0015 ea00 fffe eaff 0019 ea00 001e ea00    ................
00000020: fffe eaff d004 e24d 0001 e92d 02ac e59f    ......M...-.....
00000030: 0000 e590 0004 e58d 8001 e8bd d004 e24d    ..............M.
00000040: 0001 e92d 0298 e59f 0000 e590 0004 e58d    ..-.............
00000050: 8001 e8bd d004 e24d 0001 e92d 0284 e59f    ......M...-.....
00000060: 0000 e590 0004 e58d 8001 e8bd d004 e24d    ..............M.
00000070: 0001 e92d 0270 e59f 0000 e590 0004 e58d    ..-.p...........

命令的执行步骤
1 命令行输入命令字符
2 将命令转化为函数

查看命令的结构体
以下是common/main.c的部分代码:

int run_command (const char *cmd, int flag)
{
 cmd_tbl_t *cmdtp;
 char cmdbuf[CONFIG_SYS_CBSIZE]; /* working copy of cmd  */
 char *token;   /* start of token in cmdbuf */
 char *sep;   /* end of token (separator) in cmdbuf */
 char finaltoken[CONFIG_SYS_CBSIZE];
 char *str = cmdbuf;
 char *argv[CONFIG_SYS_MAXARGS + 1]; /* NULL terminated */
 int argc, inquotes;
 int repeatable = 1;
 int rc = 0;

#ifdef DEBUG_PARSER
 printf ("[RUN_COMMAND] cmd[%p]=\"", cmd);
 puts (cmd ? cmd : "NULL"); /* use puts - string may be loooong */
 puts ("\"\n");
#endif

 clear_ctrlc();  /* forget any previous Control C */

 if (!cmd || !*cmd) {
  return -1; /* empty command */
 }

 if (strlen(cmd) >= CONFIG_SYS_CBSIZE) {
  puts ("## Command too long!\n");
  return -1;
 }

 strcpy (cmdbuf, cmd);

 /* Process separators and check for invalid
  * repeatable commands
  */

#ifdef DEBUG_PARSER
 printf ("[PROCESS_SEPARATORS] %s\n", cmd);
#endif
 while (*str) {

  /*
   * Find separator, or string end
   * Allow simple escape of ';' by writing "\;"
   */
  for (inquotes = 0, sep = str; *sep; sep++) {
   if ((*sep=='\'') &&
       (*(sep-1) != '\\'))
    inquotes=!inquotes;

   /*多个命令的情况,分号隔开*/
   if (!inquotes &&

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值