[PATCH 1/3] spl: fit: Discard decompression if not supported

Loic Poulain loic.poulain at linaro.org
Fri Nov 3 15:34:24 CET 2023


And simplify further decompression testing.

Signed-off-by: Loic Poulain <loic.poulain at linaro.org>
---
 common/spl/spl_fit.c | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
index 70d8d5942d..1d42cb1d10 100644
--- a/common/spl/spl_fit.c
+++ b/common/spl/spl_fit.c
@@ -208,6 +208,20 @@ static int get_aligned_image_size(struct spl_load_info *info, int data_size,
 	return (data_size + info->bl_len - 1) / info->bl_len;
 }
 
+static inline bool spl_fit_decompression_supported(uint8_t comp)
+{
+	switch (comp) {
+	case IH_COMP_GZIP:
+		return IS_ENABLED(CONFIG_SPL_GZIP);
+	case IH_COMP_LZMA:
+		return IS_ENABLED(CONFIG_SPL_LZMA);
+	case IH_COMP_NONE:
+		return true;
+	}
+
+	return false;
+}
+
 /**
  * load_simple_fit(): load the image described in a certain FIT node
  * @info:	points to information about the device to load data from
@@ -235,7 +249,7 @@ static int load_simple_fit(struct spl_load_info *info, ulong sector,
 	void *src;
 	ulong overhead;
 	int nr_sectors;
-	uint8_t image_comp = -1, type = -1;
+	uint8_t image_comp, type = -1;
 	const void *data;
 	const void *fit = ctx->fit;
 	bool external_data = false;
@@ -248,9 +262,11 @@ static int load_simple_fit(struct spl_load_info *info, ulong sector,
 			debug("%s ", genimg_get_type_name(type));
 	}
 
-	if (spl_decompression_enabled()) {
-		fit_image_get_comp(fit, node, &image_comp);
-		debug("%s ", genimg_get_comp_name(image_comp));
+	fit_image_get_comp(fit, node, &image_comp);
+	if (!spl_fit_decompression_supported(image_comp)) {
+		debug("Discard unsupported compression %s ",
+		      genimg_get_comp_name(image_comp));
+		image_comp = IH_COMP_NONE;
 	}
 
 	if (fit_image_get_load(fit, node, &load_addr)) {
@@ -283,8 +299,7 @@ static int load_simple_fit(struct spl_load_info *info, ulong sector,
 			return 0;
 		}
 
-		if (spl_decompression_enabled() &&
-		    (image_comp == IH_COMP_GZIP || image_comp == IH_COMP_LZMA))
+		if (image_comp != IH_COMP_NONE)
 			src_ptr = map_sysmem(ALIGN(CONFIG_SYS_LOAD_ADDR, ARCH_DMA_MINALIGN), len);
 		else
 			src_ptr = map_sysmem(ALIGN(load_addr, ARCH_DMA_MINALIGN), len);
-- 
2.34.1



More information about the U-Boot mailing list