简体   繁体   English

如何在 ARM 上设置 Linux 内核命令行?

[英]How to set Linux kernel command line on ARM?

My understanding is that for ARM there are three sources for the kernel boot command line in general:我的理解是,对于 ARM,内核引导命令行通常有三个来源:

  1. Those given as CONFIG_CMDLINE in the kernel configuration在内核配置中作为 CONFIG_CMDLINE 给出的那些
  2. Those passed on by the boot loader (typically U-Boot on ARM processors)引导加载程序传递的那些(通常是 ARM 处理器上的 U-Boot)
  3. Those included in the device tree, under chosen/bootargs Which one is used depends on kernel configuration parameters.设备树中包含的那些,在 selected/bootargs 下使用哪个取决于内核配置参数。 My question is how to choose between these options using kernel configuration?我的问题是如何使用内核配置在这些选项之间进行选择?

And can one append to another ie can we pass some using CONFIG_CMDLINE and then append hardware specific parameters in device tree?并且可以附加到另一个,即我们可以使用 CONFIG_CMDLINE 传递一些,然后在设备树中附加硬件特定参数吗?

I'm trying combination 1, 2 AND 3 to begin with but this doesn't compile:我正在尝试组合 1、2 和 3,但这不能编译:

/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";
};

My understanding is that for ARM there are three sources for the kernel boot command line in general:我的理解是,对于 ARM,内核引导命令行通常有三个来源:

That's not accurate for the Linux ARM kernel.这对于 Linux ARM 内核来说并不准确。 The kernel only deals with two "sources", a default kernel command string and a bootloader kernel arguments string.内核只处理两个“源”,一个default kernel command字符串和一个bootloader kernel arguments字符串。
More details follow.更多细节如下。

My question is how to choose between these options using kernel configuration?我的问题是如何使用内核配置在这些选项之间进行选择?

You choices may be limited by only "using kernel configuration" .您的选择可能仅限于“使用内核配置”

The "additional" command-line configuration choices, ie 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 (ie CONFIG_ATAGS) is enabled. “附加”命令行配置选项,即 CONFIG_CMDLINE_FROM_BOOTLOADER(“如果可用,则使用bootloader kernel arguments ”)、CONFIG_CMDLINE_EXTEND(“扩展bootloader kernel arguments ”)和 CONFIG_CMDLINE_FORCE(“始终使用default kernel command字符串”)仅可用(自 3.7 版起)启用对旧 ATAG 参数传递(即 CONFIG_ATAGS)的支持。
However CONFIG_ATAGS does default to y unless explicitly disabled.但是,除非明确禁用,否则 CONFIG_ATAGS 确实默认为y About a dozen _defconfig files in mainline arch/arm/configs/ do explicitly disable this CONFIG_ATAGS.主线arch/arm/configs/ 中的十几个_defconfig文件明确禁用了这个 CONFIG_ATAGS。


But where does the device tree fit in this scheme of things?但是设备树在哪里适合这种方案呢?

The Device Tree is the provider of bootloader kernel arguments .设备树是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, ie when CONFIG_ATAGS is disabled, or either CONFIG_CMDLINE_FROM_BOOTLOADER or CONFIG_CMDLINE_EXTEND are enabled.也就是说, /chosen节点中的bootargs=属性是向 ARM 内核提供命令行的常规方法,即当 CONFIG_ATAGS 被禁用,或者 CONFIG_CMDLINE_FROM_BOOTLOADER 或 CONFIG_CMDLINE_EXTEND 被启用时。
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命令行由内核从设备树中作为字符串通过驱动程序/of/fdt.c 中的 early_init_dt_scan_chosen()检索

Only if CONFIG_CMDLINE_FORCE (with CONFIG_ATAGS) are enabled will the Device Tree bootargs= property be ignored.仅当启用 CONFIG_CMDLINE_FORCE(带 CONFIG_ATAGS)时,设备树bootargs=属性才会被忽略。

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.您可以使用 CONFIG_CMDLINE 使用default kernel command配置/构建 ARM 内核,以防其他方法无法设置命令行。
A comment in drivers/of/fdt.c documents this. driver/of/fdt.c 中的注释记录了这一点。

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. CONFIG_CMDLINE_EXTEND(带有 CONFIG_ATAGS)产生一个命令行,它是设备树bootargs=属性与 CONFIG_CMDLINE 的内容的串联。

However ...然而 ...

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.使用 U-Boot 引导 Linux 内核时,请注意,当定义环境变量bootargs ,U-Boot 会(尝试)将该bootargs环境变量(作为属性)安装到已加载设备的/chosen节点中树丛。
If the /chosen node does not exist in the DT, then it is created.如果/chosen节点在 DT 中不存在,则创建它。
If the bootargs= property does not exist in that DT node, then it is created.如果该 DT 节点中不存在bootargs=属性,则会创建它。
If the bootargs= property already exists in that DT node, then it is overwritten with the U-Boot environment variable.如果该 DT 节点中已存在bootargs=属性,则它会被 U-Boot 环境变量覆盖。
See fdt_chosen() in common/fdt_support.c .请参阅common/fdt_support.c 中的fdt_chosen()

IOW U-Boot's bootargs environment variable typically becomes the de facto kernel command line. IOW U-Boot 的bootargs环境变量通常成为事实上的内核命令行。


And can one append to another ie can we pass some using CONFIG_CMDLINE and then append hardware specific parameters in device tree?并且可以附加到另一个,即我们可以使用 CONFIG_CMDLINE 传递一些,然后在设备树中附加硬件特定参数吗?

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.仅当 (a) CONFIG_ATAGS 已启用,并且 (b) CONFIG_CMDLINE_EXTEND 已启用,并且 (c) 确保 U-Boot 环境中没有bootargs变量。


Bottom Line底线

  1. U-Boot always tries to pass its bootargs variable to the kernel using the Device Tree. U-Boot 总是尝试使用设备树将其bootargs变量传递给内核。
  2. The bootargs= property in the Device Tree is always used by the kernel as the bootloader kernel arguments as mentioned in the arch/arm/Kconfig file. bootargs=始终使用设备树中的bootargs=属性作为arch/arm/Kconfig文件中提到的bootloader kernel arguments

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM