util/cbfstool/cbfs-payload-linux: Copy segments when compression fails

When compression fails (usually due to larger result), we could retry
with memcpy() as in cbfs-mkpayload.c, instead of stopping immediately.

Signed-off-by: Bill XIE <persmule@hardenedlinux.org>
Change-Id: Id8b2cffef3832c4bad49bd722c9a5133735f61b0
Reviewed-on: https://review.coreboot.org/c/coreboot/+/87934
Reviewed-by: Matt DeVillier <matt.devillier@gmail.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Bill XIE 2025-06-04 10:04:54 +08:00 committed by Matt DeVillier
commit f3ca3aa16b

View file

@ -163,10 +163,12 @@ static int bzp_output_segment(struct bzpayload *bzp, struct buffer *b,
seg->offset = bzp->offset;
comp_func_ptr compress_func = compression_function(algo);
int ret = compress_func(buffer_get(b), buffer_size(b), buffer_get(&out), &len);
if (ret) {
ERROR("%s(): Compression failed\n", __func__);
return ret;
if (compress_func(buffer_get(b), buffer_size(b), buffer_get(&out), &len)) {
WARN("Compression failed or would make the data bigger "
"- disabled.\n");
algo = CBFS_COMPRESS_NONE;
len = buffer_size(b);
memcpy(buffer_get(&out), buffer_get(b), len);
}
seg->compression = algo;