diff options
author | Dan Ehrenberg <dehrenberg@chromium.org> | 2015-01-02 14:39:38 -0800 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2015-01-05 20:35:56 +0000 |
commit | f3f7fca07fbcb6bb9655a71257f09c71b0a1458d (patch) | |
tree | f11e478590427dcc3d0214c7cbe819d565d53294 /firmware/lib | |
parent | 5d652cdffa70dc772e80548a760e1f0d67de273f (diff) | |
download | vboot-f3f7fca07fbcb6bb9655a71257f09c71b0a1458d.tar.gz |
nand: vboot support for small GPTs
This patch makes some small modifications to cgpt and vboot to
root out the last vestigates of a fixed 128-entry GPT:
- Get rid of the TOTAL_ENTRIES_SIZE constant and all users.
- Reduce MAX_NUMBER_OF_ENTRIES to 128 (which is what the GPT
spec specifies) so that this can be used for things like memory
allocations without additional overhead.
- Base the amount of GPT read/written on the number of entries
specified in the GPT header on disk/flash.
BUG=chromium:433433
TEST=make runalltests
TEST=Modified fmap to make an 8k RW_GPT, wrote a GPT with cgpt, then
rebooted and found that the GPT was correctly read after restarting
and the appropriate mtd partitions were present.
BRANCH=none
Change-Id: I45317377da20259caf04a7a4fa077a892b03c45f
Signed-off-by: Dan Ehrenberg <dehrenberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/238245
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'firmware/lib')
-rw-r--r-- | firmware/lib/cgptlib/cgptlib_internal.c | 10 | ||||
-rw-r--r-- | firmware/lib/cgptlib/include/cgptlib_internal.h | 2 | ||||
-rw-r--r-- | firmware/lib/gpt_misc.c | 19 |
3 files changed, 21 insertions, 10 deletions
diff --git a/firmware/lib/cgptlib/cgptlib_internal.c b/firmware/lib/cgptlib/cgptlib_internal.c index 6a89d841..a389e695 100644 --- a/firmware/lib/cgptlib/cgptlib_internal.c +++ b/firmware/lib/cgptlib/cgptlib_internal.c @@ -40,11 +40,11 @@ int CheckParameters(GptData *gpt) /* * Sector count of a drive should be reasonable. If the given value is * too small to contain basic GPT structure (PMBR + Headers + Entries), - * the value is wrong. Entries size is hard coded to TOTAL_ENTRIES_SIZE (see - * cgpt_create.c). This check is only applicable when GPT is stored on device. + * the value is wrong. */ - if (!(gpt->flags & GPT_FLAG_EXTERNAL) && - gpt->gpt_drive_sectors < (1 + 2 * (1 + TOTAL_ENTRIES_SIZE / SECTOR_SIZE))) + if (gpt->gpt_drive_sectors < + (1 + 2 * (1 + MIN_NUMBER_OF_ENTRIES / + (SECTOR_SIZE / sizeof(GptEntry))))) return GPT_ERROR_INVALID_SECTOR_NUMBER; return GPT_SUCCESS; @@ -103,7 +103,7 @@ int CheckHeader(GptHeader *h, int is_secondary, if ((h->number_of_entries < MIN_NUMBER_OF_ENTRIES) || (h->number_of_entries > MAX_NUMBER_OF_ENTRIES) || (!(flags & GPT_FLAG_EXTERNAL) && - h->number_of_entries * h->size_of_entry != TOTAL_ENTRIES_SIZE)) + h->number_of_entries != MAX_NUMBER_OF_ENTRIES)) return 1; /* diff --git a/firmware/lib/cgptlib/include/cgptlib_internal.h b/firmware/lib/cgptlib/include/cgptlib_internal.h index b4e2f5f9..0be2bc5a 100644 --- a/firmware/lib/cgptlib/include/cgptlib_internal.h +++ b/firmware/lib/cgptlib/include/cgptlib_internal.h @@ -52,7 +52,7 @@ #define MAX_SIZE_OF_ENTRY 512 #define SIZE_OF_ENTRY_MULTIPLE 8 #define MIN_NUMBER_OF_ENTRIES 16 -#define MAX_NUMBER_OF_ENTRIES 512 +#define MAX_NUMBER_OF_ENTRIES 128 /* Defines GPT sizes */ #define GPT_PMBR_SECTORS 1 /* size (in sectors) of PMBR */ diff --git a/firmware/lib/gpt_misc.c b/firmware/lib/gpt_misc.c index c16d4729..00c7f9f2 100644 --- a/firmware/lib/gpt_misc.c +++ b/firmware/lib/gpt_misc.c @@ -23,7 +23,7 @@ */ int AllocAndReadGptData(VbExDiskHandle_t disk_handle, GptData *gptdata) { - uint64_t entries_sectors = TOTAL_ENTRIES_SIZE / gptdata->sector_bytes; + uint64_t max_entries_bytes = MAX_NUMBER_OF_ENTRIES * sizeof(GptEntry); int primary_valid = 0, secondary_valid = 0; /* No data to be written yet */ @@ -33,8 +33,8 @@ int AllocAndReadGptData(VbExDiskHandle_t disk_handle, GptData *gptdata) gptdata->primary_header = (uint8_t *)VbExMalloc(gptdata->sector_bytes); gptdata->secondary_header = (uint8_t *)VbExMalloc(gptdata->sector_bytes); - gptdata->primary_entries = (uint8_t *)VbExMalloc(TOTAL_ENTRIES_SIZE); - gptdata->secondary_entries = (uint8_t *)VbExMalloc(TOTAL_ENTRIES_SIZE); + gptdata->primary_entries = (uint8_t *)VbExMalloc(max_entries_bytes); + gptdata->secondary_entries = (uint8_t *)VbExMalloc(max_entries_bytes); if (gptdata->primary_header == NULL || gptdata->secondary_header == NULL || @@ -53,6 +53,10 @@ int AllocAndReadGptData(VbExDiskHandle_t disk_handle, GptData *gptdata) gptdata->gpt_drive_sectors, gptdata->flags)) { primary_valid = 1; + uint64_t entries_bytes = primary_header->number_of_entries + * primary_header->size_of_entry; + uint64_t entries_sectors = entries_bytes + / gptdata->sector_bytes; if (0 != VbExDiskRead(disk_handle, primary_header->entries_lba, entries_sectors, @@ -74,6 +78,10 @@ int AllocAndReadGptData(VbExDiskHandle_t disk_handle, GptData *gptdata) gptdata->gpt_drive_sectors, gptdata->flags)) { secondary_valid = 1; + uint64_t entries_bytes = secondary_header->number_of_entries + * secondary_header->size_of_entry; + uint64_t entries_sectors = entries_bytes + / gptdata->sector_bytes; if (0 != VbExDiskRead(disk_handle, secondary_header->entries_lba, entries_sectors, @@ -95,7 +103,10 @@ int AllocAndReadGptData(VbExDiskHandle_t disk_handle, GptData *gptdata) int WriteAndFreeGptData(VbExDiskHandle_t disk_handle, GptData *gptdata) { int legacy = 0; - uint64_t entries_sectors = TOTAL_ENTRIES_SIZE / gptdata->sector_bytes; + GptHeader *header = (GptHeader *)gptdata->primary_header; + uint64_t entries_bytes = header->number_of_entries + * header->size_of_entry; + uint64_t entries_sectors = entries_bytes / gptdata->sector_bytes; int ret = 1; /* |