DSP

uclinux内核参数处理(5):earlyprintk

2019-07-13 15:57发布

rev 0.1   快乐虾 http://blog.csdn.net/lights_joy/ lights@hb165.com   本文适用于 ADI bf561 DSP 优视BF561EVB开发板 uclinux-2008r1.5-rc3 (smp patch) Visual DSP++ 5.0(update 5) 欢迎转载,但请保留作者信息   这是uclinux最先处理的几个内核参数之一,对它的处理由parse_cmdline_early函数完成,看看内核对此参数的处理:               } else if (!memcmp(to, "earlyprintk=", 12)) {                    to += 12;                    setup_early_printk(to);               } 即它将直接调用setup_early_printk来处理。在include/asm/early_printk.h中有这样的定义: #ifdef CONFIG_EARLY_PRINTK extern int setup_early_printk(char *); #else #define setup_early_printk(fmt) do { } while (0) #endif /* CONFIG_EARLY_PRINTK */ 也就是说,如果在配置内核时没有打开CONFIG_EARLY_PRINTK,即使传递了earlyprintk参数也没什么作用。 在启用了CONFIG_EARLY_PRINTK的情况下,看看内核对earlyprintk的处理: int __init setup_early_printk(char *buf) {        /* Crashing in here would be really bad, so check both the var         and the pointer before we start using it       */      if (!buf)          return 0;        if (!*buf)          return 0;        if (early_console != NULL)          return 0;   #ifdef CONFIG_SERIAL_BFIN      /* Check for Blackfin Serial */      if (!strncmp(buf, "serial,uart", 11)) {          buf += 11;          early_console = earlyserial_init(buf);      } #endif #ifdef CONFIG_FB          /* TODO: add framebuffer console support */ #endif        if (likely(early_console)) {          early_console->flags |= CON_BOOT;            register_console(early_console);          printk(KERN_INFO "early printk enabled on %s%d/n",               early_console->name,               early_console->index);      }        return 0; } 从这一段代码可以看出,要想使用early_console,必须在内核配置时启用CONFIG_SERIAL_BFIN,也就是说要启用BF561UART,且early_console也只能使用BF561UART 从上面的这段代码还可以看出earlyprintk的参数格式为: earlyprintk=serial,uart[….] 看看earlyserial_init对后面的参数是如何处理的: /* What should get here is "0,57600" */ static struct console * __init earlyserial_init(char *buf) {      int baud, bit;      char parity;      unsigned int serial_port = DEFAULT_PORT;      unsigned int cflag = DEFAULT_CFLAG;        serial_port = simple_strtoul(buf, &buf, 10);      buf++;        cflag = 0;      baud = simple_strtoul(buf, &buf, 10);      switch (baud) {      case 1200:          cflag |= B1200;          break;      case 2400:          cflag |= B2400;          break;      case 4800:          cflag |= B4800;          break;      case 9600:          cflag |= B9600;          break;      case 19200:          cflag |= B19200;          break;      case 38400:          cflag |= B38400;          break;      case 115200:          cflag |= B115200;          break;      default:          cflag |= B57600;      }        parity = buf[0];      buf++;      switch (parity) {      case 'e':          cflag |= PARENB;          break;      case 'o':          cflag |= PARODD;          break;      }        bit = simple_strtoul(buf, &buf, 10);      switch (bit) {      case 5:          cflag |= CS5;          break;      case 6:          cflag |= CS5;          break;      case 7:          cflag |= CS5;          break;      default:          cflag |= CS8;      }   #ifdef CONFIG_SERIAL_BFIN      return bfin_earlyserial_init(serial_port, cflag); #else      return NULL; #endif   } 从这一段代码可以看出earlyprintk的完整参数定义为: earlyprintk=serial,uart[port],[baud][parity[bits]] port指定串口号,对于BF561,此值必须为0 baud指定波特率,有1200, 2400, 4800, 9600, 19200, 38400, 115200几种,除此以外的数值均无效,直接将波特率设置为57600 parity为校验位,无校验不设,’e’为偶校验,’o’为奇校验。 bits指定字长,可取5, 6, 7,除此之外的所有数值均设置为8位。 如果不设置波特率等参数,默认取下面的参数: #define DEFAULT_EARLY_PORT "serial,uart0,57600"  

1       参考资料

uclinux内核参数处理(1):参数接收(2009-1-29) uclinux内核参数处理(2)parse_cmdline_early(2009-1-29) uclinux内核参数处理(3)mem(2009-1-30) uclinux内核参数处理(4)max_mem(2009-1-30)