summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Chaulk <achaulk@chromium.org>2013-07-25 11:32:57 -0700
committerChromeBot <chrome-bot@google.com>2013-07-31 15:40:04 -0700
commit32fd6dead10a8255fea27f6e5ce9ba92d8716008 (patch)
tree4cb3db264a65a5a55bd118b205c5342719c64b8c
parent05f5944a40dca2a92070f26dad0bfbb57f59aca1 (diff)
downloadvboot-32fd6dead10a8255fea27f6e5ce9ba92d8716008.tar.gz
Add labels to MTD partitions.
Add labels to MTD partitions and clean up some of the show code, adding more info on the MTD prints and eliminating duplicated code. BRANCH=none TEST=make runtests & manual cgpt add -l "label"; cgpt show to verify labels BUG=none Change-Id: I59736128f394c2aca937a3a0bb5fc5d42b0149a9 Reviewed-on: https://gerrit.chromium.org/gerrit/63367 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Commit-Queue: Albert Chaulk <achaulk@chromium.org> Tested-by: Albert Chaulk <achaulk@chromium.org>
-rw-r--r--cgpt/cgpt_add.c3
-rw-r--r--cgpt/cgpt_show.c82
-rw-r--r--firmware/lib/cgptlib/include/mtdlib.h9
3 files changed, 55 insertions, 39 deletions
diff --git a/cgpt/cgpt_add.c b/cgpt/cgpt_add.c
index e0e24b81..a93c60c6 100644
--- a/cgpt/cgpt_add.c
+++ b/cgpt/cgpt_add.c
@@ -113,6 +113,9 @@ static int MtdSetEntryAttributes(struct drive *drive,
}
if (params->set_type)
MtdSetEntryType(entry, LookupMtdTypeForGuid(&params->type_guid));
+ if (params->label) {
+ strncpy(entry->label, params->label, sizeof(entry->label));
+ }
return 0;
}
diff --git a/cgpt/cgpt_show.c b/cgpt/cgpt_show.c
index 78a285c7..41f9d007 100644
--- a/cgpt/cgpt_show.c
+++ b/cgpt/cgpt_show.c
@@ -111,45 +111,66 @@ static void HeaderDetails(GptHeader *header, GptEntry *entries,
void MtdEntryDetails(MtdDiskPartition *entry, uint32_t index, int raw) {
const Guid *guid = LookupGuidForMtdType(MtdGetEntryType(entry));
- char buf[256]; // scratch buffer for formatting output
+ char type[256];
+ char contents[256];
+ char name[sizeof(entry->label) + 1];
uint64_t start, size;
if (guid) {
- ResolveType(guid, buf);
+ ResolveType(guid, type);
} else {
- snprintf(buf, sizeof(buf), "MTD partition type %d", MtdGetEntryType(entry));
+ snprintf(type, sizeof(type), "MTD partition type %d",
+ MtdGetEntryType(entry));
}
MtdGetPartitionSizeInSectors(entry, &start, NULL, &size);
- if (!raw) {
- printf(PARTITION_FMT, (int)start, (int)size, index+1, buf);
+ // Provide a NUL if we are at maximum size.
+ name[sizeof(name)-1] = '\0';
+ memcpy(name, entry->label, sizeof(entry->label));
+ require(snprintf(contents, sizeof(contents),
+ "Label: \"%s\"", name) < sizeof(contents));
+
+ printf(PARTITION_FMT, (int)start, (int)size, index+1, contents);
+ printf(PARTITION_MORE, "Type: ", type);
+
+ if (raw && MtdGetEntryType(entry) == MTD_PARTITION_TYPE_CHROMEOS_KERNEL) {
+ int tries = MtdGetEntryTries(entry);
+ int successful = MtdGetEntrySuccessful(entry);
+ int priority = MtdGetEntryPriority(entry);
+ require(snprintf(contents, sizeof(contents),
+ "priority=%d tries=%d successful=%d",
+ priority, tries, successful) < sizeof(contents));
+ printf(PARTITION_MORE, "Attr: ", contents);
} else {
- printf(PARTITION_FMT, (int)start, (int)size, index+1, buf);
+ require(snprintf(contents, sizeof(contents),
+ "[%x]", entry->flags) < sizeof(contents));
+ printf(PARTITION_MORE, "Attr: ", contents);
}
}
void EntryDetails(GptEntry *entry, uint32_t index, int raw) {
char contents[256]; // scratch buffer for formatting output
uint8_t label[GPT_PARTNAME_LEN];
+ char type[GUID_STRLEN], unique[GUID_STRLEN];
- if (!raw) {
- char type[GUID_STRLEN], unique[GUID_STRLEN];
+ UTF16ToUTF8(entry->name, sizeof(entry->name) / sizeof(entry->name[0]),
+ label, sizeof(label));
+ require(snprintf(contents, sizeof(contents),
+ "Label: \"%s\"", label) < sizeof(contents));
+ printf(PARTITION_FMT, (int)entry->starting_lba,
+ (int)(entry->ending_lba - entry->starting_lba + 1),
+ index+1, contents);
- UTF16ToUTF8(entry->name, sizeof(entry->name) / sizeof(entry->name[0]),
- label, sizeof(label));
- require(snprintf(contents, sizeof(contents),
- "Label: \"%s\"", label) < sizeof(contents));
- printf(PARTITION_FMT, (int)entry->starting_lba,
- (int)(entry->ending_lba - entry->starting_lba + 1),
- index+1, contents);
- if (CGPT_OK == ResolveType(&entry->type, type)) {
- printf(PARTITION_MORE, "Type: ", type);
- } else {
- GuidToStr(&entry->type, type, GUID_STRLEN);
- printf(PARTITION_MORE, "Type: ", type);
- }
- GuidToStr(&entry->unique, unique, GUID_STRLEN);
- printf(PARTITION_MORE, "UUID: ", unique);
+ if (!raw && CGPT_OK == ResolveType(&entry->type, type)) {
+ printf(PARTITION_MORE, "Type: ", type);
+ } else {
+ GuidToStr(&entry->type, type, GUID_STRLEN);
+ printf(PARTITION_MORE, "Type: ", type);
+ }
+ GuidToStr(&entry->unique, unique, GUID_STRLEN);
+ printf(PARTITION_MORE, "UUID: ", unique);
+
+ if (!raw) {
if (GuidEqual(&guid_chromeos_kernel, &entry->type)) {
int tries = (entry->attrs.fields.gpt_att &
CGPT_ATTRIBUTE_TRIES_MASK) >>
@@ -166,19 +187,6 @@ void EntryDetails(GptEntry *entry, uint32_t index, int raw) {
printf(PARTITION_MORE, "Attr: ", contents);
}
} else {
- char type[GUID_STRLEN], unique[GUID_STRLEN];
-
- UTF16ToUTF8(entry->name, sizeof(entry->name) / sizeof(entry->name[0]),
- label, sizeof(label));
- require(snprintf(contents, sizeof(contents),
- "Label: \"%s\"", label) < sizeof(contents));
- printf(PARTITION_FMT, (int)entry->starting_lba,
- (int)(entry->ending_lba - entry->starting_lba + 1),
- index+1, contents);
- GuidToStr(&entry->type, type, GUID_STRLEN);
- printf(PARTITION_MORE, "Type: ", type);
- GuidToStr(&entry->unique, unique, GUID_STRLEN);
- printf(PARTITION_MORE, "UUID: ", unique);
require(snprintf(contents, sizeof(contents),
"[%x]", entry->attrs.fields.gpt_att) < sizeof(contents));
printf(PARTITION_MORE, "Attr: ", contents);
@@ -321,7 +329,7 @@ int MtdShow(struct drive *drive, CgptShowParams *params) {
require(snprintf(indent, sizeof(indent), GPT_MORE) < sizeof(indent));
MtdHeaderDetails(&drive->mtd.primary, indent, 0);
}
-
+ printf(TITLE_FMT, "start", "size", "part", "contents");
MtdEntriesDetails(drive, PRIMARY, params->numeric);
}
diff --git a/firmware/lib/cgptlib/include/mtdlib.h b/firmware/lib/cgptlib/include/mtdlib.h
index 0c87822a..fd749aca 100644
--- a/firmware/lib/cgptlib/include/mtdlib.h
+++ b/firmware/lib/cgptlib/include/mtdlib.h
@@ -66,6 +66,11 @@ typedef struct {
uint64_t starting_offset;
uint64_t ending_offset;
uint32_t flags;
+
+ /* 28 characters is a balance between GPT parity and size constraints, at
+ * current sizes this table occupies 10% of the FTS data store.
+ */
+ char label[28];
} __attribute__((packed)) MtdDiskPartition;
typedef struct {
@@ -81,9 +86,9 @@ typedef struct {
MtdDiskPartition partitions[MTD_MAX_PARTITIONS];
} __attribute__((packed)) MtdDiskLayout;
-#define MTD_DRIVE_V1_SIZE (32 + 16*20)
+#define MTD_DRIVE_V1_SIZE (32 + 16*48)
-#define MTDENTRY_EXPECTED_SIZE (20)
+#define MTDENTRY_EXPECTED_SIZE (48)
#define MTDLAYOUT_EXPECTED_SIZE (32 + 16 * MTDENTRY_EXPECTED_SIZE)