From patchwork Mon Feb 20 21:27:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1745303 X-Patchwork-Delegate: apalos@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=cMZ72ab3; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PLFrb4jKZz23yZ for ; Tue, 21 Feb 2023 08:27:57 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A4D2685910; Mon, 20 Feb 2023 22:27:46 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="cMZ72ab3"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 33C8E85935; Mon, 20 Feb 2023 22:27:45 +0100 (CET) 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,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x129.google.com (mail-il1-x129.google.com [IPv6:2607:f8b0:4864:20::129]) (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 2C7A2858ED for ; Mon, 20 Feb 2023 22:27:42 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-il1-x129.google.com with SMTP id e10so828709ilu.4 for ; Mon, 20 Feb 2023 13:27:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=PXJ4IHXs+1f+TlrrIT67FPy9JXsiFgl3v7F56TIq/jc=; b=cMZ72ab3CDeGgUSYG9iWz9b+mkNAyx10fDn6EoalgeBy4nEqA6DqrfsNzYQaM1ooVn 0rOhQ+XlXhYozMlgFSmfhP05uz9Ux3j0uWwkyv7N1DueqA3KtwPzC63lYIM8M8NTIv+/ BVGRs0TiqAzRgxjB/jzdOtiXyeYR78rxI+DDY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=PXJ4IHXs+1f+TlrrIT67FPy9JXsiFgl3v7F56TIq/jc=; b=IlHYj6yXQvQW5X8md8qPOiTSLlW7B4sdqIEIV6yKxjtY8Kq5jIudITSXT6omfbetSI K16t/jchgwZP4/GbIGPFFlYIKCDTUhd+T+zbURYvupKTD4pSdiuQHZDFx3Do0CfIRGkn AdZCv+1phCfL8GBz9kreKCJsseYlqAO+aA67S2Y0oCi1VaIH3TrjI8F926oa/dxMAcEH VpFqDy1hjKrNsZFIc8EV+GHNF7A4wKspeQLUG4uq1Su5B0UA9qzeAuEjjuO4NTS+mjJJ uP6OGakYVcsN1bX9o0/ljo1hdz0v/1b362ZRU8PqnvGqUNOTl5AVv5Ysjj9a/y/3Zybt j4hw== X-Gm-Message-State: AO0yUKVUvsDHs1kaDASm1SumT7n+MQUkVxQnIngBPYTSjS58EnhtlK/9 xPWz26OABuR0vzUpLbUqhPc9ESn+1fgowzbw X-Google-Smtp-Source: AK7set9+is62G24yX4o7hrk/SZfMdfPjzNRkdvlfQzpMFBTHwQX0BAW9UmBlc8+NXXhGr5DaXOHvTw== X-Received: by 2002:a92:cc0c:0:b0:315:80bc:2c5d with SMTP id s12-20020a92cc0c000000b0031580bc2c5dmr2699287ilp.22.1676928460471; Mon, 20 Feb 2023 13:27:40 -0800 (PST) Received: from kea.bld.corp.google.com ([2620:15c:183:200:9f65:93e2:a4c7:ed10]) by smtp.gmail.com with ESMTPSA id u17-20020a056e02081100b00313b2148c5csm218817ilm.71.2023.02.20.13.27.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 13:27:40 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Ilias Apalodimas , Simon Glass , Andrew Scull , Dzmitry Sankouski , Etienne Carriere , =?utf-8?q?Marek_Beh=C3=BAn?= , Nikhil M Jain , Ramon Fried , Sean Anderson Subject: [PATCH 1/2] tpm: Separate out the TPM tests for v1 and v2 Date: Mon, 20 Feb 2023 14:27:35 -0700 Message-Id: <20230220212736.885114-1-sjg@chromium.org> X-Mailer: git-send-email 2.39.2.637.g21b0678d19-goog 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.6 at phobos.denx.de X-Virus-Status: Clean Currently there is only one test and it only works on TPM v2. Update it to work on v1.2 as well, using a new function to pick up the required TPM. Update sandbox to include both a v1.2 and v2 TPM so that this works. Split out the existing test into two pieces, one for init and one for the v2-only report_state feature. Signed-off-by: Simon Glass Acked-by: Ilias Apalodimas --- arch/sandbox/dts/test.dts | 4 +++ test/dm/tpm.c | 60 +++++++++++++++++++++++++++++++++------ 2 files changed, 55 insertions(+), 9 deletions(-) diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index 05e09128a38..d72d7a567a7 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -1367,6 +1367,10 @@ compatible = "sandbox,tpm2"; }; + tpm { + compatible = "google,sandbox-tpm"; + }; + uart0: serial { compatible = "sandbox,serial"; bootph-all; diff --git a/test/dm/tpm.c b/test/dm/tpm.c index dca540bb561..7d880012090 100644 --- a/test/dm/tpm.c +++ b/test/dm/tpm.c @@ -11,24 +11,66 @@ #include #include -/* Basic test of the TPM uclass */ +/* + * get_tpm_version() - Get a TPM of the given version + * + * @version: Version to get + * @devp: Returns the TPM device + * Returns: 0 if OK, -ENODEV if not found + */ +static int get_tpm_version(enum tpm_version version, struct udevice **devp) +{ + struct udevice *dev; + + /* + * For now we have to probe each TPM, since the version is set up in + * of_to_plat(). We could require TPMs to declare their version when + * probed, to avoid this + */ + uclass_foreach_dev_probe(UCLASS_TPM, dev) { + if (tpm_get_version(dev) == version) { + *devp = dev; + return 0; + } + } + + return -ENODEV; +} + +/* Basic test of initing a TPM */ +static int test_tpm_init(struct unit_test_state *uts, enum tpm_version version) +{ + struct udevice *dev; + + /* check probe success */ + ut_assertok(get_tpm_version(version, &dev)); + + ut_assertok(tpm_init(dev)); + + return 0; +} + static int dm_test_tpm(struct unit_test_state *uts) +{ + ut_assertok(test_tpm_init(uts, TPM_V1)); + ut_assertok(test_tpm_init(uts, TPM_V2)); + + return 0; +} +DM_TEST(dm_test_tpm, UT_TESTF_SCAN_FDT); + +/* Test report_state */ +static int dm_test_tpm_report_state(struct unit_test_state *uts) { struct udevice *dev; char buf[50]; /* check probe success */ - ut_assertok(uclass_first_device_err(UCLASS_TPM, &dev)); - ut_assert(tpm_is_v2(dev)); + ut_assertok(get_tpm_version(TPM_V2, &dev)); ut_assert(tpm_report_state(dev, buf, sizeof(buf))); ut_asserteq_str("init_done=0", buf); - ut_assertok(tpm_init(dev)); - /* - * tpm_auto_start will rerun tpm_init, but handles the - * -EBUSY return code internally. - */ ut_assertok(tpm_auto_start(dev)); ut_assert(tpm_report_state(dev, buf, sizeof(buf))); @@ -36,4 +78,4 @@ static int dm_test_tpm(struct unit_test_state *uts) return 0; } -DM_TEST(dm_test_tpm, UT_TESTF_SCAN_FDT); +DM_TEST(dm_test_tpm_report_state, UT_TESTF_SCAN_FDT);