ImageVerifierCode 换一换
格式:DOCX , 页数:6 ,大小:22.43KB ,
资源ID:2995129      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/2995129.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(linux kernel下输入输出console如何实现.docx)为本站会员(b****3)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

linux kernel下输入输出console如何实现.docx

1、linux kernel下输入输出console如何实现linux kernel下输入输出console如何实现 , kernel下printk console的选择 ,kernel下console的注册,user空间console的选择。一 指定kernel调试console首先看kernel启动时如何获取和处理指定的console参数。kernel的启动参数cmdline可以指定调试console,如指定console=ttyS0,115200,kernel如何解析cmdline,我之前写了一篇博文如下:根据之前的分析,cmdline中有console=xxx,start_kernel中p

2、arse_args遍历.init.setup段所有obs_kernel_param。kernel/printk.c中注册了console=的解析函数console_setup(注册了obs_kernel_param),所以匹配成功,会调用console_setup来解析,如下:cpp view plain copy static int _init console_setup(char *str) char bufsizeof(console_cmdline0.name) + 4; /* 4 for index */ char *s, *options, *brl_options = NULL

3、; int idx; #ifdef CONFIG_A11Y_BRAILLE_CONSOLE if (!memcmp(str, brl, 4) brl_options = ; str += 4; else if (!memcmp(str, brl=, 4) brl_options = str + 4; str = strchr(brl_options, ,); if (!str) printk(KERN_ERR need port name after brl=n); return 1; *(str+) = 0; #endif /* * Decode str into name, index,

4、options. */ if (str0 >= 0 && str0 <= 9) strcpy(buf, ttyS); strncpy(buf + 4, str, sizeof(buf) - 5); else strncpy(buf, str, sizeof(buf) - 1); bufsizeof(buf) - 1 = 0; if (options = strchr(str, ,) != NULL) *(options+) = 0; #ifdef _sparc_ if (!strcmp(str, ttya) strcpy(buf, ttyS0); if (!strc

5、mp(str, ttyb) strcpy(buf, ttyS1); #endif for (s = buf; *s; s+) if (*s >= 0 && *s <= 9) | *s = ,) break; idx = simple_strtoul(s, NULL, 10); *s = 0; _add_preferred_console(buf, idx, options, brl_options); console_set_on_cmdline = 1; return 1; _setup(console=, console_setup); 参数是console=的

6、值字符串,如“ttyS0,115200”,console_setup对console=参数值做解析,以ttyS0,115200为例,最后buf=“ttyS”,idx=0,options=115200,brl_options=NULL。调用_add_preferred_console如下:cpp view plain copy /* * If exclusive_console is non-NULL then only this console is to be printed to. */ static struct console *exclusive_console; /* * Arra

7、y of consoles built from command line options (console=) */ struct console_cmdline char name8; /* Name of the driver */ int index; /* Minor dev. to use */ char *options; /* Options for the driver */ #ifdef CONFIG_A11Y_BRAILLE_CONSOLE char *brl_options; /* Options for braille driver */ #endif ; #defi

8、ne MAX_CMDLINECONSOLES 8 static struct console_cmdline console_cmdlineMAX_CMDLINECONSOLES; static int selected_console = -1; static int preferred_console = -1; int console_set_on_cmdline; EXPORT_SYMBOL(console_set_on_cmdline); static int _add_preferred_console(char *name, int idx, char *options, cha

9、r *brl_options) struct console_cmdline *c; int i; /* * See if this tty is not yet registered, and * if we have a slot free. */ for (i = 0; i < MAX_CMDLINECONSOLES && console_cmdlinei.name0; i+) if (strcmp(console_cmdlinei.name, name) = 0 && console_cmdlinei.index = idx) if (!brl_o

10、ptions) selected_console = i; return 0; if (i = MAX_CMDLINECONSOLES) return -E2BIG; if (!brl_options) selected_console = i; c = &console_cmdlinei; strlcpy(c->name, name, sizeof(c->name); c->options = options; #ifdef CONFIG_A11Y_BRAILLE_CONSOLE c->brl_options = brl_options; #endif c-&

11、gt;index = idx; return 0; kernel利用结构体数组console_cmdline8,最多可支持8个cmdline传入的console参数。_add_preferred_console将name idx options保存到数组下一个成员console_cmdline结构体中,如果数组中已有重名,则不添加,并置selected_console为最新添加的console_cmdline的下标号。比如cmdline中有“console=ttyS0,115200 console=ttyS1,9600”则在console_cmdline8数组中console_cmdline0

12、代表ttyS0,console_cmdline1代表ttyS1,而selected_console=1.二 kernel下printk console的选择kernel下调试信息是通过printk输出,如果要kernel正常打印,则需要搞明白printk怎么选择输出的设备。关于printk的实现原理,我在刚工作的时候写过一篇博文,kernel版本是2.6.21的,但是原理还是一致的,可供参考: view plain copy #define MAX_CMDLINECONSOLES 8 static struct console_cmdline console_cmdlineMAX_CMDLIN

13、ECONSOLES; static int selected_console = -1; static int preferred_console = -1; int console_set_on_cmdline; EXPORT_SYMBOL(console_set_on_cmdline); /* Flag: console code may call schedule() */ static int console_may_schedule; #ifdef CONFIG_PRINTK static char _log_buf_LOG_BUF_LEN; static char *log_buf

14、 = _log_buf; static int log_buf_len = _LOG_BUF_LEN; static unsigned logged_chars; /* Number of chars produced since last read+clear operation */ static int saved_console_loglevel = -1; log_buf的大小由kernel menuconfig配置,我配置的CONFIG_LOG_BUF_SHIFT为17,则log_buf为128k。printk内容会一直存在log_buf中,log_buf满了之后则会从头在开始存,覆盖掉原来的数据。根据printk的实现原理,printk最后调用console_unlock实现log_buf数据刷出到指定设备。这里先不关心printk如何处理log buf数据(比如添加内容级别),只关心printk如何一步步找到指定的输出设备,根据printk.c代码,可以找到如下线索。printk->vprintk->console_unlock->call_console_drivers->_call_console_driv

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1