内核在 initramfs 映像中找不到 init

内核在 initramfs 映像中找不到 init

我正在尝试让我的嵌入式系统运行 initramfs。现在这个 initramfs 中的“init”什么也不做,只是回显一条消息来测试它是否正在运行。

我的初始化脚本:

#!/bin/sh
echo "HELLO INITRAMFS"

我的 initramfs cpio 文件包含静态链接的 busybox。 “init”位于文件系统中的/init。我首先创建 cpio 存档,然后将其转换为 u-boot。

(find initramfs-test |cpio -o -H newc --quiet) > initramfs.cpio
mkimage -A arm -a 80008000 -e 80008000 -T ramdisk -C none -n uInitrd -d initramfs.cpio ./uInitrd

将这个 uInitrd 文件与我的内核一起放置在 SD 卡上的 fat 分区中并启动到 u-boot 提示符,我将这两个文件加载到内存中,设置我的 bootargs 并启动。

RIM-U-Boot# fatload mmc 0 0x81000000 uImage
reading uImage
4024775 bytes read in 415 ms (9.2 MiB/s)
RIM-U-Boot# fatload mmc 0 0x85000000 uInitrd
reading uInitrd
1410112 bytes read in 148 ms (9.1 MiB/s)
RIM-U-Boot# setenv bootargs console=${console} root=/dev/ram0 rootfstype=ramfs initrd=0x85000000
RIM-U-Boot# bootm 0x81000000 0x85000000
## Booting kernel from Legacy Image at 81000000 ...
   Image Name:   Linux 4.1 + Devicetree
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    4024711 Bytes = 3.8 MiB
   Load Address: 80008000
   Entry Point:  80008000
   Verifying Checksum ... OK
## Loading init Ramdisk from Legacy Image at 85000000 ...
   Image Name:   uInitrd
   Image Type:   ARM Linux RAMDisk Image (uncompressed)
   Data Size:    1410048 Bytes = 1.3 MiB
   Load Address: 80008000
   Entry Point:  80008000
   Verifying Checksum ... OK
   Loading Kernel Image ... OK
OK

Starting kernel ...

[    0.000000] Booting Linux on physical CPU 0x0
[    0.000000] Initializing cgroup subsys cpuset
[    0.000000] Initializing cgroup subsys cpu
[    0.000000] Initializing cgroup subsys cpuacct
[    0.000000] Linux version 4.1.18-ts-armv7l-crown-1.0 (mjohn@vbox) (gcc version 4.8.3 (Timesys 20161024) ) #1 SMP Tue Nov 13 16:40:10 EST 2018
[    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] Machine model: Crown RIM
[    0.000000] cma: Reserved 16 MiB at 0x86800000
[    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] PERCPU: Embedded 13 pages/cpu @c7c77000 s23296 r8192 d21760 u53248
[    0.000000] Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 31968
[    0.000000] Kernel command line: console=ttyO3,115200n8 root=/dev/ram0 rootfstype=ramfs initrd=0x85000000
[    0.000000] PID hash table entries: 512 (order: -1, 2048 bytes)
[    0.000000] Dentry cache hash table entries: 16384 (order: 4, 65536 bytes)
[    0.000000] Inode-cache hash table entries: 8192 (order: 3, 32768 bytes)
[    0.000000] Memory: 91580K/129024K available (7192K kernel code, 871K rwdata, 2580K rodata, 464K init, 8225K bss, 21060K reserved, 16384K 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 : 0xc8800000 - 0xff000000   ( 872 MB)
[    0.000000]     lowmem  : 0xc0000000 - 0xc8000000   ( 128 MB)
[    0.000000]     pkmap   : 0xbfe00000 - 0xc0000000   (   2 MB)
[    0.000000]     modules : 0xbf000000 - 0xbfe00000   (  14 MB)
[    0.000000]       .text : 0xc0008000 - 0xc09935f0   (9774 kB)
[    0.000000]       .init : 0xc0994000 - 0xc0a08000   ( 464 kB)
[    0.000000]       .data : 0xc0a08000 - 0xc0ae1fd0   ( 872 kB)
[    0.000000]        .bss : 0xc0ae4000 - 0xc12ec688   (8226 kB)
[    0.000000] Running RCU self tests
[    0.000000] Hierarchical RCU implementation.
[    0.000000]  RCU lockdep checking is enabled.
[    0.000000]  Additional per-CPU info printed with stalls.
[    0.000000]  RCU restricting CPUs from NR_CPUS=2 to nr_cpu_ids=1.
[    0.000000] RCU: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=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.000021] sched_clock: 32 bits at 24MHz, resolution 41ns, wraps every 89478484971ns
[    0.000052] clocksource timer1: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 79635851949 ns
[    0.000118] OMAP clocksource: timer1 at 24000000 Hz
[    0.001261] Console: colour dummy device 80x30
[    0.001339] Lock dependency validator: Copyright (c) 2006 Red Hat, Inc., Ingo Molnar
[    0.001352] ... MAX_LOCKDEP_SUBCLASSES:  8
[    0.001363] ... MAX_LOCK_DEPTH:          48
[    0.001373] ... MAX_LOCKDEP_KEYS:        8191
[    0.001384] ... CLASSHASH_SIZE:          4096
[    0.001393] ... MAX_LOCKDEP_ENTRIES:     32768
[    0.001404] ... MAX_LOCKDEP_CHAINS:      65536
[    0.001414] ... CHAINHASH_SIZE:          32768
[    0.001424]  memory used by lock dependency info: 5167 kB
[    0.001435]  per task-struct memory footprint: 1152 bytes
[    0.001466] Calibrating delay loop... 718.02 BogoMIPS (lpj=3590144)
[    0.108307] pid_max: default: 32768 minimum: 301
[    0.108753] Security Framework initialized
[    0.109015] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.109041] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.113214] Initializing cgroup subsys blkio
[    0.113271] Initializing cgroup subsys memory
[    0.113392] Initializing cgroup subsys devices
[    0.113510] Initializing cgroup subsys freezer
[    0.113689] Initializing cgroup subsys perf_event
[    0.113771] CPU: Testing write buffer coherency: ok
[    0.115776] CPU0: thread -1, cpu 0, socket -1, mpidr 0
[    0.115920] Setting up static identity map for 0x80008280 - 0x800082f0
[    0.126396] Brought up 1 CPUs
[    0.126434] SMP: Total of 1 processors activated (718.02 BogoMIPS).
[    0.126448] CPU: All CPU(s) started in SVC mode.
[    0.131751] devtmpfs: initialized
[    0.178685] VFP support v0.3: implementor 41 architecture 3 part 30 variant c rev 3
[    0.251639] omap_hwmod: debugss: _wait_target_disable failed
[    0.308946] clocksource jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.312216] pinctrl core: initialized pinctrl subsystem
[    0.319501] NET: Registered protocol family 16
[    0.327296] DMA: preallocated 256 KiB pool for atomic coherent allocations
[    0.330401] cpuidle: using governor ladder
[    0.330444] cpuidle: using governor menu
[    0.347621] OMAP GPIO hardware version 0.1
[    0.379407] omap-gpmc 50000000.gpmc: could not find pctldev for node /ocp/l4_wkup@44c00000/scm@210000/pinmux@800/pinmux_nandflash_pins, deferring probe
[    0.384981] No ATAGs?
[    0.385022] hw-breakpoint: debug architecture 0x4 unsupported.
[    0.385802] omap4_sram_init:Unable to allocate sram needed to handle errata I688
[    0.385826] omap4_sram_init:Unable to get sram pool needed to handle errata I688
[    0.446811] edma 49000000.edma: TI EDMA DMA engine driver
[    0.449438] reg-fixed-voltage fixedregulator@1: could not find pctldev for node /ocp/l4_wkup@44c00000/scm@210000/pinmux@800/pinmux_wl12xx_gpio, deferring probe
[    0.453649] SCSI subsystem initialized
[    0.455728] usbcore: registered new interface driver usbfs
[    0.455982] usbcore: registered new interface driver hub
[    0.456188] usbcore: registered new device driver usb
[    0.479540] tps65910 0-002d: No interrupt support, no core IRQ
[    0.614304] omap_i2c 44e0b000.i2c: bus 0 rev0.11 at 100 kHz
[    0.615013] pps_core: LinuxPPS API ver. 1 registered
[    0.615032] pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <[email protected]>
[    0.615109] PTP clock support registered
[    0.620004] Bluetooth: Core ver 2.20
[    0.620170] NET: Registered protocol family 31
[    0.620185] Bluetooth: HCI device and connection manager initialized
[    0.620332] Bluetooth: HCI socket layer initialized
[    0.620370] Bluetooth: L2CAP socket layer initialized
[    0.620592] Bluetooth: SCO socket layer initialized
[    0.624095] Switched to clocksource timer1
[    0.820693] NET: Registered protocol family 2
[    0.823356] TCP established hash table entries: 1024 (order: 0, 4096 bytes)
[    0.823542] TCP bind hash table entries: 1024 (order: 3, 36864 bytes)
[    0.824172] TCP: Hash tables configured (established 1024 bind 1024)
[    0.824497] UDP hash table entries: 256 (order: 2, 20480 bytes)
[    0.824757] UDP-Lite hash table entries: 256 (order: 2, 20480 bytes)
[    0.825968] NET: Registered protocol family 1
[    0.828351] RPC: Registered named UNIX socket transport module.
[    0.828381] RPC: Registered udp transport module.
[    0.828394] RPC: Registered tcp transport module.
[    0.828407] RPC: Registered tcp NFSv4.1 backchannel transport module.
[    0.831337] CPU PMU: Failed to parse /pmu/interrupt-affinity[0]
[    0.831463] hw perfevents: enabled with armv7_cortex_a8 PMU driver, 5 counters available
[    0.838002] futex hash table entries: 256 (order: 2, 16384 bytes)
[    0.838313] audit: initializing netlink subsys (disabled)
[    0.838639] audit: type=2000 audit(0.830:1): initialized
[    0.845262] VFS: Disk quotas dquot_6.6.0
[    0.845456] VFS: Dquot-cache hash table entries: 1024 (order 0, 4096 bytes)
[    0.847891] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[    0.849171] NFS: Registering the id_resolver key type
[    0.849744] Key type id_resolver registered
[    0.849764] Key type id_legacy registered
[    0.860204] io scheduler noop registered
[    0.860252] io scheduler deadline registered
[    0.860327] io scheduler cfq registered (default)
[    0.863209] pinctrl-single 44e10800.pinmux: 142 pins at pa f9e10800 size 568
[    0.867560] Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled
[    0.876098] omap_uart 44e09000.serial: no wakeirq for uart0
[    0.877001] 44e09000.serial: ttyO0 at MMIO 0x44e09000 (irq = 158, base_baud = 3000000) is a OMAP UART0
[    0.879864] omap_uart 48022000.serial: no wakeirq for uart1
[    0.880322] 48022000.serial: ttyO1 at MMIO 0x48022000 (irq = 159, base_baud = 3000000) is a OMAP UART1
[    0.882065] omap_uart 481a6000.serial: no wakeirq for uart3
[    0.882510] 481a6000.serial: ttyO3 at MMIO 0x481a6000 (irq = 160, base_baud = 3000000) is a OMAP UART3
[    1.699898] console [ttyO3] enabled
[    1.705757] omap_uart 481aa000.serial: no wakeirq for uart5
[    1.712068] 481aa000.serial: ttyO5 at MMIO 0x481aa000 (irq = 161, base_baud = 3000000) is a OMAP UART5
[    1.760738] brd: module loaded
[    1.785830] loop: module loaded
[    1.789963] (stk) :sysfs entries created
[    1.800178] mtdoops: mtd device (mtddev=name/number) must be supplied
[    1.874092] davinci_mdio 4a101000.mdio: davinci mdio revision 1.6
[    1.880499] davinci_mdio 4a101000.mdio: detected phy mask fffffff5
[    1.894287] libphy: 4a101000.mdio: probed
[    1.898524] davinci_mdio 4a101000.mdio: phy[1]: device 4a101000.mdio:01, driver unknown
[    1.906962] davinci_mdio 4a101000.mdio: phy[3]: device 4a101000.mdio:03, driver unknown
[    1.917029] cpsw 4a100000.ethernet: Detected MACID = d0:ff:50:ab:2d:b7
[    1.927796] PPP generic driver version 2.4.2
[    1.933714] PPP BSD Compression module registered
[    1.938845] PPP Deflate Compression module registered
[    1.945366] usbcore: registered new interface driver cdc_acm
[    1.951296] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
[    1.959997] usbcore: registered new interface driver usb-storage
[    1.970707] 47401300.usb-phy supply vcc not found, using dummy regulator
[    1.983582] musb-hdrc musb-hdrc.0.auto: Failed to request rx1.
[    1.990461] musb-hdrc musb-hdrc.0.auto: musb_init_controller failed with status -517
[    2.000788] 47401b00.usb-phy supply vcc not found, using dummy regulator
[    2.012019] musb-hdrc musb-hdrc.1.auto: Failed to request rx1.
[    2.018436] musb-hdrc musb-hdrc.1.auto: musb_init_controller failed with status -517
[    2.055667] mousedev: PS/2 mouse device common for all mice
[    2.062865] i2c /dev entries driver
[    2.072753] omap_wdt: OMAP Watchdog Timer Rev 0x01: initial timeout 60 sec
[    2.082969] omap_hsmmc 48060000.mmc: Got CD GPIO
[    2.089408] vmmc: supplied by vbat
[    2.139221] ledtrig-cpu: registered to indicate activity on CPUs
[    2.147462] oprofile: using arm/armv7
[    2.151464] Netfilter messages via NETLINK v0.30.
[    2.157069] nf_conntrack version 0.5.0 (1686 buckets, 6744 max)
[    2.164144] ctnetlink v0.93: registering with nfnetlink.
[    2.170652] ipip: IPv4 over IPv4 tunneling driver
[    2.179323] ip_tables: (C) 2000-2006 Netfilter Core Team
[    2.185436] arp_tables: (C) 2002 David S. Miller
[    2.190642] Initializing XFRM netlink socket
[    2.195447] NET: Registered protocol family 17
[    2.200200] NET: Registered protocol family 15
[    2.207048] Bluetooth: RFCOMM TTY layer initialized
[    2.212284] Bluetooth: RFCOMM socket layer initialized
[    2.217831] Bluetooth: RFCOMM ver 1.11
[    2.221818] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
[    2.227427] Bluetooth: BNEP filters: protocol multicast
[    2.232927] Bluetooth: BNEP socket layer initialized
[    2.238179] Bluetooth: HIDP (Human Interface Emulation) ver 1.2
[    2.244432] Bluetooth: HIDP socket layer initialized
[    2.249798] BT WLAN Gpio value is :10
[    2.254432] WD Enable Gpio value is :114
[    2.258976] WD Tick Gpio value is :115
[    2.263340] BT_WLAN Gpio value is :10
[    2.267239] WL1271: BT/WLAN Enable
[    2.284032] Voltage translator init complete
[    2.302427] mmc0: host does not support reading read-only switch, assuming write-enable
[    2.310942] WD: Enable
[    2.313464] WD: TICK
[    2.317180] Key type dns_resolver registered
[    2.322818] omap_voltage_late_init: Voltage driver support not added
[    2.329621] sr_dev_init: No voltage domain specified for smartreflex0. Cannot initialize
[    2.338138] sr_dev_init: No voltage domain specified for smartreflex1. Cannot initialize
[    2.348688] ThumbEE CPU extension supported.
[    2.353214] Registering SWP/SWPB emulation handler
[    2.358356] SmartReflex Class3 initialized
[    2.364460] mmc0: new high speed SDHC card at address 0001
[    2.373404] mmcblk0: mmc0:0001 SD32G 29.3 GiB
[    2.384627]  mmcblk0: p1 p2
[    2.399807] omap-gpmc 50000000.gpmc: GPMC revision 6.0
[    2.405715] gpmc_mem_init: disabling cs 0 mapped at 0x0-0x1000000
[    2.416508] nand: device found, Manufacturer ID: 0x01, Chip ID: 0xf1
[    2.423165] nand: AMD/Spansion S34ML01G2
[    2.427383] nand: 128 MiB, SLC, erase size: 128 KiB, page size: 2048, OOB size: 64
[    2.435458] nand: using OMAP_ECC_BCH4_CODE_HW ECC scheme
[    2.441305] 8 ofpart partitions found on MTD device 8000000.nand
[    2.447640] Creating 8 MTD partitions on "8000000.nand":
[    2.453212] 0x000000000000-0x000000020000 : "SPL"
[    2.467798] 0x000000020000-0x000000040000 : "SPL.backup1"
[    2.478062] 0x000000040000-0x000000060000 : "SPL.backup2"
[    2.488203] 0x000000060000-0x000000080000 : "SPL.backup3"
[    2.498676] 0x000000080000-0x000000260000 : "U-Boot"
[    2.508970] 0x000000260000-0x000000280000 : "U-Boot Env"
[    2.518872] 0x000000280000-0x000000780000 : "Kernel"
[    2.531256] 0x000000780000-0x000008000000 : "File System"
[    2.610135] musb-hdrc musb-hdrc.0.auto: MUSB HDRC host driver
[    2.617210] musb-hdrc musb-hdrc.0.auto: new USB bus registered, assigned bus number 1
[    2.628376] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002
[    2.635588] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    2.643149] usb usb1: Product: MUSB HDRC host driver
[    2.648380] usb usb1: Manufacturer: Linux 4.1.18-ts-armv7l-crown-1.0 musb-hcd
[    2.655881] usb usb1: SerialNumber: musb-hdrc.0.auto
[    2.667430] hub 1-0:1.0: USB hub found
[    2.672216] hub 1-0:1.0: 1 port detected
[    2.692454] musb-hdrc musb-hdrc.1.auto: MUSB HDRC host driver
[    2.698661] musb-hdrc musb-hdrc.1.auto: new USB bus registered, assigned bus number 2
[    2.708020] usb usb2: New USB device found, idVendor=1d6b, idProduct=0002
[    2.715198] usb usb2: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    2.722758] usb usb2: Product: MUSB HDRC host driver
[    2.727986] usb usb2: Manufacturer: Linux 4.1.18-ts-armv7l-crown-1.0 musb-hcd
[    2.735499] usb usb2: SerialNumber: musb-hdrc.1.auto
[    2.743553] hub 2-0:1.0: USB hub found
[    2.747851] hub 2-0:1.0: 1 port detected
[    2.877465] hctosys: unable to open rtc device (rtc0)
[    2.882786] sr_init: No PMIC hook to init smartreflex
[    2.888543] sr_init: platform driver register failed for SR
[    2.930249] VFS: Mounted root (ramfs filesystem) readonly on device 0:15.
[    2.937980] devtmpfs: error mounting -2
[    2.943047] Freeing unused kernel memory: 464K (c0994000 - c0a08000)
[    2.950460] Kernel panic - not syncing: No working init found.  Try passing init= option to kernel. See Linux Documentation/init.txt for guidance.
[    2.964386] ---[ end Kernel panic - not syncing: No working init found.  Try passing init= option to kernel. See Linux Documentation/init.txt for guidance.
[   79.333959] random: nonblocking pool is initialized

正如你所看到的,内核在 initramfs 中找不到 init。知道为什么吗?内核是4.1.18,u-boot是2013.09。

谢谢

编辑: 回复jc__问题:

1. 不,设备树中没有内核切换

2.我尝试过设置initrd=/dev/ram0,但出现同样的错误。我还尝试将 init 指定为init=/init并看到以下错误:

[    2.953050] Freeing unused kernel memory: 464K (c0994000 - c0a08000)
[    2.960261] Kernel panic - not syncing: Requested init /init failed (error -2).
[    2.968092] ---[ end Kernel panic - not syncing: Requested init /init failed (error -2).

3. 我正在使用 cpio 文件,即 initramfs,但我尝试单独加载它(不是内核映像的一部分),并且我不确定 initramfs 是否可以这样工作。我发现的东西听起来好像这是可能的。我的 initramfs.cpio 文件系统包含一个/dev.这些模块目前已内置到内核中。

4. 我没有在内核映像中包含 initramfs,因此它应该只包含默认值。

CONFIG_BLK_DEV_INITRD=y
CONFIG_INITRAMFS_SOURCE=""
CONFIG_BLK_DEV_RAM=y
CONFIG_BLK_DEV_RAM_COUNT=16
CONFIG_BLK_DEV_RAM_SIZE=16384

5. 我可以将它包含在我的内核中,但这需要额外的工作。内核是由 Timesys Factory 构建系统构建的,initramfs.cpio 是稍后构建的。

回复 源杰迪

我尝试将其更改为:

# setenv bootargs console=${console} root=/dev/ram0 init=/init

并得到:

[    2.882766] sr_init: No PMIC hook to init smartreflex
[    2.888519] sr_init: platform driver register failed for SR
[    2.930847] omap_hsmmc 481d8000.mmc: card claims to support voltages below defined range
[    2.946830] List of all partitions:
[    2.950696] 0100           16384 ram0  (driver?)
[    2.955763] 0101           16384 ram1  (driver?)
[    2.960639] 0102           16384 ram2  (driver?)
[    2.965564] 0103           16384 ram3  (driver?)
[    2.970442] 0104           16384 ram4  (driver?)
[    2.975364] 0105           16384 ram5  (driver?)
[    2.980239] 0106           16384 ram6  (driver?)
[    2.985153] 0107           16384 ram7  (driver?)
[    2.990029] 0108           16384 ram8  (driver?)
[    2.994937] 0109           16384 ram9  (driver?)
[    2.999791] 010a           16384 ram10  (driver?)
[    3.004781] 010b           16384 ram11  (driver?)
[    3.009725] 010c           16384 ram12  (driver?)
[    3.014700] 010d           16384 ram13  (driver?)
[    3.019642] 010e           16384 ram14  (driver?)
[    3.024616] 010f           16384 ram15  (driver?)
[    3.029577] b300        30707712 mmcblk0  driver: mmcblk
[    3.035191]   b301            9216 mmcblk0p1 00011b5e-01
[    3.040769]   b302          440320 mmcblk0p2 00011b5e-02
[    3.046421] 1f00             128 mtdblock0  (driver?)
[    3.051727] 1f01             128 mtdblock1  (driver?)
[    3.057074] 1f02             128 mtdblock2  (driver?)
[    3.062380] 1f03             128 mtdblock3  (driver?)
[    3.067723] 1f04            1920 mtdblock4  (driver?)
[    3.073030] 1f05             128 mtdblock5  (driver?)
[    3.078369] 1f06            5120 mtdblock6  (driver?)
[    3.083676] 1f07          123392 mtdblock7  (driver?)
[    3.089006] No filesystem could mount root, tried:  ext3 ext2 ext4 cramfs squashfs vfat msdos
[    3.098220] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(1,0)
[    3.107068] ---[ end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(1,0)

如果我将其更改为同样的情况:

# setenv bootargs console=${console} root=/dev/ram0 initrd=/dev/ram0 init=/init

编辑2:

尝试过:

# setenv bootargs console=${console} root=/dev/ram0 initrd=0x85000000,2M

并看到同样的错误,除了我现在得到

[    2.978095] RAMDISK: Couldn't find valid RAM disk image starting at 0.
[    2.992086] List of all partitions:
[    2.996226] 0100           16384 ram0  (driver?)
[    3.001097] 0101           16384 ram1  (driver?)
[    3.006041] 0102           16384 ram2  (driver?)
[    3.010895] 0103           16384 ram3  (driver?)

似乎内核没有在 处看到 initramfs /dev/ram0。这可能是错误的。当 u-boot 将 uImage 和 uInitrd 加载到内存时,如何/dev/ram0与该地址 0x85000000 绑定?

编辑3:

我已经在内核中构建了 initramfs.cpio,并且可以看到回显消息。所以我的 initramfs 是有效的,只是不确定我在尝试从外部加载它时出了什么问题。

答案1

需要研究的一些项目:

1:

## Booting kernel from Legacy Image at 81000000 ...
   Image Name:   Linux 4.1 + Devicetree

设备树是否包含可能与设备冲突的内核开关setenv bootargs console=${console} root=/dev/ram0 rootfstype=ramfs initrd=0x85000000

2:

setenv bootargs console=${console} root=/dev/ram0 rootfstype=ramfs initrd=0x85000000

内核是否需要 initrd=0x850000000 的内存地址,或者只需要 dev/ram0 位置。

3:

您使用的是 initramfs 还是 initrd?你自己编译内核吗?内核映像是否已包含 initramfs?

检查内核配置中的这些:

CONFIG_BLK_DEV_INITRD

CONFIG_INITRAMFS_SOURC

[ 0.131751] devtmpfs: initialized

[ 2.937980] devtmpfs: error mounting -2

看起来 devtmpfs 几乎被安装了两次。第一次安装它时是什么(内置于 initramfs 中)? 同意@sourcejedi 的评论。不/dev,因为没有 rootfs。

内核也正在初始化硬件。蓝牙、USB、MMC 等。除非这些模块被编译到内核中并且没有加载模块,否则它们是从某个地方加载的。 (内置 initramfs)?

4:

如果您使用 initrd 而不是 initramfs,并且内核映像不包含内置 initramfs...

我认为内核配置需要:

BLK_DEV_RAM

“如果使用的话,现代内核使用 /dev/ram0 作为 initrd。”

./linux-4.x.x/Documentation/blockdev/ramdisk.txt

难道不是initrd=/dev/ram0initrd=0x85000000

“旧的 initrd 始终是一个单独的文件,而 initramfs 存档链接到 Linux 内核映像中。”

./linux-4.x.x/Documentation/filesystems/ramfs-rootfs-initramfs.txtramfs-rootfs-initramfs.txt

“旧 initrd(称为 /initrd,而不是 /init)运行的程序做了一些设置,然后返回到内核......”

./linux-4.x.x/Documentation/filesystems/ramfs-rootfs-initramfs.txtramfs-rootfs-initramfs.txt

init 应该/initrd代替 吗/init

5:

如果您编译自己的内核,那么让内核 make 进程将 initramfs 合并到内核映像中可以节省您的大量工作。

CONFIG_BLK_DEV_INITRD

CONFIG_INITRAMFS_SOURCE

答案2

你不想要rootfstype=ramfs。我确信。尽管 AFAICT 这并不是真正的问题。

安装ramfs忽略块设备(root=/dev/ram0在本例中)。 ramfs不受任何设备文件支持。它最初是空的。

因此如果rootfstype=ramfs生效的话,只是挂载一个空的fs。因此就没有init程序可以运行。 (当内核尝试在 上挂载 devtmpfs 时/dev,它还会生成错误 2 = ENOENT =“No such file or directory”,与您在日志中看到的相同)。


您表明您正在使用新型 initramfs,即 cpio 存档而不是文件系统映像。这很好。但是当内核检测到新格式并将其解压时,您应该会收到类似“Unpacking initramfs...”的消息。

原始文档说 initramfs 应该是 gzipped cpio。不过我认为当前的代码也对未压缩的 cpio 感到满意。

正如您所说,您似乎遇到了内核无法识别 initramfs 的问题。

至少,在进入时initrd_start看起来是这样。如果它非零,您将至少看到一条与 initrd 或 initramfs 相关的消息或错误。0populate_rootfs()

https://elixir.bootlin.com/linux/v4.1/source/init/initramfs.c#L608

或者,initramfs.c甚至没有包含在内核中,因为您还没有启用 CONFIG_BLK_DEV_INITRD。这是什么初始化/生成文件告诉我。

初始化:https://www.kernel.org/doc/html/v4.18/admin-guide/initrd.html

初始化内存文件系统:https://www.kernel.org/doc/Documentation/filesystems/ramfs-rootfs-initramfs.txt

答案3

RIM-U-Boot# bootm 0x81000000 0x85000000
## Booting kernel from Legacy Image at 81000000 ...
   Image Name:   Linux 4.1 + Devicetree
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    4024711 Bytes = 3.8 MiB
   Load Address: 80008000
   Entry Point:  80008000
   Verifying Checksum ... OK
## Loading init Ramdisk from Legacy Image at 85000000 ...
   Image Name:   uInitrd
   Image Type:   ARM Linux RAMDisk Image (uncompressed)
   Data Size:    1410048 Bytes = 1.3 MiB
   Load Address: 80008000
   Entry Point:  80008000
   Verifying Checksum ... OK
   Loading Kernel Image ... OK
OK

这里看起来有些不对劲。内核的加载地址不应与 initrd 的加载地址重叠!

如需比较,请参见https://community.nxp.com/thread/305045#comment-322873

使用加载地址重新创建 uInitrd 0x80408000

我不知道你的硬件。此处建议的分配不应相互冲突 AFAICT,希望它们不会与任何内容冲突别的:-)。

不要使用内核启动选项rootfsype=ramfsroot=/dev/ram0.我认为它们不应该影响你的问题任何你将它们设置为。但他们错了,所以让我们不要分心。您不需要其中任何一个来启动 initramfs。 (我的计算机使用 initramfs 启动 Linux,并且不使用这些启动选项中的任何一个!)

您应该不需要使用initrd=...,因为您将地址作为第二个选项传递给bootm. (但考虑到上述情况,正确的值是initrd=0x80408000,2M,所以不要传递任何不同的地址!)。

答案4

使用 initrd 时涉及两个“init”:

rdinit=/初始化初始化=/sbin/init (默认值)

第一个 (rdinit=) 告诉早期用户空间在内核解压并安装 initrd 后要运行什么。默认为/init。

如果没有 initrd,第二个 (init=) 告诉内核要运行哪个 init (就像 root= 告诉内核将哪个设备挂载为 /)

有了 initrd,init= 被 switchroot 在早期用户空间的末尾使用,不仅可以挂载新的、真正的 root,而且还可以运行真正的 /sbin/init - 或任何你想要的: init=/sbin/test_init

(/init 并不一定会导致 switchroot;你可以永远留在 initrd 中......嵌入式风格)

我完全同意 Charles 的观点,他是唯一提到 rdinit= 的人:

确保 initramfs 中有 /init 可执行文件。您可以通过 bootargs 中的 rdinit=/bin/sh 指定另一个 init 进程

rdinit=/init 和 init=/init 也必须是可能的,它们是不同的文件:第一个“/”表示 initrd(您的 cpio)的顶部,第二个“/”表示 root= 又名 newroot 的顶部。

相关内容