From patchwork Wed Sep 3 13:36:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 193 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=1756906625; bh=UbSXyPRip3Ik1Dm/joeT+U3BkJZ6bftZNgmG5BJlE0s=; 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=GOSbAajtW5swVHrUX0PKQIy9kr/45EwZUM2i8BepvbvvqeMk86Wv+pldNSTF0SEIB s1Q5AB8gcDS9McOxKcZAOJ7N+obFPgWgW9ASqV/lhbmp/i4htCXOtFRl783GHjwJIU c7omDlGGTPXRmYnlfbI8tqiLA8qr3XJljs9jJGtaxxHamJWtiRF59jiILiXwiXaGiX s+Wxq3TFfrLmiMAUH7/wwprtITLvAMg8FnZGWTTi0qFgxzWsjUSZKjeqkaIBR8KopN BSxljXgA94yNEsl0nBLU2blrObmEi1COwed3HX7T2Ejj2KzTl6NRmVup8ccdkteiRL cnDmwHBI00Jqw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id CFDC767910 for ; Wed, 3 Sep 2025 07:37:05 -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 cc-K4VHA2ZTC for ; Wed, 3 Sep 2025 07:37:05 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756906625; bh=UbSXyPRip3Ik1Dm/joeT+U3BkJZ6bftZNgmG5BJlE0s=; 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=GOSbAajtW5swVHrUX0PKQIy9kr/45EwZUM2i8BepvbvvqeMk86Wv+pldNSTF0SEIB s1Q5AB8gcDS9McOxKcZAOJ7N+obFPgWgW9ASqV/lhbmp/i4htCXOtFRl783GHjwJIU c7omDlGGTPXRmYnlfbI8tqiLA8qr3XJljs9jJGtaxxHamJWtiRF59jiILiXwiXaGiX s+Wxq3TFfrLmiMAUH7/wwprtITLvAMg8FnZGWTTi0qFgxzWsjUSZKjeqkaIBR8KopN BSxljXgA94yNEsl0nBLU2blrObmEi1COwed3HX7T2Ejj2KzTl6NRmVup8ccdkteiRL cnDmwHBI00Jqw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id BD0CF678F3 for ; Wed, 3 Sep 2025 07:37:05 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756906623; bh=HQYTDDwUUZj6T3LlXdkCK/gc+eZ0iyrEKtmDiu53wqU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a5fTUmAubV+0LD0MEAi0uzUGWKCWZPbVUpWc9ArSAEP432Nm4MkaiSdmuoQgc5EfZ E1A1Vxn2JOvPVrhEavax8rcsSZGr4qB3qbZgUfsiqlA/8VziScDlKj3LLq4p/xZwJT XE8Aht4sHWyACqdFgDREy0davwhd8mh+1kjT5bhpOvi1kmzq8uGIQZI4WXy3HXYQYH CvCwEbmQaFfKbtVMfsyOWNPgHNmEj3AqhhKgpnXzqSB2fsafIVN8b0jtNZefRD05Qk L+TR+R9+OVQHGdyTAg+r7Lhb7T7kYV3+ljSp0grGv+pILHZUuNRmb0QdLpMjTEaUlG 0lpVOioXQ6mhQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 9DC7F6789D; Wed, 3 Sep 2025 07:37:03 -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 oiu62vsMcS-H; Wed, 3 Sep 2025 07:37:03 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756906617; bh=CfUKX5A4QlB9qecIdt/j3b+eWWeIEHNXfD+z5RdTfsI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TjwTAFMcYopxQ745Q2B8r40UeMr7P1+LiBHULFQeuNBZj29K7Vod69f5GC7BsC8EK vjBACICDBM0yoVulkP6IrIwD/pFcWzzXYLxjMA77dVaFw7AoqtsbYR5wkMJVbdgDrz rIc1v083AaZbvCXpg29+Wxdi5/fW7jd/3D4685J6SI1SDzg/7OuE/qDAl2XErytkw9 vnS/LA1W2FBSeVNTd/ZDHTtK4lL/fAAn7XX0T9Uxy2EwtJbjFMqUFdsKiYBHXUZ4yU N5k/elJR4k5paKuUGFhIcSTZhXhNaNMZOZjM4iHKyIVR4nZLNzToqPjDULU9JngnRm kTg8D2gRdgQfw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id ACCD667910; Wed, 3 Sep 2025 07:36:57 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Wed, 3 Sep 2025 07:36:04 -0600 Message-ID: <20250903133639.3235920-5-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250903133639.3235920-1-sjg@u-boot.org> References: <20250903133639.3235920-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: EXWUYRL6LMXF3U6NP7KAK3T2XIHEFJNA X-Message-ID-Hash: EXWUYRL6LMXF3U6NP7KAK3T2XIHEFJNA 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 04/25] smbios: Update smbios_get_header() to return a void * 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 Since each table starts with a header, it isn't very useful to have a separate pointer for the (generic) header and another for the whole table. Also, casting is a bit of a pain. Update smbios_get_header() so that it returns a const void * so that it is possible to directly assign it to the appropriate SMBIOS table's pointer. Signed-off-by: Simon Glass --- board/coreboot/coreboot/sysinfo.c | 31 ++++++++++++++----------------- include/smbios.h | 9 ++++----- lib/smbios-parser.c | 13 +++++-------- 3 files changed, 23 insertions(+), 30 deletions(-) diff --git a/board/coreboot/coreboot/sysinfo.c b/board/coreboot/coreboot/sysinfo.c index 2fb68cbfa92..f431d271a1c 100644 --- a/board/coreboot/coreboot/sysinfo.c +++ b/board/coreboot/coreboot/sysinfo.c @@ -12,10 +12,8 @@ #include struct cb_sysinfo_priv { - const struct smbios_header *bios; - const struct smbios_header *system; - const struct smbios_type0 *t0; - const struct smbios_type1 *t1; + const struct smbios_type0 *bios; + const struct smbios_type1 *system; }; static int cb_get_str(struct udevice *dev, int id, size_t size, char *val) @@ -25,23 +23,24 @@ static int cb_get_str(struct udevice *dev, int id, size_t size, char *val) switch (id) { case SYSID_BOARD_MODEL: - if (priv->t1) - str = smbios_string(priv->system, - priv->t1->product_name); + if (priv->system) + str = smbios_string(&priv->system->hdr, + priv->system->product_name); break; case SYSID_BOARD_MANUFACTURER: - if (priv->t1) - str = smbios_string(priv->system, - priv->t1->manufacturer); + if (priv->system) + str = smbios_string(&priv->system->hdr, + priv->system->manufacturer); break; case SYSID_PRIOR_STAGE_VERSION: - if (priv->t0) - str = smbios_string(priv->bios, priv->t0->bios_ver); + if (priv->bios) + str = smbios_string(&priv->bios->hdr, + priv->bios->bios_ver); break; case SYSID_PRIOR_STAGE_DATE: - if (priv->t0) - str = smbios_string(priv->bios, - priv->t0->bios_release_date); + if (priv->bios) + str = smbios_string(&priv->bios->hdr, + priv->bios->bios_release_date); break; } if (!str) @@ -64,8 +63,6 @@ static int cb_detect(struct udevice *dev) priv->bios = smbios_get_header(&info, SMBIOS_BIOS_INFORMATION); priv->system = smbios_get_header(&info, SMBIOS_SYSTEM_INFORMATION); - priv->t0 = (struct smbios_type0 *)priv->bios; - priv->t1 = (struct smbios_type1 *)priv->system; return 0; } diff --git a/include/smbios.h b/include/smbios.h index 1bae4d99b05..96202f9a1c8 100644 --- a/include/smbios.h +++ b/include/smbios.h @@ -369,12 +369,11 @@ const struct smbios_entry *smbios_entry(u64 address, u32 size); /** * smbios_get_header() - Search for an SMBIOS header type * - * @entry: pointer to the first entry - * @type: SMBIOS type - * @return: NULL or a valid pointer to a struct smbios_header + * @info: SMBIOS info + * @type: SMBIOS type + * @return: NULL or a valid pointer to a struct smbios_header */ -const struct smbios_header *smbios_get_header(const struct smbios_info *info, - int type); +const void *smbios_get_header(const struct smbios_info *info, int type); /** * smbios_string() - Return string from SMBIOS diff --git a/lib/smbios-parser.c b/lib/smbios-parser.c index d8dc25da6ce..abb301ecf7e 100644 --- a/lib/smbios-parser.c +++ b/lib/smbios-parser.c @@ -62,8 +62,7 @@ const struct smbios_entry *smbios_entry(u64 address, u32 size) return entry; } -const struct smbios_header *smbios_get_header(const struct smbios_info *info, - int type) +const void *smbios_get_header(const struct smbios_info *info, int type) { struct smbios_header *header; @@ -107,9 +106,8 @@ char *smbios_string(const struct smbios_header *header, int index) int smbios_update_version_full(void *smbios_tab, const char *new_version) { - const struct smbios_header *hdr; + const struct smbios_type0 *bios; struct smbios_info info; - struct smbios_type0 *bios; uint old_len, len; char *ptr; int ret; @@ -119,11 +117,10 @@ int smbios_update_version_full(void *smbios_tab, const char *new_version) return log_msg_ret("tab", -ENOENT); log_info("Updating SMBIOS table at %p\n", smbios_tab); - hdr = smbios_get_header(&info, SMBIOS_BIOS_INFORMATION); - if (!hdr) + bios = smbios_get_header(&info, SMBIOS_BIOS_INFORMATION); + if (!bios) return log_msg_ret("tab", -ENOENT); - bios = (struct smbios_type0 *)hdr; - ptr = smbios_string(hdr, bios->bios_ver); + ptr = smbios_string(&bios->hdr, bios->bios_ver); if (!ptr) return log_msg_ret("str", -ENOMEDIUM);