arm: carry and filter previous bootloader's bootargs
Subsystems (2)
cover arm: carry and filter previous bootloader's bootargs
This series supports chainloaded U-Boot on Android devices where the previous stage bootloader (e.g. Android ABL) hands off a kernel command line via /chosen/bootargs. Some of those parameters need to be carried over into U-Boot's own $bootargs, while others such as skip_initramfs need to be explicitly dropped before the command line reaches the kernel.
Therefore this series adds a small command-line utility library and uses it to carry over and filter the inherited bootargs.
Four patches:
1. common: Add command line parsing utilities Parse key=value parameters out of a command-line string.
2. common: Add command line parameter masking functionality Mask or drop individual parameters from a command-line string.
3. common: Add Android bootloader parameter parsing helper Convenience wrapper for the numerous androidboot.* parameters.
4. arm: carry previous bootloader's bootargs into $bootargs Wire the above utilities into the boot path. Copy the previous bootloader's /chosen/bootargs into $bootargs. Drop parameters that must not survive the handoff (e.g. skip_initramfs) when CONFIG_SAVE_PREV_BL_BOOTARGS is enabled.
---
Petr Hodina (4):
common: Add command line parsing utilities
common: Add command line parameter masking functionality
common: Add Android bootloader parameter parsing helper
arm: carry previous bootloader's bootargs into $bootargs
MAINTAINERS | 6 + arch/arm/lib/save_prev_bl_data.c | 15 +- boot/Kconfig | 8 + include/cmdline_utils.h | 60 +++++++ lib/Makefile | 1 + lib/cmdline_utils.c | 331 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 420 insertions(+), 1 deletion(-)
---
base-commit: ece349ade2973e220f524ce59e59711cc919263f
change-id: 20260909-b4-android-bootargs-carryover-3ebbc6685ba6
Best regards,
Signature · 1 line
Petr Hodina <[email protected]>
PATCH 1/4 common: Add command line parsing utilities
Add a new utility library for parsing command line parameters in key=value format. This provides a reusable interface for extracting multiple parameters from command line strings.
--- MAINTAINERS | 6 ++++ include/cmdline_utils.h | 21 +++++++++++ lib/Makefile | 1 + lib/cmdline_utils.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 124 insertions(+)
MAINTAINERS +6 -0
@@ -1065,6 +1065,12 @@ T: git https://source.denx.de/u-boot/custodians/u-boot-clk.git F: drivers/clk/ F: drivers/clk/imx/ +CMDLINE_UTILS +M: Petr Hodina <[email protected]> +S: Maintained +F: include/cmdline_utils.h +F: lib/cmdline_utils.c + CPU M: Simon Glass <[email protected]> M: Hou Zhiqiang <[email protected]>
include/cmdline_utils.h new file +21 -0
@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Command line parsing utilities +* +* Copyright (c) 2026 Petr Hodina +*/ + +#ifndef _CMDLINE_UTILS_H_ +#define _CMDLINE_UTILS_H_ + +#include <linux/types.h> + +struct cmdline_param { +const char *key; +char *value; +bool found; +}; + +int parse_cmdline_params (const char *cmdline,struct cmdline_param *params,int count); + +#endif /* _CMDLINE_UTILS_H_ */
lib/Makefile +1 -0
@@ -126,6 +126,7 @@ obj-$(CONFIG_$(PHASE_)OF_LIBFDT) += fdtdec.o fdtdec_common.o obj-y += hang.o obj-y += linux_compat.o obj-y += linux_string.o +obj-y += cmdline_utils.o obj-$(CONFIG_$(PHASE_)LMB) += lmb.o obj-y += membuf.o obj-$(CONFIG_REGEX) += slre.o
lib/cmdline_utils.c new file +96 -0
96 lines not on this page · raw message
Signature · 1 line
2.55.0
Re: [PATCH 1/4] common: Add command line parsing utilities
Quoted 4 lines · On 9/11/26 8:18 PM, Petr Hodina via B4 Relay wrote:
From: Petr Hodina <[email protected]>
Add a new utility library for parsing command line parameters in key=value format.
Is this reinventing environment or UPL ?
Re: [PATCH 1/4] common: Add command line parsing utilities
Quoted 7 lines · Marek Vasut
Quoted 4 lines · On 9/11/26 8:18 PM, Petr Hodina via B4 Relay wrote:
From: Petr Hodina <[email protected]>
Add a new utility library for parsing command line parameters in key=value format.
Is this reinventing environment or UPL ?
The target is a chainloaded environment. In this case u-boot running on Android devices where you unfortunately don't have the possibility to use UPL.
As stated above it's purpose is to simplify the operations on the command line arguments from the previous stage and pass them to the next.
Typical example is to remove the skip initramfs or extract the value for the panel to pick the right dtb (not part of this patch series)
Re: [PATCH 1/4] common: Add command line parsing utilities
Quoted 7 lines · phodina
Quoted 5 lines · Marek Vasut
Quoted 4 lines · On 9/11/26 8:18 PM, Petr Hodina via B4 Relay wrote:
From: Petr Hodina <[email protected]>
Add a new utility library for parsing command line parameters in key=value format.
Quoted 8 lines
Quoted 2 lines
Is this reinventing environment or UPL ?
The target is a chainloaded environment. In this case u-boot running on Android devices where you unfortunately don't have the possibility to use UPL.
As stated above it's purpose is to simplify the operations on the command line arguments from the previous stage and pass them to the next.
Typical example is to remove the skip initramfs or extract the value for the panel to pick the right dtb (not part of this patch series)
Is this something you could do in an U-Boot script using setexpr sub/gsub instead ?
Re: [PATCH 1/4] common: Add command line parsing utilities
Quoted 11 lines · Marek Vasut
Quoted 10 lines · phodina
Quoted 7 lines · Marek Vasut
Quoted 4 lines · On 9/11/26 8:18 PM, Petr Hodina via B4 Relay wrote:
From: Petr Hodina <[email protected]>
Add a new utility library for parsing command line parameters in key=value format.
Is this reinventing environment or UPL ?
Quoted 8 lines
Quoted 5 lines
The target is a chainloaded environment. In this case u-boot running on Android devices where you unfortunately don't have the possibility to use UPL.
As stated above it's purpose is to simplify the operations on the command line arguments from the previous stage and pass them to the next.
Typical example is to remove the skip initramfs or extract the value for the panel to pick the right dtb (not part of this patch series)
Is this something you could do in an U-Boot script using setexpr sub/gsub instead ?
Yes, I would like to see how this gets used in implementation too, as I'm wondering if we shouldn't just be also saving off something like "prev_bl_bootargs" and leaving the rest to the board code to deal with. Maybe we should also add the android-specific helpers in a new file under an Android-related Kconfig as well.
Signature · 1 line
Tom
Re: [PATCH 1/4] common: Add command line parsing utilities
Quoted 18 lines · Tom Rini
Quoted 17 lines · Marek Vasut
Quoted 15 lines · phodina
Quoted 7 lines · Marek Vasut
Quoted 4 lines · On 9/11/26 8:18 PM, Petr Hodina via B4 Relay wrote:
From: Petr Hodina <[email protected]>
Add a new utility library for parsing command line parameters in key=value format.
Is this reinventing environment or UPL ?
The target is a chainloaded environment. In this case u-boot running on Android devices where you unfortunately don't have the possibility to use UPL.
As stated above it's purpose is to simplify the operations on the command line arguments from the previous stage and pass them to the next.
Typical example is to remove the skip initramfs or extract the value for the panel to pick the right dtb (not part of this patch series)
Quoted 8 lines
Quoted 2 lines
Is this something you could do in an U-Boot script using setexpr sub/gsub instead ?
Yes, I would like to see how this gets used in implementation too, as I'm wondering if we shouldn't just be also saving off something like "
prev_bl_bootargs" and leaving the rest to the board code to deal with. Maybe we should also add the android-specific helpers in a new file under an Android-relatedKconfigas well.
If this is key=value pairs that get passed in in some chunk of memory, can 'env import' help here ?
Re: [PATCH 1/4] common: Add command line parsing utilities
Quoted 22 lines · Marek Vasut
Quoted 21 lines · Tom Rini
Quoted 19 lines · Marek Vasut
Quoted 7 lines · phodina
Quoted 5 lines · Marek Vasut
Quoted 4 lines · On 9/11/26 8:18 PM, Petr Hodina via B4 Relay wrote:
From: Petr Hodina <[email protected]>
Add a new utility library for parsing command line parameters in key=value format.
Quoted 8 lines
Quoted 2 lines
Is this reinventing environment or UPL ?
The target is a chainloaded environment. In this case u-boot running on Android devices where you unfortunately don't have the possibility to use UPL.
As stated above it's purpose is to simplify the operations on the command line arguments from the previous stage and pass them to the next.
Typical example is to remove the skip initramfs or extract the value for the panel to pick the right dtb (not part of this patch series)
Is this something you could do in an U-Boot script using setexpr sub/gsub instead ?
Quoted 7 lines
Quoted 5 lines
Yes, I would like to see how this gets used in implementation too, as I'm wondering if we shouldn't just be also saving off something like "
prev_bl_bootargs" and leaving the rest to the board code to deal with. Maybe we should also add the android-specific helpers in a new file under an Android-relatedKconfigas well.If this is key=value pairs that get passed in in some chunk of memory, can 'env import' help here ?
No, from the whole series it's that we're being passed
https://www.kernel.org/doc/html/latest/arch/arm64/booting.html and then dealing with parts of it. Some platforms do this today, even:
$ ./tools/qconfig.py -f SAVE_PREV_BL_FDT_ADDR 15 matches a3y17lte a5y17lte a7y17lte coreprimevelte exynos-mobile qcm6490 qcom qcom_dragonboard820c qcom_ipq5424_mmc qcom_ipq9574_mmc qcom_qcs615 qcom_qcs6490_rubikpi3 qcom_qcs8300 qcom_qcs9100 qcom_sm8650
Signature · 1 line
Tom
Re: [PATCH 1/4] common: Add command line parsing utilities
In reply to Tom RiniQuoted 12 lines · Tom Rini
Quoted 11 lines · Marek Vasut
Quoted 10 lines · phodina
Quoted 7 lines · Marek Vasut
Quoted 4 lines · On 9/11/26 8:18 PM, Petr Hodina via B4 Relay wrote:
From: Petr Hodina <[email protected]>
Add a new utility library for parsing command line parameters in key=value format.
Is this reinventing environment or UPL ?
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
The target is a chainloaded environment. In this case u-boot running on Android devices where you unfortunately don't have the possibility to use UPL.
As stated above it's purpose is to simplify the operations on the command line arguments from the previous stage and pass them to the next.
Typical example is to remove the skip initramfs or extract the value for the panel to pick the right dtb (not part of this patch series)
Is this something you could do in an U-Boot script using setexpr sub/gsub instead ?
Well that should be possible as the C strings are messy.
However, the intention is to be used from SPL where the setexpr sub/gsub would not be available.
Quoted 8 lines
Yes, I would like to see how this gets used in implementation too, as I'm wondering if we shouldn't just be also saving off something like "
prev_bl_bootargs" and leaving the rest to the board code to deal with. Maybe we should also add the android-specific helpers in a new file under an Android-relatedKconfigas well.Signature · 1 line
Tom
Will send the example in another patch series with detailed description.
TLDR; The boot.img contains as the main target the SPL u-boot build with barebone dts. Qcom has a thing called SMEM which can be used in runtime to detect the board and based on that we pick the correct dtb and jump to normal u-boot.
Also thanks for the good idea to place the helper under Android Kconfig.
Re: [PATCH 1/4] common: Add command line parsing utilities
Quoted 35 lines · phodina
Quoted 12 lines · Tom Rini
Quoted 11 lines · Marek Vasut
Quoted 10 lines · phodina
Quoted 7 lines · Marek Vasut
Quoted 4 lines · On 9/11/26 8:18 PM, Petr Hodina via B4 Relay wrote:
From: Petr Hodina <[email protected]>
Add a new utility library for parsing command line parameters in key=value format.
Is this reinventing environment or UPL ?
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
The target is a chainloaded environment. In this case u-boot running on Android devices where you unfortunately don't have the possibility to use UPL.
As stated above it's purpose is to simplify the operations on the command line arguments from the previous stage and pass them to the next.
Typical example is to remove the skip initramfs or extract the value for the panel to pick the right dtb (not part of this patch series)
Is this something you could do in an U-Boot script using setexpr sub/gsub instead ?
Well that should be possible as the C strings are messy.
However, the intention is to be used from SPL where the setexpr sub/gsub would not be available.
Quoted 6 lines
Yes, I would like to see how this gets used in implementation too, as I'm wondering if we shouldn't just be also saving off something like "
prev_bl_bootargs" and leaving the rest to the board code to deal with. Maybe we should also add the android-specific helpers in a new file under an Android-relatedKconfigas well.
Quoted 8 lines
Quoted 2 lines
Signature · 1 line
TomWill send the example in another patch series with detailed description.
TLDR; The boot.img contains as the main target the SPL u-boot build with barebone dts. Qcom has a thing called SMEM which can be used in runtime to detect the board and based on that we pick the correct dtb and jump to normal u-boot.
Also thanks for the good idea to place the helper under Android
Kconfig.
Ah, OK. So if we're going to be jumping to full U-Boot before the OS, it might be worth thinking about how to just parse enough of that and in turn /chosen/bootargs to pick the right dtb to pass along to full U-Boot, along with anything else, and save the larger modifications until later. But, I do await your follow-up showing the real use rather than further speculation. Thanks!
Signature · 1 line
Tom
PATCH 2/4 common: Add command line parameter masking functionality
In reply to Petr HodinaExtend cmdline_utils to support masking or replacing parameters in command line strings. This is useful for filtering sensitive data or modifying boot parameters.
--- include/cmdline_utils.h | 7 +++ lib/cmdline_utils.c | 150 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 157 insertions(+)
include/cmdline_utils.h +7 -0
@@ -18,4 +18,11 @@ struct cmdline_param {int parse_cmdline_params (const char *cmdline,struct cmdline_param *params,int count); +struct cmdline_mask_param { +const char *key; +const char *new_value; +}; + +char *mask_cmdline_params (const char *cmdline,struct cmdline_mask_param *params,int count); +#endif /* _CMDLINE_UTILS_H_ */
lib/cmdline_utils.c +150 -0
153 lines not on this page · raw message
Signature · 1 line
2.55.0
PATCH 3/4 common: Add Android bootloader parameter parsing helper
In reply to Petr HodinaAdd a convenience wrapper for parsing common Android bootloader parameters from the kernel command line. This simplifies extracting the numerous androidboot.* parameters used in Android systems.
--- include/cmdline_utils.h | 32 +++++++++++++++++++ lib/cmdline_utils.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+)
include/cmdline_utils.h +32 -0
@@ -25,4 +25,36 @@ struct cmdline_mask_param {char *mask_cmdline_params (const char *cmdline,struct cmdline_mask_param *params,int count); +struct androidboot_params { +char *hardware_ddr; +char *ddr_info; +char *ddr_size; + +char *dsi_display0; + +char *slot_suffix; +char *slot_retry_count; +char *slot_successful; + +char *hardware_platform; +char *hardware; +char *revision; +char *hardware_sku; +char *hardware_majorid; + +char *bootloader; +char *bootreason; +char *secure_boot; +char *mode; + +char *cdt_hwid; +char *dtb_idx; + +char *serialno; +}; + +int parse_androidboot_params (const char *cmdline,struct androidboot_params *params); + +void free_androidboot_params (struct androidboot_params *params); +#endif /* _CMDLINE_UTILS_H_ */
lib/cmdline_utils.c +85 -0
88 lines not on this page · raw message
Signature · 1 line
2.55.0
PATCH 4/4 arm: carry previous bootloader's bootargs into $bootargs
In reply to Petr HodinaThe existing SAVE_PREV_BL_FDT_ADDR / SAVE_PREV_BL_INITRAMFS_START_ADDR options surface the chained FDT base and an initramfs pointer in env, but the kernel command-line ABL had already prepared in /chosen/bootargs is silently dropped the moment U-Boot starts.
--- arch/arm/lib/save_prev_bl_data.c | 15 ++++++++++++++- boot/Kconfig | 8 ++++++++ 2 files changed, 22 insertions(+), 1 deletion(-)
arch/arm/lib/save_prev_bl_data.c +14 -1
@@ -66,7 +66,9 @@ int save_prev_bl_data(void)if (IS_ENABLED (CONFIG_SAVE_PREV_BL_FDT_ADDR ))env_set_addr ("prevbl_fdt_addr" , (void *)reg0); -if (!IS_ENABLED (CONFIG_SAVE_PREV_BL_INITRAMFS_START_ADDR )) + +if (!IS_ENABLED (CONFIG_SAVE_PREV_BL_INITRAMFS_START_ADDR ) && + !IS_ENABLED (CONFIG_SAVE_PREV_BL_BOOTARGS ))return 0 ; node =fdt_path_offset (fdt_blob,"/chosen" );
@@ -75,6 +77,17 @@ int save_prev_bl_data(void) __func__, reg0);return -ENODATA ; } + +if (IS_ENABLED (CONFIG_SAVE_PREV_BL_BOOTARGS )) { +const char *bootargs =fdt_getprop (fdt_blob, node,"bootargs" , +NULL ); + +if (bootargs && *bootargs) +env_set ("bootargs" , bootargs); + } + +if (!IS_ENABLED (CONFIG_SAVE_PREV_BL_INITRAMFS_START_ADDR )) +return 0 ;/* * linux,initrd-start property might be either 64 or 32 bit, * depending on primary bootloader implementation.
boot/Kconfig +8 -0
@@ -2036,6 +2036,14 @@ config SAVE_PREV_BL_INITRAMFS_START_ADDR If no initramfs was provided by previous bootloader, no env variables will be created. +config SAVE_PREV_BL_BOOTARGS + depends on ARM + bool "Save /chosen/bootargs from the previous bootloader's FDT into $bootargs" + help + When u-boot is chain-loaded from a primary bootloader that already + populated /chosen/bootargs in the device tree it handed off (Android + ABL) copy that string into U-Boot's bootargs environment variable. + menu "Configuration editor" config CEDIT
Signature · 1 line
2.55.0