kernel-boot-msg

查看kernel boot訊息
發現預設為 KERN_DEBUG不會顯示出來,如何在開機讓這些訊息也打印出來


更新記錄

item note
20160930 第一版

目錄


方法: 將loglevel=8加入bootargs

kernel boot msg

  • 於ata_init內是有打印訊息如下:

    1
    printk(KERN_DEBUG "libata version " DRV_VERSION " loaded.\n");
  • 但於dmesg訊息內是沒有顯示出來,如下

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    Serial: AMBA PL011 UART driver
    uart:0: ttyAMA0 at MMIO 0x12080000 (irq = 38) is a PL011 rev2
    console [ttyAMA0] enabled
    uart:1: ttyAMA1 at MMIO 0x12090000 (irq = 39) is a PL011 rev2
    uart:2: ttyAMA2 at MMIO 0x120a0000 (irq = 40) is a PL011 rev2
    uart:3: ttyAMA3 at MMIO 0x120b0000 (irq = 41) is a PL011 rev2
    bio: create slab <bio-0> at 0
    SCSI subsystem initialized
    usbcore: registered new interface driver usbfs
    usbcore: registered new interface driver hub
    usbcore: registered new device driver usb
  • 查看kernel/linux.3.10.y/.config
    預設的boot-time-default level是7,只會顯示0~6
    因此7(KERN_DEBUG)是不會顯示

    1
    2
    ~ # cat /proc/sys/kernel/printk
    7 4 1 7
  • CONFIG_DEFAULT_MESSAGE_LOGLEVEL=4
    若於printk未指定level則採用預設值,在.config內設定

  • 將loglevel=8加入bootargs即可設定printk level,如下

    1
    setenv bootargs 'mem=250M console=ttyAMA0,115200 root=/dev/nfs rw nfsroot=192.168.0.54:/xx-rootfs ip=192.168.0.130:192.168.0.54:255.255.255.0 mtdparts=hi_sfc:1M(boot),14M(rootfs) loglevel=8'
  • 即可看到libata version 3.00 loaded.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    uart:0: ttyAMA0 at MMIO 0x12080000 (irq = 38) is a PL011 rev2
    console [ttyAMA0] enabled
    uart:1: ttyAMA1 at MMIO 0x12090000 (irq = 39) is a PL011 rev2
    uart:2: ttyAMA2 at MMIO 0x120a0000 (irq = 40) is a PL011 rev2
    uart:3: ttyAMA3 at MMIO 0x120b0000 (irq = 41) is a PL011 rev2
    bio: create slab <bio-0> at 0
    SCSI subsystem initialized
    libata version 3.00 loaded.
    usbcore: registered new interface driver usbfs
    usbcore: registered new interface driver hub
    usbcore: registered new device driver usb

說明

printk level

  • kernel (kern_levels.h)
    printk有下例0-7的level

    1
    2
    3
    4
    5
    6
    7
    8
    #define KERN_EMERG	KERN_SOH "0"	/* system is unusable */
    #define KERN_ALERT KERN_SOH "1" /* action must be taken immediately */
    #define KERN_CRIT KERN_SOH "2" /* critical conditions */
    #define KERN_ERR KERN_SOH "3" /* error conditions */
    #define KERN_WARNING KERN_SOH "4" /* warning conditions */
    #define KERN_NOTICE KERN_SOH "5" /* normal but significant condition */
    #define KERN_INFO KERN_SOH "6" /* informational */
    #define KERN_DEBUG KERN_SOH "7" /* debug-level messages */
  • printk_ratelimited
    printk打印會影響到kernel的行為, 因為uart(115200)太慢了,所以最好使用printk_ratelimited

    1
    2
    3
    Occasionally you have to insert a message in a section which gets called quite often. This not only might have a severe performance impact, it also could overwrite and spam your kernel buffer so it should be avoided.

    As always the kernel already provides you with nice functions that solve your problems:

/proc/sys/kernel/printk

  • /proc/sys/kernel/printk
    7 : current console_loglevel
    4 : default (CONFIG_DEFAULT_MESSAGE_LOGLEVEL=4)
    1 : minimum
    7 : boot-time-default
    1
    2
    ~ # cat /proc/sys/kernel/printk
    7 4 1 7

設定全部打印

  • echo 8 > /proc/sys/kernel/printk
    1
    2
    ~ # cat /proc/sys/kernel/printk
    8 4 1 7

dmesg

  • dmesg
    使用dmesg設定level
    demsg -n 8
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    ~ # dmesg -help
    dmesg: invalid option -- h
    BusyBox v1.20.2 (2015-06-29 18:40:56 CST) multi-call binary.

    Usage: dmesg [-c] [-n LEVEL] [-s SIZE]

    Print or control the kernel ring buffer

    -c Clear ring buffer after printing
    -n LEVEL Set console logging level
    -s SIZE Buffer size

    ~ #

其它參考資料