From patchwork Wed Sep 3 13:36:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 212 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=1756906690; bh=EMQKyiI0wsQN8VPITv3a0i6G7eZpDfPTe22UA1YCzj0=; 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=GpyF5BzVkGVxg7YVTHHkmV/evCj6mY8sKZHRS18RxRKbFTUM/CIbq3RCJBZ5glbEY RCUOMjNvsPUmaO4VeY6vaSXWmLxuITkXruM5QMxRYEvarygfxZSbHCV5o3IyRLGLWV G+3hX6ZARPlQuVAhLhFsC32YLc63dp/E2PuCTRK62hbSSa5Avg+B/ZNherBXYkoH1v vfwUVAIl+HGNf9C8iCv51jcsqR0QlQLYKnn7rsnuvPupIfqFtbyZmqOH7mZy9qXI4W 1mMKCrzNBRbdBkwt5sDMBbfaiMeqGOx6e8TCCcmRJEEQLyzlFEjYiPtQkB7BEHijWj 7BsFzK0Wm0tfA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 0519467920 for ; Wed, 3 Sep 2025 07:38:10 -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 u0tcS7mJ8Bbl for ; Wed, 3 Sep 2025 07:38:09 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756906689; bh=EMQKyiI0wsQN8VPITv3a0i6G7eZpDfPTe22UA1YCzj0=; 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=LMPwoke636OGZQWDrRlNAFKRF2nK/0X4C3pOQUwJL4qvZO7szhBhIhjEk74zgIAAm 4rloWYIUr1ft5yjjK+yxLFe6rAOKIoCjpursraAYuKF1PcymUFA6fnya6huOZXb0eK LvCg0AvJ5CSdIMhd7Jo5zGjlAbvEd/Zi5Y4/rJ4ITUSEOeCdoLO53PP7hFfcnmD2Ov khKcZacKzXVzWI7H64pzkCa3iBAP643X0oW5lr3tKk83Oo0HpxRYsbCtMMx5uLkYoM XIHYGirHPrTRvaTv8XcRBE9EuRWXrPZ9fFMnPrZVOyat15s2oatGenJb44LCLQwmuN /tfnVC0L7NCMw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id E8AF867819 for ; Wed, 3 Sep 2025 07:38:09 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756906687; bh=3IaSxgl1eLFV/Bg5jVzkJQvavGcNYzrwZRjlNLiP2lo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OZ/yke5+BpH8CcHcdEOUjoNYEEIoylUdyZNI2XzFZvsX6/bS+3kE5oJPcpkyID5kz +Nb1SEko9pe+2R4VvP4/WGRB2MFEJK/FBsb6mrNbYbh2PoqgKl6eMBHd6Rr9LSKazw sZtSnigTsSEG0jby96ExhLCLPNoPEV78FPMEpo4hEQIr3ECkkxQ7lPtXD6KTKdVXWC HTDT1+0ljNmH3Ax+Q1N/qJC9Y7PykvFAKCOBGRnfvuGprcuyxyDgzdpV+PNLSpuIJx 1lAAyjVbvkqzGotc0ZMbEgltl/zOlt332wFTEz8Lp3ujluvrFH9ZfCNcQvQwx2n3gT ZVVaF22XO2jug== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id EEB3A5FE1B; Wed, 3 Sep 2025 07:38:07 -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 0JJ6sHBcmUWj; Wed, 3 Sep 2025 07:38:07 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756906683; bh=hwSX06NvzwrXsIbTmqorsa1KCvnKVDygE9gHkyDco3o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FrB+gs6mzz0evOFPhZNoSSwTD7kxk/jcopuao8VtBMjMCFp8eGvsyCvNHtz6TCCI8 nQkEBW7s61IMaZmVPq5rgBm94wxYZEzpvRc3fCS6BGInE214jw42JCHcrrrkEuiO0q 1zSsteuT8WO9slbA9zkoYHCL5dD5TCkC9dO8U8Hl32i8OwEaLzDGralJmCuMeiAT1g JCdJF6L8vJDDv5Oxnbd0BorUjtG37r2UthHqmr88+eSr7bL4P9bGy5CfFFfTMHxA3r z0ycJHTHZf8XZLuu3XtXYcZ2ouXm/zt+etTe0itNtiaew5eHNG0LUlIdtk3DPSWWBq hT54TJau9F9pw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id E98955FCF5; Wed, 3 Sep 2025 07:38:02 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Wed, 3 Sep 2025 07:36:25 -0600 Message-ID: <20250903133639.3235920-26-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: WFZ3CZZIIF2REYARUJZBFRHITJJWMVOK X-Message-ID-Hash: WFZ3CZZIIF2REYARUJZBFRHITJJWMVOK 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 25/25] cmd: chid: Add 'compat' subcommand to find compatible string 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 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. Co-developed-by: Claude Signed-off-by: Simon Glass --- cmd/chid.c | 26 ++++++++++++++++++++++++++ doc/usage/cmd/chid.rst | 14 ++++++++++++++ test/cmd/chid.c | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+) diff --git a/cmd/chid.c b/cmd/chid.c index f61e8370f84..24c145a6dad 100644 --- a/cmd/chid.c +++ b/cmd/chid.c @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -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 - 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)); diff --git a/doc/usage/cmd/chid.rst b/doc/usage/cmd/chid.rst index e96101928d8..9644b28562e 100644 --- a/doc/usage/cmd/chid.rst +++ b/doc/usage/cmd/chid.rst @@ -8,6 +8,7 @@ Synopsis :: + chid compat chid list chid show chid detail @@ -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 ------------- diff --git a/test/cmd/chid.c b/test/cmd/chid.c index 9968e7dc518..01bde5d436c 100644 --- a/test/cmd/chid.c +++ b/test/cmd/chid.c @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -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);