如何在 ARM 上设置 Linux 内核命令行? [英] How to set Linux kernel command line on ARM?
问题描述
我的理解是,对于 ARM,内核引导命令行一般有三个来源:
My understanding is that for ARM there are three sources for the kernel boot command line in general:
- 在内核配置中作为 CONFIG_CMDLINE 给出的那些
- 引导加载程序传递的那些(通常是 ARM 处理器上的 U-Boot)
- 那些包含在设备树中的,在 selected/bootargs 下使用哪一个取决于内核配置参数.我的问题是如何使用内核配置在这些选项之间进行选择?
一个可以附加到另一个,即我们可以使用 CONFIG_CMDLINE 传递一些,然后在设备树中附加硬件特定的参数吗?
And can one append to another i.e. can we pass some using CONFIG_CMDLINE and then append hardware specific parameters in device tree?
我正在尝试组合 1、2 和 3,但这不能编译:
I'm trying combination 1, 2 AND 3 to begin with but this doesn't compile:
/dts-v1/;
#include "imx6q.dtsi"
#include "imx6q-h.dtsi"
#include "imx6q-m.dtsi"
/ {
model = "A M";
compatible = "a,imx6q-hydra13", "a,imx6q-mercury",
"a,imx6q-hydra", "fsl,imx6q";
};
&ssd_touch {
status = "okay";
};
ERROR AT THIS LINE: chosen {
bootargs = "console=ttymxc1,115200";
};
推荐答案
我的理解是,对于 ARM,内核引导命令行一般有三个来源:
My understanding is that for ARM there are three sources for the kernel boot command line in general:
这对于 Linux ARM 内核来说并不准确.内核只处理两个源",一个 default kernel command
字符串和一个 bootloader 内核参数
字符串.
更多详情如下.
That's not accurate for the Linux ARM kernel. The kernel only deals with two "sources", a default kernel command
string and a bootloader kernel arguments
string.
More details follow.
我的问题是如何使用内核配置在这些选项之间进行选择?
My question is how to choose between these options using kernel configuration?
您的选择可能仅限于使用内核配置".
附加"命令行配置选项,即 CONFIG_CMDLINE_FROM_BOOTLOADER(使用 bootloader 内核参数
,如果可用")、CONFIG_CMDLINE_EXTEND(扩展 bootloader 内核参数
")和 CONFIG_CMDLINE_FORCE(";始终使用 default kernel command
string") 仅在启用对旧 ATAG 参数传递(即 CONFIG_ATAGS)的支持时才可用(自 3.7 版起).
然而 CONFIG_ATAGS 确实默认为 y
除非明确禁用.主线 arch/arm/configs/ 中的十几个 _defconfig 文件明确禁用了这个 CONFIG_ATAGS.
The "additional" command-line configuration choices, i.e. CONFIG_CMDLINE_FROM_BOOTLOADER ("Use bootloader kernel arguments
if available"), CONFIG_CMDLINE_EXTEND ("Extend bootloader kernel arguments
"), and CONFIG_CMDLINE_FORCE ("Always use the default kernel command
string") are only available (since version 3.7) when support for the old ATAGs parameter passing (i.e. CONFIG_ATAGS) is enabled.
However CONFIG_ATAGS does default to y
unless explicitly disabled. About a dozen _defconfig files in mainline arch/arm/configs/ do explicitly disable this CONFIG_ATAGS.
但是设备树在哪里适合这种方案?
But where does the device tree fit in this scheme of things?
设备树是引导加载程序内核参数
的提供者.
也就是说,/chosen
节点中的 bootargs=
属性,是向 ARM 内核提供命令行的常规方法,即当 CONFIG_ATAGS 被禁用时,或者 CONFIG_CMDLINE_FROM_BOOTLOADER或 CONFIG_CMDLINE_EXTEND 已启用.
命令行由内核从设备树中作为字符串通过 early_init_dt_scan_chosen() 在 drivers/of/fdt.c
The Device Tree is the provider of bootloader kernel arguments
.
That is, the bootargs=
property in the /chosen
node, is the conventional method of providing the command line to the ARM kernel, i.e. when CONFIG_ATAGS is disabled, or either CONFIG_CMDLINE_FROM_BOOTLOADER or CONFIG_CMDLINE_EXTEND are enabled.
The command line is retrieved by the kernel from the Device Tree as a string by early_init_dt_scan_chosen() in drivers/of/fdt.c
仅当启用 CONFIG_CMDLINE_FORCE(带有 CONFIG_ATAGS)时,设备树 bootargs=
属性才会被忽略.
Only if CONFIG_CMDLINE_FORCE (with CONFIG_ATAGS) are enabled will the Device Tree bootargs=
property be ignored.
您可以使用 CONFIG_CMDLINE 使用 默认内核命令
配置/构建 ARM 内核,以防其他方法无法设置命令行.
drivers/of/fdt.c 中的注释记录了这一点.
You can configure/build the ARM kernel with a default kernel command
using CONFIG_CMDLINE in case nothing else managed to set the command line.
A comment in drivers/of/fdt.c documents this.
CONFIG_CMDLINE_EXTEND(带 CONFIG_ATAGS)生成一个命令行,它是设备树 bootargs=
属性与 CONFIG_CMDLINE 内容的串联.
CONFIG_CMDLINE_EXTEND (with CONFIG_ATAGS) results in a command line that is the concatenation of the Device Tree bootargs=
property with the contents of CONFIG_CMDLINE.
不过……
当使用 U-Boot 引导 Linux 内核时,请注意当环境变量 bootargs
被定义时,U-Boot 将(尝试)安装那个 bootargs
环境变量(作为属性)添加到加载的设备树 blob 的 /chosen
节点中.
如果/chosen
节点在DT中不存在,则创建.
如果该 DT 节点中不存在 bootargs=
属性,则创建它.
如果 bootargs=
属性已存在于该 DT 节点中,则它会被 U-Boot 环境变量覆盖.
请参阅 common/fdt_support.c 中的 fdt_chosen().
When using U-Boot to boot the Linux kernel, be aware that when the environment variable bootargs
is defined, U-Boot will (try to) install that bootargs
environment variable (as a property) into the the /chosen
node of the loaded Device Tree blob.
If the /chosen
node does not exist in the DT, then it is created.
If the bootargs=
property does not exist in that DT node, then it is created.
If the bootargs=
property already exists in that DT node, then it is overwritten with the U-Boot environment variable.
See fdt_chosen() in common/fdt_support.c.
IOW U-Boot 的 bootargs
环境变量通常成为事实上的内核命令行.
IOW U-Boot's bootargs
environment variable typically becomes the de facto kernel command line.
一个可以附加到另一个,即我们可以使用 CONFIG_CMDLINE 传递一些,然后在设备树中附加硬件特定的参数吗?
And can one append to another i.e. can we pass some using CONFIG_CMDLINE and then append hardware specific parameters in device tree?
仅当 (a) CONFIG_ATAGS 已启用,并且 (b) CONFIG_CMDLINE_EXTEND 已启用,并且 (c) 确保 U-Boot 的环境中没有 bootargs
变量.
Only if (a) CONFIG_ATAGS is enabled, and (b) CONFIG_CMDLINE_EXTEND is enabled, and (c) ensure that there is no bootargs
variable in U-Boot's environment.
底线
- U-Boot 总是尝试使用设备树将其
bootargs
变量传递给内核. - 设备树中的
bootargs=
属性始终被内核用作bootloader 内核参数
,如 arch/arm/Kconfig 中所述强> 文件.
- U-Boot always tries to pass its
bootargs
variable to the kernel using the Device Tree. - The
bootargs=
property in the Device Tree is always used by the kernel as thebootloader kernel arguments
as mentioned in the arch/arm/Kconfig file.
这篇关于如何在 ARM 上设置 Linux 内核命令行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!