From patchwork Tue May 30 06:18:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 686863 Delivered-To: patch@linaro.org Received: by 2002:a5d:4d8a:0:0:0:0:0 with SMTP id b10csp568617wru; Mon, 29 May 2023 23:19:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ73qS/YzUd9Z2difg6CC7ZllEA438mHdCOTTY8hsFEVEO6HjWNiYXS3LQNSOc5/9a7MUIaN X-Received: by 2002:a17:902:d4c8:b0:1af:c0cb:ddd8 with SMTP id o8-20020a170902d4c800b001afc0cbddd8mr1634295plg.56.1685427544403; Mon, 29 May 2023 23:19:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685427544; cv=none; d=google.com; s=arc-20160816; b=vbjEotINAb8mwFHByYfrqsVVU0JdadkPbOklMGTl5EIuseCzlB76vcJW+Jkc5dWcf+ uojABrg3haEH3cndoDKpOLVtpCc+avE+zLSbWJEeVPgtBU5Ft7qzjiNjiDiaNWL40qdE yOfKeyykBRmPNinfsH9n8K1G2yTXV94ufRVwidLse3FQiBdYYUxeIrOC30iMDPffMF3g jbwdJazrjyZwHMwX/de1G/zpn5T/u167HkF2uqVFZI2eXGG3j4nJfaQoxmieHXeSXCBp /51GH8tWeYPvoyIwRbPOsPnxZ7aYOaUiTisLVWJ5EQzSv0EYs7/1aCGWUmExIx4tAPGX gyzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=UIkMOX3M2yfgKEutf5yTXg1hgc/xnOBUZzIou/aw1xg=; b=s4Y9WZ/bvZNvnAINv1oMBLPgNZqJ9q6izx7xZGHk2DnzGFb6hiBblU/qcLUntIJZmc SqoAeFDWO0TlaFMg+HS2eJFAqTsva7RgfRkctQ6C+3plMDFq2Vo+L/qRDxehaww6Tb6g hIMuO4oopi6eDFclIhYN4hBnKNLvwE+hM5eh1f4V+IF4TeLm/EWPFd3eeiCAxoYxmfTa Rkpsi0uUDnyAg9U74j2lS6a3wsaFAV9B32X64tsM8GtTvGIwALWydwo7YT7ekhOWEUfN m/c5tNfceGVoUtY68Q6Y8tgGbw5U2HOZTRcIP+BoFXS5QTvOgXJt5+mFPZ9E8zOxZVwr hP8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SvbGqCbQ; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id bi12-20020a170902bf0c00b001a81741ef8dsi10575610plb.54.2023.05.29.23.19.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 May 2023 23:19:04 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SvbGqCbQ; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 21A1E85A85; Tue, 30 May 2023 08:18:58 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="SvbGqCbQ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B898F85A85; Tue, 30 May 2023 08:18:56 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,LOTS_OF_MONEY,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 7540D85727 for ; Tue, 30 May 2023 08:18:53 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-3f6d3f83d0cso42633185e9.2 for ; Mon, 29 May 2023 23:18:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1685427533; x=1688019533; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=UIkMOX3M2yfgKEutf5yTXg1hgc/xnOBUZzIou/aw1xg=; b=SvbGqCbQ+I38mt0PjB6jAR+WLmZDcWmw1oROSuSUB/sfTjDQeSlDdKZBDw+o8TYWHA yfeG1HFH/nwjvnn6i8U8XaITRaQU62T7LW8lwshKVIUUcR4h+XeNxhu5nIJp7fIti5QU TCOOuuuiLdsg8hQwO/YGv2DdTaJ5hMwL1WGMQgI7UZRzD1R7LRPcS3qgW+T2OCp3bPm4 khbH2wOmNgHibxVwuZR6Z13mWAAxTlFDQcPhLlFtK9xhAAq8rY6XEtSyn1+/JZ3VBN6E 8SeS9vDGN9Wc1+Tq9tZJCx/6BRZQZHHP4tYRRKTX/xLki1KmDAfWoI34TW7NF1CJD8+h RhIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685427533; x=1688019533; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=UIkMOX3M2yfgKEutf5yTXg1hgc/xnOBUZzIou/aw1xg=; b=LQfDKzGR0Sd3AA9jSp17eUEE0rGHR95dPPvjNH8+G91G0KHXMFlITw898wyH/ZC7Ak tA+b3e7J7+ScVN6z6uzsPXOrm2RzVGY8R6pFe/dhdsTgcTslGDc9KQmpmP68xaa3lghn gopg7xBoi/hbBbbH/LxzzGC/hsrdR3EOImFoyPArR8MYUmZMRXoxry0pgRg3rSlsudGE DO44M8uuVM0UR4PGCmKRKcmMrPSlvv/DpyoESWshEIdQY58REHSfZ95l0yOHpgeTDgWr hqSPB+8FYlPL4G9zfH9tG5jKOzmyHpAigMbCwtG+L88Ot7RVHmXXMM004PjVc4hrl+4x JFYw== X-Gm-Message-State: AC+VfDzp2ev4HzVfodMPrV8HmKaye8NIVRWjBMDiTZIYwvnCj6dn/Xnr tjk9aleZygJ1IpriN1Mm2/GZLA== X-Received: by 2002:a5d:654c:0:b0:307:8651:258e with SMTP id z12-20020a5d654c000000b003078651258emr624317wrv.21.1685427532767; Mon, 29 May 2023 23:18:52 -0700 (PDT) Received: from localhost.localdomain (ppp089210114029.access.hol.gr. [89.210.114.29]) by smtp.gmail.com with ESMTPSA id bf3-20020a0560001cc300b00307b5376b2csm2029575wrb.90.2023.05.29.23.18.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 May 2023 23:18:52 -0700 (PDT) From: Ilias Apalodimas To: sjg@chromium.org Cc: marex@denx.de, heinrich.schuchardt@canonical.com, trini@konsulko.com, Ilias Apalodimas , u-boot@lists.denx.de Subject: [PATCH] tpm: Make 'tpm init' to call tpm_auto_start() Date: Tue, 30 May 2023 09:18:43 +0300 Message-Id: <20230530061843.248629-1-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean For a TPM device to be operational we need to initialize it and perform its startup sequence. The 'tpm init' command currently calls tpm_init() which ends up calling the ->open() per-device callback and performs the initial hardware configuration as well as requesting locality 0 for the caller. There no code that currently calls tpm_init() without following up with a tpm_startup() and tpm_self_test_full() or tpm_continue_self_test(). So let's wire up the 'tpm init' command and call tpm_auto_start() which leaves the device in an operational state and adjust any defconfigs using 'tpm init'. It's worth noting that calling tpm_init() only, doesn't allow a someone to use the TPM since the startup sequence is mandatory. We always repeat the pattern of calling - tpm_init() - tpm_startup() - tpm_self_test_full() or tpm_continue_self_test() as a result we don't expect any regression or boot delays with the current change. While at it fix the identation of test_tpm_autostart() comments as well. Signed-off-by: Ilias Apalodimas --- This is a split and resend of https://lore.kernel.org/u-boot/20230510074359.2837818-9-ilias.apalodimas@linaro.org/ Since Simon some had concerns I decided to split this off the series and send it as a single patch for further discussion. cmd/tpm-common.c | 3 ++- configs/chromebook_coral_defconfig | 2 +- test/dm/tpm.c | 9 +++++---- test/py/tests/test_tpm2.py | 9 --------- 4 files changed, 8 insertions(+), 15 deletions(-) -- 2.39.2 diff --git a/cmd/tpm-common.c b/cmd/tpm-common.c index d0c63cadf413..9b1ad0b371df 100644 --- a/cmd/tpm-common.c +++ b/cmd/tpm-common.c @@ -11,6 +11,7 @@ #include #include #include +#include #include "tpm-user-utils.h" static struct udevice *tpm_dev; @@ -364,7 +365,7 @@ int do_tpm_init(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) if (rc) return rc; - return report_return_code(tpm_init(dev)); + return report_return_code(tpm_auto_start(dev)); } int do_tpm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) diff --git a/configs/chromebook_coral_defconfig b/configs/chromebook_coral_defconfig index f5995f22004e..8b4c1228a1fc 100644 --- a/configs/chromebook_coral_defconfig +++ b/configs/chromebook_coral_defconfig @@ -33,7 +33,7 @@ CONFIG_BOOTSTAGE_STASH=y CONFIG_USE_BOOTARGS=y CONFIG_BOOTARGS_SUBST=y CONFIG_USE_BOOTCOMMAND=y -CONFIG_BOOTCOMMAND="tpm init; tpm startup TPM2_SU_CLEAR; read mmc 0:2 100000 0 80; setexpr loader *001004f0; setexpr size *00100518; setexpr blocks $size / 200; read mmc 0:2 100000 80 $blocks; setexpr setup $loader - 1000; setexpr cmdline_ptr $loader - 2000; setexpr.s cmdline *$cmdline_ptr; setexpr cmdline gsub %U \\\\${uuid}; if part uuid mmc 0:2 uuid; then zboot start 100000 0 0 0 $setup cmdline; zboot load; zboot setup; zboot dump; zboot go;fi" +CONFIG_BOOTCOMMAND="tpm init; read mmc 0:2 100000 0 80; setexpr loader *001004f0; setexpr size *00100518; setexpr blocks $size / 200; read mmc 0:2 100000 80 $blocks; setexpr setup $loader - 1000; setexpr cmdline_ptr $loader - 2000; setexpr.s cmdline *$cmdline_ptr; setexpr cmdline gsub %U \\\\${uuid}; if part uuid mmc 0:2 uuid; then zboot start 100000 0 0 0 $setup cmdline; zboot load; zboot setup; zboot dump; zboot go;fi" CONFIG_SYS_CONSOLE_INFO_QUIET=y CONFIG_DISPLAY_BOARDINFO_LATE=y CONFIG_LAST_STAGE_INIT=y diff --git a/test/dm/tpm.c b/test/dm/tpm.c index 3defb3c3da1f..cde933ab2848 100644 --- a/test/dm/tpm.c +++ b/test/dm/tpm.c @@ -98,10 +98,11 @@ static int test_tpm_autostart(struct unit_test_state *uts, if (reinit) ut_assertok(tpm_init(dev)); - /* - * tpm_auto_start will rerun tpm_init() if reinit, but handles the - * -EBUSY return code internally. - */ + + /* + * tpm_auto_start will rerun tpm_init() if reinit, but handles the + * -EBUSY return code internally. + */ ut_assertok(tpm_auto_start(dev)); return 0; diff --git a/test/py/tests/test_tpm2.py b/test/py/tests/test_tpm2.py index d2ad6f9e73c0..6f9b1dd89258 100644 --- a/test/py/tests/test_tpm2.py +++ b/test/py/tests/test_tpm2.py @@ -44,8 +44,6 @@ def force_init(u_boot_console, force=False): output = u_boot_console.run_command('tpm2 init') if force or not 'Error' in output: u_boot_console.run_command('echo --- start of init ---') - u_boot_console.run_command('tpm2 startup TPM2_SU_CLEAR') - u_boot_console.run_command('tpm2 self_test full') u_boot_console.run_command('tpm2 clear TPM2_RH_LOCKOUT') output = u_boot_console.run_command('echo $?') if not output.endswith('0'): @@ -90,13 +88,6 @@ def tpm2_sandbox_init(u_boot_console): skip_test = u_boot_console.config.env.get('env__tpm_device_test_skip', False) if skip_test: pytest.skip('skip TPM device test') - u_boot_console.run_command('tpm2 startup TPM2_SU_CLEAR') - output = u_boot_console.run_command('echo $?') - assert output.endswith('0') - - u_boot_console.run_command('tpm2 self_test full') - output = u_boot_console.run_command('echo $?') - assert output.endswith('0') @pytest.mark.buildconfigspec('cmd_tpm_v2') def test_tpm2_sandbox_self_test_full(u_boot_console):