Skip to content

天楚锐齿

人工智能 云计算 大数据 物联网 IT 通信 嵌入式

天楚锐齿

  • 下载
  • 物联网
  • 云计算
  • 大数据
  • 人工智能
  • Linux&Android
  • 网络
  • 通信
  • 嵌入式
  • 杂七杂八

mini6410板uboot的Main.c

2018-03-13
其中的main_loop函数如下:
void main_loop (void)
{
#ifndef CFG_HUSH_PARSER
static char lastcommand[CFG_CBSIZE] = { 0, };
int len;
int rc = 1;
int flag;
#endif

#if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0)
char *s;
int bootdelay;
#endif
#ifdef CONFIG_PREBOOT
char *p;
#endif
#ifdef CONFIG_BOOTCOUNT_LIMIT
unsigned long bootcount = 0;
unsigned long bootlimit = 0;
char *bcs;
char bcs_set[16];
#endif /* CONFIG_BOOTCOUNT_LIMIT */

#if defined(CONFIG_VFD) && defined(VFD_TEST_LOGO)
ulong bmp = 0;          /* default bitmap */
extern int trab_vfd (ulong bitmap);

#ifdef CONFIG_MODEM_SUPPORT
if (do_mdm_init)
bmp = 1;     /* alternate bitmap */
#endif
trab_vfd (bmp);
#endif     /* CONFIG_VFD && VFD_TEST_LOGO */

#ifdef CONFIG_BOOTCOUNT_LIMIT
bootcount = bootcount_load();
bootcount++;
bootcount_store (bootcount);
sprintf (bcs_set, “%lu”, bootcount);
setenv (“bootcount”, bcs_set);
bcs = getenv (“bootlimit”);
bootlimit = bcs ? simple_strtoul (bcs, NULL, 10) : 0;
#endif /* CONFIG_BOOTCOUNT_LIMIT */

#ifdef CONFIG_MODEM_SUPPORT
debug (“DEBUG: main_loop:   do_mdm_init=%d\n”, do_mdm_init);
if (do_mdm_init) {
char *str = strdup(getenv(“mdm_cmd”));
setenv (“preboot”, str);  /* set or delete definition */
if (str != NULL)
free (str);
mdm_init(); /* wait for modem connection */
}
#endif  /* CONFIG_MODEM_SUPPORT */

#ifdef CONFIG_VERSION_VARIABLE
{
extern char version_string[];

setenv (“ver”, version_string);  /* set version variable */
}
#endif /* CONFIG_VERSION_VARIABLE */

#ifdef CFG_HUSH_PARSER
u_boot_hush_start ();
#endif

#ifdef CONFIG_AUTO_COMPLETE
install_auto_complete();
#endif

#ifdef CONFIG_PREBOOT
if ((p = getenv (“preboot”)) != NULL) {
# ifdef CONFIG_AUTOBOOT_KEYED
int prev = disable_ctrlc(1);     /* disable Control C checking */
# endif

# ifndef CFG_HUSH_PARSER
run_command (p, 0);
# else
parse_string_outer(p, FLAG_PARSE_SEMICOLON |
FLAG_EXIT_FROM_LOOP);
# endif

# ifdef CONFIG_AUTOBOOT_KEYED
disable_ctrlc(prev);     /* restore Control C checking */
# endif
}
#endif /* CONFIG_PREBOOT */

#if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0)
s = getenv (“bootdelay”);
bootdelay = s ? (int)simple_strtol(s, NULL, 10) : CONFIG_BOOTDELAY;

debug (“### main_loop entered: bootdelay=%d\n\n”, bootdelay);

# ifdef CONFIG_BOOT_RETRY_TIME
init_cmd_timeout ();
# endif     /* CONFIG_BOOT_RETRY_TIME */

#ifdef CONFIG_BOOTCOUNT_LIMIT
if (bootlimit && (bootcount > bootlimit)) {
printf (“Warning: Bootlimit (%u) exceeded. Using altbootcmd.\n”,
(unsigned)bootlimit);
s = getenv (“altbootcmd”);
}
else
#endif /* CONFIG_BOOTCOUNT_LIMIT */
s = getenv (“bootcmd”);

debug (“### main_loop: bootcmd=\”%s\”\n”, s ? s : “<UNDEFINED>”);

if (bootdelay >= 0 && s && !abortboot (bootdelay)) {
# ifdef CONFIG_AUTOBOOT_KEYED
int prev = disable_ctrlc(1);     /* disable Control C checking */
# endif

# ifndef CFG_HUSH_PARSER
run_command (s, 0);
# else
parse_string_outer(s, FLAG_PARSE_SEMICOLON |
FLAG_EXIT_FROM_LOOP);
# endif

# ifdef CONFIG_AUTOBOOT_KEYED
disable_ctrlc(prev);     /* restore Control C checking */
# endif
}

# ifdef CONFIG_MENUKEY
if (menukey == CONFIG_MENUKEY) {
s = getenv(“menucmd”);
if (s) {
# ifndef CFG_HUSH_PARSER
run_command (s, 0);
# else
parse_string_outer(s, FLAG_PARSE_SEMICOLON |
FLAG_EXIT_FROM_LOOP);
# endif
}
}
#endif /* CONFIG_MENUKEY */
#endif     /* CONFIG_BOOTDELAY */

#ifdef CONFIG_AMIGAONEG3SE
{
extern void video_banner(void);
video_banner();
}
#endif

FriendlyARMMenu();
/*
* Main Loop for Monitor Command Processing
*/
#ifdef CFG_HUSH_PARSER
parse_file_outer();
/* This point is never reached */
for (;;);
#else
for (;;) {
#ifdef CONFIG_BOOT_RETRY_TIME
if (rc >= 0) {
/* Saw enough of a valid command to
* restart the timeout.
*/
reset_cmd_timeout();
}
#endif
len = readline (CFG_PROMPT);

flag = 0;     /* assume no special flags for now */
if (len > 0)
strcpy (lastcommand, console_buffer);
else if (len == 0)
flag |= CMD_FLAG_REPEAT;
#ifdef CONFIG_BOOT_RETRY_TIME
else if (len == -2) {
/* -2 means timed out, retry autoboot
*/
puts (“\nTimed out waiting for command\n”);
# ifdef CONFIG_RESET_TO_RETRY
/* Reinit board to run initialization code again */
do_reset (NULL, 0, 0, NULL);
# else
return;          /* retry autoboot */
# endif
}
#endif

if (len == -1)
puts (“<INTERRUPT>\n”);
else
rc = run_command (lastcommand, flag);            /*从命令行读入命令,然后执行,run_command函数定义在同一个文件的下面部分*/

if (rc <= 0) {
/* invalid command or not repeatable, forget it */
lastcommand[0] = 0;
}
}
#endif /*CFG_HUSH_PARSER*/
}

int run_command (const char *cmd, int flag)
{
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 (strlen(cmd) >= CFG_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 &&
(*sep == ‘;’) &&     /* separator          */
( sep != str) &&     /* past string start     */
(*(sep-1) != ‘\\’))     /* and NOT escaped     */
break;
}

/*
* Limit the token to data between separators
*/
token = str;
if (*sep) {
str = sep + 1;     /* start of command for next pass */
*sep = ‘\0’;
}
else
str = sep;     /* no more commands for next pass */
#ifdef DEBUG_PARSER
printf (“token: \”%s\”\n”, token);
#endif

/* find macros in this token and replace them */
process_macros (token, finaltoken);

/* Extract arguments */
if ((argc = parse_line (finaltoken, argv)) == 0) {
rc = -1;     /* no command at all */
continue;
}

/* Look up command in command table */
if ((cmdtp = find_cmd(argv[0])) == NULL) {                                 /*找到命令对应的结构,结构定义在command.h里面,是一个结构数组,每个命令对应一个结构,命令定义在各个处理文件中,这个结构数组单独用了一个汇编段:__u_boot_cmd_start,定义uboot.lds文件中,举例:boot linux的命令定义在Cmd_bootm.c里面的U_BOOT_CMD这里,它的处理函数是do_bootm。*/
printf (“Unknown command ‘%s’ – try ‘help’\n”, argv[0]);
rc = -1;     /* give up after bad command */
continue;
}

/* found – check max args */
if (argc > cmdtp->maxargs) {
printf (“Usage:\n%s\n”, cmdtp->usage);
rc = -1;
continue;
}

#if (CONFIG_COMMANDS & CFG_CMD_BOOTD)
/* avoid “bootd” recursion */
if (cmdtp->cmd == do_bootd) {
#ifdef DEBUG_PARSER
printf (“[%s]\n”, finaltoken);
#endif
if (flag & CMD_FLAG_BOOTD) {
puts (“‘bootd’ recursion detected\n”);
rc = -1;
continue;
} else {
flag |= CMD_FLAG_BOOTD;
}
}
#endif     /* CFG_CMD_BOOTD */

/* OK – call function to do the command */
if ((cmdtp->cmd) (cmdtp, flag, argc, argv) != 0) {                             /*执行命令,比如boot linux就是执行do_bootm函数,这个函数定义在Cmd_bootm.c里面。*/
rc = -1;
}

repeatable &= cmdtp->repeatable;

/* Did the user stop this? */
if (had_ctrlc ())
return 0;     /* if stopped then not repeatable */
}

return rc ? rc : repeatable;
}

1,109次阅读

Post navigation

前一篇:

mini6410板uboot的lowlevel_init.S

后一篇:

mini6410板uboot的Nand_cp.c

发表回复 取消回复

要发表评论,您必须先登录。

个人介绍

需要么,有事情这里找联系方式:关于天楚锐齿

=== 美女同欣赏,好酒共品尝 ===

微信扫描二维码赞赏该文章:

扫描二维码分享该文章:

分类

  • Linux&Android (81)
  • Uncategorized (1)
  • 下载 (28)
  • 云计算 (38)
  • 人工智能 (9)
  • 大数据 (35)
  • 嵌入式 (34)
  • 杂七杂八 (35)
  • 物联网 (65)
  • 网络 (25)
  • 通信 (22)

归档

近期文章

  • 飞书机器人发送卡片interactive消息
  • Springboot JPA实现对数据库表统一的增删改查
  • WEB的内容安全策略CSP(Content-Security-Policy)
  • CSS利用@media和viewport实现响应式布局自动适配手机电脑等
  • VUE前端增加国际化支持

近期评论

  • linux爱好者 发表在《Linux策略路由及iptables mangle、ip rule、ip route关系及一种Network is unreachable错误》
  • maxshu 发表在《使用Android的HIDL+AIDL方式编写从HAL层到APP层的程序》
  • Ambition 发表在《使用Android的HIDL+AIDL方式编写从HAL层到APP层的程序》
  • Ambition 发表在《使用Android的HIDL+AIDL方式编写从HAL层到APP层的程序》
  • maxshu 发表在《Android9下用ethernet 的Tether模式来做路由器功能》

阅读量

  • 使用Android的HIDL+AIDL方式编写从HAL层到APP层的程序 - 23,810次阅读
  • 卸载深信服Ingress、SecurityDesktop客户端 - 18,519次阅读
  • 车机技术之车规级Linux-Automotive Grade Linux(AGL) - 10,569次阅读
  • linux下的unbound DNS服务器设置详解 - 9,323次阅读
  • 在Android9下用ndk编译vSomeIP和CommonAPI以及使用例子 - 9,136次阅读
  • linux的tee命令导致ssh客户端下的shell卡住不动 - 8,639次阅读
  • Linux策略路由及iptables mangle、ip rule、ip route关系及一种Network is unreachable错误 - 8,126次阅读
  • 车机技术之360°全景影像(环视)系统 - 8,088次阅读
  • 车机技术之Android Automotive - 7,940次阅读
  • Windows下安装QEMU并在qemu上安装ubuntu和debian - 7,840次阅读

其他操作

  • 注册
  • 登录
  • 条目 feed
  • 评论 feed
  • WordPress.org

联系方式

地址
深圳市科技园

时间
周一至周五:  9:00~12:00,14:00~18:00
周六和周日:10:00~12:00

标签

android AT命令 CAN centos docker Hadoop hdfs ip java kickstart linux mapreduce mini6410 modem nova OAuth openstack os python socket ssh uboot 内核 协议 安装 嵌入式 性能 报表 授权 操作系统 数据 数据库 月报 模型 汽车 深信服 源代码 统计 编译 脚本 虚拟机 调制解调器 车机 金融 鉴权
© 2025 天楚锐齿