summaryrefslogtreecommitdiff
path: root/firmware/lib/gpt_misc.c
diff options
context:
space:
mode:
authorJulius Werner <jwerner@chromium.org>2016-04-19 16:55:36 -0700
committerchrome-bot <chrome-bot@chromium.org>2016-04-25 15:15:32 -0700
commit39910d062dffcd16683e0626dac1e7064991c7e5 (patch)
tree0985bb84a411aaa6d46eb3d2a4f3dbbac76e8865 /firmware/lib/gpt_misc.c
parent5de0000ece70bf419130db9bdbaf444ffc98bf30 (diff)
downloadvboot-39910d062dffcd16683e0626dac1e7064991c7e5.tar.gz
cgptlib: Add support for IGNOREME GPT signature
This patch makes cgpt aware of a special "IGNOREME" GPT header signature string that may appear in either the primary or the secondary GPT and cause cgpt (and other cgptlib clients) to completely ignore that GPT. It will continue to function correctly for all other purposes (using the data from the non-ignored GPT), but never write any data back to the ignored GPT. BRANCH=None BUG=chrome-os-partner:52595 TEST=unit tests Change-Id: I7e53542385ae9d8d24dc25b75e91f4ff4917f66f Signed-off-by: Julius Werner <jwerner@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/340072 Reviewed-by: Nam Nguyen <namnguyen@google.com>
Diffstat (limited to 'firmware/lib/gpt_misc.c')
-rw-r--r--firmware/lib/gpt_misc.c66
1 files changed, 34 insertions, 32 deletions
diff --git a/firmware/lib/gpt_misc.c b/firmware/lib/gpt_misc.c
index cff9221f..0bf09401 100644
--- a/firmware/lib/gpt_misc.c
+++ b/firmware/lib/gpt_misc.c
@@ -28,6 +28,8 @@ int AllocAndReadGptData(VbExDiskHandle_t disk_handle, GptData *gptdata)
/* No data to be written yet */
gptdata->modified = 0;
+ /* This should get overwritten by GptInit() */
+ gptdata->ignored = 0;
/* Allocate all buffers */
gptdata->primary_header = (uint8_t *)VbExMalloc(gptdata->sector_bytes);
@@ -67,7 +69,11 @@ int AllocAndReadGptData(VbExDiskHandle_t disk_handle, GptData *gptdata)
primary_valid = 0;
}
} else {
- VBDEBUG(("Primary GPT header invalid!\n"));
+ VBDEBUG(("Primary GPT header is %s\n",
+ Memcmp(primary_header->signature,
+ GPT_HEADER_SIGNATURE_IGNORED,
+ GPT_HEADER_SIGNATURE_SIZE)
+ ? "invalid" : "being ignored"));
}
/* Read secondary header from the end of the drive */
@@ -96,7 +102,11 @@ int AllocAndReadGptData(VbExDiskHandle_t disk_handle, GptData *gptdata)
secondary_valid = 0;
}
} else {
- VBDEBUG(("Secondary GPT header invalid!\n"));
+ VBDEBUG(("Secondary GPT header is %s\n",
+ Memcmp(secondary_header->signature,
+ GPT_HEADER_SIGNATURE_IGNORED,
+ GPT_HEADER_SIGNATURE_SIZE)
+ ? "invalid" : "being ignored"));
}
/* Return 0 if least one GPT header was valid */
@@ -110,7 +120,7 @@ int AllocAndReadGptData(VbExDiskHandle_t disk_handle, GptData *gptdata)
*/
int WriteAndFreeGptData(VbExDiskHandle_t disk_handle, GptData *gptdata)
{
- int legacy = 0;
+ int skip_primary = 0;
GptHeader *header = (GptHeader *)gptdata->primary_header;
uint64_t entries_bytes = header->number_of_entries
* header->size_of_entry;
@@ -126,19 +136,16 @@ int WriteAndFreeGptData(VbExDiskHandle_t disk_handle, GptData *gptdata)
GptHeader *h = (GptHeader *)(gptdata->primary_header);
entries_lba = h->entries_lba;
- /*
- * Avoid even looking at this data if we don't need to. We
- * may in fact not have read it from disk if the read failed,
- * and this avoids a valgrind complaint.
- */
- if (gptdata->modified) {
- legacy = !Memcmp(h->signature, GPT_HEADER_SIGNATURE2,
- GPT_HEADER_SIGNATURE_SIZE);
- }
- if (gptdata->modified & GPT_MODIFIED_HEADER1) {
- if (legacy) {
- VBDEBUG(("Not updating GPT header 1: "
+ if (gptdata->ignored & MASK_PRIMARY) {
+ VBDEBUG(("Not updating primary GPT: "
+ "marked to be ignored.\n"));
+ skip_primary = 1;
+ } else if (gptdata->modified & GPT_MODIFIED_HEADER1) {
+ if (!Memcmp(h->signature, GPT_HEADER_SIGNATURE2,
+ GPT_HEADER_SIGNATURE_SIZE)) {
+ VBDEBUG(("Not updating primary GPT: "
"legacy mode is enabled.\n"));
+ skip_primary = 1;
} else {
VBDEBUG(("Updating GPT header 1\n"));
if (0 != VbExDiskWrite(disk_handle, 1, 1,
@@ -148,28 +155,23 @@ int WriteAndFreeGptData(VbExDiskHandle_t disk_handle, GptData *gptdata)
}
}
- if (gptdata->primary_entries) {
+ if (gptdata->primary_entries && !skip_primary) {
if (gptdata->modified & GPT_MODIFIED_ENTRIES1) {
- if (legacy) {
- VBDEBUG(("Not updating GPT entries 1: "
- "legacy mode is enabled.\n"));
- } else {
- VBDEBUG(("Updating GPT entries 1\n"));
- if (0 != VbExDiskWrite(disk_handle, entries_lba,
- entries_sectors,
- gptdata->primary_entries))
- goto fail;
- }
+ VBDEBUG(("Updating GPT entries 1\n"));
+ if (0 != VbExDiskWrite(disk_handle, entries_lba,
+ entries_sectors,
+ gptdata->primary_entries))
+ goto fail;
}
}
entries_lba = (gptdata->gpt_drive_sectors - entries_sectors -
GPT_HEADER_SECTORS);
- if (gptdata->secondary_header) {
+ if (gptdata->secondary_header && !(gptdata->ignored & MASK_SECONDARY)) {
GptHeader *h = (GptHeader *)(gptdata->secondary_header);
entries_lba = h->entries_lba;
if (gptdata->modified & GPT_MODIFIED_HEADER2) {
- VBDEBUG(("Updating GPT entries 2\n"));
+ VBDEBUG(("Updating GPT header 2\n"));
if (0 != VbExDiskWrite(disk_handle,
gptdata->gpt_drive_sectors - 1, 1,
gptdata->secondary_header))
@@ -177,12 +179,12 @@ int WriteAndFreeGptData(VbExDiskHandle_t disk_handle, GptData *gptdata)
}
}
- if (gptdata->secondary_entries) {
+ if (gptdata->secondary_entries && !(gptdata->ignored & MASK_SECONDARY)){
if (gptdata->modified & GPT_MODIFIED_ENTRIES2) {
- VBDEBUG(("Updating GPT header 2\n"));
+ VBDEBUG(("Updating GPT entries 2\n"));
if (0 != VbExDiskWrite(disk_handle,
- entries_lba, entries_sectors,
- gptdata->secondary_entries))
+ entries_lba, entries_sectors,
+ gptdata->secondary_entries))
goto fail;
}
}