0001-block-partitions-efi-Add-support-for-IGNOREME-GPT-si.patch 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. From 0f09019241a0ea6eee0b9b596a70ec8a66b820ce Mon Sep 17 00:00:00 2001
  2. From: SolidHal <hal@halemmerich.com>
  3. Date: Fri, 24 Aug 2018 11:04:43 -0500
  4. Subject: [PATCH] block: partitions: efi: Add support for IGNOREME GPT
  5. signature
  6. This patch adds support for a special GPT header signature marker (using
  7. the string 'IGNOREME' instead of the spec's 'EFI PART'). This tells the
  8. kernel to ignore this GPT completely and look at the other one instead.
  9. Since the kernel always prefers the primary GPT anyway, all we really
  10. need to do effectively is to check whether the primary GPT is marked
  11. 'IGNOREME' and force evaluation of the secondary one in that case.
  12. Borrowed from the chrome os 3.14 kernel, the commit can be found here:
  13. https://chromium.googlesource.com/chromiumos/third_party/kernel/+/abba28d0a1b7361da6e2023352e92687166ca30d
  14. Also bundled in this commit
  15. https://chromium.googlesource.com/chromiumos/third_party/kernel/+/bd0c62c7de0c8a63314b7955e5718d8f6192f9d2%5E%21/#F0
  16. Which is a small compiler warning fix for the above patch
  17. This patch fixes how the kernel detects and handles certain mmc
  18. manufatures devices, and allows the partitions on the mmc to be bootable
  19. and mountable.
  20. Signed-off-by: SolidHal <hal@halemmerich.com>
  21. ---
  22. block/partitions/efi.c | 31 ++++++++++++++++++++++---------
  23. block/partitions/efi.h | 3 ++-
  24. 2 files changed, 24 insertions(+), 10 deletions(-)
  25. diff --git a/block/partitions/efi.c b/block/partitions/efi.c
  26. index 39f70d9..aa08380 100644
  27. --- a/block/partitions/efi.c
  28. +++ b/block/partitions/efi.c
  29. @@ -344,23 +344,34 @@ static gpt_header *alloc_read_gpt_header(struct parsed_partitions *state,
  30. * @lba: logical block address of the GPT header to test
  31. * @gpt: GPT header ptr, filled on return.
  32. * @ptes: PTEs ptr, filled on return.
  33. + * @ignored is filled on return with 1 if this is an IGNOREME GPT,
  34. + * 0 otherwise. May be NULL.
  35. *
  36. * Description: returns 1 if valid, 0 on error.
  37. * If valid, returns pointers to newly allocated GPT header and PTEs.
  38. */
  39. static int is_gpt_valid(struct parsed_partitions *state, u64 lba,
  40. - gpt_header **gpt, gpt_entry **ptes)
  41. + gpt_header **gpt, gpt_entry **ptes, int *ignored)
  42. {
  43. u32 crc, origcrc;
  44. u64 lastlba, pt_size;
  45. + if (ignored)
  46. + *ignored = 0;
  47. if (!ptes)
  48. return 0;
  49. if (!(*gpt = alloc_read_gpt_header(state, lba)))
  50. return 0;
  51. /* Check the GUID Partition Table signature */
  52. - if (le64_to_cpu((*gpt)->signature) != GPT_HEADER_SIGNATURE) {
  53. +
  54. + if (le64_to_cpu((*gpt)->signature) == GPT_HEADER_SIGNATURE_IGNORED) {
  55. + pr_debug("GUID Partition Table at LBA %llu marked IGNOREME\n",
  56. + (unsigned long long)lba);
  57. + if (ignored)
  58. + *ignored = 1;
  59. + goto fail;
  60. + } else if (le64_to_cpu((*gpt)->signature) != GPT_HEADER_SIGNATURE) {
  61. pr_debug("GUID Partition Table Header signature is wrong:"
  62. "%lld != %lld\n",
  63. (unsigned long long)le64_to_cpu((*gpt)->signature),
  64. @@ -597,7 +608,7 @@ compare_gpts(gpt_header *pgpt, gpt_header *agpt, u64 lastlba)
  65. static int find_valid_gpt(struct parsed_partitions *state, gpt_header **gpt,
  66. gpt_entry **ptes)
  67. {
  68. - int good_pgpt = 0, good_agpt = 0, good_pmbr = 0;
  69. + int good_pgpt = 0, good_agpt = 0, good_pmbr = 0, pgpt_ignored = 0;
  70. gpt_header *pgpt = NULL, *agpt = NULL;
  71. gpt_entry *pptes = NULL, *aptes = NULL;
  72. legacy_mbr *legacymbr;
  73. @@ -627,19 +638,20 @@ static int find_valid_gpt(struct parsed_partitions *state, gpt_header **gpt,
  74. }
  75. good_pgpt = is_gpt_valid(state, GPT_PRIMARY_PARTITION_TABLE_LBA,
  76. - &pgpt, &pptes);
  77. + &pgpt, &pptes, &pgpt_ignored);
  78. if (good_pgpt)
  79. good_agpt = is_gpt_valid(state,
  80. le64_to_cpu(pgpt->alternate_lba),
  81. - &agpt, &aptes);
  82. - if (!good_agpt && force_gpt)
  83. - good_agpt = is_gpt_valid(state, lastlba, &agpt, &aptes);
  84. + &agpt, &aptes, NULL);
  85. + if (!good_agpt && (force_gpt || pgpt_ignored))
  86. + good_agpt = is_gpt_valid(state, lastlba, &agpt, &aptes, NULL);
  87. /* The obviously unsuccessful case */
  88. if (!good_pgpt && !good_agpt)
  89. goto fail;
  90. - compare_gpts(pgpt, agpt, lastlba);
  91. + if (!pgpt_ignored)
  92. + compare_gpts(pgpt, agpt, lastlba);
  93. /* The good cases */
  94. if (good_pgpt) {
  95. @@ -656,7 +668,8 @@ static int find_valid_gpt(struct parsed_partitions *state, gpt_header **gpt,
  96. *ptes = aptes;
  97. kfree(pgpt);
  98. kfree(pptes);
  99. - pr_warn("Primary GPT is invalid, using alternate GPT.\n");
  100. + pr_warn("Primary GPT is %s, using alternate GPT.\n",
  101. + pgpt_ignored ? "being ignored" : "invalid");
  102. return 1;
  103. }
  104. diff --git a/block/partitions/efi.h b/block/partitions/efi.h
  105. index abd0b19..36cddc8 100644
  106. --- a/block/partitions/efi.h
  107. +++ b/block/partitions/efi.h
  108. @@ -41,7 +41,8 @@
  109. #define GPT_MBR_PROTECTIVE 1
  110. #define GPT_MBR_HYBRID 2
  111. -#define GPT_HEADER_SIGNATURE 0x5452415020494645ULL
  112. +#define GPT_HEADER_SIGNATURE 0x5452415020494645ULL /* 'EFI PART' */
  113. +#define GPT_HEADER_SIGNATURE_IGNORED 0x454d45524f4e4749ULL /* 'IGNOREME' */
  114. #define GPT_HEADER_REVISION_V1 0x00010000
  115. #define GPT_PRIMARY_PARTITION_TABLE_LBA 1
  116. --
  117. 2.11.0