summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Chaulk <achaulk@chromium.org>2013-07-19 12:56:38 -0700
committerChromeBot <chrome-bot@google.com>2013-07-31 15:40:23 -0700
commit494646dbadedae88776d6fced396e3ee8af38e54 (patch)
treee5d2dffbb2610cbdef31e86e0fdd701f4b51cd1d
parent32fd6dead10a8255fea27f6e5ce9ba92d8716008 (diff)
downloadvboot-494646dbadedae88776d6fced396e3ee8af38e54.tar.gz
Fix some issues with LBA vs byte offsets
In several places the existing code assumes LBA, but was improperly converted to use byte offsets, so multiply by the sector size to correct it and maintain the same interface between MTD & GPT. Also, since we will need to cgpt create on /dev/fts, which isn't a stat()able device, allow providing the disk size on the commandline. BRANCH=none BUG=chromium:221745 TEST=make runtests; cgpt create -s 12345 on MTD image Change-Id: Icc89a4505aba9a3dfc39b176a372f6e12d106aed Reviewed-on: https://gerrit.chromium.org/gerrit/62675 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Tested-by: Albert Chaulk <achaulk@chromium.org> Commit-Queue: Albert Chaulk <achaulk@chromium.org>
-rw-r--r--cgpt/cgpt_add.c8
-rw-r--r--cgpt/cgpt_create.c8
-rw-r--r--cgpt/cgpt_show.c4
-rw-r--r--cgpt/cmd_create.c7
-rw-r--r--host/include/cgpt_params.h1
5 files changed, 22 insertions, 6 deletions
diff --git a/cgpt/cgpt_add.c b/cgpt/cgpt_add.c
index a93c60c6..fc40ebc5 100644
--- a/cgpt/cgpt_add.c
+++ b/cgpt/cgpt_add.c
@@ -102,13 +102,15 @@ static int MtdSetEntryAttributes(struct drive *drive,
MtdDiskPartition *entry;
entry = MtdGetEntry(&drive->mtd, PRIMARY, index);
- if (params->set_begin)
- memcpy(&entry->starting_offset, &params->begin, sizeof(params->begin));
+ if (params->set_begin) {
+ uint64_t start = params->begin * drive->mtd.sector_bytes;
+ memcpy(&entry->starting_offset, &start, sizeof(params->begin));
+ }
if (params->set_size) {
uint64_t start;
uint64_t end;
MtdGetPartitionSize(entry, &start, NULL, NULL);
- end = start + params->size - 1;
+ end = start + params->size * drive->mtd.sector_bytes - 1;
memcpy(&entry->ending_offset, &end, sizeof(end));
}
if (params->set_type)
diff --git a/cgpt/cgpt_create.c b/cgpt/cgpt_create.c
index e7cbadf8..90b746c6 100644
--- a/cgpt/cgpt_create.c
+++ b/cgpt/cgpt_create.c
@@ -64,6 +64,14 @@ int MtdCreate(struct drive *drive, CgptCreateParams *params) {
h->last_offset = (drive->mtd.drive_sectors * drive->mtd.sector_bytes) - 1;
h->crc32 = MtdHeaderCrc(h);
}
+ if (params->size) {
+ h->last_offset = params->size - 1;
+ drive->size = params->size;
+ drive->mtd.drive_sectors = drive->size / drive->mtd.sector_bytes;
+ } else if (!drive->mtd.drive_sectors) {
+ Error("MTD create with params->size == 0 && drive->mtd.drive_sectors == 0");
+ return -1;
+ }
return 0;
}
diff --git a/cgpt/cgpt_show.c b/cgpt/cgpt_show.c
index 41f9d007..082a5c73 100644
--- a/cgpt/cgpt_show.c
+++ b/cgpt/cgpt_show.c
@@ -73,9 +73,9 @@ void MtdHeaderDetails(MtdDiskLayout *header, const char *indent, int raw) {
printf("%sSize: %d\n", indent, header->size);
printf("%sCRC: 0x%08x %s\n", indent, header->crc32,
(MtdHeaderCrc(header) != header->crc32) ? "(INVALID)" : "");
- printf("%sFirst LBA: %llu\n", indent,
+ printf("%sFirst offset: %llu\n", indent,
(unsigned long long)header->first_offset);
- printf("%sLast LBA: %llu\n", indent,
+ printf("%sLast offset: %llu\n", indent,
(unsigned long long)header->last_offset);
}
diff --git a/cgpt/cmd_create.c b/cgpt/cmd_create.c
index 0d91b08a..4f042204 100644
--- a/cgpt/cmd_create.c
+++ b/cgpt/cmd_create.c
@@ -14,6 +14,7 @@ static void Usage(void)
"Create or reset an empty GPT.\n\n"
"Options:\n"
" -z Zero the sectors of the GPT table and entries\n"
+ " -s Size (in byes) of the disk (MTD only)\n"
"\n", progname);
}
@@ -23,15 +24,19 @@ int cmd_create(int argc, char *argv[]) {
int c;
int errorcnt = 0;
+ char *e = 0;
opterr = 0; // quiet, you
- while ((c=getopt(argc, argv, ":hz")) != -1)
+ while ((c=getopt(argc, argv, ":hzs:")) != -1)
{
switch (c)
{
case 'z':
params.zap = 1;
break;
+ case 's':
+ params.size = strtoull(optarg, &e, 0);
+ break;
case 'h':
Usage();
diff --git a/host/include/cgpt_params.h b/host/include/cgpt_params.h
index 14e380a2..72de99dc 100644
--- a/host/include/cgpt_params.h
+++ b/host/include/cgpt_params.h
@@ -16,6 +16,7 @@ enum {
typedef struct CgptCreateParams {
char *drive_name;
int zap;
+ uint64_t size;
} CgptCreateParams;
typedef struct CgptAddParams {