Sean Anderson | 2a19109 | 2021-02-05 09:38:54 -0500 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (C) 2015 Google, Inc |
| 4 | */ |
| 5 | |
Sean Anderson | 2a19109 | 2021-02-05 09:38:54 -0500 | [diff] [blame] | 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 | |
Sean Anderson | c4f2d64 | 2021-02-05 09:39:00 -0500 | [diff] [blame] | 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)); |
Sean Anderson | 2a19109 | 2021-02-05 09:38:54 -0500 | [diff] [blame] | 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 | |
Sean Anderson | c4f2d64 | 2021-02-05 09:39:00 -0500 | [diff] [blame] | 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)); |
Simon Glass | 70f4bcb | 2022-04-24 23:31:01 -0600 | [diff] [blame] | 83 | ut_asserteq(0, fastboot_mmc_get_part_info("2", &fb_dev_desc, |
Sean Anderson | c4f2d64 | 2021-02-05 09:39:00 -0500 | [diff] [blame] | 84 | &part_info, response)); |
Simon Glass | 70f4bcb | 2022-04-24 23:31:01 -0600 | [diff] [blame] | 85 | ut_asserteq(0, fastboot_mmc_get_part_info("2.0", &fb_dev_desc, |
Sean Anderson | c4f2d64 | 2021-02-05 09:39:00 -0500 | [diff] [blame] | 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 | |
Sean Anderson | 2a19109 | 2021-02-05 09:38:54 -0500 | [diff] [blame] | 92 | return 0; |
| 93 | } |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 94 | DM_TEST(dm_test_fastboot_mmc_part, UTF_SCAN_PDATA | UTF_SCAN_FDT); |