summaryrefslogtreecommitdiff
path: root/firmware/lib
diff options
context:
space:
mode:
authorSam Hurst <shurst@google.com>2018-04-11 08:50:58 -0700
committerchrome-bot <chrome-bot@chromium.org>2018-04-12 23:11:01 -0700
commitd6f52a05a3b54e3d80f4bded77f33daccbe04e23 (patch)
treea80b4215b46776e151e4a64d700171baa84c01fd /firmware/lib
parent1fc5daa6b0b5e1763d00735ff1f8c05baeba74de (diff)
downloadvboot-d6f52a05a3b54e3d80f4bded77f33daccbe04e23.tar.gz
cgpt: Remove hard coded 512 block size.
Remove 512 sector block size restriction so that UFS, with sector block size 4096 or greater, can be used. The sector block size is queried from the kernel with ioctl(BLKSSZGET) or queried from depthcharge with VbExDiskGetInfo(). BUG=b:77540192 BRANCH=none TEST=manual make runtests passed. Tested firmware on Kevin and boot to kernel from disk. Executed cgpt show /dev/mmcblk0 on eve device and verified output was correct. Should be tested on device with sector block size greater than 512. Change-Id: I8165c8ee4da68180eecc8d12b3fb501cc5c60a5d Reviewed-on: https://chromium-review.googlesource.com/1007498 Commit-Ready: Sam Hurst <shurst@google.com> Tested-by: Sam Hurst <shurst@google.com> Reviewed-by: Julius Werner <jwerner@chromium.org>
Diffstat (limited to 'firmware/lib')
-rw-r--r--firmware/lib/cgptlib/cgptlib_internal.c33
-rw-r--r--firmware/lib/cgptlib/include/cgptlib_internal.h8
-rw-r--r--firmware/lib/gpt_misc.c6
3 files changed, 29 insertions, 18 deletions
diff --git a/firmware/lib/cgptlib/cgptlib_internal.c b/firmware/lib/cgptlib/cgptlib_internal.c
index 9d7bd0c9..77a0de2b 100644
--- a/firmware/lib/cgptlib/cgptlib_internal.c
+++ b/firmware/lib/cgptlib/cgptlib_internal.c
@@ -12,19 +12,20 @@
#include "gpt_misc.h"
#include "utility.h"
-const static int SECTOR_SIZE = 512;
+const static int MIN_SECTOR_SIZE = 512;
-size_t CalculateEntriesSectors(GptHeader* h)
+size_t CalculateEntriesSectors(GptHeader* h, uint32_t sector_bytes)
{
size_t bytes = h->number_of_entries * h->size_of_entry;
- size_t ret = (bytes + SECTOR_SIZE - 1) / SECTOR_SIZE;
+ size_t ret = (bytes + sector_bytes - 1) / sector_bytes;
return ret;
}
int CheckParameters(GptData *gpt)
{
- /* Currently, we only support 512-byte sectors. */
- if (gpt->sector_bytes != SECTOR_SIZE)
+ /* Only support 512-byte or larger sectors that are a power of 2 */
+ if (gpt->sector_bytes < MIN_SECTOR_SIZE ||
+ (gpt->sector_bytes & (gpt->sector_bytes - 1)) != 0)
return GPT_ERROR_INVALID_SECTOR_SIZE;
/*
@@ -45,7 +46,7 @@ int CheckParameters(GptData *gpt)
*/
if (gpt->gpt_drive_sectors <
(1 + 2 * (1 + MIN_NUMBER_OF_ENTRIES /
- (SECTOR_SIZE / sizeof(GptEntry)))))
+ (gpt->sector_bytes / sizeof(GptEntry)))))
return GPT_ERROR_INVALID_SECTOR_NUMBER;
return GPT_SUCCESS;
@@ -66,7 +67,8 @@ uint32_t HeaderCrc(GptHeader *h)
int CheckHeader(GptHeader *h, int is_secondary,
uint64_t streaming_drive_sectors,
- uint64_t gpt_drive_sectors, uint32_t flags)
+ uint64_t gpt_drive_sectors, uint32_t flags,
+ uint32_t sector_bytes)
{
if (!h)
return 1;
@@ -115,7 +117,8 @@ 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 - CalculateEntriesSectors(h))
+ if (h->entries_lba != h->my_lba - CalculateEntriesSectors(h,
+ sector_bytes))
return 1;
} else {
if (h->my_lba != GPT_PMBR_SECTORS)
@@ -141,10 +144,11 @@ int CheckHeader(GptHeader *h, int is_secondary,
* array.
*/
/* TODO(namnguyen): Also check for padding between header & entries. */
- if (h->first_usable_lba < 2 + CalculateEntriesSectors(h))
+ if (h->first_usable_lba < 2 + CalculateEntriesSectors(h, sector_bytes))
return 1;
if (h->last_usable_lba >=
- streaming_drive_sectors - 1 - CalculateEntriesSectors(h))
+ streaming_drive_sectors - 1 - CalculateEntriesSectors(h,
+ sector_bytes))
return 1;
/* Success */
@@ -254,7 +258,8 @@ int GptSanityCheck(GptData *gpt)
/* Check both headers; we need at least one valid header. */
if (0 == CheckHeader(header1, 0, gpt->streaming_drive_sectors,
- gpt->gpt_drive_sectors, gpt->flags)) {
+ gpt->gpt_drive_sectors, gpt->flags,
+ gpt->sector_bytes)) {
gpt->valid_headers |= MASK_PRIMARY;
goodhdr = header1;
} else if (header1 && !memcmp(header1->signature,
@@ -262,7 +267,8 @@ int GptSanityCheck(GptData *gpt)
gpt->ignored |= MASK_PRIMARY;
}
if (0 == CheckHeader(header2, 1, gpt->streaming_drive_sectors,
- gpt->gpt_drive_sectors, gpt->flags)) {
+ gpt->gpt_drive_sectors, gpt->flags,
+ gpt->sector_bytes)) {
gpt->valid_headers |= MASK_SECONDARY;
if (!goodhdr)
goodhdr = header2;
@@ -347,7 +353,8 @@ 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 - CalculateEntriesSectors(header1);
+ header2->entries_lba = header2->my_lba -
+ CalculateEntriesSectors(header1, gpt->sector_bytes);
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 eaa24312..f19ef819 100644
--- a/firmware/lib/cgptlib/include/cgptlib_internal.h
+++ b/firmware/lib/cgptlib/include/cgptlib_internal.h
@@ -93,7 +93,8 @@ int CheckParameters(GptData* gpt);
*/
int CheckHeader(GptHeader *h, int is_secondary,
uint64_t streaming_drive_sectors,
- uint64_t gpt_drive_sectors, uint32_t flags);
+ uint64_t gpt_drive_sectors, uint32_t flags,
+ uint32_t sector_bytes);
/**
* Calculate and return the header CRC.
@@ -160,8 +161,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.
+ * Return number of sectors required to store the entries table. Where
+ * a sector has size sector_bytes.
*/
-size_t CalculateEntriesSectors(GptHeader* h);
+size_t CalculateEntriesSectors(GptHeader* h, uint32_t sector_bytes);
#endif /* VBOOT_REFERENCE_CGPTLIB_INTERNAL_H_ */
diff --git a/firmware/lib/gpt_misc.c b/firmware/lib/gpt_misc.c
index ca16f220..45885834 100644
--- a/firmware/lib/gpt_misc.c
+++ b/firmware/lib/gpt_misc.c
@@ -57,7 +57,8 @@ int AllocAndReadGptData(VbExDiskHandle_t disk_handle, GptData *gptdata)
if (0 == CheckHeader(primary_header, 0,
gptdata->streaming_drive_sectors,
gptdata->gpt_drive_sectors,
- gptdata->flags)) {
+ gptdata->flags,
+ gptdata->sector_bytes)) {
primary_valid = 1;
uint64_t entries_bytes =
(uint64_t)primary_header->number_of_entries
@@ -91,7 +92,8 @@ int AllocAndReadGptData(VbExDiskHandle_t disk_handle, GptData *gptdata)
if (0 == CheckHeader(secondary_header, 1,
gptdata->streaming_drive_sectors,
gptdata->gpt_drive_sectors,
- gptdata->flags)) {
+ gptdata->flags,
+ gptdata->sector_bytes)) {
secondary_valid = 1;
uint64_t entries_bytes =
(uint64_t)secondary_header->number_of_entries