[PATCH v2 2/9] test: dm: Add test for fastboot mmc partition naming
Sean Anderson
sean.anderson at seco.com
Thu Jan 7 16:20:56 CET 2021
This test verifies the mapping between fastboot partitions and partitions
as understood by U-Boot. It also tests the creation of GPT partitions,
though that is not the primary goal.
Signed-off-by: Sean Anderson <sean.anderson at seco.com>
Reviewed-by: Simon Glass <sjg at chromium.org>
---
(no changes since v1)
configs/sandbox64_defconfig | 2 ++
configs/sandbox_defconfig | 2 ++
test/dm/Makefile | 3 ++
test/dm/fastboot.c | 64 +++++++++++++++++++++++++++++++++++++
4 files changed, 71 insertions(+)
create mode 100644 test/dm/fastboot.c
diff --git a/configs/sandbox64_defconfig b/configs/sandbox64_defconfig
index 5fbbfd7236..e61aa71fbc 100644
--- a/configs/sandbox64_defconfig
+++ b/configs/sandbox64_defconfig
@@ -109,6 +109,8 @@ CONFIG_CPU=y
CONFIG_DM_DEMO=y
CONFIG_DM_DEMO_SIMPLE=y
CONFIG_DM_DEMO_SHAPE=y
+CONFIG_FASTBOOT_FLASH=y
+CONFIG_FASTBOOT_FLASH_MMC_DEV=0
CONFIG_GPIO_HOG=y
CONFIG_DM_GPIO_LOOKUP_LABEL=y
CONFIG_PM8916_GPIO=y
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index f1ec701a9f..ba53426df4 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -134,6 +134,8 @@ CONFIG_DM_DEMO_SHAPE=y
CONFIG_DMA=y
CONFIG_DMA_CHANNELS=y
CONFIG_SANDBOX_DMA=y
+CONFIG_FASTBOOT_FLASH=y
+CONFIG_FASTBOOT_FLASH_MMC_DEV=0
CONFIG_GPIO_HOG=y
CONFIG_DM_GPIO_LOOKUP_LABEL=y
CONFIG_PM8916_GPIO=y
diff --git a/test/dm/Makefile b/test/dm/Makefile
index 46e076ed09..be4385c709 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -91,5 +91,8 @@ obj-$(CONFIG_SCMI_FIRMWARE) += scmi.o
ifneq ($(CONFIG_PINMUX),)
obj-$(CONFIG_PINCONF) += pinmux.o
endif
+ifneq ($(CONFIG_EFI_PARTITION)$(CONFIG_FASTBOOT_FLASH_MMC),)
+obj-y += fastboot.o
+endif
endif
endif # !SPL
diff --git a/test/dm/fastboot.c b/test/dm/fastboot.c
new file mode 100644
index 0000000000..8f905d8fa8
--- /dev/null
+++ b/test/dm/fastboot.c
@@ -0,0 +1,64 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2015 Google, Inc
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <fastboot.h>
+#include <fb_mmc.h>
+#include <mmc.h>
+#include <part.h>
+#include <part_efi.h>
+#include <dm/test.h>
+#include <test/ut.h>
+#include <linux/stringify.h>
+
+#define FB_ALIAS_PREFIX "fastboot_partition_alias_"
+
+static int dm_test_fastboot_mmc_part(struct unit_test_state *uts)
+{
+ char response[FASTBOOT_RESPONSE_LEN] = {0};
+ char str_disk_guid[UUID_STR_LEN + 1];
+ struct blk_desc *mmc_dev_desc, *fb_dev_desc;
+ struct disk_partition part_info;
+ struct disk_partition parts[2] = {
+ {
+ .start = 48, /* GPT data takes up the first 34 blocks or so */
+ .size = 1,
+ .name = "test1",
+ },
+ {
+ .start = 49,
+ .size = 1,
+ .name = "test2",
+ },
+ };
+
+ ut_assertok(blk_get_device_by_str("mmc",
+ __stringify(CONFIG_FASTBOOT_FLASH_MMC_DEV),
+ &mmc_dev_desc));
+ if (CONFIG_IS_ENABLED(RANDOM_UUID)) {
+ gen_rand_uuid_str(parts[0].uuid, UUID_STR_FORMAT_STD);
+ gen_rand_uuid_str(parts[1].uuid, UUID_STR_FORMAT_STD);
+ gen_rand_uuid_str(str_disk_guid, UUID_STR_FORMAT_STD);
+ }
+ ut_assertok(gpt_restore(mmc_dev_desc, str_disk_guid, parts,
+ ARRAY_SIZE(parts)));
+
+ /* "Classic" partition labels */
+ ut_asserteq(1, fastboot_mmc_get_part_info("test1", &fb_dev_desc,
+ &part_info, response));
+ ut_asserteq(2, fastboot_mmc_get_part_info("test2", &fb_dev_desc,
+ &part_info, response));
+
+ /* Test aliases */
+ ut_assertnull(env_get(FB_ALIAS_PREFIX "test3"));
+ ut_assertok(env_set(FB_ALIAS_PREFIX "test3", "test1"));
+ ut_asserteq(1, fastboot_mmc_get_part_info("test3", &fb_dev_desc,
+ &part_info, response));
+ ut_assertok(env_set(FB_ALIAS_PREFIX "test3", NULL));
+
+ return 0;
+}
+DM_TEST(dm_test_fastboot_mmc_part, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
--
2.25.1
More information about the U-Boot
mailing list