aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSughosh Ganu <sughosh.ganu@linaro.org>2022-02-06 15:17:52 +0530
committerSughosh Ganu <sughosh.ganu@linaro.org>2022-02-13 22:47:22 +0530
commitcac47954876ac996405994a254abaf57f20a7246 (patch)
tree69f18c860aa71747a75319997fd55eefded493ca
parent829848b7916f9cd4e2001bf263d1526f3a2d3548 (diff)
test: dm: Add test cases for FWU Metadata uclass
Add test cases for accessing the FWU Metadata on the sandbox platform. The sandbox platform also uses the metadata access driver for GPT partitioned block devices. Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org> Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
-rw-r--r--arch/sandbox/dts/test.dts11
-rw-r--r--test/dm/Makefile1
-rw-r--r--test/dm/fwu_mdata.c132
-rw-r--r--test/dm/fwu_mdata_disk_image.h92
-rw-r--r--tools/Makefile2
5 files changed, 234 insertions, 4 deletions
diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 48ca3e1e4721..c82589158033 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -886,16 +886,16 @@
compatible = "sandbox,misc_sandbox";
};
- mmc2 {
+ mmc2: mmc2 {
compatible = "sandbox,mmc";
non-removable;
};
- mmc1 {
+ mmc1: mmc1 {
compatible = "sandbox,mmc";
};
- mmc0 {
+ mmc0: mmc0 {
compatible = "sandbox,mmc";
};
@@ -1609,6 +1609,11 @@
compatible = "sandbox,regmap_test";
};
};
+
+ fwu-mdata {
+ compatible = "sandbox,fwu-mdata";
+ fwu-mdata-store = <&mmc0>;
+ };
};
#include "sandbox_pmic.dtsi"
diff --git a/test/dm/Makefile b/test/dm/Makefile
index d46552fbf320..fba386e9a632 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -43,6 +43,7 @@ ifneq ($(CONFIG_EFI_PARTITION),)
obj-$(CONFIG_FASTBOOT_FLASH_MMC) += fastboot.o
endif
obj-$(CONFIG_FIRMWARE) += firmware.o
+obj-$(CONFIG_FWU_MDATA_GPT_BLK) += fwu_mdata.o
obj-$(CONFIG_DM_GPIO) += gpio.o
obj-$(CONFIG_DM_HWSPINLOCK) += hwspinlock.o
obj-$(CONFIG_DM_I2C) += i2c.o
diff --git a/test/dm/fwu_mdata.c b/test/dm/fwu_mdata.c
new file mode 100644
index 000000000000..06aedd6ca9d8
--- /dev/null
+++ b/test/dm/fwu_mdata.c
@@ -0,0 +1,132 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2022, Linaro Limited
+ * Copyright (c) 2022, Heinrich Schuchardt <xypron.glpk@gmx.de>
+ */
+
+#include <blk.h>
+#include <common.h>
+#include <dm.h>
+#include <fwu.h>
+#include <fwu_mdata.h>
+#include <log.h>
+#include <malloc.h>
+#include <memalign.h>
+#include <part.h>
+
+#include <dm/test.h>
+#include <test/ut.h>
+
+#include "fwu_mdata_disk_image.h"
+
+/* Block size of compressed disk image */
+#define COMPRESSED_DISK_IMAGE_BLOCK_SIZE 8
+
+static struct udevice *mmc_dev;
+static struct blk_desc *dev_desc;
+
+/* One 8 byte block of the compressed disk image */
+struct line {
+ size_t addr;
+ char *line;
+};
+
+/* Compressed disk image */
+struct compressed_disk_image {
+ size_t length;
+ struct line lines[];
+};
+
+static const struct compressed_disk_image img = FWU_MDATA_DISK_IMG;
+
+/* Decompressed disk image */
+static u8 *image;
+
+static int setup_blk_device(struct unit_test_state *uts)
+{
+ ut_assertok(uclass_get_device(UCLASS_MMC, 0, &mmc_dev));
+ ut_assertok(blk_get_device_by_str("mmc", "0", &dev_desc));
+
+ return 0;
+}
+
+static int populate_mmc_disk_image(struct unit_test_state *uts)
+{
+ u8 *buf;
+ size_t i;
+ size_t addr;
+ size_t len;
+
+ buf = malloc(img.length);
+ if (!buf)
+ return -ENOMEM;
+
+ memset(buf, 0, img.length);
+
+ for (i = 0; ; i++) {
+ if (!img.lines[i].line)
+ break;
+ addr = img.lines[i].addr;
+ len = COMPRESSED_DISK_IMAGE_BLOCK_SIZE;
+ if (addr + len > img.length)
+ len = img.length - addr;
+ memcpy(buf + addr, img.lines[i].line, len);
+ }
+ image = buf;
+
+ return 0;
+}
+
+static int write_mmc_blk_device(struct unit_test_state *uts)
+{
+ lbaint_t blkcnt;
+
+ blkcnt = BLOCK_CNT(img.length, dev_desc);
+
+ ut_asserteq(blkcnt, blk_dwrite(dev_desc, 0, blkcnt, image));
+
+ return 0;
+}
+
+static int dm_test_fwu_mdata_read(struct unit_test_state *uts)
+{
+ struct fwu_mdata *mdata = NULL;
+
+ ut_assertok(setup_blk_device(uts));
+ ut_assertok(populate_mmc_disk_image(uts));
+ ut_assertok(write_mmc_blk_device(uts));
+
+ ut_assertok(fwu_get_mdata(&mdata));
+ ut_assertnonnull(mdata);
+
+ ut_asserteq(mdata->version, 0x1);
+
+ return 0;
+}
+DM_TEST(dm_test_fwu_mdata_read, UT_TESTF_SCAN_FDT);
+
+static int dm_test_fwu_mdata_write(struct unit_test_state *uts)
+{
+ u32 active_idx;
+ struct udevice *dev;
+ struct fwu_mdata *mdata = NULL;
+
+ ut_assertok(setup_blk_device(uts));
+ ut_assertok(populate_mmc_disk_image(uts));
+ ut_assertok(write_mmc_blk_device(uts));
+
+ ut_assertok(uclass_get_device(UCLASS_FWU_MDATA, 0, &dev));
+ ut_assertnonnull(dev);
+
+ ut_assertok(fwu_get_mdata(&mdata));
+ ut_assertnonnull(mdata);
+
+ active_idx = mdata->active_index ^ 0x1;
+ ut_assertok(fwu_update_active_index(active_idx));
+
+ ut_assertok(fwu_get_mdata(&mdata));
+ ut_asserteq(mdata->active_index, active_idx);
+
+ return 0;
+}
+DM_TEST(dm_test_fwu_mdata_write, UT_TESTF_SCAN_FDT);
diff --git a/test/dm/fwu_mdata_disk_image.h b/test/dm/fwu_mdata_disk_image.h
new file mode 100644
index 000000000000..5247159ac8cd
--- /dev/null
+++ b/test/dm/fwu_mdata_disk_image.h
@@ -0,0 +1,92 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Non-zero 8 byte strings of a disk image
+ *
+ * Generated with tools/file2include
+ */
+
+#define FWU_MDATA_DISK_IMG { 0x00010000, { \
+ {0x000001c0, "\x02\x00\xee\x02\x02\x00\x01\x00"}, /* ........ */ \
+ {0x000001c8, "\x00\x00\x7f\x00\x00\x00\x00\x00"}, /* ........ */ \
+ {0x000001f8, "\x00\x00\x00\x00\x00\x00\x55\xaa"}, /* ......U. */ \
+ {0x00000200, "\x45\x46\x49\x20\x50\x41\x52\x54"}, /* EFI PART */ \
+ {0x00000208, "\x00\x00\x01\x00\x5c\x00\x00\x00"}, /* ....\... */ \
+ {0x00000210, "\x11\x1c\x9d\x27\x00\x00\x00\x00"}, /* ...'.... */ \
+ {0x00000218, "\x01\x00\x00\x00\x00\x00\x00\x00"}, /* ........ */ \
+ {0x00000220, "\x7f\x00\x00\x00\x00\x00\x00\x00"}, /* ........ */ \
+ {0x00000228, "\x22\x00\x00\x00\x00\x00\x00\x00"}, /* "....... */ \
+ {0x00000230, "\x5e\x00\x00\x00\x00\x00\x00\x00"}, /* ^....... */ \
+ {0x00000238, "\x15\xf7\x1a\xea\x1c\x34\xe1\x45"}, /* .....4.E */ \
+ {0x00000240, "\x90\x10\x8c\x42\xa3\xb1\x1b\x3f"}, /* ...B...? */ \
+ {0x00000248, "\x02\x00\x00\x00\x00\x00\x00\x00"}, /* ........ */ \
+ {0x00000250, "\x80\x00\x00\x00\x80\x00\x00\x00"}, /* ........ */ \
+ {0x00000258, "\xf1\xa0\xe0\x3b\x00\x00\x00\x00"}, /* ...;.... */ \
+ {0x00000400, "\xa0\x84\x7a\x8a\x87\x83\xf6\x40"}, /* ..z....@ */ \
+ {0x00000408, "\xab\x41\xa8\xb9\xa5\xa6\x0d\x23"}, /* .A.....# */ \
+ {0x00000410, "\x93\x45\x18\x6c\x4d\x3e\x8a\x4b"}, /* .E.lM>.K */ \
+ {0x00000418, "\xbd\x23\xdf\x57\xa9\xdd\x1a\xed"}, /* .#.W.... */ \
+ {0x00000420, "\x22\x00\x00\x00\x00\x00\x00\x00"}, /* "....... */ \
+ {0x00000428, "\x23\x00\x00\x00\x00\x00\x00\x00"}, /* #....... */ \
+ {0x00000438, "\x55\x00\x6e\x00\x6b\x00\x6e\x00"}, /* U.n.k.n. */ \
+ {0x00000440, "\x6f\x00\x77\x00\x6e\x00\x00\x00"}, /* o.w.n... */ \
+ {0x00000480, "\xa0\x84\x7a\x8a\x87\x83\xf6\x40"}, /* ..z....@ */ \
+ {0x00000488, "\xab\x41\xa8\xb9\xa5\xa6\x0d\x23"}, /* .A.....# */ \
+ {0x00000490, "\x22\xae\x43\xf1\x8e\x74\xa0\x47"}, /* ".C..t.G */ \
+ {0x00000498, "\xb4\xf7\x67\x06\x20\xe0\x44\xd7"}, /* ..g. .D. */ \
+ {0x000004a0, "\x24\x00\x00\x00\x00\x00\x00\x00"}, /* $....... */ \
+ {0x000004a8, "\x25\x00\x00\x00\x00\x00\x00\x00"}, /* %....... */ \
+ {0x000004b8, "\x55\x00\x6e\x00\x6b\x00\x6e\x00"}, /* U.n.k.n. */ \
+ {0x000004c0, "\x6f\x00\x77\x00\x6e\x00\x00\x00"}, /* o.w.n... */ \
+ {0x00004400, "\x09\xb9\xe5\x20\x01\x00\x00\x00"}, /* ... .... */ \
+ {0x00004408, "\x00\x00\x00\x00\x01\x00\x00\x00"}, /* ........ */ \
+ {0x00004410, "\x83\xdf\xd5\x19\xb0\x11\x7b\x45"}, /* ......{E */ \
+ {0x00004418, "\xbe\x2c\x75\x59\xc1\x31\x42\xa5"}, /* .,uY.1B. */ \
+ {0x00004420, "\xeb\x2b\x27\x49\xd8\x8d\xdf\x46"}, /* .+'I...F */ \
+ {0x00004428, "\x8d\x75\x35\x6c\x65\xef\xf4\x17"}, /* .u5le... */ \
+ {0x00004430, "\xcc\x28\x74\xd5\x9a\xbb\xe0\x42"}, /* .(t....B */ \
+ {0x00004438, "\xaa\x36\x3f\x5a\x13\x20\x59\xc7"}, /* .6?Z. Y. */ \
+ {0x00004440, "\x01\x00\x00\x00\x00\x00\x00\x00"}, /* ........ */ \
+ {0x00004448, "\x6d\x7d\xe3\x2b\x81\x82\x38\x49"}, /* m}.+..8I */ \
+ {0x00004450, "\xbd\x7b\x9a\x5b\xbf\x80\x86\x9f"}, /* .{.[.... */ \
+ {0x00004458, "\x01\x00\x00\x00\x00\x00\x00\x00"}, /* ........ */ \
+ {0x00004800, "\x09\xb9\xe5\x20\x01\x00\x00\x00"}, /* ... .... */ \
+ {0x00004808, "\x00\x00\x00\x00\x01\x00\x00\x00"}, /* ........ */ \
+ {0x00004810, "\x83\xdf\xd5\x19\xb0\x11\x7b\x45"}, /* ......{E */ \
+ {0x00004818, "\xbe\x2c\x75\x59\xc1\x31\x42\xa5"}, /* .,uY.1B. */ \
+ {0x00004820, "\xeb\x2b\x27\x49\xd8\x8d\xdf\x46"}, /* .+'I...F */ \
+ {0x00004828, "\x8d\x75\x35\x6c\x65\xef\xf4\x17"}, /* .u5le... */ \
+ {0x00004830, "\xcc\x28\x74\xd5\x9a\xbb\xe0\x42"}, /* .(t....B */ \
+ {0x00004838, "\xaa\x36\x3f\x5a\x13\x20\x59\xc7"}, /* .6?Z. Y. */ \
+ {0x00004840, "\x01\x00\x00\x00\x00\x00\x00\x00"}, /* ........ */ \
+ {0x00004848, "\x6d\x7d\xe3\x2b\x81\x82\x38\x49"}, /* m}.+..8I */ \
+ {0x00004850, "\xbd\x7b\x9a\x5b\xbf\x80\x86\x9f"}, /* .{.[.... */ \
+ {0x00004858, "\x01\x00\x00\x00\x00\x00\x00\x00"}, /* ........ */ \
+ {0x0000be00, "\xa0\x84\x7a\x8a\x87\x83\xf6\x40"}, /* ..z....@ */ \
+ {0x0000be08, "\xab\x41\xa8\xb9\xa5\xa6\x0d\x23"}, /* .A.....# */ \
+ {0x0000be10, "\x93\x45\x18\x6c\x4d\x3e\x8a\x4b"}, /* .E.lM>.K */ \
+ {0x0000be18, "\xbd\x23\xdf\x57\xa9\xdd\x1a\xed"}, /* .#.W.... */ \
+ {0x0000be20, "\x22\x00\x00\x00\x00\x00\x00\x00"}, /* "....... */ \
+ {0x0000be28, "\x23\x00\x00\x00\x00\x00\x00\x00"}, /* #....... */ \
+ {0x0000be38, "\x55\x00\x6e\x00\x6b\x00\x6e\x00"}, /* U.n.k.n. */ \
+ {0x0000be40, "\x6f\x00\x77\x00\x6e\x00\x00\x00"}, /* o.w.n... */ \
+ {0x0000be80, "\xa0\x84\x7a\x8a\x87\x83\xf6\x40"}, /* ..z....@ */ \
+ {0x0000be88, "\xab\x41\xa8\xb9\xa5\xa6\x0d\x23"}, /* .A.....# */ \
+ {0x0000be90, "\x22\xae\x43\xf1\x8e\x74\xa0\x47"}, /* ".C..t.G */ \
+ {0x0000be98, "\xb4\xf7\x67\x06\x20\xe0\x44\xd7"}, /* ..g. .D. */ \
+ {0x0000bea0, "\x24\x00\x00\x00\x00\x00\x00\x00"}, /* $....... */ \
+ {0x0000bea8, "\x25\x00\x00\x00\x00\x00\x00\x00"}, /* %....... */ \
+ {0x0000beb8, "\x55\x00\x6e\x00\x6b\x00\x6e\x00"}, /* U.n.k.n. */ \
+ {0x0000bec0, "\x6f\x00\x77\x00\x6e\x00\x00\x00"}, /* o.w.n... */ \
+ {0x0000fe00, "\x45\x46\x49\x20\x50\x41\x52\x54"}, /* EFI PART */ \
+ {0x0000fe08, "\x00\x00\x01\x00\x5c\x00\x00\x00"}, /* ....\... */ \
+ {0x0000fe10, "\x15\x24\x2c\xfb\x00\x00\x00\x00"}, /* .$,..... */ \
+ {0x0000fe18, "\x7f\x00\x00\x00\x00\x00\x00\x00"}, /* ........ */ \
+ {0x0000fe20, "\x01\x00\x00\x00\x00\x00\x00\x00"}, /* ........ */ \
+ {0x0000fe28, "\x22\x00\x00\x00\x00\x00\x00\x00"}, /* "....... */ \
+ {0x0000fe30, "\x5e\x00\x00\x00\x00\x00\x00\x00"}, /* ^....... */ \
+ {0x0000fe38, "\x15\xf7\x1a\xea\x1c\x34\xe1\x45"}, /* .....4.E */ \
+ {0x0000fe40, "\x90\x10\x8c\x42\xa3\xb1\x1b\x3f"}, /* ...B...? */ \
+ {0x0000fe48, "\x5f\x00\x00\x00\x00\x00\x00\x00"}, /* _....... */ \
+ {0x0000fe50, "\x80\x00\x00\x00\x80\x00\x00\x00"}, /* ........ */ \
+ {0x0000fe58, "\xf1\xa0\xe0\x3b\x00\x00\x00\x00"}, /* ...;.... */ \
+ {0, NULL} } }
diff --git a/tools/Makefile b/tools/Makefile
index 5409ff2879c6..2c6290624ad9 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -74,7 +74,7 @@ mkenvimage-objs := mkenvimage.o os_support.o lib/crc32.o
hostprogs-y += dumpimage mkimage
hostprogs-$(CONFIG_TOOLS_LIBCRYPTO) += fit_info fit_check_sign
-hostprogs-$(CONFIG_CMD_BOOTEFI_SELFTEST) += file2include
+hostprogs-$(CONFIG_CMD_BOOTEFI_SELFTEST)$(CONFIG_FWU_MDATA_GPT_BLK) += file2include
FIT_OBJS-y := fit_common.o fit_image.o image-host.o boot/image-fit.o
FIT_SIG_OBJS-$(CONFIG_TOOLS_LIBCRYPTO) := image-sig-host.o boot/image-fit-sig.o