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