summaryrefslogtreecommitdiff
path: root/cgpt
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 /cgpt
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 'cgpt')
-rw-r--r--cgpt/cgpt_common.c21
-rw-r--r--cgpt/cgpt_create.c8
-rw-r--r--cgpt/cgpt_find.c11
-rw-r--r--cgpt/cgpt_show.c6
4 files changed, 26 insertions, 20 deletions
diff --git a/cgpt/cgpt_common.c b/cgpt/cgpt_common.c
index f6108c1e..a5550b4c 100644
--- a/cgpt/cgpt_common.c
+++ b/cgpt/cgpt_common.c
@@ -191,11 +191,13 @@ static int GptLoad(struct drive *drive, uint32_t sector_bytes) {
GptHeader* primary_header = (GptHeader*)drive->gpt.primary_header;
if (CheckHeader(primary_header, 0, drive->gpt.streaming_drive_sectors,
drive->gpt.gpt_drive_sectors,
- drive->gpt.flags) == 0) {
+ drive->gpt.flags,
+ drive->gpt.sector_bytes) == 0) {
if (CGPT_OK != Load(drive, &drive->gpt.primary_entries,
primary_header->entries_lba,
drive->gpt.sector_bytes,
- CalculateEntriesSectors(primary_header))) {
+ CalculateEntriesSectors(primary_header,
+ drive->gpt.sector_bytes))) {
Error("Cannot read primary partition entry array\n");
return -1;
}
@@ -209,11 +211,13 @@ static int GptLoad(struct drive *drive, uint32_t sector_bytes) {
GptHeader* secondary_header = (GptHeader*)drive->gpt.secondary_header;
if (CheckHeader(secondary_header, 1, drive->gpt.streaming_drive_sectors,
drive->gpt.gpt_drive_sectors,
- drive->gpt.flags) == 0) {
+ drive->gpt.flags,
+ drive->gpt.sector_bytes) == 0) {
if (CGPT_OK != Load(drive, &drive->gpt.secondary_entries,
secondary_header->entries_lba,
drive->gpt.sector_bytes,
- CalculateEntriesSectors(secondary_header))) {
+ CalculateEntriesSectors(secondary_header,
+ drive->gpt.sector_bytes))) {
Error("Cannot read secondary partition entry array\n");
return -1;
}
@@ -244,7 +248,8 @@ static int GptSave(struct drive *drive) {
if (CGPT_OK != Save(drive, drive->gpt.primary_entries,
primary_header->entries_lba,
drive->gpt.sector_bytes,
- CalculateEntriesSectors(primary_header))) {
+ CalculateEntriesSectors(primary_header,
+ drive->gpt.sector_bytes))) {
errors++;
Error("Cannot write primary entries: %s\n", strerror(errno));
}
@@ -273,7 +278,8 @@ static int GptSave(struct drive *drive) {
if (CGPT_OK != Save(drive, drive->gpt.secondary_entries,
secondary_header->entries_lba,
drive->gpt.sector_bytes,
- CalculateEntriesSectors(secondary_header))) {
+ CalculateEntriesSectors(secondary_header,
+ drive->gpt.sector_bytes))) {
errors++;
Error("Cannot write secondary entries: %s\n", strerror(errno));
}
@@ -343,7 +349,6 @@ int DriveOpen(const char *drive_path, struct drive *drive, int mode,
return CGPT_FAILED;
}
- sector_bytes = 512;
uint64_t gpt_drive_size;
if (ObtainDriveSize(drive->fd, &gpt_drive_size, &sector_bytes) != 0) {
Error("Can't get drive size and bytes per sector for %s: %s\n",
@@ -1015,7 +1020,7 @@ uint8_t RepairHeader(GptData *gpt, const uint32_t valid_headers) {
secondary_header->my_lba = gpt->gpt_drive_sectors - 1; /* the last sector */
secondary_header->alternate_lba = primary_header->my_lba;
secondary_header->entries_lba = secondary_header->my_lba -
- CalculateEntriesSectors(primary_header);
+ CalculateEntriesSectors(primary_header, gpt->sector_bytes);
return GPT_MODIFIED_HEADER2;
} else if (valid_headers == MASK_SECONDARY) {
memcpy(primary_header, secondary_header, sizeof(GptHeader));
diff --git a/cgpt/cgpt_create.c b/cgpt/cgpt_create.c
index c34cfe31..a56a9762 100644
--- a/cgpt/cgpt_create.c
+++ b/cgpt/cgpt_create.c
@@ -81,9 +81,11 @@ static int GptCreate(struct drive *drive, CgptCreateParams *params) {
h->entries_lba = h->my_lba + GPT_HEADER_SECTORS;
if (!(drive->gpt.flags & GPT_FLAG_EXTERNAL)) {
h->entries_lba += params->padding;
- h->first_usable_lba = h->entries_lba + CalculateEntriesSectors(h);
- h->last_usable_lba = (drive->gpt.streaming_drive_sectors - GPT_HEADER_SECTORS -
- CalculateEntriesSectors(h) - 1);
+ h->first_usable_lba = h->entries_lba + CalculateEntriesSectors(h,
+ drive->gpt.sector_bytes);
+ h->last_usable_lba =
+ (drive->gpt.streaming_drive_sectors - GPT_HEADER_SECTORS -
+ CalculateEntriesSectors(h, drive->gpt.sector_bytes) - 1);
} else {
h->first_usable_lba = params->padding;
h->last_usable_lba = (drive->gpt.streaming_drive_sectors - 1);
diff --git a/cgpt/cgpt_find.c b/cgpt/cgpt_find.c
index a02ad7ae..e207fb3a 100644
--- a/cgpt/cgpt_find.c
+++ b/cgpt/cgpt_find.c
@@ -14,9 +14,6 @@
#include "vboot_host.h"
#define BUFSIZE 1024
-// FIXME: currently we only support 512-byte sectors.
-#define LBA_SIZE 512
-
// fill comparebuf with the data to be examined, returning true on success.
static int FillBuffer(CgptFindParams *params, int fd, uint64_t pos,
@@ -48,15 +45,15 @@ static int match_content(CgptFindParams *params, struct drive *drive,
return 1;
// Ensure that the region we want to match against is inside the partition.
- part_size = LBA_SIZE * (entry->ending_lba - entry->starting_lba + 1);
+ part_size = drive->gpt.sector_bytes *
+ (entry->ending_lba - entry->starting_lba + 1);
if (params->matchoffset + params->matchlen > part_size) {
return 0;
}
// Read the partition data.
- if (!FillBuffer(params,
- drive->fd,
- (LBA_SIZE * entry->starting_lba) + params->matchoffset,
+ if (!FillBuffer(params, drive->fd,
+ (drive->gpt.sector_bytes * entry->starting_lba) + params->matchoffset,
params->matchlen)) {
Error("unable to read partition data\n");
return 0;
diff --git a/cgpt/cgpt_show.c b/cgpt/cgpt_show.c
index 60d73ec7..72217419 100644
--- a/cgpt/cgpt_show.c
+++ b/cgpt/cgpt_show.c
@@ -302,7 +302,8 @@ static int GptShow(struct drive *drive, CgptShowParams *params) {
GptHeader* primary_header = (GptHeader*)drive->gpt.primary_header;
printf(GPT_FMT, (uint64_t)primary_header->entries_lba,
- (uint64_t)CalculateEntriesSectors(primary_header),
+ (uint64_t)CalculateEntriesSectors(primary_header,
+ drive->gpt.sector_bytes),
drive->gpt.valid_entries & MASK_PRIMARY ? "" : "INVALID",
"Pri GPT table");
@@ -319,7 +320,8 @@ static int GptShow(struct drive *drive, CgptShowParams *params) {
} else {
GptHeader* secondary_header = (GptHeader*)drive->gpt.secondary_header;
printf(GPT_FMT, (uint64_t)secondary_header->entries_lba,
- (uint64_t)CalculateEntriesSectors(secondary_header),
+ (uint64_t)CalculateEntriesSectors(secondary_header,
+ drive->gpt.sector_bytes),
drive->gpt.valid_entries & MASK_SECONDARY ? "" : "INVALID",
"Sec GPT table");
/* We show secondary table details if any of following is true.