Chinaunix首页 | 论坛 | 博客
  • 博客访问: 444470
  • 博文数量: 72
  • 博客积分: 3186
  • 博客等级: 中校
  • 技术积分: 1039
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-07 16:53
文章分类

全部博文(72)

文章存档

2012年(1)

2011年(5)

2010年(10)

2009年(56)

我的朋友

分类: 嵌入式

2009-12-19 20:50:58

去跳一些我没有用到的预编译之后,大致如下

     1    void main_loop (void)
     2    {
     3    #if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0)
     4            char *s;
     5            int bootdelay;
     6    #endif
     7    #if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0)
     8            s = getenv ("bootdelay");
     9            bootdelay = s ? (int)simple_strtol(s, NULL, 10) :
                            CONFIG_BOOTDELAY;

// 8~9行,到环境变量里取bootdelay时间,如果有这一项环境变量存在,则使用
// 环境变量里的值。若没有,则使用配置值CONFIG_BOOTDELAY

    10            debug ("### main_loop entered: bootdelay=%d\n\n", bootdelay);
    11            s = getenv ("bootcmd");
    12            debug ("### main_loop: bootcmd=\"%s\"\n", s ? s : "");
//11行,到环境变量里获取启动命令字符串
    13            if (bootdelay >= 0 && s && !abortboot (bootdelay)) {
                        run_command (s, 0);
    16            }
    17    #endif    /* CONFIG_BOOTDELAY */

// 1. bootdelay 是否大于等于0? 若为真,判断2
// 2. 是否有bootcmd这一项环境变量? 若为真,判断3
// 3. 延时(!abortboot), 若延时期间没有按下任意按键,则返回0, 经!之后
//    变为1
// 最终程序进入run_command直接执行s
//
// 以上三个条件是依次判断的,若有一个与上面描述不符,则跳过if语句,
// 进入下面的for语句里,即进入uboot的命令行里

    18            /*
    19             * Main Loop for Monitor Command Processing
    20             */
    21            for (;;) {
    22                    len = readline (CFG_PROMPT);
    23                    flag = 0; /* assume no special flags for now */
    24                    if (len > 0)
    25                            strcpy (lastcommand, console_buffer);
    26                    else if (len == 0)
    27                            flag |= CMD_FLAG_REPEAT;
    28                    if (len == -1)
    29                            puts ("\n");
    30                    else
    31                            rc = run_command (lastcommand, flag);
       
    32                    if (rc <= 0) {
    33                            /* invalid command or not repeatable, forget it */
    34                            lastcommand[0] = 0;
    35                    }
    36            }
    37    }
22行,读命令到console_buffer数组里,这个数组的定义实际上为
        char console_buffer[256];
31行可以看到,命令的执行都是通过run_command来实现的。

小结:
     main_loop()里实际上就是延时
     若延时期间未有按键,则直接启动环境变量里的启动命令。
     否则,进入终端,接收命令并执行它
阅读(2394) | 评论(0) | 转发(0) |
0

上一篇:5. console_init_r

下一篇:7. bootm命令

给主人留下些什么吧!~~