Files
u-boot/test/cmd/chid.c
Simon Glass 817fd8201f 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
2025-09-04 07:08:25 -06:00

126 lines
3.7 KiB
C

// SPDX-License-Identifier: GPL-2.0+
/*
* Test for chid command
*
* Copyright 2025 Simon Glass <sjg@chromium.org>
*/
#include <command.h>
#include <console.h>
#include <env.h>
#include <test/cmd.h>
#include <test/ut.h>
#include <version.h>
/* Test the 'chid show' command */
static int cmd_chid_show_test(struct unit_test_state *uts)
{
/* Test chid show command and verify expected output */
ut_assertok(run_command("chid show", 0));
ut_assert_nextline("Manufacturer: Sandbox Corp");
ut_assert_nextline("Family: Sandbox_Family");
ut_assert_nextline("Product Name: Sandbox Computer");
ut_assert_nextline("Product SKU: SANDBOX-SKU");
ut_assert_nextline("Baseboard Manuf: Sandbox Boards");
ut_assert_nextline("Baseboard Product: Sandbox Motherboard");
ut_assert_nextline("BIOS Vendor: U-Boot");
ut_assert_nextlinen("BIOS Version: " PLAIN_VERSION);
ut_assert_nextline("BIOS Major: %u", U_BOOT_VERSION_NUM % 100);
ut_assert_nextline("BIOS Minor: %u", U_BOOT_VERSION_NUM_PATCH);
ut_assert_nextline("Enclosure Type: 2");
ut_assert_console_end();
return 0;
}
CMD_TEST(cmd_chid_show_test, UTF_CONSOLE);
/* Test invalid chid subcommand */
static int cmd_chid_invalid_test(struct unit_test_state *uts)
{
/* Test chid command with invalid arguments */
ut_asserteq(1, run_command("chid invalid", 0));
return 0;
}
CMD_TEST(cmd_chid_invalid_test, UTF_CONSOLE);
/* Test the 'chid list' command */
static int cmd_chid_list_test(struct unit_test_state *uts)
{
/* Test chid list command runs successfully */
ut_assertok(run_command("chid list", 0));
/* Just verify that some output is produced - exact CHIDs vary */
return 0;
}
CMD_TEST(cmd_chid_list_test, UTF_CONSOLE);
/* Test the 'chid detail' command */
static int cmd_chid_detail_test(struct unit_test_state *uts)
{
/* Test chid detail command for variant 14 (manufacturer only) */
ut_assertok(run_command("chid detail 14", 0));
ut_assert_nextlinen("HardwareID-14: ");
ut_assert_nextline("Fields: Manufacturer");
ut_assert_console_end();
/* Test chid detail command for variant 0 (most specific) */
ut_assertok(run_command("chid detail 0", 0));
ut_assert_nextlinen("HardwareID-00: ");
ut_assert_nextline(
"Fields: Manufacturer + Family + ProductName + ProductSku + "
"BiosVendor + BiosVersion + BiosMajorRelease + "
"BiosMinorRelease");
ut_assert_console_end();
return 0;
}
CMD_TEST(cmd_chid_detail_test, UTF_CONSOLE);
/* Test chid detail with invalid variant */
static int cmd_chid_detail_invalid_test(struct unit_test_state *uts)
{
/* Test chid detail with invalid variant number - should fail */
ut_asserteq(1, run_command("chid detail 15", 0));
/* Test chid detail with negative variant number - should fail */
ut_asserteq(1, run_command("chid detail -1", 0));
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);