cbfstool: add unprocessed flag for file exporting

Add an unprocessed flag (-U) which modifies how files are exported.
In the case of a compressed raw file, extract without decompressing.
In the case of a stage or payload, extract without decompressing or
converting to an ELF.

This can be useful for verifying the integrity of a stage or payload,
since converting to an ELF may not be a deterministic process on
different platforms or coreboot versions.

BUG=b:111577108
TEST=USE=cb_legacy_tianocore emerge-eve edk2 coreboot-utils chromeos-bootimage
     cd /build/eve/firmware
     /build/eve/usr/bin/cbfstool image.bin extract -r RW_LEGACY \
       -n payload -f /tmp/payload_1 -U
     START=$((16#`xxd -s 20 -l 4 -p tianocore.cbfs`))
     SIZE=$((16#`xxd -s 8 -l 4 -p tianocore.cbfs`))
     dd if=tianocore.cbfs skip=$START count=$SIZE bs=1 > /tmp/payload_2
     diff /tmp/payload_1 /tmp/payload_2
     rm /tmp/payload_1 /tmp/payload_2

Change-Id: I351d471d699daedd51adf4a860661877f25607e6
Signed-off-by: Joel Kitching <kitching@chromium.org>
Reviewed-on: https://review.coreboot.org/29616
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
Reviewed-by: Julius Werner <jwerner@chromium.org>
This commit is contained in:
Joel Kitching
2018-08-09 17:49:52 +08:00
committed by Patrick Georgi
parent 73bbcee932
commit 21fdd89b0c
3 changed files with 47 additions and 23 deletions

View File

@@ -83,6 +83,7 @@ static struct param {
bool stage_xip;
bool autogen_attr;
bool machine_parseable;
bool unprocessed;
int fit_empty_entries;
enum comp_algo compression;
int precompression;
@@ -1095,7 +1096,7 @@ static int cbfs_extract(void)
return 1;
return cbfs_export_entry(&image, param.name, param.filename,
param.arch);
param.arch, !param.unprocessed);
}
static int cbfs_write(void)
@@ -1314,7 +1315,7 @@ static const struct command commands[] = {
{"compact", "r:h?", cbfs_compact, true, true},
{"copy", "r:R:h?", cbfs_copy, true, true},
{"create", "M:r:s:B:b:H:o:m:vh?", cbfs_create, true, true},
{"extract", "H:r:m:n:f:vh?", cbfs_extract, true, false},
{"extract", "H:r:m:n:f:Uvh?", cbfs_extract, true, false},
{"layout", "wvh?", cbfs_layout, false, false},
{"print", "H:r:vkh?", cbfs_print, true, false},
{"read", "r:f:vh?", cbfs_read, true, false},
@@ -1362,6 +1363,7 @@ static struct option long_options[] = {
{"xip", no_argument, 0, 'y' },
{"gen-attribute", no_argument, 0, 'g' },
{"mach-parseable",no_argument, 0, 'k' },
{"unprocessed", no_argument, 0, 'U' },
{NULL, 0, 0, 0 }
};
@@ -1428,6 +1430,7 @@ static void usage(char *name)
" -d Accept short data; fill downward/from top\n"
" -F Force action\n"
" -g Generate position and alignment arguments\n"
" -U Unprocessed; don't decompress or make ELF\n"
" -v Provide verbose output\n"
" -h Display this help message\n\n"
"COMMANDs:\n"
@@ -1473,8 +1476,8 @@ static void usage(char *name)
"List mutable (or, with -w, readable) image regions\n"
" print [-r image,regions] "
"Show the contents of the ROM\n"
" extract [-r image,regions] [-m ARCH] -n NAME -f FILE "
"Extracts a raw payload from ROM\n"
" extract [-r image,regions] [-m ARCH] -n NAME -f FILE [-U] "
"Extracts a file from ROM\n"
" write [-F] -r image,regions -f file [-u | -d] [-i int] "
"Write file into same-size [or larger] raw region\n"
" read [-r fmap-region] -f file "
@@ -1770,6 +1773,9 @@ int main(int argc, char **argv)
case 'k':
param.machine_parseable = true;
break;
case 'U':
param.unprocessed = true;
break;
case 'h':
case '?':
usage(argv[0]);