summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
authorDan Ehrenberg <dehrenberg@chromium.org>2014-11-06 16:22:24 -0800
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-11-14 22:46:54 +0000
commita524a3a51591618c1395cb9e1238ee72b3f5e767 (patch)
treee3ba27f590375e71ff40d8df29c9e04466a743bb /firmware
parent837b408c92d02108cbb16a97769675f39598d576 (diff)
downloadvboot-a524a3a51591618c1395cb9e1238ee72b3f5e767.tar.gz
vboot: cgpt: fix my_lba of the secondary GPT
Previously, my_lba of the secondary GPT was recorded as if that GPT was written at the end of the device. This patch tweaks my_lba to report where it is in the random-access GPT address space, namely at the end of that space. TEST=Compiled it into the firmware and observed the firmware to update the my_lba field of the secondary GPT. BRANCH=none BUG=chromium:425677 Signed-off-by: Dan Ehrenberg <dehrenberg@chromium.org> Change-Id: I88791fb2cff1086351ca8a3adeef675c4a88cc9a Reviewed-on: https://chromium-review.googlesource.com/228942 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Commit-Queue: Daniel Ehrenberg <dehrenberg@chromium.org> Tested-by: Daniel Ehrenberg <dehrenberg@chromium.org>
Diffstat (limited to 'firmware')
-rw-r--r--firmware/lib/cgptlib/cgptlib_internal.c12
-rw-r--r--firmware/lib/cgptlib/include/cgptlib_internal.h2
-rw-r--r--firmware/lib/gpt_misc.c6
3 files changed, 12 insertions, 8 deletions
diff --git a/firmware/lib/cgptlib/cgptlib_internal.c b/firmware/lib/cgptlib/cgptlib_internal.c
index e9f27c96..48b527ac 100644
--- a/firmware/lib/cgptlib/cgptlib_internal.c
+++ b/firmware/lib/cgptlib/cgptlib_internal.c
@@ -54,7 +54,7 @@ uint32_t HeaderCrc(GptHeader *h)
}
int CheckHeader(GptHeader *h, int is_secondary, uint64_t drive_sectors,
- uint8_t stored_on_device)
+ uint64_t gpt_drive_sectors, uint8_t stored_on_device)
{
if (!h)
return 1;
@@ -101,7 +101,7 @@ int CheckHeader(GptHeader *h, int is_secondary, uint64_t drive_sectors,
* secondary is at the end of the drive, preceded by its entries.
*/
if (is_secondary) {
- if (h->my_lba != drive_sectors - GPT_HEADER_SECTORS)
+ if (h->my_lba != gpt_drive_sectors - GPT_HEADER_SECTORS)
return 1;
if (h->entries_lba != h->my_lba - GPT_ENTRIES_SECTORS)
return 1;
@@ -245,11 +245,13 @@ int GptSanityCheck(GptData *gpt)
return retval;
/* Check both headers; we need at least one valid header. */
- if (0 == CheckHeader(header1, 0, gpt->drive_sectors, gpt->stored_on_device)) {
+ if (0 == CheckHeader(header1, 0, gpt->drive_sectors,
+ gpt->gpt_drive_sectors, gpt->stored_on_device)) {
gpt->valid_headers |= MASK_PRIMARY;
goodhdr = header1;
}
- if (0 == CheckHeader(header2, 1, gpt->drive_sectors, gpt->stored_on_device)) {
+ if (0 == CheckHeader(header2, 1, gpt->drive_sectors,
+ gpt->gpt_drive_sectors, gpt->stored_on_device)) {
gpt->valid_headers |= MASK_SECONDARY;
if (!goodhdr)
goodhdr = header2;
@@ -320,7 +322,7 @@ void GptRepair(GptData *gpt)
if (MASK_PRIMARY == gpt->valid_headers) {
/* Primary is good, secondary is bad */
Memcpy(header2, header1, sizeof(GptHeader));
- header2->my_lba = gpt->drive_sectors - GPT_HEADER_SECTORS;
+ header2->my_lba = gpt->gpt_drive_sectors - GPT_HEADER_SECTORS;
header2->alternate_lba = GPT_PMBR_SECTORS; /* Second sector. */
header2->entries_lba = header2->my_lba - GPT_ENTRIES_SECTORS;
header2->header_crc32 = HeaderCrc(header2);
diff --git a/firmware/lib/cgptlib/include/cgptlib_internal.h b/firmware/lib/cgptlib/include/cgptlib_internal.h
index 4a52420c..825bbbb2 100644
--- a/firmware/lib/cgptlib/include/cgptlib_internal.h
+++ b/firmware/lib/cgptlib/include/cgptlib_internal.h
@@ -91,7 +91,7 @@ int CheckParameters(GptData* gpt);
* Returns 0 if header is valid, 1 if invalid.
*/
int CheckHeader(GptHeader *h, int is_secondary, uint64_t drive_sectors,
- uint8_t stored_on_device);
+ uint64_t gpt_drive_sectors, uint8_t stored_on_device);
/**
* Calculate and return the header CRC.
diff --git a/firmware/lib/gpt_misc.c b/firmware/lib/gpt_misc.c
index 499cc9e7..dc15d915 100644
--- a/firmware/lib/gpt_misc.c
+++ b/firmware/lib/gpt_misc.c
@@ -48,7 +48,8 @@ int AllocAndReadGptData(VbExDiskHandle_t disk_handle, GptData *gptdata)
/* Only read primary GPT if the primary header is valid */
GptHeader* primary_header = (GptHeader*)gptdata->primary_header;
- if (0 == CheckHeader(primary_header, 0, gptdata->gpt_drive_sectors,
+ if (0 == CheckHeader(primary_header, 0, gptdata->drive_sectors,
+ gptdata->gpt_drive_sectors,
gptdata->stored_on_device)) {
primary_valid = 1;
if (0 != VbExDiskRead(disk_handle,
@@ -67,7 +68,8 @@ int AllocAndReadGptData(VbExDiskHandle_t disk_handle, GptData *gptdata)
/* Only read secondary GPT if the secondary header is valid */
GptHeader* secondary_header = (GptHeader*)gptdata->secondary_header;
- if (0 == CheckHeader(secondary_header, 1, gptdata->gpt_drive_sectors,
+ if (0 == CheckHeader(secondary_header, 1, gptdata->drive_sectors,
+ gptdata->gpt_drive_sectors,
gptdata->stored_on_device)) {
secondary_valid = 1;
if (0 != VbExDiskRead(disk_handle,