aboutsummaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
authorNam T. Nguyen <namnguyen@chromium.org>2014-12-12 09:38:35 -0800
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-12-12 23:15:08 +0000
commit3200401242aec1521e7c4a8b1906366fcabfb1a2 (patch)
tree9e26df71f99eb92a09871ad64d66236d133cbe4d /firmware
parent32a999d2c0e5bf8a1c0f6141d3db77a1dcc6f5af (diff)
downloadvboot_reference-3200401242aec1521e7c4a8b1906366fcabfb1a2.tar.gz
cgpt: Support non-standard (smaller) entries table
The standard says that entries table must be at least 16384 bytes. On some of our devices, the NOR section is only 8 KiB and used to store both primary and secondary tables. On this device, we can only store 24 entries. Therefore, this CL adds support for non-standard entry table. It adjusts the MIN_NUMBER_OF_ENTRIES to 16, and replaces GPT_ENTRIES_SECTORS with CalculateEntriesSectors. BUG=chromium:441812 BRANCH=none TEST=unittest Change-Id: I6b85b35ce5612c7abb22142f8252bd0d45b676c5 Reviewed-on: https://chromium-review.googlesource.com/234996 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Commit-Queue: Nam Nguyen <namnguyen@chromium.org> Tested-by: Nam Nguyen <namnguyen@chromium.org>
Diffstat (limited to 'firmware')
-rw-r--r--firmware/lib/cgptlib/cgptlib_internal.c23
-rw-r--r--firmware/lib/cgptlib/include/cgptlib_internal.h12
2 files changed, 22 insertions, 13 deletions
diff --git a/firmware/lib/cgptlib/cgptlib_internal.c b/firmware/lib/cgptlib/cgptlib_internal.c
index 5e2889c6..6a89d841 100644
--- a/firmware/lib/cgptlib/cgptlib_internal.c
+++ b/firmware/lib/cgptlib/cgptlib_internal.c
@@ -12,11 +12,18 @@
#include "gpt_misc.h"
#include "utility.h"
+const static int SECTOR_SIZE = 512;
+
+size_t CalculateEntriesSectors(GptHeader* h) {
+ size_t bytes = h->number_of_entries * h->size_of_entry;
+ size_t ret = (bytes + SECTOR_SIZE - 1) / SECTOR_SIZE;
+ return ret;
+}
int CheckParameters(GptData *gpt)
{
/* Currently, we only support 512-byte sectors. */
- if (gpt->sector_bytes != 512)
+ if (gpt->sector_bytes != SECTOR_SIZE)
return GPT_ERROR_INVALID_SECTOR_SIZE;
/*
@@ -33,9 +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.
+ * 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.
*/
- if (gpt->gpt_drive_sectors < (1 + 2 * (1 + GPT_ENTRIES_SECTORS)))
+ if (!(gpt->flags & GPT_FLAG_EXTERNAL) &&
+ gpt->gpt_drive_sectors < (1 + 2 * (1 + TOTAL_ENTRIES_SIZE / SECTOR_SIZE)))
return GPT_ERROR_INVALID_SECTOR_NUMBER;
return GPT_SUCCESS;
@@ -105,7 +114,7 @@ int CheckHeader(GptHeader *h, int is_secondary,
if (is_secondary) {
if (h->my_lba != gpt_drive_sectors - GPT_HEADER_SECTORS)
return 1;
- if (h->entries_lba != h->my_lba - GPT_ENTRIES_SECTORS)
+ if (h->entries_lba != h->my_lba - CalculateEntriesSectors(h))
return 1;
} else {
if (h->my_lba != GPT_PMBR_SECTORS)
@@ -131,10 +140,10 @@ int CheckHeader(GptHeader *h, int is_secondary,
* array.
*/
/* TODO(namnguyen): Also check for padding between header & entries. */
- if (h->first_usable_lba < 2 + GPT_ENTRIES_SECTORS)
+ if (h->first_usable_lba < 2 + CalculateEntriesSectors(h))
return 1;
if (h->last_usable_lba >=
- streaming_drive_sectors - 1 - GPT_ENTRIES_SECTORS)
+ streaming_drive_sectors - 1 - CalculateEntriesSectors(h))
return 1;
/* Success */
@@ -321,7 +330,7 @@ void GptRepair(GptData *gpt)
Memcpy(header2, header1, sizeof(GptHeader));
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->entries_lba = header2->my_lba - CalculateEntriesSectors(header1);
header2->header_crc32 = HeaderCrc(header2);
gpt->modified |= GPT_MODIFIED_HEADER2;
}
diff --git a/firmware/lib/cgptlib/include/cgptlib_internal.h b/firmware/lib/cgptlib/include/cgptlib_internal.h
index f88bc567..b4e2f5f9 100644
--- a/firmware/lib/cgptlib/include/cgptlib_internal.h
+++ b/firmware/lib/cgptlib/include/cgptlib_internal.h
@@ -51,17 +51,12 @@
#define MIN_SIZE_OF_ENTRY 128
#define MAX_SIZE_OF_ENTRY 512
#define SIZE_OF_ENTRY_MULTIPLE 8
-#define MIN_NUMBER_OF_ENTRIES 32
+#define MIN_NUMBER_OF_ENTRIES 16
#define MAX_NUMBER_OF_ENTRIES 512
/* Defines GPT sizes */
#define GPT_PMBR_SECTORS 1 /* size (in sectors) of PMBR */
#define GPT_HEADER_SECTORS 1
-/*
- * Entries sectors assumes sector size if 512 bytes; then (TOTAL_ENTRIES_SIZE /
- * 512) = 32
- */
-#define GPT_ENTRIES_SECTORS 32
/*
* Alias name of index in internal array for primary and secondary header and
@@ -163,4 +158,9 @@ void GetCurrentKernelUniqueGuid(GptData *gpt, void *dest);
*/
const char *GptErrorText(int error_code);
+/**
+ * Return number of 512-byte sectors required to store the entries table.
+ */
+size_t CalculateEntriesSectors(GptHeader* h);
+
#endif /* VBOOT_REFERENCE_CGPTLIB_INTERNAL_H_ */