Commit ae95fad5af3793ae804b4390727e0f431e5514d7
Committed by
Tom Rini
1 parent
fa39ffe5d6
Exists in
v2017.01-smarct4x
and in
40 other branches
disk: part_efi: add support for the Backup GPT
Check the Backup GPT table if the Primary GPT table is invalid. Renamed "Secondary GPT" to "Backup GPT" as per: UEFI Specification (Version 2.3.1, Errata A) Signed-off-by: Steve Rae <srae@broadcom.com>
Showing 2 changed files with 26 additions and 10 deletions Side-by-side Diff
disk/part_efi.c
... | ... | @@ -93,7 +93,15 @@ |
93 | 93 | if (is_gpt_valid(dev_desc, GPT_PRIMARY_PARTITION_TABLE_LBA, |
94 | 94 | gpt_head, &gpt_pte) != 1) { |
95 | 95 | printf("%s: *** ERROR: Invalid GPT ***\n", __func__); |
96 | - return; | |
96 | + if (is_gpt_valid(dev_desc, (dev_desc->lba - 1), | |
97 | + gpt_head, &gpt_pte) != 1) { | |
98 | + printf("%s: *** ERROR: Invalid Backup GPT ***\n", | |
99 | + __func__); | |
100 | + return; | |
101 | + } else { | |
102 | + printf("%s: *** Using Backup GPT ***\n", | |
103 | + __func__); | |
104 | + } | |
97 | 105 | } |
98 | 106 | |
99 | 107 | debug("%s: gpt-entry at %p\n", __func__, gpt_pte); |
... | ... | @@ -142,7 +150,15 @@ |
142 | 150 | if (is_gpt_valid(dev_desc, GPT_PRIMARY_PARTITION_TABLE_LBA, |
143 | 151 | gpt_head, &gpt_pte) != 1) { |
144 | 152 | printf("%s: *** ERROR: Invalid GPT ***\n", __func__); |
145 | - return -1; | |
153 | + if (is_gpt_valid(dev_desc, (dev_desc->lba - 1), | |
154 | + gpt_head, &gpt_pte) != 1) { | |
155 | + printf("%s: *** ERROR: Invalid Backup GPT ***\n", | |
156 | + __func__); | |
157 | + return -1; | |
158 | + } else { | |
159 | + printf("%s: *** Using Backup GPT ***\n", | |
160 | + __func__); | |
161 | + } | |
146 | 162 | } |
147 | 163 | |
148 | 164 | if (part > le32_to_cpu(gpt_head->num_partition_entries) || |
... | ... | @@ -252,7 +268,7 @@ |
252 | 268 | != pte_blk_cnt) |
253 | 269 | goto err; |
254 | 270 | |
255 | - /* recalculate the values for the Second GPT Header */ | |
271 | + /* recalculate the values for the Backup GPT Header */ | |
256 | 272 | val = le64_to_cpu(gpt_h->my_lba); |
257 | 273 | gpt_h->my_lba = gpt_h->alternate_lba; |
258 | 274 | gpt_h->alternate_lba = cpu_to_le64(val); |
doc/README.gpt
... | ... | @@ -66,14 +66,14 @@ |
66 | 66 | |Partition n | |
67 | 67 | | | |
68 | 68 | ---------------------------------------------------------- |
69 | - LBA -34 |Entry 1|Entry 2| Entry 3| Entry 4| Secondary | |
70 | - -------------------------------------------------- (bkp) | |
71 | - LBA -33 |Entries 5 - 128 | GPT | |
69 | + LBA -34 |Entry 1|Entry 2| Entry 3| Entry 4| Backup | |
70 | + -------------------------------------------------- GPT | |
71 | + LBA -33 |Entries 5 - 128 | | |
72 | 72 | | | |
73 | 73 | | | |
74 | 74 | LBA -2 | | |
75 | 75 | -------------------------------------------------- |
76 | - LBA -1 |Secondary GPT Header | | |
76 | + LBA -1 |Backup GPT Header | | |
77 | 77 | ---------------------------------------------------------- |
78 | 78 | |
79 | 79 | For a legacy reasons, GPT's LBA 0 sector has a MBR structure. It is called |
... | ... | @@ -86,7 +86,7 @@ |
86 | 86 | "LBA -1" means the last addressable block (in the mmc subsystem: |
87 | 87 | "dev_desc->lba - 1") |
88 | 88 | |
89 | -Primary/Secondary GPT header: | |
89 | +Primary/Backup GPT header: | |
90 | 90 | ---------------------------- |
91 | 91 | Offset Size Description |
92 | 92 | |
... | ... | @@ -115,7 +115,7 @@ |
115 | 115 | |
116 | 116 | GPT headers and partition entries are protected by CRC32 (the POSIX CRC32). |
117 | 117 | |
118 | -Primary GPT header and Secondary GPT header have swapped values of "Current LBA" | |
118 | +Primary GPT header and Backup GPT header have swapped values of "Current LBA" | |
119 | 119 | and "Backup LBA" and therefore different CRC32 check-sum. |
120 | 120 | |
121 | 121 | CRC32 for GPT headers (field "CRC of header") are calculated up till |
... | ... | @@ -125,7 +125,7 @@ |
125 | 125 | the whole array entry ( Number_of_partition_entries * |
126 | 126 | sizeof(partition_entry_size (usually 128))) |
127 | 127 | |
128 | -Observe, how Secondary GPT is placed in the memory. It is NOT a mirror reflect | |
128 | +Observe, how Backup GPT is placed in the memory. It is NOT a mirror reflect | |
129 | 129 | of the Primary. |
130 | 130 | |
131 | 131 | Partition Entry Format: |