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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. From 2b4a8bfd9379fd9431d517e4db20c57468ecf3e6 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. ---
  27. block/partitions/efi.c | 31 ++++++++++++++++++++++---------
  28. block/partitions/efi.h | 3 ++-
  29. 2 files changed, 24 insertions(+), 10 deletions(-)
  30. diff --git a/block/partitions/efi.c b/block/partitions/efi.c
  31. index db2fef7dfc47..90103e0471c4 100644
  32. --- a/block/partitions/efi.c
  33. +++ b/block/partitions/efi.c
  34. @@ -330,23 +330,33 @@ static gpt_header *alloc_read_gpt_header(struct parsed_partitions *state,
  35. * @lba: logical block address of the GPT header to test
  36. * @gpt: GPT header ptr, filled on return.
  37. * @ptes: PTEs ptr, filled on return.
  38. + * @ignored is filled on return with 1 if this is an IGNOREME GPT,
  39. + * 0 otherwise. May be NULL.
  40. *
  41. * Description: returns 1 if valid, 0 on error.
  42. * If valid, returns pointers to newly allocated GPT header and PTEs.
  43. */
  44. static int is_gpt_valid(struct parsed_partitions *state, u64 lba,
  45. - gpt_header **gpt, gpt_entry **ptes)
  46. + gpt_header **gpt, gpt_entry **ptes, int *ignored)
  47. {
  48. u32 crc, origcrc;
  49. u64 lastlba, pt_size;
  50. + if (ignored)
  51. + *ignored = 0;
  52. if (!ptes)
  53. return 0;
  54. if (!(*gpt = alloc_read_gpt_header(state, lba)))
  55. return 0;
  56. /* Check the GUID Partition Table signature */
  57. - if (le64_to_cpu((*gpt)->signature) != GPT_HEADER_SIGNATURE) {
  58. + if (le64_to_cpu((*gpt)->signature) == GPT_HEADER_SIGNATURE_IGNORED) {
  59. + pr_debug("GUID Partition Table at LBA %llu marked IGNOREME\n",
  60. + lba);
  61. + if (ignored)
  62. + *ignored = 1;
  63. + goto fail;
  64. + } else if (le64_to_cpu((*gpt)->signature) != GPT_HEADER_SIGNATURE) {
  65. pr_debug("GUID Partition Table Header signature is wrong:"
  66. "%lld != %lld\n",
  67. (unsigned long long)le64_to_cpu((*gpt)->signature),
  68. @@ -583,7 +593,7 @@ compare_gpts(gpt_header *pgpt, gpt_header *agpt, u64 lastlba)
  69. static int find_valid_gpt(struct parsed_partitions *state, gpt_header **gpt,
  70. gpt_entry **ptes)
  71. {
  72. - int good_pgpt = 0, good_agpt = 0, good_pmbr = 0;
  73. + int good_pgpt = 0, good_agpt = 0, good_pmbr = 0, pgpt_ignored = 0;
  74. gpt_header *pgpt = NULL, *agpt = NULL;
  75. gpt_entry *pptes = NULL, *aptes = NULL;
  76. legacy_mbr *legacymbr;
  77. @@ -613,19 +623,21 @@ static int find_valid_gpt(struct parsed_partitions *state, gpt_header **gpt,
  78. }
  79. good_pgpt = is_gpt_valid(state, GPT_PRIMARY_PARTITION_TABLE_LBA,
  80. - &pgpt, &pptes);
  81. + &pgpt, &pptes, &pgpt_ignored);
  82. if (good_pgpt)
  83. good_agpt = is_gpt_valid(state,
  84. le64_to_cpu(pgpt->alternate_lba),
  85. - &agpt, &aptes);
  86. - if (!good_agpt && force_gpt)
  87. - good_agpt = is_gpt_valid(state, lastlba, &agpt, &aptes);
  88. + &agpt, &aptes, NULL);
  89. +
  90. + if (!good_agpt && (force_gpt || pgpt_ignored))
  91. + good_agpt = is_gpt_valid(state, lastlba, &agpt, &aptes, NULL);
  92. /* The obviously unsuccessful case */
  93. if (!good_pgpt && !good_agpt)
  94. goto fail;
  95. - compare_gpts(pgpt, agpt, lastlba);
  96. + if (!pgpt_ignored)
  97. + compare_gpts(pgpt, agpt, lastlba);
  98. /* The good cases */
  99. if (good_pgpt) {
  100. @@ -642,7 +654,8 @@ static int find_valid_gpt(struct parsed_partitions *state, gpt_header **gpt,
  101. *ptes = aptes;
  102. kfree(pgpt);
  103. kfree(pptes);
  104. - pr_warn("Primary GPT is invalid, using alternate GPT.\n");
  105. + pr_warn("Primary GPT is %s, using alternate GPT.\n",
  106. + pgpt_ignored ? "being ignored" : "invalid");
  107. return 1;
  108. }
  109. diff --git a/block/partitions/efi.h b/block/partitions/efi.h
  110. index 3e8576157575..260c24c54750 100644
  111. --- a/block/partitions/efi.h
  112. +++ b/block/partitions/efi.h
  113. @@ -27,7 +27,8 @@
  114. #define GPT_MBR_PROTECTIVE 1
  115. #define GPT_MBR_HYBRID 2
  116. -#define GPT_HEADER_SIGNATURE 0x5452415020494645ULL
  117. +#define GPT_HEADER_SIGNATURE 0x5452415020494645ULL /* 'EFI PART' */
  118. +#define GPT_HEADER_SIGNATURE_IGNORED 0x454d45524f4e4749ULL /* 'IGNOREME' */
  119. #define GPT_HEADER_REVISION_V1 0x00010000
  120. #define GPT_PRIMARY_PARTITION_TABLE_LBA 1
  121. --
  122. 2.25.0