summaryrefslogtreecommitdiff
path: root/firmware/lib/gpt_misc.c
diff options
context:
space:
mode:
authorDan Ehrenberg <dehrenberg@chromium.org>2015-04-22 11:00:51 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-04-29 00:21:30 +0000
commitd7da706484823654f4f7f50b8d30f4d7a9d61089 (patch)
treeac15a3dbb490cb0976bae3fa51bb811ae7eb74ba /firmware/lib/gpt_misc.c
parente2e14ae8274ef85041bf3b25a87a465380fe2ced (diff)
downloadvboot-d7da706484823654f4f7f50b8d30f4d7a9d61089.tar.gz
cgpt: Handle read errors gracefullystabilize-7019.Bstabilize-7018.B
When a read fails in getting the GPT, just zero the contents of the buffer and carry on. Some testing changes are required for this. When a read of the GPT fails, it is no longer fatal, so tests of that have been adjusted. Tests have been improved to show that the GPT is automatically repaired when a read error occurs. There was one test which checked that a zero-sized disk would fail to load a kernel, but it was surrounded by a number of mocked functions which normally do that error checking, and it amounted to the same test as read failure; that test was deleted. BUG=chrome-os-partner:35440 TEST=vboot tests pass BRANCH=none Change-Id: I0c05813e7492920433733947d3fb74a7e4aa66f2 Signed-off-by: Dan Ehrenberg <dehrenberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/266882 Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'firmware/lib/gpt_misc.c')
-rw-r--r--firmware/lib/gpt_misc.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/firmware/lib/gpt_misc.c b/firmware/lib/gpt_misc.c
index 4061bdd9..cff9221f 100644
--- a/firmware/lib/gpt_misc.c
+++ b/firmware/lib/gpt_misc.c
@@ -43,8 +43,10 @@ int AllocAndReadGptData(VbExDiskHandle_t disk_handle, GptData *gptdata)
return 1;
/* Read primary header from the drive, skipping the protective MBR */
- if (0 != VbExDiskRead(disk_handle, 1, 1, gptdata->primary_header))
- return 1;
+ if (0 != VbExDiskRead(disk_handle, 1, 1, gptdata->primary_header)) {
+ VBDEBUG(("Read error in primary GPT header\n"));
+ Memset(gptdata->primary_header, 0, gptdata->sector_bytes);
+ }
/* Only read primary GPT if the primary header is valid */
GptHeader* primary_header = (GptHeader*)gptdata->primary_header;
@@ -60,16 +62,20 @@ int AllocAndReadGptData(VbExDiskHandle_t disk_handle, GptData *gptdata)
if (0 != VbExDiskRead(disk_handle,
primary_header->entries_lba,
entries_sectors,
- gptdata->primary_entries))
- return 1;
+ gptdata->primary_entries)) {
+ VBDEBUG(("Read error in primary GPT entries\n"));
+ primary_valid = 0;
+ }
} else {
VBDEBUG(("Primary GPT header invalid!\n"));
}
/* Read secondary header from the end of the drive */
if (0 != VbExDiskRead(disk_handle, gptdata->gpt_drive_sectors - 1, 1,
- gptdata->secondary_header))
- return 1;
+ gptdata->secondary_header)) {
+ VBDEBUG(("Read error in secondary GPT header\n"));
+ Memset(gptdata->secondary_header, 0, gptdata->sector_bytes);
+ }
/* Only read secondary GPT if the secondary header is valid */
GptHeader* secondary_header = (GptHeader*)gptdata->secondary_header;
@@ -85,8 +91,10 @@ int AllocAndReadGptData(VbExDiskHandle_t disk_handle, GptData *gptdata)
if (0 != VbExDiskRead(disk_handle,
secondary_header->entries_lba,
entries_sectors,
- gptdata->secondary_entries))
- return 1;
+ gptdata->secondary_entries)) {
+ VBDEBUG(("Read error in secondary GPT entries\n"));
+ secondary_valid = 0;
+ }
} else {
VBDEBUG(("Secondary GPT header invalid!\n"));
}