How does printk export data to UART?

Source: Internet
Author: User

We usually configure this sentence in config: "config_cmdline =" console = tty0 console = ttymt3, 921600n1 root =/dev/Ram "", then, you can modify the value assignment of the console to change the output position. How can this problem be implemented in the code?

Next, in the printk. c file above, there is such a function first:
/*
* Set up a list of tables Les. Called from init/Main. c
*/
The pull comment directly tells us that this function is called by a function in the init/Main. c file.

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_CONSOLEif (!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, sizeof(buf) - 1);}buf[sizeof(buf) - 1] = 0;if ((options = strchr(str, ',')) != NULL)*(options++) = 0;#ifdef __sparc__if (!strcmp(str, "ttya"))strcpy(buf, "ttyS0");if (!strcmp(str, "ttyb"))strcpy(buf, "ttyS1");#endiffor (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;}

We can see that the string is parsed to obtain the TTY name, index, and options. The following macro is used to add a linked list.

__setup("console=", console_setup);

Does it seem that something is missing, the linked list called in Main. C? Here register_console ().

/** The console driver callthis routine during kernel initialization * to register the console printing procedure with printk () and to * print any messages that were printed by the kernel before the * console driver was initialized. ** this can happen pretty early during the boot process (because of * early_printk)-sometimes before setup_arch () completes-be careful * Of what kernel features Are used-they may not be initialised yet. ** there are two types of wide les-bootles (early_printk) and * "real" wide les (everything which is not a bootconsole) which are * handled differently. *-any number of bootlescan be registered at any time. *-as soon as a "real" console is registered, all bootelizles * will be unregistered automatically. *-once a "real" console is R Egistered, any attempt to register a * bootsecrets les will be rejected */void register_console (struct console * newcon) {............................ /** see if this console matches one we selected on * the command line. * /// read the preceding comments. We can also understand that the definition in command line also works here for (I = 0; I <max_cmdlineconsoles & lele_cmdline [I]. name [0]; I ++) {If (strcmp (console_line line [I]. name, newcon-> name )! = 0) continue; If (newcon-> index> = 0 & newcon-> index! = Console_policline [I]. index) continue; If (newcon-> index <0) newcon-> Index = lele_line line [I]. index; # ifdef config_a11y_braille_consoleif (lele_cmdline [I]. brl_options) {newcon-> flags | = con_dpm; braille_register_console (newcon, console_cmdline [I]. index, lele_policline [I]. options, console_policline [I]. brl_options); Return ;}# endifif (newcon-> Setup & newcon-> setup (newcon, console_cmdline [I]. options )! = 0) /// here we can see that the setup process is break; newcon-> flags | = con_enabled; newcon-> Index = lele_cmdline [I]. index; if (I = selected_console) {newcon-> flags | = con_consdev; preferred_console = selected_console;} break;} If (! (Newcon-> flags & con_enabled )) // other console driver blocks return ;.............................. ..........}

Of course, the comments of the above functions in the source code are very detailed. If you need to read them, reading the source code is the best choice.

Here, the TTY port of so command line is specified here.

Have fun!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.