如何解决u-boot 如何在 bootargs 中没有控制台参数的情况下启动并仍然获取内核日志和所有要打印的日志
我目前正在使用 uboot 来启动 linux 内核。我没有在控制台参数中提到 ttyS0 或任何内容。仅当没有控制台参数时我才能看到输出,而如果我指定控制台参数,则日志在“启动内核...”后停止。所以我试图找到linux内核是否使用u-boot串行驱动程序来打印和获取字符。但是,当我在驱动程序中进行一些小的更改或添加打印语句时,我可以在 u-boot 命令行之前看到该更改,而在启动 Linux 时我看不到这些更改。我想知道正在使用哪个驱动程序打印数据并从控制台获取数据。
Edit(1) :在使用 TTY 驱动程序后,我现在在控制台上收到打印语句。请参阅下面的日志:
[ 0.000000] OF: fdt: Ignoring memory range 0x80000000 - 0x84000000
[ 0.000000] Linux version 5.5.0-rc1-00032-g264b43306b8c-dirty (venkatakrishnan@venkatakrishnan-ubuntu) (gcc version 10.2.0 (GCC)) #22 Tue Jul 27 15:02:20 IST 2021
[ 0.000000] initrd not found or empty - disabling initrd
[ 0.000000] Zone ranges:
[ 0.000000] DMA32 [mem 0x0000000084000000-0x000000008fffffff]
[ 0.000000] Normal empty
[ 0.000000] Movable zone start for each node
[ 0.000000] Early memory node ranges
[ 0.000000] node 0: [mem 0x0000000084000000-0x000000008fffffff]
[ 0.000000] Initmem setup node 0 [mem 0x0000000084000000-0x000000008fffffff]
[ 0.000000] software IO TLB: mapped [mem 0x8bd5b000-0x8fd5b000] (64MB)
[ 0.000000] elf_hwcap is 0x1105
[ 0.000000] Built 1 zonelists,mobility grouping on. Total pages: 48480
[ 0.000000] Kernel command line: console=ttySHAKTI0,19200n8 earlycon root=/dev/mmcblk1p1 rw rootfs=ext4 noinitrd selinux=0
[ 0.000000] Dentry cache hash table entries: 32768 (order: 6,262144 bytes,linear)
[ 0.000000] Inode-cache hash table entries: 16384 (order: 5,131072 bytes,linear)
[ 0.000000] Sorting __ex_table...
[ 0.000000] mem auto-init: stack:off,heap alloc:off,heap free:off
[ 0.000000] Memory: 112684K/196608K available (3868K kernel code,199K rwdata,702K rodata,9856K init,233K bss,83924K reserved,0K cma-reserved)
[ 0.000000] SLUB: HWalign=64,Order=0-3,MinObjects=0,CPUs=1,Nodes=1
[ 0.000000] NR_IRQS: 0,nr_irqs: 0,preallocated irqs: 0
[ 0.000000] plic: mapped 29 interrupts with 1 handlers for 2 contexts.
[ 0.000000] riscv_timer_init_dt: Registering clocksource cpuid [0] hartid [0]
[ 0.000000] clocksource: riscv_clocksource: mask: 0xffffffffffffffff max_cycles: 0x1ef4687b1,max_idle_ns: 112843571739654 ns
[ 0.001342] sched_clock: 64 bits at 32kHz,resolution 30517ns,wraps every 70368744171142ns
[ 0.011474] Calibrating delay loop (skipped),value calculated using timer frequency.. 0.06 BogoMIPS (lpj=131)
[ 0.016326] pid_max: default: 32768 minimum: 301
[ 0.077301] Mount-cache hash table entries: 512 (order: 0,4096 bytes,linear)
[ 0.082397] Mountpoint-cache hash table entries: 512 (order: 0,linear)
[ 0.482940] devtmpfs: initialized
[ 1.069976] random: get_random_bytes called from setup_net+0x54/0x1dc with crng_init=0
[ 1.123840] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff,max_idle_ns: 7645041785100000 ns
[ 1.129333] futex hash table entries: 256 (order: 0,6144 bytes,linear)
[ 1.213317] NET: Registered protocol family 16
[ 1.639770] Shakti UART Probing started...
[ 1.669952] 11300.uart: ttySHAKTI0 at MMIO 0x11300 (irq = 0,base_baud = 0) is a Shakti UART 0
[ 234.333038] printk: console [ttySHAKTI0] enabled
[ 235.845855] clocksource: Switched to clocksource riscv_clocksource
[ 236.541534] NET: Registered protocol family 2
[ 236.840209] tcp_listen_portaddr_hash hash table entries: 256 (order: 0,linear)
[ 237.152709] TCP established hash table entries: 2048 (order: 2,16384 bytes,linear)
[ 237.442626] TCP bind hash table entries: 2048 (order: 2,linear)
[ 237.703186] TCP: Hash tables configured (established 2048 bind 2048)
[ 237.953887] UDP hash table entries: 256 (order: 1,8192 bytes,linear)
[ 238.188140] UDP-Lite hash table entries: 256 (order: 1,linear)
[ 238.492340] NET: Registered protocol family 1
[ 268.344238] workingset: timestamp_bits=62 max_order=15 bucket_order=0
[ 281.773803] ntfs: driver 2.1.32 [Flags: R/W DEBUG].
[ 282.271209] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 253)
[ 282.536315] io scheduler mq-deadline registered
[ 282.675445] io scheduler kyber registered
[ 282.983062] io scheduler bfq registered
[ 304.778137] Error: Driver 'shakti-uart' is already registered,aborting...
[ 305.379852] shakti_spi 20100.spi: Shakti SPI Driver initialized
[ 306.020507] libphy: Fixed MDIO Bus: probed
[ 306.185424] xilinx_emaclite 44000.ethernet: Device Tree Probing
[ 306.439025] libphy: Xilinx Emaclite MDIO: probed
[ 306.686065] xilinx_emaclite 44000.ethernet: MAC address is now 00:0a:35:00:00:00
[ 307.191101] xilinx_emaclite 44000.ethernet: Xilinx EmacLite at 0x00044000 mapped to 0x04010000,irq=29
[ 307.796661] mmc_spi spi0.0: SD/MMC host mmc0,no DMA,no WP,no poweroff,cd polling
[ 308.229644] NET: Registered protocol family 17
[ 311.828765] Freeing unused kernel memory: 9856K
[ 311.968719] This architecture does not have kernel memory protection.
[ 312.218292] Run /init as init process
[ 313.042419] mmc0: host does not support reading read-only switch,assuming write-enable
[ 313.339843] mmc0: new SDHC card on SPI
[ 314.152679] mmcblk0: mmc0:0000 SS08G 7.40 GiB
[ 315.783752] mmcblk0: p1
我仍然想知道我看不到登录提示,我可以看到这个控制台被用作日志控制台,其中仅打印 printk 语句(类似于 dmesg 命令)。同样对于输入,我们是否需要注册中断并将其用于数据输入,或者是否有任何可能的轮询方法?
解决方法
有一个 bootargs 的概念,它通常可以通过使用 cat/proc/cmdline 从 linux 提示符访问。请检查这个。这是从 u-boot 传递的默认引导参数。
,只有当没有控制台参数时我才能看到输出,而如果我指定控制台参数,日志会在“启动内核...”后停止。
这意味着
一种。当您指定控制台时,该设备或其驱动程序未按预期运行。
和
湾当您不指定控制台时,内核默认为它发现能够执行的串行终端
充当系统控制台。
如 Documentation/admin-guide/serial-console.rst 中所述:
If no console device is specified [in the command line],the first device found capable
of acting as a system console will be used.
...
So if you don't have a VGA card in your system the first serial port will automatically
become the console.
所以我试图找出linux内核是否使用u-boot串行驱动程序来打印和获取字符。
如前所述,Linux 内核不会在自己的映像之外执行代码。
然而,有“低级内核调试”功能(CONFIG_DEBUG_LL 及其朋友)(可能取决于体系结构)将利用已由引导加载程序初始化的 UART。此功能需要对设备地址进行硬编码,以便内核能够立即显示文本消息,而无需执行任何设备初始化。
EARLYPRINTK 功能依赖于这个预初始化的串口。
我想知道正在使用哪个驱动程序来打印数据和从控制台获取数据。
显示内核消息是与“从控制台获取数据”不同的功能。
内核控制台本质上是一个仅输出设备。例如在 PC 上,Linux 可以使用 VGA 显示适配器作为控制台;显示适配器没有输入功能。控制台只是内核显示其消息的设备。
console=...
内核参数不设置/配置交互式终端。 UART 上的内核控制台通常甚至没有输入功能。 struct console 确实允许读取函数(用于输入),但 drivers/tty/serial/ 驱动程序没有实现它。
通过使用getty 命令(在用户空间中)提供在串行终端上登录的功能;学习Documentation/admin-guide/serial-console.rst。
作为实验,我启动了 Linux ARM SBC,但编辑了 bootargs 变量,以便命令行中没有 console=ttyS0...
参数。
无论如何,通过串行链路显示内核启动消息,有 printk: console [tty0] enabled
消息,在 UART 驱动程序初始化后,显示消息 printk: console [ttyS0] enabled
。
Booting Linux on physical CPU 0x0
Linux version 5.4.81-linux4sam-2020.10 (oe-user@oe-host) (gcc version 9.3.0 (GCC)) #1 Thu Jan 14 12:54:56 UTC 2021
...
Kernel command line: root=/dev/mmcblk0p1 rw rootfstype=ext4 rootwait atmel.pm_modes=standby,ulp1
...
Switching to timer-based delay loop,resolution 96ns
Console: colour dummy device 80x30
printk: console [tty0] enabled
Calibrating delay loop (skipped),value calculated using timer frequency.. 20.75 BogoMIPS (lpj=103750)
...
atmel_usart_serial.0.auto: ttyS0 at MMIO 0xf8020000 (irq = 35,base_baud = 5187500) is a ATMEL_SERIAL
printk: console [ttyS0] enabled
...
因此,此内核默认使用控制台的第一个串行终端,如文档所述:“如果未指定控制台设备,...第一个串行端口将自动成为控制台。”
你的启动日志有以下内容
[ 0.000000] Linux version 5.5.0-rc1-00032-g264b43306b8c-dirty (venkatakrishnan@venkatakrishnan-ubuntu) (gcc version 10.2.0 (GCC)) #22 Tue Jul 27 15:02:20 IST 2021
...
[ 0.000000] Kernel command line: console=ttySHAKTI0,19200n8 earlycon root=/dev/mmcblk1p1 rw rootfs=ext4 noinitrd selinux=0
...
[ 1.639770] Shakti UART Probing started...
[ 1.669952] 11300.uart: ttySHAKTI0 at MMIO 0x11300 (irq = 0,base_baud = 0) is a Shakti UART 0
[ 234.333038] printk: console [ttySHAKTI0] enabled
因此 console=ttySHAKTI0...
的规范似乎是有效的,因为内核报告控制台已为 /dev/ttySHAKTI0 启用。
命令行中 earlycon
的规范似乎无效,因为这通常会生成适当的消息,而没有任何此类消息。
如果您希望使用 /dev/ttySHAKTI0 登录,那么这将取决于功能齐全的串行终端 驱动程序(即UART 驱动程序,支持 termios 功能),以及适当的 /etc/inittab 条目,该条目(重复)在该终端设备上执行(或重新生成)getty(或变体)。
例如我的 Linux ARM SBC 有:
S0:12345:respawn:/bin/start_getty 115200 ttyS0 vt102
其中 start_getty 是用于自动设置串行终端以在启动时登录的脚本。
此登录规范独立于 console=...
内核参数。但惯例是对两种任务使用相同的设备,这可能会导致混淆“控制台”是什么。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。