]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
tpm: Separate out the TPM tests for v1 and v2
authorSimon Glass <sjg@chromium.org>
Tue, 21 Feb 2023 13:24:51 +0000 (06:24 -0700)
committerIlias Apalodimas <ilias.apalodimas@linaro.org>
Tue, 28 Feb 2023 07:44:30 +0000 (09:44 +0200)
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.

Acked-by: Ilias Apalodimas <ilias.apalodimas@linaro.org
Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
arch/sandbox/dts/test.dts
test/dm/tpm.c

index 05e09128a38681b7ab3f32b8975a8184014e81fa..d72d7a567a71e4332095f07b029df7f35bc3ba5b 100644 (file)
                compatible = "sandbox,tpm2";
        };
 
+       tpm {
+               compatible = "google,sandbox-tpm";
+       };
+
        uart0: serial {
                compatible = "sandbox,serial";
                bootph-all;
index 8ee17f6a9bc34950fd3fd3153527fa9cd5c61882..7d88001209061831c15684d6e2af26494ba1046f 100644 (file)
 #include <test/test.h>
 #include <test/ut.h>
 
-/* 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);