public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
* [PATCH 0/7] Simplify writing initramfs hooks
@ 2024-11-11 20:50 'Jan Kiszka' via isar-users
  2024-11-11 20:50 ` [PATCH 1/7] initramfs-hook: Add infrastructure to ease writing hooks 'Jan Kiszka' via isar-users
                   ` (6 more replies)
  0 siblings, 7 replies; 12+ messages in thread
From: 'Jan Kiszka' via isar-users @ 2024-11-11 20:50 UTC (permalink / raw)
  To: isar-users; +Cc: 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

-- 
You received this message because you are subscribed to the Google Groups "isar-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/isar-users/cover.1731358224.git.jan.kiszka%40siemens.com.

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

* [PATCH 1/7] initramfs-hook: Add infrastructure to ease writing hooks
  2024-11-11 20:50 [PATCH 0/7] Simplify writing initramfs hooks 'Jan Kiszka' via isar-users
@ 2024-11-11 20:50 ` 'Jan Kiszka' via isar-users
  2024-11-12 10:00   ` 'Quirin Gylstorff' via isar-users
                     ` (2 more replies)
  2024-11-11 20:50 ` [PATCH 2/7] doc: Describe initramfs customizations 'Jan Kiszka' via isar-users
                   ` (5 subsequent siblings)
  6 siblings, 3 replies; 12+ messages in thread
From: 'Jan Kiszka' via isar-users @ 2024-11-11 20:50 UTC (permalink / raw)
  To: isar-users; +Cc: Quirin Gylstorff

From: Jan Kiszka <jan.kiszka@siemens.com>

xxx

Signed-off-by: Jan Kiszka <jan.kiszka@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.kiszka@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.kiszka@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.kiszka@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

-- 
You received this message because you are subscribed to the Google Groups "isar-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/isar-users/934f188717e95b8c019736e4546d57e90a247327.1731358224.git.jan.kiszka%40siemens.com.

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

* [PATCH 2/7] doc: Describe initramfs customizations
  2024-11-11 20:50 [PATCH 0/7] Simplify writing initramfs hooks 'Jan Kiszka' via isar-users
  2024-11-11 20:50 ` [PATCH 1/7] initramfs-hook: Add infrastructure to ease writing hooks 'Jan Kiszka' via isar-users
@ 2024-11-11 20:50 ` 'Jan Kiszka' via isar-users
  2024-11-11 20:50 ` [PATCH 3/7] isar-initramfs: Add initramfs-fsck-hook-ext4 'Jan Kiszka' via isar-users
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 12+ messages in thread
From: 'Jan Kiszka' via isar-users @ 2024-11-11 20:50 UTC (permalink / raw)
  To: isar-users; +Cc: Quirin Gylstorff

From: Jan Kiszka <jan.kiszka@siemens.com>

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

Signed-off-by: Jan Kiszka <jan.kiszka@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

-- 
You received this message because you are subscribed to the Google Groups "isar-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/isar-users/423377b14db0f2acc9534af4f8f436fc862accff.1731358224.git.jan.kiszka%40siemens.com.

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

* [PATCH 3/7] isar-initramfs: Add initramfs-fsck-hook-ext4
  2024-11-11 20:50 [PATCH 0/7] Simplify writing initramfs hooks 'Jan Kiszka' via isar-users
  2024-11-11 20:50 ` [PATCH 1/7] initramfs-hook: Add infrastructure to ease writing hooks 'Jan Kiszka' via isar-users
  2024-11-11 20:50 ` [PATCH 2/7] doc: Describe initramfs customizations 'Jan Kiszka' via isar-users
@ 2024-11-11 20:50 ` 'Jan Kiszka' via isar-users
  2024-11-11 20:50 ` [PATCH 4/7] initramfs-isar-example-hook: Convert recipe over to new hook.inc 'Jan Kiszka' via isar-users
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 12+ messages in thread
From: 'Jan Kiszka' via isar-users @ 2024-11-11 20:50 UTC (permalink / raw)
  To: isar-users; +Cc: Quirin Gylstorff

From: Jan Kiszka <jan.kiszka@siemens.com>

Ensure basic CI coverage for this hook recipe.

Signed-off-by: Jan Kiszka <jan.kiszka@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

-- 
You received this message because you are subscribed to the Google Groups "isar-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/isar-users/ba110a118b23548b8e4108f0f09c4408bed656f3.1731358224.git.jan.kiszka%40siemens.com.

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

* [PATCH 4/7] initramfs-isar-example-hook: Convert recipe over to new hook.inc
  2024-11-11 20:50 [PATCH 0/7] Simplify writing initramfs hooks 'Jan Kiszka' via isar-users
                   ` (2 preceding siblings ...)
  2024-11-11 20:50 ` [PATCH 3/7] isar-initramfs: Add initramfs-fsck-hook-ext4 'Jan Kiszka' via isar-users
@ 2024-11-11 20:50 ` 'Jan Kiszka' via isar-users
  2024-11-11 20:50 ` [PATCH 5/7] initramfs-fsck-ext4-hook: Convert to hook.inc and improve 'Jan Kiszka' via isar-users
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 12+ messages in thread
From: 'Jan Kiszka' via isar-users @ 2024-11-11 20:50 UTC (permalink / raw)
  To: isar-users; +Cc: Quirin Gylstorff

From: Jan Kiszka <jan.kiszka@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.kiszka@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 <you@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

-- 
You received this message because you are subscribed to the Google Groups "isar-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/isar-users/780bf2b1ace9344af7834997088095d1e1500179.1731358224.git.jan.kiszka%40siemens.com.

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

* [PATCH 5/7] initramfs-fsck-ext4-hook: Convert to hook.inc and improve
  2024-11-11 20:50 [PATCH 0/7] Simplify writing initramfs hooks 'Jan Kiszka' via isar-users
                   ` (3 preceding siblings ...)
  2024-11-11 20:50 ` [PATCH 4/7] initramfs-isar-example-hook: Convert recipe over to new hook.inc 'Jan Kiszka' via isar-users
@ 2024-11-11 20:50 ` 'Jan Kiszka' via isar-users
  2024-11-11 20:50 ` [PATCH 6/7] initramfs-tee-ftpm-hook: Convert to hook.inc 'Jan Kiszka' via isar-users
  2024-11-11 20:50 ` [PATCH 7/7] initramfs-tee-supplicant-hook: " 'Jan Kiszka' via isar-users
  6 siblings, 0 replies; 12+ messages in thread
From: 'Jan Kiszka' via isar-users @ 2024-11-11 20:50 UTC (permalink / raw)
  To: isar-users; +Cc: Quirin Gylstorff

From: Jan Kiszka <jan.kiszka@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.kiszka@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

-- 
You received this message because you are subscribed to the Google Groups "isar-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/isar-users/119732ece3ac710416516282f0cdcb5c05c9b4d1.1731358224.git.jan.kiszka%40siemens.com.

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

* [PATCH 6/7] initramfs-tee-ftpm-hook: Convert to hook.inc
  2024-11-11 20:50 [PATCH 0/7] Simplify writing initramfs hooks 'Jan Kiszka' via isar-users
                   ` (4 preceding siblings ...)
  2024-11-11 20:50 ` [PATCH 5/7] initramfs-fsck-ext4-hook: Convert to hook.inc and improve 'Jan Kiszka' via isar-users
@ 2024-11-11 20:50 ` 'Jan Kiszka' via isar-users
  2024-11-11 20:50 ` [PATCH 7/7] initramfs-tee-supplicant-hook: " 'Jan Kiszka' via isar-users
  6 siblings, 0 replies; 12+ messages in thread
From: 'Jan Kiszka' via isar-users @ 2024-11-11 20:50 UTC (permalink / raw)
  To: isar-users; +Cc: Quirin Gylstorff

From: Jan Kiszka <jan.kiszka@siemens.com>

Reduces the own bits significantly.

Signed-off-by: Jan Kiszka <jan.kiszka@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 <baocheng.su@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 <baocheng.su@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 <baocheng.su@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

-- 
You received this message because you are subscribed to the Google Groups "isar-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/isar-users/e30003325628891e335d5186e63c3451c1918dae.1731358224.git.jan.kiszka%40siemens.com.

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

* [PATCH 7/7] initramfs-tee-supplicant-hook: Convert to hook.inc
  2024-11-11 20:50 [PATCH 0/7] Simplify writing initramfs hooks 'Jan Kiszka' via isar-users
                   ` (5 preceding siblings ...)
  2024-11-11 20:50 ` [PATCH 6/7] initramfs-tee-ftpm-hook: Convert to hook.inc 'Jan Kiszka' via isar-users
@ 2024-11-11 20:50 ` 'Jan Kiszka' via isar-users
  6 siblings, 0 replies; 12+ messages in thread
From: 'Jan Kiszka' via isar-users @ 2024-11-11 20:50 UTC (permalink / raw)
  To: isar-users; +Cc: Quirin Gylstorff

From: Jan Kiszka <jan.kiszka@siemens.com>

Reduces the own bits significantly.

Signed-off-by: Jan Kiszka <jan.kiszka@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 <baocheng.su@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 <baocheng.su@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 <baocheng.su@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

-- 
You received this message because you are subscribed to the Google Groups "isar-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/isar-users/f4624a4e64793794de97891f8108ee392aa36a29.1731358224.git.jan.kiszka%40siemens.com.

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

* Re: [PATCH 1/7] initramfs-hook: Add infrastructure to ease writing hooks
  2024-11-11 20:50 ` [PATCH 1/7] initramfs-hook: Add infrastructure to ease writing hooks 'Jan Kiszka' via isar-users
@ 2024-11-12 10:00   ` 'Quirin Gylstorff' via isar-users
  2024-11-12 10:14   ` 'Quirin Gylstorff' via isar-users
  2024-11-13  7:47   ` [PATCH v2 " 'Jan Kiszka' via isar-users
  2 siblings, 0 replies; 12+ messages in thread
From: 'Quirin Gylstorff' via isar-users @ 2024-11-12 10:00 UTC (permalink / raw)
  To: Jan Kiszka, isar-users



On 11/11/24 21:50, Jan Kiszka wrote:
> From: Jan Kiszka <jan.kiszka@siemens.com>
> 
> xxx
Some Documentation is missing
> 
> Signed-off-by: Jan Kiszka <jan.kiszka@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.kiszka@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.kiszka@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.kiszka@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
> +}

-- 
You received this message because you are subscribed to the Google Groups "isar-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/isar-users/c7cb6b22-0671-412b-886b-57a1b0de65e1%40siemens.com.

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

* Re: [PATCH 1/7] initramfs-hook: Add infrastructure to ease writing hooks
  2024-11-11 20:50 ` [PATCH 1/7] initramfs-hook: Add infrastructure to ease writing hooks 'Jan Kiszka' via isar-users
  2024-11-12 10:00   ` 'Quirin Gylstorff' via isar-users
@ 2024-11-12 10:14   ` 'Quirin Gylstorff' via isar-users
  2024-11-13  6:43     ` 'Jan Kiszka' via isar-users
  2024-11-13  7:47   ` [PATCH v2 " 'Jan Kiszka' via isar-users
  2 siblings, 1 reply; 12+ messages in thread
From: 'Quirin Gylstorff' via isar-users @ 2024-11-12 10:14 UTC (permalink / raw)
  To: Jan Kiszka, isar-users



On 11/11/24 21:50, Jan Kiszka wrote:
> From: Jan Kiszka <jan.kiszka@siemens.com>
> 
> xxx
> 
> Signed-off-by: Jan Kiszka <jan.kiszka@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.kiszka@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.kiszka@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.kiszka@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
This supports only on file per folder is this intentional?
Quirin
> +		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
> +}

-- 
You received this message because you are subscribed to the Google Groups "isar-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/isar-users/4c85c0de-2e3a-446e-8b2e-d5f058e11b9f%40siemens.com.

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

* Re: [PATCH 1/7] initramfs-hook: Add infrastructure to ease writing hooks
  2024-11-12 10:14   ` 'Quirin Gylstorff' via isar-users
@ 2024-11-13  6:43     ` 'Jan Kiszka' via isar-users
  0 siblings, 0 replies; 12+ messages in thread
From: 'Jan Kiszka' via isar-users @ 2024-11-13  6:43 UTC (permalink / raw)
  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.kiszka@siemens.com>
>>
>> xxx

Oops, forgotten to finish this.

>>
>> Signed-off-by: Jan Kiszka <jan.kiszka@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.kiszka@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.kiszka@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.kiszka@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
> This supports only on file per folder is this intentional?

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

-- 
You received this message because you are subscribed to the Google Groups "isar-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/isar-users/967fc582-9cf0-4216-8c82-f191907709e4%40siemens.com.

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

* [PATCH v2 1/7] initramfs-hook: Add infrastructure to ease writing hooks
  2024-11-11 20:50 ` [PATCH 1/7] initramfs-hook: Add infrastructure to ease writing hooks 'Jan Kiszka' via isar-users
  2024-11-12 10:00   ` 'Quirin Gylstorff' via isar-users
  2024-11-12 10:14   ` 'Quirin Gylstorff' via isar-users
@ 2024-11-13  7:47   ` 'Jan Kiszka' via isar-users
  2 siblings, 0 replies; 12+ messages in thread
From: 'Jan Kiszka' via isar-users @ 2024-11-13  7:47 UTC (permalink / raw)
  To: isar-users; +Cc: Quirin Gylstorff

From: Jan Kiszka <jan.kiszka@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.kiszka@siemens.com>
---

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

 .../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.kiszka@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.kiszka@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.kiszka@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

-- 
You received this message because you are subscribed to the Google Groups "isar-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/isar-users/d3614d1f-9646-4411-958f-54664a81a2ac%40siemens.com.

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

end of thread, other threads:[~2024-11-13  7:48 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-11 20:50 [PATCH 0/7] Simplify writing initramfs hooks 'Jan Kiszka' via isar-users
2024-11-11 20:50 ` [PATCH 1/7] initramfs-hook: Add infrastructure to ease writing hooks 'Jan Kiszka' via isar-users
2024-11-12 10:00   ` 'Quirin Gylstorff' via isar-users
2024-11-12 10:14   ` 'Quirin Gylstorff' via isar-users
2024-11-13  6:43     ` 'Jan Kiszka' via isar-users
2024-11-13  7:47   ` [PATCH v2 " 'Jan Kiszka' via isar-users
2024-11-11 20:50 ` [PATCH 2/7] doc: Describe initramfs customizations 'Jan Kiszka' via isar-users
2024-11-11 20:50 ` [PATCH 3/7] isar-initramfs: Add initramfs-fsck-hook-ext4 'Jan Kiszka' via isar-users
2024-11-11 20:50 ` [PATCH 4/7] initramfs-isar-example-hook: Convert recipe over to new hook.inc 'Jan Kiszka' via isar-users
2024-11-11 20:50 ` [PATCH 5/7] initramfs-fsck-ext4-hook: Convert to hook.inc and improve 'Jan Kiszka' via isar-users
2024-11-11 20:50 ` [PATCH 6/7] initramfs-tee-ftpm-hook: Convert to hook.inc 'Jan Kiszka' via isar-users
2024-11-11 20:50 ` [PATCH 7/7] initramfs-tee-supplicant-hook: " 'Jan Kiszka' via isar-users

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