boot -o bootm.bootconfig=FILE replaces the bootconfig a boot entry would get from global.bootm.bootconfig, an empty value removes it. Together with the other overrides this changes kernel parameters, init options or tracing for one boot of an existing entry.
Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Steffen Trumtrar <[email protected]> --- Documentation/user/devboot.rst | 17 +++++++++++++++++ commands/boot.c | 5 ++++- common/bootm-overrides.c | 23 +++++++++++++++++++++-- include/bootm-overrides.h | 3 +++ include/bootm.h | 1 + 5 files changed, 46 insertions(+), 3 deletions(-) diff --git a/Documentation/user/devboot.rst b/Documentation/user/devboot.rst index e319636994..fce8398b22 100644 --- a/Documentation/user/devboot.rst +++ b/Documentation/user/devboot.rst @@ -105,6 +105,23 @@ Override rules mount -n --bind /lib/modules ${ROOT_MOUNT}/lib/modules +``bootm.bootconfig`` + A Linux bootconfig file (``CONFIG_BOOTM_BOOTCONFIG``), appended to the + initrd after all initrds, or passed alone as the initrd if there is + none, see :ref:`global.bootm.bootconfig + <magicvar_global_bootm_bootconfig>`. It replaces the bootconfig the boot + entry would get from the variable; an empty string removes it. This + configures the kernel and init without touching the boot entry's + command line or the root filesystem, e.g. tracing for one boot: + + .. code-block:: sh + + # /mnt/tftp/trace.bconf + ftrace.event.sched.sched_switch.enable + kernel.trace_buf_size = 4M + + boot -o bootm.bootconfig=/mnt/tftp/trace.bconf mmc + .. note:: When secure boot is enforced (``bootm_signed_images_are_forced()``), diff --git a/commands/boot.c b/commands/boot.c index cc7a64bcca..bd09b90901 100644 --- a/commands/boot.c +++ b/commands/boot.c @@ -49,6 +49,9 @@ static int boot_add_override(struct bootm_overrides *overrides, char *var) overrides->oftree_file = val; } else if (!strcmp(var, "bootm.initrd")) { overrides->initrd_file = val; + } else if (IS_ENABLED(CONFIG_BOOTM_BOOTCONFIG) && + !strcmp(var, "bootm.bootconfig")) { + overrides->bootconfig_file = val; } else { return -EINVAL; } @@ -241,7 +244,7 @@ BAREBOX_CMD_HELP_OPT ("-m","Show a menu with boot options") BAREBOX_CMD_HELP_OPT ("-M DEFAULT","Show a menu with boot options with entry DEFAULT preselected") BAREBOX_CMD_HELP_OPT ("-w SECS","Start watchdog with timeout SECS before booting") #ifdef CONFIG_BOOT_OVERRIDE -BAREBOX_CMD_HELP_OPT ("-o VAR[=VAL]","override VAR (bootm.{oftree,initrd}) with VAL") +BAREBOX_CMD_HELP_OPT ("-o VAR[=VAL]","override VAR (bootm.{oftree,initrd,bootconfig}) with VAL") BAREBOX_CMD_HELP_OPT (" ","if VAL is not specified, the value of VAR is taken") #endif BAREBOX_CMD_HELP_OPT ("-t SECS","specify timeout in SECS") diff --git a/common/bootm-overrides.c b/common/bootm-overrides.c index 720d5636f3..f02a037b13 100644 --- a/common/bootm-overrides.c +++ b/common/bootm-overrides.c @@ -3,6 +3,7 @@ #include <bootm.h> #include <bootm-overrides.h> #include <bootm-fit.h> +#include <bootconfig.h> #include <init.h> #include <libfile.h> #include <of.h> @@ -107,6 +108,8 @@ static void report_active_overrides(const struct image_data *data) report_active_override("initrd", data->initrd); if (data->is_override.oftree) report_active_override("FDT", data->oftree); + if (data->is_override.bootconfig) + report_active_override("bootconfig", data->bootconfig); } /** @@ -114,8 +117,9 @@ static void report_active_overrides(const struct image_data *data) * @data: image data context * @overrides: overrides to apply * - * Applies bootm.image, bootm.initrd, and bootm.oftree overrides by translating - * them into file-based loadables or FIT image replacements. + * Applies bootm.image, bootm.initrd, bootm.oftree and bootm.bootconfig + * overrides by translating them into file-based loadables or FIT image + * replacements. * * Context: Called during boot preparation * Return: 0 on success, negative error code otherwise @@ -143,6 +147,21 @@ int bootm_apply_overrides(struct image_data *data, data->is_override.initrd = true; } + if (IS_ENABLED(CONFIG_BOOTM_BOOTCONFIG) && overrides->bootconfig_file) { + /* an empty bootconfig_file removes the bootconfig */ + loadable_release(&data->bootconfig); + if (nonempty(overrides->bootconfig_file)) { + data->bootconfig = bootconfig_loadable(overrides->bootconfig_file); + if (IS_ERR(data->bootconfig)) { + ret = PTR_ERR(data->bootconfig); + + data->bootconfig = NULL; + return ret; + } + } + data->is_override.bootconfig = true; + } + if (overrides->oftree_file) { int ret = loadables_from_files(&data->oftree, overrides->oftree_file, ":", diff --git a/include/bootm-overrides.h b/include/bootm-overrides.h index 0dbf6e7fa8..fde543a8e4 100644 --- a/include/bootm-overrides.h +++ b/include/bootm-overrides.h @@ -6,6 +6,7 @@ struct bootm_overrides { const char *os_file; const char *oftree_file; const char *initrd_file; + const char *bootconfig_file; }; struct image_data; @@ -21,6 +22,8 @@ static inline void bootm_merge_overrides(struct bootm_overrides *dst, dst->oftree_file = src->oftree_file; if (src->initrd_file) dst->initrd_file = src->initrd_file; + if (src->bootconfig_file) + dst->bootconfig_file = src->bootconfig_file; } int bootm_apply_overrides(struct image_data *data, diff --git a/include/bootm.h b/include/bootm.h index 134b01d453..9038ba7300 100644 --- a/include/bootm.h +++ b/include/bootm.h @@ -148,6 +148,7 @@ struct image_data { u8 os:1; u8 initrd:1; u8 oftree:1; + u8 bootconfig:1; } is_override; enum bootm_efi_mode efi_boot; }; -- 2.56.0
