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