QEMU Linux Bash 初始化脚本未打印到控制台

问题描述 投票:0回答:2

我正在模拟 TI 的一块运行 ARM-Cortex A15 的板。该板使用 UART8250,默认 UART 编号为 3,地址为 0x48020000。我使用 U-boot 来启动 Linux 内核并运行 qemu:

qemu-system-arm -machine vexpress-a15 -smp 1 -m 1G -kernel u-boot.elf \
-drive file="nandflash.bin",if=mtd,index=0,format=raw \                                                       -chardev file,id=char1,path="${HOME}/serial1.txt",signal=on\                                                         -chardev file,id=char2,path="${HOME}/serial2.txt",signal=on\
-s -S -serial chardev:char1 -serial chardev:char2  -serial stdio
Linux image, skipping rbs!
OK! Booting Image main.bin with bootargs console=ttyO2,9600 rdinit=/sbin/init quiet loglevel=7 log_buf_len=1M...
## Booting kernel from Legacy Image at 84000200 ...
   Image Name:   linux
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    4086200 Bytes = 3.9 MiB
   Load Address: 82000000
   Entry Point:  82000000
## Loading init Ramdisk from Legacy Image at 843fae14 ...
   Image Name:   rootfs
   Image Type:   ARM Linux RAMDisk Image (uncompressed)
   Data Size:    23410472 Bytes = 22.3 MiB
   Load Address: 00000000
   Entry Point:  00000000
## Flattened Device Tree blob at 843e5df8
   Booting using the fdt blob at 0x843e5df8
   Loading Kernel Image ... OK
   Loading Ramdisk to 9c8db000, end 9df2e728 ... OK
   Loading Device Tree to 9c8c3000, end 9c8dae19 ... OK
Starting kernel ...

SF: Detected n25q256 with page size 256 Bytes, erase size 4 KiB, total 32 MiB, mapped at 5c000000
Uncompressing Linux... done, booting the kernel.
[    0.000000] Booting Linux on physical CPU 0x0
[    0.000000] Linux version 4.14.115-rt59 (lamnguyen@DENEC1LT0933) (gcc version 11.3.0) #1 PREEMPT RT Mon Jul 17 10:48:38 UTC 2023
[    0.000000] CPU: ARMv7 Processor [414fc0f0] revision 0 (ARMv7), cr=30c53c7d
[    0.000000] CPU: div instructions available: patching division code
[    0.000000] CPU: PIPT / VIPT nonaliasing data cache, PIPT instruction cache
[    0.000000] OF: fdt: Machine model: Hirschmann Greyhound Switch
[    0.000000] Memory policy: Data cache writeback
[    0.000000] cma: Reserved 24 MiB at 0x000000009e400000
[    0.000000] OMAP4: Map 0x000000009fd00000 to fe600000 for dram barrier
[    0.000000] CPU: All CPU(s) started in SVC mode.

我可以从 U-Boot 获取所有消息,从 Linux 获取内核消息,但来自应用程序的消息不会打印到控制台。当内核运行我的初始化脚本时,它只打印发送到 /dev/kmsg 的消息。例如:

#This one below will not print to my console (ttyS2)
echo -n " Mounting /dev/pts          : " 
#This one will but in the format of kernel message with the timestamp
echo -n " Mounting /dev/pts          : " | tee /dev/kmsg 

这些脚本实际上正在运行,但问题是我用普通命令“echo”看不到任何东西。我认为我的串行终端运行良好。除非,我不会看到不包含内核消息的东西。我在运行 init 脚本时输入

dmesg | grep "tty" | tee /dev/kmsg
并得到:

[   16.141290] [    0.000000] Kernel command line: console=ttyO2,9600 rdinit=/sbin/init quiet loglevel=7 log_buf_len=1M
[   16.141290] [    0.017880] WARNING: Your 'console=ttyO2' has been replaced by 'ttyS2'
[   16.141290] [    3.235689] 48020000.serial: ttyS2 at MMIO 0x48020000 (irq = 45, base_baud = 3000000) is a 8250
[   16.141290] [    7.652801] console [ttyS2] enabled

我的目标是将“echo without tee /dev/kmsg”的输出打印到我的控制台。我无法使用 GDB 进行调试,因为当执行这些初始化脚本时,我唯一看到的是 CPU 转到 WFI 和 NOP。我是新学习者,所以您的任何建议对我来说都会非常有价值。

linux bash console arm qemu
2个回答
1
投票

我可以想到两种攻击方式来调试:

首先,内核命令行上的“console=ttyO2”告诉内核使用该串行端口,但它不一定告诉/sbin/init 使用该串行端口(例如,用于生成登录提示)。因此,来宾文件系统中可能有一些配置可以控制它。检查您的来宾用户空间进程是否尝试将数据发送到内核以进入串行端口。

其次,内核打印可能以非中断驱动的方式使用 UART,而通过 tty 层打印则使用带中断的 UART。既然你说这是一个自定义板模型,你应该检查是否正确处理了中断(即它们是否按照客户的 UART 驱动程序的预期连接到中断控制器)。


0
投票

问题已经解决了。 Peter Maydell 的第二个假设是正确的,echo 命令需要 UART 中断与 QEMU 中的 pic[] 进行适当映射。由于 DRA72X 板使用中断交叉开关来复用中断源,但 QEMU 没有实现此类功能,因此我必须使用来自内核的交叉开关中断对 QEMU 中的中断 UART 进行硬编码。

© www.soinside.com 2019 - 2024. All rights reserved.