Linux Kernel printk, early_printk, early_print, printascii

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)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值