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>
diff --git a/src/lib/cbfs.c b/src/lib/cbfs.c
index a3294de..74df3c5 100644
--- a/src/lib/cbfs.c
+++ b/src/lib/cbfs.c
@@ -91,6 +91,27 @@
 	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 @@
 		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 @@
 		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)