[coreboot-gerrit] New patch to review for coreboot: util/cbfstool: add machine parseable print
Aaron Durbin (adurbin@chromium.org)
gerrit at coreboot.org
Tue Jan 26 22:39:31 CET 2016
Aaron Durbin (adurbin at chromium.org) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/13475
-gerrit
commit 2b8f74af3d98e5b875d4daceef4abef97a61c6c0
Author: Aaron Durbin <adurbin at chromium.org>
Date: Tue Jan 26 15:35:34 2016 -0600
util/cbfstool: add machine parseable print
In order to more easily process the output of 'cbfstool print'
with other tools provide a -k option which spits out the
tab-separated header and fields:
Name Offset Type Metadata Size Data Size Total Size
ALIGN_UP(Offset + Total Size, 64) would be the start
of the next entry. Also, one can analzye the overhead
and offsets of each file more easily.
Change-Id: I1c5f8c1b5f2f980033d6c954c9840299c6268431
Signed-off-by: Aaron Durbin <adurbin at chromium.org>
---
util/cbfstool/cbfs_image.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++
util/cbfstool/cbfs_image.h | 1 +
util/cbfstool/cbfstool.c | 13 ++++++++---
3 files changed, 67 insertions(+), 3 deletions(-)
diff --git a/util/cbfstool/cbfs_image.c b/util/cbfstool/cbfs_image.c
index 2d7a6f0..24231fb 100644
--- a/util/cbfstool/cbfs_image.c
+++ b/util/cbfstool/cbfs_image.c
@@ -1075,6 +1075,42 @@ int cbfs_print_entry_info(struct cbfs_image *image, struct cbfs_file *entry,
return 0;
}
+static int cbfs_print_parseable_entry_info(struct cbfs_image *image,
+ struct cbfs_file *entry, void *arg)
+{
+ FILE *fp = (FILE *)arg;
+ const char *name;
+ const char *type;
+ size_t offset;
+ size_t metadata_size;
+ size_t data_size;
+ const char *sep = "\t";
+
+ if (!cbfs_is_valid_entry(image, entry)) {
+ ERROR("cbfs_print_entry_info: Invalid entry at 0x%x\n",
+ cbfs_get_entry_addr(image, entry));
+ return -1;
+ }
+
+ name = entry->filename;
+ if (*name == '\0')
+ name = "(empty)";
+ type = get_cbfs_entry_type_name(ntohl(entry->type)),
+ metadata_size = ntohl(entry->offset);
+ data_size = ntohl(entry->len);
+ offset = cbfs_get_entry_addr(image, entry);
+
+ fprintf(fp, "%s%s", name, sep);
+ fprintf(fp, "0x%zx%s", offset, sep);
+ fprintf(fp, "%s%s", type, sep);
+ fprintf(fp, "0x%zx%s", metadata_size, sep);
+ fprintf(fp, "0x%zx%s", data_size, sep);
+ fprintf(fp, "0x%zx%s", metadata_size + data_size, sep);
+ fprintf(fp, "\n");
+
+ return 0;
+}
+
int cbfs_print_directory(struct cbfs_image *image)
{
if (cbfs_is_legacy_cbfs(image))
@@ -1084,6 +1120,26 @@ int cbfs_print_directory(struct cbfs_image *image)
return 0;
}
+int cbfs_print_parseable_directory(struct cbfs_image *image)
+{
+ int i;
+ const char *header[] = {
+ "Name",
+ "Offset",
+ "Type",
+ "Metadata Size",
+ "Data Size",
+ "Total Size",
+ };
+ const char *sep = "\t";
+
+ for (i = 0; i < ARRAY_SIZE(header); i++)
+ fprintf(stdout, "%s%s", header[i], sep);
+ fprintf(stdout, "\n");
+ cbfs_walk(image, cbfs_print_parseable_entry_info, stdout);
+ return 0;
+}
+
int cbfs_merge_empty_entry(struct cbfs_image *image, struct cbfs_file *entry,
unused void *arg)
{
diff --git a/util/cbfstool/cbfs_image.h b/util/cbfstool/cbfs_image.h
index 00adcc8..38510d2 100644
--- a/util/cbfstool/cbfs_image.h
+++ b/util/cbfstool/cbfs_image.h
@@ -158,6 +158,7 @@ int cbfs_is_valid_entry(struct cbfs_image *image, struct cbfs_file *entry);
/* Print CBFS component information. */
int cbfs_print_directory(struct cbfs_image *image);
+int cbfs_print_parseable_directory(struct cbfs_image *image);
int cbfs_print_header_info(struct cbfs_image *image);
int cbfs_print_entry_info(struct cbfs_image *image, struct cbfs_file *entry,
void *arg);
diff --git a/util/cbfstool/cbfstool.c b/util/cbfstool/cbfstool.c
index 23787d8..13a9956 100644
--- a/util/cbfstool/cbfstool.c
+++ b/util/cbfstool/cbfstool.c
@@ -75,6 +75,7 @@ static struct param {
bool show_immutable;
bool stage_xip;
bool autogen_attr;
+ bool machine_parseable;
int fit_empty_entries;
enum comp_algo compression;
enum vb2_hash_algorithm hash;
@@ -838,8 +839,10 @@ static int cbfs_print(void)
if (cbfs_image_from_buffer(&image, param.image_region,
param.headeroffset))
return 1;
- cbfs_print_directory(&image);
- return 0;
+ if (param.machine_parseable)
+ return cbfs_print_parseable_directory(&image);
+ else
+ return cbfs_print_directory(&image);
}
/* Forward declared so there aren't type collisions with cbfstool proper
@@ -1066,7 +1069,7 @@ static const struct command commands[] = {
{"hashcbfs", "r:R:A:vh?", cbfs_hash, true, true},
{"extract", "H:r:m:n:f:vh?", cbfs_extract, true, false},
{"layout", "wvh?", cbfs_layout, false, false},
- {"print", "H:r:vh?", cbfs_print, true, false},
+ {"print", "H:r:vkh?", cbfs_print, true, false},
{"read", "r:f:vh?", cbfs_read, true, false},
{"remove", "H:r:n:vh?", cbfs_remove, true, true},
{"update-fit", "H:r:n:x:vh?", cbfs_update_fit, true, true},
@@ -1105,6 +1108,7 @@ static struct option long_options[] = {
{"with-readonly", no_argument, 0, 'w' },
{"xip", no_argument, 0, 'y' },
{"gen-attribute", no_argument, 0, 'g' },
+ {"mach-parseable",no_argument, 0, 'k' },
{NULL, 0, 0, 0 }
};
@@ -1407,6 +1411,9 @@ int main(int argc, char **argv)
case 'g':
param.autogen_attr = true;
break;
+ case 'k':
+ param.machine_parseable = true;
+ break;
case 'h':
case '?':
usage(argv[0]);
More information about the coreboot-gerrit
mailing list