]>
Commit | Line | Data |
---|---|---|
d4f22cb3 SA |
1 | // SPDX-License-Identifier: GPL-2.0+ |
2 | /* | |
3 | * Copyright (C) 2015 Google, Inc | |
4 | */ | |
5 | ||
d4f22cb3 SA |
6 | #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 | ||
18 | static 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 | ||
de1728ce SA |
37 | /* |
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)); | |
d4f22cb3 SA |
43 | 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 | ||
de1728ce SA |
64 | /* "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)); | |
9bd2f62d | 83 | ut_asserteq(0, fastboot_mmc_get_part_info("2", &fb_dev_desc, |
de1728ce | 84 | &part_info, response)); |
9bd2f62d | 85 | ut_asserteq(0, fastboot_mmc_get_part_info("2.0", &fb_dev_desc, |
de1728ce SA |
86 | &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 | ||
d4f22cb3 SA |
92 | return 0; |
93 | } | |
94 | DM_TEST(dm_test_fastboot_mmc_part, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |