Linux Kernel printk, early_printk, early_print, printascii
Linux Version: 4.9
ARM32
Linux Kernel has four print functions
printk()
early_printk()
early_print()
printascii()
#####
# This function call both printascii() and printk() if we define
# CONFIG_DEBUG_LL. So if we call this function, the log would output twice.
#################################################
void __init early_print(const char *str, ...)
{
extern void printascii(const char *);
char buf[256];
va_list ap;
va_start(ap, str);
vsnprintf(buf, sizeof(buf), str, ap);
va_end(ap);
#ifdef CONFIG_DEBUG_LL
printascii(buf);
#endif
printk("%s", buf);
}
#####
# This function can work only when we enable earlyprintk after
# the earlycon registered successfully, or it would return back and do nothing.
#################################################
#ifdef CONFIG_EARLY_PRINTK
struct console *early_console;
asmlinkage __visible void early_printk(const char *fmt, ...)
{
va_list ap;
char buf[512];
int n;
if (!early_console)
return;
va_start(ap, fmt);
n = vscnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
early_console->write(early_console, buf, n);
}
#endif
/arch/arm/kernel/early_printk.c
static void early_console_write(struct console *con, const char *s, unsigned n)
{
early_write(s, n);
}
static struct console early_console_dev = {
.name = "earlycon",
.write = early_console_write,
.flags = CON_PRINTBUFFER | CON_BOOT,
.index = -1,
};
static int __init setup_early_printk(char *buf)
{
early_console = &early_console_dev;
register_console(&early_console_dev); ====> /kernel/printk.c
return 0;
}
early_param("earlyprintk", setup_early_printk);
#####
# //Assume the real console is ttyS0
# When earlycon0 be registered, printk would call its driver output log,
# when the real ttyS0 be registered, then printk would call ttyS0 driver.
#################################################
asmlinkage __visible int printk(const char *fmt, ...)
{
va_list args;
int r;
va_start(args, fmt);
r = vprintk_func(fmt, args);
va_end(args);
return r;
}
ENTRY(printascii)
mov r1, r0
mov r0, #0x04 @ SYS_WRITE0
ARM( svc #0x123456 )
THUMB( svc #0xab )
ret lr
ENDPROC(printascii)
Linux Version: 4.9
ARM32
Linux Kernel has four print functions
printk()
early_printk()
early_print()
printascii()
#####
# This function call both printascii() and printk() if we define
# CONFIG_DEBUG_LL. So if we call this function, the log would output twice.
#################################################
void __init early_print(const char *str, ...)
{
extern void printascii(const char *);
char buf[256];
va_list ap;
va_start(ap, str);
vsnprintf(buf, sizeof(buf), str, ap);
va_end(ap);
#ifdef CONFIG_DEBUG_LL
printascii(buf);
#endif
printk("%s", buf);
}
#####
# This function can work only when we enable earlyprintk after
# the earlycon registered successfully, or it would return back and do nothing.
#################################################
#ifdef CONFIG_EARLY_PRINTK
struct console *early_console;
asmlinkage __visible void early_printk(const char *fmt, ...)
{
va_list ap;
char buf[512];
int n;
if (!early_console)
return;
va_start(ap, fmt);
n = vscnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
early_console->write(early_console, buf, n);
}
#endif
/arch/arm/kernel/early_printk.c
static void early_console_write(struct console *con, const char *s, unsigned n)
{
early_write(s, n);
}
static struct console early_console_dev = {
.name = "earlycon",
.write = early_console_write,
.flags = CON_PRINTBUFFER | CON_BOOT,
.index = -1,
};
static int __init setup_early_printk(char *buf)
{
early_console = &early_console_dev;
register_console(&early_console_dev); ====> /kernel/printk.c
return 0;
}
early_param("earlyprintk", setup_early_printk);
#####
# //Assume the real console is ttyS0
# When earlycon0 be registered, printk would call its driver output log,
# when the real ttyS0 be registered, then printk would call ttyS0 driver.
#################################################
asmlinkage __visible int printk(const char *fmt, ...)
{
va_list args;
int r;
va_start(args, fmt);
r = vprintk_func(fmt, args);
va_end(args);
return r;
}
ENTRY(printascii)
mov r1, r0
mov r0, #0x04 @ SYS_WRITE0
ARM( svc #0x123456 )
THUMB( svc #0xab )
ret lr
ENDPROC(printascii)