From patchwork Sat Nov 16 10:55:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 3931 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 11:56:04 +0100 X-Sieve: CMU Sieve 2.4 Received: from mail-il1-f184.google.com (mail-il1-f184.google.com [209.85.166.184]) by shymkent.ilbers.de (8.15.2/8.15.2/Debian-8+deb9u1) with ESMTPS id 4AGAu2Aw013474 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 16 Nov 2024 11:56:03 +0100 Received: by mail-il1-f184.google.com with SMTP id e9e14a558f8ab-3a7191aa79csf18282705ab.1 for ; Sat, 16 Nov 2024 02:56:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1731754557; cv=pass; d=google.com; s=arc-20240605; b=XqU6jqkCRtCYLrcnqFCH9E3S3ekasiWeh/of+/2p+avY8zcoQc7Vh1hHGc/2oiqYHe QiltsO9BcblHQAhTHiMFLZMAIZ+v+k3fziCu6dhOkrZf8EOa+hAxzBP5Wz4fVdPe+6+u BDpqx3TvMnuAHtSM1UJuXOD3rLP4Fq9EYSPdA40Ap0OOO4fFBWu9Hfh+apT7lAlsqlvd aHIFkjOK4MMlDFTuLWyYHKPLA6VLvgch2wZ1j9yQ3kPALR8IhRHT8ZwkxxN0lhJighab +lUzEckuzqXwMp3s83AOttiZI/D60lidBJbCUSO66EeGD3r3GXbVfrzV+s5rxpgFLWlo iT7A== 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=xRPEKDQHRNxDOFRNG5gYCCigFl9cyaatDiRIQ4Sl1F0=; fh=crhuwspyVH4mwdroeaC1dRu+msmDf4rlkko7MOWTYGY=; b=aYP9QuNit60u/m5h3uMAItB07YQES3ZKqp0sIUG7dKjCRaoXni5HRr82xjx/p5o1GS 30TsZNrRbGVKXh8TuYe3uP0gJzEsf3VX4EpaJHqJ3j76Huyy9SAbwSKsm9UrbdEGPDA8 6CQqI2JjHzGc5R87++UtRYFWs1OMcZisYUXxJSJLngODdeymzsqM3Wx4aTpCBHg1nSZx 3PYVRxLjM02VbnP07tdO3jV/ifkz6SGYIh40s6pXQjSmJDNKuVpNXIg+aGTtAgp2GQTx gKLPPFWUdBi7H7jgne1dV3F4Y/SewDPyO/j/2v/k4MfriqOswhBDWD/vWUJ1paJetTGs Om0A==; darn=isar-build.org ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@siemens.com header.s=fm1 header.b=TJyoxYac; spf=pass (google.com: domain of fm-294854-20241116105553d2c4da3917f5cbbe3a-vxkfj4@rts-flowmailer.siemens.com designates 185.136.64.228 as permitted sender) smtp.mailfrom=fm-294854-20241116105553d2c4da3917f5cbbe3a-VXkfJ4@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=1731754557; x=1732359357; 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=xRPEKDQHRNxDOFRNG5gYCCigFl9cyaatDiRIQ4Sl1F0=; b=oUPs+Clg9w0AT0STqTVLMGk2laCUtvkNNNXVKJpi6ZlwOhjRP2nKbqoKw4nPQQAuU8 bhPfEpmGp4X0UwxLxsReaxmLVpNRATfK4Nx/k7Hb8WgGPtBUi5dDgqSHGauyf+cjtcws dC9xZZOfeHXE2kDZ6Vs3JcweqLiqJYYF3P6ta7x3YDE+TU5u9tnbmKNRcGNBvQx/slBs 7EZc0rUkLS+O+atkbktDvGtqC+hikCrsQy7gdmO/TdTk/5RF0FMeDk+boVsA+VhG6xsJ DptySz3vPDAtAVnUtvin5NMxeir6RoLFXpcTbuVSvOTfhHRxgs6TOw6i2nCiBM7AxQ74 J9rA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731754557; x=1732359357; 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=xRPEKDQHRNxDOFRNG5gYCCigFl9cyaatDiRIQ4Sl1F0=; b=OaYH4R+P0tbKx/nMR43fBcfEJKfIegZFYtmGCi8ru3ZOI395OgwGfJFVEcZ2WI+YEm f4sFOvOK10BFPLJBm+gU271/OphzJN7Dhr9vZe4FHAA4SY42EdmNplnjhRYv/PBoOTJn ucQat2c66U0o9ufA90gzfRAuN4vT59dnB7UANC0dVVYdLndE/lg38r8n/8U+sCGOG5Gu yM0iGw6INwjh3VUwnM237MoYPZQwRMZgtljrCLhL3tHkErFo/1bzRMntfffqKlCFY25G sQjlAmqIW/oajs12MK/gKV/5PyAyF3TzDnA2C36okSDr+ciexk3bPM9wJzUJqwXVVgqb Ix8w== X-Forwarded-Encrypted: i=2; AJvYcCWwpkgJv/ETe7GyXSeepB4TOVhNMAtXDtD4WO7en/RtHwHSpnmAlTQvC4nmod1xhscnllCnlrE=@isar-build.org X-Gm-Message-State: AOJu0Yzr81khDX7guy4L6MvAE5CpnqG4VXu8Q6Orn8zEKJBM4HHOrLr0 tjk6qX2V/OZTyR4tJjqLZIs/3gLwKlN0QhQv4Q05TwdmMdIu+6wE X-Google-Smtp-Source: AGHT+IHPtAhJeXqelpU/Xju80m85hjnJ8Rx6ryFiZBZmNhPa26MYeejygQhDbmHhmbGybsN9YSnRqg== X-Received: by 2002:a05:6e02:1a26:b0:3a7:172f:1299 with SMTP id e9e14a558f8ab-3a74802cb47mr66401465ab.12.1731754557212; Sat, 16 Nov 2024 02:55:57 -0800 (PST) X-BeenThere: isar-users@googlegroups.com Received: by 2002:a92:c5c5:0:b0:3a7:158d:67d9 with SMTP id e9e14a558f8ab-3a74803791dls7798645ab.1.-pod-prod-03-us; Sat, 16 Nov 2024 02:55:56 -0800 (PST) X-Received: by 2002:a05:6e02:1a8d:b0:3a6:b445:dc9c with SMTP id e9e14a558f8ab-3a747ff7fc7mr79269405ab.3.1731754555973; Sat, 16 Nov 2024 02:55:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1731754555; cv=none; d=google.com; s=arc-20240605; b=HLyLPycik8a/KZs0jml3+5t3KpRMTycM8Q60T4gcaKX8o8tDc2qKjlzHUFGcxM++ZO 3Oh3NZZ3X3tN3otUBDNgA7JPNNdAgCPbaqE+SpbTCrmMuZLpl01kV3GrxXtBlCmwd3/X AH+Zv2dnCQXOpw03gSOn+EZiFt842IbsWUKf7QA8yOCEO5ByvQMc+p7izGtMxlQStIzM I5m32+byHie/xPh/0ed4LajRjFE5/8RG9feGC0ffvUoP74LP9kIimA1MFulpAAo6FsPg L7ddEDoUhqDOsuBCjVTqKFJFfA2J7Fuc0SmjcG51V94mAIdBl1tTuYpb7+pvSg7+DBpg GswQ== 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=7EU6YckRabf024yXnVkL6BMsC9wvRooCqyNfekm8K58=; fh=TWGwN84gUgHIe5O4CbyH9KISyeWwGbvUX7cnJPxVD70=; b=QdclUkX4JxDbGw0eduMr94IEIkzfeNWStyGUlpXWD58voumpjRkQZWfQSL5itMqKBA fSefBjPC2NWotth+xSmzcGck3GulsFPrRP29qzwiUafnFsZLglIs4XNgwc+AR4tJ7qiH AbM/xGBKsg9jhPMai9SW2HljwuS+t4nXbA+VteGot2OhxBalf5e+G8+tfIbnrRG4OjRN d36QXfanaJ70oP84ehfmRLBrJIQG1rvf6nYS0n6w6kMy1Lo+poqDzh3kS+0bjlI9DaUp Kj6Qs8QrDb8Cmpg3FwotcsPdfqlX0A+XknAlLEghmcNzdlZwotIDa8tC3iDka9AbuMxy 2JUA==; dara=google.com ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@siemens.com header.s=fm1 header.b=TJyoxYac; spf=pass (google.com: domain of fm-294854-20241116105553d2c4da3917f5cbbe3a-vxkfj4@rts-flowmailer.siemens.com designates 185.136.64.228 as permitted sender) smtp.mailfrom=fm-294854-20241116105553d2c4da3917f5cbbe3a-VXkfJ4@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 e9e14a558f8ab-3a747fc3e04si1609295ab.0.2024.11.16.02.55.55 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 16 Nov 2024 02:55:55 -0800 (PST) Received-SPF: pass (google.com: domain of fm-294854-20241116105553d2c4da3917f5cbbe3a-vxkfj4@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 20241116105553d2c4da3917f5cbbe3a for ; Sat, 16 Nov 2024 11:55:54 +0100 X-Patchwork-Original-From: "'Jan Kiszka' via isar-users" From: Jan Kiszka To: isar-users Cc: Quirin Gylstorff Subject: [PATCH v3 1/7] initramfs-hook: Add infrastructure to ease writing hooks Date: Sat, 16 Nov 2024 11:55:46 +0100 Message-ID: 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=TJyoxYac; spf=pass (google.com: domain of fm-294854-20241116105553d2c4da3917f5cbbe3a-vxkfj4@rts-flowmailer.siemens.com designates 185.136.64.228 as permitted sender) smtp.mailfrom=fm-294854-20241116105553d2c4da3917f5cbbe3a-VXkfJ4@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 | 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 +# +# 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..5509c074 --- /dev/null +++ b/meta/recipes-initramfs/initramfs-hook/hook.inc @@ -0,0 +1,74 @@ +# +# 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" \ + "${D}/usr/share/initramfs-tools/scripts/$script/${INITRAMFS_HOOK_NAME}" + done +}