fastboot.c 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2015 Google, Inc
  4. */
  5. #include <common.h>
  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. #define FB_ALIAS_PREFIX "fastboot_partition_alias_"
  16. static int dm_test_fastboot_mmc_part(struct unit_test_state *uts)
  17. {
  18. char response[FASTBOOT_RESPONSE_LEN] = {0};
  19. char str_disk_guid[UUID_STR_LEN + 1];
  20. struct blk_desc *mmc_dev_desc, *fb_dev_desc;
  21. struct disk_partition part_info;
  22. struct disk_partition parts[2] = {
  23. {
  24. .start = 48, /* GPT data takes up the first 34 blocks or so */
  25. .size = 1,
  26. .name = "test1",
  27. },
  28. {
  29. .start = 49,
  30. .size = 1,
  31. .name = "test2",
  32. },
  33. };
  34. /*
  35. * There are a lot of literal 0s I don't want to have to construct from
  36. * MMC_DEV.
  37. */
  38. ut_asserteq(0, CONFIG_FASTBOOT_FLASH_MMC_DEV);
  39. ut_assertok(blk_get_device_by_str("mmc", "0", &mmc_dev_desc));
  40. if (CONFIG_IS_ENABLED(RANDOM_UUID)) {
  41. gen_rand_uuid_str(parts[0].uuid, UUID_STR_FORMAT_STD);
  42. gen_rand_uuid_str(parts[1].uuid, UUID_STR_FORMAT_STD);
  43. gen_rand_uuid_str(str_disk_guid, UUID_STR_FORMAT_STD);
  44. }
  45. ut_assertok(gpt_restore(mmc_dev_desc, str_disk_guid, parts,
  46. ARRAY_SIZE(parts)));
  47. /* "Classic" partition labels */
  48. ut_asserteq(1, fastboot_mmc_get_part_info("test1", &fb_dev_desc,
  49. &part_info, response));
  50. ut_asserteq(2, fastboot_mmc_get_part_info("test2", &fb_dev_desc,
  51. &part_info, response));
  52. /* Test aliases */
  53. ut_assertnull(env_get(FB_ALIAS_PREFIX "test3"));
  54. ut_assertok(env_set(FB_ALIAS_PREFIX "test3", "test1"));
  55. ut_asserteq(1, fastboot_mmc_get_part_info("test3", &fb_dev_desc,
  56. &part_info, response));
  57. ut_assertok(env_set(FB_ALIAS_PREFIX "test3", NULL));
  58. /* "New" partition labels */
  59. ut_asserteq(1, fastboot_mmc_get_part_info("#test1", &fb_dev_desc,
  60. &part_info, response));
  61. ut_asserteq(1, fastboot_mmc_get_part_info("0#test1", &fb_dev_desc,
  62. &part_info, response));
  63. ut_asserteq(1, fastboot_mmc_get_part_info("0.0#test1", &fb_dev_desc,
  64. &part_info, response));
  65. ut_asserteq(1, fastboot_mmc_get_part_info("0:1", &fb_dev_desc,
  66. &part_info, response));
  67. ut_asserteq(1, fastboot_mmc_get_part_info("0.0:1", &fb_dev_desc,
  68. &part_info, response));
  69. ut_asserteq(1, fastboot_mmc_get_part_info("0", &fb_dev_desc,
  70. &part_info, response));
  71. ut_asserteq(1, fastboot_mmc_get_part_info("0.0", &fb_dev_desc,
  72. &part_info, response));
  73. ut_asserteq(0, fastboot_mmc_get_part_info("0:0", &fb_dev_desc,
  74. &part_info, response));
  75. ut_asserteq(0, fastboot_mmc_get_part_info("0.0:0", &fb_dev_desc,
  76. &part_info, response));
  77. ut_asserteq(0, fastboot_mmc_get_part_info("1", &fb_dev_desc,
  78. &part_info, response));
  79. ut_asserteq(0, fastboot_mmc_get_part_info("1.0", &fb_dev_desc,
  80. &part_info, response));
  81. ut_asserteq(1, fastboot_mmc_get_part_info(":1", &fb_dev_desc,
  82. &part_info, response));
  83. ut_asserteq(0, fastboot_mmc_get_part_info(":0", &fb_dev_desc,
  84. &part_info, response));
  85. return 0;
  86. }
  87. DM_TEST(dm_test_fastboot_mmc_part, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);