cbfstool: Don't add compression attribute for uncompressed files

Our current cbfstool has always added a compression attribute to the
CBFS file header for all files that used the cbfstool_convert_raw()
function (basically anything other than a stage or payload), even if the
compression type was NONE. This was likely some sort of oversight, since
coreboot CBFS reading code has always accepted the absence of a
compression attribute to mean "no compression". This patch fixes the
behavior to avoid adding the attribute in these cases.

Change-Id: Ic4a41152db9df66376fa26096d6f3a53baea51de
Signed-off-by: Julius Werner <jwerner@chromium.org>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/46835
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
This commit is contained in:
Julius Werner 2020-10-23 19:19:32 -07:00 committed by Patrick Georgi
parent d87a84830e
commit 105cdf5625
1 changed files with 5 additions and 1 deletions

View File

@ -595,6 +595,9 @@ static int cbfstool_convert_raw(struct buffer *buffer,
return -1; return -1;
memcpy(compressed, buffer->data + 8, compressed_size); memcpy(compressed, buffer->data + 8, compressed_size);
} else { } else {
if (param.compression == CBFS_COMPRESS_NONE)
goto out;
compress = compression_function(param.compression); compress = compression_function(param.compression);
if (!compress) if (!compress)
return -1; return -1;
@ -606,7 +609,7 @@ static int cbfstool_convert_raw(struct buffer *buffer,
compressed, &compressed_size)) { compressed, &compressed_size)) {
WARN("Compression failed - disabled\n"); WARN("Compression failed - disabled\n");
free(compressed); free(compressed);
return 0; goto out;
} }
} }
@ -626,6 +629,7 @@ static int cbfstool_convert_raw(struct buffer *buffer,
buffer->data = compressed; buffer->data = compressed;
buffer->size = compressed_size; buffer->size = compressed_size;
out:
header->len = htonl(buffer->size); header->len = htonl(buffer->size);
return 0; return 0;
} }