[coreboot-gerrit] Patch set updated for coreboot: cbfstool: implement decompression support for cbfstool extract

Patrick Georgi (pgeorgi@google.com) gerrit at coreboot.org
Mon Aug 31 22:18:49 CEST 2015


Patrick Georgi (pgeorgi at google.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/11363

-gerrit

commit 121930b47b4c070b8e711447d437b9445b3f1a02
Author: Patrick Georgi <patrick at georgi-clan.de>
Date:   Wed Aug 26 13:01:10 2015 +0200

    cbfstool: implement decompression support for cbfstool extract
    
    Change-Id: I5142b03d3c3e028eeb179f225848f762186f94a8
    Signed-off-by: Patrick Georgi <patrick at georgi-clan.de>
---
 util/cbfstool/cbfs_image.c | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/util/cbfstool/cbfs_image.c b/util/cbfstool/cbfs_image.c
index 082fe06..ff06f5d 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;



More information about the coreboot-gerrit mailing list