[PATCH 0/7] Simplify writing initramfs hooks

34 views
Skip to first unread message

Jan Kiszka

unread,
Nov 11, 2024, 3:50:27 PM11/11/24
to isar-users, Quirin Gylstorff
Specifically while looking at the initramfs recipes we have in
isar-cip-core, it felt like it's time to simplify their creation and
offload the developers from all the related boilerplate bits. But the
benefit can also be observed with the initramfs recipes in isar itself.

Jan

Jan Kiszka (7):
initramfs-hook: Add infrastructure to ease writing hooks
doc: Describe initramfs customizations
isar-initramfs: Add initramfs-fsck-hook-ext4
initramfs-isar-example-hook: Convert recipe over to new hook.inc
initramfs-fsck-ext4-hook: Convert to hook.inc and improve
initramfs-tee-ftpm-hook: Convert to hook.inc
initramfs-tee-supplicant-hook: Convert to hook.inc

doc/user_manual.md | 54 ++++++++++++++
.../images/isar-initramfs.bb | 3 +-
.../initramfs-example/files/example.hook | 21 ------
.../initramfs-example/files/example.script | 23 ------
.../initramfs-example/files/local-top | 3 +
....bb => initramfs-isar-example-hook_0.1.bb} | 21 ++----
.../files/initramfs-fsck-hook-ext4.triggers | 0
.../initramfs-fsck-ext4-hook_0.3.bb | 14 ++++
.../initramfs-hook/files/hook-header.tmpl | 39 ++++++++++
.../initramfs-hook/files/script-header.tmpl | 26 +++++++
.../recipes-initramfs/initramfs-hook/hook.inc | 74 +++++++++++++++++++
.../files/{tee-ftpm.script => local-top} | 18 +----
.../files/tee-ftpm.hook | 28 -------
.../initramfs-tee-ftpm-hook_0.1.bb | 27 -------
.../initramfs-tee-ftpm-hook_0.2.bb | 15 ++++
.../{tee-supplicant.script => local-top} | 18 +----
.../files/tee-supplicant.hook | 36 ---------
.../initramfs-tee-supplicant-hook_0.1.bb | 27 -------
.../initramfs-tee-supplicant-hook_0.2.bb | 16 ++++
.../files/initramfs.fsck.ext4.hook | 39 ----------
.../initramfs-fsck-hook-ext4_0.2.bb | 18 -----
21 files changed, 252 insertions(+), 268 deletions(-)
delete mode 100644 meta-isar/recipes-initramfs/initramfs-example/files/example.hook
delete mode 100644 meta-isar/recipes-initramfs/initramfs-example/files/example.script
create mode 100644 meta-isar/recipes-initramfs/initramfs-example/files/local-top
rename meta-isar/recipes-initramfs/initramfs-example/{initramfs-example.bb => initramfs-isar-example-hook_0.1.bb} (63%)
rename meta/{recipes-support => recipes-initramfs}/initramfs-fsck-hook/files/initramfs-fsck-hook-ext4.triggers (100%)
create mode 100644 meta/recipes-initramfs/initramfs-fsck-hook/initramfs-fsck-ext4-hook_0.3.bb
create mode 100644 meta/recipes-initramfs/initramfs-hook/files/hook-header.tmpl
create mode 100644 meta/recipes-initramfs/initramfs-hook/files/script-header.tmpl
create mode 100644 meta/recipes-initramfs/initramfs-hook/hook.inc
rename meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/{tee-ftpm.script => local-top} (75%)
delete mode 100644 meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/tee-ftpm.hook
delete mode 100644 meta/recipes-initramfs/initramfs-tee-ftpm-hook/initramfs-tee-ftpm-hook_0.1.bb
create mode 100644 meta/recipes-initramfs/initramfs-tee-ftpm-hook/initramfs-tee-ftpm-hook_0.2.bb
rename meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/{tee-supplicant.script => local-top} (68%)
delete mode 100644 meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/tee-supplicant.hook
delete mode 100644 meta/recipes-initramfs/initramfs-tee-supplicant-hook/initramfs-tee-supplicant-hook_0.1.bb
create mode 100644 meta/recipes-initramfs/initramfs-tee-supplicant-hook/initramfs-tee-supplicant-hook_0.2.bb
delete mode 100644 meta/recipes-support/initramfs-fsck-hook/files/initramfs.fsck.ext4.hook
delete mode 100644 meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-hook-ext4_0.2.bb

--
2.43.0

Jan Kiszka

unread,
Nov 11, 2024, 3:50:28 PM11/11/24
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

Allows to drop the own hook recipe and makes the local-top boot script
effectively a one-liner.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
.../images/isar-initramfs.bb | 2 +-
.../initramfs-example/files/example.hook | 21 -----------------
.../initramfs-example/files/example.script | 23 -------------------
.../initramfs-example/files/local-top | 3 +++
....bb => initramfs-isar-example-hook_0.1.bb} | 21 ++++++-----------
5 files changed, 11 insertions(+), 59 deletions(-)
delete mode 100644 meta-isar/recipes-initramfs/initramfs-example/files/example.hook
delete mode 100644 meta-isar/recipes-initramfs/initramfs-example/files/example.script
create mode 100644 meta-isar/recipes-initramfs/initramfs-example/files/local-top
rename meta-isar/recipes-initramfs/initramfs-example/{initramfs-example.bb => initramfs-isar-example-hook_0.1.bb} (63%)

diff --git a/meta-isar/recipes-initramfs/images/isar-initramfs.bb b/meta-isar/recipes-initramfs/images/isar-initramfs.bb
index 4df9e0b8..71dbaa43 100644
--- a/meta-isar/recipes-initramfs/images/isar-initramfs.bb
+++ b/meta-isar/recipes-initramfs/images/isar-initramfs.bb
@@ -14,6 +14,6 @@ INITRAMFS_PREINSTALL += " \

# Recipes that should be installed into the initramfs build rootfs.
INITRAMFS_INSTALL += " \
- initramfs-example \
+ initramfs-isar-example-hook \
initramfs-fsck-hook-ext4 \
"
diff --git a/meta-isar/recipes-initramfs/initramfs-example/files/example.hook b/meta-isar/recipes-initramfs/initramfs-example/files/example.hook
deleted file mode 100644
index ba848c92..00000000
--- a/meta-isar/recipes-initramfs/initramfs-example/files/example.hook
+++ /dev/null
@@ -1,21 +0,0 @@
-#!/bin/sh
-# Example hook script.
-#
-# See "HOOK SCRIPTS" in initramfs-tools(7) for details.
-
-set -e
-
-PREREQ=""
-prereqs()
-{
- echo "$PREREQ"
-}
-case $1 in
-prereqs)
- prereqs
- exit 0
- ;;
-esac
-
-. /usr/share/initramfs-tools/hook-functions
-# Begin real processing below this line
diff --git a/meta-isar/recipes-initramfs/initramfs-example/files/example.script b/meta-isar/recipes-initramfs/initramfs-example/files/example.script
deleted file mode 100644
index c55e9ea7..00000000
--- a/meta-isar/recipes-initramfs/initramfs-example/files/example.script
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/bin/sh
-# Example boot script.
-#
-# See "BOOT SCRIPTS" in initramfs-tools(7) for details.
-
-set -e
-
-PREREQ=""
-prereqs()
-{
- echo "$PREREQ"
-}
-case $1 in
-prereqs)
- prereqs
- exit 0
- ;;
-esac
-
-. /scripts/functions
-# Begin real processing below this line
-
-log_success_msg "Hello from ISAR!"
diff --git a/meta-isar/recipes-initramfs/initramfs-example/files/local-top b/meta-isar/recipes-initramfs/initramfs-example/files/local-top
new file mode 100644
index 00000000..66e382b4
--- /dev/null
+++ b/meta-isar/recipes-initramfs/initramfs-example/files/local-top
@@ -0,0 +1,3 @@
+# Script header is provided by initramfs-hook/hook.inc
+
+log_success_msg "Hello from ISAR!"
diff --git a/meta-isar/recipes-initramfs/initramfs-example/initramfs-example.bb b/meta-isar/recipes-initramfs/initramfs-example/initramfs-isar-example-hook_0.1.bb
similarity index 63%
rename from meta-isar/recipes-initramfs/initramfs-example/initramfs-example.bb
rename to meta-isar/recipes-initramfs/initramfs-example/initramfs-isar-example-hook_0.1.bb
index c336dda9..8c600639 100644
--- a/meta-isar/recipes-initramfs/initramfs-example/initramfs-example.bb
+++ b/meta-isar/recipes-initramfs/initramfs-example/initramfs-isar-example-hook_0.1.bb
@@ -4,37 +4,30 @@
#
# This software is a part of ISAR.

+require recipes-initramfs/initramfs-hook/hook.inc
+
DESCRIPTION = "Sample initramfs module for ISAR"
MAINTAINER = "Your name here <y...@domain.com>"
-DEBIAN_DEPENDS = "initramfs-tools"

# If the conf-hook enables BUSYBOX=y, busybox is needed:
DEBIAN_DEPENDS .= ", busybox"

-SRC_URI = " \
+SRC_URI += " \
file://example.conf-hook \
- file://example.hook \
- file://example.script \
+ file://local-top \
"

-inherit dpkg-raw
-
do_install[cleandirs] += " \
${D}/usr/share/initramfs-tools/conf-hooks.d \
- ${D}/usr/share/initramfs-tools/hooks \
- ${D}/usr/share/initramfs-tools/scripts/local-top \
"
-do_install() {
+do_install:append() {
# See "CONFIGURATION HOOK SCRIPTS" in initramfs-tools(7) for details.
install "${WORKDIR}/example.conf-hook" \
"${D}/usr/share/initramfs-tools/conf-hooks.d/isar-example"

- # See "HOOK SCRIPTS" in initramfs-tools(7) for details.
- install "${WORKDIR}/example.hook" \
- "${D}/usr/share/initramfs-tools/hooks/isar-example"
+ # See "HOOK SCRIPTS" in initramfs-tools(7) for details on
+ # hook-header[.tmpl] + hook.

# Note that there are other places where a boot script might be deployed to,
# apart from local-top. See "BOOT SCRIPTS" in initramfs-tools(7) for details.
- install "${WORKDIR}/example.script" \
- "${D}/usr/share/initramfs-tools/scripts/local-top/example.script"
}
--
2.43.0

Jan Kiszka

unread,
Nov 11, 2024, 3:50:28 PM11/11/24
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

Ensure basic CI coverage for this hook recipe.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
meta-isar/recipes-initramfs/images/isar-initramfs.bb | 1 +
1 file changed, 1 insertion(+)

diff --git a/meta-isar/recipes-initramfs/images/isar-initramfs.bb b/meta-isar/recipes-initramfs/images/isar-initramfs.bb
index aaa0350a..4df9e0b8 100644
--- a/meta-isar/recipes-initramfs/images/isar-initramfs.bb
+++ b/meta-isar/recipes-initramfs/images/isar-initramfs.bb
@@ -15,4 +15,5 @@ INITRAMFS_PREINSTALL += " \
# Recipes that should be installed into the initramfs build rootfs.
INITRAMFS_INSTALL += " \
initramfs-example \
+ initramfs-fsck-hook-ext4 \
"
--
2.43.0

Jan Kiszka

unread,
Nov 11, 2024, 3:50:29 PM11/11/24
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

xxx

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
.../initramfs-hook/files/hook-header.tmpl | 39 ++++++++++
.../initramfs-hook/files/script-header.tmpl | 26 +++++++
.../recipes-initramfs/initramfs-hook/hook.inc | 74 +++++++++++++++++++
3 files changed, 139 insertions(+)
create mode 100644 meta/recipes-initramfs/initramfs-hook/files/hook-header.tmpl
create mode 100644 meta/recipes-initramfs/initramfs-hook/files/script-header.tmpl
create mode 100644 meta/recipes-initramfs/initramfs-hook/hook.inc

diff --git a/meta/recipes-initramfs/initramfs-hook/files/hook-header.tmpl b/meta/recipes-initramfs/initramfs-hook/files/hook-header.tmpl
new file mode 100644
index 00000000..ee30d691
--- /dev/null
+++ b/meta/recipes-initramfs/initramfs-hook/files/hook-header.tmpl
@@ -0,0 +1,39 @@
+#!/bin/sh
+#
+# Copyright (c) Siemens AG, 2024
+#
+# Authors:
+# Jan Kiszka <jan.k...@siemens.com>
+#
+# SPDX-License-Identifier: MIT
+#
+
+set -e
+
+prereqs()
+{
+ echo "${HOOK_PREREQ}"
+}
+
+case $1 in
+prereqs)
+ prereqs
+ exit 0
+ ;;
+esac
+
+. /usr/share/initramfs-tools/hook-functions
+
+for module in ${HOOK_ADD_MODULES}; do
+ manual_add_modules $module
+done
+
+for executable in ${HOOK_COPY_EXECS}; do
+ if exec_path=$(command -v $executable 2>/dev/null); then
+ copy_exec "$exec_path"
+ else
+ echo "(ERROR): Unable to copy $executable" >&2
+ exit 1
+ fi
+done
+
diff --git a/meta/recipes-initramfs/initramfs-hook/files/script-header.tmpl b/meta/recipes-initramfs/initramfs-hook/files/script-header.tmpl
new file mode 100644
index 00000000..faa1a644
--- /dev/null
+++ b/meta/recipes-initramfs/initramfs-hook/files/script-header.tmpl
@@ -0,0 +1,26 @@
+#!/bin/sh
+#
+# Copyright (c) Siemens AG, 2024
+#
+# Authors:
+# Jan Kiszka <jan.k...@siemens.com>
+#
+# SPDX-License-Identifier: MIT
+#
+
+set -e
+
+prereqs()
+{
+ echo "${SCRIPT_PREREQ}"
+}
+
+case $1 in
+prereqs)
+ prereqs
+ exit 0
+ ;;
+esac
+
+. /scripts/functions
+
diff --git a/meta/recipes-initramfs/initramfs-hook/hook.inc b/meta/recipes-initramfs/initramfs-hook/hook.inc
new file mode 100644
index 00000000..5509c074
--- /dev/null
+++ b/meta/recipes-initramfs/initramfs-hook/hook.inc
@@ -0,0 +1,74 @@
+#
+# Copyright (c) Siemens AG, 2024
+#
+# Authors:
+# Jan Kiszka <jan.k...@siemens.com>
+#
+# SPDX-License-Identifier: MIT
+#
+
+FILESPATH:append := ":${FILE_DIRNAME}/files"
+
+inherit dpkg-raw
+
+SRC_URI = " \
+ file://hook-header.tmpl \
+ file://script-header.tmpl"
+
+TEMPLATE_FILES = " \
+ hook-header.tmpl \
+ script-header.tmpl"
+
+TEMPLATE_VARS:append = " \
+ HOOK_PREREQ \
+ HOOK_ADD_MODULES \
+ HOOK_COPY_EXECS \
+ SCRIPT_PREREQ"
+
+HOOK_PREREQ ?= ""
+HOOK_ADD_MODULES ?= ""
+HOOK_COPY_EXECS ?= ""
+SCRIPT_PREREQ ?= ""
+
+DEBIAN_DEPENDS = "initramfs-tools"
+
+def get_initramfs_hook_name(d):
+ name = d.getVar('BPN')
+ if name.startswith("initramfs-"):
+ name = name[10:]
+ if name.endswith("-hook"):
+ name = name[:-5]
+ return name
+
+INITRAMFS_HOOK_NAME ?= "${@get_initramfs_hook_name(d)}"
+
+do_install() {
+ if [ -f "${WORKDIR}/hook" ] || [ -n "${HOOK_COPY_EXECS}" ] || \
+ [ -n "${HOOK_ADD_MODULES}" ]; then
+ rm -rf "${D}/usr/share/initramfs-tools/hooks"
+ install -d -m 0755 "${D}/usr/share/initramfs-tools/hooks"
+
+ install -m 0755 "${WORKDIR}/hook-header" \
+ "${D}/usr/share/initramfs-tools/hooks/${INITRAMFS_HOOK_NAME}"
+ if [ -f "${WORKDIR}/hook" ]; then
+ cat "${WORKDIR}/hook" >> \
+ "${D}/usr/share/initramfs-tools/hooks/${INITRAMFS_HOOK_NAME}"
+ else
+ echo "exit 0" >> \
+ "${D}/usr/share/initramfs-tools/hooks/${INITRAMFS_HOOK_NAME}"
+ fi
+ fi
+
+ for script in init-top init-premount local-top nfs-top local-block \
+ local-premount nfs-premount local-bottom nfs-bottom \
+ init-bottom; do
+ if [ ! -f "${WORKDIR}/$script" ]; then
+ continue
+ fi
+
+ rm -rf "${D}/usr/share/initramfs-tools/scripts/$script"
+ install -d -m 0755 "${D}/usr/share/initramfs-tools/scripts/$script"
+ install -m 0755 "${WORKDIR}/$script" \
+ "${D}/usr/share/initramfs-tools/scripts/$script/${INITRAMFS_HOOK_NAME}"
+ done
+}
--
2.43.0

Jan Kiszka

unread,
Nov 11, 2024, 3:50:29 PM11/11/24
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

Document to new hook.inc as well as the preexisting initramfs class.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
doc/user_manual.md | 54 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 54 insertions(+)

diff --git a/doc/user_manual.md b/doc/user_manual.md
index 284847c8..7e04c7e8 100644
--- a/doc/user_manual.md
+++ b/doc/user_manual.md
@@ -1600,3 +1600,57 @@ CONTAINER_DELETE_AFTER_LOAD = "1"

SRC_URI += "docker://debian;digest=sha256:f528891ab1aa484bf7233dbcc84f3c806c3e427571d75510a9d74bb5ec535b33;tag=bookworm-20240701-slim"
```
+
+## Customize the initramfs
+
+Isar supports the customization of initramfs images by providing an
+infrastructure for quickly creating hooks and by allowing to replace the
+Debian-generated image with a separately built one.
+
+### Creating initramfs hooks
+
+To create an initramfs hook that adds tools or modules to the image and may
+also run custom scripts during boot, use the include file
+`recipes-initramfs/initramfs-hook/hook.inc`. It is controlled via a number of
+variables:
+
+ - `HOOK_PREREQ` defines the prerequisites for running the hook script.
+ - `HOOK_ADD_MODULES` passes the provided modules names to the
+ `manual_add_modules` function during initramfs creation.
+ - `HOOK_COPY_EXECS` identifies the source of the passed executables on the
+ rootfs that runs mkinitramfs and passes that to `copy_exec`. If an
+ executable is not found, an error thrown, and the creation fails.
+ - `SCRIPT_PREREQ` defines the prerequisites for running the boot script.
+
+If the generated hook script is not sufficient, you can append an own
+bottom-half script by providing a `hook` file in `${WORKDIR}`. It will be
+appended to the `hook-header` that the helper generates.
+
+For running a custom script during boot-up, provide a bottom-half file in
+`${WORKDIR}`. Its name defines where it is hooked up with the initramfs boot
+process: `init-top`, `init-premount`, `local-top`, `nfs-top`, `local-block`,
+`local-premount`, `nfs-premount`, `local-bottom`, `nfs-bottom`, `init-bottom`
+
+See https://manpages.debian.org/stable/initramfs-tools-core/initramfs-tools.7.en.html
+for further details.
+
+The hook recipe should follow the naming convention `initramfs-<hook-name>-hook`
+so that its scripts will then be called `<hook-name>` in the generated
+initramfs.
+
+See `initramfs-example` for an exemplary hook recipe.
+
+### Creating an initramfs image aside the rootfs
+
+To avoid shipping all tools and binaries needed to generate an initramfs, isar
+provides the initramfs class. It creates a temporary Debian rootfs with all
+those dependencies and generates the initramfs from there, rather than the
+target's rootfs.
+
+This initramfs class should be pulled in by an image recipe. Said recipe
+specifies all dependencies of the initramfs via `INITRAMFS_INSTALL` for
+self-built packages and `INITRAMFS_PREINSTALL` for prebuilt ones, analogously
+to the respective `IMAGE_*` variables. Note that the kernel is automatically
+added to `INITRAMFS_INSTALL` if `KERNEL_NAME` is set.
+
+See `isar-initramfs` for an example recipe.
--
2.43.0

Jan Kiszka

unread,
Nov 11, 2024, 3:50:29 PM11/11/24
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

Reduces the own bits significantly.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
.../files/{tee-ftpm.script => local-top} | 18 +-----------
.../files/tee-ftpm.hook | 28 -------------------
.../initramfs-tee-ftpm-hook_0.1.bb | 27 ------------------
.../initramfs-tee-ftpm-hook_0.2.bb | 15 ++++++++++
4 files changed, 16 insertions(+), 72 deletions(-)
rename meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/{tee-ftpm.script => local-top} (75%)
delete mode 100644 meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/tee-ftpm.hook
delete mode 100644 meta/recipes-initramfs/initramfs-tee-ftpm-hook/initramfs-tee-ftpm-hook_0.1.bb
create mode 100644 meta/recipes-initramfs/initramfs-tee-ftpm-hook/initramfs-tee-ftpm-hook_0.2.bb

diff --git a/meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/tee-ftpm.script b/meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/local-top
similarity index 75%
rename from meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/tee-ftpm.script
rename to meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/local-top
index 3355a7e0..989bf288 100644
--- a/meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/tee-ftpm.script
+++ b/meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/local-top
@@ -1,4 +1,4 @@
-#!/bin/sh
+#
# Copyright (c) Siemens AG, 2023
#
# Authors:
@@ -7,22 +7,6 @@
# SPDX-License-Identifier: MIT
#

-set -e
-
-PREREQ="tee-supplicant"
-prereqs()
-{
- echo "$PREREQ"
-}
-case $1 in
-prereqs)
- prereqs
- exit 0
- ;;
-esac
-
-. /scripts/functions
-
FTPM_DEV=/dev/tpmrm0

# The tee-supplicant would take some time to be discovered, 30 seconds should
diff --git a/meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/tee-ftpm.hook b/meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/tee-ftpm.hook
deleted file mode 100644
index e80f00b4..00000000
--- a/meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/tee-ftpm.hook
+++ /dev/null
@@ -1,28 +0,0 @@
-#!/bin/sh
-# Copyright (c) Siemens AG, 2023
-#
-# Authors:
-# Su Bao Cheng <baoch...@siemens.com>
-#
-# SPDX-License-Identifier: MIT
-#
-
-set -e
-
-PREREQ="tee-supplicant"
-prereqs()
-{
- echo "$PREREQ"
-}
-case $1 in
-prereqs)
- prereqs
- exit 0
- ;;
-esac
-
-. /usr/share/initramfs-tools/hook-functions
-
-# The tpm_ftpm_tee.ko does not exist in any stock debian kernels, it could be
-# provided by customized kernel.
-manual_add_modules tpm_ftpm_tee
diff --git a/meta/recipes-initramfs/initramfs-tee-ftpm-hook/initramfs-tee-ftpm-hook_0.1.bb b/meta/recipes-initramfs/initramfs-tee-ftpm-hook/initramfs-tee-ftpm-hook_0.1.bb
deleted file mode 100644
index 82fec1bb..00000000
--- a/meta/recipes-initramfs/initramfs-tee-ftpm-hook/initramfs-tee-ftpm-hook_0.1.bb
+++ /dev/null
@@ -1,27 +0,0 @@
-# Copyright (c) Siemens AG, 2023
-#
-# Authors:
-# Su Bao Cheng <baoch...@siemens.com>
-#
-# SPDX-License-Identifier: MIT
-#
-
-inherit dpkg-raw
-
-SRC_URI += " \
- file://tee-ftpm.hook \
- file://tee-ftpm.script \
- "
-
-DEBIAN_DEPENDS = "initramfs-tools"
-
-do_install[cleandirs] += " \
- ${D}/usr/share/initramfs-tools/hooks \
- ${D}/usr/share/initramfs-tools/scripts/local-top"
-
-do_install() {
- install -m 0755 "${WORKDIR}/tee-ftpm.hook" \
- "${D}/usr/share/initramfs-tools/hooks/tee-ftpm"
- install -m 0755 "${WORKDIR}/tee-ftpm.script" \
- "${D}/usr/share/initramfs-tools/scripts/local-top/tee-ftpm"
-}
diff --git a/meta/recipes-initramfs/initramfs-tee-ftpm-hook/initramfs-tee-ftpm-hook_0.2.bb b/meta/recipes-initramfs/initramfs-tee-ftpm-hook/initramfs-tee-ftpm-hook_0.2.bb
new file mode 100644
index 00000000..9f77c158
--- /dev/null
+++ b/meta/recipes-initramfs/initramfs-tee-ftpm-hook/initramfs-tee-ftpm-hook_0.2.bb
@@ -0,0 +1,15 @@
+# Copyright (c) Siemens AG, 2023-2024
+#
+# Authors:
+# Su Bao Cheng <baoch...@siemens.com>
+#
+# SPDX-License-Identifier: MIT
+#
+
+require recipes-initramfs/initramfs-hook/hook.inc
+
+SRC_URI += "file://local-top"
+
+HOOK_PREREQ = "tee-supplicant"
+HOOK_ADD_MODULES = "tpm_ftpm_tee"
+SCRIPT_PREREQ = "tee-supplicant"
--
2.43.0

Jan Kiszka

unread,
Nov 11, 2024, 3:50:29 PM11/11/24
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

Use the convention and helping features of the new initramfs hook.inc to
simplify this hook. We move it under recipes-initramfs to align with
other recipes there. Another change is making fsck.ext4 mandatory, both
as dependency and while copying it in via the helper - there is no
reason for this recipe to almost silently ignore any unavailability.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
.../images/isar-initramfs.bb | 2 +-
.../files/initramfs-fsck-hook-ext4.triggers | 0
.../initramfs-fsck-ext4-hook_0.3.bb | 14 +++++++
.../files/initramfs.fsck.ext4.hook | 39 -------------------
.../initramfs-fsck-hook-ext4_0.2.bb | 18 ---------
5 files changed, 15 insertions(+), 58 deletions(-)
rename meta/{recipes-support => recipes-initramfs}/initramfs-fsck-hook/files/initramfs-fsck-hook-ext4.triggers (100%)
create mode 100644 meta/recipes-initramfs/initramfs-fsck-hook/initramfs-fsck-ext4-hook_0.3.bb
delete mode 100644 meta/recipes-support/initramfs-fsck-hook/files/initramfs.fsck.ext4.hook
delete mode 100644 meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-hook-ext4_0.2.bb

diff --git a/meta-isar/recipes-initramfs/images/isar-initramfs.bb b/meta-isar/recipes-initramfs/images/isar-initramfs.bb
index 71dbaa43..d2a946f7 100644
--- a/meta-isar/recipes-initramfs/images/isar-initramfs.bb
+++ b/meta-isar/recipes-initramfs/images/isar-initramfs.bb
@@ -15,5 +15,5 @@ INITRAMFS_PREINSTALL += " \
# Recipes that should be installed into the initramfs build rootfs.
INITRAMFS_INSTALL += " \
initramfs-isar-example-hook \
- initramfs-fsck-hook-ext4 \
+ initramfs-fsck-ext4-hook \
"
diff --git a/meta/recipes-support/initramfs-fsck-hook/files/initramfs-fsck-hook-ext4.triggers b/meta/recipes-initramfs/initramfs-fsck-hook/files/initramfs-fsck-hook-ext4.triggers
similarity index 100%
rename from meta/recipes-support/initramfs-fsck-hook/files/initramfs-fsck-hook-ext4.triggers
rename to meta/recipes-initramfs/initramfs-fsck-hook/files/initramfs-fsck-hook-ext4.triggers
diff --git a/meta/recipes-initramfs/initramfs-fsck-hook/initramfs-fsck-ext4-hook_0.3.bb b/meta/recipes-initramfs/initramfs-fsck-hook/initramfs-fsck-ext4-hook_0.3.bb
new file mode 100644
index 00000000..9e9654ad
--- /dev/null
+++ b/meta/recipes-initramfs/initramfs-fsck-hook/initramfs-fsck-ext4-hook_0.3.bb
@@ -0,0 +1,14 @@
+# This software is a part of ISAR.
+# Copyright (C) Siemens AG, 2019-2024
+#
+# SPDX-License-Identifier: MIT
+
+DESCRIPTION = "Recipe to add fsck hook to the initramfs"
+
+require recipes-initramfs/initramfs-hook/hook.inc
+
+SRC_URI += "file://initramfs-fsck-hook-ext4.triggers"
+
+HOOK_COPY_EXECS = "fsck fsck.ext4 logsave"
+
+DEBIAN_DEPENDS += ", e2fsprogs, logsave"
diff --git a/meta/recipes-support/initramfs-fsck-hook/files/initramfs.fsck.ext4.hook b/meta/recipes-support/initramfs-fsck-hook/files/initramfs.fsck.ext4.hook
deleted file mode 100644
index 259b73b4..00000000
--- a/meta/recipes-support/initramfs-fsck-hook/files/initramfs.fsck.ext4.hook
+++ /dev/null
@@ -1,39 +0,0 @@
-# This software is a part of ISAR.
-# Copyright (C) Siemens AG, 2019
-#
-# SPDX-License-Identifier: MIT
-
-#!/bin/sh
-
-set -e
-
-PREREQ=""
-
-prereqs()
-{
- echo "$PREREQ"
-}
-
-case $1 in
-prereqs)
- prereqs
- exit 0
- ;;
-esac
-
-. /usr/share/initramfs-tools/scripts/functions
-. /usr/share/initramfs-tools/hook-functions
-
-if [ ! -x /sbin/fsck ]; then
- echo "Warning: couldn't find /sbin/fsck!"
- exit 0
-fi
-
-copy_exec /sbin/fsck
-copy_exec /sbin/logsave
-
-if prog="$(command -v fsck.ext4)"; then
- copy_exec "$prog"
-else
- echo "Warning: /sbin/fsck.ext4 doesn't exist, can't install to initramfs, ignoring."
-fi
diff --git a/meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-hook-ext4_0.2.bb b/meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-hook-ext4_0.2.bb
deleted file mode 100644
index 9860dbc8..00000000
--- a/meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-hook-ext4_0.2.bb
+++ /dev/null
@@ -1,18 +0,0 @@
-# This software is a part of ISAR.
-# Copyright (C) Siemens AG, 2019
-#
-# SPDX-License-Identifier: MIT
-
-
-DESCRIPTION = "Recipe to add fsck hook to the initramfs"
-
-inherit dpkg-raw
-SRC_URI = "file://initramfs-fsck-hook-ext4.triggers \
- file://initramfs.fsck.ext4.hook \
- "
-
-
-do_install() {
- install -m 0755 -d ${D}/etc/initramfs-tools/hooks
- install -m 0740 ${WORKDIR}/initramfs.fsck.ext4.hook ${D}/etc/initramfs-tools/hooks/fsck.ext4.hook
-}
--
2.43.0

Jan Kiszka

unread,
Nov 11, 2024, 3:50:30 PM11/11/24
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

Reduces the own bits significantly.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
.../{tee-supplicant.script => local-top} | 18 +---------
.../files/tee-supplicant.hook | 36 -------------------
.../initramfs-tee-supplicant-hook_0.1.bb | 27 --------------
.../initramfs-tee-supplicant-hook_0.2.bb | 16 +++++++++
4 files changed, 17 insertions(+), 80 deletions(-)
rename meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/{tee-supplicant.script => local-top} (68%)
delete mode 100644 meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/tee-supplicant.hook
delete mode 100644 meta/recipes-initramfs/initramfs-tee-supplicant-hook/initramfs-tee-supplicant-hook_0.1.bb
create mode 100644 meta/recipes-initramfs/initramfs-tee-supplicant-hook/initramfs-tee-supplicant-hook_0.2.bb

diff --git a/meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/tee-supplicant.script b/meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/local-top
similarity index 68%
rename from meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/tee-supplicant.script
rename to meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/local-top
index ac01d7ec..575a742d 100644
--- a/meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/tee-supplicant.script
+++ b/meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/local-top
@@ -1,4 +1,4 @@
-#!/bin/sh
+#
# Copyright (c) Siemens AG, 2023
#
# Authors:
@@ -7,22 +7,6 @@
# SPDX-License-Identifier: MIT
#

-set -e
-
-PREREQ=""
-prereqs()
-{
- echo "$PREREQ"
-}
-case $1 in
-prereqs)
- prereqs
- exit 0
- ;;
-esac
-
-. /scripts/functions
-
/usr/sbin/modprobe optee
/usr/sbin/tee-supplicant -d

diff --git a/meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/tee-supplicant.hook b/meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/tee-supplicant.hook
deleted file mode 100644
index 3e2f4016..00000000
--- a/meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/tee-supplicant.hook
+++ /dev/null
@@ -1,36 +0,0 @@
-#!/bin/sh
-# Copyright (c) Siemens AG, 2023
-#
-# Authors:
-# Su Bao Cheng <baoch...@siemens.com>
-#
-# SPDX-License-Identifier: MIT
-#
-
-set -e
-
-PREREQ=""
-prereqs()
-{
- echo "$PREREQ"
-}
-case $1 in
-prereqs)
- prereqs
- exit 0
- ;;
-esac
-
-. /usr/share/initramfs-tools/hook-functions
-
-hook_error() {
- echo "(ERROR): $1" >&2
- exit 1
-}
-
-# For stock debian bookworm arm64 kernel, these two .ko exist, but not built-in.
-manual_add_modules tee
-manual_add_modules optee
-
-copy_exec /usr/sbin/tee-supplicant || hook_error "/usr/sbin/tee-supplicant not found"
-copy_exec /usr/bin/pgrep || hook_error "/usr/bin/pgrep not found"
diff --git a/meta/recipes-initramfs/initramfs-tee-supplicant-hook/initramfs-tee-supplicant-hook_0.1.bb b/meta/recipes-initramfs/initramfs-tee-supplicant-hook/initramfs-tee-supplicant-hook_0.1.bb
deleted file mode 100644
index a7a19bee..00000000
--- a/meta/recipes-initramfs/initramfs-tee-supplicant-hook/initramfs-tee-supplicant-hook_0.1.bb
+++ /dev/null
@@ -1,27 +0,0 @@
-# Copyright (c) Siemens AG, 2023
-#
-# Authors:
-# Su Bao Cheng <baoch...@siemens.com>
-#
-# SPDX-License-Identifier: MIT
-#
-
-inherit dpkg-raw
-
-SRC_URI += " \
- file://tee-supplicant.hook \
- file://tee-supplicant.script \
- "
-
-DEBIAN_DEPENDS = "initramfs-tools, tee-supplicant, procps"
-
-do_install[cleandirs] += " \
- ${D}/usr/share/initramfs-tools/hooks \
- ${D}/usr/share/initramfs-tools/scripts/local-top"
-
-do_install() {
- install -m 0755 "${WORKDIR}/tee-supplicant.hook" \
- "${D}/usr/share/initramfs-tools/hooks/tee-supplicant"
- install -m 0755 "${WORKDIR}/tee-supplicant.script" \
- "${D}/usr/share/initramfs-tools/scripts/local-top/tee-supplicant"
-}
diff --git a/meta/recipes-initramfs/initramfs-tee-supplicant-hook/initramfs-tee-supplicant-hook_0.2.bb b/meta/recipes-initramfs/initramfs-tee-supplicant-hook/initramfs-tee-supplicant-hook_0.2.bb
new file mode 100644
index 00000000..6bea92e8
--- /dev/null
+++ b/meta/recipes-initramfs/initramfs-tee-supplicant-hook/initramfs-tee-supplicant-hook_0.2.bb
@@ -0,0 +1,16 @@
+# Copyright (c) Siemens AG, 2023-2024
+#
+# Authors:
+# Su Bao Cheng <baoch...@siemens.com>
+#
+# SPDX-License-Identifier: MIT
+#
+
+require recipes-initramfs/initramfs-hook/hook.inc
+
+SRC_URI += "file://local-top"
+
+HOOK_ADD_MODULES = "tee optee"
+HOOK_COPY_EXECS = "tee-supplicant pgrep"
+
+DEBIAN_DEPENDS = "tee-supplicant, procps"
--
2.43.0

Quirin Gylstorff

unread,
Nov 12, 2024, 5:00:58 AM11/12/24
to Jan Kiszka, isar-users


On 11/11/24 21:50, Jan Kiszka wrote:
> From: Jan Kiszka <jan.k...@siemens.com>
>
> xxx
Some Documentation is missing

Quirin Gylstorff

unread,
Nov 12, 2024, 5:14:16 AM11/12/24
to Jan Kiszka, isar-users


On 11/11/24 21:50, Jan Kiszka wrote:
This supports only on file per folder is this intentional?
Quirin

Jan Kiszka

unread,
Nov 13, 2024, 1:43:07 AM11/13/24
to Quirin Gylstorff, isar-users
On 12.11.24 11:14, Quirin Gylstorff wrote:
>
>
> On 11/11/24 21:50, Jan Kiszka wrote:
>> From: Jan Kiszka <jan.k...@siemens.com>
>>
>> xxx

Oops, forgotten to finish this.
Yes, until someone can tell me a valid use case where one hook would
need multiple boot scripts (not talking about helpers that would be
called by the a boot script).

Jan

>> +        if [ ! -f "${WORKDIR}/$script" ]; then
>> +            continue
>> +        fi
>> +
>> +        rm -rf "${D}/usr/share/initramfs-tools/scripts/$script"
>> +        install -d -m 0755 "${D}/usr/share/initramfs-tools/scripts/
>> $script"
>
>> +        install -m 0755 "${WORKDIR}/$script" \
>> +            "${D}/usr/share/initramfs-tools/scripts/$script/
>> ${INITRAMFS_HOOK_NAME}"
>> +    done
>> +}
>


--
Siemens AG, Technology
Linux Expert Center

Jan Kiszka

unread,
Nov 13, 2024, 2:47:56 AM11/13/24
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

This recipe include shall simplify writing of initramfs hooks. It
provides the usual headers for the installation hook as well as the boot
scripts, allow to generate that code that installs executables and
modules into the image, but also supports expanding the scripts with own
snippets.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---

Changes in v2:
- fill out commit message, no code changes

Jan Kiszka

unread,
Nov 16, 2024, 5:55:57 AM11/16/24
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

Allows to drop the own hook recipe and makes the local-top boot script
effectively a one-liner.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
.../images/isar-initramfs.bb | 2 +-
.../initramfs-example/files/example.hook | 21 -----------------
.../initramfs-example/files/example.script | 23 -------------------
.../initramfs-example/files/local-top | 3 +++
....bb => initramfs-isar-example-hook_0.1.bb} | 21 ++++++-----------
5 files changed, 11 insertions(+), 59 deletions(-)
delete mode 100644 meta-isar/recipes-initramfs/initramfs-example/files/example.hook
delete mode 100644 meta-isar/recipes-initramfs/initramfs-example/files/example.script
create mode 100644 meta-isar/recipes-initramfs/initramfs-example/files/local-top
rename meta-isar/recipes-initramfs/initramfs-example/{initramfs-example.bb => initramfs-isar-example-hook_0.1.bb} (63%)

diff --git a/meta-isar/recipes-initramfs/images/isar-initramfs.bb b/meta-isar/recipes-initramfs/images/isar-initramfs.bb
index 4df9e0b8..71dbaa43 100644
--- a/meta-isar/recipes-initramfs/images/isar-initramfs.bb
+++ b/meta-isar/recipes-initramfs/images/isar-initramfs.bb
@@ -14,6 +14,6 @@ INITRAMFS_PREINSTALL += " \

# Recipes that should be installed into the initramfs build rootfs.
INITRAMFS_INSTALL += " \
- initramfs-example \
+ initramfs-isar-example-hook \
initramfs-fsck-hook-ext4 \
"
diff --git a/meta-isar/recipes-initramfs/initramfs-example/files/example.hook b/meta-isar/recipes-initramfs/initramfs-example/files/example.hook
deleted file mode 100644
index ba848c92..00000000
--- a/meta-isar/recipes-initramfs/initramfs-example/files/example.hook
+++ /dev/null
@@ -1,21 +0,0 @@
-#!/bin/sh
-# Example hook script.
-#
-# See "HOOK SCRIPTS" in initramfs-tools(7) for details.
-
-set -e
-
-PREREQ=""
-prereqs()
-{
- echo "$PREREQ"
-}
-case $1 in
-prereqs)
- prereqs
- exit 0
- ;;
-esac
-
-. /usr/share/initramfs-tools/hook-functions
-# Begin real processing below this line
diff --git a/meta-isar/recipes-initramfs/initramfs-example/files/example.script b/meta-isar/recipes-initramfs/initramfs-example/files/example.script
deleted file mode 100644
index c55e9ea7..00000000
--- a/meta-isar/recipes-initramfs/initramfs-example/files/example.script
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/bin/sh
-# Example boot script.
-#
-# See "BOOT SCRIPTS" in initramfs-tools(7) for details.
-
-set -e
-
-PREREQ=""
-prereqs()
-{
- echo "$PREREQ"
-}
-case $1 in
-prereqs)
- prereqs
- exit 0
- ;;
-esac
-
-. /scripts/functions
-# Begin real processing below this line
-
-log_success_msg "Hello from ISAR!"
diff --git a/meta-isar/recipes-initramfs/initramfs-example/files/local-top b/meta-isar/recipes-initramfs/initramfs-example/files/local-top
new file mode 100644
index 00000000..66e382b4
--- /dev/null
+++ b/meta-isar/recipes-initramfs/initramfs-example/files/local-top
@@ -0,0 +1,3 @@
+# Script header is provided by initramfs-hook/hook.inc
+
+log_success_msg "Hello from ISAR!"
diff --git a/meta-isar/recipes-initramfs/initramfs-example/initramfs-example.bb b/meta-isar/recipes-initramfs/initramfs-example/initramfs-isar-example-hook_0.1.bb
similarity index 63%
rename from meta-isar/recipes-initramfs/initramfs-example/initramfs-example.bb
rename to meta-isar/recipes-initramfs/initramfs-example/initramfs-isar-example-hook_0.1.bb
index c336dda9..8c600639 100644
--- a/meta-isar/recipes-initramfs/initramfs-example/initramfs-example.bb
+++ b/meta-isar/recipes-initramfs/initramfs-example/initramfs-isar-example-hook_0.1.bb
@@ -4,37 +4,30 @@
#
# This software is a part of ISAR.

+require recipes-initramfs/initramfs-hook/hook.inc
+
DESCRIPTION = "Sample initramfs module for ISAR"
MAINTAINER = "Your name here <y...@domain.com>"
-DEBIAN_DEPENDS = "initramfs-tools"

# If the conf-hook enables BUSYBOX=y, busybox is needed:
DEBIAN_DEPENDS .= ", busybox"

-SRC_URI = " \
+SRC_URI += " \
file://example.conf-hook \
- file://example.hook \
- file://example.script \
+ file://local-top \
"

-inherit dpkg-raw
-
do_install[cleandirs] += " \
${D}/usr/share/initramfs-tools/conf-hooks.d \
- ${D}/usr/share/initramfs-tools/hooks \

Jan Kiszka

unread,
Nov 16, 2024, 5:55:57 AM11/16/24
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

Document to new hook.inc as well as the preexisting initramfs class.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
doc/user_manual.md | 54 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 54 insertions(+)

diff --git a/doc/user_manual.md b/doc/user_manual.md
index 4b07f903..c20ffd93 100644
--- a/doc/user_manual.md
+++ b/doc/user_manual.md
@@ -1602,3 +1602,57 @@ CONTAINER_DELETE_AFTER_LOAD = "1"

Jan Kiszka

unread,
Nov 16, 2024, 5:55:57 AM11/16/24
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

This recipe include shall simplify writing of initramfs hooks. It
provides the usual headers for the installation hook as well as the boot
scripts, allow to generate that code that installs executables and
modules into the image, but also supports expanding the scripts with own
snippets.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
.../initramfs-hook/files/hook-header.tmpl | 39 ++++++++++
.../initramfs-hook/files/script-header.tmpl | 26 +++++++
.../recipes-initramfs/initramfs-hook/hook.inc | 74 +++++++++++++++++++
3 files changed, 139 insertions(+)
create mode 100644 meta/recipes-initramfs/initramfs-hook/files/hook-header.tmpl
create mode 100644 meta/recipes-initramfs/initramfs-hook/files/script-header.tmpl
create mode 100644 meta/recipes-initramfs/initramfs-hook/hook.inc

diff --git a/meta/recipes-initramfs/initramfs-hook/files/hook-header.tmpl b/meta/recipes-initramfs/initramfs-hook/files/hook-header.tmpl
new file mode 100644
new file mode 100644
new file mode 100644

Jan Kiszka

unread,
Nov 16, 2024, 5:55:58 AM11/16/24
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

Ensure basic CI coverage for this hook recipe.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
meta-isar/recipes-initramfs/images/isar-initramfs.bb | 1 +
1 file changed, 1 insertion(+)

diff --git a/meta-isar/recipes-initramfs/images/isar-initramfs.bb b/meta-isar/recipes-initramfs/images/isar-initramfs.bb
index aaa0350a..4df9e0b8 100644
--- a/meta-isar/recipes-initramfs/images/isar-initramfs.bb
+++ b/meta-isar/recipes-initramfs/images/isar-initramfs.bb
@@ -15,4 +15,5 @@ INITRAMFS_PREINSTALL += " \
# Recipes that should be installed into the initramfs build rootfs.
INITRAMFS_INSTALL += " \

Jan Kiszka

unread,
Nov 16, 2024, 5:55:58 AM11/16/24
to isar-users, Quirin Gylstorff
Changes in v3:
- fix DEBIAN_DEPENDS for initramfs-tee-supplicant-hook
- use .= for extending DEBIAN_DEPENDS

Changes in v2:
- add commit message to patch 1

Specifically while looking at the initramfs recipes we have in
isar-cip-core, it felt like it's time to simplify their creation and
offload the developers from all the related boilerplate bits. But the
benefit can also be observed with the initramfs recipes in isar itself.

Jan

Jan Kiszka (7):
initramfs-hook: Add infrastructure to ease writing hooks
doc: Describe initramfs customizations
isar-initramfs: Add initramfs-fsck-hook-ext4
initramfs-isar-example-hook: Convert recipe over to new hook.inc
initramfs-fsck-ext4-hook: Convert to hook.inc and improve
initramfs-tee-ftpm-hook: Convert to hook.inc
initramfs-tee-supplicant-hook: Convert to hook.inc

doc/user_manual.md | 54 ++++++++++++++
.../images/isar-initramfs.bb | 3 +-
.../initramfs-example/files/example.hook | 21 ------
.../initramfs-example/files/example.script | 23 ------
.../initramfs-example/files/local-top | 3 +
....bb => initramfs-isar-example-hook_0.1.bb} | 21 ++----
.../files/initramfs-fsck-hook-ext4.triggers | 0
.../initramfs-fsck-ext4-hook_0.3.bb | 14 ++++
.../initramfs-hook/files/hook-header.tmpl | 39 ++++++++++
.../initramfs-hook/files/script-header.tmpl | 26 +++++++
.../recipes-initramfs/initramfs-hook/hook.inc | 74 +++++++++++++++++++
.../files/{tee-ftpm.script => local-top} | 18 +----
.../files/tee-ftpm.hook | 28 -------
.../initramfs-tee-ftpm-hook_0.1.bb | 27 -------
.../initramfs-tee-ftpm-hook_0.2.bb | 15 ++++
.../{tee-supplicant.script => local-top} | 18 +----
.../files/tee-supplicant.hook | 36 ---------
.../initramfs-tee-supplicant-hook_0.1.bb | 27 -------
.../initramfs-tee-supplicant-hook_0.2.bb | 16 ++++
.../files/initramfs.fsck.ext4.hook | 39 ----------
.../initramfs-fsck-hook-ext4_0.2.bb | 18 -----
21 files changed, 252 insertions(+), 268 deletions(-)
delete mode 100644 meta-isar/recipes-initramfs/initramfs-example/files/example.hook
delete mode 100644 meta-isar/recipes-initramfs/initramfs-example/files/example.script
create mode 100644 meta-isar/recipes-initramfs/initramfs-example/files/local-top
rename meta-isar/recipes-initramfs/initramfs-example/{initramfs-example.bb => initramfs-isar-example-hook_0.1.bb} (63%)
rename meta/{recipes-support => recipes-initramfs}/initramfs-fsck-hook/files/initramfs-fsck-hook-ext4.triggers (100%)
create mode 100644 meta/recipes-initramfs/initramfs-fsck-hook/initramfs-fsck-ext4-hook_0.3.bb
create mode 100644 meta/recipes-initramfs/initramfs-hook/files/hook-header.tmpl
create mode 100644 meta/recipes-initramfs/initramfs-hook/files/script-header.tmpl
create mode 100644 meta/recipes-initramfs/initramfs-hook/hook.inc
rename meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/{tee-ftpm.script => local-top} (75%)
delete mode 100644 meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/tee-ftpm.hook
delete mode 100644 meta/recipes-initramfs/initramfs-tee-ftpm-hook/initramfs-tee-ftpm-hook_0.1.bb
create mode 100644 meta/recipes-initramfs/initramfs-tee-ftpm-hook/initramfs-tee-ftpm-hook_0.2.bb
rename meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/{tee-supplicant.script => local-top} (68%)
delete mode 100644 meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/tee-supplicant.hook
delete mode 100644 meta/recipes-initramfs/initramfs-tee-supplicant-hook/initramfs-tee-supplicant-hook_0.1.bb
create mode 100644 meta/recipes-initramfs/initramfs-tee-supplicant-hook/initramfs-tee-supplicant-hook_0.2.bb
delete mode 100644 meta/recipes-support/initramfs-fsck-hook/files/initramfs.fsck.ext4.hook
delete mode 100644 meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-hook-ext4_0.2.bb

--
2.43.0

Jan Kiszka

unread,
Nov 16, 2024, 5:55:58 AM11/16/24
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

Reduces the own bits significantly.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
.../files/{tee-ftpm.script => local-top} | 18 +-----------
.../files/tee-ftpm.hook | 28 -------------------
.../initramfs-tee-ftpm-hook_0.1.bb | 27 ------------------
.../initramfs-tee-ftpm-hook_0.2.bb | 15 ++++++++++
4 files changed, 16 insertions(+), 72 deletions(-)
rename meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/{tee-ftpm.script => local-top} (75%)
delete mode 100644 meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/tee-ftpm.hook
delete mode 100644 meta/recipes-initramfs/initramfs-tee-ftpm-hook/initramfs-tee-ftpm-hook_0.1.bb
create mode 100644 meta/recipes-initramfs/initramfs-tee-ftpm-hook/initramfs-tee-ftpm-hook_0.2.bb

diff --git a/meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/tee-ftpm.script b/meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/local-top
similarity index 75%
rename from meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/tee-ftpm.script
rename to meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/local-top
index 3355a7e0..989bf288 100644
--- a/meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/tee-ftpm.script
+++ b/meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/local-top
@@ -1,4 +1,4 @@
-#!/bin/sh
+#
# Copyright (c) Siemens AG, 2023
#
# Authors:
@@ -7,22 +7,6 @@
# SPDX-License-Identifier: MIT
#

-set -e
-
-PREREQ="tee-supplicant"
-prereqs()
-{
- echo "$PREREQ"
-}
-case $1 in
-prereqs)
- prereqs
- exit 0
- ;;
-esac
-
-. /scripts/functions
-
FTPM_DEV=/dev/tpmrm0

# The tee-supplicant would take some time to be discovered, 30 seconds should
diff --git a/meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/tee-ftpm.hook b/meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/tee-ftpm.hook
deleted file mode 100644
index e80f00b4..00000000
--- a/meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/tee-ftpm.hook
+++ /dev/null
@@ -1,28 +0,0 @@
-#!/bin/sh
-# Copyright (c) Siemens AG, 2023
-#
-# Authors:
-# Su Bao Cheng <baoch...@siemens.com>
-#
-# SPDX-License-Identifier: MIT
-#
-
-set -e
-
-PREREQ="tee-supplicant"
-prereqs()
-{
- echo "$PREREQ"
-}
-case $1 in
-prereqs)
- prereqs
- exit 0
- ;;
-esac
-
-. /usr/share/initramfs-tools/hook-functions
-
-# The tpm_ftpm_tee.ko does not exist in any stock debian kernels, it could be
-# provided by customized kernel.
-manual_add_modules tpm_ftpm_tee
diff --git a/meta/recipes-initramfs/initramfs-tee-ftpm-hook/initramfs-tee-ftpm-hook_0.1.bb b/meta/recipes-initramfs/initramfs-tee-ftpm-hook/initramfs-tee-ftpm-hook_0.1.bb
deleted file mode 100644
index 82fec1bb..00000000
--- a/meta/recipes-initramfs/initramfs-tee-ftpm-hook/initramfs-tee-ftpm-hook_0.1.bb
+++ /dev/null
@@ -1,27 +0,0 @@
-# Copyright (c) Siemens AG, 2023
-#
-# Authors:
-# Su Bao Cheng <baoch...@siemens.com>
-#
-# SPDX-License-Identifier: MIT
-#
-
-inherit dpkg-raw
-
-SRC_URI += " \
- file://tee-ftpm.hook \
- file://tee-ftpm.script \
- "
-
-DEBIAN_DEPENDS = "initramfs-tools"
-
-do_install[cleandirs] += " \
- ${D}/usr/share/initramfs-tools/hooks \
- ${D}/usr/share/initramfs-tools/scripts/local-top"
-
-do_install() {
- install -m 0755 "${WORKDIR}/tee-ftpm.hook" \
- "${D}/usr/share/initramfs-tools/hooks/tee-ftpm"
- install -m 0755 "${WORKDIR}/tee-ftpm.script" \
- "${D}/usr/share/initramfs-tools/scripts/local-top/tee-ftpm"
-}
diff --git a/meta/recipes-initramfs/initramfs-tee-ftpm-hook/initramfs-tee-ftpm-hook_0.2.bb b/meta/recipes-initramfs/initramfs-tee-ftpm-hook/initramfs-tee-ftpm-hook_0.2.bb
new file mode 100644
index 00000000..9f77c158
--- /dev/null
+++ b/meta/recipes-initramfs/initramfs-tee-ftpm-hook/initramfs-tee-ftpm-hook_0.2.bb
@@ -0,0 +1,15 @@
+# Copyright (c) Siemens AG, 2023-2024
+#
+# Authors:
+# Su Bao Cheng <baoch...@siemens.com>
+#
+# SPDX-License-Identifier: MIT
+#
+
+require recipes-initramfs/initramfs-hook/hook.inc
+
+SRC_URI += "file://local-top"
+

Jan Kiszka

unread,
Nov 16, 2024, 5:55:58 AM11/16/24
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

Use the convention and helping features of the new initramfs hook.inc to
simplify this hook. We move it under recipes-initramfs to align with
other recipes there. Another change is making fsck.ext4 mandatory, both
as dependency and while copying it in via the helper - there is no
reason for this recipe to almost silently ignore any unavailability.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
.../images/isar-initramfs.bb | 2 +-
.../files/initramfs-fsck-hook-ext4.triggers | 0
.../initramfs-fsck-ext4-hook_0.3.bb | 14 +++++++
.../files/initramfs.fsck.ext4.hook | 39 -------------------
.../initramfs-fsck-hook-ext4_0.2.bb | 18 ---------
5 files changed, 15 insertions(+), 58 deletions(-)
rename meta/{recipes-support => recipes-initramfs}/initramfs-fsck-hook/files/initramfs-fsck-hook-ext4.triggers (100%)
create mode 100644 meta/recipes-initramfs/initramfs-fsck-hook/initramfs-fsck-ext4-hook_0.3.bb
delete mode 100644 meta/recipes-support/initramfs-fsck-hook/files/initramfs.fsck.ext4.hook
delete mode 100644 meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-hook-ext4_0.2.bb

diff --git a/meta-isar/recipes-initramfs/images/isar-initramfs.bb b/meta-isar/recipes-initramfs/images/isar-initramfs.bb
index 71dbaa43..d2a946f7 100644
--- a/meta-isar/recipes-initramfs/images/isar-initramfs.bb
+++ b/meta-isar/recipes-initramfs/images/isar-initramfs.bb
@@ -15,5 +15,5 @@ INITRAMFS_PREINSTALL += " \
# Recipes that should be installed into the initramfs build rootfs.
INITRAMFS_INSTALL += " \
initramfs-isar-example-hook \
- initramfs-fsck-hook-ext4 \
+ initramfs-fsck-ext4-hook \
"
diff --git a/meta/recipes-support/initramfs-fsck-hook/files/initramfs-fsck-hook-ext4.triggers b/meta/recipes-initramfs/initramfs-fsck-hook/files/initramfs-fsck-hook-ext4.triggers
similarity index 100%
rename from meta/recipes-support/initramfs-fsck-hook/files/initramfs-fsck-hook-ext4.triggers
rename to meta/recipes-initramfs/initramfs-fsck-hook/files/initramfs-fsck-hook-ext4.triggers
diff --git a/meta/recipes-initramfs/initramfs-fsck-hook/initramfs-fsck-ext4-hook_0.3.bb b/meta/recipes-initramfs/initramfs-fsck-hook/initramfs-fsck-ext4-hook_0.3.bb
new file mode 100644
index 00000000..c4d10c44
--- /dev/null
+++ b/meta/recipes-initramfs/initramfs-fsck-hook/initramfs-fsck-ext4-hook_0.3.bb
@@ -0,0 +1,14 @@
+# This software is a part of ISAR.
+# Copyright (C) Siemens AG, 2019-2024
+#
+# SPDX-License-Identifier: MIT
+
+DESCRIPTION = "Recipe to add fsck hook to the initramfs"
+
+require recipes-initramfs/initramfs-hook/hook.inc
+
+SRC_URI += "file://initramfs-fsck-hook-ext4.triggers"
+
+HOOK_COPY_EXECS = "fsck fsck.ext4 logsave"
+
+DEBIAN_DEPENDS .= ", e2fsprogs, logsave"
diff --git a/meta/recipes-support/initramfs-fsck-hook/files/initramfs.fsck.ext4.hook b/meta/recipes-support/initramfs-fsck-hook/files/initramfs.fsck.ext4.hook
deleted file mode 100644
index 259b73b4..00000000
--- a/meta/recipes-support/initramfs-fsck-hook/files/initramfs.fsck.ext4.hook
+++ /dev/null
@@ -1,39 +0,0 @@
-# This software is a part of ISAR.
-# Copyright (C) Siemens AG, 2019
-#
-# SPDX-License-Identifier: MIT
-
-#!/bin/sh
-
-set -e
-
-PREREQ=""
-
-prereqs()
-{
- echo "$PREREQ"
-}
-
-case $1 in
-prereqs)
- prereqs
- exit 0
- ;;
-esac
-
-. /usr/share/initramfs-tools/scripts/functions
-. /usr/share/initramfs-tools/hook-functions
-
-if [ ! -x /sbin/fsck ]; then
- echo "Warning: couldn't find /sbin/fsck!"
- exit 0
-fi
-
-copy_exec /sbin/fsck
-copy_exec /sbin/logsave
-
-if prog="$(command -v fsck.ext4)"; then
- copy_exec "$prog"
-else
- echo "Warning: /sbin/fsck.ext4 doesn't exist, can't install to initramfs, ignoring."
-fi
diff --git a/meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-hook-ext4_0.2.bb b/meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-hook-ext4_0.2.bb
deleted file mode 100644
index 9860dbc8..00000000
--- a/meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-hook-ext4_0.2.bb
+++ /dev/null
@@ -1,18 +0,0 @@
-# This software is a part of ISAR.
-# Copyright (C) Siemens AG, 2019
-#
-# SPDX-License-Identifier: MIT
-
-
-DESCRIPTION = "Recipe to add fsck hook to the initramfs"
-
-inherit dpkg-raw
-SRC_URI = "file://initramfs-fsck-hook-ext4.triggers \
- file://initramfs.fsck.ext4.hook \
- "
-
-
-do_install() {

Jan Kiszka

unread,
Nov 16, 2024, 5:55:59 AM11/16/24
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

Reduces the own bits significantly.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
.../{tee-supplicant.script => local-top} | 18 +---------
.../files/tee-supplicant.hook | 36 -------------------
.../initramfs-tee-supplicant-hook_0.1.bb | 27 --------------
.../initramfs-tee-supplicant-hook_0.2.bb | 16 +++++++++
4 files changed, 17 insertions(+), 80 deletions(-)
rename meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/{tee-supplicant.script => local-top} (68%)
delete mode 100644 meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/tee-supplicant.hook
delete mode 100644 meta/recipes-initramfs/initramfs-tee-supplicant-hook/initramfs-tee-supplicant-hook_0.1.bb
create mode 100644 meta/recipes-initramfs/initramfs-tee-supplicant-hook/initramfs-tee-supplicant-hook_0.2.bb

diff --git a/meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/tee-supplicant.script b/meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/local-top
similarity index 68%
rename from meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/tee-supplicant.script
rename to meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/local-top
index ac01d7ec..575a742d 100644
--- a/meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/tee-supplicant.script
+++ b/meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/local-top
@@ -1,4 +1,4 @@
-#!/bin/sh
+#
# Copyright (c) Siemens AG, 2023
#
# Authors:
@@ -7,22 +7,6 @@
# SPDX-License-Identifier: MIT
#

-set -e
-
-PREREQ=""
-prereqs()
-{
- echo "$PREREQ"
-}
-case $1 in
-prereqs)
- prereqs
- exit 0
- ;;
-esac
-
-. /scripts/functions
-
/usr/sbin/modprobe optee
/usr/sbin/tee-supplicant -d

diff --git a/meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/tee-supplicant.hook b/meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/tee-supplicant.hook
deleted file mode 100644
index 3e2f4016..00000000
--- a/meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/tee-supplicant.hook
+++ /dev/null
@@ -1,36 +0,0 @@
-#!/bin/sh
-# Copyright (c) Siemens AG, 2023
-#
-# Authors:
-# Su Bao Cheng <baoch...@siemens.com>
-#
-# SPDX-License-Identifier: MIT
-#
-
-set -e
-
-PREREQ=""
-prereqs()
-{
- echo "$PREREQ"
-}
-case $1 in
-prereqs)
- prereqs
- exit 0
- ;;
-esac
-
-. /usr/share/initramfs-tools/hook-functions
-
-hook_error() {
- echo "(ERROR): $1" >&2
- exit 1
-}
-
-# For stock debian bookworm arm64 kernel, these two .ko exist, but not built-in.
-manual_add_modules tee
-manual_add_modules optee
-
-copy_exec /usr/sbin/tee-supplicant || hook_error "/usr/sbin/tee-supplicant not found"
-copy_exec /usr/bin/pgrep || hook_error "/usr/bin/pgrep not found"
diff --git a/meta/recipes-initramfs/initramfs-tee-supplicant-hook/initramfs-tee-supplicant-hook_0.1.bb b/meta/recipes-initramfs/initramfs-tee-supplicant-hook/initramfs-tee-supplicant-hook_0.1.bb
deleted file mode 100644
index a7a19bee..00000000
--- a/meta/recipes-initramfs/initramfs-tee-supplicant-hook/initramfs-tee-supplicant-hook_0.1.bb
+++ /dev/null
@@ -1,27 +0,0 @@
-# Copyright (c) Siemens AG, 2023
-#
-# Authors:
-# Su Bao Cheng <baoch...@siemens.com>
-#
-# SPDX-License-Identifier: MIT
-#
-
-inherit dpkg-raw
-
-SRC_URI += " \
- file://tee-supplicant.hook \
- file://tee-supplicant.script \
- "
-
-DEBIAN_DEPENDS = "initramfs-tools, tee-supplicant, procps"
-
-do_install[cleandirs] += " \
- ${D}/usr/share/initramfs-tools/hooks \
- ${D}/usr/share/initramfs-tools/scripts/local-top"
-
-do_install() {
- install -m 0755 "${WORKDIR}/tee-supplicant.hook" \
- "${D}/usr/share/initramfs-tools/hooks/tee-supplicant"
- install -m 0755 "${WORKDIR}/tee-supplicant.script" \
- "${D}/usr/share/initramfs-tools/scripts/local-top/tee-supplicant"
-}
diff --git a/meta/recipes-initramfs/initramfs-tee-supplicant-hook/initramfs-tee-supplicant-hook_0.2.bb b/meta/recipes-initramfs/initramfs-tee-supplicant-hook/initramfs-tee-supplicant-hook_0.2.bb
new file mode 100644
index 00000000..b9dedfd3
--- /dev/null
+++ b/meta/recipes-initramfs/initramfs-tee-supplicant-hook/initramfs-tee-supplicant-hook_0.2.bb
@@ -0,0 +1,16 @@
+# Copyright (c) Siemens AG, 2023-2024
+#
+# Authors:
+# Su Bao Cheng <baoch...@siemens.com>
+#
+# SPDX-License-Identifier: MIT
+#
+
+require recipes-initramfs/initramfs-hook/hook.inc
+
+SRC_URI += "file://local-top"
+
+HOOK_ADD_MODULES = "tee optee"
+HOOK_COPY_EXECS = "tee-supplicant pgrep"
+
+DEBIAN_DEPENDS .= ", tee-supplicant, procps"
--
2.43.0

Jan Kiszka

unread,
Nov 16, 2024, 6:13:04 AM11/16/24
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

This recipe include shall simplify writing of initramfs hooks. It
provides the usual headers for the installation hook as well as the boot
scripts, allow to generate that code that installs executables and
modules into the image, but also supports expanding the scripts with own
snippets.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
.../initramfs-hook/files/hook-header.tmpl | 39 ++++++++++
.../initramfs-hook/files/script-header.tmpl | 26 +++++++
.../recipes-initramfs/initramfs-hook/hook.inc | 76 +++++++++++++++++++
3 files changed, 141 insertions(+)
create mode 100644 meta/recipes-initramfs/initramfs-hook/files/hook-header.tmpl
create mode 100644 meta/recipes-initramfs/initramfs-hook/files/script-header.tmpl
create mode 100644 meta/recipes-initramfs/initramfs-hook/hook.inc

diff --git a/meta/recipes-initramfs/initramfs-hook/files/hook-header.tmpl b/meta/recipes-initramfs/initramfs-hook/files/hook-header.tmpl
new file mode 100644
index 00000000..ee30d691
--- /dev/null
+++ b/meta/recipes-initramfs/initramfs-hook/files/hook-header.tmpl
@@ -0,0 +1,39 @@
+#!/bin/sh
+#
+# Copyright (c) Siemens AG, 2024
+#
+# Authors:
+# Jan Kiszka <jan.k...@siemens.com>
+#
+# SPDX-License-Identifier: MIT
+#
+
new file mode 100644
index 00000000..faa1a644
--- /dev/null
+++ b/meta/recipes-initramfs/initramfs-hook/files/script-header.tmpl
@@ -0,0 +1,26 @@
+#!/bin/sh
+#
+# Copyright (c) Siemens AG, 2024
+#
+# Authors:
+# Jan Kiszka <jan.k...@siemens.com>
+#
+# SPDX-License-Identifier: MIT
+#
+
+set -e
+
+prereqs()
+{
+ echo "${SCRIPT_PREREQ}"
+}
+
+case $1 in
+prereqs)
+ prereqs
+ exit 0
+ ;;
+esac
+
+. /scripts/functions
+
diff --git a/meta/recipes-initramfs/initramfs-hook/hook.inc b/meta/recipes-initramfs/initramfs-hook/hook.inc
new file mode 100644
index 00000000..b0e7c66c
--- /dev/null
+++ b/meta/recipes-initramfs/initramfs-hook/hook.inc
@@ -0,0 +1,76 @@
+#
+# Copyright (c) Siemens AG, 2024
+#
+# Authors:
+# Jan Kiszka <jan.k...@siemens.com>
+#
+# SPDX-License-Identifier: MIT
+#
+
+ install -m 0755 "${WORKDIR}/script-header" \
+ "${D}/usr/share/initramfs-tools/scripts/$script/${INITRAMFS_HOOK_NAME}"
+ cat "${WORKDIR}/$script" >> \

Jan Kiszka

unread,
Nov 16, 2024, 6:13:04 AM11/16/24
to isar-users, Quirin Gylstorff
Changes in v4:
- add forgotten header to boot scripts
(this part was apparently only build-tested so far...)

Changes in v3:
- fix DEBIAN_DEPENDS for initramfs-tee-supplicant-hook
- use .= for extending DEBIAN_DEPENDS

Changes in v2:
- add commit message to patch 1

Specifically while looking at the initramfs recipes we have in
isar-cip-core, it felt like it's time to simplify their creation and
offload the developers from all the related boilerplate bits. But the
benefit can also be observed with the initramfs recipes in isar itself.

Jan

Jan Kiszka (7):
initramfs-hook: Add infrastructure to ease writing hooks
doc: Describe initramfs customizations
isar-initramfs: Add initramfs-fsck-hook-ext4
initramfs-isar-example-hook: Convert recipe over to new hook.inc
initramfs-fsck-ext4-hook: Convert to hook.inc and improve
initramfs-tee-ftpm-hook: Convert to hook.inc
initramfs-tee-supplicant-hook: Convert to hook.inc

doc/user_manual.md | 54 +++++++++++++
.../images/isar-initramfs.bb | 3 +-
.../initramfs-example/files/example.hook | 21 -----
.../initramfs-example/files/example.script | 23 ------
.../initramfs-example/files/local-top | 3 +
....bb => initramfs-isar-example-hook_0.1.bb} | 21 ++---
.../files/initramfs-fsck-hook-ext4.triggers | 0
.../initramfs-fsck-ext4-hook_0.3.bb | 14 ++++
.../initramfs-hook/files/hook-header.tmpl | 39 ++++++++++
.../initramfs-hook/files/script-header.tmpl | 26 +++++++
.../recipes-initramfs/initramfs-hook/hook.inc | 76 +++++++++++++++++++
.../files/{tee-ftpm.script => local-top} | 18 +----
.../files/tee-ftpm.hook | 28 -------
.../initramfs-tee-ftpm-hook_0.1.bb | 27 -------
.../initramfs-tee-ftpm-hook_0.2.bb | 15 ++++
.../{tee-supplicant.script => local-top} | 18 +----
.../files/tee-supplicant.hook | 36 ---------
.../initramfs-tee-supplicant-hook_0.1.bb | 27 -------
.../initramfs-tee-supplicant-hook_0.2.bb | 16 ++++
.../files/initramfs.fsck.ext4.hook | 39 ----------
.../initramfs-fsck-hook-ext4_0.2.bb | 18 -----
21 files changed, 254 insertions(+), 268 deletions(-)
delete mode 100644 meta-isar/recipes-initramfs/initramfs-example/files/example.hook
delete mode 100644 meta-isar/recipes-initramfs/initramfs-example/files/example.script
create mode 100644 meta-isar/recipes-initramfs/initramfs-example/files/local-top
rename meta-isar/recipes-initramfs/initramfs-example/{initramfs-example.bb => initramfs-isar-example-hook_0.1.bb} (63%)
rename meta/{recipes-support => recipes-initramfs}/initramfs-fsck-hook/files/initramfs-fsck-hook-ext4.triggers (100%)
create mode 100644 meta/recipes-initramfs/initramfs-fsck-hook/initramfs-fsck-ext4-hook_0.3.bb
create mode 100644 meta/recipes-initramfs/initramfs-hook/files/hook-header.tmpl
create mode 100644 meta/recipes-initramfs/initramfs-hook/files/script-header.tmpl
create mode 100644 meta/recipes-initramfs/initramfs-hook/hook.inc
rename meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/{tee-ftpm.script => local-top} (75%)
delete mode 100644 meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/tee-ftpm.hook
delete mode 100644 meta/recipes-initramfs/initramfs-tee-ftpm-hook/initramfs-tee-ftpm-hook_0.1.bb
create mode 100644 meta/recipes-initramfs/initramfs-tee-ftpm-hook/initramfs-tee-ftpm-hook_0.2.bb
rename meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/{tee-supplicant.script => local-top} (68%)
delete mode 100644 meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/tee-supplicant.hook
delete mode 100644 meta/recipes-initramfs/initramfs-tee-supplicant-hook/initramfs-tee-supplicant-hook_0.1.bb
create mode 100644 meta/recipes-initramfs/initramfs-tee-supplicant-hook/initramfs-tee-supplicant-hook_0.2.bb
delete mode 100644 meta/recipes-support/initramfs-fsck-hook/files/initramfs.fsck.ext4.hook
delete mode 100644 meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-hook-ext4_0.2.bb

--
2.43.0

Jan Kiszka

unread,
Nov 16, 2024, 6:13:05 AM11/16/24
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

Document to new hook.inc as well as the preexisting initramfs class.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---

Jan Kiszka

unread,
Nov 16, 2024, 6:13:05 AM11/16/24
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

Allows to drop the own hook recipe and makes the local-top boot script
effectively a one-liner.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
.../images/isar-initramfs.bb | 2 +-
.../initramfs-example/files/example.hook | 21 -----------------
.../initramfs-example/files/example.script | 23 -------------------
.../initramfs-example/files/local-top | 3 +++
....bb => initramfs-isar-example-hook_0.1.bb} | 21 ++++++-----------
5 files changed, 11 insertions(+), 59 deletions(-)
delete mode 100644 meta-isar/recipes-initramfs/initramfs-example/files/example.hook
delete mode 100644 meta-isar/recipes-initramfs/initramfs-example/files/example.script
create mode 100644 meta-isar/recipes-initramfs/initramfs-example/files/local-top
rename meta-isar/recipes-initramfs/initramfs-example/{initramfs-example.bb => initramfs-isar-example-hook_0.1.bb} (63%)

diff --git a/meta-isar/recipes-initramfs/images/isar-initramfs.bb b/meta-isar/recipes-initramfs/images/isar-initramfs.bb
index 4df9e0b8..71dbaa43 100644
--- a/meta-isar/recipes-initramfs/images/isar-initramfs.bb
+++ b/meta-isar/recipes-initramfs/images/isar-initramfs.bb
@@ -14,6 +14,6 @@ INITRAMFS_PREINSTALL += " \

# Recipes that should be installed into the initramfs build rootfs.
INITRAMFS_INSTALL += " \
- initramfs-example \
+ initramfs-isar-example-hook \
initramfs-fsck-hook-ext4 \
"
diff --git a/meta-isar/recipes-initramfs/initramfs-example/files/example.hook b/meta-isar/recipes-initramfs/initramfs-example/files/example.hook
deleted file mode 100644
index ba848c92..00000000
--- a/meta-isar/recipes-initramfs/initramfs-example/files/example.hook
+++ /dev/null
@@ -1,21 +0,0 @@
-#!/bin/sh
-# Example hook script.
-#
-# See "HOOK SCRIPTS" in initramfs-tools(7) for details.
-
-set -e
-
-PREREQ=""
-prereqs()
-{
- echo "$PREREQ"
-}
-case $1 in
-prereqs)
- prereqs
- exit 0
- ;;
-esac
-
-. /usr/share/initramfs-tools/hook-functions
-# Begin real processing below this line
diff --git a/meta-isar/recipes-initramfs/initramfs-example/files/example.script b/meta-isar/recipes-initramfs/initramfs-example/files/example.script
deleted file mode 100644
index c55e9ea7..00000000
--- a/meta-isar/recipes-initramfs/initramfs-example/files/example.script
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/bin/sh
-# Example boot script.
-#
-# See "BOOT SCRIPTS" in initramfs-tools(7) for details.
-
-set -e
-
-PREREQ=""
-prereqs()
-{
- echo "$PREREQ"
-}
-case $1 in
-prereqs)
- prereqs
- exit 0
- ;;
-esac
-
-. /scripts/functions
-# Begin real processing below this line
-
-log_success_msg "Hello from ISAR!"
diff --git a/meta-isar/recipes-initramfs/initramfs-example/files/local-top b/meta-isar/recipes-initramfs/initramfs-example/files/local-top
new file mode 100644
index 00000000..66e382b4
--- /dev/null
+++ b/meta-isar/recipes-initramfs/initramfs-example/files/local-top
@@ -0,0 +1,3 @@
+# Script header is provided by initramfs-hook/hook.inc
+
+log_success_msg "Hello from ISAR!"
diff --git a/meta-isar/recipes-initramfs/initramfs-example/initramfs-example.bb b/meta-isar/recipes-initramfs/initramfs-example/initramfs-isar-example-hook_0.1.bb
similarity index 63%
rename from meta-isar/recipes-initramfs/initramfs-example/initramfs-example.bb
rename to meta-isar/recipes-initramfs/initramfs-example/initramfs-isar-example-hook_0.1.bb
index c336dda9..8c600639 100644
--- a/meta-isar/recipes-initramfs/initramfs-example/initramfs-example.bb
+++ b/meta-isar/recipes-initramfs/initramfs-example/initramfs-isar-example-hook_0.1.bb
@@ -4,37 +4,30 @@
#
# This software is a part of ISAR.

+require recipes-initramfs/initramfs-hook/hook.inc
+
DESCRIPTION = "Sample initramfs module for ISAR"
MAINTAINER = "Your name here <y...@domain.com>"
-DEBIAN_DEPENDS = "initramfs-tools"

# If the conf-hook enables BUSYBOX=y, busybox is needed:
DEBIAN_DEPENDS .= ", busybox"

-SRC_URI = " \
+SRC_URI += " \
file://example.conf-hook \
- file://example.hook \
- file://example.script \
+ file://local-top \
"

-inherit dpkg-raw
-
do_install[cleandirs] += " \
${D}/usr/share/initramfs-tools/conf-hooks.d \
- ${D}/usr/share/initramfs-tools/hooks \

Jan Kiszka

unread,
Nov 16, 2024, 6:13:06 AM11/16/24
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

Reduces the own bits significantly.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
.../{tee-supplicant.script => local-top} | 18 +---------
.../files/tee-supplicant.hook | 36 -------------------
.../initramfs-tee-supplicant-hook_0.1.bb | 27 --------------
.../initramfs-tee-supplicant-hook_0.2.bb | 16 +++++++++
4 files changed, 17 insertions(+), 80 deletions(-)
rename meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/{tee-supplicant.script => local-top} (68%)
delete mode 100644 meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/tee-supplicant.hook
delete mode 100644 meta/recipes-initramfs/initramfs-tee-supplicant-hook/initramfs-tee-supplicant-hook_0.1.bb
create mode 100644 meta/recipes-initramfs/initramfs-tee-supplicant-hook/initramfs-tee-supplicant-hook_0.2.bb

diff --git a/meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/tee-supplicant.script b/meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/local-top
similarity index 68%
rename from meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/tee-supplicant.script
rename to meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/local-top
index ac01d7ec..575a742d 100644
--- a/meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/tee-supplicant.script
+++ b/meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/local-top
@@ -1,4 +1,4 @@
-#!/bin/sh
+#
# Copyright (c) Siemens AG, 2023
#
# Authors:
@@ -7,22 +7,6 @@
# SPDX-License-Identifier: MIT
#

-set -e
-
-PREREQ=""
-prereqs()
-{
- echo "$PREREQ"
-}
-case $1 in
-prereqs)
- prereqs
- exit 0
- ;;
-esac
-
-. /scripts/functions
-
/usr/sbin/modprobe optee
/usr/sbin/tee-supplicant -d

diff --git a/meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/tee-supplicant.hook b/meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/tee-supplicant.hook
deleted file mode 100644
index 3e2f4016..00000000
--- a/meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/tee-supplicant.hook
+++ /dev/null
@@ -1,36 +0,0 @@
-#!/bin/sh
-# Copyright (c) Siemens AG, 2023
-#
-# Authors:
-# Su Bao Cheng <baoch...@siemens.com>
-#
-# SPDX-License-Identifier: MIT
-#
-
-set -e
-
-PREREQ=""
-prereqs()
-{
- echo "$PREREQ"
-}
-case $1 in
-prereqs)
- prereqs
- exit 0
- ;;
-esac
-
-. /usr/share/initramfs-tools/hook-functions
-
-hook_error() {
- echo "(ERROR): $1" >&2
- exit 1
-}
-
-# For stock debian bookworm arm64 kernel, these two .ko exist, but not built-in.
-manual_add_modules tee
-manual_add_modules optee
-
-copy_exec /usr/sbin/tee-supplicant || hook_error "/usr/sbin/tee-supplicant not found"
-copy_exec /usr/bin/pgrep || hook_error "/usr/bin/pgrep not found"
diff --git a/meta/recipes-initramfs/initramfs-tee-supplicant-hook/initramfs-tee-supplicant-hook_0.1.bb b/meta/recipes-initramfs/initramfs-tee-supplicant-hook/initramfs-tee-supplicant-hook_0.1.bb
deleted file mode 100644
index a7a19bee..00000000
--- a/meta/recipes-initramfs/initramfs-tee-supplicant-hook/initramfs-tee-supplicant-hook_0.1.bb
+++ /dev/null
@@ -1,27 +0,0 @@
-# Copyright (c) Siemens AG, 2023
-#
-# Authors:
-# Su Bao Cheng <baoch...@siemens.com>
-#
-# SPDX-License-Identifier: MIT
-#
-
-inherit dpkg-raw
-
-SRC_URI += " \
- file://tee-supplicant.hook \
- file://tee-supplicant.script \
- "
-
-DEBIAN_DEPENDS = "initramfs-tools, tee-supplicant, procps"
-
-do_install[cleandirs] += " \
- ${D}/usr/share/initramfs-tools/hooks \
- ${D}/usr/share/initramfs-tools/scripts/local-top"
-
-do_install() {
- install -m 0755 "${WORKDIR}/tee-supplicant.hook" \
- "${D}/usr/share/initramfs-tools/hooks/tee-supplicant"
- install -m 0755 "${WORKDIR}/tee-supplicant.script" \
- "${D}/usr/share/initramfs-tools/scripts/local-top/tee-supplicant"
-}
diff --git a/meta/recipes-initramfs/initramfs-tee-supplicant-hook/initramfs-tee-supplicant-hook_0.2.bb b/meta/recipes-initramfs/initramfs-tee-supplicant-hook/initramfs-tee-supplicant-hook_0.2.bb
new file mode 100644
index 00000000..b9dedfd3
--- /dev/null
+++ b/meta/recipes-initramfs/initramfs-tee-supplicant-hook/initramfs-tee-supplicant-hook_0.2.bb
@@ -0,0 +1,16 @@
+# Copyright (c) Siemens AG, 2023-2024
+#
+# Authors:
+# Su Bao Cheng <baoch...@siemens.com>
+#
+# SPDX-License-Identifier: MIT
+#
+

Jan Kiszka

unread,
Nov 16, 2024, 6:13:06 AM11/16/24
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

Use the convention and helping features of the new initramfs hook.inc to
simplify this hook. We move it under recipes-initramfs to align with
other recipes there. Another change is making fsck.ext4 mandatory, both
as dependency and while copying it in via the helper - there is no
reason for this recipe to almost silently ignore any unavailability.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
.../images/isar-initramfs.bb | 2 +-
.../files/initramfs-fsck-hook-ext4.triggers | 0
.../initramfs-fsck-ext4-hook_0.3.bb | 14 +++++++
.../files/initramfs.fsck.ext4.hook | 39 -------------------
.../initramfs-fsck-hook-ext4_0.2.bb | 18 ---------
5 files changed, 15 insertions(+), 58 deletions(-)
rename meta/{recipes-support => recipes-initramfs}/initramfs-fsck-hook/files/initramfs-fsck-hook-ext4.triggers (100%)
create mode 100644 meta/recipes-initramfs/initramfs-fsck-hook/initramfs-fsck-ext4-hook_0.3.bb
delete mode 100644 meta/recipes-support/initramfs-fsck-hook/files/initramfs.fsck.ext4.hook
delete mode 100644 meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-hook-ext4_0.2.bb

diff --git a/meta-isar/recipes-initramfs/images/isar-initramfs.bb b/meta-isar/recipes-initramfs/images/isar-initramfs.bb
index 71dbaa43..d2a946f7 100644
--- a/meta-isar/recipes-initramfs/images/isar-initramfs.bb
+++ b/meta-isar/recipes-initramfs/images/isar-initramfs.bb
@@ -15,5 +15,5 @@ INITRAMFS_PREINSTALL += " \
# Recipes that should be installed into the initramfs build rootfs.
INITRAMFS_INSTALL += " \
initramfs-isar-example-hook \
- initramfs-fsck-hook-ext4 \
+ initramfs-fsck-ext4-hook \
"
diff --git a/meta/recipes-support/initramfs-fsck-hook/files/initramfs-fsck-hook-ext4.triggers b/meta/recipes-initramfs/initramfs-fsck-hook/files/initramfs-fsck-hook-ext4.triggers
similarity index 100%
rename from meta/recipes-support/initramfs-fsck-hook/files/initramfs-fsck-hook-ext4.triggers
rename to meta/recipes-initramfs/initramfs-fsck-hook/files/initramfs-fsck-hook-ext4.triggers
diff --git a/meta/recipes-initramfs/initramfs-fsck-hook/initramfs-fsck-ext4-hook_0.3.bb b/meta/recipes-initramfs/initramfs-fsck-hook/initramfs-fsck-ext4-hook_0.3.bb
new file mode 100644
index 00000000..c4d10c44
--- /dev/null
+++ b/meta/recipes-initramfs/initramfs-fsck-hook/initramfs-fsck-ext4-hook_0.3.bb
@@ -0,0 +1,14 @@
+# This software is a part of ISAR.
+# Copyright (C) Siemens AG, 2019-2024
+#
+# SPDX-License-Identifier: MIT
+
+DESCRIPTION = "Recipe to add fsck hook to the initramfs"
+
+require recipes-initramfs/initramfs-hook/hook.inc
+
+SRC_URI += "file://initramfs-fsck-hook-ext4.triggers"
+
+HOOK_COPY_EXECS = "fsck fsck.ext4 logsave"
+
+DEBIAN_DEPENDS .= ", e2fsprogs, logsave"
diff --git a/meta/recipes-support/initramfs-fsck-hook/files/initramfs.fsck.ext4.hook b/meta/recipes-support/initramfs-fsck-hook/files/initramfs.fsck.ext4.hook
deleted file mode 100644
index 259b73b4..00000000
--- a/meta/recipes-support/initramfs-fsck-hook/files/initramfs.fsck.ext4.hook
+++ /dev/null
@@ -1,39 +0,0 @@
-# This software is a part of ISAR.
-# Copyright (C) Siemens AG, 2019
-#
-# SPDX-License-Identifier: MIT
-
-#!/bin/sh
-
-set -e
-
-PREREQ=""
-
-prereqs()
-{
- echo "$PREREQ"
-}
-
-case $1 in
-prereqs)
- prereqs
- exit 0
- ;;
-esac
-
-. /usr/share/initramfs-tools/scripts/functions
-. /usr/share/initramfs-tools/hook-functions
-
-if [ ! -x /sbin/fsck ]; then
- echo "Warning: couldn't find /sbin/fsck!"
- exit 0
-fi
-
-copy_exec /sbin/fsck
-copy_exec /sbin/logsave
-
-if prog="$(command -v fsck.ext4)"; then
- copy_exec "$prog"
-else
- echo "Warning: /sbin/fsck.ext4 doesn't exist, can't install to initramfs, ignoring."
-fi
diff --git a/meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-hook-ext4_0.2.bb b/meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-hook-ext4_0.2.bb
deleted file mode 100644
index 9860dbc8..00000000
--- a/meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-hook-ext4_0.2.bb
+++ /dev/null
@@ -1,18 +0,0 @@
-# This software is a part of ISAR.
-# Copyright (C) Siemens AG, 2019
-#
-# SPDX-License-Identifier: MIT
-
-
-DESCRIPTION = "Recipe to add fsck hook to the initramfs"
-
-inherit dpkg-raw
-SRC_URI = "file://initramfs-fsck-hook-ext4.triggers \
- file://initramfs.fsck.ext4.hook \
- "
-
-
-do_install() {

Jan Kiszka

unread,
Nov 16, 2024, 6:13:07 AM11/16/24
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

Reduces the own bits significantly.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
.../files/{tee-ftpm.script => local-top} | 18 +-----------
.../files/tee-ftpm.hook | 28 -------------------
.../initramfs-tee-ftpm-hook_0.1.bb | 27 ------------------
.../initramfs-tee-ftpm-hook_0.2.bb | 15 ++++++++++
4 files changed, 16 insertions(+), 72 deletions(-)
rename meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/{tee-ftpm.script => local-top} (75%)
delete mode 100644 meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/tee-ftpm.hook
delete mode 100644 meta/recipes-initramfs/initramfs-tee-ftpm-hook/initramfs-tee-ftpm-hook_0.1.bb
create mode 100644 meta/recipes-initramfs/initramfs-tee-ftpm-hook/initramfs-tee-ftpm-hook_0.2.bb

diff --git a/meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/tee-ftpm.script b/meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/local-top
similarity index 75%
rename from meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/tee-ftpm.script
rename to meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/local-top
index 3355a7e0..989bf288 100644
--- a/meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/tee-ftpm.script
+++ b/meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/local-top
@@ -1,4 +1,4 @@
-#!/bin/sh
+#
# Copyright (c) Siemens AG, 2023
#
# Authors:
@@ -7,22 +7,6 @@
# SPDX-License-Identifier: MIT
#

-set -e
-
-PREREQ="tee-supplicant"
-prereqs()
-{
- echo "$PREREQ"
-}
-case $1 in
-prereqs)
- prereqs
- exit 0
- ;;
-esac
-
-. /scripts/functions
-
FTPM_DEV=/dev/tpmrm0

# The tee-supplicant would take some time to be discovered, 30 seconds should
diff --git a/meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/tee-ftpm.hook b/meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/tee-ftpm.hook
deleted file mode 100644
index e80f00b4..00000000
--- a/meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/tee-ftpm.hook
+++ /dev/null
@@ -1,28 +0,0 @@
-#!/bin/sh
-# Copyright (c) Siemens AG, 2023
-#
-# Authors:
-# Su Bao Cheng <baoch...@siemens.com>
-#
-# SPDX-License-Identifier: MIT
-#
-
-set -e
-
-PREREQ="tee-supplicant"
-prereqs()
-{
- echo "$PREREQ"
-}
-case $1 in
-prereqs)
- prereqs
- exit 0
- ;;
-esac
-
-. /usr/share/initramfs-tools/hook-functions
-
-# The tpm_ftpm_tee.ko does not exist in any stock debian kernels, it could be
-# provided by customized kernel.
-manual_add_modules tpm_ftpm_tee
diff --git a/meta/recipes-initramfs/initramfs-tee-ftpm-hook/initramfs-tee-ftpm-hook_0.1.bb b/meta/recipes-initramfs/initramfs-tee-ftpm-hook/initramfs-tee-ftpm-hook_0.1.bb
deleted file mode 100644
index 82fec1bb..00000000
--- a/meta/recipes-initramfs/initramfs-tee-ftpm-hook/initramfs-tee-ftpm-hook_0.1.bb
+++ /dev/null
@@ -1,27 +0,0 @@
-# Copyright (c) Siemens AG, 2023
-#
-# Authors:
-# Su Bao Cheng <baoch...@siemens.com>
-#
-# SPDX-License-Identifier: MIT
-#
-
-inherit dpkg-raw
-
-SRC_URI += " \
- file://tee-ftpm.hook \
- file://tee-ftpm.script \
- "
-
-DEBIAN_DEPENDS = "initramfs-tools"
-
-do_install[cleandirs] += " \
- ${D}/usr/share/initramfs-tools/hooks \
- ${D}/usr/share/initramfs-tools/scripts/local-top"
-
-do_install() {
- install -m 0755 "${WORKDIR}/tee-ftpm.hook" \
- "${D}/usr/share/initramfs-tools/hooks/tee-ftpm"
- install -m 0755 "${WORKDIR}/tee-ftpm.script" \
- "${D}/usr/share/initramfs-tools/scripts/local-top/tee-ftpm"
-}
diff --git a/meta/recipes-initramfs/initramfs-tee-ftpm-hook/initramfs-tee-ftpm-hook_0.2.bb b/meta/recipes-initramfs/initramfs-tee-ftpm-hook/initramfs-tee-ftpm-hook_0.2.bb
new file mode 100644
index 00000000..9f77c158
--- /dev/null
+++ b/meta/recipes-initramfs/initramfs-tee-ftpm-hook/initramfs-tee-ftpm-hook_0.2.bb
@@ -0,0 +1,15 @@
+# Copyright (c) Siemens AG, 2023-2024
+#
+# Authors:
+# Su Bao Cheng <baoch...@siemens.com>
+#
+# SPDX-License-Identifier: MIT
+#
+
+require recipes-initramfs/initramfs-hook/hook.inc
+

Jan Kiszka

unread,
Nov 16, 2024, 6:13:07 AM11/16/24
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

Ensure basic CI coverage for this hook recipe.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
meta-isar/recipes-initramfs/images/isar-initramfs.bb | 1 +
1 file changed, 1 insertion(+)

diff --git a/meta-isar/recipes-initramfs/images/isar-initramfs.bb b/meta-isar/recipes-initramfs/images/isar-initramfs.bb
index aaa0350a..4df9e0b8 100644
--- a/meta-isar/recipes-initramfs/images/isar-initramfs.bb
+++ b/meta-isar/recipes-initramfs/images/isar-initramfs.bb
@@ -15,4 +15,5 @@ INITRAMFS_PREINSTALL += " \
# Recipes that should be installed into the initramfs build rootfs.
INITRAMFS_INSTALL += " \

Jan Kiszka

unread,
Nov 18, 2024, 9:35:16 AM11/18/24
to isar-users, Quirin Gylstorff
OK, will need v5: Unconditionally adding a script header is too
inflexible. There are cases where the users are better of providing a
complete script themselves, e.g. when the PREREQ are function-generated
or when there are multiple boot scripts at multiple stages in the same
recipe with different PREREQs. We need an opt-out.

Jan

Jan Kiszka

unread,
Nov 20, 2024, 12:03:05 PM11/20/24
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

Ensure basic CI coverage for this hook recipe.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---

Jan Kiszka

unread,
Nov 20, 2024, 12:03:05 PM11/20/24
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

This recipe include shall simplify writing of initramfs hooks. It
provides the usual headers for the installation hook as well as the boot
scripts, allow to generate that code that installs executables and
modules into the image, but also supports expanding the scripts with own
snippets or defining own ones completely.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
.../initramfs-hook/files/hook-header.tmpl | 39 +++++++++
.../initramfs-hook/files/script-header.tmpl | 26 ++++++
.../recipes-initramfs/initramfs-hook/hook.inc | 81 +++++++++++++++++++
3 files changed, 146 insertions(+)
index 00000000..c80b781d
--- /dev/null
+++ b/meta/recipes-initramfs/initramfs-hook/hook.inc
@@ -0,0 +1,81 @@
+ if [ ! -f "${WORKDIR}/$script" ] && [ ! -f "${WORKDIR}/${script}-complete" ]; then
+ continue
+ fi
+
+ rm -rf "${D}/usr/share/initramfs-tools/scripts/$script"
+ install -d -m 0755 "${D}/usr/share/initramfs-tools/scripts/$script"
+ if [ -f "${WORKDIR}/${script}" ]; then
+ install -m 0755 "${WORKDIR}/script-header" \
+ "${D}/usr/share/initramfs-tools/scripts/$script/${INITRAMFS_HOOK_NAME}"
+ cat "${WORKDIR}/$script" >> \
+ "${D}/usr/share/initramfs-tools/scripts/$script/${INITRAMFS_HOOK_NAME}"
+ else
+ install -m 0755 "${WORKDIR}/${script}-complete" \
+ "${D}/usr/share/initramfs-tools/scripts/$script/${INITRAMFS_HOOK_NAME}"
+ fi

Jan Kiszka

unread,
Nov 20, 2024, 12:03:05 PM11/20/24
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

Document to new hook.inc as well as the preexisting initramfs class.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
doc/user_manual.md | 58 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 58 insertions(+)

diff --git a/doc/user_manual.md b/doc/user_manual.md
index 8f745214..1e505c66 100644
--- a/doc/user_manual.md
+++ b/doc/user_manual.md
@@ -1611,3 +1611,61 @@ CONTAINER_DELETE_AFTER_LOAD = "1"

SRC_URI += "docker://debian;digest=sha256:f528891ab1aa484bf7233dbcc84f3c806c3e427571d75510a9d74bb5ec535b33;tag=bookworm-20240701-slim"
```
+
+## Customize the initramfs
+
+Isar supports the customization of initramfs images by providing an
+infrastructure for quickly creating hooks and by allowing to replace the
+Debian-generated image with a separately built one.
+
+### Creating initramfs hooks
+
+To create an initramfs hook that adds tools or modules to the image and may
+also run custom scripts during boot, use the include file
+`recipes-initramfs/initramfs-hook/hook.inc`. It is controlled via a number of
+variables:
+
+ - `HOOK_PREREQ` defines the prerequisites for running the hook script.
+ - `HOOK_ADD_MODULES` passes the provided modules names to the
+ `manual_add_modules` function during initramfs creation.
+ - `HOOK_COPY_EXECS` identifies the source of the passed executables on the
+ rootfs that runs mkinitramfs and passes that to `copy_exec`. If an
+ executable is not found, an error thrown, and the creation fails.
+ - `SCRIPT_PREREQ` defines the prerequisites for running the boot script(s).
+
+If the generated hook script is not sufficient, you can append an own
+bottom-half script by providing a `hook` file in `${WORKDIR}`. It will be
+appended to the `hook-header` that the helper generates.
+
+For running a custom script during boot-up, provide a bottom-half file in
+`${WORKDIR}`. Its name defines where it is hooked up with the initramfs boot
+process: `init-top`, `init-premount`, `local-top`, `nfs-top`, `local-block`,
+`local-premount`, `nfs-premount`, `local-bottom`, `nfs-bottom`, `init-bottom`.
+If you do not benefit from the script header with its static `SCRIPT_PREREQ`,
+you may instead provide `init-top-complete`, `init-premount-complete` etc. to
+still use automatic installation while defining the boot script completely
+yourself.

Jan Kiszka

unread,
Nov 20, 2024, 12:03:05 PM11/20/24
to isar-users, Quirin Gylstorff
Changes in v5:
- permit completely self-provided boot scripts as well
(now fully tested against an isar-cip-core port)

Changes in v4:
- add forgotten header to boot scripts
(this part was apparently only build-tested so far...)

Changes in v3:
- fix DEBIAN_DEPENDS for initramfs-tee-supplicant-hook
- use .= for extending DEBIAN_DEPENDS

Changes in v2:
- add commit message to patch 1

Specifically while looking at the initramfs recipes we have in
isar-cip-core, it felt like it's time to simplify their creation and
offload the developers from all the related boilerplate bits. But the
benefit can also be observed with the initramfs recipes in isar itself.

Jan

Jan Kiszka (7):
initramfs-hook: Add infrastructure to ease writing hooks
doc: Describe initramfs customizations
isar-initramfs: Add initramfs-fsck-hook-ext4
initramfs-isar-example-hook: Convert recipe over to new hook.inc
initramfs-fsck-ext4-hook: Convert to hook.inc and improve
initramfs-tee-ftpm-hook: Convert to hook.inc
initramfs-tee-supplicant-hook: Convert to hook.inc

doc/user_manual.md | 58 +++++++++++++
.../images/isar-initramfs.bb | 3 +-
.../initramfs-example/files/example.hook | 21 -----
.../initramfs-example/files/example.script | 23 ------
.../initramfs-example/files/local-top | 3 +
....bb => initramfs-isar-example-hook_0.1.bb} | 21 ++---
.../files/initramfs-fsck-hook-ext4.triggers | 0
.../initramfs-fsck-ext4-hook_0.3.bb | 14 ++++
.../initramfs-hook/files/hook-header.tmpl | 39 +++++++++
.../initramfs-hook/files/script-header.tmpl | 26 ++++++
.../recipes-initramfs/initramfs-hook/hook.inc | 81 +++++++++++++++++++
.../files/{tee-ftpm.script => local-top} | 18 +----
.../files/tee-ftpm.hook | 28 -------
.../initramfs-tee-ftpm-hook_0.1.bb | 27 -------
.../initramfs-tee-ftpm-hook_0.2.bb | 15 ++++
.../{tee-supplicant.script => local-top} | 18 +----
.../files/tee-supplicant.hook | 36 ---------
.../initramfs-tee-supplicant-hook_0.1.bb | 27 -------
.../initramfs-tee-supplicant-hook_0.2.bb | 16 ++++
.../files/initramfs.fsck.ext4.hook | 39 ---------
.../initramfs-fsck-hook-ext4_0.2.bb | 18 -----
21 files changed, 263 insertions(+), 268 deletions(-)
delete mode 100644 meta-isar/recipes-initramfs/initramfs-example/files/example.hook
delete mode 100644 meta-isar/recipes-initramfs/initramfs-example/files/example.script
create mode 100644 meta-isar/recipes-initramfs/initramfs-example/files/local-top
rename meta-isar/recipes-initramfs/initramfs-example/{initramfs-example.bb => initramfs-isar-example-hook_0.1.bb} (63%)
rename meta/{recipes-support => recipes-initramfs}/initramfs-fsck-hook/files/initramfs-fsck-hook-ext4.triggers (100%)
create mode 100644 meta/recipes-initramfs/initramfs-fsck-hook/initramfs-fsck-ext4-hook_0.3.bb
create mode 100644 meta/recipes-initramfs/initramfs-hook/files/hook-header.tmpl
create mode 100644 meta/recipes-initramfs/initramfs-hook/files/script-header.tmpl
create mode 100644 meta/recipes-initramfs/initramfs-hook/hook.inc
rename meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/{tee-ftpm.script => local-top} (75%)
delete mode 100644 meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/tee-ftpm.hook
delete mode 100644 meta/recipes-initramfs/initramfs-tee-ftpm-hook/initramfs-tee-ftpm-hook_0.1.bb
create mode 100644 meta/recipes-initramfs/initramfs-tee-ftpm-hook/initramfs-tee-ftpm-hook_0.2.bb
rename meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/{tee-supplicant.script => local-top} (68%)
delete mode 100644 meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/tee-supplicant.hook
delete mode 100644 meta/recipes-initramfs/initramfs-tee-supplicant-hook/initramfs-tee-supplicant-hook_0.1.bb
create mode 100644 meta/recipes-initramfs/initramfs-tee-supplicant-hook/initramfs-tee-supplicant-hook_0.2.bb
delete mode 100644 meta/recipes-support/initramfs-fsck-hook/files/initramfs.fsck.ext4.hook
delete mode 100644 meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-hook-ext4_0.2.bb

--
2.43.0

Jan Kiszka

unread,
Nov 20, 2024, 12:03:06 PM11/20/24
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

Use the convention and helping features of the new initramfs hook.inc to
simplify this hook. We move it under recipes-initramfs to align with
other recipes there. Another change is making fsck.ext4 mandatory, both
as dependency and while copying it in via the helper - there is no
reason for this recipe to almost silently ignore any unavailability.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
.../images/isar-initramfs.bb | 2 +-
.../files/initramfs-fsck-hook-ext4.triggers | 0
.../initramfs-fsck-ext4-hook_0.3.bb | 14 +++++++
.../files/initramfs.fsck.ext4.hook | 39 -------------------
.../initramfs-fsck-hook-ext4_0.2.bb | 18 ---------
5 files changed, 15 insertions(+), 58 deletions(-)
rename meta/{recipes-support => recipes-initramfs}/initramfs-fsck-hook/files/initramfs-fsck-hook-ext4.triggers (100%)
create mode 100644 meta/recipes-initramfs/initramfs-fsck-hook/initramfs-fsck-ext4-hook_0.3.bb
delete mode 100644 meta/recipes-support/initramfs-fsck-hook/files/initramfs.fsck.ext4.hook
delete mode 100644 meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-hook-ext4_0.2.bb

diff --git a/meta-isar/recipes-initramfs/images/isar-initramfs.bb b/meta-isar/recipes-initramfs/images/isar-initramfs.bb
index 71dbaa43..d2a946f7 100644
--- a/meta-isar/recipes-initramfs/images/isar-initramfs.bb
+++ b/meta-isar/recipes-initramfs/images/isar-initramfs.bb
@@ -15,5 +15,5 @@ INITRAMFS_PREINSTALL += " \
# Recipes that should be installed into the initramfs build rootfs.
INITRAMFS_INSTALL += " \
initramfs-isar-example-hook \
- initramfs-fsck-hook-ext4 \
+ initramfs-fsck-ext4-hook \
"
diff --git a/meta/recipes-support/initramfs-fsck-hook/files/initramfs-fsck-hook-ext4.triggers b/meta/recipes-initramfs/initramfs-fsck-hook/files/initramfs-fsck-hook-ext4.triggers
similarity index 100%
rename from meta/recipes-support/initramfs-fsck-hook/files/initramfs-fsck-hook-ext4.triggers
rename to meta/recipes-initramfs/initramfs-fsck-hook/files/initramfs-fsck-hook-ext4.triggers
diff --git a/meta/recipes-initramfs/initramfs-fsck-hook/initramfs-fsck-ext4-hook_0.3.bb b/meta/recipes-initramfs/initramfs-fsck-hook/initramfs-fsck-ext4-hook_0.3.bb
new file mode 100644
index 00000000..c4d10c44
--- /dev/null
+++ b/meta/recipes-initramfs/initramfs-fsck-hook/initramfs-fsck-ext4-hook_0.3.bb
@@ -0,0 +1,14 @@
+# This software is a part of ISAR.
+# Copyright (C) Siemens AG, 2019-2024
+#
+# SPDX-License-Identifier: MIT
+
+DESCRIPTION = "Recipe to add fsck hook to the initramfs"
+
+require recipes-initramfs/initramfs-hook/hook.inc
+
+SRC_URI += "file://initramfs-fsck-hook-ext4.triggers"
+
+HOOK_COPY_EXECS = "fsck fsck.ext4 logsave"
+
+DEBIAN_DEPENDS .= ", e2fsprogs, logsave"
diff --git a/meta/recipes-support/initramfs-fsck-hook/files/initramfs.fsck.ext4.hook b/meta/recipes-support/initramfs-fsck-hook/files/initramfs.fsck.ext4.hook
deleted file mode 100644
index 259b73b4..00000000
--- a/meta/recipes-support/initramfs-fsck-hook/files/initramfs.fsck.ext4.hook
+++ /dev/null
@@ -1,39 +0,0 @@
-# This software is a part of ISAR.
-# Copyright (C) Siemens AG, 2019
-#
-# SPDX-License-Identifier: MIT
-
-#!/bin/sh
-
-set -e
-
-PREREQ=""
-
-prereqs()
-{
- echo "$PREREQ"
-}
-
-case $1 in
-prereqs)
- prereqs
- exit 0
- ;;
-esac
-
-. /usr/share/initramfs-tools/scripts/functions
-. /usr/share/initramfs-tools/hook-functions
-
-if [ ! -x /sbin/fsck ]; then
- echo "Warning: couldn't find /sbin/fsck!"
- exit 0
-fi
-
-copy_exec /sbin/fsck
-copy_exec /sbin/logsave
-
-if prog="$(command -v fsck.ext4)"; then
- copy_exec "$prog"
-else
- echo "Warning: /sbin/fsck.ext4 doesn't exist, can't install to initramfs, ignoring."
-fi
diff --git a/meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-hook-ext4_0.2.bb b/meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-hook-ext4_0.2.bb
deleted file mode 100644
index 9860dbc8..00000000
--- a/meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-hook-ext4_0.2.bb
+++ /dev/null
@@ -1,18 +0,0 @@
-# This software is a part of ISAR.
-# Copyright (C) Siemens AG, 2019
-#
-# SPDX-License-Identifier: MIT
-
-
-DESCRIPTION = "Recipe to add fsck hook to the initramfs"
-
-inherit dpkg-raw
-SRC_URI = "file://initramfs-fsck-hook-ext4.triggers \
- file://initramfs.fsck.ext4.hook \
- "
-
-
-do_install() {

Jan Kiszka

unread,
Nov 20, 2024, 12:03:07 PM11/20/24
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

Reduces the own bits significantly.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
.../{tee-supplicant.script => local-top} | 18 +---------
.../files/tee-supplicant.hook | 36 -------------------
.../initramfs-tee-supplicant-hook_0.1.bb | 27 --------------
.../initramfs-tee-supplicant-hook_0.2.bb | 16 +++++++++
4 files changed, 17 insertions(+), 80 deletions(-)
rename meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/{tee-supplicant.script => local-top} (68%)
delete mode 100644 meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/tee-supplicant.hook
delete mode 100644 meta/recipes-initramfs/initramfs-tee-supplicant-hook/initramfs-tee-supplicant-hook_0.1.bb
create mode 100644 meta/recipes-initramfs/initramfs-tee-supplicant-hook/initramfs-tee-supplicant-hook_0.2.bb

diff --git a/meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/tee-supplicant.script b/meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/local-top
similarity index 68%
rename from meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/tee-supplicant.script
rename to meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/local-top
index ac01d7ec..575a742d 100644
--- a/meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/tee-supplicant.script
+++ b/meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/local-top
@@ -1,4 +1,4 @@
-#!/bin/sh
+#
# Copyright (c) Siemens AG, 2023
#
# Authors:
@@ -7,22 +7,6 @@
# SPDX-License-Identifier: MIT
#

-set -e
-
-PREREQ=""
-prereqs()
-{
- echo "$PREREQ"
-}
-case $1 in
-prereqs)
- prereqs
- exit 0
- ;;
-esac
-
-. /scripts/functions
-
/usr/sbin/modprobe optee
/usr/sbin/tee-supplicant -d

diff --git a/meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/tee-supplicant.hook b/meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/tee-supplicant.hook
deleted file mode 100644
index 3e2f4016..00000000
--- a/meta/recipes-initramfs/initramfs-tee-supplicant-hook/files/tee-supplicant.hook
+++ /dev/null
@@ -1,36 +0,0 @@
-#!/bin/sh
-# Copyright (c) Siemens AG, 2023
-#
-# Authors:
-# Su Bao Cheng <baoch...@siemens.com>
-#
-# SPDX-License-Identifier: MIT
-#
-
-set -e
-
-PREREQ=""
-prereqs()
-{
- echo "$PREREQ"
-}
-case $1 in
-prereqs)
- prereqs
- exit 0
- ;;
-esac
-
-. /usr/share/initramfs-tools/hook-functions
-
-hook_error() {
- echo "(ERROR): $1" >&2
- exit 1
-}
-
-# For stock debian bookworm arm64 kernel, these two .ko exist, but not built-in.
-manual_add_modules tee
-manual_add_modules optee
-
-copy_exec /usr/sbin/tee-supplicant || hook_error "/usr/sbin/tee-supplicant not found"
-copy_exec /usr/bin/pgrep || hook_error "/usr/bin/pgrep not found"
diff --git a/meta/recipes-initramfs/initramfs-tee-supplicant-hook/initramfs-tee-supplicant-hook_0.1.bb b/meta/recipes-initramfs/initramfs-tee-supplicant-hook/initramfs-tee-supplicant-hook_0.1.bb
deleted file mode 100644
index a7a19bee..00000000
--- a/meta/recipes-initramfs/initramfs-tee-supplicant-hook/initramfs-tee-supplicant-hook_0.1.bb
+++ /dev/null
@@ -1,27 +0,0 @@
-# Copyright (c) Siemens AG, 2023
-#
-# Authors:
-# Su Bao Cheng <baoch...@siemens.com>
-#
-# SPDX-License-Identifier: MIT
-#
-
-inherit dpkg-raw
-
-SRC_URI += " \
- file://tee-supplicant.hook \
- file://tee-supplicant.script \
- "
-
-DEBIAN_DEPENDS = "initramfs-tools, tee-supplicant, procps"
-
-do_install[cleandirs] += " \
- ${D}/usr/share/initramfs-tools/hooks \
- ${D}/usr/share/initramfs-tools/scripts/local-top"
-
-do_install() {
- install -m 0755 "${WORKDIR}/tee-supplicant.hook" \
- "${D}/usr/share/initramfs-tools/hooks/tee-supplicant"
- install -m 0755 "${WORKDIR}/tee-supplicant.script" \
- "${D}/usr/share/initramfs-tools/scripts/local-top/tee-supplicant"
-}
diff --git a/meta/recipes-initramfs/initramfs-tee-supplicant-hook/initramfs-tee-supplicant-hook_0.2.bb b/meta/recipes-initramfs/initramfs-tee-supplicant-hook/initramfs-tee-supplicant-hook_0.2.bb
new file mode 100644
index 00000000..b9dedfd3
--- /dev/null
+++ b/meta/recipes-initramfs/initramfs-tee-supplicant-hook/initramfs-tee-supplicant-hook_0.2.bb
@@ -0,0 +1,16 @@
+# Copyright (c) Siemens AG, 2023-2024
+#
+# Authors:
+# Su Bao Cheng <baoch...@siemens.com>
+#
+# SPDX-License-Identifier: MIT
+#
+
+require recipes-initramfs/initramfs-hook/hook.inc
+

Jan Kiszka

unread,
Nov 20, 2024, 12:03:07 PM11/20/24
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

Reduces the own bits significantly.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
.../files/{tee-ftpm.script => local-top} | 18 +-----------
.../files/tee-ftpm.hook | 28 -------------------
.../initramfs-tee-ftpm-hook_0.1.bb | 27 ------------------
.../initramfs-tee-ftpm-hook_0.2.bb | 15 ++++++++++
4 files changed, 16 insertions(+), 72 deletions(-)
rename meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/{tee-ftpm.script => local-top} (75%)
delete mode 100644 meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/tee-ftpm.hook
delete mode 100644 meta/recipes-initramfs/initramfs-tee-ftpm-hook/initramfs-tee-ftpm-hook_0.1.bb
create mode 100644 meta/recipes-initramfs/initramfs-tee-ftpm-hook/initramfs-tee-ftpm-hook_0.2.bb

diff --git a/meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/tee-ftpm.script b/meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/local-top
similarity index 75%
rename from meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/tee-ftpm.script
rename to meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/local-top
index 3355a7e0..989bf288 100644
--- a/meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/tee-ftpm.script
+++ b/meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/local-top
@@ -1,4 +1,4 @@
-#!/bin/sh
+#
# Copyright (c) Siemens AG, 2023
#
# Authors:
@@ -7,22 +7,6 @@
# SPDX-License-Identifier: MIT
#

-set -e
-
-PREREQ="tee-supplicant"
-prereqs()
-{
- echo "$PREREQ"
-}
-case $1 in
-prereqs)
- prereqs
- exit 0
- ;;
-esac
-
-. /scripts/functions
-
FTPM_DEV=/dev/tpmrm0

# The tee-supplicant would take some time to be discovered, 30 seconds should
diff --git a/meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/tee-ftpm.hook b/meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/tee-ftpm.hook
deleted file mode 100644
index e80f00b4..00000000
--- a/meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/tee-ftpm.hook
+++ /dev/null
@@ -1,28 +0,0 @@
-#!/bin/sh
-# Copyright (c) Siemens AG, 2023
-#
-# Authors:
-# Su Bao Cheng <baoch...@siemens.com>
-#
-# SPDX-License-Identifier: MIT
-#
-
-set -e
-
-PREREQ="tee-supplicant"
-prereqs()
-{
- echo "$PREREQ"
-}
-case $1 in
-prereqs)
- prereqs
- exit 0
- ;;
-esac
-
-. /usr/share/initramfs-tools/hook-functions
-
-# The tpm_ftpm_tee.ko does not exist in any stock debian kernels, it could be
-# provided by customized kernel.
-manual_add_modules tpm_ftpm_tee
diff --git a/meta/recipes-initramfs/initramfs-tee-ftpm-hook/initramfs-tee-ftpm-hook_0.1.bb b/meta/recipes-initramfs/initramfs-tee-ftpm-hook/initramfs-tee-ftpm-hook_0.1.bb
deleted file mode 100644
index 82fec1bb..00000000
--- a/meta/recipes-initramfs/initramfs-tee-ftpm-hook/initramfs-tee-ftpm-hook_0.1.bb
+++ /dev/null
@@ -1,27 +0,0 @@
-# Copyright (c) Siemens AG, 2023
-#
-# Authors:
-# Su Bao Cheng <baoch...@siemens.com>
-#
-# SPDX-License-Identifier: MIT
-#
-
-inherit dpkg-raw
-
-SRC_URI += " \
- file://tee-ftpm.hook \
- file://tee-ftpm.script \
- "
-
-DEBIAN_DEPENDS = "initramfs-tools"
-
-do_install[cleandirs] += " \
- ${D}/usr/share/initramfs-tools/hooks \
- ${D}/usr/share/initramfs-tools/scripts/local-top"
-
-do_install() {
- install -m 0755 "${WORKDIR}/tee-ftpm.hook" \
- "${D}/usr/share/initramfs-tools/hooks/tee-ftpm"
- install -m 0755 "${WORKDIR}/tee-ftpm.script" \
- "${D}/usr/share/initramfs-tools/scripts/local-top/tee-ftpm"
-}
diff --git a/meta/recipes-initramfs/initramfs-tee-ftpm-hook/initramfs-tee-ftpm-hook_0.2.bb b/meta/recipes-initramfs/initramfs-tee-ftpm-hook/initramfs-tee-ftpm-hook_0.2.bb
new file mode 100644
index 00000000..9f77c158
--- /dev/null
+++ b/meta/recipes-initramfs/initramfs-tee-ftpm-hook/initramfs-tee-ftpm-hook_0.2.bb
@@ -0,0 +1,15 @@
+# Copyright (c) Siemens AG, 2023-2024
+#
+# Authors:
+# Su Bao Cheng <baoch...@siemens.com>
+#
+# SPDX-License-Identifier: MIT
+#
+
+require recipes-initramfs/initramfs-hook/hook.inc
+
+SRC_URI += "file://local-top"
+

Jan Kiszka

unread,
Nov 20, 2024, 12:03:08 PM11/20/24
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

Allows to drop the own hook recipe and makes the local-top boot script
effectively a one-liner.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
.../images/isar-initramfs.bb | 2 +-
.../initramfs-example/files/example.hook | 21 -----------------
.../initramfs-example/files/example.script | 23 -------------------
.../initramfs-example/files/local-top | 3 +++
....bb => initramfs-isar-example-hook_0.1.bb} | 21 ++++++-----------
5 files changed, 11 insertions(+), 59 deletions(-)
delete mode 100644 meta-isar/recipes-initramfs/initramfs-example/files/example.hook
delete mode 100644 meta-isar/recipes-initramfs/initramfs-example/files/example.script
create mode 100644 meta-isar/recipes-initramfs/initramfs-example/files/local-top
rename meta-isar/recipes-initramfs/initramfs-example/{initramfs-example.bb => initramfs-isar-example-hook_0.1.bb} (63%)

diff --git a/meta-isar/recipes-initramfs/images/isar-initramfs.bb b/meta-isar/recipes-initramfs/images/isar-initramfs.bb
index 4df9e0b8..71dbaa43 100644
--- a/meta-isar/recipes-initramfs/images/isar-initramfs.bb
+++ b/meta-isar/recipes-initramfs/images/isar-initramfs.bb
@@ -14,6 +14,6 @@ INITRAMFS_PREINSTALL += " \

# Recipes that should be installed into the initramfs build rootfs.
INITRAMFS_INSTALL += " \
- initramfs-example \
+ initramfs-isar-example-hook \
initramfs-fsck-hook-ext4 \
"
diff --git a/meta-isar/recipes-initramfs/initramfs-example/files/example.hook b/meta-isar/recipes-initramfs/initramfs-example/files/example.hook
deleted file mode 100644
index ba848c92..00000000
--- a/meta-isar/recipes-initramfs/initramfs-example/files/example.hook
+++ /dev/null
@@ -1,21 +0,0 @@
-#!/bin/sh
-# Example hook script.
-#
-# See "HOOK SCRIPTS" in initramfs-tools(7) for details.
-
-set -e
-
-PREREQ=""
-prereqs()
-{
- echo "$PREREQ"
-}
-case $1 in
-prereqs)
- prereqs
- exit 0
- ;;
-esac
-
-. /usr/share/initramfs-tools/hook-functions
-# Begin real processing below this line
diff --git a/meta-isar/recipes-initramfs/initramfs-example/files/example.script b/meta-isar/recipes-initramfs/initramfs-example/files/example.script
deleted file mode 100644
index c55e9ea7..00000000
--- a/meta-isar/recipes-initramfs/initramfs-example/files/example.script
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/bin/sh
-# Example boot script.
-#
-# See "BOOT SCRIPTS" in initramfs-tools(7) for details.
-
-set -e
-
-PREREQ=""
-prereqs()
-{
- echo "$PREREQ"
-}
-case $1 in
-prereqs)
- prereqs
- exit 0
- ;;
-esac
-
-. /scripts/functions
-# Begin real processing below this line
-
-log_success_msg "Hello from ISAR!"
diff --git a/meta-isar/recipes-initramfs/initramfs-example/files/local-top b/meta-isar/recipes-initramfs/initramfs-example/files/local-top
new file mode 100644
index 00000000..66e382b4
--- /dev/null
+++ b/meta-isar/recipes-initramfs/initramfs-example/files/local-top
@@ -0,0 +1,3 @@
+# Script header is provided by initramfs-hook/hook.inc
+
+log_success_msg "Hello from ISAR!"
diff --git a/meta-isar/recipes-initramfs/initramfs-example/initramfs-example.bb b/meta-isar/recipes-initramfs/initramfs-example/initramfs-isar-example-hook_0.1.bb
similarity index 63%
rename from meta-isar/recipes-initramfs/initramfs-example/initramfs-example.bb
rename to meta-isar/recipes-initramfs/initramfs-example/initramfs-isar-example-hook_0.1.bb
index c336dda9..8c600639 100644
--- a/meta-isar/recipes-initramfs/initramfs-example/initramfs-example.bb
+++ b/meta-isar/recipes-initramfs/initramfs-example/initramfs-isar-example-hook_0.1.bb
@@ -4,37 +4,30 @@
#
# This software is a part of ISAR.

+require recipes-initramfs/initramfs-hook/hook.inc
+
DESCRIPTION = "Sample initramfs module for ISAR"
MAINTAINER = "Your name here <y...@domain.com>"
-DEBIAN_DEPENDS = "initramfs-tools"

# If the conf-hook enables BUSYBOX=y, busybox is needed:
DEBIAN_DEPENDS .= ", busybox"

-SRC_URI = " \
+SRC_URI += " \
file://example.conf-hook \
- file://example.hook \
- file://example.script \
+ file://local-top \
"

-inherit dpkg-raw
-
do_install[cleandirs] += " \
${D}/usr/share/initramfs-tools/conf-hooks.d \
- ${D}/usr/share/initramfs-tools/hooks \

Jan Kiszka

unread,
Nov 20, 2024, 1:02:46 PM11/20/24
to isar-users, Quirin Gylstorff
On 20.11.24 18:02, 'Jan Kiszka' via isar-users wrote:
> Changes in v5:
> - permit completely self-provided boot scripts as well
> (now fully tested against an isar-cip-core port)
>

And here is the WiP branch of isar-cip-core that makes use of the new
hook.inc:

https://gitlab.com/cip-project/cip-core/isar-cip-core/-/commits/jan/rework-initramfs?ref_type=heads

Jan

Jan Kiszka

unread,
Dec 2, 2024, 12:59:33 AM12/2/24
to isar-users, Quirin Gylstorff
On 20.11.24 18:02, 'Jan Kiszka' via isar-users wrote:
Anything missing to get this merged? Downstream isar-cip-core would
benefit from it for its next release.

Jan

Uladzimir Bely

unread,
Dec 2, 2024, 3:04:36 AM12/2/24
to Jan Kiszka, isar-users
At least, not from the point of CI testing. The patchset recently was
tested and passes it. So, if there are no objections, it will be merged
today.

> --
> Siemens AG, Technology
> Linux Expert Center
>

--
Best regards,
Uladzimir.



Uladzimir Bely

unread,
Dec 2, 2024, 4:19:08 AM12/2/24
to Jan Kiszka, isar-users
>  delete mode 100644 meta-isar/recipes-initramfs/initramfs-
> example/files/example.hook
>  delete mode 100644 meta-isar/recipes-initramfs/initramfs-
> example/files/example.script
>  create mode 100644 meta-isar/recipes-initramfs/initramfs-
> example/files/local-top
>  rename meta-isar/recipes-initramfs/initramfs-example/{initramfs-
> example.bb => initramfs-isar-example-hook_0.1.bb} (63%)
>  rename meta/{recipes-support => recipes-initramfs}/initramfs-fsck-
> hook/files/initramfs-fsck-hook-ext4.triggers (100%)
>  create mode 100644 meta/recipes-initramfs/initramfs-fsck-
> hook/initramfs-fsck-ext4-hook_0.3.bb
>  create mode 100644 meta/recipes-initramfs/initramfs-hook/files/hook-
> header.tmpl
>  create mode 100644 meta/recipes-initramfs/initramfs-
> hook/files/script-header.tmpl
>  create mode 100644 meta/recipes-initramfs/initramfs-hook/hook.inc
>  rename meta/recipes-initramfs/initramfs-tee-ftpm-hook/files/{tee-
> ftpm.script => local-top} (75%)
>  delete mode 100644 meta/recipes-initramfs/initramfs-tee-ftpm-
> hook/files/tee-ftpm.hook
>  delete mode 100644 meta/recipes-initramfs/initramfs-tee-ftpm-
> hook/initramfs-tee-ftpm-hook_0.1.bb
>  create mode 100644 meta/recipes-initramfs/initramfs-tee-ftpm-
> hook/initramfs-tee-ftpm-hook_0.2.bb
>  rename meta/recipes-initramfs/initramfs-tee-supplicant-
> hook/files/{tee-supplicant.script => local-top} (68%)
>  delete mode 100644 meta/recipes-initramfs/initramfs-tee-supplicant-
> hook/files/tee-supplicant.hook
>  delete mode 100644 meta/recipes-initramfs/initramfs-tee-supplicant-
> hook/initramfs-tee-supplicant-hook_0.1.bb
>  create mode 100644 meta/recipes-initramfs/initramfs-tee-supplicant-
> hook/initramfs-tee-supplicant-hook_0.2.bb
>  delete mode 100644 meta/recipes-support/initramfs-fsck-
> hook/files/initramfs.fsck.ext4.hook
>  delete mode 100644 meta/recipes-support/initramfs-fsck-
> hook/initramfs-fsck-hook-ext4_0.2.bb
>
> --
> 2.43.0
>

Applied to next, thanks.

--
Best regards,
Uladzimir.
Reply all
Reply to author
Forward
0 new messages