spl_decompression_enabled() names the two algorithms SPL happened to
support, so every algorithm added to image_decomp() requires editing the
header. It also asks about CONFIG_SPL_* from a header included in every
phase, so a VPL build with VPL_LZMA reads SPL_LZMA and answers about the
wrong phase.

Add a hidden per-phase symbol selected by any of the compression
algorithms and ask about that instead, which also matches how
image_decomp() gates its own cases.

SPL_BZIP2 is out of scope: lib/bzip2 has no phase-aware build rule.

Signed-off-by: Alexey Charkov <[email protected]>
---
 common/spl/spl_fit.c |  6 +++---
 include/spl.h        | 10 ----------
 lib/Kconfig          | 30 ++++++++++++++++++++++++++++++
 3 files changed, 33 insertions(+), 13 deletions(-)

diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
index 1a0066c92a05..e02c746af5d3 100644
--- a/common/spl/spl_fit.c
+++ b/common/spl/spl_fit.c
@@ -284,15 +284,15 @@ static int load_simple_fit(struct spl_load_info *info, 
ulong fit_offset,
                }
        }
 
-       if (IS_ENABLED(CONFIG_SPL_FPGA) ||
-           (IS_ENABLED(CONFIG_SPL_OS_BOOT) && spl_decompression_enabled())) {
+       if (CONFIG_IS_ENABLED(FPGA) ||
+           (CONFIG_IS_ENABLED(OS_BOOT) && CONFIG_IS_ENABLED(DECOMPRESSION))) {
                if (fit_image_get_type(fit, node, &type))
                        puts("Cannot get image type.\n");
                else
                        debug("%s ", genimg_get_type_name(type));
        }
 
-       if (spl_decompression_enabled()) {
+       if (CONFIG_IS_ENABLED(DECOMPRESSION)) {
                fit_image_get_comp(fit, node, &image_comp);
                debug("%s ", genimg_get_comp_name(image_comp));
        }
diff --git a/include/spl.h b/include/spl.h
index 8a9f799f192a..32a9d7eb5230 100644
--- a/include/spl.h
+++ b/include/spl.h
@@ -1203,16 +1203,6 @@ void spl_save_restore_data(void);
 int spl_load_fit_image(struct spl_image_info *spl_image,
                       const struct legacy_img_hdr *header);
 
-/*
- * spl_decompression_enabled() - check decompression support is enabled for 
SPL build
- *
- * Returns  true  if decompression support is enabled, else False
- */
-static inline bool spl_decompression_enabled(void)
-{
-       return IS_ENABLED(CONFIG_SPL_GZIP) || IS_ENABLED(CONFIG_SPL_LZMA);
-}
-
 /**
  * spl_write_upl_handoff() - Write a Universal Payload hand-off structure
  *
diff --git a/lib/Kconfig b/lib/Kconfig
index 1292185e03f8..b42856ee6a92 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -934,6 +934,7 @@ config SPL_BZIP2
 config SPL_LZ4
        bool "Enable LZ4 decompression support in SPL"
        depends on SPL
+       select SPL_DECOMPRESSION
        help
          This enables support for the LZ4 decompression algorithm in SPL. LZ4
          is a lossless data compression algorithm that is focused on
@@ -943,6 +944,7 @@ config SPL_LZ4
 config TPL_LZ4
        bool "Enable LZ4 decompression support in TPL"
        depends on TPL
+       select TPL_DECOMPRESSION
        help
          This enables support for the LZ4 decompression algorithm in TPL. LZ4
          is a lossless data compression algorithm that is focused on
@@ -952,6 +954,7 @@ config TPL_LZ4
 config VPL_LZ4
        bool "Enable LZ4 decompression support in VPL"
        depends on VPL
+       select VPL_DECOMPRESSION
        help
          This enables support for the LZ4 decompression algorithm in VPL. LZ4
          is a lossless data compression algorithm that is focused on
@@ -961,6 +964,7 @@ config VPL_LZ4
 config SPL_LZMA
        bool "Enable LZMA decompression support for SPL build"
        depends on SPL
+       select SPL_DECOMPRESSION
        help
          This enables support for LZMA compression algorithm for SPL boot.
 
@@ -974,30 +978,35 @@ config SPL_LZMA_SIZE_OPTIMIZATION
 config TPL_LZMA
        bool "Enable LZMA decompression support for TPL build"
        depends on TPL
+       select TPL_DECOMPRESSION
        help
          This enables support for LZMA compression algorithm for TPL boot.
 
 config VPL_LZMA
        bool "Enable LZMA decompression support for VPL build"
        default y if LZMA
+       select VPL_DECOMPRESSION
        help
          This enables support for LZMA compression algorithm for VPL boot.
 
 config SPL_LZO
        bool "Enable LZO decompression support in SPL"
        depends on SPL
+       select SPL_DECOMPRESSION
        help
          This enables support for LZO compression algorithm in the SPL.
 
 config SPL_GZIP
        bool "Enable gzip decompression support for SPL build"
        select SPL_ZLIB
+       select SPL_DECOMPRESSION
        help
          This enables support for the GZIP compression algorithm for SPL boot.
 
 config TPL_GZIP
        bool "Enable gzip decompression support for SPL build"
        select TPL_ZLIB
+       select TPL_DECOMPRESSION
        help
          This enables support for the GZIP compression algorithm for TPL
 
@@ -1011,10 +1020,31 @@ config TPL_ZLIB
        help
          This enables compression lib for TPL
 
+config SPL_DECOMPRESSION
+       bool
+       help
+         Selected by every decompression algorithm available to SPL. Code
+         which hands a buffer to image_decomp() without caring which
+         algorithm produced it should depend on this, rather than list each
+         algorithm in turn.
+
+config TPL_DECOMPRESSION
+       bool
+       help
+         Selected by every decompression algorithm available to TPL. See
+         SPL_DECOMPRESSION.
+
+config VPL_DECOMPRESSION
+       bool
+       help
+         Selected by every decompression algorithm available to VPL. See
+         SPL_DECOMPRESSION.
+
 config SPL_ZSTD
        bool "Enable Zstandard decompression support in SPL"
        depends on SPL
        select SPL_XXHASH
+       select SPL_DECOMPRESSION
        help
          This enables Zstandard decompression library in the SPL.
 

-- 
2.55.0

Reply via email to