uboot伝達パラメータ'console=ttyXXX'の役割
3293 ワード
linux起動時ubootはconsole=ttyS 0151200 n 8のパラメータに渡される
カーネルで使用_setup()マクロ宣言パラメータ処理の方法
についてsetupマクロリファレンスearly_paramと_setupマクロ
console_setup関数処理
1.console_cmdline構造体
2.console_setup
__add_preferred_console関数
全体的な役割はubootが渡すパラメータに基づいてグローバルconsole_を設定することです.cmdline配列この配列およびグローバルselected_console,register_コンソールでは二コンソールデバイスドライバが使用されます
カーネルで使用_setup()マクロ宣言パラメータ処理の方法
についてsetupマクロリファレンスearly_paramと_setupマクロ
__setup("console=", console_setup);
console_setup関数処理
1.console_cmdline構造体
struct console_cmdline
{
char name[8]; //
int index; //
char *options; //
#ifdef CONFIG_A11Y_BRAILLE_CONSOLE
char *brl_options;
#endif
};
2.console_setup
static int __init console_setup(char *str)
{
char buf[sizeof(console_cmdline[0].name) + 4]; // +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=
");
return 1;
}
*(str++) = 0;
}
#endif
if (str[0] >= '0' && str[0] <= '9') { // [0,9]
strcpy(buf, "ttyS"); // ttyS
strncpy(buf + 4, str, sizeof(buf) - 5);//
} else {
strncpy(buf, str, sizeof(buf) - 1); //
}
buf[sizeof(buf) - 1] = 0;
if ((options = strchr(str, ',')) != NULL) // options
*(options++) = 0;
#ifdef __sparc__
if (!strcmp(str, "ttya"))
strcpy(buf, "ttyS0");
if (!strcmp(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;
}
__add_preferred_console関数
static int __add_preferred_console(char *name, int idx, char *options,char *brl_options)
{
struct console_cmdline *c;
int i;
for (i = 0; i < MAX_CMDLINECONSOLES && console_cmdline[i].name[0]; i++) // 8 console
if (strcmp(console_cmdline[i].name, name) == 0 && console_cmdline[i].index == idx) {
// console_cmdline , console_cmdline
if (!brl_options)
selected_console = i; // selected_console
return 0; //
}
if (i == MAX_CMDLINECONSOLES) // console_cmdline
return -E2BIG;
if (!brl_options)
selected_console = i; // selected_console
c = &console_cmdline[i]; // console_cmdline i
strlcpy(c->name, name, sizeof(c->name)); // console_cmdline
c->options = options; // 115200n8
#ifdef CONFIG_A11Y_BRAILLE_CONSOLE
c->brl_options = brl_options;
#endif
c->index = idx; // 0
return 0;
}
全体的な役割はubootが渡すパラメータに基づいてグローバルconsole_を設定することです.cmdline配列この配列およびグローバルselected_console,register_コンソールでは二コンソールデバイスドライバが使用されます