0001-CHROMIUM-block-partitions-efi-Add-support-for-IGNORE.patch 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. From a49bd34de33ab54a1cbfdaae121dbaf99648d3b6 Mon Sep 17 00:00:00 2001
  2. From: Julius Werner <jwerner@chromium.org>
  3. Date: Wed, 20 Apr 2016 15:20:00 -0700
  4. Subject: [PATCH] CHROMIUM: block: partitions: efi: Add support for IGNOREME
  5. GPT 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. Signed-off-by: Julius Werner <jwerner@chromium.org>
  13. Reviewed-on: https://chromium-review.googlesource.com/340080
  14. Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
  15. An earlier attempt to upstream an alternative solution:
  16. https://patchwork.kernel.org/patch/8933841/
  17. mka@: added missing param 'lba' to log message and resolved minor
  18. conflicts.
  19. BUG=chromium:941638, chrome-os-partner:52595
  20. TEST=Booted on Minnie with 'IGNOREME' primary GPT
  21. Change-Id: Ibaee639fac9fa2f04b8836ef153c95b7d0b045a4
  22. Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
  23. Reviewed-on: https://chromium-review.googlesource.com/1531701
  24. Reviewed-by: Douglas Anderson <dianders@chromium.org>
  25. Reviewed-by: Julius Werner <jwerner@chromium.org>
  26. [rebase515(groeck):
  27. Squash:
  28. FIXUP: partitions/efi: Support non-standard GPT location
  29. (API change)
  30. ]
  31. Signed-off-by: Guenter Roeck <groeck@google.com>
  32. ---
  33. block/partitions/efi.c | 33 +++++++++++++++++++++++----------
  34. block/partitions/efi.h | 3 ++-
  35. 2 files changed, 25 insertions(+), 11 deletions(-)
  36. diff --git a/block/partitions/efi.c b/block/partitions/efi.c
  37. index 7ca5c4c374d4..102d2587bdb3 100644
  38. --- a/block/partitions/efi.c
  39. +++ b/block/partitions/efi.c
  40. @@ -328,23 +328,33 @@ static gpt_header *alloc_read_gpt_header(struct parsed_partitions *state,
  41. * @lba: logical block address of the GPT header to test
  42. * @gpt: GPT header ptr, filled on return.
  43. * @ptes: PTEs ptr, filled on return.
  44. + * @ignored is filled on return with 1 if this is an IGNOREME GPT,
  45. + * 0 otherwise. May be NULL.
  46. *
  47. * Description: returns 1 if valid, 0 on error.
  48. * If valid, returns pointers to newly allocated GPT header and PTEs.
  49. */
  50. static int is_gpt_valid(struct parsed_partitions *state, u64 lba,
  51. - gpt_header **gpt, gpt_entry **ptes)
  52. + gpt_header **gpt, gpt_entry **ptes, int *ignored)
  53. {
  54. u32 crc, origcrc;
  55. u64 lastlba, pt_size;
  56. + if (ignored)
  57. + *ignored = 0;
  58. if (!ptes)
  59. return 0;
  60. if (!(*gpt = alloc_read_gpt_header(state, lba)))
  61. return 0;
  62. /* Check the GUID Partition Table signature */
  63. - if (le64_to_cpu((*gpt)->signature) != GPT_HEADER_SIGNATURE) {
  64. + if (le64_to_cpu((*gpt)->signature) == GPT_HEADER_SIGNATURE_IGNORED) {
  65. + pr_debug("GUID Partition Table at LBA %llu marked IGNOREME\n",
  66. + lba);
  67. + if (ignored)
  68. + *ignored = 1;
  69. + goto fail;
  70. + } else if (le64_to_cpu((*gpt)->signature) != GPT_HEADER_SIGNATURE) {
  71. pr_debug("GUID Partition Table Header signature is wrong:"
  72. "%lld != %lld\n",
  73. (unsigned long long)le64_to_cpu((*gpt)->signature),
  74. @@ -581,7 +591,7 @@ compare_gpts(gpt_header *pgpt, gpt_header *agpt, u64 lastlba)
  75. static int find_valid_gpt(struct parsed_partitions *state, gpt_header **gpt,
  76. gpt_entry **ptes)
  77. {
  78. - int good_pgpt = 0, good_agpt = 0, good_pmbr = 0;
  79. + int good_pgpt = 0, good_agpt = 0, good_pmbr = 0, pgpt_ignored = 0;
  80. gpt_header *pgpt = NULL, *agpt = NULL;
  81. gpt_entry *pptes = NULL, *aptes = NULL;
  82. legacy_mbr *legacymbr;
  83. @@ -613,13 +623,14 @@ static int find_valid_gpt(struct parsed_partitions *state, gpt_header **gpt,
  84. }
  85. good_pgpt = is_gpt_valid(state, GPT_PRIMARY_PARTITION_TABLE_LBA,
  86. - &pgpt, &pptes);
  87. + &pgpt, &pptes, &pgpt_ignored);
  88. if (good_pgpt)
  89. good_agpt = is_gpt_valid(state,
  90. le64_to_cpu(pgpt->alternate_lba),
  91. - &agpt, &aptes);
  92. - if (!good_agpt && force_gpt)
  93. - good_agpt = is_gpt_valid(state, lastlba, &agpt, &aptes);
  94. + &agpt, &aptes, NULL);
  95. +
  96. + if (!good_agpt && (force_gpt || pgpt_ignored))
  97. + good_agpt = is_gpt_valid(state, lastlba, &agpt, &aptes, NULL);
  98. if (!good_agpt && force_gpt && fops->alternative_gpt_sector) {
  99. sector_t agpt_sector;
  100. @@ -628,14 +639,15 @@ static int find_valid_gpt(struct parsed_partitions *state, gpt_header **gpt,
  101. err = fops->alternative_gpt_sector(disk, &agpt_sector);
  102. if (!err)
  103. good_agpt = is_gpt_valid(state, agpt_sector,
  104. - &agpt, &aptes);
  105. + &agpt, &aptes, NULL);
  106. }
  107. /* The obviously unsuccessful case */
  108. if (!good_pgpt && !good_agpt)
  109. goto fail;
  110. - compare_gpts(pgpt, agpt, lastlba);
  111. + if (!pgpt_ignored)
  112. + compare_gpts(pgpt, agpt, lastlba);
  113. /* The good cases */
  114. if (good_pgpt) {
  115. @@ -652,7 +664,8 @@ static int find_valid_gpt(struct parsed_partitions *state, gpt_header **gpt,
  116. *ptes = aptes;
  117. kfree(pgpt);
  118. kfree(pptes);
  119. - pr_warn("Primary GPT is invalid, using alternate GPT.\n");
  120. + pr_warn("Primary GPT is %s, using alternate GPT.\n",
  121. + pgpt_ignored ? "being ignored" : "invalid");
  122. return 1;
  123. }
  124. diff --git a/block/partitions/efi.h b/block/partitions/efi.h
  125. index 8cc2b88d0aa8..fcf65ebbaa85 100644
  126. --- a/block/partitions/efi.h
  127. +++ b/block/partitions/efi.h
  128. @@ -27,7 +27,8 @@
  129. #define GPT_MBR_PROTECTIVE 1
  130. #define GPT_MBR_HYBRID 2
  131. -#define GPT_HEADER_SIGNATURE 0x5452415020494645ULL
  132. +#define GPT_HEADER_SIGNATURE 0x5452415020494645ULL /* 'EFI PART' */
  133. +#define GPT_HEADER_SIGNATURE_IGNORED 0x454d45524f4e4749ULL /* 'IGNOREME' */
  134. #define GPT_HEADER_REVISION_V1 0x00010000
  135. #define GPT_PRIMARY_PARTITION_TABLE_LBA 1
  136. --
  137. 2.36.1