From patchwork Sat Nov 15 18:52:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 710 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=1763232823; bh=icgzknDuCGh56BVsL5gyYA0YazoyVAVbyngOUpTr4UE=; 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=YtZ1CTIv/a9D5CuIPwJ/k5XZvNTlAKqhBd8aFcOU3diuEpR2iN08MmvUSbuSn58Mk VxU4Ueu284Dx8GIwc9R1gZ0ggw0atqBILm+MKYw0yYpM9zYXQYlm1XAGzjVepVVb3f huV7rxe/1FqCLDtuJ6Je1Eo/Bt8Lug1jqnJFU4n+9k5qkci5uhwmfbhe/8wVFUiIZL S0/s0BuiWKDxqYQifcgLEZ3q2TZ6dT+WqWtbhJk/8EW7kAq+GCiNOSSWCkAfshmeHC pFgwpRaEpOOwX0EGTojBHzl/1/8ktYYONSqqOl0mS7aeO2TFXgY7o0VG00KPRDiwcC cug6FzBtvAwLA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 7112468521 for ; Sat, 15 Nov 2025 11:53:43 -0700 (MST) 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 DRFmghEaZjBt for ; Sat, 15 Nov 2025 11:53:43 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1763232823; bh=icgzknDuCGh56BVsL5gyYA0YazoyVAVbyngOUpTr4UE=; 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=YtZ1CTIv/a9D5CuIPwJ/k5XZvNTlAKqhBd8aFcOU3diuEpR2iN08MmvUSbuSn58Mk VxU4Ueu284Dx8GIwc9R1gZ0ggw0atqBILm+MKYw0yYpM9zYXQYlm1XAGzjVepVVb3f huV7rxe/1FqCLDtuJ6Je1Eo/Bt8Lug1jqnJFU4n+9k5qkci5uhwmfbhe/8wVFUiIZL S0/s0BuiWKDxqYQifcgLEZ3q2TZ6dT+WqWtbhJk/8EW7kAq+GCiNOSSWCkAfshmeHC pFgwpRaEpOOwX0EGTojBHzl/1/8ktYYONSqqOl0mS7aeO2TFXgY7o0VG00KPRDiwcC cug6FzBtvAwLA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 60F74685D9 for ; Sat, 15 Nov 2025 11:53:43 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1763232820; bh=qO2ewK2SXEHPfWio8sDju4061YNr4hVOeD1A9cozynQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CxjhF/FYzbknlIvCjY35H1Y7qeG9sz2Imcf++9WclcUCYQ4qGTCK5KV9feMIDDfN4 FqZSH0FLSVbZZri1thjM2StR5ZFr2D2pjK5u2t0zX2JcOcvOOFy+HdcMky8Z80A7XP KisRBvCWveYYDornu9pswuSNThED3F1RO/tLBzGuuXKhvpEOm7zL//5sUFuMKsxAyI ibhcUM/VquQ5xEOYAeJt5YVY0gQ7EORRup22qXaS11UOFqx0QM5HtaRYrDMMp3QooK YLYJgnNpzQwThOG2mdaSEXJ6jKRlgiW+klZgtW0msYjaedlySdKEnG1HvATQoSp++3 c8dKB9s9RSNcQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id B918768521; Sat, 15 Nov 2025 11:53:40 -0700 (MST) 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 w8kQBiBROYzF; Sat, 15 Nov 2025 11:53:40 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1763232814; bh=7vdjfIgGI6h+s/Ptm3wh3NDjYE9t6T2OkzpXDbD6lLk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PbsbSQ6tzaBICfWH7OmP6UM1PlVjQYwOmlaG4QAX/Q2fD+vrcI5Z+2XbBLZSv2ZmQ yWNq7W6AHUvZd8u49oMMDUG8GGl/ktgo+jR/eoG/tLqHdz94W70r9T734GkHNCk1xJ n1Gnm9FtRCrLSQTMbLz8AX9iFtzRzj4e8nrTeBddwC5S34HkgI5Q2KTImpev7haOlU FXFD/0X9SxfzHtwpTfBtKFEq7ojcdlpUTIHT4TKZ++QJ7AVrMWOD0l6BdUC9DVmqit cSL1pPHfu0fohmetMH20G95RyfWZENeiPg4Q8AGk7lSIAw02tjW0Py2R+WzN2HS6fk y7h6PCCCBoYRA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 9CD41685D9; Sat, 15 Nov 2025 11:53:34 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 15 Nov 2025 11:52:01 -0700 Message-ID: <20251115185212.539268-13-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251115185212.539268-1-sjg@u-boot.org> References: <20251115185212.539268-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 6CMMVHMFUC3RRBQN7PAJ4FTTNG5VDG7K X-Message-ID-Hash: 6CMMVHMFUC3RRBQN7PAJ4FTTNG5VDG7K 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 12/16] tkey: Allow selecting the TKey device by name 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 Enhance the 'tkey connect' command to allow the device name to be specified. This will be useful in tests. Signed-off-by: Simon Glass --- cmd/tkey.c | 36 +++++++++++++++++++++++++++++++----- doc/usage/cmd/tkey.rst | 24 ++++++++++++++++++++---- 2 files changed, 51 insertions(+), 9 deletions(-) diff --git a/cmd/tkey.c b/cmd/tkey.c index a269ca86085..3a31712990a 100644 --- a/cmd/tkey.c +++ b/cmd/tkey.c @@ -19,11 +19,18 @@ #include #include +/* Static device pointer set by tkey connect command */ +static struct udevice *tkey_dev; + static struct udevice *tkey_get_device(void) { struct udevice *dev; int ret; + /* If a device was set by tkey connect, return it */ + if (tkey_dev) + return tkey_dev; + ret = uclass_first_device_err(UCLASS_TKEY, &dev); if (ret) { printf("No device found (err %dE)\n", ret); @@ -47,10 +54,28 @@ static int do_tkey_connect(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { struct udevice *dev; + int ret; - dev = tkey_get_device(); - if (!dev) - return CMD_RET_FAILURE; + /* Check if device name is provided as optional first argument */ + if (argc > 1) { + const char *dev_name = argv[1]; + + ret = uclass_get_device_by_name(UCLASS_TKEY, dev_name, &dev); + if (ret) { + printf("Failed to find TKey device '%s' (err %dE)\n", + dev_name, ret); + return CMD_RET_FAILURE; + } + } else { + ret = uclass_first_device_err(UCLASS_TKEY, &dev); + if (ret) { + printf("No device found (err %dE)\n", ret); + return CMD_RET_FAILURE; + } + } + + /* Set the static device pointer for subsequent commands */ + tkey_dev = dev; printf("Connected to TKey device\n"); @@ -276,7 +301,8 @@ static int do_tkey_loadapp(struct cmd_tbl *cmdtp, int flag, int argc, } U_BOOT_LONGHELP(tkey, - "connect - Connect to TKey device\n" + "connect [device-name] - Connect to TKey device\n" + " Optional device-name to connect to specific TKey device\n" "tkey fwmode - Check if device is in firmware or app mode\n" "tkey getkey [verify-hash] - Get disk encryption key\n" " Loads app with USS, derives key. Same USS always produces same key.\n" @@ -289,7 +315,7 @@ U_BOOT_LONGHELP(tkey, U_BOOT_CMD_WITH_SUBCMDS(tkey, "Tillitis TKey security token operations", tkey_help_text, - U_BOOT_SUBCMD_MKENT(connect, 1, 1, do_tkey_connect), + U_BOOT_SUBCMD_MKENT(connect, 2, 1, do_tkey_connect), U_BOOT_SUBCMD_MKENT(fwmode, 1, 1, do_tkey_fwmode), U_BOOT_SUBCMD_MKENT(getkey, 3, 1, do_tkey_getkey), U_BOOT_SUBCMD_MKENT(info, 1, 1, do_tkey_info), diff --git a/doc/usage/cmd/tkey.rst b/doc/usage/cmd/tkey.rst index 6a9f37354eb..b7d138f7307 100644 --- a/doc/usage/cmd/tkey.rst +++ b/doc/usage/cmd/tkey.rst @@ -11,7 +11,7 @@ Synopsis :: - tkey connect + tkey connect [device-name] tkey fwmode tkey getkey [verify-hash] tkey info @@ -46,8 +46,19 @@ internal UDI to generate deterministic encryption keys. tkey connect ~~~~~~~~~~~~ -Test connectivity to a TKey device. This command attempts to find and connect -to the first available TKey device in the system. +Test connectivity to a TKey device and optionally select a specific device for +subsequent commands. + +When called without arguments, this command connects to the first available TKey +device in the system. When a device name is provided, it connects to that +specific device. + +Once connected, the selected device is remembered and will be used by all +subsequent tkey commands (info, getkey, loadapp, etc.) until a different device +is selected with another connect command. + +device-name + Optional name of a specific TKey device to connect to tkey fwmode @@ -160,11 +171,16 @@ password Example ------- -Connect to device:: +Connect to the first available device:: => tkey connect Connected to TKey device +Connect to a specific device by name:: + + => tkey connect tkey@0 + Connected to TKey device + Check device mode:: => tkey fwmode