从零开始之驱动发开、linux驱动(六十七、内核调试篇--printk使用)

printk的使用我们在内核,驱动调试的时候使用的非常多

比如前面在调试usb驱动的时候

#include <linux/init.h>
#include <linux/usb/input.h>
#include <linux/hid.h>



static int usb_simple_probe(struct usb_interface *intf, const struct usb_device_id *id)
{
    struct usb_device *dev = interface_to_usbdev(intf);

    printk(KERN_INFO"usb_simple_probe\n");

    printk(KERN_INFO"bcdUSB = 0x%x\n",dev->descriptor.bcdUSB);
    printk(KERN_INFO"VID    = 0x%x\n",dev->descriptor.idVendor);
    printk(KERN_INFO"PID    = 0x%x\n",dev->descriptor.idProduct);
    
    return 0;
}


static void usb_simple_disconnect(struct usb_interface *intf)
{
    printk(KERN_INFO"usb_mouse_disconnect\n");
}

static const struct usb_device_id usb_simple_id_table[] = { 
    { USB_INTERFACE_INFO(USB_INTERFACE_CLASS_HID, USB_INTERFACE_SUBCLASS_BOOT,
        USB_INTERFACE_PROTOCOL_MOUSE) },
    {} /* Terminating entry */
};

static struct usb_driver usb_simple_driver = {
    .name       = "usb_simple",
    .probe      = usb_simple_probe,
    .disconnect = usb_simple_disconnect,
    .id_table   = usb_simple_id_table,
};


module_usb_driver(usb_simple_driver);
MODULE_LICENSE("GPL");

同时因为我们上一节已经看到了printk在用串口实现的时候,没有使用中断,采用查询方式(这样才能在任何上下文调用)来打印的,所以在某些情况下会导致程序的响应时间受到很大影响。

所以内核在使用了打印等级,让使用者根据需要来控制需要打印的信息。

方式1,内核启动后,修改proc文件系统中的打印等级

在 /proc/sys/kernel/printk 会显示4个数值(可由 echo 修改),分别表示当前控制台日志级别、未明确指定日志级别的默认消息日志级别、最小(最高)允许设置的控制台日志级别、引导时默认的日志级别。当 printk() 中的消息日志级别小于当前控制台日志级别时,printk 的信息(要有\n符)就会在控制台上显示。但无论当前控制台日志级别是何值,通过 /proc/kmsg (或使用dmesg)总能查看。另外如果配置好并运行了 syslogd 或 klogd,没有在控制台上显示的 printk 的信息也会追加到 /var/log/messages.log 中。

比如,修改默认的打印等级

echo "7 7 1 7" > /proc/sys/kernel/printk

当然这种只能在内核启动后修改。

下面给出bootloader启动内核时,没指定打印等级时的log信息(默认为4)

Bytes transferred = 3649656 (37b078 hex)
## Booting kernel from Legacy Image at 30007fc0 ...
   Image Name:   Linux-4.19.0-ga2a89a6-dirty
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    3649592 Bytes = 3.5 MiB
   Load Address: 30008000
   Entry Point:  30008000
## Flattened Device Tree blob at 40000000
   Booting using the fdt blob at 0x40000000
   XIP Kernel Image ... OK
   Loading Device Tree to 3fff7000, end 3ffffeb2 ... OK

Starting kernel ...

Booting Linux on physical CPU 0x0
Linux version 4.19.0-ga2a89a6-dirty (run@ubuntu) (gcc version 4.8.3 20140320 (prerelease) (Sourcery CodeBench Lite 2014.05-29)) #16 PREEMPT Sat Apr 20 00:50:52 CST 2019
CPU: ARMv7 Processor [412fc082] revision 2 (ARMv7), cr=10c5387d
CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
OF: fdt: Machine model: YIC System SMDKV210 based on S5PV210
Memory policy: Data cache writeback
CPU: All CPU(s) started in SVC mode.
random: get_random_bytes called from start_kernel+0x88/0x3ec with crng_init=0
Built 1 zonelists, mobility grouping on.  Total pages: 130048
Kernel command line: root=/dev/nfs nfsroot=192.168.0.101:/home/run/work/rootfs/rootfs_3.16.57 ip=192.168.0.20:192.168.0.101:192.168.0.1:255.255.255.0::eth0:off init=/linuxrc console=ttySAC2,115200
Dentry cache hash table entries: 65536 (order: 6, 262144 bytes)
Inode-cache hash table entries: 32768 (order: 5, 131072 bytes)
Memory: 510956K/524288K available (5120K kernel code, 223K rwdata, 1512K rodata, 1024K init, 259K bss, 13332K reserved, 0K cma-reserved)
Virtual kernel memory layout:
    vector  : 0xffff0000 - 0xffff1000   (   4 kB)
    fixmap  : 0xffc00000 - 0xfff00000   (3072 kB)
    vmalloc : 0xa0800000 - 0xff800000   (1520 MB)
    lowmem  : 0x80000000 - 0xa0000000   ( 512 MB)
    modules : 0x7f000000 - 0x80000000   (  16 MB)
      .text : 0x(ptrval) - 0x(ptrval)   (6112 kB)
      .init : 0x(ptrval) - 0x(ptrval)   (1024 kB)
      .data : 0x(ptrval) - 0x(ptrval)   ( 224 kB)
       .bss : 0x(ptrval) - 0x(ptrval)   ( 260 kB)
SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
rcu: Preemptible hierarchical RCU implementation.
        Tasks RCU enabled.
NR_IRQS: 16, nr_irqs: 16, preallocated irqs: 16
VIC @(ptrval): id 0x00041192, vendor 0x41
VIC @(ptrval): id 0x00041192, vendor 0x41
VIC @(ptrval): id 0x00041192, vendor 0x41
VIC @(ptrval): id 0x00041192, vendor 0x41
S5PV210 clocks: mout_apll = 1000000000, mout_mpll = 667000000
        mout_epll = 96000000, mout_vpll = 54000000
sched_clock: 32 bits at 33MHz, resolution 29ns, wraps every 64392313329ns
clocksource: samsung_clocksource_timer: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 57309158834 ns
Console: colour dummy device 80x30
Calibrating delay loop... 996.14 BogoMIPS (lpj=4980736)
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
CPU: Testing write buffer coherency: ok
CPU0: Spectre v2: firmware did not set auxiliary control register IBE bit, system vulnerable
Setting up static identity map for 0x30100000 - 0x30100060
rcu: Hierarchical SRCU implementation.
devtmpfs: initialized
VFP support v0.3: implementor 41 architecture 3 part 30 variant c rev 2
clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
futex hash table entries: 256 (order: 0, 7168 bytes)
pinctrl core: initialized pinctrl subsystem
NET: Registered protocol family 16
DMA: preallocated 256 KiB pool for atomic coherent allocations
SCSI subsystem initialized
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
s3c-i2c e1800000.i2c: slave address 0x00
s3c-i2c e1800000.i2c: bus frequency set to 65 KHz
s3c-i2c e1800000.i2c: i2c-0: S3C I2C adapter
clocksource: Switched to clocksource samsung_clocksource_timer
NET: Registered protocol family 2
tcp_listen_portaddr_hash hash table entries: 256 (order: 0, 6144 bytes)
TCP established hash table entries: 4096 (order: 2, 16384 bytes)
TCP bind hash table entries: 4096 (order: 4, 81920 bytes)
TCP: Hash tables configured (established 4096 bind 4096)
UDP hash table entries: 256 (order: 1, 12288 bytes)
UDP-Lite hash table entries: 256 (order: 1, 12288 bytes)
NET: Registered protocol family 1
RPC: Registered named UNIX socket transport module.
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
Initialise system trusted keyrings
workingset: timestamp_bits=30 max_order=17 bucket_order=0
romfs: ROMFS MTD (C) 2007 Red Hat, Inc.
Key type asymmetric registered
Asymmetric key parser 'x509' registered
io scheduler noop registered
io scheduler deadline registered
io scheduler cfq registered (default)
io scheduler mq-deadline registered
io scheduler kyber registered
samsung-usb2-phy ec100000.usbphy: ec100000.usbphy supply vbus not found, using dummy regulator
samsung-usb2-phy ec100000.usbphy: Linked as a consumer to regulator.0
Serial: 8250/16550 driver, 4 ports, IRQ sharing disabled
e2900000.serial: ttySAC0 at MMIO 0xe2900000 (irq = 58, base_baud = 0) is a S3C6400/10
e2900400.serial: ttySAC1 at MMIO 0xe2900400 (irq = 59, base_baud = 0) is a S3C6400/10
e2900800.serial: ttySAC2 at MMIO 0xe2900800 (irq = 60, base_baud = 0) is a S3C6400/10
console [ttySAC2] enabled
e2900c00.serial: ttySAC3 at MMIO 0xe2900c00 (irq = 61, base_baud = 0) is a S3C6400/10
brd: module loaded
loop: module loaded
dm9000 88000000.ethernet: 88000000.ethernet supply vcc not found, using dummy regulator
dm9000 88000000.ethernet: Linked as a consumer to regulator.0
dm9000 88000000.ethernet: enable clock 'sromc'
eth0: dm9000b at (ptrval),(ptrval) IRQ 144 MAC: 00:00:de:ad:be:ef (platform data)
dwc2 ec000000.hsotg: ec000000.hsotg supply vusb_d not found, using dummy regulator
dwc2 ec000000.hsotg: Linked as a consumer to regulator.0
dwc2 ec000000.hsotg: ec000000.hsotg supply vusb_a not found, using dummy regulator
dwc2 ec000000.hsotg: Configuration mismatch. dr_mode forced to host
dwc2 ec000000.hsotg: dwc2_core_reset: HANG! AHB Idle timeout GRSTCTL GRSTCTL_AHBIDLE
dwc2: probe of ec000000.hsotg failed with error -16
ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
ehci-exynos: EHCI EXYNOS driver
exynos-ehci ec200000.ehci: EHCI Host Controller
exynos-ehci ec200000.ehci: new USB bus registered, assigned bus number 1
exynos-ehci ec200000.ehci: irq 71, io mem 0xec200000
exynos-ehci ec200000.ehci: USB 2.0 started, EHCI 1.00
usb usb1: New USB device found, idVendor=1d6b, idProduct=0002, bcdDevice= 4.19
usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
usb usb1: Product: EHCI Host Controller
usb usb1: Manufacturer: Linux 4.19.0-ga2a89a6-dirty ehci_hcd
usb usb1: SerialNumber: ec200000.ehci
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 1 port detected
ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
ohci-exynos: OHCI EXYNOS driver
exynos-ohci ec300000.ohci: USB Host Controller
exynos-ohci ec300000.ohci: new USB bus registered, assigned bus number 2
exynos-ohci ec300000.ohci: irq 71, io mem 0xec300000
usb usb2: New USB device found, idVendor=1d6b, idProduct=0001, bcdDevice= 4.19
usb usb2: New USB device strings: Mfr=3, Product=2, SerialNumber=1
usb usb2: Product: USB Host Controller
usb usb2: Manufacturer: Linux 4.19.0-ga2a89a6-dirty ohci_hcd
usb usb2: SerialNumber: ec300000.ohci
hub 2-0:1.0: USB hub found
hub 2-0:1.0: 1 port detected
usbcore: registered new interface driver usb-storage
usbcore: registered new interface driver ums-sddr09
usbcore: registered new interface driver ums-sddr55
i2c /dev entries driver
sdhci: Secure Digital Host Controller Interface driver
sdhci: Copyright(c) Pierre Ossman
s3c-sdhci eb000000.sdhci: clock source 0: mmc_busclk.0 (133400000 Hz)
s3c-sdhci eb000000.sdhci: clock source 2: mmc_busclk.2 (96000000 Hz)
mmc0: SDHCI controller on samsung-hsmmc [eb000000.sdhci] using ADMA
s3c-sdhci eb100000.sdhci: clock source 0: mmc_busclk.0 (133400000 Hz)
s3c-sdhci eb100000.sdhci: clock source 2: mmc_busclk.2 (96000000 Hz)
mmc1: SDHCI controller on samsung-hsmmc [eb100000.sdhci] using ADMA
s3c-sdhci eb200000.sdhci: clock source 0: mmc_busclk.0 (133400000 Hz)
s3c-sdhci eb200000.sdhci: clock source 2: mmc_busclk.2 (96000000 Hz)
mmc2: SDHCI controller on samsung-hsmmc [eb200000.sdhci] using ADMA
s3c-sdhci eb300000.sdhci: clock source 0: mmc_busclk.0 (133400000 Hz)
s3c-sdhci eb300000.sdhci: clock source 3: mmc_busclk.3 (96000000 Hz)
mmc2: new high speed SDHC card at address 0007
mmcblk2: mmc2:0007 SD04G 3.68 GiB 
mmc3: Internal clock never stabilised.
mmc3: sdhci: ============ SDHCI REGISTER DUMP ===========
mmc3: sdhci: Sys addr:  0x00000000 | Version:  0x00002401
 mmcblk2: p1
mmc3: sdhci: Blk size:  0x00000000 | Blk cnt:  0x00000000
mmc3: sdhci: Argument:  0x00000000 | Trn mode: 0x00000000
mmc3: sdhci: Present:   0x01fa0000 | Host ctl: 0x00000000
mmc3: sdhci: Power:     0x0000000e | Blk gap:  0x00000000
mmc3: sdhci: Wake-up:   0x00000000 | Clock:    0x00008001
mmc3: sdhci: Timeout:   0x00000000 | Int stat: 0x00000000
usb 1-1: new high-speed USB device number 2 using exynos-ehci
mmc3: sdhci: Int enab:  0x00ff0043 | Sig enab: 0x00ff0043
mmc3: sdhci: AC12 err:  0x00000000 | Slot int: 0x00000000
mmc3: sdhci: Caps:      0x05e80080 | Caps_1:   0x00000000
mmc3: sdhci: Cmd:       0x00000000 | Max curr: 0x00000000
mmc3: sdhci: Resp[0]:   0x00000000 | Resp[1]:  0x00000000
mmc3: sdhci: Resp[2]:   0x00000000 | Resp[3]:  0x00000000
mmc3: sdhci: Host ctl2: 0x00000000
mmc3: sdhci: ADMA Err:  0x00000000 | ADMA Ptr: 0x00000000
mmc3: sdhci: ============================================
mmc3: SDHCI controller on samsung-hsmmc [eb300000.sdhci] using ADMA
NET: Registered protocol family 10
Segment Routing with IPv6
sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver
NET: Registered protocol family 17
Loading compiled-in X.509 certificates
hctosys: unable to open rtc device (rtc0)
usb 1-1: New USB device found, idVendor=05e3, idProduct=0608, bcdDevice=85.36
usb 1-1: New USB device strings: Mfr=0, Product=1, SerialNumber=0
usb 1-1: Product: USB2.0 Hub
hub 1-1:1.0: USB hub found
hub 1-1:1.0: 4 ports detected
dm9000 88000000.ethernet eth0: link down
random: fast init done
dm9000 88000000.ethernet eth0: link down
IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
IP-Config: Complete:
     device=eth0, hwaddr=00:00:de:ad:be:ef, ipaddr=192.168.0.20, mask=255.255.255.0, gw=192.168.0.1
     host=192.168.0.20, domain=, nis-domain=(none)
dm9000 88000000.ethernet eth0: link up, 100Mbps, full-duplex, lpa 0xCDE1
     bootserver=192.168.0.101, rootserver=192.168.0.101, rootpath=
VFS: Mounted root (nfs filesystem) readonly on device 0:11.
devtmpfs: mounted
Freeing unused kernel memory: 1024K
Run /linuxrc as init process
fbcon: Taking over console

Please press Enter to activate this console. 
[root@linux]/# 

下面给出dmesg/kmesg打印出来的log信息

[root@linux]/# 
[root@linux]/# dmesg 
Booting Linux on physical CPU 0x0
Linux version 4.19.0-ga2a89a6-dirty (run@ubuntu) (gcc version 4.8.3 20140320 (prerelease) (Sourcery CodeBench Lite 2014.05-29)) #16 PREEMPT Sat Apr 20 00:50:52 CST 2019
CPU: ARMv7 Processor [412fc082] revision 2 (ARMv7), cr=10c5387d
CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
OF: fdt: Machine model: YIC System SMDKV210 based on S5PV210
Memory policy: Data cache writeback
On node 0 totalpages: 131072
  Normal zone: 1024 pages used for memmap
  Normal zone: 0 pages reserved
  Normal zone: 131072 pages, LIFO batch:31
CPU: All CPU(s) started in SVC mode.
random: get_random_bytes called from start_kernel+0x88/0x3ec with crng_init=0
pcpu-alloc: s0 r0 d32768 u32768 alloc=1*32768
pcpu-alloc: [0] 0 
Built 1 zonelists, mobility grouping on.  Total pages: 130048
Kernel command line: root=/dev/nfs nfsroot=192.168.0.101:/home/run/work/rootfs/rootfs_3.16.57 ip=192.168.0.20:192.168.0.101:192.168.0.1:255.255.255.0::eth0:off init=/linuxrc console=ttySAC2,115200
Dentry cache hash table entries: 65536 (order: 6, 262144 bytes)
Inode-cache hash table entries: 32768 (order: 5, 131072 bytes)
Memory: 510956K/524288K available (5120K kernel code, 223K rwdata, 1512K rodata, 1024K init, 259K bss, 13332K reserved, 0K cma-reserved)
Virtual kernel memory layout:
    vector  : 0xffff0000 - 0xffff1000   (   4 kB)
    fixmap  : 0xffc00000 - 0xfff00000   (3072 kB)
    vmalloc : 0xa0800000 - 0xff800000   (1520 MB)
    lowmem  : 0x80000000 - 0xa0000000   ( 512 MB)
    modules : 0x7f000000 - 0x80000000   (  16 MB)
      .text : 0x(ptrval) - 0x(ptrval)   (6112 kB)
      .init : 0x(ptrval) - 0x(ptrval)   (1024 kB)
      .data : 0x(ptrval) - 0x(ptrval)   ( 224 kB)
       .bss : 0x(ptrval) - 0x(ptrval)   ( 260 kB)
SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
rcu: Preemptible hierarchical RCU implementation.
        Tasks RCU enabled.
NR_IRQS: 16, nr_irqs: 16, preallocated irqs: 16
VIC @(ptrval): id 0x00041192, vendor 0x41
VIC @(ptrval): id 0x00041192, vendor 0x41
VIC @(ptrval): id 0x00041192, vendor 0x41
VIC @(ptrval): id 0x00041192, vendor 0x41
S5PV210 clocks: mout_apll = 1000000000, mout_mpll = 667000000
        mout_epll = 96000000, mout_vpll = 54000000
sched_clock: 32 bits at 33MHz, resolution 29ns, wraps every 64392313329ns
clocksource: samsung_clocksource_timer: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 57309158834 ns
Console: colour dummy device 80x30
Calibrating delay loop... 996.14 BogoMIPS (lpj=4980736)
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
CPU: Testing write buffer coherency: ok
CPU0: Spectre v2: firmware did not set auxiliary control register IBE bit, system vulnerable
Setting up static identity map for 0x30100000 - 0x30100060
rcu: Hierarchical SRCU implementation.
devtmpfs: initialized
VFP support v0.3: implementor 41 architecture 3 part 30 variant c rev 2
clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
futex hash table entries: 256 (order: 0, 7168 bytes)
pinctrl core: initialized pinctrl subsystem
NET: Registered protocol family 16
DMA: preallocated 256 KiB pool for atomic coherent allocations
i2c-core: driver [dummy] registered
gpio gpiochip0: (gpa0): added GPIO chardev (254:0)
gpiochip_setup_dev: registered GPIOs 0 to 7 on device: gpiochip0 (gpa0)
gpio gpiochip1: (gpa1): added GPIO chardev (254:1)
gpiochip_setup_dev: registered GPIOs 8 to 11 on device: gpiochip1 (gpa1)
gpio gpiochip2: (gpb): added GPIO chardev (254:2)
gpiochip_setup_dev: registered GPIOs 12 to 19 on device: gpiochip2 (gpb)
gpio gpiochip3: (gpc0): added GPIO chardev (254:3)
gpiochip_setup_dev: registered GPIOs 20 to 24 on device: gpiochip3 (gpc0)
gpio gpiochip4: (gpc1): added GPIO chardev (254:4)
gpiochip_setup_dev: registered GPIOs 25 to 29 on device: gpiochip4 (gpc1)
gpio gpiochip5: (gpd0): added GPIO chardev (254:5)
gpiochip_setup_dev: registered GPIOs 30 to 33 on device: gpiochip5 (gpd0)
gpio gpiochip6: (gpd1): added GPIO chardev (254:6)
gpiochip_setup_dev: registered GPIOs 34 to 39 on device: gpiochip6 (gpd1)
gpio gpiochip7: (gpe0): added GPIO chardev (254:7)
gpiochip_setup_dev: registered GPIOs 40 to 47 on device: gpiochip7 (gpe0)
gpio gpiochip8: (gpe1): added GPIO chardev (254:8)
gpiochip_setup_dev: registered GPIOs 48 to 52 on device: gpiochip8 (gpe1)
gpio gpiochip9: (gpf0): added GPIO chardev (254:9)
gpiochip_setup_dev: registered GPIOs 53 to 60 on device: gpiochip9 (gpf0)
gpio gpiochip10: (gpf1): added GPIO chardev (254:10)
gpiochip_setup_dev: registered GPIOs 61 to 68 on device: gpiochip10 (gpf1)
gpio gpiochip11: (gpf2): added GPIO chardev (254:11)
gpiochip_setup_dev: registered GPIOs 69 to 76 on device: gpiochip11 (gpf2)
gpio gpiochip12: (gpf3): added GPIO chardev (254:12)
gpiochip_setup_dev: registered GPIOs 77 to 82 on device: gpiochip12 (gpf3)
gpio gpiochip13: (gpg0): added GPIO chardev (254:13)
gpiochip_setup_dev: registered GPIOs 83 to 89 on device: gpiochip13 (gpg0)
gpio gpiochip14: (gpg1): added GPIO chardev (254:14)
gpiochip_setup_dev: registered GPIOs 90 to 96 on device: gpiochip14 (gpg1)
gpio gpiochip15: (gpg2): added GPIO chardev (254:15)
gpiochip_setup_dev: registered GPIOs 97 to 103 on device: gpiochip15 (gpg2)
gpio gpiochip16: (gpg3): added GPIO chardev (254:16)
gpiochip_setup_dev: registered GPIOs 104 to 110 on device: gpiochip16 (gpg3)
gpio gpiochip17: (gpj0): added GPIO chardev (254:17)
gpiochip_setup_dev: registered GPIOs 111 to 118 on device: gpiochip17 (gpj0)
gpio gpiochip18: (gpj1): added GPIO chardev (254:18)
gpiochip_setup_dev: registered GPIOs 119 to 124 on device: gpiochip18 (gpj1)
gpio gpiochip19: (gpj2): added GPIO chardev (254:19)
gpiochip_setup_dev: registered GPIOs 125 to 132 on device: gpiochip19 (gpj2)
gpio gpiochip20: (gpj3): added GPIO chardev (254:20)
gpiochip_setup_dev: registered GPIOs 133 to 140 on device: gpiochip20 (gpj3)
gpio gpiochip21: (gpj4): added GPIO chardev (254:21)
gpiochip_setup_dev: registered GPIOs 141 to 145 on device: gpiochip21 (gpj4)
gpio gpiochip22: (gpi): added GPIO chardev (254:22)
gpiochip_setup_dev: registered GPIOs 146 to 152 on device: gpiochip22 (gpi)
gpio gpiochip23: (mp01): added GPIO chardev (254:23)
gpiochip_setup_dev: registered GPIOs 153 to 160 on device: gpiochip23 (mp01)
gpio gpiochip24: (mp02): added GPIO chardev (254:24)
gpiochip_setup_dev: registered GPIOs 161 to 164 on device: gpiochip24 (mp02)
gpio gpiochip25: (mp03): added GPIO chardev (254:25)
gpiochip_setup_dev: registered GPIOs 165 to 172 on device: gpiochip25 (mp03)
gpio gpiochip26: (mp04): added GPIO chardev (254:26)
gpiochip_setup_dev: registered GPIOs 173 to 180 on device: gpiochip26 (mp04)
gpio gpiochip27: (mp05): added GPIO chardev (254:27)
gpiochip_setup_dev: registered GPIOs 181 to 188 on device: gpiochip27 (mp05)
gpio gpiochip28: (mp06): added GPIO chardev (254:28)
gpiochip_setup_dev: registered GPIOs 189 to 196 on device: gpiochip28 (mp06)
gpio gpiochip29: (mp07): added GPIO chardev (254:29)
gpiochip_setup_dev: registered GPIOs 197 to 204 on device: gpiochip29 (mp07)
gpio gpiochip30: (gph0): added GPIO chardev (254:30)
gpiochip_setup_dev: registered GPIOs 205 to 212 on device: gpiochip30 (gph0)
gpio gpiochip31: (gph1): added GPIO chardev (254:31)
gpiochip_setup_dev: registered GPIOs 213 to 220 on device: gpiochip31 (gph1)
gpio gpiochip32: (gph2): added GPIO chardev (254:32)
gpiochip_setup_dev: registered GPIOs 221 to 228 on device: gpiochip32 (gph2)
gpio gpiochip33: (gph3): added GPIO chardev (254:33)
gpiochip_setup_dev: registered GPIOs 229 to 236 on device: gpiochip33 (gph3)
i2c-core: driver [max8998] registered
SCSI subsystem initialized
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
s3c-i2c e1800000.i2c: clock source (ptrval)
s3c-i2c e1800000.i2c: registers (ptrval) ((ptrval))
s3c-i2c e1800000.i2c: slave address 0x00
s3c-i2c e1800000.i2c: pdata desired frequency 0
s3c-i2c e1800000.i2c: IICLC=00000000
s3c-i2c e1800000.i2c: bus frequency set to 65 KHz
s3c-i2c e1800000.i2c: S3C2410_IICCON=0x41
i2c i2c-0: adapter [s3c2410-i2c] registered
i2c i2c-0: of_i2c: walking child nodes
s3c-i2c e1800000.i2c: i2c-0: S3C I2C adapter
clocksource: Switched to clocksource samsung_clocksource_timer
NET: Registered protocol family 2
tcp_listen_portaddr_hash hash table entries: 256 (order: 0, 6144 bytes)
TCP established hash table entries: 4096 (order: 2, 16384 bytes)
TCP bind hash table entries: 4096 (order: 4, 81920 bytes)
TCP: Hash tables configured (established 4096 bind 4096)
UDP hash table entries: 256 (order: 1, 12288 bytes)
UDP-Lite hash table entries: 256 (order: 1, 12288 bytes)
NET: Registered protocol family 1
RPC: Registered named UNIX socket transport module.
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
Initialise system trusted keyrings
workingset: timestamp_bits=30 max_order=17 bucket_order=0
romfs: ROMFS MTD (C) 2007 Red Hat, Inc.
Key type asymmetric registered
Asymmetric key parser 'x509' registered
io scheduler noop registered
io scheduler deadline registered
io scheduler cfq registered (default)
io scheduler mq-deadline registered
io scheduler kyber registered
samsung-usb2-phy ec100000.usbphy: ec100000.usbphy supply vbus not found, using dummy regulator
samsung-usb2-phy ec100000.usbphy: Linked as a consumer to regulator.0
Serial: 8250/16550 driver, 4 ports, IRQ sharing disabled
e2900000.serial: ttySAC0 at MMIO 0xe2900000 (irq = 58, base_baud = 0) is a S3C6400/10
e2900400.serial: ttySAC1 at MMIO 0xe2900400 (irq = 59, base_baud = 0) is a S3C6400/10
e2900800.serial: ttySAC2 at MMIO 0xe2900800 (irq = 60, base_baud = 0) is a S3C6400/10
console [ttySAC2] enabled
e2900c00.serial: ttySAC3 at MMIO 0xe2900c00 (irq = 61, base_baud = 0) is a S3C6400/10
brd: module loaded
loop: module loaded
dm9000 88000000.ethernet: 88000000.ethernet supply vcc not found, using dummy regulator
dm9000 88000000.ethernet: Linked as a consumer to regulator.0
of_get_named_gpiod_flags: can't parse 'reset-gpios' property of node '/ethernet@88000000[0]'
dm9000 88000000.ethernet: enable clock 'sromc'
eth0: dm9000b at (ptrval),(ptrval) IRQ 144 MAC: 00:00:de:ad:be:ef (platform data)
dwc2 ec000000.hsotg: ec000000.hsotg supply vusb_d not found, using dummy regulator
dwc2 ec000000.hsotg: Linked as a consumer to regulator.0
dwc2 ec000000.hsotg: ec000000.hsotg supply vusb_a not found, using dummy regulator
dwc2 ec000000.hsotg: Configuration mismatch. dr_mode forced to host
dwc2 ec000000.hsotg: dwc2_core_reset: HANG! AHB Idle timeout GRSTCTL GRSTCTL_AHBIDLE
dwc2: probe of ec000000.hsotg failed with error -16
ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
ehci-exynos: EHCI EXYNOS driver
of_get_named_gpiod_flags: can't parse 'samsung,vbus-gpio' property of node '/soc/ehci@ec200000[0]'
exynos-ehci ec200000.ehci: EHCI Host Controller
exynos-ehci ec200000.ehci: new USB bus registered, assigned bus number 1
exynos-ehci ec200000.ehci: irq 71, io mem 0xec200000
exynos-ehci ec200000.ehci: USB 2.0 started, EHCI 1.00
usb usb1: New USB device found, idVendor=1d6b, idProduct=0002, bcdDevice= 4.19
usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
usb usb1: Product: EHCI Host Controller
usb usb1: Manufacturer: Linux 4.19.0-ga2a89a6-dirty ehci_hcd
usb usb1: SerialNumber: ec200000.ehci
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 1 port detected
ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
ohci-exynos: OHCI EXYNOS driver
exynos-ohci ec300000.ohci: USB Host Controller
exynos-ohci ec300000.ohci: new USB bus registered, assigned bus number 2
exynos-ohci ec300000.ohci: irq 71, io mem 0xec300000
usb usb2: New USB device found, idVendor=1d6b, idProduct=0001, bcdDevice= 4.19
usb usb2: New USB device strings: Mfr=3, Product=2, SerialNumber=1
usb usb2: Product: USB Host Controller
usb usb2: Manufacturer: Linux 4.19.0-ga2a89a6-dirty ohci_hcd
usb usb2: SerialNumber: ec300000.ohci
hub 2-0:1.0: USB hub found
hub 2-0:1.0: 1 port detected
usbcore: registered new interface driver usb-storage
usbcore: registered new interface driver ums-sddr09
usbcore: registered new interface driver ums-sddr55
i2c /dev entries driver
i2c-dev: adapter [s3c2410-i2c] registered as minor 0
i2c-core: driver [max17040] registered
sdhci: Secure Digital Host Controller Interface driver
sdhci: Copyright(c) Pierre Ossman
of_get_named_gpiod_flags: can't parse 'cd-gpios' property of node '/soc/sdhci@eb000000[0]'
s3c-sdhci eb000000.sdhci: clock source 0: mmc_busclk.0 (133400000 Hz)
s3c-sdhci eb000000.sdhci: clock source 2: mmc_busclk.2 (96000000 Hz)
s3c-sdhci eb000000.sdhci: GPIO lookup for consumer cd
s3c-sdhci eb000000.sdhci: using device tree for GPIO lookup
of_get_named_gpiod_flags: can't parse 'cd-gpios' property of node '/soc/sdhci@eb000000[0]'
of_get_named_gpiod_flags: can't parse 'cd-gpio' property of node '/soc/sdhci@eb000000[0]'
s3c-sdhci eb000000.sdhci: using lookup tables for GPIO lookup
s3c-sdhci eb000000.sdhci: No GPIO consumer cd found
s3c-sdhci eb000000.sdhci: GPIO lookup for consumer wp
s3c-sdhci eb000000.sdhci: using device tree for GPIO lookup
of_get_named_gpiod_flags: can't parse 'wp-gpios' property of node '/soc/sdhci@eb000000[0]'
of_get_named_gpiod_flags: can't parse 'wp-gpio' property of node '/soc/sdhci@eb000000[0]'
s3c-sdhci eb000000.sdhci: using lookup tables for GPIO lookup
s3c-sdhci eb000000.sdhci: No GPIO consumer wp found
mmc0: SDHCI controller on samsung-hsmmc [eb000000.sdhci] using ADMA
of_get_named_gpiod_flags: can't parse 'cd-gpios' property of node '/soc/sdhci@eb100000[0]'
s3c-sdhci eb100000.sdhci: clock source 0: mmc_busclk.0 (133400000 Hz)
s3c-sdhci eb100000.sdhci: clock source 2: mmc_busclk.2 (96000000 Hz)
s3c-sdhci eb100000.sdhci: GPIO lookup for consumer cd
s3c-sdhci eb100000.sdhci: using device tree for GPIO lookup
of_get_named_gpiod_flags: can't parse 'cd-gpios' property of node '/soc/sdhci@eb100000[0]'
of_get_named_gpiod_flags: can't parse 'cd-gpio' property of node '/soc/sdhci@eb100000[0]'
s3c-sdhci eb100000.sdhci: using lookup tables for GPIO lookup
s3c-sdhci eb100000.sdhci: No GPIO consumer cd found
s3c-sdhci eb100000.sdhci: GPIO lookup for consumer wp
s3c-sdhci eb100000.sdhci: using device tree for GPIO lookup
of_get_named_gpiod_flags: can't parse 'wp-gpios' property of node '/soc/sdhci@eb100000[0]'
of_get_named_gpiod_flags: can't parse 'wp-gpio' property of node '/soc/sdhci@eb100000[0]'
s3c-sdhci eb100000.sdhci: using lookup tables for GPIO lookup
s3c-sdhci eb100000.sdhci: No GPIO consumer wp found
mmc1: SDHCI controller on samsung-hsmmc [eb100000.sdhci] using ADMA
of_get_named_gpiod_flags: can't parse 'cd-gpios' property of node '/soc/sdhci@eb200000[0]'
s3c-sdhci eb200000.sdhci: clock source 0: mmc_busclk.0 (133400000 Hz)
s3c-sdhci eb200000.sdhci: clock source 2: mmc_busclk.2 (96000000 Hz)
s3c-sdhci eb200000.sdhci: GPIO lookup for consumer cd
s3c-sdhci eb200000.sdhci: using device tree for GPIO lookup
of_get_named_gpiod_flags: can't parse 'cd-gpios' property of node '/soc/sdhci@eb200000[0]'
of_get_named_gpiod_flags: can't parse 'cd-gpio' property of node '/soc/sdhci@eb200000[0]'
s3c-sdhci eb200000.sdhci: using lookup tables for GPIO lookup
s3c-sdhci eb200000.sdhci: No GPIO consumer cd found
s3c-sdhci eb200000.sdhci: GPIO lookup for consumer wp
s3c-sdhci eb200000.sdhci: using device tree for GPIO lookup
of_get_named_gpiod_flags: can't parse 'wp-gpios' property of node '/soc/sdhci@eb200000[0]'
of_get_named_gpiod_flags: can't parse 'wp-gpio' property of node '/soc/sdhci@eb200000[0]'
s3c-sdhci eb200000.sdhci: using lookup tables for GPIO lookup
s3c-sdhci eb200000.sdhci: No GPIO consumer wp found
mmc2: SDHCI controller on samsung-hsmmc [eb200000.sdhci] using ADMA
of_get_named_gpiod_flags: can't parse 'cd-gpios' property of node '/soc/sdhci@eb300000[0]'
s3c-sdhci eb300000.sdhci: clock source 0: mmc_busclk.0 (133400000 Hz)
s3c-sdhci eb300000.sdhci: clock source 3: mmc_busclk.3 (96000000 Hz)
s3c-sdhci eb300000.sdhci: GPIO lookup for consumer cd
s3c-sdhci eb300000.sdhci: using device tree for GPIO lookup
of_get_named_gpiod_flags: can't parse 'cd-gpios' property of node '/soc/sdhci@eb300000[0]'
of_get_named_gpiod_flags: can't parse 'cd-gpio' property of node '/soc/sdhci@eb300000[0]'
s3c-sdhci eb300000.sdhci: using lookup tables for GPIO lookup
s3c-sdhci eb300000.sdhci: No GPIO consumer cd found
s3c-sdhci eb300000.sdhci: GPIO lookup for consumer wp
s3c-sdhci eb300000.sdhci: using device tree for GPIO lookup
of_get_named_gpiod_flags: can't parse 'wp-gpios' property of node '/soc/sdhci@eb300000[0]'
of_get_named_gpiod_flags: can't parse 'wp-gpio' property of node '/soc/sdhci@eb300000[0]'
s3c-sdhci eb300000.sdhci: using lookup tables for GPIO lookup
s3c-sdhci eb300000.sdhci: No GPIO consumer wp found
mmc2: new high speed SDHC card at address 0007
mmcblk2: mmc2:0007 SD04G 3.68 GiB 
mmc3: Internal clock never stabilised.
mmc3: sdhci: ============ SDHCI REGISTER DUMP ===========
mmc3: sdhci: Sys addr:  0x00000000 | Version:  0x00002401
 mmcblk2: p1
mmc3: sdhci: Blk size:  0x00000000 | Blk cnt:  0x00000000
mmc3: sdhci: Argument:  0x00000000 | Trn mode: 0x00000000
mmc3: sdhci: Present:   0x01fa0000 | Host ctl: 0x00000000
mmc3: sdhci: Power:     0x0000000e | Blk gap:  0x00000000
mmc3: sdhci: Wake-up:   0x00000000 | Clock:    0x00008001
mmc3: sdhci: Timeout:   0x00000000 | Int stat: 0x00000000
usb 1-1: new high-speed USB device number 2 using exynos-ehci
mmc3: sdhci: Int enab:  0x00ff0043 | Sig enab: 0x00ff0043
mmc3: sdhci: AC12 err:  0x00000000 | Slot int: 0x00000000
mmc3: sdhci: Caps:      0x05e80080 | Caps_1:   0x00000000
mmc3: sdhci: Cmd:       0x00000000 | Max curr: 0x00000000
mmc3: sdhci: Resp[0]:   0x00000000 | Resp[1]:  0x00000000
mmc3: sdhci: Resp[2]:   0x00000000 | Resp[3]:  0x00000000
mmc3: sdhci: Host ctl2: 0x00000000
mmc3: sdhci: ADMA Err:  0x00000000 | ADMA Ptr: 0x00000000
mmc3: sdhci: ============================================
mmc3: SDHCI controller on samsung-hsmmc [eb300000.sdhci] using ADMA
NET: Registered protocol family 10
Segment Routing with IPv6
sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver
NET: Registered protocol family 17
Loading compiled-in X.509 certificates
hctosys: unable to open rtc device (rtc0)
usb 1-1: New USB device found, idVendor=05e3, idProduct=0608, bcdDevice=85.36
usb 1-1: New USB device strings: Mfr=0, Product=1, SerialNumber=0
usb 1-1: Product: USB2.0 Hub
hub 1-1:1.0: USB hub found
hub 1-1:1.0: 4 ports detected
dm9000 88000000.ethernet eth0: link down
random: fast init done
dm9000 88000000.ethernet eth0: link down
IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
IP-Config: Complete:
     device=eth0, hwaddr=00:00:de:ad:be:ef, ipaddr=192.168.0.20, mask=255.255.255.0, gw=192.168.0.1
     host=192.168.0.20, domain=, nis-domain=(none)
dm9000 88000000.ethernet eth0: link up, 100Mbps, full-duplex, lpa 0xCDE1
     bootserver=192.168.0.101, rootserver=192.168.0.101, rootpath=
VFS: Mounted root (nfs filesystem) readonly on device 0:11.
devtmpfs: mounted
Freeing unused kernel memory: 1024K
Run /linuxrc as init process
fbcon: Taking over console
random: crng init done
[root@linux]/# 

可以看到默认打印等级4,打印出来的是不全或者说不是所有的打印信息。

当然我们还可以在内核启动前修改打印等级。

比如在编译内核前,可以通过配置和printk相关的CONFIG来决定打印等级。

上一节我们已经知道了,log输出与否是通过打印等级和console_loglevel 变量比较来实现了,如果我们修改了console_loglevel 变量,那么打印等级自然也就该了。

static bool suppress_message_printing(int level)
{
	return (level >= console_loglevel && !ignore_loglevel);
}

下面给出几种方式:

如果不想编译内核,可以通过bootloader传参中指定loglevel等级来实现,

下面就是 内核使用文档给出的一个例子

bootloader传参,loglevel的解析函数

static int __init loglevel(char *str)
{
	int newlevel;

	/*
	 * Only update loglevel value when a correct setting was passed,
	 * to prevent blind crashes (when loglevel being set to 0) that
	 * are quite hard to debug
	 */
	if (get_option(&str, &newlevel)) {
		console_loglevel = newlevel;
		return 0;
	}

	return -EINVAL;
}

early_param("loglevel", loglevel);

当然也可以在bootloader指定具体的名字来指定打印等级。

static int __init debug_kernel(char *str)
{
	console_loglevel = CONSOLE_LOGLEVEL_DEBUG;
	return 0;
}

static int __init quiet_kernel(char *str)
{
	console_loglevel = CONSOLE_LOGLEVEL_QUIET;
	return 0;
}

early_param("debug", debug_kernel);
early_param("quiet", quiet_kernel);

猜你喜欢

转载自blog.csdn.net/qq_16777851/article/details/89736667