blob: 5d938eb7f121ac3a843b6cb069a26cc0f3848965 [file] [log] [blame]
Sean Andersond4f22cb2021-02-05 09:38:54 -05001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2015 Google, Inc
4 */
5
Sean Andersond4f22cb2021-02-05 09:38:54 -05006#include <dm.h>
7#include <fastboot.h>
8#include <fb_mmc.h>
9#include <mmc.h>
10#include <part.h>
11#include <part_efi.h>
12#include <dm/test.h>
13#include <test/ut.h>
14#include <linux/stringify.h>
15
16#define FB_ALIAS_PREFIX "fastboot_partition_alias_"
17
18static int dm_test_fastboot_mmc_part(struct unit_test_state *uts)
19{
20 char response[FASTBOOT_RESPONSE_LEN] = {0};
21 char str_disk_guid[UUID_STR_LEN + 1];
22 struct blk_desc *mmc_dev_desc, *fb_dev_desc;
23 struct disk_partition part_info;
24 struct disk_partition parts[2] = {
25 {
26 .start = 48, /* GPT data takes up the first 34 blocks or so */
27 .size = 1,
28 .name = "test1",
29 },
30 {
31 .start = 49,
32 .size = 1,
33 .name = "test2",
34 },
35 };
36
Sean Andersonde1728c2021-02-05 09:39:00 -050037 /*
38 * There are a lot of literal 0s I don't want to have to construct from
39 * MMC_DEV.
40 */
41 ut_asserteq(0, CONFIG_FASTBOOT_FLASH_MMC_DEV);
42 ut_assertok(blk_get_device_by_str("mmc", "0", &mmc_dev_desc));
Sean Andersond4f22cb2021-02-05 09:38:54 -050043 if (CONFIG_IS_ENABLED(RANDOM_UUID)) {
44 gen_rand_uuid_str(parts[0].uuid, UUID_STR_FORMAT_STD);
45 gen_rand_uuid_str(parts[1].uuid, UUID_STR_FORMAT_STD);
46 gen_rand_uuid_str(str_disk_guid, UUID_STR_FORMAT_STD);
47 }
48 ut_assertok(gpt_restore(mmc_dev_desc, str_disk_guid, parts,
49 ARRAY_SIZE(parts)));
50
51 /* "Classic" partition labels */
52 ut_asserteq(1, fastboot_mmc_get_part_info("test1", &fb_dev_desc,
53 &part_info, response));
54 ut_asserteq(2, fastboot_mmc_get_part_info("test2", &fb_dev_desc,
55 &part_info, response));
56
57 /* Test aliases */
58 ut_assertnull(env_get(FB_ALIAS_PREFIX "test3"));
59 ut_assertok(env_set(FB_ALIAS_PREFIX "test3", "test1"));
60 ut_asserteq(1, fastboot_mmc_get_part_info("test3", &fb_dev_desc,
61 &part_info, response));
62 ut_assertok(env_set(FB_ALIAS_PREFIX "test3", NULL));
63
Sean Andersonde1728c2021-02-05 09:39:00 -050064 /* "New" partition labels */
65 ut_asserteq(1, fastboot_mmc_get_part_info("#test1", &fb_dev_desc,
66 &part_info, response));
67 ut_asserteq(1, fastboot_mmc_get_part_info("0#test1", &fb_dev_desc,
68 &part_info, response));
69 ut_asserteq(1, fastboot_mmc_get_part_info("0.0#test1", &fb_dev_desc,
70 &part_info, response));
71 ut_asserteq(1, fastboot_mmc_get_part_info("0:1", &fb_dev_desc,
72 &part_info, response));
73 ut_asserteq(1, fastboot_mmc_get_part_info("0.0:1", &fb_dev_desc,
74 &part_info, response));
75 ut_asserteq(1, fastboot_mmc_get_part_info("0", &fb_dev_desc,
76 &part_info, response));
77 ut_asserteq(1, fastboot_mmc_get_part_info("0.0", &fb_dev_desc,
78 &part_info, response));
79 ut_asserteq(0, fastboot_mmc_get_part_info("0:0", &fb_dev_desc,
80 &part_info, response));
81 ut_asserteq(0, fastboot_mmc_get_part_info("0.0:0", &fb_dev_desc,
82 &part_info, response));
Simon Glass9bd2f622022-04-24 23:31:01 -060083 ut_asserteq(0, fastboot_mmc_get_part_info("2", &fb_dev_desc,
Sean Andersonde1728c2021-02-05 09:39:00 -050084 &part_info, response));
Simon Glass9bd2f622022-04-24 23:31:01 -060085 ut_asserteq(0, fastboot_mmc_get_part_info("2.0", &fb_dev_desc,
Sean Andersonde1728c2021-02-05 09:39:00 -050086 &part_info, response));
87 ut_asserteq(1, fastboot_mmc_get_part_info(":1", &fb_dev_desc,
88 &part_info, response));
89 ut_asserteq(0, fastboot_mmc_get_part_info(":0", &fb_dev_desc,
90 &part_info, response));
91
Sean Andersond4f22cb2021-02-05 09:38:54 -050092 return 0;
93}
94DM_TEST(dm_test_fastboot_mmc_part, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);