diff options
author | Aaron Durbin <adurbin@chromium.org> | 2020-05-26 15:48:10 -0600 |
---|---|---|
committer | Patrick Georgi <pgeorgi@google.com> | 2020-05-28 05:47:53 +0000 |
commit | a121f953937eb718cc579ce2c428937d00a91287 (patch) | |
tree | 79c4c91676a8512f24cbb8b84c23115e8fc52359 /src/lib | |
parent | 02a1344921a6cd848fe4f766e64e602632435ea8 (diff) |
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>
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/cbfs.c | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/src/lib/cbfs.c b/src/lib/cbfs.c index a3294de63e..74df3c5b39 100644 --- a/src/lib/cbfs.c +++ b/src/lib/cbfs.c @@ -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) |