cip-dev.lists.cip-project.org archive mirror
 help / color / mirror / Atom feed
From: "Quirin Gylstorff" <quirin.gylstorff@siemens.com>
To: Jan.Kiszka@siemens.com, cip-dev@lists.cip-project.org
Cc: Vijai Kumar K <Vijaikumar_Kanagarajan@mentor.com>,
	Quirin Gylstorff <quirin.gylstorff@siemens.com>
Subject: [cip-dev] [isar-cip-core][PATCH v2 2/2] Secureboot: Wait until udev populates /dev
Date: Mon, 30 Nov 2020 15:48:42 +0100	[thread overview]
Message-ID: <20201130144842.4221-3-Quirin.Gylstorff@siemens.com> (raw)
In-Reply-To: <20201130144842.4221-1-Quirin.Gylstorff@siemens.com>

[-- Attachment #1: Type: text/plain, Size: 5310 bytes --]

From: Vijai Kumar K <Vijaikumar_Kanagarajan@mentor.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 --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()
-- 
2.20.1


[-- Attachment #2: Type: text/plain, Size: 420 bytes --]


-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#5904): https://lists.cip-project.org/g/cip-dev/message/5904
Mute This Topic: https://lists.cip-project.org/mt/78609369/4520388
Group Owner: cip-dev+owner@lists.cip-project.org
Unsubscribe: https://lists.cip-project.org/g/cip-dev/leave/8129055/727948398/xyzzy [cip-dev@archiver.kernel.org]
-=-=-=-=-=-=-=-=-=-=-=-


  parent reply	other threads:[~2020-11-30 14:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-30 14:48 [cip-dev] [isar-cip-core][PATCH v2 0/2] Secureboot fixes Quirin Gylstorff
2020-11-30 14:48 ` [cip-dev] [isar-cip-core][PATCH v2 1/2] start-qemu.sh: Change OVMF binary names Quirin Gylstorff
2020-11-30 14:48 ` Quirin Gylstorff [this message]
2020-11-30 18:41 ` [cip-dev] [isar-cip-core][PATCH v2 0/2] Secureboot fixes Jan Kiszka

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=20201130144842.4221-3-Quirin.Gylstorff@siemens.com \
    --to=quirin.gylstorff@siemens.com \
    --cc=Jan.Kiszka@siemens.com \
    --cc=Vijaikumar_Kanagarajan@mentor.com \
    --cc=cip-dev@lists.cip-project.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).