diff mbox series

initramfs-framework: avoid external commands in rootfs resolution

Message ID 20260914055715.1787659-1-wenwfu@qti.qualcomm.com
State New
Headers show
Series initramfs-framework: avoid external commands in rootfs resolution | expand

Commit Message

Wenwen Fu Sept. 14, 2026, 5:57 a.m. UTC
The rootfs module uses echo, cut, and grep to resolve root=
identifiers. This starts several short-lived processes before
checking the root device.

Use POSIX shell case matching and parameter expansion for UUID,
PARTUUID, PARTLABEL, and LABEL identifiers. Validate ubiN:
identifiers with shell pattern matching while preserving the
existing behavior.

Measured on rb3gen2-core-kit with root=LABEL=otaroot using
rootfs-resolve-start and rootfs-resolve-end kernel markers:

  before: 18.195 ms
  after:   0.089 ms
  improvement: 18.106 ms (99.5%)

The overall rootfs time is also affected by storage mount
variability, so the resolution interval is the direct measurement.

Tested with dash and BusyBox sh syntax checks.

Signed-off-by: Wenwen Fu <wenwfu@qti.qualcomm.com>
---
 .../initrdscripts/initramfs-framework/rootfs  | 37 +++++++++++--------
 1 file changed, 22 insertions(+), 15 deletions(-)
diff mbox series

Patch

diff --git a/meta/recipes-core/initrdscripts/initramfs-framework/rootfs b/meta/recipes-core/initrdscripts/initramfs-framework/rootfs
index df0cbfb091..05557be211 100644
--- a/meta/recipes-core/initrdscripts/initramfs-framework/rootfs
+++ b/meta/recipes-core/initrdscripts/initramfs-framework/rootfs
@@ -21,21 +21,28 @@  rootfs_run() {
 		if [ -n "$bootparam_root" ]; then
 			debug "No e2fs compatible filesystem has been mounted, mounting $bootparam_root..."
 
-			if [ "`echo ${bootparam_root} | cut -c1-5`" = "UUID=" ]; then
-				root_uuid=`echo $bootparam_root | cut -c6-`
-				bootparam_root="/dev/disk/by-uuid/$root_uuid"
-			elif [ "`echo ${bootparam_root} | cut -c1-9`" = "PARTUUID=" ]; then
-				root_partuuid=`echo $bootparam_root | cut -c10-`
-				bootparam_root="/dev/disk/by-partuuid/$root_partuuid"
-			elif [ "`echo ${bootparam_root} | cut -c1-10`" = "PARTLABEL=" ]; then
-				root_partlabel=`echo $bootparam_root | cut -c11-`
-				bootparam_root="/dev/disk/by-partlabel/$root_partlabel"
-			elif [ "`echo ${bootparam_root} | cut -c1-6`" = "LABEL=" ]; then
-				root_label=`echo $bootparam_root | cut -c7-`
-				bootparam_root="/dev/disk/by-label/$root_label"
-			elif echo "${bootparam_root}" | grep -q '^ubi[0-9]\+:'; then
-				bootparam_rootfstype="ubifs"
-			fi
+			case "$bootparam_root" in
+				UUID=*)
+					bootparam_root="/dev/disk/by-uuid/${bootparam_root#UUID=}"
+					;;
+				PARTUUID=*)
+					bootparam_root="/dev/disk/by-partuuid/${bootparam_root#PARTUUID=}"
+					;;
+				PARTLABEL=*)
+					bootparam_root="/dev/disk/by-partlabel/${bootparam_root#PARTLABEL=}"
+					;;
+				LABEL=*)
+					bootparam_root="/dev/disk/by-label/${bootparam_root#LABEL=}"
+					;;
+				ubi[0-9]*:*)
+					ubi_prefix=${bootparam_root%%:*}
+					ubi_digits=${ubi_prefix#ubi}
+					case "$ubi_digits" in
+						''|*[!0-9]*) ;;
+						*) bootparam_rootfstype="ubifs" ;;
+					esac
+					;;
+			esac
 
 			if [ -e "$bootparam_root" ] || [ -n "$bootparam_rootfstype" ]; then
 				flags=""