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

__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 设备驱动

uboot传递参数'console=ttyXXX'的作用的更多相关文章

  1. uboot向内核模块传递参数的方法

    1 模块参数 定义模块参数 1 module_param(name, type, perm); 定义一个模块参数, name 变量名 type 数据类型 bool:布尔型 invbool:一个布尔型( ...

  2. uboot 如何向内核传递参数

    a.uboot 向内核传递的参数有两种类型 1.一个是bootargs 2.一个是环境参数, 而环境参数的设置靠的是 Y:\junda\JdLinuxApp\A1801_uboot\source\u- ...

  3. C#形参,实参,值传递参数,引用传递参数,输出参数,参数数组的学习

    1)形参 形参顾名思义就是形式上的参数,不是实际的参数,它代替实际传入方法的值.在方法体代码中代表了值本身参与运算.形参定义于参数中,它不同于方法体内局部变量,因为是一个变量,在它的作用域内不允许存在 ...

  4. 【openresty】向lua代码中传递参数

    前面介绍FormInputNginxModule模块时,明白了openresty如何获取post提交的数据. 然后,如果需要通过lua处理这些数据,需要把数据作为参数传递到lua中,lua获取了这些数 ...

  5. Vue系列:通过vue-router如何传递参数

    使用vue-router 来实现webapp的页面跳转,有时候需要传递参数,做法如下: 参考文献:http://router.vuejs.org/en/named.html  主要有以下几个步骤: ( ...

  6. 利用call与apply向函数传递参数

    Js中函数对象都有call与apply两个方法属性,二者使用方法和功能一样,只是传递参数的格式不同,call逐个传递单个参数,apply一次性传递一个参数数组. 这两个方法可以改变函数的调用对象,并且 ...

  7. .net中常用的几种页面间传递参数的方法

    转自:http://www.cnblogs.com/lxshanye/archive/2013/04/11/3014207.html 参考:http://www.cnblogs.com/zhangka ...

  8. ref和out 传递参数(C#)

    1.参数传递默认都是传递栈空间里面存储的内容 2.如果添加了ref那么传递的都是栈空间地址,而不再是栈空间里面的内容 3.如果添加了out,那么传递的也是栈空间的地址 //写一个方法计算一个int类型 ...

  9. C#传递参数

    与函数交换数据的最好方式就是传递参数,在C#中有四种方法来控制参数如何传递给目标方法 C#中的参数修饰符 无修饰 如果一个参数没有用参数修饰符,则认为它将按值传递 out 输出参数由被调用的方法赋值. ...

随机推荐

  1. PHP mysqli_fetch_assoc() 函数

    从结果集中取得一行作为关联数组: <?php // 假定数据库用户名:root,密码:123456,数据库:RUNOOB $con=mysqli_connect("localhost& ...

  2. 泛目录/泛目录程序/泛目录解析/莲花泛目录解析/寄生虫程序/黑帽SEO

    莲花泛目录程序强大之处: 蜘蛛抓取繁殖新页面,对搜索引擎更加友好采用PHP7语言开发,代码执行率高.蜘蛛抓取目录页面触发繁殖新页面,诱导搜索引擎爬虫爬行更多目录页面, 并且在本地生成缓存页面,搜索引擎 ...

  3. vue 编译大量空格警告问题总结 warning: Replace `↹↹` with `&#183;&#183;`

    1.vue开发中发现最后越来越多的编译警告,如 warning: Replace `↹↹` with `··` (prettier/prettier) at src/views/shebei/shou ...

  4. art-template自定义函数

    自定义函数 // 百分比计算 template.defaults.imports.percentage = function (num1, num2) { var res; if(!num1 & ...

  5. Android学习_注意事项

    一. Fragment中加载ListView public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle ...

  6. webpack4 打包 library 遇到的坑

    output: { publicPath: '/', path: path.join(__dirname, 'lib'), filename: 'chart.js', library: 'tchart ...

  7. VMware Workstation 与 Device/Credential Guard 不兼容

    之前在本机搭建Docker for Windows的时候,启用了win10自带的虚拟Hyper-V,但是win10的虚拟与VMware Workstation的虚拟有冲突,运行VMware Works ...

  8. DS博客作业07—查找

    1.本周学习总结 1.1思维导图 1.2学习体会 本章学习了顺序表.树表.哈希表的查找方式,学会计算各种查找方式下的ASL 树表部分的b树和平衡二叉树较为复杂,哈希表相对容易掌握 期末要复习的有点多, ...

  9. postgresql 字符串转整数 int、integer

    --把'1234'转成整数 select cast('1234' as integer ) ; --用substring截取字符串,从第8个字符开始截取2个字符:结果是12 select cast(s ...

  10. css3_1

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...