From nobody Sun May 24 22:00:01 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) client-ip=78.46.105.101; envelope-from=seabios-bounces@seabios.org; helo=coreboot.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) smtp.mailfrom=seabios-bounces@seabios.org; arc=fail (BodyHash is different from the expected one); dmarc=pass(p=reject dis=none) header.from=seabios.org Return-Path: Received: from coreboot.org (mail.coreboot.org [78.46.105.101]) by mx.zohomail.com with SMTPS id 1778271807768458.4895979784677; Fri, 8 May 2026 13:23:27 -0700 (PDT) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id 56FE754EBEF; Fri, 8 May 2026 20:23:25 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) [209.85.160.181]) by coreboot.org (Postfix) with ESMTP id 9804C81732 for ; Tue, 13 Jan 2026 20:00:56 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) d75a77b69052e-4ee243b98caso95051cf.1 for ; Tue, 13 Jan 2026 12:00:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seabios.org; s=dkim; t=1778271805; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:list-id:list-owner:list-unsubscribe:list-subscribe:list-post; bh=5aCBBJuVA/pS/NUWzevWckLigzexSHF3+GFytl3YH/Y=; b=p9A1cZs1E7wlHlXQavWQriqhChsJ3/zqHGM3cDTwFRg6TUbzCIPA097ShpvOW8GMW5HLAQ C80Inb85W9fX65yr9sAESI29n55HMH3YG0Jov56hM3Cf5NP6Y42RVUoPA0BUlrLvfmvCSd 1OCc2gzHLBWdG4jmT3t0ukDRQb5VU0I= ARC-Seal: i=1; a=rsa-sha256; t=1768334455; cv=none; d=google.com; s=arc-20240605; b=AJ5evLy5HogQkxU3JSSauvcSxzhtvIUYdqd3Spt7nMG9v5/pyG4sri1bXLOs6PmsVg jVVk93hiWIarLu33g90stQnX0ojeScDJg5BVM0Brha0MqGl54Xqlb/VJPmw16RFkz8fc 65vEDHqo3yEptM5lLbn7PMMcJ+wvSZcPLbjTNkF5tTbj4sE3XPlSt4aFlvb+uPOav1cS Q/d2jIzySr0e9SGSjHJgItC8y8D3xQ5cvQbK+n/gTDe5ez2uCTK+yjmQBI1FgIIczMt+ sS6XeLSmIm9nWFHmJLHM2Ya0CcXVketAajcZOBPbQc5JJ2VixfXy56F5W8c/r0shyxOV m9ZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=to:subject:message-id:date:from:mime-version:dkim-signature; bh=/Iht34Zu+48W9hzGc/8On4gNTzWfja8WvIOf/3FCPf8=; fh=Ojiz1Ls82Hh2+087o5dkFgqBcCQ1ySy8hFuOrpUxsHk=; b=RBU6zQd7GB+sjXyY6MVuxcdAtMv4W4/0KGvah4s6SKxAUYo+1UbPkj+ZinnVVG4wyx nknkgcfNByTslwT8zsbLMaWU0kATzI18dl98ewQx4ykmbeLtOeHl3WpXLZgGK523BZRO F8BwrhjgYKXJ8KeGaBHqM5VXYnDHlgdld0YbA3YQAFpw4vJ9T295OwDmhFaI9MjpAxG0 n3EIkbj1D2c0UUHm0clIwJAnrW1M4KBhpPCZyvsHNHp+xnNdix2S5V+8/4bEyPhcVnMZ NkDVgTLZvDMJ5JW36BwrJqdXBKoniq+oq5XUcnE88PnuLKQxvJ9jB0EKo40p6pjRwPDc KiNw==; darn=seabios.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1768334455; x=1768939255; darn=seabios.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=/Iht34Zu+48W9hzGc/8On4gNTzWfja8WvIOf/3FCPf8=; b=u6VaeKuvEUETrWhUoWPJhDA5NzW0lADW+fkX7S7+ZqgHTl9fcSHQUJR5/XRzDvuGXk NL5hdkJRS1TwxC6hnTdOWFP5fIAImn5kqVsVcD55u3d8+ptdWjOobE6wrndJxuSfZ9nQ isVvkTLnZKRxUmzIiGo0dR7TEqxp0mG20LEK210Uo3cAv9r/37F18xguN28bpgt4SwMn 9mbtPc3DimoPMWRy47uro1mM/WApcZPJrCu0Qxi9NIwOHsk5wHywg6oEE3jeV7Bi1DfJ uBOuCBMvrImFK1LPHKFUixUxQqmgGbQkBLpMx9uYJ2DzDpMyEUI1Z4SNJkW9oNarf7pH gCbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768334455; x=1768939255; h=to:subject:message-id:date:from:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/Iht34Zu+48W9hzGc/8On4gNTzWfja8WvIOf/3FCPf8=; b=d/794+Y+mQScd51JtmfuLGgx5GYy+EhuAtTAU0cljZXPKAwHy0Db1/+jvKZz5dbxGx nB1gn5ojxLYklgHlCb6zfulCOcnogOtGzy5HD/oJ3xL4wjq/LGSTEf8RE2wVWa25XYgO 0TETP/H94ViFvswQdKyi4y6PhwN65Hio78bUg4QCF9Fsv2F5bK4f5UgkXBAs4DKYohWH me5mFxpIdWBh/PWZgFt3EpLY8GIPOhPRy5DEeCJ2SvoXItRSJS79mhVtlcUSRjhUJmEd 3hjvOS7Gh+pQ/QCpPn9iR8ujHYq36c9xjJjEsN4zbU3dHktLZlUW8GpywmquSVizjS15 S0bw== X-Gm-Message-State: AOJu0YwZtxJOdHWXYkYCDXR01u4J4munV7KaSDGBGF+vCIGKJipirMyg zB+G7N6XZJn0H+s/B4q2+BBkt4wZ2i0KoOGGuBndtgUx3pUG6jT1qJktLg+Vt9Ga4zcNLlJCDK2 0KcR3lAYxXxEJsYfuAi1yncSR0UtcS6Tvvco4S+StdKqHXSEnK3zHP12I5+U= X-Gm-Gg: AY/fxX64qNN1rApJz4GoFC25Oc9sPq0P3Dr73YWBXvt5H3KNIAtyIaf26llner/iVnE Wu1jqQQPLyhnj9TGR26OTJ8P3zVDh7KnAiYdRrn1hsZyQEy4GW3756dR6A6M4KhU0LSXvxa1mKQ HaE12B52l4BrHRFIz09+6fNUHjpOw+g9G/p2nuDgUPUWDiralTG7neLndh8EIWOPIFMYJBXrhNJ yZv9ZoKbMQS1Zl6W5TwxObgk9tqbUZNi1QwOpkWnQ0TtnX1uuMFvQ6kz2nWgLyr7G46jv4KSU6P awW3Bvp3qhcWpA+ME5MOCrZPCw== X-Received: by 2002:a05:622a:1187:b0:4ff:cb25:998b with SMTP id d75a77b69052e-5014821f599mr1591441cf.12.1768334454337; Tue, 13 Jan 2026 12:00:54 -0800 (PST) MIME-Version: 1.0 Date: Tue, 13 Jan 2026 12:00:43 -0800 X-Gm-Features: AZwV_QhGgNJuWiA4-_QnTIHo3A1et30Yu-SQjhVqmwWMMfEziNnPP04Y4_qHvhU Message-ID: To: seabios@seabios.org X-MailFrom: glenng@google.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-seabios.seabios.org-0; header-match-seabios.seabios.org-1; emergency; member-moderation Message-ID-Hash: RNMXVW2NY6J5KHCRUXZ245REZPDBCB5S X-Message-ID-Hash: RNMXVW2NY6J5KHCRUXZ245REZPDBCB5S X-Mailman-Approved-At: Fri, 08 May 2026 20:22:49 +0000 X-Mailman-Version: 3.3.11b1 Precedence: list Subject: [SeaBIOS] [PATCH] Implement semantic OFW path matching and unit address parsing List-Id: SeaBIOS mailing list Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Glenn Griffin via SeaBIOS Reply-To: Glenn Griffin Content-Transfer-Encoding: quoted-printable X-Spamd-Bar: ++ X-Spam-Level: ** Authentication-Results: coreboot.org; auth=pass smtp.auth=mailman@coreboot.org smtp.mailfrom=seabios-bounces@seabios.org X-ZohoMail-DKIM: pass (identity @seabios.org) X-ZM-MESSAGEID: 1778271808633158500 Content-Type: text/plain; charset="utf-8" Introduce a robust semantic matcher for Open Firmware (OFW) device paths to replace the previous prefix-based string matching logic. This change enables SeaBIOS to accurately correlate bootorder entries with concrete hardware devices by understanding the topological structure and addressing scheme of IEEE 1275-compliant paths. Key changes: - Implement parse_hex to handle standard and relaxed unit addresses (e.g., treating "@1,0" and "@1" as equivalent for function 0). - Implement fw_path_match to perform node-by-node comparisons, supporting wildcards ('*') for both node names and unit addresses. - Incorporate a generic name fallback mechanism where nodes match based sol= ely on unit addresses if names differ, essential for Broadcom/standard PCI addressing compatibility. - Update find_prio and boot_lchs_find to utilize the new semantic matcher, ensuring consistent behavior across boot priority and disk geometry selec= tion. These improvements ensure that boot ordering remains predictable and flexib= le even when host-side tools use generic labels or when controller driver names vary within the guest. Signed-off-by: Glenn Griffin --- src/boot.c | 142 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 126 insertions(+), 16 deletions(-) diff --git a/src/boot.c b/src/boot.c index 5c37dafd..d60950c1 100644 --- a/src/boot.c +++ b/src/boot.c @@ -29,24 +29,134 @@ // See if 'str' starts with 'glob' - if glob contains an '*' character // it will match any number of characters in str that aren't a '/' or // the next glob character. -static char * -glob_prefix(const char *glob, const char *str) +// Parse a hex number from a string. +static int +parse_hex(const char **ptr) { - for (;;) { - if (!*glob && (!*str || *str =3D=3D '/')) - return (char*)str; - if (*glob =3D=3D '*') { - if (!*str || *str =3D=3D '/' || *str =3D=3D glob[1]) - glob++; - else - str++; + const char *p =3D *ptr; + int val =3D 0; + while (1) { + char c =3D *p; + if (c >=3D '0' && c <=3D '9') + val =3D (val << 4) | (c - '0'); + else if (c >=3D 'a' && c <=3D 'f') + val =3D (val << 4) | (c - 'a' + 10); + else if (c >=3D 'A' && c <=3D 'F') + val =3D (val << 4) | (c - 'A' + 10); + else + break; + p++; + } + *ptr =3D p; + return val; +} + +// Perform semantic matching of an Open Firmware path glob against a concrete path. +// Supports: +// - '*' wildcard for node names (e.g., /pci@* matches /pci@i0cf8) +// - Generic fallback: if addresses match, node name is ignored (e.g. /disk@3,0 matches /nvme@3) +// - Relaxed unit address matching (e.g., @3,0 matches @3) +static int +fw_path_match(const char *glob, const char *path) +{ + while (*glob && *path) { + // match separators + if (*glob =3D=3D '/') { + if (*path !=3D '/') + return 0; + glob++; + path++; continue; } - if (*glob !=3D *str) - return NULL; - glob++; - str++; + + // parse node name + const char *glob_end =3D strchr(glob, '@'); + const char *path_end =3D strchr(path, '@'); + // Handle cases where @ is missing (malformed or root?) or next char is / + const char *glob_slash =3D strchr(glob, '/'); + const char *path_slash =3D strchr(path, '/'); + + if (!glob_end || (glob_slash && glob_slash < glob_end)) + glob_end =3D glob_slash ? glob_slash : glob + strlen(glob); + if (!path_end || (path_slash && path_slash < path_end)) + path_end =3D path_slash ? path_slash : path + strlen(path); + + int glob_len =3D glob_end - glob; + int path_len =3D path_end - path; + + // Check Name Match + int name_match =3D 0; + if (glob[0] =3D=3D '*') + name_match =3D 1; // Wildcard matches anything + else if (glob_len =3D=3D path_len && memcmp(glob, path, glob_len) = =3D=3D 0) + name_match =3D 1; // Exact match + + glob =3D glob_end; + path =3D path_end; + + // Check Address Match + int glob_has_addr =3D (*glob =3D=3D '@'); + int path_has_addr =3D (*path =3D=3D '@'); + + if (glob_has_addr !=3D path_has_addr) + return 0; // Structure mismatch + + if (glob_has_addr) { + glob++; + path++; + + // Check for wildcard in address + if (glob[0] =3D=3D '*') { + // Wildcard address matches any path address + // But we still require structure match (both had @) + // We advance pointers past address + // Consume glob address until / or end + while (*glob && *glob !=3D '/') glob++; + // Consume path address until / or end + while (*path && *path !=3D '/') path++; + + // If name matched (or was *) AND address is *, then match. + if (!name_match) return 0; + continue; + } + + // Parse Address + // Format: N[,M] + int glob_val1 =3D parse_hex(&glob); + int path_val1 =3D parse_hex(&path); + + if (glob_val1 !=3D path_val1) + return 0; + + int glob_val2 =3D 0; + int path_val2 =3D 0; + + if (*glob =3D=3D ',') { + glob++; + glob_val2 =3D parse_hex(&glob); + } + if (*path =3D=3D ',') { + path++; + path_val2 =3D parse_hex(&path); + } + + // Semantic Address Match: Treat missing secondary address as 0 + // If addresses match, we consider the node a match even if names differed! + // (Generic PCI fallback logic: /ethernet@3 =3D=3D /scsi@3 if address is 3) + if (glob_val2 !=3D path_val2) + return 0; + + // If we are here, addresses matched. + // We ignore 'name_match' result (allow mismatch/alias) + } else { + // No addresses. Strict name match required (or wildcard) + if (!name_match) + return 0; + } } + + // Both must end or have matched fully + return (*glob =3D=3D '\0' && *path =3D=3D '\0'); } #define FW_PCI_DOMAIN "/pci@i0cf8" @@ -177,7 +287,7 @@ boot_lchs_find(const char *glob) dprintf(1, "Searching bios-geometry for: %s\n", glob); int i; for (i =3D 0; i < BiosGeometryCount; i++) - if (glob_prefix(glob, BiosGeometry[i].name)) + if (fw_path_match(glob, BiosGeometry[i].name)) return &BiosGeometry[i]; return NULL; } @@ -290,7 +400,7 @@ find_prio(const char *glob) dprintf(1, "Searching bootorder for: %s\n", glob); int i; for (i =3D 0; i < BootorderCount; i++) - if (glob_prefix(glob, Bootorder[i])) + if (fw_path_match(glob, Bootorder[i])) return i+1; return -1; } --=20 2.52.0.457.g6b5491de43-goog _______________________________________________ SeaBIOS mailing list -- seabios@seabios.org To unsubscribe send an email to seabios-leave@seabios.org