From patchwork Sat Nov 16 11:12:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 3938 Return-Path: Received: from shymkent.ilbers.de ([unix socket]) by shymkent (Cyrus 2.5.10-Debian-2.5.10-3+deb9u2) with LMTPA; Sat, 16 Nov 2024 12:13:11 +0100 X-Sieve: CMU Sieve 2.4 Received: from mail-qk1-f191.google.com (mail-qk1-f191.google.com [209.85.222.191]) by shymkent.ilbers.de (8.15.2/8.15.2/Debian-8+deb9u1) with ESMTPS id 4AGBDAr0014072 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 16 Nov 2024 12:13:11 +0100 Received: by mail-qk1-f191.google.com with SMTP id af79cd13be357-7b16223e610sf99488485a.2 for ; Sat, 16 Nov 2024 03:13:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1731755585; cv=pass; d=google.com; s=arc-20240605; b=GcBMl01W+esr3dl3YEHeph2hSsYG+0vCsdc0k/5e/vc4EvS3tDbXIQCDfC/n7U9wIR gWD5PKhEeaFoTYJh8Uz0d4p7+IfAvz9k34S4xvIu2Yv33bRq3ocojxGb9yPn3rd+C48b HC9jrCrtCwq0QbKZ8vYxUemeo2+phuoLSrO4KodLpfkwka92CIW7j5Xq1Wvr18plqidr tXrly0rjsiZiYLVs5JEZWjM8rhjsHboST1C+09R7X8RmmiAUeXkLCHgjz1ziXhuH8lR0 PvsW93uY+C2RGbXf/6z6K2dA/GShTftURmMCzmM/mresQfrhv0YkJ7el3ReucthDX1zz FOiQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:reply-to:feedback-id:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=y0U9hCQCNFVGYGhcIq1mm9pEGYDV7udk/QLN/OGafW0=; fh=+o/HK8ibpGfMQTnKRgBnne1LsktmI0pWCxCFASSpnx8=; b=N3x3W52Dnn+iLhsFfrGlXG9Uwk7nRLRkzEn36rhR+s/Y1+7+bFzwObeFCJLxWarpPu L5drdZbIuIN1NdrJJs0boi10sEuAwYrYvtfnjaXCaahgI6atEc2Amm7Z0yWLwOoivqvO VgZyJlVTOQoES0qHgr+cX/8r3kx3Kud5KSPx1311u+cSrgJ79PcOc6ZPsPh8QWhNCSnw 7V/z6wuPQEw6LRV3WANJFTcfDGba3sg9T96kDGbYIMhhjz12Kqy1LGy1Zuc/es1uiV2s 1P6ZtPIcjYQdOlqg75zkACUAKg4UEcgmtl+3IIV8fUGzrbBOEP7Qf3ecpnQEPnHexUC1 a8TQ==; darn=isar-build.org ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@siemens.com header.s=fm1 header.b=Z1n01Myu; spf=pass (google.com: domain of fm-294854-202411161113021a6363467dd204d7fc-8i2jis@rts-flowmailer.siemens.com designates 185.136.64.227 as permitted sender) smtp.mailfrom=fm-294854-202411161113021a6363467dd204d7fc-8I2jIS@rts-flowmailer.siemens.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=siemens.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20230601; t=1731755585; x=1732360385; darn=isar-build.org; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:reply-to :x-original-authentication-results:x-original-sender:feedback-id :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=y0U9hCQCNFVGYGhcIq1mm9pEGYDV7udk/QLN/OGafW0=; b=esFdrK7loQQOMNDmTExsjGZLQW9EWEWapr91OMxTJwS79ZQYUxzIBUpqwvilao3FRt 8iPewXcymORCShnE7lYO90mD6hRPnf4jI1Vh1Cbnpn9a6+X8/8dAh56huG1dxYeHA5Cf 3a5rLPJOX3KOoi6CfMX9J7OPe3Cay419zGSOCECLzfprUvqAcTCI+JRg1Fub++s5wUsq hz6iSYwBhp5g5LFBg1vNeueAZ8nXNsPGHMBLHdtl4kCzEgtNSGCA8/cZb/1p3CoZe4w7 7zeou7ZakXEl6eEy8iStzcprL3Nuwb0Q0CvcaYewVqRm5SZpQsnW3856QuPtA4BAMxDp g7Sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731755585; x=1732360385; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence:reply-to :x-original-authentication-results:x-original-sender:feedback-id :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:x-beenthere:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=y0U9hCQCNFVGYGhcIq1mm9pEGYDV7udk/QLN/OGafW0=; b=uS8MEvwdbeOdXlbQM6yj9x2SQ98J4ewk7P+IjKkCQnPKbESzjYVj62dryz59NM+iis 7wd12J/o2qYBEt295CWITARmWVZJZrRloFfUWQnMvTc6uj+4ZvaDof9NuINnLnAejvGm OB6n5Q+ESpzMEGiw/njRx6fzYZyLG6C4j3m7FbsRYmqKMT73x3DZDlQjI67ML1cXBtWh RqKFymPVXV6uLz746Kd0BA2TT0674EZhieF2b4EFJXWJy7gu6ROg1J1PZnkOrmmkzTmQ o8j6GkTVC9qcGGtxaaIGOg55AR5NFCreAu/JJdi0YIDENsyCqCdilJlT1uQolmyr6Y0i cRTg== X-Forwarded-Encrypted: i=2; AJvYcCVf/Pjf+2nL4RLNzOzpq0q7k38+W0Fjp4GeoRqvqgjr63dO1YFiCAq4Gvd/gJNFtilNzJ40OtM=@isar-build.org X-Gm-Message-State: AOJu0YxAzT9b9lR1GWUkaHsDFKQWy20dHw8skM/5Lw8KCA4d36WeX0v3 PzXoTNs40ONj8A6WQjmbLfOJbFN1ru3CDUjav/YimRUcImPXgaq6 X-Google-Smtp-Source: AGHT+IGdd9N76Mh2reXp2oIY8NtJEO+Q3Ppn1UbllPsVmKVArE0zF6zSw/a7SaaK/Kjl+Egph0wKRQ== X-Received: by 2002:a05:620a:170b:b0:7b1:11f4:d0af with SMTP id af79cd13be357-7b3622e3aeemr707795085a.29.1731755584718; Sat, 16 Nov 2024 03:13:04 -0800 (PST) X-BeenThere: isar-users@googlegroups.com Received: by 2002:ac8:5fc5:0:b0:463:17df:8a80 with SMTP id d75a77b69052e-46370578e98ls7050671cf.1.-pod-prod-04-us; Sat, 16 Nov 2024 03:13:04 -0800 (PST) X-Received: by 2002:a05:622a:4d4b:b0:460:9d81:4bc8 with SMTP id d75a77b69052e-46363e941c6mr80307971cf.42.1731755583969; Sat, 16 Nov 2024 03:13:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1731755583; cv=none; d=google.com; s=arc-20240605; b=UkFDBGptqZZKQ66t2WnNQwo3LvcBGyxgRHmgIE7qsulr3RzbqJTrjTi3nNOiuJfqhP VqYybGMY63iFjASP7yoZMGkYuBFhyqo2yB1DxFuhzPDcUT9BA9xRSZc140M42hkFAJrN nmnzW9L5vdLizoa9OSgM7xIhlMDK87Qv0clVAeWFbeLI3i5nlzMLuB7mGBCwkyZ8WD/e AEVXQFzc1pjkaaFdb3ZDHqfSRzCZf13nHu0vRmaRolNO8cs9kNxEnzea8llctH9gIE3A sH7jk1Rj0AraNWUiHAQaj6AF56WwuNww5SAItEaeOzRhY7RchYvBZGrxkAX+hlloe1/c Qlxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=feedback-id:content-transfer-encoding:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=7dZBuOrqumNDmXfNrDIicYZmwXKWUxS8UsY+0CFsDiw=; fh=TWGwN84gUgHIe5O4CbyH9KISyeWwGbvUX7cnJPxVD70=; b=Wu/NFGJQ5OEo9TJ6P9Vh9JgpJwwzxIebbcA2mjgXbjxMU4xUYo6Q7yhxHVjJHkhueL H4qvnYyRXv5TEFR1Hnd7RTeJb+9j0OMYWcB9CCww+oxNsNE8mU+tE5N2CAtpY2iImlPf BAnOg3OapOE5uICpH7VRzG76pEj+v+vjsD60N19A2l9PO6UXYXQwUpc3jqD03RcAoRg7 GtwVZJvls/5r54Nhg+cnWMeV++IjvMFXOouERP5Nbt8t0+MLIbqxvMlp3pp2ny5xFvoE xXwIsPWZVzad5VEphP6hMuSlNCpdEY0R9aIl89ZpTg/naAIh5ZAquVZIDL6OIJ8fhC6N QY6w==; dara=google.com ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@siemens.com header.s=fm1 header.b=Z1n01Myu; spf=pass (google.com: domain of fm-294854-202411161113021a6363467dd204d7fc-8i2jis@rts-flowmailer.siemens.com designates 185.136.64.227 as permitted sender) smtp.mailfrom=fm-294854-202411161113021a6363467dd204d7fc-8I2jIS@rts-flowmailer.siemens.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=siemens.com Received: from mta-64-227.siemens.flowmailer.net (mta-64-227.siemens.flowmailer.net. [185.136.64.227]) by gmr-mx.google.com with ESMTPS id d75a77b69052e-4635a9c1a0fsi2608411cf.1.2024.11.16.03.13.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 16 Nov 2024 03:13:03 -0800 (PST) Received-SPF: pass (google.com: domain of fm-294854-202411161113021a6363467dd204d7fc-8i2jis@rts-flowmailer.siemens.com designates 185.136.64.227 as permitted sender) client-ip=185.136.64.227; Received: by mta-64-227.siemens.flowmailer.net with ESMTPSA id 202411161113021a6363467dd204d7fc for ; Sat, 16 Nov 2024 12:13:02 +0100 X-Patchwork-Original-From: "'Jan Kiszka' via isar-users" From: Jan Kiszka To: isar-users Cc: Quirin Gylstorff Subject: [PATCH v4 1/7] initramfs-hook: Add infrastructure to ease writing hooks Date: Sat, 16 Nov 2024 12:12:55 +0100 Message-ID: <1d32929bfb26982f9950737f689ea20f2056a45c.1731755581.git.jan.kiszka@siemens.com> In-Reply-To: References: MIME-Version: 1.0 X-Flowmailer-Platform: Siemens Feedback-ID: 519:519-294854:519-21489:flowmailer X-Original-Sender: jan.kiszka@siemens.com X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@siemens.com header.s=fm1 header.b=Z1n01Myu; spf=pass (google.com: domain of fm-294854-202411161113021a6363467dd204d7fc-8i2jis@rts-flowmailer.siemens.com designates 185.136.64.227 as permitted sender) smtp.mailfrom=fm-294854-202411161113021a6363467dd204d7fc-8I2jIS@rts-flowmailer.siemens.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=siemens.com X-Original-From: Jan Kiszka Reply-To: Jan Kiszka Precedence: list Mailing-list: list isar-users@googlegroups.com; contact isar-users+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: isar-users@googlegroups.com X-Google-Group-Id: 914930254986 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , X-Spam-Status: No, score=-4.9 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,RCVD_IN_RP_CERTIFIED, RCVD_IN_RP_RNBL,RCVD_IN_RP_SAFE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on shymkent.ilbers.de X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= From: Jan Kiszka 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 --- .../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 +# +# 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 +# +# 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 +# +# 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 +}