启动linux内核时打印不一致

Posted

技术标签:

【中文标题】启动linux内核时打印不一致【英文标题】:Print inconsistency when booting linux kernel 【发布时间】:2017-08-03 19:02:44 【问题描述】:

我正在尝试将内核 4.12 移植到我的主板上,但我遇到了一个非常奇怪的问题。

一些上下文:我使用 u-boot 作为引导加载程序,从具有设备树支持的 zImage 引导。该板有一个 Sitara AM3352。

发生的情况是有时内核会开始打印东西,但大多数情况下它什么都不做。

情况1:

U-Boot# bootz $kloadaddr - $fdtaddr
## Current stack ends at 0x83ee8bf8 Kernel image @ 0x80007fc0 [ 0x00000000 - 0x002d9430 ]
## Flattened Device Tree blob at 88000000
   Booting using the fdt blob at 0x88000000
using: FDT
using: FDT
   Loading Device Tree to 83edd000, end 83ee7337 ... OK
## Transferring control to Linux (at address 80007fc0)...

Starting kernel ...

情况2:

U-Boot# bootz $kloadaddr - $fdtaddr
## Current stack ends at 0x83ee8bf8 Kernel image @ 0x80007fc0 [ 0x00000000 - 0x002d9430 ]
## Flattened Device Tree blob at 88000000
   Booting using the fdt blob at 0x88000000
using: FDT
using: FDT
   Loading Device Tree to 83edd000, end 83ee7337 ... OK
## Transferring control to Linux (at address 80007fc0)...

Starting kernel ...

[    0.000000] Booting Linux on physical CPU 0x0
[    0.000000] Linux version 4.12.0R01-Beta (guilherme@epoch) (gcc version 4.9.3 (crosstool-NG crosstool-ng-1.22.0) ) #4 Thu Aug 3 14:30:16 BRT 2017
[    0.000000] CPU: ARMv7 Processor [413fc082] revision 2 (ARMv7), cr=10c5387d
[    0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
[    0.000000] OF: fdt: Machine model: Test Board
[    0.000000] earlycon: omapserial0 at MMIO 0x44e09000 (options '')
[    0.000000] bootconsole [omapserial0] enabled
[    0.000000] Memory policy: Data cache writeback
[    0.000000] CPU: All CPU(s) started in SVC mode.
[    0.000000] AM335X ES2.1 (neon)
[    0.000000] Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 16256
[    0.000000] Kernel command line: console=ttyO0,115200n8 root=/dev/mtdblock10 rw rootfstype=jffs2 noinitrd earlycon
[    0.000000] PID hash table entries: 256 (order: -2, 1024 bytes)
[    0.000000] Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
[    0.000000] Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)
[    0.000000] Memory: 56952K/65536K available (4096K kernel code, 179K rwdata, 1484K rodata, 1024K init, 438K bss, 8584K reserved, 0K cma-reserved, 0K highmem)
[    0.000000] Virtual kernel memory layout:
[    0.000000]     vector  : 0xffff0000 - 0xffff1000   (   4 kB)
[    0.000000]     fixmap  : 0xffc00000 - 0xfff00000   (3072 kB)
[    0.000000]     vmalloc : 0xc4800000 - 0xff800000   ( 944 MB)
[    0.000000]     lowmem  : 0xc0000000 - 0xc4000000   (  64 MB)
[    0.000000]     pkmap   : 0xbfe00000 - 0xc0000000   (   2 MB)
[    0.000000]     modules : 0xbf000000 - 0xbfe00000   (  14 MB)
[    0.000000]       .text : 0xc0008000 - 0xc0500000   (5088 kB)
[    0.000000]       .init : 0xc0700000 - 0xc0800000   (1024 kB)
[    0.000000]       .data : 0xc0800000 - 0xc082cd90   ( 180 kB)
[    0.000000]        .bss : 0xc0831794 - 0xc089f2c8   ( 439 kB)
[    0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[    0.000000] NR_IRQS:16 nr_irqs:16 16
[    0.000000] IRQ: Found an INTC at 0xfa200000 (revision 5.0) with 128 interrupts
[    0.000000] OMAP clockevent source: timer2 at 24000000 Hz
[    0.000020] sched_clock: 32 bits at 24MHz, resolution 41ns, wraps every 89478484971ns
[    0.008003] clocksource: timer1: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 79635851949 ns
[    0.017467] OMAP clocksource: timer1 at 24000000 Hz
[    0.022622] clocksource_probe: no matching clocksources found
[    0.028583] Calibrating delay loop... 599.04 BogoMIPS (lpj=1198080)
[    0.059960] pid_max: default: 32768 minimum: 301
[    0.064987] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.071729] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.079579] CPU: Testing write buffer coherency: ok
[    0.085216] Setting up static identity map for 0x80100000 - 0x80100060
[    0.095211] devtmpfs: initialized
[    0.107961] VFP support v0.3: implementor 41 architecture 3 part 30 variant c rev 3
[    0.116265] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 7645041785100000 ns
[    0.126579] futex hash table entries: 256 (order: -1, 3072 bytes)
[    0.132888] pinctrl core: initialized pinctrl subsystem
[    0.139759] NET: Registered protocol family 16
[    0.145433] DMA: preallocated 256 KiB pool for atomic coherent allocations
[    0.165036] omap_hwmod: debugss: _wait_target_disable failed
[    0.171060] Unhandled fault: external abort on non-linefetch (0x1028) at 0xf9e3e078
[    0.178849] pgd = c0004000
[    0.181618] [f9e3e078] *pgd=44e11452(bad)
[    0.185740] Internal error: : 1028 [#1] ARM
[    0.190019] Modules linked in:
[    0.193157] CPU: 0 PID: 1 Comm: swapper Not tainted 4.12.0R01-Beta #4
[    0.199760] Hardware name: Generic AM33XX (Flattened Device Tree)
[    0.206019] task: c3830000 task.stack: c382e000
[    0.210684] PC is at _update_sysc_cache+0x2c/0x94
[    0.215494] LR is at _enable+0x240/0x2a8
[    0.219517] pc : [<c0120b24>]    lr : [<c0121314>]    psr: 40000013
[    0.219517] sp : c382fe98  ip : c0124774  fp : 00000000
[    0.231311] r10: c0721838  r9 : 00000045  r8 : c08317c0
[    0.236673] r7 : c080abf0  r6 : 00000000  r5 : c0831c68  r4 : c080a5a4
[    0.243377] r3 : f9e3e078  r2 : c080b084  r1 : f9e3e000  r0 : c080a5a4
[    0.250083] Flags: nZcv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment none
[    0.257409] Control: 10c5387d  Table: 80004019  DAC: 00000051
[    0.263307] Process swapper (pid: 1, stack limit = 0xc382e210)
[    0.269296] Stack: (0xc382fe98 to 0xc3830000)
[    0.273768] fe80:                                                       00000000 c0121314
[    0.282173] fea0: 00000000 a0000013 c08092a8 c0803048 c080a5a4 c080a5d4 c080a5e8 c0709328
[    0.290574] fec0: c382fed4 d3053b52 c080ae5c d3053b52 c080a5a4 c0807808 c0709240 00000000
[    0.298975] fee0: c08317c0 c0121718 0000100c c0803048 00000002 c07099c8 00000000 c0709a6c
[    0.307377] ff00: 00000000 c0101794 00000154 c3ffed09 c0671b34 c0147200 000017c0 c0228d30
[    0.315777] ff20: c0803048 c05edd2c c07005dc 00000000 00000002 00000002 00000000 c0803048
[    0.324179] ff40: 00000000 c3ffed09 00000000 d3053b52 00000000 d3053b52 00000002 c072c0f8
[    0.332580] ff60: 00000002 c0721820 c08317c0 c08317c0 00000045 c0700dc8 00000002 00000002
[    0.340981] ff80: 00000000 c07005dc 00000000 c04a7cc0 00000000 00000000 00000000 00000000
[    0.349382] ffa0: 00000000 c04a7cc8 00000000 c010dd98 00000000 00000000 00000000 00000000
[    0.357783] ffc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[    0.366184] ffe0: 00000000 00000000 00000000 00000000 00000013 00000000 ffffffff fffffffb
[    0.374609] [<c0120b24>] (_update_sysc_cache) from [<c0121314>] (_enable+0x240/0x2a8)
[    0.382637] [<c0121314>] (_enable) from [<c0709328>] (_setup+0xe8/0x4e8)
[    0.389516] [<c0709328>] (_setup) from [<c0121718>] (omap_hwmod_for_each+0x38/0x60)
[    0.397378] [<c0121718>] (omap_hwmod_for_each) from [<c0709a6c>] (__omap_hwmod_setup_all+0xa4/0xac)
[    0.406676] [<c0709a6c>] (__omap_hwmod_setup_all) from [<c0101794>] (do_one_initcall+0x50/0x18c)
[    0.415708] [<c0101794>] (do_one_initcall) from [<c0700dc8>] (kernel_init_freeable+0x140/0x1dc)
[    0.424650] [<c0700dc8>] (kernel_init_freeable) from [<c04a7cc8>] (kernel_init+0x8/0x10c)
[    0.433052] [<c04a7cc8>] (kernel_init) from [<c010dd98>] (ret_from_fork+0x14/0x3c)
[    0.440815] Code: e3110c01 e5901054 e6f13073 1a00000c (e5933000)
[    0.447075] ---[ end trace 396cebd12b8145f9 ]---
[    0.451867] Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b
[    0.451867]
[    0.461190] ---[ end Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b
[    0.461190]
[    1.373583] random: fast init done

这是我的.dts 文件:

/dts-v1/;                                                                                               

#include "am33xx.dtsi"                                                                                  
#include <dt-bindings/interrupt-controller/irq.h>                                                       

/                                                                                                      
   model = "Test Board";                                                                             
   compatible = "guilherme,test_board", "ti,am33xx";                                                           

   memory@80000000                                                                                     
      device_type = "memory";                                                                           
      reg = <0x80000000 0x04000000>; /* 64 MB */                                                        
   ;                                                                                                   

   chosen                                                                                              
      stdout-path = &uart0;                                                                             
      bootargs ="console=ttyO0,115200n8 root=/dev/mtdblock10 rw rootfstype=jffs2 noinitrd earlycon";    
   ;

;

虽然我预计会遇到内核恐慌,但让我烦恼的是这种打印不一致。此外,我无法确定此问题是由于某些奇怪的 u-boot 配置还是与内核本身相关的原因造成的。

【问题讨论】:

你实际有多少内存?这是定制板吗?您是否更新了内存配置信息以知道您只有 dts 所说的 64MB? 是定制板,内存大小确实是64MB。 我可能想到了错误的内存设置和/或地址。 “打印不一致” 表示启动失败。您可以间歇性地看到内核执行初始化的事实意味着 U-Boot 和内核加载地址是可以的。间歇性启动失败确实使内存功能受到质疑。您是否在您的这块板上进行过广泛的内存测试? 首先,由于您只有 64MB,请检查您是否正确更新了内存初始化序列。其次,由于您只有 64MB,因此只有 0x80000000 和 0x84000000 之间的区域有效。您将设备树放置在 0x88000000 (距基础 +128MB)处,发现这意味着不,部分内存配置不正确,我认为它“镜像”了 0x80000000 处的内容。您可能需要检查使用的其他地址,因为一般假设是至少 256MB,而不是 64MB。 【参考方案1】:

所以,找出问题所在!当我使用之前配置的 u-Boot 时,我尝试将 u-Boot 修改保持在最低限度。在这些先前存在的配置中,有一个setenv bootargs = ...。这个bootargs 定义会覆盖.dtb 文件中的定义,从而导致冲突。一旦我删除了这个变量定义,打印问题就解决了。

系统看似随机打印的原因是因为bootargs 定义取决于用于从 SDCard 中的图像引导的引脚状态。

【讨论】:

以上是关于启动linux内核时打印不一致的主要内容,如果未能解决你的问题,请参考以下文章

Linux内核知识杂记

Linux系统启动过程的打印信息从何而来?

为啥打印不出linux内核调试信息

Linux内核的启动过程分析

linux内核打印数据到串口控制台,printk数据不打印问题

编译天嵌官方的linux-2.6.30.4内核下载到TQ2440开发板不断重启的解决办法