summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2021-02-26 15:11:08 -0500
committerTom Rini <trini@konsulko.com>2021-02-26 15:11:08 -0500
commit08cca188c120b8337600091c94dc0e211cd03e10 (patch)
treebb6980e98ba2b14919b38619994ffa6f65d839b5 /test
parentb839fc9d47bbfc4ab4f0817a03e0e0e25b93e925 (diff)
parent0a7e5e5f103867789328067f87e34b25b26fc3b0 (diff)
downloadu-boot-08cca188c120b8337600091c94dc0e211cd03e10.tar.gz
Merge https://gitlab.denx.de/u-boot/custodians/u-boot-usbWIP/26Feb2021
- fastboot updates / fixes
Diffstat (limited to 'test')
-rw-r--r--test/dm/Makefile3
-rw-r--r--test/dm/fastboot.c95
-rw-r--r--test/dm/mmc.c19
3 files changed, 112 insertions, 5 deletions
diff --git a/test/dm/Makefile b/test/dm/Makefile
index 6275ec56ea..fd1455109d 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -95,5 +95,8 @@ obj-$(CONFIG_SCMI_FIRMWARE) += scmi.o
ifneq ($(CONFIG_PINMUX),)
obj-$(CONFIG_PINCONF) += pinmux.o
endif
+ifneq ($(CONFIG_EFI_PARTITION),)
+obj-$(CONFIG_FASTBOOT_FLASH_MMC) += fastboot.o
+endif
endif
endif # !SPL
diff --git a/test/dm/fastboot.c b/test/dm/fastboot.c
new file mode 100644
index 0000000000..e7f8c362b8
--- /dev/null
+++ b/test/dm/fastboot.c
@@ -0,0 +1,95 @@
+// 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",
+ },
+ };
+
+ /*
+ * There are a lot of literal 0s I don't want to have to construct from
+ * MMC_DEV.
+ */
+ ut_asserteq(0, CONFIG_FASTBOOT_FLASH_MMC_DEV);
+ ut_assertok(blk_get_device_by_str("mmc", "0", &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));
+
+ /* "New" partition labels */
+ ut_asserteq(1, fastboot_mmc_get_part_info("#test1", &fb_dev_desc,
+ &part_info, response));
+ ut_asserteq(1, fastboot_mmc_get_part_info("0#test1", &fb_dev_desc,
+ &part_info, response));
+ ut_asserteq(1, fastboot_mmc_get_part_info("0.0#test1", &fb_dev_desc,
+ &part_info, response));
+ ut_asserteq(1, fastboot_mmc_get_part_info("0:1", &fb_dev_desc,
+ &part_info, response));
+ ut_asserteq(1, fastboot_mmc_get_part_info("0.0:1", &fb_dev_desc,
+ &part_info, response));
+ ut_asserteq(1, fastboot_mmc_get_part_info("0", &fb_dev_desc,
+ &part_info, response));
+ ut_asserteq(1, fastboot_mmc_get_part_info("0.0", &fb_dev_desc,
+ &part_info, response));
+ ut_asserteq(0, fastboot_mmc_get_part_info("0:0", &fb_dev_desc,
+ &part_info, response));
+ ut_asserteq(0, fastboot_mmc_get_part_info("0.0:0", &fb_dev_desc,
+ &part_info, response));
+ ut_asserteq(0, fastboot_mmc_get_part_info("1", &fb_dev_desc,
+ &part_info, response));
+ ut_asserteq(0, fastboot_mmc_get_part_info("1.0", &fb_dev_desc,
+ &part_info, response));
+ ut_asserteq(1, fastboot_mmc_get_part_info(":1", &fb_dev_desc,
+ &part_info, response));
+ ut_asserteq(0, fastboot_mmc_get_part_info(":0", &fb_dev_desc,
+ &part_info, response));
+
+ return 0;
+}
+DM_TEST(dm_test_fastboot_mmc_part, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
diff --git a/test/dm/mmc.c b/test/dm/mmc.c
index 4e5136c850..f744452ff2 100644
--- a/test/dm/mmc.c
+++ b/test/dm/mmc.c
@@ -29,16 +29,25 @@ static int dm_test_mmc_blk(struct unit_test_state *uts)
{
struct udevice *dev;
struct blk_desc *dev_desc;
- char cmp[1024];
+ int i;
+ char write[1024], read[1024];
ut_assertok(uclass_get_device(UCLASS_MMC, 0, &dev));
ut_assertok(blk_get_device_by_str("mmc", "0", &dev_desc));
- /* Read a few blocks and look for the string we expect */
+ /* Write a few blocks and verify that we get the same data back */
ut_asserteq(512, dev_desc->blksz);
- memset(cmp, '\0', sizeof(cmp));
- ut_asserteq(2, blk_dread(dev_desc, 0, 2, cmp));
- ut_assertok(strcmp(cmp, "this is a test"));
+ for (i = 0; i < sizeof(write); i++)
+ write[i] = i;
+ ut_asserteq(2, blk_dwrite(dev_desc, 0, 2, write));
+ ut_asserteq(2, blk_dread(dev_desc, 0, 2, read));
+ ut_asserteq_mem(write, read, sizeof(write));
+
+ /* Now erase them */
+ memset(write, '\0', sizeof(write));
+ ut_asserteq(2, blk_derase(dev_desc, 0, 2));
+ ut_asserteq(2, blk_dread(dev_desc, 0, 2, read));
+ ut_asserteq_mem(write, read, sizeof(write));
return 0;
}