early_printk.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * linux/arch/arm/kernel/early_printk.c
  3. *
  4. * Copyright (C) 2009 Sascha Hauer <s.hauer@pengutronix.de>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/console.h>
  12. #include <linux/init.h>
  13. extern void printch(int);
  14. static void early_write(const char *s, unsigned n)
  15. {
  16. while (n-- > 0) {
  17. if (*s == '\n')
  18. printch('\r');
  19. printch(*s);
  20. s++;
  21. }
  22. }
  23. static void early_console_write(struct console *con, const char *s, unsigned n)
  24. {
  25. early_write(s, n);
  26. }
  27. static struct console early_console = {
  28. .name = "earlycon",
  29. .write = early_console_write,
  30. .flags = CON_PRINTBUFFER | CON_BOOT,
  31. .index = -1,
  32. };
  33. asmlinkage void early_printk(const char *fmt, ...)
  34. {
  35. char buf[512];
  36. int n;
  37. va_list ap;
  38. va_start(ap, fmt);
  39. n = vscnprintf(buf, sizeof(buf), fmt, ap);
  40. early_write(buf, n);
  41. va_end(ap);
  42. }
  43. static int __init setup_early_printk(char *buf)
  44. {
  45. register_console(&early_console);
  46. return 0;
  47. }
  48. early_param("earlyprintk", setup_early_printk);