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>
This commit is contained in:
Julius Werner 2018-05-15 17:30:20 -07:00
parent 55b3081b89
commit 88f4e08acf
1 changed files with 21 additions and 20 deletions

View File

@ -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,6 +160,7 @@ int compress(char *infile, char *outfile, char *algoname)
algo = &types_cbfs_compression[0];
}
if (write_header) {
char header[8];
header[0] = algo->type & 0xff;
header[1] = (algo->type >> 8) & 0xff;
@ -176,6 +174,7 @@ int compress(char *infile, char *outfile, char *algoname)
fprintf(stderr, "failed writing header\n");
goto out;
}
}
if (fwrite(outdata, outsize, 1, fout) != 1) {
fprintf(stderr, "failed writing compressed data\n");
goto out;
@ -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;
}