summaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorPatrick Georgi <patrick@georgi-clan.de>2015-08-26 12:53:41 +0200
committerPatrick Georgi <pgeorgi@google.com>2015-09-01 14:51:53 +0000
commit61c822900e8907e28ef6dca326835692ae6d18ca (patch)
tree1c6cb5b36d9753fce53350eac446bda601c84888 /util
parenta71c83fa5c3904b562bad939a3103387cd561c80 (diff)
downloadcoreboot-61c822900e8907e28ef6dca326835692ae6d18ca.tar.gz
coreboot-61c822900e8907e28ef6dca326835692ae6d18ca.tar.bz2
coreboot-61c822900e8907e28ef6dca326835692ae6d18ca.zip
cbfstool: add decompression wrappers
... and document the interface. Change-Id: I86a071a61fd6c1ef842f8ffe51f12f0cefdaf2fe Signed-off-by: Patrick Georgi <patrick@georgi-clan.de> Reviewed-on: http://review.coreboot.org/11362 Reviewed-by: Aaron Durbin <adurbin@chromium.org> Tested-by: build bot (Jenkins)
Diffstat (limited to 'util')
-rw-r--r--util/cbfstool/common.h16
-rw-r--r--util/cbfstool/compress.c27
2 files changed, 42 insertions, 1 deletions
diff --git a/util/cbfstool/common.h b/util/cbfstool/common.h
index 5fb19065dfc9..4a97fed6cb45 100644
--- a/util/cbfstool/common.h
+++ b/util/cbfstool/common.h
@@ -146,10 +146,24 @@ void buffer_delete(struct buffer *buffer);
const char *arch_to_string(uint32_t a);
uint32_t string_to_arch(const char *arch_string);
-typedef int (*comp_func_ptr) (char *, int, char *, int *);
+/* Compress in_len bytes from in, storing the result at out, returning the
+ * resulting length in out_len.
+ * Returns 0 on error,
+ * != 0 otherwise, depending on the compressing function.
+ */
+typedef int (*comp_func_ptr) (char *in, int in_len, char *out, int *out_len);
+
+/* Decompress in_len bytes from in, storing the result at out, up to out_len
+ * bytes.
+ * Returns 0 on error,
+ * != 0 otherwise, depending on the decompressing function.
+ */
+typedef int (*decomp_func_ptr) (char *in, int in_len, char *out, int out_len);
+
enum comp_algo { CBFS_COMPRESS_NONE = 0, CBFS_COMPRESS_LZMA = 1 };
comp_func_ptr compression_function(enum comp_algo algo);
+decomp_func_ptr decompression_function(enum comp_algo algo);
uint64_t intfiletype(const char *name);
diff --git a/util/cbfstool/compress.c b/util/cbfstool/compress.c
index ab94b353290c..2bde7df96adb 100644
--- a/util/cbfstool/compress.c
+++ b/util/cbfstool/compress.c
@@ -31,6 +31,10 @@ static int lzma_compress(char *in, int in_len, char *out, int *out_len)
return do_lzma_compress(in, in_len, out, out_len);
}
+static int lzma_decompress(char *in, int in_len, char *out, unused int out_len)
+{
+ return do_lzma_uncompress(out, out_len, in, in_len);
+}
static int none_compress(char *in, int in_len, char *out, int *out_len)
{
memcpy(out, in, in_len);
@@ -38,6 +42,12 @@ static int none_compress(char *in, int in_len, char *out, int *out_len)
return 0;
}
+static int none_decompress(char *in, int in_len, char *out, unused int out_len)
+{
+ memcpy(out, in, in_len);
+ return 0;
+}
+
comp_func_ptr compression_function(enum comp_algo algo)
{
comp_func_ptr compress;
@@ -54,3 +64,20 @@ comp_func_ptr compression_function(enum comp_algo algo)
}
return compress;
}
+
+decomp_func_ptr decompression_function(enum comp_algo algo)
+{
+ decomp_func_ptr decompress;
+ switch (algo) {
+ case CBFS_COMPRESS_NONE:
+ decompress = none_decompress;
+ break;
+ case CBFS_COMPRESS_LZMA:
+ decompress = lzma_decompress;
+ break;
+ default:
+ ERROR("Unknown compression algorithm %d!\n", algo);
+ return NULL;
+ }
+ return decompress;
+}