early_printk.c 943 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * linux/arch/arm/kernel/early_printk.c
  4. *
  5. * Copyright (C) 2009 Sascha Hauer <[email protected]>
  6. */
  7. #include <linux/kernel.h>
  8. #include <linux/console.h>
  9. #include <linux/init.h>
  10. #include <linux/string.h>
  11. extern void printascii(const char *);
  12. static void early_write(const char *s, unsigned n)
  13. {
  14. char buf[128];
  15. while (n) {
  16. unsigned l = min(n, sizeof(buf)-1);
  17. memcpy(buf, s, l);
  18. buf[l] = 0;
  19. s += l;
  20. n -= l;
  21. printascii(buf);
  22. }
  23. }
  24. static void early_console_write(struct console *con, const char *s, unsigned n)
  25. {
  26. early_write(s, n);
  27. }
  28. static struct console early_console_dev = {
  29. .name = "earlycon",
  30. .write = early_console_write,
  31. .flags = CON_PRINTBUFFER | CON_BOOT,
  32. .index = -1,
  33. };
  34. static int __init setup_early_printk(char *buf)
  35. {
  36. early_console = &early_console_dev;
  37. register_console(&early_console_dev);
  38. return 0;
  39. }
  40. early_param("earlyprintk", setup_early_printk);