diff options
author | Patrick Georgi <patrick@georgi-clan.de> | 2015-08-26 13:01:10 +0200 |
---|---|---|
committer | Patrick Georgi <pgeorgi@google.com> | 2015-09-01 14:52:02 +0000 |
commit | 23aeaff41b94af818191a8668a517abb04a7d516 (patch) | |
tree | 803d82a4688065693587f4dbbd3b5f66a61975ae | |
parent | 61c822900e8907e28ef6dca326835692ae6d18ca (diff) |
cbfstool: implement decompression support for cbfstool extract
Change-Id: I5142b03d3c3e028eeb179f225848f762186f94a8
Signed-off-by: Patrick Georgi <patrick@georgi-clan.de>
Reviewed-on: http://review.coreboot.org/11363
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
-rw-r--r-- | util/cbfstool/cbfs_image.c | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/util/cbfstool/cbfs_image.c b/util/cbfstool/cbfs_image.c index 619bf0bd5b..c40bd66411 100644 --- a/util/cbfstool/cbfs_image.c +++ b/util/cbfstool/cbfs_image.c @@ -661,9 +661,20 @@ int cbfs_export_entry(struct cbfs_image *image, const char *entry_name, ERROR("File not found: %s\n", entry_name); return -1; } + + unsigned int decompressed_size = 0; + unsigned int compression = cbfs_file_get_compression_info(entry, + &decompressed_size); + + decomp_func_ptr decompress = decompression_function(compression); + if (!decompress) { + ERROR("looking up decompression routine failed\n"); + return -1; + } + LOG("Found file %.30s at 0x%x, type %.12s, size %d\n", entry_name, cbfs_get_entry_addr(image, entry), - get_cbfs_entry_type_name(ntohl(entry->type)), ntohl(entry->len)); + get_cbfs_entry_type_name(ntohl(entry->type)), decompressed_size); if (ntohl(entry->type) == CBFS_COMPONENT_STAGE) { WARN("Stages are extracted in SELF format.\n"); @@ -673,8 +684,13 @@ int cbfs_export_entry(struct cbfs_image *image, const char *entry_name, WARN("Payloads are extracted in SELF format.\n"); } - buffer.data = CBFS_SUBHEADER(entry); - buffer.size = ntohl(entry->len); + buffer.data = malloc(decompressed_size); + buffer.size = decompressed_size; + if (decompress(CBFS_SUBHEADER(entry), ntohl(entry->len), + buffer.data, buffer.size)) { + ERROR("decompression failed for %s\n", entry_name); + return -1; + } buffer.name = strdup("(cbfs_export_entry)"); if (buffer_write_file(&buffer, filename) != 0) { ERROR("Failed to write %s into %s.\n", @@ -682,6 +698,7 @@ int cbfs_export_entry(struct cbfs_image *image, const char *entry_name, free(buffer.name); return -1; } + free(buffer.data); free(buffer.name); INFO("Successfully dumped the file to: %s\n", filename); return 0; |