zoukankan      html  css  js  c++  java
  • uboot传递参数'console=ttyXXX'的作用

    转载于:http://blog.csdn.net/jgdu1981/article/details/8643057

    linux启动时uboot传递进console=ttyS0,115200n8的参数

    内核中用__setup()宏声明参数处理的方法

    关于__setup宏参考 early_param和__setup宏

    1. __setup("console=", console_setup);  

    console_setup函数处理

    1.console_cmdline结构体

    1. struct console_cmdline  
    2. {  
    3.     char    name[8];        //驱动名  
    4.     int index;      //次设备号  
    5.     char    *options;       //选项  
    6. #ifdef CONFIG_A11Y_BRAILLE_CONSOLE  
    7.     char    *brl_options;     
    8. #endif  
    9. };  

    2.console_setup

    1. static int __init console_setup(char *str)  
    2. {  
    3.     char buf[sizeof(console_cmdline[0].name) + 4]; //分配驱动名+index的缓冲区  
    4.     char *s, *options, *brl_options = NULL;  
    5.     int idx;  
    6.   
    7. #ifdef CONFIG_A11Y_BRAILLE_CONSOLE  
    8.     if (!memcmp(str, "brl,", 4)) {  
    9.         brl_options = "";  
    10.         str += 4;  
    11.     } else if (!memcmp(str, "brl=", 4)) {  
    12.         brl_options = str + 4;  
    13.         str = strchr(brl_options, ',');  
    14.         if (!str) {  
    15.             printk(KERN_ERR "need port name after brl= ");  
    16.             return 1;  
    17.         }  
    18.         *(str++) = 0;  
    19.     }  
    20. #endif  
    21.     if (str[0] >= '0' && str[0] <= '9') { //第一个参数属于[0,9]  
    22.         strcpy(buf, "ttyS");    //则将其驱动名设为ttyS  
    23.         strncpy(buf + 4, str, sizeof(buf) - 5);//将次设备号放其后面  
    24.     } else {  
    25.         strncpy(buf, str, sizeof(buf) - 1); //放设备号到其后面  
    26.     }  
    27.     buf[sizeof(buf) - 1] = 0;  
    28.     if ((options = strchr(str, ',')) != NULL)   //获取options  
    29.         *(options++) = 0;  
    30. #ifdef __sparc__  
    31.     if (!strcmp(str, "ttya"))  
    32.         strcpy(buf, "ttyS0");  
    33.     if (!strcmp(str, "ttyb"))  
    34.         strcpy(buf, "ttyS1");  
    35. #endif  
    36.     for (s = buf; *s; s++)  
    37.         if ((*s >= '0' && *s <= '9') || *s == ',')  
    38.             break;  
    39.     idx = simple_strtoul(s, NULL, 10);  //获取次设备号  
    40.     *s = 0;  
    41.   
    42.     __add_preferred_console(buf, idx, options, brl_options);  
    43.     console_set_on_cmdline = 1;  
    44.     return 1;  
    45. }  

    __add_preferred_console函数

    1. static int __add_preferred_console(char *name, int idx, char *options,char *brl_options)  
    2. {  
    3.     struct console_cmdline *c;  
    4.     int i;  
    5.     for (i = 0; i < MAX_CMDLINECONSOLES && console_cmdline[i].name[0]; i++)  //可以最多8个console  
    6.         if (strcmp(console_cmdline[i].name, name) == 0 && console_cmdline[i].index == idx) {  
    7.             //比较已注册的console_cmdline数组中的项的名字及次设备号,若console_cmdline已经存在  
    8.                 if (!brl_options)  
    9.                     selected_console = i;   //设置全局selected_console索引号  
    10.                 return 0;       //则返回  
    11.         }  
    12.     if (i == MAX_CMDLINECONSOLES)   //判断console_cmdline数组是否满了  
    13.         return -E2BIG;  
    14.     if (!brl_options)  
    15.         selected_console = i;   //设置全局selected_console索引号  
    16.     c = &console_cmdline[i];    //获取全局console_cmdline数组的第i项地址  
    17.     strlcpy(c->name, name, sizeof(c->name));  //填充全局console_cmdline的驱动名  
    18.     c->options = options;    //填充配置选项115200n8  
    19. #ifdef CONFIG_A11Y_BRAILLE_CONSOLE  
    20.     c->brl_options = brl_options;  
    21. #endif  
    22.     c->index = idx;  //填充索引号0  
    23.     return 0;  
    24. }  

    整体的作用是根据uboot传递的参数设置全局console_cmdline数组 该数组及全局selected_console,在register_console中会使用到 二 console 设备驱动

  • 相关阅读:
    LeetCode
    LeetCode
    一篇真正教会你开发移动端页面的文章(一)
    移动端页面开发资源总结
    Vue 模板
    使用 concurrently 并行地运行多个命令(同时跑前端和后端的服务)
    值得H5前端学习的60个JS插件(含DEMO演示)
    解读浮动闭合最佳方案:clearfix
    JavaScript 如何工作的: 事件循环和异步编程的崛起 + 5 个关于如何使用 async/await 编写更好的技巧
    JavaScript 运行机制详解:再谈Event Loop
  • 原文地址:https://www.cnblogs.com/baiduboy/p/7688319.html
Copyright © 2011-2022 走看看