public inbox for openembedded-core@lists.openembedded.org
 help / color / mirror / Atom feed
* [PATCH] initramfs-framework: init: fix kernel cmdline parsing
@ 2026-03-26 17:34 michael.opdenacker
  2026-04-03  9:46 ` Michael Opdenacker
  0 siblings, 1 reply; 2+ messages in thread
From: michael.opdenacker @ 2026-03-26 17:34 UTC (permalink / raw)
  To: openembedded-core; +Cc: Michael Opdenacker

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}\""


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-04-03  9:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-26 17:34 [PATCH] initramfs-framework: init: fix kernel cmdline parsing michael.opdenacker
2026-04-03  9:46 ` Michael Opdenacker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox