From patchwork Thu May 7 22:14:48 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 2281 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=1778192130; bh=xDf3ciNVK6IqhOZTWG7y03gDhHdaPzpr+rtkJc2wORA=; 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=HXR6aTvGinngKO+XQ9zc6wOrW7nnZ4f2tAzdVqpAiZO45u+r8NvdgSTVEvOSICo2H YyU2GMGsOFPurVKvOfiY8nHQznLjxsf4z1Iigpi//ARjPnBy9F90ptbGB+1J1nvvbb dUVlMeoT0u1s08uUMJAfC2yKbwF0ARWmUSFjSxAk= Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 176266A9A5 for ; Thu, 7 May 2026 16:15:30 -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 ckYKarmPICMr for ; Thu, 7 May 2026 16:15:30 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1778192130; bh=xDf3ciNVK6IqhOZTWG7y03gDhHdaPzpr+rtkJc2wORA=; 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=HXR6aTvGinngKO+XQ9zc6wOrW7nnZ4f2tAzdVqpAiZO45u+r8NvdgSTVEvOSICo2H YyU2GMGsOFPurVKvOfiY8nHQznLjxsf4z1Iigpi//ARjPnBy9F90ptbGB+1J1nvvbb dUVlMeoT0u1s08uUMJAfC2yKbwF0ARWmUSFjSxAk= Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 003DA6A9A8 for ; Thu, 7 May 2026 16:15:29 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1778192127; bh=jtp0rNGwbjQ7XRt7wfoMrvl/nnkavtWxlgikkEIRvi8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gHg+oTKamsLX0AIm/jlqI85pZuuPN9YjyNGjGfIZnJIGOfVNRBeVcow5S01/fE44h +HUOi7dQVa6qaRBAVuCUUMAT9TI6AfrACou28IzrIpyux5QN4TcdYOTTsS7g65ifYC Cqu9ERacTMXrMsYCXzW2EuZujUjEt4EZ6kmVMo9k= Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id BC6956A9A7; Thu, 7 May 2026 16:15:27 -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 L3YZeZgiKWwc; Thu, 7 May 2026 16:15:27 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1778192122; bh=Gy1/4BHl1Xy1A23sdNM3SffY3NXhEH5eH6Ia97K/1PI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=leyuWOJVJddCpwWg6EsX5V5aaqKsvhJQruIUlc8oWugm0aiufdoFlXUQcJDhDi30b mtj9zplPf/RGzQoKuhWTHh9J4dopPXVmY8uicvBkY6n1FwMsyjIDRf6X6lC2Qcrp23 yfIykfJ6G41Q2cJnWwDmbUVAuxboZ0jRjYvNwKm0= Received: from u-boot.org (unknown [174.51.25.52]) by mail.u-boot.org (Postfix) with ESMTPSA id 91A2D6A959; Thu, 7 May 2026 16:15:22 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Thu, 7 May 2026 16:14:48 -0600 Message-ID: <20260507221507.505998-4-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: 4PJIHPHCGD5XRPZ7IGODSCVS265HZP24 X-Message-ID-Hash: 4PJIHPHCGD5XRPZ7IGODSCVS265HZP24 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 03/13] scripts: ubuntu: Honour --kernel in grub-cfg parser 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 parse_grub_cmdline() hard-codes 'casper/vmlinuz' in its regex, so a user passing -k with a non-default kernel path silently falls through to the 'could not find a casper linux entry' error even when grub.cfg does carry a matching entry under the requested path. Take the kernel path as a parameter, re.escape() it before splicing into the pattern, and quote it in the failure message so the user sees what was searched for. Signed-off-by: Simon Glass --- scripts/ubuntu-iso-to-uboot.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/scripts/ubuntu-iso-to-uboot.py b/scripts/ubuntu-iso-to-uboot.py index f6326b7eceb..22c6928091b 100755 --- a/scripts/ubuntu-iso-to-uboot.py +++ b/scripts/ubuntu-iso-to-uboot.py @@ -104,10 +104,10 @@ def check_tools() -> None: ) -def parse_grub_cmdline(iso: Path) -> str: +def parse_grub_cmdline(iso: Path, kernel: str) -> str: """Return the kernel cmdline from the ISO's default grub entry. - Parses the first `linux /casper/vmlinuz ...` line in /boot/grub/grub.cfg + Parses the first `linux ...` line in /boot/grub/grub.cfg and strips the kernel path, so the caller can pass the remaining tokens to the kernel (e.g. '--- quiet splash' on Ubuntu 24.04.1). """ @@ -119,12 +119,17 @@ def parse_grub_cmdline(iso: Path) -> str: ) cfg = dst.read_text(errors='replace') + # The kernel path comes from the user (or its default), so escape it + # before splicing it into the regex. + kernel_re = re.escape(kernel.lstrip('/')) m = re.search( - r'^\s*linux\s+\S*casper/vmlinuz\S*\s*(.*)$', + rf'^\s*linux\s+\S*{kernel_re}\S*\s*(.*)$', cfg, re.MULTILINE, ) if not m: - tout.fatal('could not find a casper linux entry in /boot/grub/grub.cfg') + tout.fatal( + f'could not find a {kernel} linux entry in /boot/grub/grub.cfg' + ) # Collapse any run of whitespace to a single space return ' '.join(m.group(1).split()) @@ -249,7 +254,7 @@ def main() -> None: title = args.title or f'U-Boot BLS boot ({vol_id})' cmdline = args.cmdline if cmdline is None: - cmdline = parse_grub_cmdline(args.iso) + cmdline = parse_grub_cmdline(args.iso, args.kernel) tout.notice(f' Volume label: {vol_id}') tout.notice(f' ESP GUID: {esp_guid}') tout.notice(f' Cmdline: {cmdline}')