util/cbfstool: Enable adding precompressed files to cbfs
cbfstool ... add ... -c precompression assumes the input file to be created by cbfs-compression-tool's compress command and uses that to add the file with correct metadata. When adding the locale_*.bin files to Chrome OS images, this provides a nice speedup (since we can parallelize the precompression and avoid compressing everything twice) while creating a bit-identical file. Change-Id: Iadd106672c505909528b55e2cd43c914b95b6c6d Signed-off-by: Patrick Georgi <pgeorgi@chromium.org> Reviewed-on: https://review.coreboot.org/18102 Tested-by: build bot (Jenkins) Reviewed-by: Nico Huber <nico.h@gmx.de>
This commit is contained in:
parent
c88d16baaf
commit
ecaa570b60
|
@ -79,6 +79,7 @@ static struct param {
|
||||||
bool machine_parseable;
|
bool machine_parseable;
|
||||||
int fit_empty_entries;
|
int fit_empty_entries;
|
||||||
enum comp_algo compression;
|
enum comp_algo compression;
|
||||||
|
int precompression;
|
||||||
enum vb2_hash_algorithm hash;
|
enum vb2_hash_algorithm hash;
|
||||||
/* for linux payloads */
|
/* for linux payloads */
|
||||||
char *initrd;
|
char *initrd;
|
||||||
|
@ -439,33 +440,51 @@ static int cbfstool_convert_raw(struct buffer *buffer,
|
||||||
unused uint32_t *offset, struct cbfs_file *header)
|
unused uint32_t *offset, struct cbfs_file *header)
|
||||||
{
|
{
|
||||||
char *compressed;
|
char *compressed;
|
||||||
int compressed_size;
|
int decompressed_size, compressed_size;
|
||||||
|
comp_func_ptr compress;
|
||||||
|
|
||||||
comp_func_ptr compress = compression_function(param.compression);
|
decompressed_size = buffer->size;
|
||||||
if (!compress)
|
if (param.precompression) {
|
||||||
return -1;
|
param.compression = le32toh(((uint32_t *)buffer->data)[0]);
|
||||||
compressed = calloc(buffer->size, 1);
|
decompressed_size = le32toh(((uint32_t *)buffer->data)[1]);
|
||||||
|
compressed_size = buffer->size - 8;
|
||||||
if (compress(buffer->data, buffer->size,
|
compressed = malloc(compressed_size);
|
||||||
compressed, &compressed_size)) {
|
if (!compressed)
|
||||||
WARN("Compression failed - disabled\n");
|
return -1;
|
||||||
} else {
|
memcpy(compressed, buffer->data + 8, compressed_size);
|
||||||
struct cbfs_file_attr_compression *attrs =
|
} else {
|
||||||
(struct cbfs_file_attr_compression *)
|
compress = compression_function(param.compression);
|
||||||
cbfs_add_file_attr(header,
|
if (!compress)
|
||||||
CBFS_FILE_ATTR_TAG_COMPRESSION,
|
return -1;
|
||||||
sizeof(struct cbfs_file_attr_compression));
|
compressed = calloc(buffer->size, 1);
|
||||||
if (attrs == NULL)
|
if (!compressed)
|
||||||
return -1;
|
return -1;
|
||||||
attrs->compression = htonl(param.compression);
|
|
||||||
attrs->decompressed_size = htonl(buffer->size);
|
|
||||||
|
|
||||||
free(buffer->data);
|
if (compress(buffer->data, buffer->size,
|
||||||
buffer->data = compressed;
|
compressed, &compressed_size)) {
|
||||||
buffer->size = compressed_size;
|
WARN("Compression failed - disabled\n");
|
||||||
|
free(compressed);
|
||||||
header->len = htonl(buffer->size);
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct cbfs_file_attr_compression *attrs =
|
||||||
|
(struct cbfs_file_attr_compression *)
|
||||||
|
cbfs_add_file_attr(header,
|
||||||
|
CBFS_FILE_ATTR_TAG_COMPRESSION,
|
||||||
|
sizeof(struct cbfs_file_attr_compression));
|
||||||
|
if (attrs == NULL) {
|
||||||
|
free(compressed);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
attrs->compression = htonl(param.compression);
|
||||||
|
attrs->decompressed_size = htonl(decompressed_size);
|
||||||
|
|
||||||
|
free(buffer->data);
|
||||||
|
buffer->data = compressed;
|
||||||
|
buffer->size = compressed_size;
|
||||||
|
|
||||||
|
header->len = htonl(buffer->size);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1347,6 +1366,10 @@ int main(int argc, char **argv)
|
||||||
optarg);
|
optarg);
|
||||||
break;
|
break;
|
||||||
case 'c': {
|
case 'c': {
|
||||||
|
if (strcmp(optarg, "precompression") == 0) {
|
||||||
|
param.precompression = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
int algo = cbfs_parse_comp_algo(optarg);
|
int algo = cbfs_parse_comp_algo(optarg);
|
||||||
if (algo >= 0)
|
if (algo >= 0)
|
||||||
param.compression = algo;
|
param.compression = algo;
|
||||||
|
|
Loading…
Reference in New Issue