From patchwork Wed Sep 3 13:36:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 201 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=1756906653; bh=JCLzFsttUdDRMj55vRhTia5ny+hkCVfsI+oTXhEr8NQ=; 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=vuuzLFxces+NvYwn+hDDgUdcjKNks8ZLaksgTDGo9XCHzl6gFONbrPI++iQtipyW2 XHUBLWD9cYOlSeCw56Bgjv8EDb5L0IaA1fdZzxSr9Is547jHIg2194LYKPS4RuKA3u y0wQ8DOZtX47+QXcjY+wNeCKj6owdpSX4PO+lCaJnVTbCd4ob1oe0ZQ5kiK4ztmG6e nQ7KCVO5U1qBAsVqSMTPTMcRhRP2Hc+DLtTwpWUIv4Qh0XUr3SFTz2N52u8fH7kPRI b0rFY41PX0ueZxAkGRmETBrIVIJBSUq1gnRjJ2Bv8mAo3hEiPf1En6KJTEuMX1h4Zy tzaW8gt97X/iw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id CEB2267920 for ; Wed, 3 Sep 2025 07:37:33 -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 4Hm0pNAxo9dF for ; Wed, 3 Sep 2025 07:37:33 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756906653; bh=JCLzFsttUdDRMj55vRhTia5ny+hkCVfsI+oTXhEr8NQ=; 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=vuuzLFxces+NvYwn+hDDgUdcjKNks8ZLaksgTDGo9XCHzl6gFONbrPI++iQtipyW2 XHUBLWD9cYOlSeCw56Bgjv8EDb5L0IaA1fdZzxSr9Is547jHIg2194LYKPS4RuKA3u y0wQ8DOZtX47+QXcjY+wNeCKj6owdpSX4PO+lCaJnVTbCd4ob1oe0ZQ5kiK4ztmG6e nQ7KCVO5U1qBAsVqSMTPTMcRhRP2Hc+DLtTwpWUIv4Qh0XUr3SFTz2N52u8fH7kPRI b0rFY41PX0ueZxAkGRmETBrIVIJBSUq1gnRjJ2Bv8mAo3hEiPf1En6KJTEuMX1h4Zy tzaW8gt97X/iw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id BC7625FE1B for ; Wed, 3 Sep 2025 07:37:33 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756906651; bh=4UbthefW4kLvtxJX0/1uXTexxsYxa+1zRd+om/UwkJo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mxSmij4mlxjiZlDH6fSS8uVsPIbQyRfV87BkLSSdLKarGpCnYGB/WDknzX223ZdSz MiO8yUnb/We/AXML0ERcEUz1ap7jygeScmrni5I64tnn+tjzAEMJ1bNAnLASA97j5j sbZ1loXwwA0BsyhngdWBRH9/w+xRHXYTxApamg3z70/CuwSbVVM9RRhkh6ccNFUtB/ +2mGUdVaDlCsaT8+RgBdvUikL7rDte3hUjsw9NGwJ2s7huZ0qdJLzVudDGPDuTerJh xOkeGswrfDhb1ERQUV9zDsPbEtm7eGwSbpoopXbw0oLbSJQYFKoCxBf0x0u5aKAGLa 2fPBBc+eUIJig== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 2E7EC6789D; Wed, 3 Sep 2025 07:37:31 -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 b8wnB5qg219O; Wed, 3 Sep 2025 07:37:31 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756906648; bh=E64PdVtCZXU93f7KmkyPBfad3bsxmt5gk15AdJj2baM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cAub+qDbHa0D1zjfJd7KyBT4EvpGRkUesTp0UK3cI80nyfAI5cF5xCghW3kmu0bSf 85V55Ng5uAADwNcbQBe9297osWRlTPqrZPoSr63rWuwi6lMs3GqiOU/4SxBhjPNxCQ UPvNcagN39UCu+tOEHW56DO8Hh+OLjhTbzC0GFegJgCBQNCmfgyfWFP8tABhxbJ+ld BwXPGJTj7k4WXf3ibywOXeIA0NnZJcYa/BZ8l3RdgDlH6XRSjoQUYFPoEMzqRq0mZT ZJJAN6aBjjpHi+oz6z5Gok7M9JxurpehEuG4ABYEF3sXQYKH2dCaAUTgvq+gp6Wfq6 JW7MctberWQzQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 6A4E55FE1B; Wed, 3 Sep 2025 07:37:28 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Wed, 3 Sep 2025 07:36:13 -0600 Message-ID: <20250903133639.3235920-14-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: 3J6BCEEROC3B4A5KUTDKEFOFDZDANLYN X-Message-ID-Hash: 3J6BCEEROC3B4A5KUTDKEFOFDZDANLYN 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 , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 13/25] chid: Create a basic CHID header and smbios interface 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 Microsoft uses information from SMBIOS tables to determine the device Windows is running on. This same approach has been adopted by fwupd and other projects. The information is used to create a list of Computer Hardware Identifiers (CHIDs) which are used to select firmware builds, etc. The EFI app needs to support this approach so it can map CHIDs to the associated compatible string. Introduce a header file for CHIDs and a function which can extract the necessary information from the SMBIOS tables. Further work will deal with actually calculating CHIDs. Co-developed-by: Claude Signed-off-by: Simon Glass --- include/chid.h | 106 +++++++++++++++++++++++++++++++++++++++++++++++++ lib/Kconfig | 9 +++++ lib/Makefile | 2 + lib/chid.c | 73 ++++++++++++++++++++++++++++++++++ 4 files changed, 190 insertions(+) create mode 100644 include/chid.h create mode 100644 lib/chid.c diff --git a/include/chid.h b/include/chid.h new file mode 100644 index 00000000000..5746ba88c32 --- /dev/null +++ b/include/chid.h @@ -0,0 +1,106 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Computer Hardware Identifiers (Windows CHID) + * + * See: https://github.com/fwupd/fwupd/blob/main/docs/hwids.md + * + * Copyright 2025 Simon Glass + */ + +#ifndef __chid_h +#define __chid_h + +#include + +/** + * enum chid_field_t - fields we pick up from SMBIOS tables + * + * Used as BIT(x) values that can be ORed together to define which fields are + * used in each CHID variant. + * + * The table and field name is shown here (see smbios.h). All are strings + * except those noted as int. + * + * @CHID_MANUF: SMBIOS Type 1 (System Information): manufacturer + * @CHID_FAMILY: SMBIOS Type 1 (System Information): family + * @CHID_PRODUCT_NAME: SMBIOS Type 1 (System Information): product_name + * @CHID_PRODUCT_SKU: SMBIOS Type 1 (System Information): sku_number + * @CHID_BOARD_MANUF: SMBIOS Type 2 (Baseboard Information): manufacturer + * @CHID_BOARD_PRODUCT: SMBIOS Type 2 (Baseboard Information): product_name + * @CHID_BIOS_VENDOR: SMBIOS Type 0 (BIOS Information): vendor + * @CHID_BIOS_VERSION: SMBIOS Type 0 (BIOS Information): bios_ver + * @CHID_BIOS_MAJOR: SMBIOS Type 0 (BIOS Information): bios_major_release (int) + * @CHID_BIOS_MINOR: SMBIOS Type 0 (BIOS Information): bios_minor_release (int) + * @CHID_ENCLOSURE_TYPE: SMBIOS Type 3 (System Enclosure): chassis_type (int) + * @CHID_COUNT: Number of CHID fields + */ +enum chid_field_t { + CHID_MANUF, + CHID_FAMILY, + CHID_PRODUCT_NAME, + CHID_PRODUCT_SKU, + CHID_BOARD_MANUF, + CHID_BOARD_PRODUCT, + CHID_BIOS_VENDOR, + CHID_BIOS_VERSION, + CHID_BIOS_MAJOR, + CHID_BIOS_MINOR, + CHID_ENCLOSURE_TYPE, + + CHID_COUNT, +}; + +/** + * struct chid_variant - defines which fields are used in each CHID variant + * + * @name: Human-readable name for debugging + * @fields: Bitmask of fields (BIT(CHID_xxx) values ORed together) + */ +struct chid_variant { + const char *name; + u32 fields; +}; + +/** + * struct chid_data - contains SMBIOS field values to use in calculating CHID + * + * There is one field here for each item in enum chid_field_t + * + * @manuf: System manufacturer string + * @family: Product family string + * @product_name: Product name string + * @product_sku: Product SKU string + * @board_manuf: Baseboard manufacturer string + * @board_product: Baseboard product string + * @bios_vendor: BIOS vendor string + * @bios_version: BIOS version string + * @bios_major: BIOS major version number + * @bios_minor: BIOS minor version number + * @enclosure_type: System enclosure type + */ +struct chid_data { + const char *manuf; + const char *family; + const char *product_name; + const char *product_sku; + const char *board_manuf; + const char *board_product; + const char *bios_vendor; + const char *bios_version; + u8 bios_major; + u8 bios_minor; + u8 enclosure_type; +}; + +/** + * chid_from_smbios() - Extract CHID data from SMBIOS tables + * + * @chid: Pointer to CHID data structure to fill + * + * Return: 0 if OK, -ENOENT if a required table is missing (SMBIOS types 0-1), + * other -ve error code if the SMBIOS tables cannot be found (see + * smbios_locate()) + */ +int chid_from_smbios(struct chid_data *chid); + +#endif diff --git a/lib/Kconfig b/lib/Kconfig index ed35c1f0b30..c45a98313aa 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -1187,6 +1187,15 @@ config SMBIOS_PARSER help A simple parser for SMBIOS data. +config CHID + bool "Support Microsoft Computer Hardware IDs (CHIDs)" + depends on SMBIOS_PARSER + default y if ARCH_EFI_ARM || SANDBOX + help + Provides support for Microsoft Computer Hardware IDs (CHIDs) which + can be used to identify a board so that the correct devicetree is + used with it. + source "lib/optee/Kconfig" config TEST_FDTDEC diff --git a/lib/Makefile b/lib/Makefile index bcca308e0d8..af191913873 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -29,6 +29,8 @@ obj-y += charset.o endif endif +obj-$(CONFIG_CHID) += chid.o + ifdef CONFIG_USB_TTY obj-y += circbuf.o else diff --git a/lib/chid.c b/lib/chid.c new file mode 100644 index 00000000000..10e9b8fecae --- /dev/null +++ b/lib/chid.c @@ -0,0 +1,73 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Computer Hardware Identifiers (Windows CHID) support + * + * This implements the Microsoft Computer Hardware ID specification + * used by Windows Update and fwupd for hardware identification. + * + * See: https://github.com/fwupd/fwupd/blob/main/docs/hwids.md + * See: https://docs.microsoft.com/en-us/windows-hardware/drivers/install/specifying-hardware-ids-for-a-computer + * + * Copyright 2025 Simon Glass + */ + +#define LOG_CATEGORY LOGC_ACPI + +#include +#include +#include +#include + +DECLARE_GLOBAL_DATA_PTR; + +int chid_from_smbios(struct chid_data *chid) +{ + const struct smbios_type0 *bios; + const struct smbios_type1 *sys; + const struct smbios_type2 *board; + const struct smbios_type3 *encl; + struct smbios_info info; + int ret; + + /* Clear the structure first */ + memset(chid, '\0', sizeof(*chid)); + + ret = smbios_locate(gd_smbios_start(), &info); + if (ret) + return ret; + + /* Extract BIOS Information (Type 0) */ + bios = smbios_get_header(&info, SMBIOS_BIOS_INFORMATION); + if (!bios) + return log_msg_ret("cf0", -ENOENT); + + chid->bios_vendor = smbios_string(&bios->hdr, bios->vendor); + chid->bios_version = smbios_string(&bios->hdr, bios->bios_ver); + chid->bios_major = bios->bios_major_release; + chid->bios_minor = bios->bios_minor_release; + + /* Extract System Information (Type 1) */ + sys = smbios_get_header(&info, SMBIOS_SYSTEM_INFORMATION); + if (!sys) + return log_msg_ret("cf1", -ENOENT); + chid->manuf = smbios_string(&sys->hdr, sys->manufacturer); + chid->product_name = smbios_string(&sys->hdr, sys->product_name); + chid->family = smbios_string(&sys->hdr, sys->family); + chid->product_sku = smbios_string(&sys->hdr, sys->sku_number); + + /* Extract Baseboard Information (Type 2) */ + board = smbios_get_header(&info, SMBIOS_BOARD_INFORMATION); + if (board) { + chid->board_manuf = smbios_string(&board->hdr, + board->manufacturer); + chid->board_product = smbios_string(&board->hdr, + board->product_name); + } + + /* Extract System Enclosure Information (Type 3) */ + encl = smbios_get_header(&info, SMBIOS_SYSTEM_ENCLOSURE); + if (encl) + chid->enclosure_type = encl->chassis_type; + + return 0; +}