lib/cbfs: refactor code culling compression checks

Provide helper functions to determine if a compression
algorithm is supported in a given stage. Future patches can
use those functions to amend which algorithms to include in
the final link.

BUG=b:155322763,b:150746858,b:152909132

Change-Id: I898c939cec73d1f300ea38b165f379038877f05e
Signed-off-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/41754
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Furquan Shaikh <furquan@google.com>
Reviewed-by: Arthur Heymans <arthur@aheymans.xyz>
Reviewed-by: Julius Werner <jwerner@chromium.org>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
This commit is contained in:
Aaron Durbin 2020-05-26 15:48:10 -06:00 committed by Patrick Georgi
parent 02a1344921
commit a121f95393
1 changed files with 23 additions and 9 deletions

View File

@ -91,6 +91,27 @@ int cbfs_locate_file_in_region(struct cbfsf *fh, const char *region_name,
return ret;
}
static inline bool cbfs_lz4_enabled(void)
{
if ((ENV_BOOTBLOCK || ENV_SEPARATE_VERSTAGE) && !CONFIG(COMPRESS_PRERAM_STAGES))
return false;
return true;
}
static inline bool cbfs_lzma_enabled(void)
{
/* We assume here romstage and postcar are never compressed. */
if (ENV_BOOTBLOCK || ENV_SEPARATE_VERSTAGE)
return false;
if (ENV_ROMSTAGE && CONFIG(POSTCAR_STAGE))
return false;
if ((ENV_ROMSTAGE || ENV_POSTCAR)
&& !CONFIG(COMPRESS_RAMSTAGE))
return false;
return true;
}
size_t cbfs_load_and_decompress(const struct region_device *rdev, size_t offset,
size_t in_size, void *buffer, size_t buffer_size, uint32_t compression)
{
@ -105,8 +126,7 @@ size_t cbfs_load_and_decompress(const struct region_device *rdev, size_t offset,
return in_size;
case CBFS_COMPRESS_LZ4:
if ((ENV_BOOTBLOCK || ENV_SEPARATE_VERSTAGE) &&
!CONFIG(COMPRESS_PRERAM_STAGES))
if (!cbfs_lz4_enabled())
return 0;
/* Load the compressed image to the end of the available memory
@ -123,13 +143,7 @@ size_t cbfs_load_and_decompress(const struct region_device *rdev, size_t offset,
return out_size;
case CBFS_COMPRESS_LZMA:
/* We assume here romstage and postcar are never compressed. */
if (ENV_BOOTBLOCK || ENV_SEPARATE_VERSTAGE)
return 0;
if (ENV_ROMSTAGE && CONFIG(POSTCAR_STAGE))
return 0;
if ((ENV_ROMSTAGE || ENV_POSTCAR)
&& !CONFIG(COMPRESS_RAMSTAGE))
if (!cbfs_lzma_enabled())
return 0;
void *map = rdev_mmap(rdev, offset, in_size);
if (map == NULL)