:::{note} AI Translation Notice
This document was automatically translated by Qwen/Qwen3-8B
model, for reference only.
Source document: kernel/boot/cmdline.md
Translation time: 2025-05-19 01:41:48
Translation model: Qwen/Qwen3-8B
Please report issues via Community Channel
:::
:::{note} Author:
The DragonOS kernel boot command line parameter parsing module aims to provide support for parsing kernel boot command line parameters similar to Linux, enabling more flexible behavior for the kernel. This module allows the kernel to receive and parse command line parameters at boot time, and execute corresponding callback functions or set environment variables based on the type of parameters.
:::{note} Callback functions are not supported temporarily. :::
Kernel boot command line parameters are divided into three types:
Arg type parameters have only a name and no value. They are divided into the following two types:
false
. If the parameter is present in the command line, it will be set to true
.true
. If the parameter is present in the command line, it will be set to false
.KV type parameters are represented in the command line as name=value
, value
separated by commas. Kernel modules can provide default values for these parameters.
EarlyKV type parameters are similar to KV type parameters, but they are parsed before memory management initialization.
Module flags are similar to usbprobe.xxxx
.
Provides macros to declare kernel command line parameters.
:::{note}
TODO: Display the current kernel's boot command line parameters under /proc/cmdline
.
:::
kernel_cmdline_param_arg!(varname, name, default_bool, inv);
varname
: The variable name of the parametername
: The name of the parameterdefault_bool
: The default valueinv
: Whether to invertkernel_cmdline_param_kv!(varname, name, default_str);
varname
: The variable name of the parametername
: The name of the parameterdefault_str
: The default valuekernel_cmdline_param_early_kv!(varname, name, default_str);
varname
: The variable name of the parametername
: The name of the parameterdefault_str
: The default valueThe following example demonstrates how to declare and use KV type parameters:
kernel_cmdline_param_kv!(ROOTFS_PATH_PARAM, root, "");
if let Some(rootfs_dev_path) = ROOTFS_PATH_PARAM.value_str() {
.......
} else {
.......
};
kernel_cmdline_param_kv!
macro to declare the required KV type parameters.value_str()
or value_bool()
method of the parameter.By following these steps, developers can flexibly use kernel boot command line parameters to control kernel behavior.
/proc/cmdline
(requires procfs refactoring)