通过dump内存中printk的__log_buf地址查看Linux启动部分的错误

这篇博客主要介绍了如何通过dump内存中printk的__log_buf地址来查看Linux启动过程中的错误。内容涉及到Linux内核参数、加载过程、错误提示,以及在启动过程中遇到的内核错误,如无法处理的页错误。通过这些信息,可以定位并解决启动问题。
部署运行你感兴趣的模型镜像

已经将u-boot移植到了自己做的demo板上,现在开始移植linux PowerPC内核,前两天用bootm引导内核,当执行到:
  1.         /*
  2.          * Linux Kernel Parameters (passing board info data):
  3.          *   r3: ptr to board info data
  4.          *   r4: initrd_start or 0 if no initrd
  5.          *   r5: initrd_end - unused if r4 is 0
  6.          *   r6: Start of command line string
  7.          *   r7: End   of command line string
  8.          */
  9.         debug ("   Booting using board info.../n");
  10.         (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end);
内核开始执行,但直接就挂起,串口没有输出:
  1. #> bootm 0xffd00000 - 0xa000000
  2. *  kernel: cmdline image address = 0xffd00000
  3. ## Booting kernel from Legacy Image at ffd00000 ...
  4.    Image Name:   Linux-2.6.26.3
  5.    Created:      2008-09-08  15:40:26 UTC
  6.    Image Type:   PowerPC Linux Kernel Image (gzip compressed)
  7.    Data Size:    1199265 Bytes =  1.1 MB
  8.    Load Address: 00000000
  9.    Entry Point:  00000000
  10.    Verifying Checksum ... OK
  11.    kernel data at 0xffd00040, len = 0x00124ca1 (1199265)
  12. ## Skipping init Ramdisk
  13. ## No init Ramdisk
  14.    ramdisk start = 0x00000000, ramdisk end = 0x00000000
  15. *  fdt: cmdline image address = 0x0a000000
  16. ## Checking for 'FDT'/'FDT Image' at 0a000000
  17. *  fdt: raw FDT blob
  18. ## Flattened Device Tree blob at 0a000000
  19.    Booting using the fdt blob at 0xa000000
  20.    of_flat_tree at 0x0a000000 size 0x00002cdc
  21.    Uncompressing Kernel Image ... OK
  22.    kernel loaded at 0x00000000, end = 0x1fe9fcf8
  23. ## Current stack ends at 0x1fe9fca8
  24. ## device tree at 0x0A000000 ... 0x0A002CDB (len=23772=0x5CDC)
  25.    Loading Device Tree to 007fa000, end 007ffcdb ... OK
  26. Updating property 'timebase-frequency' =  1d cd 65 02
  27. Updating property 'clock-frequency' =  1d cd 65 02
  28. Updating property '/plb/clock-frequency' =  09 ef 21 ab
  29. Updating property '/plb/opb/clock-frequency' =  04 f7 90 d5
  30. Updating property '/plb/opb/ebc/clock-frequency' =  04 f7 90 d5
  31. Updating property 'clock-frequency' =  00 54 c5 63
  32. Updating property '/plb/opb/ethernet@40000c00/mac-address' =  00 22 33 44 55 66
  33. Updating property '/plb/opb/ethernet@40000c00/local-mac-address' =  00 22 33 446
  34. Updating property '/plb/opb/ethernet@40000e00/mac-address' =  00 33 44 55 66 77
  35. Updating property '/plb/opb/ethernet@40000e00/local-mac-address' =  00 33 44 557
  36. No alias for ethernet2
  37. No alias for ethernet3
  38. ## initrd_high = 0x30000000, copy_to_ram = 1
  39.    ramdisk load start = 0x00000000, ramdisk load end = 0x00000000
  40. ## Transferring control to Linux (at address 00000000) ...
  41.    Booting using OF flat tree...

不知道问题在哪,本准备点led来看代码执行情况,突然发现网上邮件列表里有人提到可以利用printk的__log_buf地址来查看错误信息,试了一下,能定位到错误发生的大概位置了。
.config中配置CONFIG_PPC_EARLY_DEBUG_44x、CONFIG_PPC_EARLY_DEBUG_44x_PHYSLOW和CONFIG_EARLY_PRINTK:等,这样在内核启动时,如串口还没初始化,printk的信息将先存放在__log_buf中。
  1. static char __log_buf[__LOG_BUF_LEN]; /* /kernel/printk.c */
这时,直接dump __log_buf这块内存就可以看到错误信息了。通过System.map查到__log_buf的虚拟地址,内核默认虚拟地址KERNELBASE0xc0000000,现在内核的加载位置是0x0,所以__log_buf的地址是0xc00271bc0-0xc0000000=0x271bc0,重启u-boot  dump内存,dump输出是
  1. >md 0x271bc0
  2. 00271bc0 : 00000000 00000000 3c313e55 6e61626c  ........<1>Unabl
  3. 00271bd0 : 6520746f 2068616e 646c6520 6b65726e  e to handle kern
  4. 00271be0 : 656c2070 6167696e 67207265 71756573  el paging reques
  5. 00271bf0 : 7420666f 72206461 74612061 74206164  t for data at ad
  6. 00271c00 : 64726573 73203078 62663766 66653530  dress 0xbf7ffe50
  7. 00271c10 : 0a3c313e 4661756c 74696e67 20696e73  .<1>Faulting ins
  8. 00271c20 : 74727563 74696f6e 20616464 72657373  truction address
  9. 00271c30 : 3a203078 63303232 66656634 0a3c343e  : 0xc022fef4.<4>
  10. 00271c40 : 4f6f7073 3a204b65 726e656c 20616363  Oops: Kernel acc
  11. 00271c50 : 65737320 6f662062 61642061 7265612c  ess of bad area,
  12. 00271c60 : 20736967 3a203131 205b2331 5d0a3c34   sig: 11 [#1].<4
  13. 00271c70 : 3e0a3c34 3e4d6f64 756c6573 206c696e  >.<4>Modules lin
  14. 00271c80 : 6b656420 696e3a0a 3c343e4e 49503a20  ked in:.<4>NIP:
  15. 00271c90 : 63303232 66656634 204c523a 20633032  c022fef4 LR: c02
  16. 00271ca0 : 33303036 38204354 523a2063 30303039  30068 CTR: c0009
  17. 00271cb0 : 3263300a 3c343e52 4547533a 20633032  2c0.<4>REGS: c02
  18. >md 0x271cb0
  19. 00271cb0 : 3263300a 3c343e52 4547533a 20633032  2c0.<4>REGS: c02
  20. 00271cc0 : 36356565 30205452 41503a20 30333030  65ee0 TRAP: 0300
  21. 00271cd0 : 2020204e 6f742074 61696e74 65642020     Not tainted
  22. 00271ce0 : 28322e36 2e32362e 33290a3c 343e4d53  (2.6.26.3).<4>MS
  23. 00271cf0 : 523a2030 30303231 30303020 3c4d453e  R: 00021000 <ME>
  24. 00271d00 : 20204352 3a203234 30323234 32322020    CR: 24022422
  25. 00271d10 : 5845523a 20303030 30303030 300a3c34  XER: 00000000.<4
  26. 00271d20 : 3e444541 523a2062 66376666 6535302c  >DEAR: bf7ffe50,
  27. 00271d30 : 20455352 3a203030 30303030 30300a3c   ESR: 00000000.<
  28. 00271d40 : 343e5441 534b203d 20633032 34643461  4>TASK = c024d4a
  29. 00271d50 : 305b305d 20277377 61707065 72272054  0[0] 'swapper' T
  30. 00271d60 : 48524541 443a2063 30323634 3030300a  HREAD: c0264000.
  31. 00271d70 : 3c363e47 50523030 3a206666 30303030  <6>GPR00: ff0000
  32. 00271d80 : 30302063 30323635 66393020 63303234  00 c0265f90 c024
  33. 00271d90 : 64346130 20303030 30303030 30203030  d4a0 00000000 00
  34. 00271da0 : 30303030 30302030 30303030 30303020  000000 00000000
  35. 440GX>md 0x271da0
  36. 00271da0 : 30303030 30302030 30303030 30303020  000000 00000000
  37. 00271db0 : 30303766 66663030 20303037 66666630  007fff00 007fff0
  38. 00271dc0 : 30200a3c 363e4750 5230383a 20633030  0 .<6>GPR08: c00
  39. 00271dd0 : 30613666 30206330 37666665 35302063  0a6f0 c07ffe50 c
  40. 00271de0 : 30303064 37353820 63303030 64373563  000d758 c000d75c
  41. 00271df0 : 20303030 30303030 31203461 31303630   00000001 4a1060
  42. 00271e00 : 63312031 66666535 66303020 30303030  c1 1ffe5f00 0000
  43. 00271e10 : 30303030 200a3c36 3e475052 31363a20  0000 .<6>GPR16:
  44. 00271e20 : 31666664 62376534 20316666 65303137  1ffdb7e4 1ffe017
  45. 00271e30 : 38203030 30303030 30302030 30303030  8 00000000 00000
  46. 00271e40 : 30303020 30303030 30303030 20303030  000 00000000 000
  47. 00271e50 : 30303030 30203166 66653131 31632030  00000 1ffe111c 0
  48. 00271e60 : 30303030 30303620 0a3c363e 47505232  0000006 .<6>GPR2
  49. 00271e70 : 343a2030 30303030 30303020 30303030  4: 00000000 0000
  50. 00271e80 : 30303030 20633032 37303030 30206330  0000 c0270000 c0
  51. 00271e90 : 32326638 61632030 30303030 30303020  22f8ac 00000000
  52. >md 0x271e90
  53. 00271e90 : 32326638 61632030 30303030 30303020  22f8ac 00000000
  54. 00271ea0 : 66666666 66666666 20303030 30303030  ffffffff 0000000
  55. 00271eb0 : 30206266 37666665 3530200a 3c343e4e  0 bf7ffe50 .<4>N
  56. 00271ec0 : 4950205b 63303232 66656634 5d206f66  IP [c022fef4] of
  57. 00271ed0 : 5f736361 6e5f666c 61745f64 742b3078  _scan_flat_dt+0x
  58. 00271ee0 : 33302f30 78313763 0a3c343e 4c52205b  30/0x17c.<4>LR [
  59. 00271ef0 : 63303233 30303638 5d206561 726c795f  c0230068] early_
  60. 00271f00 : 696e6974 5f646576 74726565 2b307832  init_devtree+0x2
  61. 00271f10 : 382f3078 3234630a 3c343e43 616c6c20  8/0x24c.<4>Call
  62. 00271f20 : 54726163 653a0a3c 343e5b63 30323635  Trace:.<4>[c0265
  63. 00271f30 : 6662305d 205b6330 32333030 36385d20  fb0] [c0230068]
  64. 00271f40 : 6561726c 795f696e 69745f64 65767472  early_init_devtr
  65. 00271f50 : 65652b30 7832382f 30783234 630a3c34  ee+0x28/0x24c.<4
  66. 00271f60 : 3e5b6330 32363566 64305d20 5b633032  >[c0265fd0] [c02
  67. 00271f70 : 33306466 385d206d 61636869 6e655f69  30df8] machine_i
  68. 00271f80 : 6e69742b 30783230 2f307835 630a3c34  nit+0x20/0x5c.<4
  69. >md 0x271f80
  70. 00271f80 : 6e69742b 30783230 2f307835 630a3c34  nit+0x20/0x5c.<4
  71. 00271f90 : 3e5b6330 32363566 66305d20 5b633030  >[c0265ff0] [c00
  72. 00271fa0 : 30303165 345d2073 6b70696e 762b3078  001e4] skpinv+0x
  73. 00271fb0 : 3138632f 30783163 630a3c34 3e496e73  18c/0x1cc.<4>Ins
  74. 00271fc0 : 74727563 74696f6e 2064756d 703a0a3c  truction dump:.<
  75. 00271fd0 : 343e3934 32316666 65302037 63303830  4>9421ffe0 7c080
  76. 00271fe0 : 32613620 62663431 30303038 20393030  2a6 bf410008 900
  77. 00271ff0 : 31303032 34203366 34306330 32372038  10024 3f40c027 8
  78. 00272000 : 31336162 30386320 37633762 31623738  13ab08c 7c7b1b78
  79. 00272010 : 20383030 39303030 38200a3c 343e3763   80090008 .<4>7c
  80. 00272020 : 39633233 37382037 66653930 32313420  9c2378 7fe90214
  81. 00272030 : 33383630 30303030 20336261 30666666  38600000 3ba0fff
  82. 00272040 : 66203c38 30396630 3030303e 20336266  f <809f0000> 3bf
  83. 00272050 : 66303030 34203266 38343030 30322034  f0004 2f840002 4
  84. 00272060 : 31396530 30643020 0a3c343e 2d2d2d5b  19e00d0 .<4>---[
  85. 00272070 : 20656e64 20747261 63652033 31666430   end trace 31fd0
  86. >md 0x272070
  87. 00272070 : 20656e64 20747261 63652033 31666430   end trace 31fd0
  88. 00272080 : 62613764 38373536 30303120 5d2d2d2d  ba7d8756001 ]---
  89. 00272090 : 0a3c303e 4b65726e 656c2070 616e6963  .<0>Kernel panic
  90. 002720a0 : 202d206e 6f742073 796e6369 6e673a20   - not syncing:
  91. 002720b0 : 41747465 6d707465 6420746f 206b696c  Attempted to kil
  92. 002720c0 : 6c207468 65206964 6c652074 61736b21  l the idle task!
利用backtrace,看到错误与device tree相关,看来是device tree文件有问题,查了下,修正,重新引导内核,串口输出
  1. #> bootm 0xffd00000 - 0xa000000
  2. *  kernel: cmdline image address = 0xffd00000
  3. ## Booting kernel from Legacy Image at ffd00000 ...
  4.    Image Name:   Linux-2.6.26.3
  5.    Created:      2008-09-08  15:40:26 UTC
  6.    Image Type:   PowerPC Linux Kernel Image (gzip compressed)
  7.    Data Size:    1199265 Bytes =  1.1 MB
  8.    Load Address: 00000000
  9.    Entry Point:  00000000
  10.    Verifying Checksum ... OK
  11.    kernel data at 0xffd00040, len = 0x00124ca1 (1199265)
  12. ## Skipping init Ramdisk
  13. ## No init Ramdisk
  14.    ramdisk start = 0x00000000, ramdisk end = 0x00000000
  15. *  fdt: cmdline image address = 0x0a000000
  16. ## Checking for 'FDT'/'FDT Image' at 0a000000
  17. *  fdt: raw FDT blob
  18. ## Flattened Device Tree blob at 0a000000
  19.    Booting using the fdt blob at 0xa000000
  20.    of_flat_tree at 0x0a000000 size 0x00002cdc
  21.    Uncompressing Kernel Image ... OK
  22.    kernel loaded at 0x00000000, end = 0x1fe9fcf8
  23. ## Current stack ends at 0x1fe9fca8
  24. ## device tree at 0x0A000000 ... 0x0A002CDB (len=23772=0x5CDC)
  25.    Loading Device Tree to 007fa000, end 007ffcdb ... OK
  26. Updating property 'timebase-frequency' =  1d cd 65 02
  27. Updating property 'clock-frequency' =  1d cd 65 02
  28. Updating property '/plb/clock-frequency' =  09 ef 21 ab
  29. Updating property '/plb/opb/clock-frequency' =  04 f7 90 d5
  30. Updating property '/plb/opb/ebc/clock-frequency' =  04 f7 90 d5
  31. Updating property 'clock-frequency' =  00 54 c5 63
  32. Updating property '/plb/opb/ethernet@40000c00/mac-address' =  00 22 33 44 55 66
  33. Updating property '/plb/opb/ethernet@40000c00/local-mac-address' =  00 22 33 446
  34. Updating property '/plb/opb/ethernet@40000e00/mac-address' =  00 33 44 55 66 77
  35. Updating property '/plb/opb/ethernet@40000e00/local-mac-address' =  00 33 44 557
  36. No alias for ethernet2
  37. No alias for ethernet3
  38. ## initrd_high = 0x30000000, copy_to_ram = 1
  39.    ramdisk load start = 0x00000000, ramdisk load end = 0x00000000
  40. ## Transferring control to Linux (at address 00000000) ...
  41.    Booting using OF flat tree...
  42. Using Galaxy machine description
  43. Linux version 2.6.26.3 (gr1x@mars) (gcc version 4.2.2) #1 Mon Sep 8 23:39:50 CS8
  44. console [udbg0] enabled
  45. setup_arch: bootmem
  46. arch: exit
  47. Zone PFN ranges:
  48.   DMA             0 ->   131072
  49.   Normal     131072 ->   131072
  50. Movable zone start PFN for each node
  51. early_node_map[1] active PFN ranges
  52.     0:        0 ->   131072
  53. Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 130048
  54. Kernel command line:
  55. UIC3 (32 IRQ sources) at DCR 0x200
  56. UIC0 (32 IRQ sources) at DCR 0xc0
  57. UIC1 (32 IRQ sources) at DCR 0xd0
  58. UIC2 (32 IRQ sources) at DCR 0x210
  59. Unable to handle kernel paging request for data at address 0x00000000
  60. Faulting instruction address: 0xc0010a2c
  61. Oops: Kernel access of bad area, sig: 11 [#1]
  62. Galaxy
  63. Modules linked in:
  64. NIP: c0010a2c LR: c01418cc CTR: c0013aec
  65. REGS: c0265e60 TRAP: 0300   Not tainted  (2.6.26.3)
  66. MSR: 00021000 <ME>  CR: 84e22448  XER: 20000000
  67. DEAR: 00000000, ESR: 00000000
  68. TASK = c024d4a0[0] 'swapper' THREAD: c0264000
  69. GPR00: c014190c c0265f10 c024d4a0 00000000 c01f6103 ffffffff 00000000 00000090
  70. GPR08: 00000000 00000069 c025be8c c07faafb 42e22484 4a1060c1 1ffe5f00 00000000
  71. GPR16: 1ffdb7e4 1ffe0178 00000000 00000000 00000000 00000000 1ffe111c 00000006
  72. GPR24: 00000000 00000000 c00161f4 c01f6220 dfffe434 c0265f48 c01f6104 dffff048
  73. NIP [c0010a2c] strcmp+0x8/0x24
  74. LR [c01418cc] of_find_property+0x4c/0x7c
  75. Call Trace:
  76. [c0265f10] [c0047784] set_irq_type+0x60/0x98 (unreliable)
  77. [c0265f30] [c014190c] of_get_property+0x10/0x34
  78. [c0265f40] [c0141ce8] of_device_is_compatible+0x24/0xa0
  79. [c0265f70] [c0141f54] of_find_compatible_node+0x78/0xc4
  80. [c0265f90] [c023303c] uic_init_tree+0x140/0x17c
  81. [c0265fb0] [c022e7e0] init_IRQ+0x24/0x34
  82. [c0265fc0] [c02288f8] start_kernel+0x174/0x2a8
  83. [c0265ff0] [c00001e8] skpinv+0x190/0x1cc
  84. Instruction dump:
  85. 3884ffff 8c050001 2c000000 4082fff8 38a5ffff 8c040001 2c000000 9c050001
  86. 4082fff4 4e800020 38a3ffff 3884ffff <8c650001> 2c830000 8c040001 7c601851
  87. ---[ end trace 31fd0ba7d8756001 ]---
  88. Kernel panic - not syncing: Attempted to kill the idle task!
  89. Rebooting in 180 seconds..
摸黑调试,又进来一步;)。

您可能感兴趣的与本文相关的镜像

Stable-Diffusion-3.5

Stable-Diffusion-3.5

图片生成
Stable-Diffusion

Stable Diffusion 3.5 (SD 3.5) 是由 Stability AI 推出的新一代文本到图像生成模型,相比 3.0 版本,它提升了图像质量、运行速度和硬件效率

int printk(const char *fmt, ...); /* * Special printk facility for scheduler/timekeeping use only, _DO_NOT_USE_ ! */ __printf(1, 2) __cold int printk_deferred(const char *fmt, ...); /* * Please don't use printk_ratelimit(), because it shares ratelimiting state * with all other unrelated printk_ratelimit() callsites. Instead use * printk_ratelimited() or plain old __ratelimit(). */ extern int __printk_ratelimit(const char *func); #define printk_ratelimit() __printk_ratelimit(__func__) extern bool printk_timed_ratelimit(unsigned long *caller_jiffies, unsigned int interval_msec); extern int printk_delay_msec; extern int dmesg_restrict; extern int devkmsg_sysctl_set_loglvl(struct ctl_table *table, int write, void *buf, size_t *lenp, loff_t *ppos); extern void wake_up_klogd(void); char *log_buf_addr_get(void); u32 log_buf_len_get(void); void log_buf_vmcoreinfo_setup(void); void __init setup_log_buf(int early); __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...); void dump_stack_print_info(const char *log_lvl); void show_regs_print_info(const char *log_lvl); extern asmlinkage void dump_stack_lvl(const char *log_lvl) __cold; extern asmlinkage void dump_stack(void) __cold; extern void printk_safe_flush(void); extern void printk_safe_flush_on_panic(void); #else static inline __printf(1, 0) int vprintk(const char *s, va_list args) { return 0; } static inline __printf(1, 2) __cold int printk(const char *s, ...) { return 0; } 底下有 int printk(const char *s, ...) { return 0; }
最新发布
10-15
/* SPDX-License-Identifier: GPL-2.0 */ #ifndef __KERNEL_PRINTK__ #define __KERNEL_PRINTK__ #include <stdarg.h> #include <linux/init.h> #include <linux/kern_levels.h> #include <linux/linkage.h> #include <linux/cache.h> #include <linux/ratelimit_types.h> extern const char linux_banner[]; extern const char linux_proc_banner[]; extern int oops_in_progress; /* If set, an oops, panic(), BUG() or die() is in progress */ #define PRINTK_MAX_SINGLE_HEADER_LEN 2 static inline int printk_get_level(const char *buffer) { if (buffer[0] == KERN_SOH_ASCII && buffer[1]) { switch (buffer[1]) { case '0' ... '7': case 'c': /* KERN_CONT */ return buffer[1]; } } return 0; } static inline const char *printk_skip_level(const char *buffer) { if (printk_get_level(buffer)) return buffer + 2; return buffer; } static inline const char *printk_skip_headers(const char *buffer) { while (printk_get_level(buffer)) buffer = printk_skip_level(buffer); return buffer; } #define CONSOLE_EXT_LOG_MAX 8192 /* printk's without a loglevel use this.. */ #define MESSAGE_LOGLEVEL_DEFAULT CONFIG_MESSAGE_LOGLEVEL_DEFAULT /* We show everything that is MORE important than this.. */ #define CONSOLE_LOGLEVEL_SILENT 0 /* Mum's the word */ #define CONSOLE_LOGLEVEL_MIN 1 /* Minimum loglevel we let people use */ #define CONSOLE_LOGLEVEL_DEBUG 10 /* issue debug messages */ #define CONSOLE_LOGLEVEL_MOTORMOUTH 15 /* You can't shut this one up */ /* * Default used to be hard-coded at 7, quiet used to be hardcoded at 4, * we're now allowing both to be set from kernel config. */ #define CONSOLE_LOGLEVEL_DEFAULT CONFIG_CONSOLE_LOGLEVEL_DEFAULT #define CONSOLE_LOGLEVEL_QUIET CONFIG_CONSOLE_LOGLEVEL_QUIET extern int console_printk[]; #define console_loglevel (console_printk[0]) #define default_message_loglevel (console_printk[1]) #define minimum_console_loglevel (console_printk[2]) #define default_console_loglevel (console_printk[3]) static inline void console_silent(void) { console_loglevel = CONSOLE_LOGLEVEL_SILENT; } static inline void console_verbose(void) { if (console_loglevel) console_loglevel = CONSOLE_LOGLEVEL_MOTORMOUTH; } /* strlen("ratelimit") + 1 */ #define DEVKMSG_STR_MAX_SIZE 10 extern char devkmsg_log_str[]; struct ctl_table; extern int suppress_printk; struct va_format { const char *fmt; va_list *va; }; /* * FW_BUG * Add this to a message where you are sure the firmware is buggy or behaves * really stupid or out of spec. Be aware that the responsible BIOS developer * should be able to fix this issue or at least get a concrete idea of the * problem by reading your message without the need of looking at the kernel * code. * * Use it for definite and high priority BIOS bugs. * * FW_WARN * Use it for not that clear (e.g. could the kernel messed up things already?) * and medium priority BIOS bugs. * * FW_INFO * Use this one if you want to tell the user or vendor about something * suspicious, but generally harmless related to the firmware. * * Use it for information or very low priority BIOS bugs. */ #define FW_BUG "[Firmware Bug]: " #define FW_WARN "[Firmware Warn]: " #define FW_INFO "[Firmware Info]: " /* * HW_ERR * Add this to a message for hardware errors, so that user can report * it to hardware vendor instead of LKML or software vendor. */ #define HW_ERR "[Hardware Error]: " /* * DEPRECATED * Add this to a message whenever you want to warn user space about the use * of a deprecated aspect of an API so they can stop using it */ #define DEPRECATED "[Deprecated]: " /* * Dummy printk for disabled debugging statements to use whilst maintaining * gcc's format checking. */ #define no_printk(fmt, ...) \ ({ \ if (0) \ printk(fmt, ##__VA_ARGS__); \ 0; \ }) #ifdef CONFIG_EARLY_PRINTK extern asmlinkage __printf(1, 2) void early_printk(const char *fmt, ...); #else static inline __printf(1, 2) __cold void early_printk(const char *s, ...) { } #endif #ifdef CONFIG_PRINTK_NMI extern void printk_nmi_enter(void); extern void printk_nmi_exit(void); extern void printk_nmi_direct_enter(void); extern void printk_nmi_direct_exit(void); #else static inline void printk_nmi_enter(void) { } static inline void printk_nmi_exit(void) { } static inline void printk_nmi_direct_enter(void) { } static inline void printk_nmi_direct_exit(void) { } #endif /* PRINTK_NMI */ struct dev_printk_info; #ifdef CONFIG_PRINTK asmlinkage __printf(4, 0) int vprintk_emit(int facility, int level, const struct dev_printk_info *dev_info, const char *fmt, va_list args); asmlinkage __printf(1, 0) int vprintk(const char *fmt, va_list args); asmlinkage __printf(1, 2) __cold int printk(const char *fmt, ...); /* * Special printk facility for scheduler/timekeeping use only, _DO_NOT_USE_ ! */ __printf(1, 2) __cold int printk_deferred(const char *fmt, ...); /* * Please don't use printk_ratelimit(), because it shares ratelimiting state * with all other unrelated printk_ratelimit() callsites. Instead use * printk_ratelimited() or plain old __ratelimit(). */ extern int __printk_ratelimit(const char *func); #define printk_ratelimit() __printk_ratelimit(__func__) extern bool printk_timed_ratelimit(unsigned long *caller_jiffies, unsigned int interval_msec); extern int printk_delay_msec; extern int dmesg_restrict; extern int devkmsg_sysctl_set_loglvl(struct ctl_table *table, int write, void *buf, size_t *lenp, loff_t *ppos); extern void wake_up_klogd(void); char *log_buf_addr_get(void); u32 log_buf_len_get(void); void log_buf_vmcoreinfo_setup(void); void __init setup_log_buf(int early); __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...); void dump_stack_print_info(const char *log_lvl); void show_regs_print_info(const char *log_lvl); extern asmlinkage void dump_stack_lvl(const char *log_lvl) __cold; extern asmlinkage void dump_stack(void) __cold; extern void printk_safe_flush(void); extern void printk_safe_flush_on_panic(void); #else static inline __printf(1, 0) int vprintk(const char *s, va_list args) { return 0; } static inline __printf(1, 2) __cold int printk(const char *s, ...) { return 0; } static inline __printf(1, 2) __cold int printk_deferred(const char *s, ...) { return 0; } static inline int printk_ratelimit(void) { return 0; } static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies, unsigned int interval_msec) { return false; } static inline void wake_up_klogd(void) { } static inline char *log_buf_addr_get(void) { return NULL; } static inline u32 log_buf_len_get(void) { return 0; } static inline void log_buf_vmcoreinfo_setup(void) { } static inline void setup_log_buf(int early) { } static inline __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...) { } static inline void dump_stack_print_info(const char *log_lvl) { } static inline void show_regs_print_info(const char *log_lvl) { } static inline void dump_stack_lvl(const char *log_lvl) { } static inline void dump_stack(void) { } static inline void printk_safe_flush(void) { } static inline void printk_safe_flush_on_panic(void) { } #endif extern int kptr_restrict; /** * pr_fmt - used by the pr_*() macros to generate the printk format string * @fmt: format string passed from a pr_*() macro * * This macro can be used to generate a unified format string for pr_*() * macros. A common use is to prefix all pr_*() messages in a file with a common * string. For example, defining this at the top of a source file: * * #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt * * would prefix all pr_info, pr_emerg... messages in the file with the module * name. */ #ifndef pr_fmt #define pr_fmt(fmt) fmt #endif /** * pr_emerg - Print an emergency-level message * @fmt: format string * @...: arguments for the format string * * This macro expands to a printk with KERN_EMERG loglevel. It uses pr_fmt() to * generate the format string. */ #define pr_emerg(fmt, ...) \ printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__) /** * pr_alert - Print an alert-level message * @fmt: format string * @...: arguments for the format string * * This macro expands to a printk with KERN_ALERT loglevel. It uses pr_fmt() to * generate the format string. */ #define pr_alert(fmt, ...) \ printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__) /** * pr_crit - Print a critical-level message * @fmt: format string * @...: arguments for the format string * * This macro expands to a printk with KERN_CRIT loglevel. It uses pr_fmt() to * generate the format string. */ #define pr_crit(fmt, ...) \ printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__) /** * pr_err - Print an error-level message * @fmt: format string * @...: arguments for the format string * * This macro expands to a printk with KERN_ERR loglevel. It uses pr_fmt() to * generate the format string. */ #define pr_err(fmt, ...) \ printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) /** * pr_warn - Print a warning-level message * @fmt: format string * @...: arguments for the format string * * This macro expands to a printk with KERN_WARNING loglevel. It uses pr_fmt() * to generate the format string. */ #define pr_warn(fmt, ...) \ printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) /** * pr_notice - Print a notice-level message * @fmt: format string * @...: arguments for the format string * * This macro expands to a printk with KERN_NOTICE loglevel. It uses pr_fmt() to * generate the format string. */ #define pr_notice(fmt, ...) \ printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) /** * pr_info - Print an info-level message * @fmt: format string * @...: arguments for the format string * * This macro expands to a printk with KERN_INFO loglevel. It uses pr_fmt() to * generate the format string. */ #define pr_info(fmt, ...) \ printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) /** * pr_cont - Continues a previous log message in the same line. * @fmt: format string * @...: arguments for the format string * * This macro expands to a printk with KERN_CONT loglevel. It should only be * used when continuing a log message with no newline ('\n') enclosed. Otherwise * it defaults back to KERN_DEFAULT loglevel. */ #define pr_cont(fmt, ...) \ printk(KERN_CONT fmt, ##__VA_ARGS__) /** * pr_devel - Print a debug-level message conditionally * @fmt: format string * @...: arguments for the format string * * This macro expands to a printk with KERN_DEBUG loglevel if DEBUG is * defined. Otherwise it does nothing. * * It uses pr_fmt() to generate the format string. */ #ifdef DEBUG #define pr_devel(fmt, ...) \ printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) #else #define pr_devel(fmt, ...) \ no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) #endif /* If you are writing a driver, please use dev_dbg instead */ #if defined(CONFIG_DYNAMIC_DEBUG) || \ (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE)) #include <linux/dynamic_debug.h> /** * pr_debug - Print a debug-level message conditionally * @fmt: format string * @...: arguments for the format string * * This macro expands to dynamic_pr_debug() if CONFIG_DYNAMIC_DEBUG is * set. Otherwise, if DEBUG is defined, it's equivalent to a printk with * KERN_DEBUG loglevel. If DEBUG is not defined it does nothing. * * It uses pr_fmt() to generate the format string (dynamic_pr_debug() uses * pr_fmt() internally). */ #define pr_debug(fmt, ...) \ dynamic_pr_debug(fmt, ##__VA_ARGS__) #elif defined(DEBUG) #define pr_debug(fmt, ...) \ printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) #else #define pr_debug(fmt, ...) \ no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) #endif /* * Print a one-time message (analogous to WARN_ONCE() et al): */ #ifdef CONFIG_PRINTK #define printk_once(fmt, ...) \ ({ \ static bool __section(".data.once") __print_once; \ bool __ret_print_once = !__print_once; \ \ if (!__print_once) { \ __print_once = true; \ printk(fmt, ##__VA_ARGS__); \ } \ unlikely(__ret_print_once); \ }) #define printk_deferred_once(fmt, ...) \ ({ \ static bool __section(".data.once") __print_once; \ bool __ret_print_once = !__print_once; \ \ if (!__print_once) { \ __print_once = true; \ printk_deferred(fmt, ##__VA_ARGS__); \ } \ unlikely(__ret_print_once); \ }) #else #define printk_once(fmt, ...) \ no_printk(fmt, ##__VA_ARGS__) #define printk_deferred_once(fmt, ...) \ no_printk(fmt, ##__VA_ARGS__) #endif #define pr_emerg_once(fmt, ...) \ printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__) #define pr_alert_once(fmt, ...) \ printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__) #define pr_crit_once(fmt, ...) \ printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__) #define pr_err_once(fmt, ...) \ printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) #define pr_warn_once(fmt, ...) \ printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) #define pr_notice_once(fmt, ...) \ printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) #define pr_info_once(fmt, ...) \ printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) /* no pr_cont_once, don't do that... */ #if defined(DEBUG) #define pr_devel_once(fmt, ...) \ printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) #else #define pr_devel_once(fmt, ...) \ no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) #endif /* If you are writing a driver, please use dev_dbg instead */ #if defined(DEBUG) #define pr_debug_once(fmt, ...) \ printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) #else #define pr_debug_once(fmt, ...) \ no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) #endif /* * ratelimited messages with local ratelimit_state, * no local ratelimit_state used in the !PRINTK case */ #ifdef CONFIG_PRINTK #define printk_ratelimited(fmt, ...) \ ({ \ static DEFINE_RATELIMIT_STATE(_rs, \ DEFAULT_RATELIMIT_INTERVAL, \ DEFAULT_RATELIMIT_BURST); \ \ if (__ratelimit(&_rs)) \ printk(fmt, ##__VA_ARGS__); \ }) #else #define printk_ratelimited(fmt, ...) \ no_printk(fmt, ##__VA_ARGS__) #endif #define pr_emerg_ratelimited(fmt, ...) \ printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__) #define pr_alert_ratelimited(fmt, ...) \ printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__) #define pr_crit_ratelimited(fmt, ...) \ printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__) #define pr_err_ratelimited(fmt, ...) \ printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) #define pr_warn_ratelimited(fmt, ...) \ printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) #define pr_notice_ratelimited(fmt, ...) \ printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) #define pr_info_ratelimited(fmt, ...) \ printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) /* no pr_cont_ratelimited, don't do that... */ #if defined(DEBUG) #define pr_devel_ratelimited(fmt, ...) \ printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) #else #define pr_devel_ratelimited(fmt, ...) \ no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) #endif /* If you are writing a driver, please use dev_dbg instead */ #if defined(CONFIG_DYNAMIC_DEBUG) || \ (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE)) /* descriptor check is first to prevent flooding with "callbacks suppressed" */ #define pr_debug_ratelimited(fmt, ...) \ do { \ static DEFINE_RATELIMIT_STATE(_rs, \ DEFAULT_RATELIMIT_INTERVAL, \ DEFAULT_RATELIMIT_BURST); \ DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, pr_fmt(fmt)); \ if (DYNAMIC_DEBUG_BRANCH(descriptor) && \ __ratelimit(&_rs)) \ __dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__); \ } while (0) #elif defined(DEBUG) #define pr_debug_ratelimited(fmt, ...) \ printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) #else #define pr_debug_ratelimited(fmt, ...) \ no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) #endif extern const struct file_operations kmsg_fops; enum { DUMP_PREFIX_NONE, DUMP_PREFIX_ADDRESS, DUMP_PREFIX_OFFSET }; extern int hex_dump_to_buffer(const void *buf, size_t len, int rowsize, int groupsize, char *linebuf, size_t linebuflen, bool ascii); #ifdef CONFIG_PRINTK extern void print_hex_dump(const char *level, const char *prefix_str, int prefix_type, int rowsize, int groupsize, const void *buf, size_t len, bool ascii); #else static inline void print_hex_dump(const char *level, const char *prefix_str, int prefix_type, int rowsize, int groupsize, const void *buf, size_t len, bool ascii) { } static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type, const void *buf, size_t len) { } #endif #if defined(CONFIG_DYNAMIC_DEBUG) || \ (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE)) #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \ groupsize, buf, len, ascii) \ dynamic_hex_dump(prefix_str, prefix_type, rowsize, \ groupsize, buf, len, ascii) #elif defined(DEBUG) #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \ groupsize, buf, len, ascii) \ print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize, \ groupsize, buf, len, ascii) #else static inline void print_hex_dump_debug(const char *prefix_str, int prefix_type, int rowsize, int groupsize, const void *buf, size_t len, bool ascii) { } #endif /** * print_hex_dump_bytes - shorthand form of print_hex_dump() with default params * @prefix_str: string to prefix each line with; * caller supplies trailing spaces for alignment if desired * @prefix_type: controls whether prefix of an offset, address, or none * is printed (%DUMP_PREFIX_OFFSET, %DUMP_PREFIX_ADDRESS, %DUMP_PREFIX_NONE) * @buf: data blob to dump * @len: number of bytes in the @buf * * Calls print_hex_dump(), with log level of KERN_DEBUG, * rowsize of 16, groupsize of 1, and ASCII output included. */ #define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \ print_hex_dump_debug(prefix_str, prefix_type, 16, 1, buf, len, true) #endif
10-15
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值