From: "'Jan Kiszka' via isar-users" <isar-users@googlegroups.com>
To: isar-users <isar-users@googlegroups.com>
Cc: Quirin Gylstorff <quirin.gylstorff@siemens.com>
Subject: Re: [PATCH v4 1/7] initramfs-hook: Add infrastructure to ease writing hooks
Date: Mon, 18 Nov 2024 15:35:09 +0100 [thread overview]
Message-ID: <2ce9a4f4-b899-48bf-b9fe-018dfdc6ff8c@siemens.com> (raw)
In-Reply-To: <1d32929bfb26982f9950737f689ea20f2056a45c.1731755581.git.jan.kiszka@siemens.com>
On 16.11.24 12:12, 'Jan Kiszka' via isar-users wrote:
> 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>
> ---
> .../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.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..b0e7c66c
> --- /dev/null
> +++ b/meta/recipes-initramfs/initramfs-hook/hook.inc
> @@ -0,0 +1,76 @@
> +#
> +# 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-header" \
> + "${D}/usr/share/initramfs-tools/scripts/$script/${INITRAMFS_HOOK_NAME}"
> + cat "${WORKDIR}/$script" >> \
> + "${D}/usr/share/initramfs-tools/scripts/$script/${INITRAMFS_HOOK_NAME}"
> + done
> +}
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
--
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/2ce9a4f4-b899-48bf-b9fe-018dfdc6ff8c%40siemens.com.
next prev parent reply other threads:[~2024-11-18 14:35 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-16 11:12 [PATCH v4 0/7] Simplify writing initramfs hooks 'Jan Kiszka' via isar-users
2024-11-16 11:12 ` [PATCH v4 1/7] initramfs-hook: Add infrastructure to ease writing hooks 'Jan Kiszka' via isar-users
2024-11-18 14:35 ` 'Jan Kiszka' via isar-users [this message]
2024-11-16 11:12 ` [PATCH v4 2/7] doc: Describe initramfs customizations 'Jan Kiszka' via isar-users
2024-11-16 11:12 ` [PATCH v4 3/7] isar-initramfs: Add initramfs-fsck-hook-ext4 'Jan Kiszka' via isar-users
2024-11-16 11:12 ` [PATCH v4 4/7] initramfs-isar-example-hook: Convert recipe over to new hook.inc 'Jan Kiszka' via isar-users
2024-11-16 11:12 ` [PATCH v4 5/7] initramfs-fsck-ext4-hook: Convert to hook.inc and improve 'Jan Kiszka' via isar-users
2024-11-16 11:13 ` [PATCH v4 6/7] initramfs-tee-ftpm-hook: Convert to hook.inc 'Jan Kiszka' via isar-users
2024-11-16 11:13 ` [PATCH v4 7/7] initramfs-tee-supplicant-hook: " 'Jan Kiszka' via isar-users
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2ce9a4f4-b899-48bf-b9fe-018dfdc6ff8c@siemens.com \
--to=isar-users@googlegroups.com \
--cc=jan.kiszka@siemens.com \
--cc=quirin.gylstorff@siemens.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox