三、console_init_f
控制台的前期初始化。
- int console_init_f (void)
- {
- gd->have_console = 1;
- #ifdef CONFIG_SILENT_CONSOLE
- if (getenv("silent") != NULL)
- gd->flags |= GD_FLG_SILENT;
- #endif
- return (0);
- }
四、devices_init
这一部分在前面的文章已经分析过了,这里就不在叙述了。
五、console_init_r
控制台后期初始化。查看环境参数stdin,stdout,stderr中对标准IO的指定的设备名称,如果没有知道再按照环境指定的名称搜索devlist,将搜到的设备指针赋给标准IO数组stdio_devices[]。
- int console_init_r (void)
- {
- char *stdinname, *stdoutname, *stderrname;
- device_t *inputdev = NULL, *outputdev = NULL, *errdev = NULL;
- #ifdef CFG_CONSOLE_ENV_OVERWRITE
- int i;
- #endif /* CFG_CONSOLE_ENV_OVERWRITE */
- /* set default handlers at first 设置跳转表*/
- gd->jt[XF_getc] = serial_getc;
- gd->jt[XF_tstc] = serial_tstc;
- gd->jt[XF_putc] = serial_putc;
- gd->jt[XF_puts] = serial_puts;
- gd->jt[XF_printf] = serial_printf;
- /* stdin stdout and stderr are in environment 查看环境参数stdin,stdout,stderr中对标准IO的指定的设备名称*/
- /* scan for it */
- stdinname = getenv ("stdin");
- stdoutname = getenv ("stdout");
- stderrname = getenv ("stderr");
- if (OVERWRITE_CONSOLE == 0) { /* if not overwritten by config switch */
- inputdev = search_device (DEV_FLAGS_INPUT, stdinname);
- outputdev = search_device (DEV_FLAGS_OUTPUT, stdoutname);
- errdev = search_device (DEV_FLAGS_OUTPUT, stderrname);
- }
- /* if the devices are overwritten or not found, use default device 按指定的名称搜索设备*/
- if (inputdev == NULL) {
- inputdev = search_device (DEV_FLAGS_INPUT, "serial");
- }
- if (outputdev == NULL) {
- outputdev = search_device (DEV_FLAGS_OUTPUT, "serial");
- }
- if (errdev == NULL) {
- errdev = search_device (DEV_FLAGS_OUTPUT, "serial");
- }
- /* Initializes output console first将搜到的设备指针赋给标准IO数组stdio_devices[],在下面会将为什么要这样做 */
- if (outputdev != NULL) {
- console_setfile (stdout, outputdev);
- }
- if (errdev != NULL) {
- console_setfile (stderr, errdev);
- }
- if (inputdev != NULL) {
- console_setfile (stdin, inputdev);
- }
- gd->flags |= GD_FLG_DEVINIT; /* device initialization completed,到此串口设备才初始化完成,这个标志会影响getc等函数 */
- #ifndef CFG_CONSOLE_INFO_QUIET
- /* Print information 打印信息*/
- puts ("In: ");
- if (stdio_devices[stdin] == NULL) {
- puts ("No input devices available!\n");
- } else {
- printf ("%s\n", stdio_devices[stdin]->name);
- }
- puts ("Out: ");
- if (stdio_devices[stdout] == NULL) {
- puts ("No output devices available!\n");
- } else {
- printf ("%s\n", stdio_devices[stdout]->name);
- }
- puts ("Err: ");
- if (stdio_devices[stderr] == NULL) {
- puts ("No error devices available!\n");
- } else {
- printf ("%s\n", stdio_devices[stderr]->name);
- }
- #endif /* CFG_CONSOLE_INFO_QUIET */
- #ifdef CFG_CONSOLE_ENV_OVERWRITE
- /* set the environment variables (will overwrite previous env settings) */
- for (i = 0; i < 3; i++) {
- setenv (stdio_names[i], stdio_devices[i]->name);
- }
- #endif /* CFG_CONSOLE_ENV_OVERWRITE */
- #if 0
- /* If nothing usable installed, use only the initial console */
- if ((stdio_devices[stdin] == NULL) && (stdio_devices[stdout] == NULL))
- return (0);
- #endif
- return (0);
- }
