0
点赞
收藏
分享

微信扫一扫

如果把ChatGPT和“挖呀挖”的黄老师结合起来,她可以为你做什么事情?

徐一村 2023-05-11 阅读 73

RISC-V U-Boot 启动 Linux 内核的参数

U-Boot (the Universal Boot Loader简写U-Boot)

flyfish

U-Boot 启动Linux内核的参数举例说明

方式一 文本操作

内核命令参数
可以在 buildroot /board/型号/env.cfg 这里进行添加
举例

#kernel command arguments
console=ttyS0,115200
root_partition=rootfs
boot_partition=boot
keybox_list=widevine,ec_key,ec_cert1,ec_cert2,ec_cert3,rsa_key,rsa_cert1,rsa_cert2,rsa_cert3
#set kernel cmdline if boot.img or recovery.img has no cmdline we will use this
bootargs=earlyprintk=sunxi-uart,0x02500000 clk_ignore_unused initcall_debug=0 console=ttyS0,115200 loglevel=8 root=/dev/mmcblk0p4  init=/sbin/init partitions=ext4 cma=8M  gpt=1
#uboot system env config
bootdelay=1
kernel=boot.img
mmc_boot_part=3
mmc_dev=0
boot_check=sunxi_card0_probe;mmcinfo;mmc part
boot_mmc=fatload mmc ${mmc_dev}:${mmc_boot_part} 45000000 ${kernel}; bootm 45000000
bootcmd=run boot_check boot_mmc

uboot传递给内核的启动参数

bootargs=earlyprintk=sunxi-uart,0x02500000 clk_ignore_unused initcall_debug=0 console=ttyS0,115200 loglevel=8 root=/dev/mmcblk0p4  rw init=/sbin/init partitions=ext4 cma=8M  gpt=1

解释

earlyprintk=sunxi-uart,0x02500000

early_printk在内核串口设备初始化之前,打印输出日志,用于调试内核的启动问题
Sunxi:指 Allwinner 的一系列 SoC 硬件平台
UART:Universal Asynchronous Receiver/Transmitter,通用异步收发传输器
Console:控制台,Linux 内核中用于输出调试信息的 TTY 设备
0x02500000:可以根据具体厂商的设备树填写 例如
文件路径buildroot/output/build/linux-origin_master/arch/riscv/boot/dts/sunxi/sun20iw1p1.dtsi

uart0: uart@2500000 {
	compatible = "allwinner,sun20i-uart";
	device_type = "uart0";
	reg = <0x0 0x02500000 0x0 0x400>;
	interrupts-extended = <&plic0 18 IRQ_TYPE_LEVEL_HIGH>;
	clocks = <&ccu CLK_BUS_UART0>;
	clock-names = "uart0";
	resets = <&ccu RST_BUS_UART0>;
	sunxi,uart-fifosize = <64>;
	uart0_port = <0>;
	uart0_type = <2>;
	status = "okay";
};

uart1: uart@2500400 {
	compatible = "allwinner,sun20i-uart";
	device_type = "uart1";
	reg = <0x0 0x02500400 0x0 0x400>;
	interrupts-extended = <&plic0 19 IRQ_TYPE_LEVEL_HIGH>;
	sunxi,uart-fifosize = <256>;
	clocks = <&ccu CLK_BUS_UART1>;
	clock-names = "uart1";
	resets = <&ccu RST_BUS_UART1>;
	uart1_port = <1>;
	uart1_type = <4>;
	status = "disabled";
};

uart2: uart@2500800 {
	compatible = "allwinner,sun20i-uart";
	device_type = "uart2";
	reg = <0x0 0x02500800 0x0 0x400>;
	interrupts-extended = <&plic0 20 IRQ_TYPE_LEVEL_HIGH>;
	sunxi,uart-fifosize = <256>;
	clocks = <&ccu CLK_BUS_UART2>;
	clock-names = "uart2";
	resets = <&ccu RST_BUS_UART2>;
	uart2_port = <2>;
	uart2_type = <4>;
	status = "disabled";
};

。。。。。。

想要改uart2后面就要跟着 2500800
对应的源码结构

|-- drivers
| |-- tty
| | |-- serial
| | |-- serial_core.c
| | |-- sunxi-uart.c
| | |-- sunxi-uart.h

看其他厂商

/buildroot/output/build/linux-origin_master/arch/riscv/boot/dts/sifive/fu540-c000.dtsi

clk_ignore_unused

是忽略掉没有使用的时钟

console=ttyS0,115200

tty 是 Teletype 或 Teletypewriter 的缩写,是指电传打字机,硬件虽然现在不用流行了,现在做为传统名字保留到现在,现在tty设备还包括虚拟控制台,串口以及伪终端设备。
这里的意思是串口名从ttyS0开始依次是ttyS1、ttyS2等,这里使用ttyS0作为通信串口。

波特率115200
root=/dev/mmcblk0p4 rw
根文件系统在SD卡端口0设备第4分区,rw是根文件系统可读写

mmcblk0p4的含义
MMC全称MultiMedia Card,是1997年的多媒体记忆卡标准
SD卡全称Secure DigitalMemory Card,是1999年的新一代记忆卡标准,已完全兼容MMC标准。
MMC 是 SD 的前身,SD兼容MMC,Linux 的设备节点延用了 MMC 的这个名字
blk (block)是块设备,后面的数字是设备的顺序编号
p(partition)表示分区,p4就是第一个分区

init=/sbin/init

/sbin/init linux的进程1的路径,也可以是/linuxrc

partitions=ext4

根文件系统的类型是ext4

cma=8M

CMA: 连续内存分配器 (Contiguous Memory Allocator)
内存初始化时预留一块连续内存

gpt=1

GUID分区表 GUID Partition Table

方式二 使用界面的方式进行配置

在Buildroot配置内核
在Buildroot根目录运行命令

make linux-menuconfig

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
填写例如

earlyprintk=sunxi-uart,0x02500000 clk_ignore_unused initcall_debug=0 console=ttyS0,115200 loglevel=8 root=/dev/mmcblk0p4 rw init=/sbin/init partitions=ext4 cma=8M  gpt=1

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
更改完配置之后,需要重新编译linux内核,然后重新烧写sdcard.img
dmesg(display message)查看启动信息
Kernel command line 之后更改之后的信息

[    0.000000] Kernel command line: earlyprintk=sunxi-uart,0x02500000 clk_ignore_unused initcall_debug=0 console=ttyS0,115200 loglevel=8 root=/dev/mmcblk0p4 rw  init=/sbin/init partitions=ext4 cma=8M  gpt=1
[    0.000000] Dentry cache hash table entries: 65536 (order: 7, 524288 bytes, linear)
[    0.000000] Inode-cache hash table entries: 32768 (order: 6, 262144 bytes, linear)
[    0.000000] Sorting __ex_table...
[    0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
[    0.000000] Memory: 490532K/522240K available (6716K kernel code, 704K rwdata, 2226K rodata, 196K init, 411K bss, 23516K reserved, 8192K cma-reserved)
[    0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1

参考
https://itsfoss.com/what-is-tty-in-linux/
https://www.kernel.org/doc/html/latest/driver-api/clk.html

举报

相关推荐

0 条评论