下面分析的code都在register_console 这个函数中
在register_console中,如果console_cmdline 中的console driver和selected_console相等,也就是下面的条件成立
if (i == selected_console) {
newcon->flags |= CON_CONSDEV;
preferred_console = selected_console;
}
这样当注册真正的console的时候下面的条件就会成立
if (bcon && ((newcon->flags & (CON_CONSDEV | CON_BOOT)) == CON_CONSDEV))
newcon->flags &= ~CON_PRINTBUFFER;
这样下面这个if条件就不成了,因此console_seq 就不会被修改,还保持上一次earlycon 打印的值,也就是earlycon打印的log,真正的console不会重复打印
if (newcon->flags & CON_PRINTBUFFER) {
/*
* console_unlock(); will print out the buffered messages
* for us.
*/
raw_spin_lock_irqsave(&logbuf_lock, flags);
console_seq = syslog_seq;
console_idx = syslog_idx;
console_prev = syslog_prev;
raw_spin_unlock_irqrestore(&logbuf_lock, flags);
/*
* We're about to replay the log buffer. Only do this to the
* just-registered console to avoid excessive message spam to
* the already-registered consoles.
*/
exclusive_console = newcon;
}
总结一下CON_PRINTBUFFER这个flag,表示从buffer中的第一行log开始打印,而CON_CONSDEV表示从earlycon没有打印的log开始打印,通过设置CON_CONSDEV来清零CON_PRINTBUFFER,这样就避免earlycon和real console的log的重复打印
在register_console中,如果console_cmdline 中的console driver和selected_console相等,也就是下面的条件成立
if (i == selected_console) {
newcon->flags |= CON_CONSDEV;
preferred_console = selected_console;
}
这样当注册真正的console的时候下面的条件就会成立
if (bcon && ((newcon->flags & (CON_CONSDEV | CON_BOOT)) == CON_CONSDEV))
newcon->flags &= ~CON_PRINTBUFFER;
这样下面这个if条件就不成了,因此console_seq 就不会被修改,还保持上一次earlycon 打印的值,也就是earlycon打印的log,真正的console不会重复打印
if (newcon->flags & CON_PRINTBUFFER) {
/*
* console_unlock(); will print out the buffered messages
* for us.
*/
raw_spin_lock_irqsave(&logbuf_lock, flags);
console_seq = syslog_seq;
console_idx = syslog_idx;
console_prev = syslog_prev;
raw_spin_unlock_irqrestore(&logbuf_lock, flags);
/*
* We're about to replay the log buffer. Only do this to the
* just-registered console to avoid excessive message spam to
* the already-registered consoles.
*/
exclusive_console = newcon;
}
总结一下CON_PRINTBUFFER这个flag,表示从buffer中的第一行log开始打印,而CON_CONSDEV表示从earlycon没有打印的log开始打印,通过设置CON_CONSDEV来清零CON_PRINTBUFFER,这样就避免earlycon和real console的log的重复打印