cmd: chid: Add 'compat' subcommand to find compatible string

Add a new 'chid compat' subcommand that finds the compatible string
matching the current hardware's CHID and sets the fdtcompat environment
variable. This examines the devicetree under /chid for nodes with
hardware-id child nodes containing CHID data that matches the system's
generated CHIDs.

The command prints the found compatible string to the console and
automatically sets the fdtcompat environment variable for use by
other U-Boot commands.

Series-to: concept
Cover-letter:
Selection of devicetree using CHIDs
This series implements support for Microsoft's Computer Hardware
Identifier (CHID) specification in U-Boot. CHIDs provide a standardised
way to identify hardware configurations using SMBIOS data, enabling
automatic selection of appropriate device tree overlays and drivers when
the firmware itself lacks support for devicetree.

The CHID system generates UUIDs from various combinations of hardware
information (manufacturer, product name, BIOS version, etc.) creating a
hierarchy from most to least specific. This allows U-Boot to
automatically select the correct devicetree compatible-string for the
hardware on which it running.

This series includes:

* Core CHID Infrastructure:
   - UUID v5 generation with Microsoft's CHID namespace
   - Support for all 15 CHID variants (HardwareID-00 through HardwareID-14)
   - SMBIOS data extraction and processing

* Devicetree Integration:
   - hwids_to_dtsi.py script to convert CHID files to devicetree .dtsi
   - Automatic inclusion of the .dtsi into the board'' devicetree
   - Runtime compatible-string-selection based on hardware CHIDs

* chid command:
   - chid show - show current hardware information and generated CHIDs
   - chid list - list all supported CHID variants and generated UUIDs
   - chid variants - show information about CHID variant restrictions
   - chid compat - select the compatible string for current hardware

* ARM/EFI Support:
   - CHID mappings for a selection of ARM-based Windows devices
   - Support for Qualcomm Snapdragon platforms (MSM8998, SC7180, SC8180X,
     SC8280XP, SDM850, X1E series)

* Testing:
   - Sandbox tests using mock SMBIOS data
   - CI integration for hwids_to_dtsi validation
   - Validation against Microsoft's ComputerHardwareIds.exe output

Documentation is provided for this new subsystem and associated
commands.
END

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
Series-links: 1:22
This commit is contained in:
Simon Glass
2025-09-01 20:07:23 -06:00
parent 546c5dcc17
commit 817fd8201f
3 changed files with 72 additions and 0 deletions

View File

@@ -7,6 +7,7 @@
#include <chid.h>
#include <command.h>
#include <env.h>
#include <vsprintf.h>
#include <linux/bitops.h>
#include <u-boot/uuid.h>
@@ -123,12 +124,37 @@ static int do_chid_detail(struct cmd_tbl *cmdtp, int flag, int argc,
return 0;
}
static int do_chid_compat(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
{
const char *compat;
int ret;
ret = chid_select(&compat);
if (ret) {
printf("No compatible string found (err=%d)\n", ret);
return CMD_RET_FAILURE;
}
printf("%s\n", compat);
ret = env_set("fdtcompat", compat);
if (ret) {
printf("Failed to set fdtcompat environment variable (err=%d)\n", ret);
return CMD_RET_FAILURE;
}
return 0;
}
U_BOOT_LONGHELP(chid,
"compat - Find compatible string and set fdtcompat env var\n"
"list - List all CHID variants\n"
"show - Show CHID data extracted from SMBIOS\n"
"detail <variant> - Show details for a specific CHID variant (0-14)");
U_BOOT_CMD_WITH_SUBCMDS(chid, "Computer Hardware ID utilities", chid_help_text,
U_BOOT_SUBCMD_MKENT(compat, 1, 1, do_chid_compat),
U_BOOT_SUBCMD_MKENT(list, 1, 1, do_chid_list),
U_BOOT_SUBCMD_MKENT(show, 1, 1, do_chid_show),
U_BOOT_SUBCMD_MKENT(detail, 2, 1, do_chid_detail));

View File

@@ -8,6 +8,7 @@ Synopsis
::
chid compat
chid list
chid show
chid detail <variant>
@@ -32,6 +33,12 @@ show
Show the relevant SMBIOS values for the current board. These are used to
calculate CHIDs.
compat
Find the compatible string that matches the current hardware's CHID and
set the fdtcompat environment variable. This examines the devicetree under
/chid for nodes with hardware-id child nodes containing CHID data that
matches the system's generated CHIDs.
list
Display all 15 CHID variants with their generated UUIDs
@@ -83,6 +90,13 @@ Show details for a specific variant::
HardwareID-14: 45c5e2e7-db48-556b-aae4-0a03c5a15eae
Fields: Manufacturer
Find compatible string and set environment variable::
=> chid compat
google,veyron-speedy
=> printenv fdtcompat
fdtcompat=google,veyron-speedy
Configuration
-------------

View File

@@ -7,6 +7,7 @@
#include <command.h>
#include <console.h>
#include <env.h>
#include <test/cmd.h>
#include <test/ut.h>
#include <version.h>
@@ -91,3 +92,34 @@ static int cmd_chid_detail_invalid_test(struct unit_test_state *uts)
return 0;
}
CMD_TEST(cmd_chid_detail_invalid_test, 0);
/* Test the 'chid compat' command */
static int cmd_chid_compat_test(struct unit_test_state *uts)
{
const char *fdtcompat_val;
int ret;
/* Clear any existing fdtcompat environment variable */
env_set("fdtcompat", NULL);
ut_assertnull(env_get("fdtcompat"));
/* Run chid compat command - may succeed or fail depending on devicetree */
ret = run_command("chid compat", 0);
if (ret == 0) {
/* Command succeeded, check that fdtcompat was set */
fdtcompat_val = env_get("fdtcompat");
ut_assertnonnull(fdtcompat_val);
ut_assert(strlen(fdtcompat_val) > 0);
/* Command should print the compatible string it found */
ut_assert_nextline(fdtcompat_val);
} else {
/* Command failed, check expected failure message and no env var set */
ut_assert_nextline("No compatible string found");
ut_assertnull(env_get("fdtcompat"));
}
ut_assert_console_end();
return 0;
}
CMD_TEST(cmd_chid_compat_test, UTF_CONSOLE);