From patchwork Wed Nov 20 17:02: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: 3952 Return-Path: Received: from shymkent.ilbers.de ([unix socket]) by shymkent (Cyrus 2.5.10-Debian-2.5.10-3+deb9u2) with LMTPA; Wed, 20 Nov 2024 18:03:14 +0100 X-Sieve: CMU Sieve 2.4 Received: from mail-qv1-f62.google.com (mail-qv1-f62.google.com [209.85.219.62]) by shymkent.ilbers.de (8.15.2/8.15.2/Debian-8+deb9u1) with ESMTPS id 4AKH3CgY006919 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 20 Nov 2024 18:03:13 +0100 Received: by mail-qv1-f62.google.com with SMTP id 6a1803df08f44-6d40783aa19sf285276d6.0 for ; Wed, 20 Nov 2024 09:03:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1732122185; cv=pass; d=google.com; s=arc-20240605; b=TvKUFDOWxO3SA8Pc0bpJdn0yNQToX3S3hGCkXoBwzSWQbzvEhPSD9duaFzFc2yRj3a JqbU8VLUzleIyC8tADBiRaWqcU+kSrBT5++N7FkWcS/6OMGm+PIr6EP3SyNKA1U+C9oU QjFxRI5t1NKx0llUPE3Sop6edhE82ji2gfvESlQW8TTZNfjc+W7M61DBRfdchivdx0az EfbBGDJWPMOIc99ufRt+QVpqNKjQTEa7b4TUOlgFYFDVYTFy3he4nzRrsIilcha2EuZX 79EjZzcUsUXIQD3ZtH2IXJ/Yfv1/zri0Ebq9WPOYE+uWAcOoEQ0mMO+W9BOrhZMDi/AC ifUQ== 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=Iv79RXHq4xj9IYc7kX+CrGI/BIf3Hth6zlPC4PRu5Kw=; fh=qcSeF/WFJEOdcaQn/cVg4MpRGRBQCDdFPj015UE4Itg=; b=XXg1boJePJ/UVFK3YCdl+gyb6XxWtD7Bt8wZ2RvmKs815ymyIwejRL/iJbkBZnpA1c LVhvkFEt4/zGoNrjQwLgWE5iOoVhO/cprYTnp0kat00Zz9uN2xdrxegA6pO2okrPqckY Bttivciy7UadOjttnOd/rFPOc4mOQOjSn3BUaxy9m46kfpDghjK4x88Da8uShzn2RaZL UUI6kPTv/EK/dZW8nZOZfuEB5lDtZltQd/9KVOVuIYm4b3huHowTbXZThirFyr8DGJ1/ UHe65hdNLOq7JTDxmsm2UfgepuyRbzuN6Skax44Rqd4lREAdjgVoYK/FSeKdqdjFgDmR 2BMg==; darn=isar-build.org ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@siemens.com header.s=fm2 header.b=W5fNZW8Z; spf=pass (google.com: domain of fm-294854-202411201703025ffeba3e1c5bf5765a-dzvbjd@rts-flowmailer.siemens.com designates 185.136.64.228 as permitted sender) smtp.mailfrom=fm-294854-202411201703025ffeba3e1c5bf5765a-dZVbJD@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=1732122185; x=1732726985; 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=Iv79RXHq4xj9IYc7kX+CrGI/BIf3Hth6zlPC4PRu5Kw=; b=glhYWgGnwW6cWdYJUw5LF1hwFR/9+F8zXdqja9/yBtb0fp3EfiolY0w+vOpxI8xvJs 7mu0jesFyyVkV8Gw+tArjTh5JW0bEMiyI7Qn+vzT8HTzNp5W2edv1LWZiZdEzZ9u7gmF LwYZLK11iblIva9jcvnvxMekHh1/myCzCPTdsH+2ohkU2mZyzXehH2l/oSTwYxFddxZZ FpZy50w7shL9PPfz2KN9bzUB9HGatvO0stIEK0l8Z92WAEHhpCl42eKQWdtp9yAzcFFs bQDb/lYBMWw76NlRcHW/ZlKd+3FXfJ2wUf8erEja1FLSD5A9iXb9yIjh/2vj2h2tmkGz r+dQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732122185; x=1732726985; 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=Iv79RXHq4xj9IYc7kX+CrGI/BIf3Hth6zlPC4PRu5Kw=; b=WWwmc17SquVTN4NGcrhaCuKvccJ/IAtTjfvxTfyC9c9QKGvWAJGtlLkt2EFueYHc0t ZuVJAHF0NyXA4uz305tafdHFSYHZ1OHa1eZp26iCEYpyhzKAevmheXFc9zKUR8jHhTHV 1sJ1zXpLxVlc6W+5Zc6Ol9ur2CFf43+XRlql2X8HGfTiAVhQT7YMNi1psgDoMwPi7pz6 QfvA+iKdxv8BogyqlRGy0Gqo5ha5b6B1Smn8fv1QPTDU899B7bR02ufm4ppdngBsoTHJ qTOJ9KZrnip2t1v9PSLrZFJqHaymwcx3+SkEJdUYxE7wX1Wj/4AXbMr5PZfHK4o/O6XR GrAg== X-Forwarded-Encrypted: i=2; AJvYcCU3yDf3E1h/NbFUWFRSZmNr4XgZA8gdaneM7NE81LpAXQMjBzfj6uh3FRlKEwTO7snU4HkPPO4=@isar-build.org X-Gm-Message-State: AOJu0YwSp5vtalMG+22mDnvC90yh9GGJq+MA7kZM/2K9irRCCcuBx63Y 8wQBOr1Rq5XqqiVtrsB9aedZFw3rX5ub7OSupyyhR7MsHU3rvopY X-Google-Smtp-Source: AGHT+IHlznZWRFp6fqpscGqO7dA68TIKq45vH+fKWhS8148zsIc+GT5SJVs2Pd61WKsu95ebBBej1w== X-Received: by 2002:a05:6214:dcc:b0:6ce:34d5:8882 with SMTP id 6a1803df08f44-6d437859d96mr53732396d6.39.1732122185221; Wed, 20 Nov 2024 09:03:05 -0800 (PST) X-BeenThere: isar-users@googlegroups.com Received: by 2002:a05:6214:f08:b0:6c5:127c:2ebc with SMTP id 6a1803df08f44-6d44241d5d6ls555376d6.2.-pod-prod-05-us; Wed, 20 Nov 2024 09:03:04 -0800 (PST) X-Received: by 2002:a05:6122:1ac5:b0:50d:2769:d741 with SMTP id 71dfb90a1353d-514cfb6e816mr3719216e0c.11.1732122183947; Wed, 20 Nov 2024 09:03:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1732122183; cv=none; d=google.com; s=arc-20240605; b=NT4C3e8/pDTG6cWdTf1TZKDEE9MJ5h6bs6qSwAd27TZ5jL4vAse07zXlb03tdN67tv y4YJIyvgvBJU30nuIMZhoc9kMJ9bHV04iaCw30csXdv1hK3cTAaf5nwUe09mHbNTWjy8 /P2RR3L5GU0JjPlFrhYzqr8TvUDd+7eRnH1XgOEbrmdZXs0IbsvI5n3VKvdfLTh0gF5A q5Ayjdt9qhl8q1BiLC/KHLyTxYflAqpDColxwUwJL3JkIbsSGhYWkunXczXqpvQ+Zekq QssDXBVluDDpjbmPSg9homAQ01nq8OpGCzICAtRCaE6w/Qde+/3cz+5fdqnSqwIp6hpb hp8w== 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=Xl38PQkK7qK1k/zNjnAIrhV98xAbhYcrTbelfD58lHg=; fh=TWGwN84gUgHIe5O4CbyH9KISyeWwGbvUX7cnJPxVD70=; b=JZq7EwuWNH6dHdRP8uroqi+s8sHx3A2Ejw/u8VIyosT+W8OogHm9wXiJmnyJTNrYwz DVm28O9S5yQDqLSOMvq7I6jWnLz+Df/1ku2ti5hkJrUpuHB3a8RdGMCr8RoXgf5lveg5 8qizpnKIM3bcfnjy0wfER9yWSDxv0uvJ/opIT9Cw9dvlQZ5wjY+SPc+CvIAYBNrujKrC ttvSB7W16tvVC96+JB+b7XHnrxVCiI5sW0MVEFfGZijUIK4fevFw3Orbpn3OtHUMWexC csvqf6B0zAk+CRKC5e5lmTa1kx+zfkpmpCmDAquI1dih8qkbc2gTTxmA/KHzZ0bgIyVH PLPA==; dara=google.com ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@siemens.com header.s=fm2 header.b=W5fNZW8Z; spf=pass (google.com: domain of fm-294854-202411201703025ffeba3e1c5bf5765a-dzvbjd@rts-flowmailer.siemens.com designates 185.136.64.228 as permitted sender) smtp.mailfrom=fm-294854-202411201703025ffeba3e1c5bf5765a-dZVbJD@rts-flowmailer.siemens.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=siemens.com Received: from mta-64-228.siemens.flowmailer.net (mta-64-228.siemens.flowmailer.net. [185.136.64.228]) by gmr-mx.google.com with ESMTPS id 71dfb90a1353d-51479dd7b1asi913678e0c.5.2024.11.20.09.03.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Nov 2024 09:03:03 -0800 (PST) Received-SPF: pass (google.com: domain of fm-294854-202411201703025ffeba3e1c5bf5765a-dzvbjd@rts-flowmailer.siemens.com designates 185.136.64.228 as permitted sender) client-ip=185.136.64.228; Received: by mta-64-228.siemens.flowmailer.net with ESMTPSA id 202411201703025ffeba3e1c5bf5765a for ; Wed, 20 Nov 2024 18:03:02 +0100 X-Patchwork-Original-From: "'Jan Kiszka' via isar-users" From: Jan Kiszka To: isar-users Cc: Quirin Gylstorff Subject: [PATCH v5 1/7] initramfs-hook: Add infrastructure to ease writing hooks Date: Wed, 20 Nov 2024 18:02:55 +0100 Message-ID: <22c10d97f224599c405086346cbadea5c8797919.1732122181.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=fm2 header.b=W5fNZW8Z; spf=pass (google.com: domain of fm-294854-202411201703025ffeba3e1c5bf5765a-dzvbjd@rts-flowmailer.siemens.com designates 185.136.64.228 as permitted sender) smtp.mailfrom=fm-294854-202411201703025ffeba3e1c5bf5765a-dZVbJD@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 or defining own ones completely. 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 | 81 +++++++++++++++++++ 3 files changed, 146 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..c80b781d --- /dev/null +++ b/meta/recipes-initramfs/initramfs-hook/hook.inc @@ -0,0 +1,81 @@ +# +# 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" ] && [ ! -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 + done +}