From patchwork Sat Nov 15 18:51:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 705 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=1763232803; bh=sJdBYYxDxIGDK5GhKZ6tIMox5uYAkMzwYEQ9chO7OTo=; 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=lq6LiAGITtG3Fd34K4EV+WLc88jeL/FpVqnZZUgRF1/RedWs2iQBdWJFc+Z5BInDy lwQBzTC2iAx8z07OaHwImVjNJs8n46XvaIj2olGlbdWrfDbTMDCVzI4m9xT2ZMvU8z cNdD8OA6ATuAIK8WLenfO4Vmc317CEMJcQ72wR9gNdaYixKITHApRAfu196qHztr83 6DoPoOKG+bJDi5x0vfWhutND45WOBZHmOtgr9yo47XZHCY6RaZixXBZOoHVVkBWgmP Rw1mrig1XICQaCzE9feu0fRIZqPhHFr0Z7A7+1ufCQdjaAQjaaKVjykgeUezxFmt1q PqzEe9CYe0fcQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 50B5B68625 for ; Sat, 15 Nov 2025 11:53:23 -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 dUb2uq-JxUcD for ; Sat, 15 Nov 2025 11:53:23 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1763232803; bh=sJdBYYxDxIGDK5GhKZ6tIMox5uYAkMzwYEQ9chO7OTo=; 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=lq6LiAGITtG3Fd34K4EV+WLc88jeL/FpVqnZZUgRF1/RedWs2iQBdWJFc+Z5BInDy lwQBzTC2iAx8z07OaHwImVjNJs8n46XvaIj2olGlbdWrfDbTMDCVzI4m9xT2ZMvU8z cNdD8OA6ATuAIK8WLenfO4Vmc317CEMJcQ72wR9gNdaYixKITHApRAfu196qHztr83 6DoPoOKG+bJDi5x0vfWhutND45WOBZHmOtgr9yo47XZHCY6RaZixXBZOoHVVkBWgmP Rw1mrig1XICQaCzE9feu0fRIZqPhHFr0Z7A7+1ufCQdjaAQjaaKVjykgeUezxFmt1q PqzEe9CYe0fcQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 3791F68521 for ; Sat, 15 Nov 2025 11:53:23 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1763232800; bh=XtFYueBk8XTn9839ampufd+dLA0XZeQgxmtggKlKSSE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kaFN+AGxjujvW0jUQfXamLPJYvNohf57PTqf+MM31t7VzXeS1wEzN+lmpCdXC07s9 YWJDd1otYCY4do/sODaneGb6SvCIGGc9iJ7E8pxgb2k1Haxz1lDqhTUhI19/cl36Wd hay3Ax61RGOIuDQchCb6GTI3k6G7+OTw2EO1+OmHjQblBjjgmk+fWGDYK+vD7u9QS8 U1nju7w211XM4IR6Ng6K+AMc9Q/jsCstt+4VYL9GR2fXDolArTWhpwAM7O0cQqjAF9 D0tB2h/aX1YL1Aj+tXwOgz2/kZr2kWdEe16OhFMCW7IkPcj/huiHjEpR/OuYbEppUX 5b8jSnIzs2bBw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 76B9F685E5; Sat, 15 Nov 2025 11:53:20 -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 wD2iAD3QAlkd; Sat, 15 Nov 2025 11:53:20 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1763232795; bh=TAEGNRddK5GsFvD07yCrRicpfL4Z4HKhO7yUy0R0xO4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=muMbJ4L8yK1LRzBxQHXyLtDkTcXrhJR8EhR5uqgfPiN/tmH6n6z18iXjacXP+W1+o bfOXbg6jl5YRzyTU/BgQAnl7CB6QT1D5a5P79hnsqVWUovQZ/IoMp9/6ZiART9/V6x 9SD0BwvKyKvC+AV/Q4gLRmwSE3K9iZEZ51MIJeEBtMQ06dKrf57cjEIYCQRwcKZwgr MUZ6dgq9nRN/IKXTdajna1h9Y51Wnlu5+dLU4FjEZW6fE5aGgQGMfcte5x1OaqcZt4 vMhy3rU/CYVBwTQldi20KCzOSTNq9M0yL42ZTzQH4ZP56F1N/5nU5GhUCYUQC5gPxf LFeqfOXQa96ZQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 863686861A; Sat, 15 Nov 2025 11:53:15 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 15 Nov 2025 11:51:56 -0700 Message-ID: <20251115185212.539268-8-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: SPIHHVGXXDBRKTUAATN2JMAFOSTRJGTK X-Message-ID-Hash: SPIHHVGXXDBRKTUAATN2JMAFOSTRJGTK 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 07/16] tkey: Allow modelling the tkey being disconnected 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 Provide some plat data which tracks whether the emulated tkey is connected or not, to allow testing of re-inserting a tkey to reset the passphrase. Signed-off-by: Simon Glass --- drivers/misc/tkey_emul.c | 41 +++++++++++++++++++++++++++++++++++++++- include/tkey.h | 13 +++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/drivers/misc/tkey_emul.c b/drivers/misc/tkey_emul.c index d8d81280486..5f7a4aa2f09 100644 --- a/drivers/misc/tkey_emul.c +++ b/drivers/misc/tkey_emul.c @@ -45,6 +45,15 @@ #define STATUS_OK 0x00 #define STATUS_ERROR 0x01 +/* + * struct tkey_emul_plat - TKey emulator platform data (persists across remove) + * + * @disconnected: Whether device is disconnected (for testing removal) + */ +struct tkey_emul_plat { + bool disconnected; +}; + /* * struct tkey_emul_priv - TKey emulator state * @@ -200,10 +209,15 @@ static int handle_app_cmd(struct udevice *dev, u8 cmd) static int tkey_emul_write(struct udevice *dev, const void *buf, int len) { + struct tkey_emul_plat *plat = dev_get_plat(dev); const u8 *data = buf; u8 header, endpoint, cmd; int ret; + /* Simulate device disconnection */ + if (plat->disconnected) + return -EIO; + if (len < 2) return -EINVAL; @@ -229,8 +243,15 @@ static int tkey_emul_write(struct udevice *dev, const void *buf, int len) static int tkey_emul_read_all(struct udevice *dev, void *buf, int maxlen, int timeout_ms) { + struct tkey_emul_plat *plat = dev_get_plat(dev); struct tkey_emul_priv *priv = dev_get_priv(dev); - int len = min(priv->resp_len, maxlen); + int len; + + /* Simulate device disconnection */ + if (plat->disconnected) + return -EIO; + + len = min(priv->resp_len, maxlen); log_debug("read_all: %d bytes max, returning %d bytes\n", maxlen, len); @@ -241,11 +262,28 @@ static int tkey_emul_read_all(struct udevice *dev, void *buf, int maxlen, return len; } +int tkey_emul_set_connected_for_test(struct udevice *dev, bool connected) +{ + struct tkey_emul_plat *plat = dev_get_plat(dev); + + plat->disconnected = !connected; + log_debug("Set emulator %s\n", connected ? "connected" : "disconnected"); + + return 0; +} + static int tkey_emul_probe(struct udevice *dev) { + struct tkey_emul_plat *plat = dev_get_plat(dev); struct tkey_emul_priv *priv = dev_get_priv(dev); int i; + /* Fail probe if device is disconnected */ + if (plat->disconnected) { + log_debug("probe failed - device disconnected\n"); + return -ENODEV; + } + /* Generate a deterministic UDI based on device name */ for (i = 0; i < 8; i++) priv->udi[i] = 0xa0 + i; @@ -281,4 +319,5 @@ U_BOOT_DRIVER(tkey_emul) = { .probe = tkey_emul_probe, .ops = &tkey_emul_ops, .priv_auto = sizeof(struct tkey_emul_priv), + .plat_auto = sizeof(struct tkey_emul_plat), }; diff --git a/include/tkey.h b/include/tkey.h index a16447795b1..14ad3ebc9e9 100644 --- a/include/tkey.h +++ b/include/tkey.h @@ -229,4 +229,17 @@ int tkey_derive_disk_key(struct udevice *dev, const void *app_data, int tkey_derive_wrapping_key(struct udevice *dev, const char *password, void *wrapping_key); +/** + * tkey_emul_set_connected_for_test() - Simulate device connection state + * + * This is a back-door function for tests to simulate physical insertion or + * removal of the TKey device. When disconnected, all I/O operations and + * probe attempts will fail. + * + * @dev: TKey device (must be tkey-emul) + * @connected: true to simulate device present, false to simulate removal + * Return: 0 on success, -ve error on failure + */ +int tkey_emul_set_connected_for_test(struct udevice *dev, bool connected); + #endif /* _TKEY_UCLASS_H */