From: Michael Opdenacker <michael.opdenacker@rootcommit.com>
To: openembedded-core@lists.openembedded.org
Cc: michael.opdenacker@rootcommit.com
Subject: Re: [PATCH] initramfs-framework: init: fix kernel cmdline parsing
Date: Fri, 3 Apr 2026 09:46:49 +0000 (UTC) [thread overview]
Message-ID: <36b63c79-2640-4fa7-9c82-d96ca77582ee@rootcommit.com> (raw)
In-Reply-To: <20260326173432.3286250-1-michael.opdenacker@rootcommit.com>
Greetings
On 3/26/26 6:34 PM, michael.opdenacker@rootcommit.com wrote:
> From: Michael Opdenacker <michael.opdenacker@rootcommit.com>
>
> Fix several issues with double quotes in kernel command line
>
> - Kernel options like 'opt="value"' were breaking the parser,
> causing the whole reminder of the command line to be ignored.
> The code only supported 'opt="word1 word2..."
>
> - Setting variables without removing quotes in the value
>
> - Setting variables to values with spaces without enclosing
> the value with quotes. This caused execution errors evaluating
> expressions like:
> bootparam_opt=word1 word2
>
> The first fix is particularly needed for people using the kernel
> "bootconfig" configuration parameters to add options to the kernel
> command line:
>
> CONFIG_BOOT_CONFIG=y
> CONFIG_BOOT_CONFIG_EMBED=y
> CONFIG_BOOT_CONFIG_EMBED_FILE="additional-bootargs.bootconfig"
>
> This mechanism systematically adds quotes around options
> with values, for example:
> init="/sbin/preinit"
>
> Without the fix, the wrong init program can be started from the
> initramfs and debug messages are ignored when "debug" is
> present after "init" in the kernel command line.
>
> For readability and performance sake, also use shell variable operators
> instead of "sed" to remove leading and trailing quotes.
>
> Tested both on host and target machines.
> With the below kernel command line:
> rootwait init="/sbin/preinit" debug root=/dev/mmcblk0p2 console=ttymxc0 dyndbg="file drivers/usb/core/hub.c +pltf" quiet
>
> The following variables are set:
> bootparam_rootwait="true"
> bootparam_init="/sbin/preinit"
> bootparam_root="/dev/mmcblk0p2"
> bootparam_debug="true"
> bootparam_console="ttymxc0"
> bootparam_dyndbg="file drivers/usb/core/hub.c +pltf"
> bootparam_quiet="true"
>
> Signed-off-by: Michael Opdenacker <michael.opdenacker@rootcommit.com>
> ---
> .../initrdscripts/initramfs-framework/init | 24 +++++++++++++++----
> 1 file changed, 19 insertions(+), 5 deletions(-)
>
> diff --git a/meta/recipes-core/initrdscripts/initramfs-framework/init b/meta/recipes-core/initrdscripts/initramfs-framework/init
> index 51db083e2e..67590ad765 100755
> --- a/meta/recipes-core/initrdscripts/initramfs-framework/init
> +++ b/meta/recipes-core/initrdscripts/initramfs-framework/init
> @@ -94,9 +94,11 @@ fi
> # populate bootparam environment
> for p in `cat /proc/cmdline`; do
> if [ -n "$quoted" ]; then
> - value="$value $p"
> - if [ "`echo $p | sed -e 's/\"$//'`" != "$p" ]; then
> - eval "bootparam_${quoted}=${value}"
> + p_rstripped=${p%\"}
> + value="$value $p_rstripped"
> + if [ "$p_rstripped" != "$p" ]; then
> + # End of a opt="word1 word2..." parameter
> + eval "bootparam_${quoted}=\"${value}\""
> unset quoted
> fi
> continue
> @@ -105,11 +107,23 @@ for p in `cat /proc/cmdline`; do
> opt=`echo $p | cut -d'=' -f1`
> opt=`echo $opt | sed -e 'y/.-/__/'`
> if [ "`echo $p | cut -d'=' -f1`" = "$p" ]; then
> + # opt parameter
> eval "bootparam_${opt}=true"
> else
> - value="`echo $p | cut -d'=' -f2-`"
> - if [ "`echo $value | sed -e 's/^\"//'`" != "$value" ]; then
> + value="`echo $p | cut -d'=' -f2-`" # Option value
> + value_lstripped=${value#\"}
> + value_rstripped=${value%\"}
> +
> + if [ "$value_lstripped" != "$value" ] && [ "$value_rstripped" != "$value" ]; then
> + # opt="value" parameter
> + eval "bootparam_${opt}=${value_lstripped%\"}"
> + continue
> + fi
> +
> + if [ "$value_lstripped" != "$value" ]; then
> + # Start of a opt="word1 word2..." parameter
> quoted=${opt}
> + value=${value_lstripped}
> continue
> fi
> eval "bootparam_${opt}=\"${value}\""
Any objections to merging this fix?
Cheers
Michael.
--
Root Commit
Embedded Linux Training and Consulting
https://rootcommit.com
prev parent reply other threads:[~2026-04-03 9:46 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-26 17:34 [PATCH] initramfs-framework: init: fix kernel cmdline parsing michael.opdenacker
2026-04-03 9:46 ` Michael Opdenacker [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=36b63c79-2640-4fa7-9c82-d96ca77582ee@rootcommit.com \
--to=michael.opdenacker@rootcommit.com \
--cc=openembedded-core@lists.openembedded.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.