Linux console

这篇博客详细介绍了Linux控制台的启动流程,包括console_cmdline结构体解析、console=参数的`console_setup()`函数以及`__add_preferred_console()`的调用。此外,还讨论了kernel调试信息如何通过`printk()`输出,并涉及到log_buf缓冲区和`console_drivers`链表。最后,文章提及了`console_init()`和`register_console()`在控制台注册中的作用。
摘要由CSDN通过智能技术生成

console 启动流程:

start_kernel–>parse_args–>parse_early_options–>parse_args–>do_early_param–>console_setup–>__add_preferred_console–>console_cmdline[i],在该函数内部,将控制台参数保存到到了全局变量结构体console_cmdline[i]中。

console_cmdline 结构体:

struct console_cmdline
{
                     
    char    name[8];            /* 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
};

console_cmdline[MAX_CMDLINECONSOLES ] 是一个全局变量,最多可以存放MAX_CMDLINECONSOLES 个kernel启动参数cmdline.

#define MAX_CMDLINECONSOLES 8
        
static struct console_cmdline console_cmdline[MAX_CMDLINECONSOLES];
static int selected_console = -1;
static int preferred_console = -1;
int console_set_on_cmdline;
EXPORT_SYMBOL(console_set_on_cmdline);

kernel/printk中注册了’console='的解析函数console_setup(),找到匹配成功以后会调用console_setup来解析 , 参数值是console=的字符串,例如"ttyS0, 115200".

static int __init console_setup(char *str)
{
   
    char buf[sizeof(console_cmdline[0].name) + 4]; /* 4 for index */
    char *s, *options, *brl_options = NULL;
    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, options.
     */
    if (str[0] >= '0' && str[0] <= '9') {
   
        strcpy(buf, "ttyS");
        strncpy(buf + 4, str, sizeof(buf) - 5);
    } else {
   
        strncpy(buf, str
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值