diff mbox series

[isar-cip-core,2/2] Secureboot: Wait until udev populates /dev

Message ID 20201125085538.1561-3-Quirin.Gylstorff@siemens.com (mailing list archive)
State Not Applicable
Headers show
Series Secureboot fixes | expand

Commit Message

Gylstorff Quirin Nov. 25, 2020, 8:55 a.m. UTC
From: Quirin Gylstorff <quirin.gylstorff@siemens.com>

In actual physical targets like ipc227e, with the current initramfs
local file, the system drops to initramfs shell during boot.

This is due to "blkid -o device" returning empty list since the udev
has not yet created the necessary entries in /dev.

Add a timeout to reattempt finding a valid partition before giving up.

Signed-off-by: Vijai Kumar K <Vijaikumar_Kanagarajan@mentor.com>
Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com>
---
 .../files/secure-boot-debian-local-patch      | 104 +++++++++++-------
 1 file changed, 64 insertions(+), 40 deletions(-)
diff mbox series

Patch

diff --git a/recipes-support/initramfs-config/files/secure-boot-debian-local-patch b/recipes-support/initramfs-config/files/secure-boot-debian-local-patch
index 219578c..cd2d271 100644
--- a/recipes-support/initramfs-config/files/secure-boot-debian-local-patch
+++ b/recipes-support/initramfs-config/files/secure-boot-debian-local-patch
@@ -1,79 +1,103 @@ 
---- local	2020-07-02 14:59:15.461895194 +0200
-+++ ../../../../../../../../../../../recipes-support/initramfs-config/files/local	2020-07-02 14:58:58.405730914 +0200
+--- local.orig	2020-11-18 14:42:43.540055680 +0530
++++ local	2020-11-18 20:15:48.687164540 +0530
 @@ -1,5 +1,4 @@
  # Local filesystem mounting			-*- shell-script -*-
 -
  local_top()
  {
  	if [ "${local_top_used}" != "yes" ]; then
-@@ -155,34 +154,47 @@
- local_mount_root()
+@@ -152,36 +151,70 @@
+ 	DEV="${real_dev}"
+ }
+ 
+-local_mount_root()
++local_find_by_uuid()
  {
- 	local_top
+-	local_top
 -	if [ -z "${ROOT}" ]; then
 -		panic "No root device specified. Boot arguments must include a root= parameter."
 -	fi
 -	local_device_setup "${ROOT}" "root file system"
 -	ROOT="${DEV}"
--
++	partitions="$1"
+ 
 -	# Get the root filesystem type if not set
 -	if [ -z "${ROOTFSTYPE}" ] || [ "${ROOTFSTYPE}" = auto ]; then
 -		FSTYPE=$(get_fstype "${ROOT}")
 -	else
 -		FSTYPE=${ROOTFSTYPE}
-+	if [ ! -e /conf/image_uuid ]; then
-+		 panic "could not find image_uuid to select correct root file system"
- 	fi
-+	local INITRAMFS_IMAGE_UUID=$(cat /conf/image_uuid)
-+	local partitions=$(blkid -o device)
+-	fi
 +	for part in $partitions; do
-+			if [ "$(blkid -p ${part} --match-types novfat -s USAGE -o value)" = "filesystem" ]; then
-+					local_device_setup "${part}" "root file system"
-+					ROOT="${DEV}"
++		if [ "$(blkid -p ${part} --match-types novfat -s USAGE -o value)" = "filesystem" ]; then
++			local_device_setup "${part}" "root file system"
++			ROOT="${DEV}"
 +
-+					# Get the root filesystem type if not set
-+					if [ -z "${ROOTFSTYPE}" ] || [ "${ROOTFSTYPE}" = auto ]; then
-+							FSTYPE=$(get_fstype "${ROOT}")
-+					else
-+							FSTYPE=${ROOTFSTYPE}
-+					fi
++			# Get the root filesystem type if not set
++			if [ -z "${ROOTFSTYPE}" ] || [ "${ROOTFSTYPE}" = auto ]; then
++				FSTYPE=$(get_fstype "${ROOT}")
++			else
++				FSTYPE=${ROOTFSTYPE}
++			fi
  
 -	local_premount
-+				local_premount
++			local_premount
  
 -	if [ "${readonly?}" = "y" ]; then
 -		roflag=-r
 -	else
 -		roflag=-w
 -	fi
-+				if [ "${readonly?}" = "y" ]; then
-+						roflag=-r
-+				else
-+						roflag=-w
-+				fi
-+				checkfs "${ROOT}" root "${FSTYPE}"
++			if [ "${readonly?}" = "y" ]; then
++				roflag=-r
++			else
++				roflag=-w
++			fi
++			checkfs "${ROOT}" root "${FSTYPE}"
  
 -	checkfs "${ROOT}" root "${FSTYPE}"
-+				# Mount root
-+				# shellcheck disable=SC2086
-+				if mount ${roflag} ${FSTYPE:+-t "${FSTYPE}"} ${ROOTFLAGS} "${ROOT}" "${rootmnt?}"; then
-+						if [ -e "${rootmnt?}"/etc/os-release ]; then
-+								image_uuid=$(sed -n 's/^IMAGE_UUID=//p' "${rootmnt?}"/etc/os-release | tr -d '"' )
-+								if [ "${INITRAMFS_IMAGE_UUID}" = "${image_uuid}" ]; then
-+										return
-+								fi
-+						fi
-+						umount "${rootmnt?}"
++			# Mount root
++			# shellcheck disable=SC2086
++			if mount ${roflag} ${FSTYPE:+-t "${FSTYPE}"} ${ROOTFLAGS} "${ROOT}" "${rootmnt?}"; then
++				if [ -e "${rootmnt?}"/etc/os-release ]; then
++				image_uuid=$(sed -n 's/^IMAGE_UUID=//p' "${rootmnt?}"/etc/os-release | tr -d '"' )
++					if [ "${INITRAMFS_IMAGE_UUID}" = "${image_uuid}" ]; then
++						return 0
++					fi
 +				fi
++				umount "${rootmnt?}"
 +			fi
++		fi
 +	done
-+	panic "Could not find ROOTFS with matching UUID $INITRAMFS_IMAGE_UUID"
++	return 1
++}
  
 -	# Mount root
 -	# shellcheck disable=SC2086
 -	if ! mount ${roflag} ${FSTYPE:+-t "${FSTYPE}"} ${ROOTFLAGS} "${ROOT}" "${rootmnt?}"; then
 -		panic "Failed to mount ${ROOT} as root file system."
--	fi
++local_mount_root()
++{
++	local_top
++	if [ ! -e /conf/image_uuid ]; then
++		 panic "could not find image_uuid to select correct root file system"
++	fi
++	local INITRAMFS_IMAGE_UUID=$(cat /conf/image_uuid)
++	local partitions=""
++	local ret=1
++	local timeout_uuid=0
++	while [ "${ret}" != 0 ] && [ "${timeout_uuid}" -le 10 ]; do
++		wait_for_udev 10
++		partitions=$(blkid -o device)
++		local_find_by_uuid "$partitions"
++		ret=$?
++		timeout_uuid="$(cat /proc/uptime)"
++		timeout_uuid="${timeout_uuid%%[. ]*}"
++		timeout_uuid=$((timeout_uuid - local_top_time))
++	done
++	if [ "${ret}" != 0 ]; then
++		panic "Could not find ROOTFS with matching UUID $INITRAMFS_IMAGE_UUID"
++	else
++		return $ret
+ 	fi
  }
  
- local_mount_fs()