How logs will come to UART serial console?

Haphazard H hhaphazard at yahoo.com
Wed May 18 14:49:51 EDT 2011


> Hi sandeep,
>
> On Tue, May 17, 2011 at 12:52 AM, sandeep kumar
> <coolsandyforyou at gmail.com> wrote:
> >
> > Hi ,
> > Here is my question.
> > when we put 'printk's in kernel code the logs will go to the log_buffer.(i observed that from implementation)
> > But when UART is enabled(in the bootloader), the same printk logs?are going to the serial console.
> > As per my study printk doesnot implementing anything that writes to the UART console.
> >
> > Now here are?my questions,
> > how this is being achieved??Where this is implemented?(which file)
>
> When you register your UART driver there is typically an option to
> register a console driver at the same time.
>
> For example, let's take a look at the 8250 serial driver. We'll look
> at the file drivers/serial/8250.c

Think the file has changed, its now in drivers/tty/serial/8250.c 

> Search for the function serial8250_console_init, which has a call to
> register_console.
>
> That's the starting point that sets up the console driver. You can
> have other drivers call register_console and get your console messages
> sent out whatever bizarre device you may have connected to your
> system.

> You can also have multiple consoles registered at the same time.

If so, you can see the output in all the registered ports.

> > Where wil be the parsing of the cmdline string sent from the bootloader is done?
>
> The function console_setup is called when the console= parameter is
> passed on the kernel command line.
> <http://lxr.linux.no/linux+v2.6.38/kernel/printk.c#L904>

In the console_setup function, the struct console's address in stored in a char pointer.
If you want to know how the parsing is done,

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;

I they check the str[0], the first element in the received char array, it corresponds to 
char name[16] // from linux/console.h
the name parameter in the static struct console serial8250_console is "ttyS".
Basically what the first line does is that, the console device's name 
should not start with numbers. If not actual name is copied.

> The __setup just after the end of the function is what causes it to
> call that function when the console= parameter is passed.

/harper




More information about the Kernelnewbies mailing list