完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
以下皆是分析u-boot菜单控制 case '6': { strcpy(cmd_buf, "u***slave 1 0x30000000; nand erase root; nand write.yaffs 0x30000000 root $(filesize)"); run_command(cmd_buf, 0); break; } “case '6'”表示的是:在u-boot菜单界面中串口输入了字符"6",然后就是 cmd_buf[]=u***slave 1 0x30000000; nand erase root; nand write.yaffs 0x30000000 root $(filesize) 在此处有三条命令:1 u***slave 1 0x30000000 ; 2 nand erase root 3 nand write.yaffs 0x30000000 root $(filesize) 然后在run_command中一一解析他们 int run_command (const char *cmd, int flag) //cmd正是从串口获得的字符串 { cmd_tbl_t *cmdtp; char cmdbuf[CFG_CBSIZE]; /* working copy of cmd */ char *token; /* start of token in cmdbuf */ char *sep; /* end of token (separator) in cmdbuf */ char finaltoken[CFG_CBSIZE]; char *str = cmdbuf; char *argv[CFG_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语句判断命令是否太长, //还是避免有些变态的家伙输入了超过CFG_CBSIZE个字符的命令 if (strlen(cmd) >=CFG_CBSIZE)// 命令从console_buffer搬运到lastcommand中) { puts ("## Command too long!n"); return -1; strcpy (cmdbuf, cmd); //对命令又进行了一次拷贝 /* Process separators and check for invalidrepeatable commands*/ #ifdef DEBUG_PARSER printf ("[PROCESS_SEPARATORS] %sn", cmd); #endif //str就是指向cmdbuf的指针, 其实这些东西都是针对的刚才那行命令 //注释很清楚, 找到;作为命令结束符, 因为多个命令可以一次输入, 并以;分割. 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 && (*sep == ';') && /* separator */ ( sep != str) && /* past string start */ (*(sep-1) != '\')) /* and NOT escaped */ break; } //如果上面for循环找到一条以';'结束的命令, 那么sep指向命令末尾 /*Limit the token to data between separators */ token = str; if (*sep) { str = sep + 1; /* start of command for next pass */ *sep = ' |