summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulius Werner <jwerner@chromium.org>2018-05-15 17:30:20 -0700
committerJulius Werner <jwerner@chromium.org>2018-05-22 02:38:35 +0000
commit88f4e08acf1dc39367aaa4bc121386c899193253 (patch)
treee2e36cbbaad05b4bd5dc1e1cc2cb03958d705936
parent55b3081b89cfe8cf4215047e31d8d89b60eb7c01 (diff)
downloadcoreboot-88f4e08acf1dc39367aaa4bc121386c899193253.tar.xz
cbfs-compression-tool: Add raw compression support
This patch adds a new "rawcompress" command to cbfs-compression-tool, that works exactly the same as "compress" except that it doesn't add the custom 8-byte header to the file. This can be useful if you need to compress something into a format that coreboot's decompression routines can work with, but it's not supposed to go into CBFS. Change-Id: I18a97a35bb0b0f71f3226f97114936dc81d379eb Signed-off-by: Julius Werner <jwerner@chromium.org> Reviewed-on: https://review.coreboot.org/26337 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Aaron Durbin <adurbin@chromium.org>
-rw-r--r--util/cbfstool/cbfscomptool.c41
1 files changed, 21 insertions, 20 deletions
diff --git a/util/cbfstool/cbfscomptool.c b/util/cbfstool/cbfscomptool.c
index 33303ab62c..c32be64ba2 100644
--- a/util/cbfstool/cbfscomptool.c
+++ b/util/cbfstool/cbfscomptool.c
@@ -20,10 +20,6 @@
#include "common.h"
-void usage(void);
-int benchmark(void);
-int compress(char *infile, char *outfile, char *algoname);
-
const char *usage_text = "cbfs-compression-tool benchmark\n"
" runs benchmarks for all implemented algorithms\n"
"cbfs-compression-tool compress inFile outFile algo\n"
@@ -34,12 +30,12 @@ const char *usage_text = "cbfs-compression-tool benchmark\n"
" 4 bytes little endian: uncompressed size\n"
" ...: compressed data stream\n";
-void usage()
+static void usage(void)
{
puts(usage_text);
}
-int benchmark()
+static int benchmark(void)
{
const int bufsize = 10*1024*1024;
char *data = malloc(bufsize);
@@ -88,7 +84,8 @@ int benchmark()
return 0;
}
-int compress(char *infile, char *outfile, char *algoname)
+static int compress(char *infile, char *outfile, char *algoname,
+ int write_header)
{
int err = 1;
FILE *fin = NULL;
@@ -163,18 +160,20 @@ int compress(char *infile, char *outfile, char *algoname)
algo = &types_cbfs_compression[0];
}
- char header[8];
- header[0] = algo->type & 0xff;
- header[1] = (algo->type >> 8) & 0xff;
- header[2] = (algo->type >> 16) & 0xff;
- header[3] = (algo->type >> 24) & 0xff;
- header[4] = insize & 0xff;
- header[5] = (insize >> 8) & 0xff;
- header[6] = (insize >> 16) & 0xff;
- header[7] = (insize >> 24) & 0xff;
- if (fwrite(header, 8, 1, fout) != 1) {
- fprintf(stderr, "failed writing header\n");
- goto out;
+ if (write_header) {
+ char header[8];
+ header[0] = algo->type & 0xff;
+ header[1] = (algo->type >> 8) & 0xff;
+ header[2] = (algo->type >> 16) & 0xff;
+ header[3] = (algo->type >> 24) & 0xff;
+ header[4] = insize & 0xff;
+ header[5] = (insize >> 8) & 0xff;
+ header[6] = (insize >> 16) & 0xff;
+ header[7] = (insize >> 24) & 0xff;
+ if (fwrite(header, 8, 1, fout) != 1) {
+ fprintf(stderr, "failed writing header\n");
+ goto out;
+ }
}
if (fwrite(outdata, outsize, 1, fout) != 1) {
fprintf(stderr, "failed writing compressed data\n");
@@ -194,7 +193,9 @@ int main(int argc, char **argv)
if ((argc == 2) && (strcmp(argv[1], "benchmark") == 0))
return benchmark();
if ((argc == 5) && (strcmp(argv[1], "compress") == 0))
- return compress(argv[2], argv[3], argv[4]);
+ return compress(argv[2], argv[3], argv[4], 1);
+ if ((argc == 5) && (strcmp(argv[1], "rawcompress") == 0))
+ return compress(argv[2], argv[3], argv[4], 0);
usage();
return 1;
}