The dtsi infers how to compress from whichever SPL decompressor happens
to be enabled, so there is no way to ask for one in particular, turning
a decompressor on for something else silently changes the image, and the
conditional has to be updated with every new algorithm.

Move the selection to Kconfig instead, with proper help texts and support
for all available compression algorithms. Each choice enables the
decompressor that provides it, and carries the compression level.

Signed-off-by: Alexey Charkov <[email protected]>
---
 arch/arm/dts/rockchip-u-boot.dtsi | 16 +++-----
 arch/arm/mach-rockchip/Kconfig    | 78 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 84 insertions(+), 10 deletions(-)

diff --git a/arch/arm/dts/rockchip-u-boot.dtsi 
b/arch/arm/dts/rockchip-u-boot.dtsi
index 4ba6a87e78ab..a72b55cec05a 100644
--- a/arch/arm/dts/rockchip-u-boot.dtsi
+++ b/arch/arm/dts/rockchip-u-boot.dtsi
@@ -11,14 +11,6 @@
 #define FIT_ARCH               "arm"
 #endif
 
-#if defined(CONFIG_SPL_GZIP)
-#define FIT_UBOOT_COMP         "gzip"
-#elif defined(CONFIG_SPL_LZMA)
-#define FIT_UBOOT_COMP         "lzma"
-#else
-#define FIT_UBOOT_COMP         "none"
-#endif
-
 /*
  * SHA256 should be enabled in SPL when signature validation is involved,
  * CRC32 should only be used for basic checksum validation of FIT images.
@@ -61,11 +53,15 @@
                                type = "standalone";
                                os = "u-boot";
                                arch = FIT_ARCH;
-                               compression = FIT_UBOOT_COMP;
+                               compression = CONFIG_ROCKCHIP_UBOOT_COMP;
                                load = <CONFIG_TEXT_BASE>;
                                entry = <CONFIG_TEXT_BASE>;
                                u-boot-nodtb {
-                                       compress = FIT_UBOOT_COMP;
+                                       compress = CONFIG_ROCKCHIP_UBOOT_COMP;
+#if CONFIG_ROCKCHIP_UBOOT_COMP_LEVEL != 0
+                                       compress-level =
+                                               
<CONFIG_ROCKCHIP_UBOOT_COMP_LEVEL>;
+#endif
                                };
 #ifdef FIT_HASH_ALGO
                                hash {
diff --git a/arch/arm/mach-rockchip/Kconfig b/arch/arm/mach-rockchip/Kconfig
index 1a2e7847c9e7..6e98534f28d7 100644
--- a/arch/arm/mach-rockchip/Kconfig
+++ b/arch/arm/mach-rockchip/Kconfig
@@ -758,6 +758,84 @@ config ROCKCHIP_MASKROM_IMAGE
          Rockchip SoCs support maskrom mode boot over USB. Enable this
          option to produce maskrom mode boot images containing U-Boot.
 
+choice
+       prompt "Compression for U-Boot proper in the SPL FIT"
+       depends on SPL_FIT
+       default ROCKCHIP_UBOOT_COMP_NONE
+       help
+         Pick how U-Boot proper is stored in the FIT which SPL loads it from.
+
+         It is around a megabyte, so what SPL spends unpacking it is close to
+         what it saves reading a smaller image, and leaving it alone is a
+         reasonable answer. Compress it where the room it takes up matters
+         more than the time.
+
+config ROCKCHIP_UBOOT_COMP_NONE
+       bool "none"
+       help
+         Store it as it is. SPL copies it into place rather than unpacking
+         it, and the build needs no host tool.
+
+config ROCKCHIP_UBOOT_COMP_GZIP
+       bool "gzip"
+       select SPL_GZIP
+       help
+         Compress with gzip, run from the host 'gzip' binary. A middling
+         ratio, quick to unpack, and it needs no SPL heap.
+
+config ROCKCHIP_UBOOT_COMP_LZMA
+       bool "lzma"
+       select SPL_LZMA
+       help
+         Compress with LZMA, run from the host 'lzma_alone' binary. The best
+         ratio on offer, and by far the slowest to unpack.
+
+config ROCKCHIP_UBOOT_COMP_LZO
+       bool "lzo"
+       select SPL_LZO
+       help
+         Compress with LZO, run from the host 'lzop' binary. A poor ratio in
+         exchange for fast decompression.
+
+config ROCKCHIP_UBOOT_COMP_LZ4
+       bool "lz4"
+       select SPL_LZ4
+       help
+         Compress with LZ4, run from the host 'lz4' binary. The fastest to
+         unpack and the worst ratio, so it suits a fast boot medium.
+
+config ROCKCHIP_UBOOT_COMP_ZSTD
+       bool "zstd"
+       select SPL_ZSTD
+       help
+         Compress with Zstandard, run from the host 'zstd' binary. Close to
+         the LZMA ratio for a fraction of the time, but its decompressor
+         wants around 94KB of SPL heap - see SPL_ZSTD.
+
+endchoice
+
+config ROCKCHIP_UBOOT_COMP
+       string
+       default "gzip" if ROCKCHIP_UBOOT_COMP_GZIP
+       default "lzma" if ROCKCHIP_UBOOT_COMP_LZMA
+       default "lzo" if ROCKCHIP_UBOOT_COMP_LZO
+       default "lz4" if ROCKCHIP_UBOOT_COMP_LZ4
+       default "zstd" if ROCKCHIP_UBOOT_COMP_ZSTD
+       default "none"
+
+config ROCKCHIP_UBOOT_COMP_LEVEL
+       int "Compression level for U-Boot proper"
+       depends on !ROCKCHIP_UBOOT_COMP_NONE && !ROCKCHIP_UBOOT_COMP_LZMA
+       range 0 9 if ROCKCHIP_UBOOT_COMP_GZIP || ROCKCHIP_UBOOT_COMP_LZO
+       range 0 12 if ROCKCHIP_UBOOT_COMP_LZ4
+       range 0 19 if ROCKCHIP_UBOOT_COMP_ZSTD
+       default 0
+       help
+         How hard to compress, numbered the way the algorithm's own tool
+         numbers it. Leave it at 0 to take the tool's default.
+
+         lzma has no such knob, so it is not offered there.
+
 config LNX_KRNL_IMG_TEXT_OFFSET_BASE
        default TEXT_BASE
 

-- 
2.55.0

Reply via email to