summaryrefslogtreecommitdiff
path: root/test/dm
diff options
context:
space:
mode:
Diffstat (limited to 'test/dm')
-rw-r--r--test/dm/Makefile1
-rw-r--r--test/dm/aes.c57
-rw-r--r--test/dm/blkmap.c1
-rw-r--r--test/dm/button.c1
-rw-r--r--test/dm/clk_ccf.c30
-rw-r--r--test/dm/dsa.c1
-rw-r--r--test/dm/fastboot.c1
-rw-r--r--test/dm/part.c1
-rw-r--r--test/dm/tpm.c77
9 files changed, 153 insertions, 17 deletions
diff --git a/test/dm/Makefile b/test/dm/Makefile
index 917dafe7d22..d15859eca30 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -29,6 +29,7 @@ obj-(CONFIG_DM_GPIO) += gpio.o
obj-y += irq.o
endif
obj-$(CONFIG_ADC) += adc.o
+obj-$(CONFIG_AES_SOFTWARE) += aes.o
obj-$(CONFIG_SOUND) += audio.o
obj-$(CONFIG_AXI) += axi.o
obj-$(CONFIG_BLK) += blk.o
diff --git a/test/dm/aes.c b/test/dm/aes.c
new file mode 100644
index 00000000000..702e4db2b35
--- /dev/null
+++ b/test/dm/aes.c
@@ -0,0 +1,57 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Tests for the driver model AES API
+ *
+ * Copyright (c) 2025 Svyatoslav Ryhel <clamor95@gmail.com>
+ */
+
+#include <dm.h>
+#include <dm/test.h>
+#include <uboot_aes.h>
+#include <test/test.h>
+#include <test/ut.h>
+
+#define AES128_KEYSIZE 128
+
+static int dm_test_aes(struct unit_test_state *uts)
+{
+ struct udevice *dev;
+ u8 test_key[AES128_KEY_LENGTH] = { 0x63, 0x68, 0x69, 0x63, 0x6b, 0x65, 0x6e, 0x20,
+ 0x74, 0x65, 0x72, 0x69, 0x79, 0x61, 0x6b, 0x69 };
+ u8 test_iv[AES128_KEY_LENGTH] = { 0 };
+
+ u8 test_input[AES_BLOCK_LENGTH] = { 0x49, 0x20, 0x77, 0x6f, 0x75, 0x6c, 0x64, 0x20,
+ 0x6c, 0x69, 0x6b, 0x65, 0x20, 0x74, 0x68, 0x65 };
+ u8 exp_output[AES_BLOCK_LENGTH] = { 0x97, 0x68, 0x72, 0x68, 0xd6, 0xec, 0xcc, 0xc0,
+ 0xc0, 0x7b, 0x25, 0xe2, 0x5e, 0xcf, 0xe5, 0x84 };
+ u8 exp_cmac[AES_BLOCK_LENGTH] = { 0xfc, 0x89, 0x20, 0xc8, 0x46, 0x97, 0xb1, 0x3d,
+ 0x31, 0x2c, 0xc2, 0x49, 0x5c, 0x5a, 0x0b, 0x9f };
+ u8 test_output[AES_BLOCK_LENGTH];
+
+ ut_assertok(uclass_first_device_err(UCLASS_AES, &dev));
+
+ /* software AES exposes 2 key slots */
+ ut_asserteq(2, dm_aes_get_available_key_slots(dev));
+
+ ut_assertok(dm_aes_select_key_slot(dev, AES128_KEYSIZE, 0));
+ ut_assertok(dm_aes_set_key_for_key_slot(dev, AES128_KEYSIZE, test_key, 0));
+
+ ut_assertok(dm_aes_ecb_encrypt(dev, test_input, test_output, 1));
+ ut_assertok(memcmp(exp_output, test_output, 16));
+
+ ut_assertok(dm_aes_ecb_decrypt(dev, test_output, test_output, 1));
+ ut_assertok(memcmp(test_input, test_output, 16));
+
+ ut_assertok(dm_aes_cbc_encrypt(dev, test_iv, test_input, test_output, 1));
+ ut_assertok(memcmp(exp_output, test_output, 16));
+
+ ut_assertok(dm_aes_cbc_decrypt(dev, test_iv, test_output, test_output, 1));
+ ut_assertok(memcmp(test_input, test_output, 16));
+
+ ut_assertok(dm_aes_cmac(dev, test_input, test_output, 1));
+ ut_assertok(memcmp(exp_cmac, test_output, 16));
+
+ return 0;
+}
+
+DM_TEST(dm_test_aes, UTF_SCAN_FDT);
diff --git a/test/dm/blkmap.c b/test/dm/blkmap.c
index a6a0b4d4e20..d04b68b50ae 100644
--- a/test/dm/blkmap.c
+++ b/test/dm/blkmap.c
@@ -7,6 +7,7 @@
#include <blk.h>
#include <blkmap.h>
#include <dm.h>
+#include <env.h>
#include <asm/test.h>
#include <dm/test.h>
#include <test/test.h>
diff --git a/test/dm/button.c b/test/dm/button.c
index 3612f308f02..f05f4ca27ce 100644
--- a/test/dm/button.c
+++ b/test/dm/button.c
@@ -8,6 +8,7 @@
#include <dm.h>
#include <adc.h>
#include <button.h>
+#include <env.h>
#include <power/regulator.h>
#include <power/sandbox_pmic.h>
#include <asm/gpio.h>
diff --git a/test/dm/clk_ccf.c b/test/dm/clk_ccf.c
index ac56f17b775..64c21b10c3e 100644
--- a/test/dm/clk_ccf.c
+++ b/test/dm/clk_ccf.c
@@ -32,13 +32,13 @@ static int dm_test_clk_ccf(struct unit_test_state *uts)
ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "clk-test", &test_dev));
/* Test for clk_get_by_id() */
- ret = clk_get_by_id(SANDBOX_CLK_ECSPI_ROOT, &clk);
+ ret = clk_get_by_id(CLK_ID(dev, SANDBOX_CLK_ECSPI_ROOT), &clk);
ut_assertok(ret);
ut_asserteq_str("ecspi_root", clk->dev->name);
ut_asserteq(CLK_SET_RATE_PARENT, clk->flags);
/* Test for clk_get_parent_rate() */
- ret = clk_get_by_id(SANDBOX_CLK_ECSPI1, &clk);
+ ret = clk_get_by_id(CLK_ID(dev, SANDBOX_CLK_ECSPI1), &clk);
ut_assertok(ret);
ut_asserteq_str("ecspi1", clk->dev->name);
ut_asserteq(CLK_SET_RATE_PARENT, clk->flags);
@@ -47,7 +47,7 @@ static int dm_test_clk_ccf(struct unit_test_state *uts)
ut_asserteq(rate, 20000000);
/* test the gate of CCF */
- ret = clk_get_by_id(SANDBOX_CLK_ECSPI0, &clk);
+ ret = clk_get_by_id(CLK_ID(dev, SANDBOX_CLK_ECSPI0), &clk);
ut_assertok(ret);
ut_asserteq_str("ecspi0", clk->dev->name);
ut_asserteq(CLK_SET_RATE_PARENT, clk->flags);
@@ -56,7 +56,7 @@ static int dm_test_clk_ccf(struct unit_test_state *uts)
ut_asserteq(rate, 20000000);
/* Test the mux of CCF */
- ret = clk_get_by_id(SANDBOX_CLK_USDHC1_SEL, &clk);
+ ret = clk_get_by_id(CLK_ID(dev, SANDBOX_CLK_USDHC1_SEL), &clk);
ut_assertok(ret);
ut_asserteq_str("usdhc1_sel", clk->dev->name);
ut_asserteq(CLK_SET_RATE_NO_REPARENT, clk->flags);
@@ -70,7 +70,7 @@ static int dm_test_clk_ccf(struct unit_test_state *uts)
rate = clk_get_rate(clk);
ut_asserteq(rate, 60000000);
- ret = clk_get_by_id(SANDBOX_CLK_PLL3_80M, &pclk);
+ ret = clk_get_by_id(CLK_ID(dev, SANDBOX_CLK_PLL3_80M), &pclk);
ut_assertok(ret);
ret = clk_set_parent(clk, pclk);
@@ -79,7 +79,7 @@ static int dm_test_clk_ccf(struct unit_test_state *uts)
rate = clk_get_rate(clk);
ut_asserteq(rate, 80000000);
- ret = clk_get_by_id(SANDBOX_CLK_USDHC2_SEL, &clk);
+ ret = clk_get_by_id(CLK_ID(dev, SANDBOX_CLK_USDHC2_SEL), &clk);
ut_assertok(ret);
ut_asserteq_str("usdhc2_sel", clk->dev->name);
ut_asserteq(CLK_SET_RATE_NO_REPARENT, clk->flags);
@@ -97,7 +97,7 @@ static int dm_test_clk_ccf(struct unit_test_state *uts)
rate = clk_get_rate(clk);
ut_asserteq(rate, 80000000);
- ret = clk_get_by_id(SANDBOX_CLK_PLL3_60M, &pclk);
+ ret = clk_get_by_id(CLK_ID(dev, SANDBOX_CLK_PLL3_60M), &pclk);
ut_assertok(ret);
ret = clk_set_parent(clk, pclk);
@@ -107,7 +107,7 @@ static int dm_test_clk_ccf(struct unit_test_state *uts)
ut_asserteq(rate, 60000000);
/* Test the composite of CCF */
- ret = clk_get_by_id(SANDBOX_CLK_I2C, &clk);
+ ret = clk_get_by_id(CLK_ID(dev, SANDBOX_CLK_I2C), &clk);
ut_assertok(ret);
ut_asserteq_str("i2c", clk->dev->name);
ut_asserteq(CLK_SET_RATE_UNGATE, clk->flags);
@@ -124,12 +124,12 @@ static int dm_test_clk_ccf(struct unit_test_state *uts)
ret = clk_get_by_index(test_dev, SANDBOX_CLK_TEST_ID_I2C_ROOT, &clk_ccf);
ut_assertok(ret);
ut_asserteq_str("clk-ccf", clk_ccf.dev->name);
- ut_asserteq(clk_ccf.id, SANDBOX_CLK_I2C_ROOT);
+ ut_asserteq(clk_ccf.id, CLK_ID(clk_ccf.dev, SANDBOX_CLK_I2C_ROOT));
- ret = clk_get_by_id(SANDBOX_CLK_I2C_ROOT, &clk);
+ ret = clk_get_by_id(CLK_ID(dev, SANDBOX_CLK_I2C_ROOT), &clk);
ut_assertok(ret);
ut_asserteq_str("i2c_root", clk->dev->name);
- ut_asserteq(clk->id, SANDBOX_CLK_I2C_ROOT);
+ ut_asserteq(clk_get_id(clk), SANDBOX_CLK_I2C_ROOT);
ret = clk_enable(&clk_ccf);
ut_assertok(ret);
@@ -137,7 +137,7 @@ static int dm_test_clk_ccf(struct unit_test_state *uts)
ret = sandbox_clk_enable_count(clk);
ut_asserteq(ret, 1);
- ret = clk_get_by_id(SANDBOX_CLK_I2C, &pclk);
+ ret = clk_get_by_id(CLK_ID(dev, SANDBOX_CLK_I2C), &pclk);
ut_assertok(ret);
ret = sandbox_clk_enable_count(pclk);
@@ -153,7 +153,7 @@ static int dm_test_clk_ccf(struct unit_test_state *uts)
ut_asserteq(ret, 0);
/* Test clock re-parenting. */
- ret = clk_get_by_id(SANDBOX_CLK_USDHC1_SEL, &clk);
+ ret = clk_get_by_id(CLK_ID(dev, SANDBOX_CLK_USDHC1_SEL), &clk);
ut_assertok(ret);
ut_asserteq_str("usdhc1_sel", clk->dev->name);
@@ -167,7 +167,7 @@ static int dm_test_clk_ccf(struct unit_test_state *uts)
clkid = SANDBOX_CLK_PLL3_60M;
}
- ret = clk_get_by_id(clkid, &pclk);
+ ret = clk_get_by_id(CLK_ID(dev, clkid), &pclk);
ut_assertok(ret);
ret = clk_set_parent(clk, pclk);
ut_assertok(ret);
@@ -176,7 +176,7 @@ static int dm_test_clk_ccf(struct unit_test_state *uts)
ut_asserteq_str(clkname, pclk->dev->name);
/* Test disabling critical clock. */
- ret = clk_get_by_id(SANDBOX_CLK_I2C_ROOT, &clk);
+ ret = clk_get_by_id(CLK_ID(dev, SANDBOX_CLK_I2C_ROOT), &clk);
ut_assertok(ret);
ut_asserteq_str("i2c_root", clk->dev->name);
diff --git a/test/dm/dsa.c b/test/dm/dsa.c
index 9a31ae39d95..46e48741fba 100644
--- a/test/dm/dsa.c
+++ b/test/dm/dsa.c
@@ -3,6 +3,7 @@
* Copyright 2020-2021 NXP
*/
+#include <env.h>
#include <net/dsa.h>
#include <dm/test.h>
#include <test/ut.h>
diff --git a/test/dm/fastboot.c b/test/dm/fastboot.c
index 73c43f82924..5b51b6bf9dd 100644
--- a/test/dm/fastboot.c
+++ b/test/dm/fastboot.c
@@ -4,6 +4,7 @@
*/
#include <dm.h>
+#include <env.h>
#include <fastboot.h>
#include <fb_mmc.h>
#include <mmc.h>
diff --git a/test/dm/part.c b/test/dm/part.c
index c5c4b3fdba1..caae23bd4aa 100644
--- a/test/dm/part.c
+++ b/test/dm/part.c
@@ -4,6 +4,7 @@
*/
#include <dm.h>
+#include <env.h>
#include <mmc.h>
#include <part.h>
#include <part_efi.h>
diff --git a/test/dm/tpm.c b/test/dm/tpm.c
index 962a3fd1943..87c5c416daa 100644
--- a/test/dm/tpm.c
+++ b/test/dm/tpm.c
@@ -49,14 +49,87 @@ static int test_tpm_init(struct unit_test_state *uts, enum tpm_version version)
return 0;
}
-static int dm_test_tpm(struct unit_test_state *uts)
+static int dm_test_tpm_init(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, UTF_SCAN_FDT);
+DM_TEST(dm_test_tpm_init, UTF_SCAN_FDT);
+
+/* check TPM startup */
+static int check_tpm_startup(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));
+ ut_assertok(tpm_startup(dev, TPM_ST_CLEAR));
+
+ return 0;
+}
+
+/* test TPM startup */
+static int dm_test_tpm_startup(struct unit_test_state *uts)
+{
+ ut_assertok(check_tpm_startup(uts, TPM_V1));
+ ut_assertok(check_tpm_startup(uts, TPM_V2));
+
+ return 0;
+}
+DM_TEST(dm_test_tpm_startup, UTF_SCAN_FDT);
+
+static int check_tpm_self_test_full(struct unit_test_state *uts,
+ enum tpm_version version)
+{
+ struct udevice *dev;
+
+ ut_assertok(check_tpm_startup(uts, version));
+
+ ut_assertok(get_tpm_version(version, &dev));
+ ut_assertok(tpm_self_test_full(dev));
+
+ return 0;
+}
+
+/* Test TPM self-test full */
+static int dm_test_tpm_self_test_full(struct unit_test_state *uts)
+{
+ ut_assertok(check_tpm_self_test_full(uts, TPM_V1));
+ ut_assertok(check_tpm_self_test_full(uts, TPM_V2));
+
+ return 0;
+}
+DM_TEST(dm_test_tpm_self_test_full, UTF_SCAN_FDT);
+
+/* Test TPM self-test continue */
+static int test_tpm_self_test_cont(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));
+ ut_assertok(tpm_startup(dev, TPM_ST_CLEAR));
+ ut_assertok(tpm_continue_self_test(dev));
+
+ return 0;
+}
+
+static int dm_test_tpm_self_test_cont(struct unit_test_state *uts)
+{
+ ut_assertok(test_tpm_self_test_cont(uts, TPM_V1));
+ ut_assertok(test_tpm_self_test_cont(uts, TPM_V2));
+
+ return 0;
+}
+DM_TEST(dm_test_tpm_self_test_cont, UTF_SCAN_FDT);
/* Test report_state */
static int dm_test_tpm_report_state(struct unit_test_state *uts)