uboot分析之cconsole_init_r函数

来源:互联网 发布:qt多窗口编程 编辑:程序博客网 时间:2024/06/09 17:29

在开发板启动的过程中,在uboot阶段,我们会看到串口输出一段:

In:    serial
Out:   serial
Err:   serial

经过调试,定位程序输出调用函数为:cconsole_init_r。

下边,我们再来看在/arm/arm/lib/borad.c中关于board_init_r部分的.cconsole_init_r

函数,他是关于个中设备初始化的函数。具体如下:
     1    /* Called after the relocation - use desired console functions */     2    int console_init_r (void)     3    {     4        device_t *inputdev = NULL, *outputdev = NULL;     5        int i, items = ListNumItems (devlist); // 第5行, 取得设备链中的设备数     6        /* Scan devices looking for input and output devices */     7        for (i = 1;     8             (i <= items) && ((inputdev == NULL) || (outputdev == NULL));     9             i++    10            ) {    11            device_t *dev = ListGetPtrToItem (devlist, i);    12            if ((dev->flags & DEV_FLAGS_INPUT) && (inputdev == NULL)) {    13                inputdev = dev;    14            }    15            if ((dev->flags & DEV_FLAGS_OUTPUT) && (outputdev == NULL)) {    16                outputdev = dev;    17            }    18        }// 7~18行,在设备链中按注册的顺序查找输入输出设备,在设备注册时 dev.flags表示此设备的类型。// 比如这里drv_system_init,此设备是第一个注册的设备,且其dev.flags为// DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT | DEV_FLAGS_SYSTEM 所以上面18行过后,输入输出设备都指定为// drv_system_init里注册的设备了    19        /* Initializes output console first */    20        if (outputdev != NULL) {    21            console_setfile (stdout, outputdev);    22            console_setfile (stderr, outputdev);    23        }    24        /* Initializes input console */    25        if (inputdev != NULL) {    26            console_setfile (stdin, inputdev);    27        }21~27行, console_setfile做如下几件事:1. 如果初始化该设备时注册了device_t.start,即启动设备的函数,则运行该函数,开启该设备2. 将设备的指针存入stdio_devices[file],这应该是标准输入标准输出、标准出错。       #define stdin        0      #define stdout        1        #define stderr        222行将标准出错定为输出设备,这样有错误信息就会通过输出设备打印出来了    28        gd->flags |= GD_FLG_DEVINIT;    /* device initialization completed */    29        /* Print information */    30        puts ("In:    ");    31        if (stdio_devices[stdin] == NULL) {    32            puts ("No input devices available!\n");    33        } else {    34            printf ("%s\n", stdio_devices[stdin]->name);    35        }    36        puts ("Out:   ");    37        if (stdio_devices[stdout] == NULL) {    38            puts ("No output devices available!\n");    39        } else {    40            printf ("%s\n", stdio_devices[stdout]->name);    41        }    42        puts ("Err:   ");    43        if (stdio_devices[stderr] == NULL) {    44            puts ("No error devices available!\n");    45        } else {    46            printf ("%s\n", stdio_devices[stderr]->name);    47        }30~47行,将信息打印出来,这里打印出出的信息就为In:    serialOut:   serialErr:   serial    48        /* Setting environment variables */    49        for (i = 0; i < 3; i++) {    50            setenv (stdio_names[i], stdio_devices[i]->name);    51        }49~51行 将信息写到环境变量中去char *stdio_names[MAX_FILES] = { "stdin", "stdout", "stderr" };这样环境变量里 stdin stdout stderr 都为serial    52        return (0);    53    }

现在应该明白串口在uboot启动阶段为什么会输出

In:    serial
Out:   serial
Err:   serial

以及他的作用了吧~
原创粉丝点击