From patchwork Thu May 7 22:14:55 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 2288 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1778192139; bh=WSXH3BPTDAogkXJc3EYAGrDosudEfBk4hKwmW4Q/Hz8=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=qxZZJ8CZrzFm6NH4iEebVhRPxH9Hqh/pm05d3dHMiQfh8j/RGpC/oI10rjxs9RIn5 h/2DlVCgMfDoy0TB1hu9Aku68B/W+AVQuPEeeGKAIj76C9wX4+Uaw5CRfjXKrpNRpb nEeRzLwsfXFxdg6fAKz+4A7ykw6oy5rLb72ivn5g= Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id D258A6A9AA for ; Thu, 7 May 2026 16:15:39 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id th9gxwag7GWg for ; Thu, 7 May 2026 16:15:39 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1778192139; bh=WSXH3BPTDAogkXJc3EYAGrDosudEfBk4hKwmW4Q/Hz8=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=qxZZJ8CZrzFm6NH4iEebVhRPxH9Hqh/pm05d3dHMiQfh8j/RGpC/oI10rjxs9RIn5 h/2DlVCgMfDoy0TB1hu9Aku68B/W+AVQuPEeeGKAIj76C9wX4+Uaw5CRfjXKrpNRpb nEeRzLwsfXFxdg6fAKz+4A7ykw6oy5rLb72ivn5g= Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C213E6A9A8 for ; Thu, 7 May 2026 16:15:39 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1778192138; bh=OtX8L4ItI9FGZ8PocKh7NC/hcOBfWHWyvlsNAxNgDFc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YDWOb115fDt9mX9e0QsmIvPfZhlMiiJJBVaDyBILc1aQ3pFf0uDcudBGCBRKrjPGS nvoTLVZbuCNO+zj9ygfbI5W3xnyQa9IG0Qd42VJtY0dC2dXZd0v800+ByDZ7xVl5cS pU/D9jMyOcMfgSrfnSHbbxfBmF8FIbHJPu4JbcI0= Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 6F5936A9A5; Thu, 7 May 2026 16:15:38 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id cYITrKMNkPhD; Thu, 7 May 2026 16:15:38 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1778192131; bh=w3xt7TQ4pbn2I99LaQQXDQ8aUnfad1ExiCu70aIZpsI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RXB/Ia9sMcGcphX1CuoE67YSff++cbbeDdirkcg2ugWGbYAE5NDWUpgtCl8g78miD vUV+HIuIYusgvj41A+IkDuP2XuXc8DnzmyNBEG8ZJuTF5Dh9zgX9KvjU+wVvrSxBYT vd4w/d0Zs1o0QzzSZDK+m1N6QNR6yPaOF+WsyONo= Received: from u-boot.org (unknown [174.51.25.52]) by mail.u-boot.org (Postfix) with ESMTPSA id 72D4A6A9B5; Thu, 7 May 2026 16:15:31 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Thu, 7 May 2026 16:14:55 -0600 Message-ID: <20260507221507.505998-11-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260507221507.505998-1-sjg@u-boot.org> References: <20260507221507.505998-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 3OSXPPRNKCMO6VJJFEZVQVUPXW3L54T6 X-Message-ID-Hash: 3OSXPPRNKCMO6VJJFEZVQVUPXW3L54T6 X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Simon Glass X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 10/13] scripts: ubuntu: Lift BLS-setup magic strings List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass The first-boot helper script's name, its done-file path and the in-target u-boot.efi location each appear in three places: the two shell heredocs (FIRST_BOOT_SCRIPT, FIRST_BOOT_UNIT) and the shell template inside inject_first_boot_unit() and autoinstall_yaml(). Renaming any of them today means hunting through six call sites and getting them all to agree, which is exactly the kind of edit that silently desyncs. Hoist BLS_SETUP_NAME, BLS_SETUP_DONE and TARGET_UBOOT_EFI to module scope and switch the heredocs to f-strings (no '{' in the original shell, so no escaping needed). Output is byte-identical: the rewrite just makes future renames a one-line change. Signed-off-by: Simon Glass --- scripts/ubuntu-iso-to-uboot.py | 49 +++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/scripts/ubuntu-iso-to-uboot.py b/scripts/ubuntu-iso-to-uboot.py index d43308676e3..ba11aedc89c 100755 --- a/scripts/ubuntu-iso-to-uboot.py +++ b/scripts/ubuntu-iso-to-uboot.py @@ -83,12 +83,23 @@ REQUIRED_TOOLS = ( ) MIB = 1024 * 1024 +# Name shared by the first-boot helper script (under /usr/local/sbin) +# and its systemd unit (with .service appended); also used as the +# stem of the done-file under /var/lib that gates the unit. +BLS_SETUP_NAME = 'ubuntu-iso-to-uboot-bls-setup' +BLS_SETUP_DONE = f'/var/lib/{BLS_SETUP_NAME}.done' + +# Where u-boot.efi lands inside the install squashfs. The first-boot +# unit, the autoinstall late-commands and inject_first_boot_unit() +# all read or write this path, so keep them in sync via this constant. +TARGET_UBOOT_EFI = '/usr/lib/u-boot/u-boot.efi' + # First-boot systemd unit + helper script written into the install # squashfs so kernel-install manages BLS entries on the installed # system. ConditionPathExists=!/cdrom keeps the unit dormant inside # the live session, and the done-file stops it re-running on every # subsequent boot. -FIRST_BOOT_SCRIPT = '''\ +FIRST_BOOT_SCRIPT = f'''\ #!/bin/sh # Set up BLS entries and install U-Boot on the target ESP so the # installed system boots via U-Boot + BLS without the live ISO @@ -109,25 +120,25 @@ done # fallback; shimx64.efi is what the 'ubuntu' NVRAM entry Subiquity # registers points at, so overwriting both means the disk boots # U-Boot whichever path the firmware takes. -UBOOT=/usr/lib/u-boot/u-boot.efi +UBOOT={TARGET_UBOOT_EFI} install -D -m 644 "$UBOOT" /boot/efi/EFI/BOOT/BOOTX64.EFI if [ -f /boot/efi/EFI/ubuntu/shimx64.efi ]; then install -m 644 "$UBOOT" /boot/efi/EFI/ubuntu/shimx64.efi fi -touch /var/lib/ubuntu-iso-to-uboot-bls-setup.done +touch {BLS_SETUP_DONE} ''' -FIRST_BOOT_UNIT = '''\ +FIRST_BOOT_UNIT = f'''\ [Unit] Description=Set up BLS entries for future kernel updates -ConditionPathExists=!/var/lib/ubuntu-iso-to-uboot-bls-setup.done +ConditionPathExists=!{BLS_SETUP_DONE} ConditionPathExists=!/cdrom After=network-online.target Wants=network-online.target [Service] Type=oneshot -ExecStart=/usr/local/sbin/ubuntu-iso-to-uboot-bls-setup +ExecStart=/usr/local/sbin/{BLS_SETUP_NAME} RemainAfterExit=yes [Install] @@ -298,10 +309,10 @@ def inject_first_boot_unit( stage = work / 'sqfs-stage' aux = work / 'aux' aux.mkdir() - script_src = aux / 'ubuntu-iso-to-uboot-bls-setup' + script_src = aux / BLS_SETUP_NAME script_src.write_text(FIRST_BOOT_SCRIPT) script_src.chmod(0o755) - unit_src = aux / 'ubuntu-iso-to-uboot-bls-setup.service' + unit_src = aux / f'{BLS_SETUP_NAME}.service' unit_src.write_text(FIRST_BOOT_UNIT) tout.notice(f'=> Extracting {sqfs_in_iso}') @@ -311,20 +322,22 @@ def inject_first_boot_unit( ) tout.notice('=> Unpacking, injecting unit, repacking (xz, slow)') + unit_in_etc = f'/etc/systemd/system/{BLS_SETUP_NAME}.service' + wants_link = ( + f'/etc/systemd/system/multi-user.target.wants/{BLS_SETUP_NAME}.service' + ) shell = f''' set -e unsquashfs -d '{stage}' '{extracted}' install -D -m 755 -o root -g root '{script_src}' \\ - '{stage}/usr/local/sbin/ubuntu-iso-to-uboot-bls-setup' + '{stage}/usr/local/sbin/{BLS_SETUP_NAME}' install -D -m 644 -o root -g root '{unit_src}' \\ - '{stage}/etc/systemd/system/ubuntu-iso-to-uboot-bls-setup.service' + '{stage}{unit_in_etc}' install -D -m 644 -o root -g root '{uboot_efi}' \\ - '{stage}/usr/lib/u-boot/u-boot.efi' + '{stage}{TARGET_UBOOT_EFI}' mkdir -p '{stage}/etc/systemd/system/multi-user.target.wants' -ln -sf ../ubuntu-iso-to-uboot-bls-setup.service \\ - '{stage}/etc/systemd/system/multi-user.target.wants/ubuntu-iso-to-uboot-bls-setup.service' -chown -h root:root \\ - '{stage}/etc/systemd/system/multi-user.target.wants/ubuntu-iso-to-uboot-bls-setup.service' +ln -sf ../{BLS_SETUP_NAME}.service '{stage}{wants_link}' +chown -h root:root '{stage}{wants_link}' mksquashfs '{stage}' '{modified}' -noappend -comp xz -no-progress ''' _run('fakeroot', 'sh', '-c', shell) @@ -433,12 +446,12 @@ options root=UUID=%s ro console=ttyS0,115200 console=tty0\\n"\ # 'ubuntu' NVRAM entry points at, so the disk boots U-Boot # whichever path firmware takes - no need to keep the ISO # attached after the install reboot. - ''' - curtin in-target -- install -D -m 644\ - /usr/lib/u-boot/u-boot.efi /boot/efi/EFI/BOOT/BOOTX64.EFI + f''' - curtin in-target -- install -D -m 644\ + {TARGET_UBOOT_EFI} /boot/efi/EFI/BOOT/BOOTX64.EFI - | curtin in-target -- sh -c '[ -f\ /boot/efi/EFI/ubuntu/shimx64.efi ] && install -m 644\ - /usr/lib/u-boot/u-boot.efi\ + {TARGET_UBOOT_EFI}\ /boot/efi/EFI/ubuntu/shimx64.efi; true' ''' )