手机版
你好,游客 登录 注册
背景:
阅读新闻

U-Boot串口初始化详解

[日期:2012-03-22] 来源:Linux社区  作者:ce123 [字体:大 中 小]

三、console_init_f

控制台的前期初始化。

  1. int console_init_f (void)  
  2. {  
  3.     gd->have_console = 1;  
  4.   
  5. #ifdef CONFIG_SILENT_CONSOLE  
  6.     if (getenv("silent") != NULL)  
  7.         gd->flags |= GD_FLG_SILENT;  
  8. #endif  
  9.   
  10.     return (0);  
  11. }  

四、devices_init

这一部分在前面的文章已经分析过了,这里就不在叙述了。

五、console_init_r

控制台后期初始化。查看环境参数stdin,stdout,stderr中对标准IO的指定的设备名称,如果没有知道再按照环境指定的名称搜索devlist,将搜到的设备指针赋给标准IO数组stdio_devices[]。

  1. int console_init_r (void)  
  2. {  
  3.     char *stdinname, *stdoutname, *stderrname;  
  4.     device_t *inputdev = NULL, *outputdev = NULL, *errdev = NULL;  
  5. #ifdef CFG_CONSOLE_ENV_OVERWRITE  
  6.     int i;  
  7. #endif /* CFG_CONSOLE_ENV_OVERWRITE */  
  8.   
  9.     /* set default handlers at first 设置跳转表*/  
  10.     gd->jt[XF_getc] = serial_getc;  
  11.     gd->jt[XF_tstc] = serial_tstc;  
  12.     gd->jt[XF_putc] = serial_putc;  
  13.     gd->jt[XF_puts] = serial_puts;  
  14.     gd->jt[XF_printf] = serial_printf;  
  15.   
  16.     /* stdin stdout and stderr are in environment 查看环境参数stdin,stdout,stderr中对标准IO的指定的设备名称*/  
  17.     /* scan for it */  
  18.     stdinname  = getenv ("stdin");  
  19.     stdoutname = getenv ("stdout");  
  20.     stderrname = getenv ("stderr");  
  21.   
  22.     if (OVERWRITE_CONSOLE == 0) {   /* if not overwritten by config switch */  
  23.         inputdev  = search_device (DEV_FLAGS_INPUT,  stdinname);  
  24.         outputdev = search_device (DEV_FLAGS_OUTPUT, stdoutname);  
  25.         errdev    = search_device (DEV_FLAGS_OUTPUT, stderrname);  
  26.     }  
  27.     /* if the devices are overwritten or not found, use default device 按指定的名称搜索设备*/  
  28.     if (inputdev == NULL) {  
  29.         inputdev  = search_device (DEV_FLAGS_INPUT,  "serial");  
  30.     }  
  31.     if (outputdev == NULL) {  
  32.         outputdev = search_device (DEV_FLAGS_OUTPUT, "serial");  
  33.     }  
  34.     if (errdev == NULL) {  
  35.         errdev    = search_device (DEV_FLAGS_OUTPUT, "serial");  
  36.     }  
  37.     /* Initializes output console first将搜到的设备指针赋给标准IO数组stdio_devices[],在下面会将为什么要这样做 */  
  38.     if (outputdev != NULL) {  
  39.         console_setfile (stdout, outputdev);  
  40.     }  
  41.     if (errdev != NULL) {  
  42.         console_setfile (stderr, errdev);  
  43.     }  
  44.     if (inputdev != NULL) {  
  45.         console_setfile (stdin, inputdev);  
  46.     }  
  47.   
  48.     gd->flags |= GD_FLG_DEVINIT; /* device initialization completed,到此串口设备才初始化完成,这个标志会影响getc等函数 */  
  49.   
  50. #ifndef CFG_CONSOLE_INFO_QUIET  
  51.     /* Print information 打印信息*/  
  52.     puts ("In:    ");  
  53.     if (stdio_devices[stdin] == NULL) {  
  54.         puts ("No input devices available!\n");  
  55.     } else {  
  56.         printf ("%s\n", stdio_devices[stdin]->name);  
  57.     }  
  58.   
  59.     puts ("Out:   ");  
  60.     if (stdio_devices[stdout] == NULL) {  
  61.         puts ("No output devices available!\n");  
  62.     } else {  
  63.         printf ("%s\n", stdio_devices[stdout]->name);  
  64.     }  
  65.   
  66.     puts ("Err:   ");  
  67.     if (stdio_devices[stderr] == NULL) {  
  68.         puts ("No error devices available!\n");  
  69.     } else {  
  70.         printf ("%s\n", stdio_devices[stderr]->name);  
  71.     }  
  72. #endif /* CFG_CONSOLE_INFO_QUIET */  
  73.   
  74. #ifdef CFG_CONSOLE_ENV_OVERWRITE  
  75.     /* set the environment variables (will overwrite previous env settings) */  
  76.     for (i = 0; i < 3; i++) {  
  77.         setenv (stdio_names[i], stdio_devices[i]->name);  
  78.     }  
  79. #endif /* CFG_CONSOLE_ENV_OVERWRITE */  
  80.   
  81. #if 0  
  82.     /* If nothing usable installed, use only the initial console */  
  83.     if ((stdio_devices[stdin] == NULL) && (stdio_devices[stdout] == NULL))  
  84.         return (0);  
  85. #endif  
  86.     return (0);  
  87. }  
linux
相关资讯       U-boot 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款