spl: fit: Generalize compression support
Subsystems (5)
v2 cover spl: fit: Generalize compression support
SPL knows about multiple compression algorithms, but only two are hand-rolled into the simple FIT loading code, in spite of a nice ready made helper already being available right there.
Generalize the compressed FIT handling code to accept any compression algorithm compiled into the SPL, and fix up the SPL_ZSTD linkage which requires xxhash in the SPL but which was absent to date.
While here, also extend binman to support passing a compression level via its image templates, which helps squeeze additional ~15% size savings in my testing with Zstd level 19 without impacting decompression speed.
This is done with Rockchip RK3576 in mind, so a small Rockchip image template refactor is included.
CI passes all green: https://git.u-boot-project.org/u-boot/contributors/alchark/u-boot/-/pipelines/1319
---
Changes in v2:
- Dropped redundant help text passage about SPL heap free() being noop (thanks Tom)
- Dropped redundant indirection via spl_decompression_enabled() now that it's directly queryable via the new Kconfig symbol (thanks Tom)
- Link to v1: https://patch.msgid.link/[email protected]
To: [email protected]
Cc: Tom Rini <[email protected]>
Cc: Alexey Charkov <[email protected]>
Cc: Quentin Schulz <[email protected]>
Cc: Ilias Apalodimas <[email protected]>
Cc: Vincent Jardin <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: Casey Connolly <[email protected]>
Cc: Michael Srba <[email protected]>
Cc: Cole Munz <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Francesco Valla <[email protected]>
Cc: Anton Ivanov <[email protected]>
Cc: Aristo Chen <[email protected]>
Cc: João Marcos Costa <[email protected]>
Cc: Richard Genoud <[email protected]>
Cc: Daniel Golle <[email protected]>
Cc: Heinrich Schuchardt <[email protected]>
Cc: Alper Nebi Yasak <[email protected]>
Cc: James Hilliard <[email protected]>
Cc: Quentin Schulz <[email protected]>
Cc: Kever Yang <[email protected]>
Cc: Johan Jonker <[email protected]>
---
Alexey Charkov (11):
boot: image: Keep the image-type table out of xPL
lib: Build xxhash in the SPL phase
lib: Let SPL minify zstd on its own
lib: Track whether a phase has a decompressor
spl: fit: Decompress any supported algorithm
test: spl: Keep the payload create_fit() is handed
test: spl: Size the FIT properties for the image name
test: spl: Cover FIT image decompression
sandbox: spl: Enable zstd
binman: Allow choosing the compression level
rockchip: Choose FIT payload compression via Kconfig
arch/arm/dts/rockchip-u-boot.dtsi | 16 ++--- arch/arm/mach-rockchip/Kconfig | 78 ++++++++++++++++++++ boot/image.c | 7 +- common/spl/spl_fit.c | 33 ++++----- configs/sandbox_spl_defconfig | 3 +- include/spl.h | 10 --- include/test/spl.h | 8 +++ lib/Kconfig | 52 +++++++++++++- lib/Makefile | 3 +- lib/zstd/Makefile | 2 +- test/image/spl_load.c | 84 +++++++++++++++++----- test/image/spl_load_nor.c | 2 + tools/binman/binman.rst | 21 ++++++ tools/binman/bintool.py | 10 ++- tools/binman/btool/lz4.py | 6 +- tools/binman/btool/lzma_alone.py | 6 +- tools/binman/entry.py | 6 +- tools/binman/ftest.py | 34 +++++++++ tools/binman/test/entry/compress_level.dts | 12 ++++ tools/binman/test/entry/compress_level_gzip.dts | 12 ++++ tools/binman/test/entry/compress_level_lzma.dts | 12 ++++ .../test/entry/compress_level_no_compress.dts | 11 +++ 22 files changed, 359 insertions(+), 69 deletions(-)
---
base-commit: b8e0086b585791a771416ce51b58ce0097bc0b28
change-id: 20260915-spl-fit-compression-62108358dc6f
Best regards,
Signature · 1 line
Alexey Charkov <[email protected]>
PATCH v2 1/11 boot: image: Keep the image-type table out of xPL
print_decomp_msg() names the image it is about to unpack, which drags uimage_type[] and its strings into any phase that links image_decomp(). That is about 2.5KB, measured on a Rockchip RK3576 SPL, spent on one line of progress output in a phase built for size.
Name it "image" there instead. U-Boot proper is unchanged.
--- boot/image.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
boot/image.c +6 -1
@@ -416,7 +416,12 @@ void image_print_contents(const void *ptr)static void print_decomp_msg (int comp_type,int type,bool is_xip,ulong load) { -const char *name =genimg_get_type_name (type); +/* +* The image-type table and its strings cost about 2.5KB, which is a +* lot to spend on a progress message in a phase built for size. +*/ +const char *name =IS_ENABLED (CONFIG_XPL_BUILD ) ?"image" : +genimg_get_type_name (type);/* Shows "Loading Kernel Image" for example */ if (comp_type ==IH_COMP_NONE )
Signature · 1 line
2.55.0
Re: [PATCH v2 01/11] boot: image: Keep the image-type table out of xPL
Hi Alexey,
Quoted 7 lines · Alexey Charkov
print_decomp_msg()names the image it is about to unpack, which drags uimage_type[] and its strings into any phase that linksimage_decomp(). That is about 2.5KB, measured on a Rockchip RK3576 SPL, spent on one line of progress output in a phase built for size.Name it "image" there instead. U-Boot proper is unchanged.
Would it make sense to also print the hex/dec value image type stored in the type parameter? Considering we have:
## Checking hash(es) for Image u-boot ... sha256+ OK
Uncompressing image to 800000
we know which image we're trying to uncompress so maybe this isn't so important (provided you have access to the original u-boot.itb and know you can run mkimage -l on it).
I tried reverting only this patch in the series and I get
Uncompressing Invalid Image to 800000
which is a bit odd since we actually should have a known type instead of invalid image (standalone program is what we have for U-Boot proper). So it wouldn't actually help to print the hex/dec value and would even be more confusing to the user (well, except if we fix this type being of unexpected value).
Cheers,
Quentin
Quoted 25 lines
Reviewed-by Tom Rini <[email protected]>Signed-off-by Alexey Charkov <[email protected]>--- boot/image.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)boot/image.c +6
-1@@ -416,7 +416,12 @@ void image_print_contents(const void *ptr)static void print_decomp_msg (int comp_type,int type,bool is_xip,ulong load) { -const char *name =genimg_get_type_name (type); +/* +* The image-type table and its strings cost about 2.5KB, which is a +* lot to spend on a progress message in a phase built for size. +*/ +const char *name =IS_ENABLED (CONFIG_XPL_BUILD ) ?"image" : +genimg_get_type_name (type);/* Shows "Loading Kernel Image" for example */ if (comp_type ==IH_COMP_NONE )
Re: [PATCH v2 01/11] boot: image: Keep the image-type table out of xPL
Hi Quentin,
Quoted 12 lines · Quentin Schulz
Hi Alexey,
Quoted 7 lines · Alexey Charkov
print_decomp_msg()names the image it is about to unpack, which drags uimage_type[] and its strings into any phase that linksimage_decomp(). That is about 2.5KB, measured on a Rockchip RK3576 SPL, spent on one line of progress output in a phase built for size.Name it "image" there instead. U-Boot proper is unchanged.
Quoted 7 lines
Would it make sense to also print the hex/dec value image type stored in the type parameter? Considering we have:
## Checking hash(es) for Image u-boot ... sha256+ OK
Uncompressing image to 800000
we know which image we're trying to uncompress so maybe this isn't so important (provided you have access to the original u-boot.itb and know you can run mkimage -l on it).
In fact, we aren't even parsing the image type by default in SPL, except in limited cases defined by CONFIG_IS_ENABLED(FPGA) || (CONFIG_IS_ENABLED(OS_BOOT) && CONFIG_IS_ENABLED(DECOMPRESSION)), so printing the numeric type value won't be helpful most of the time.
Quoted 7 lines
I tried reverting only this patch in the series and I get
Uncompressing Invalid Image to 800000
which is a bit odd since we actually should have a known type instead of invalid image (standalone program is what we have for U-Boot proper). So it wouldn't actually help to print the hex/dec value and would even be more confusing to the user (well, except if we fix this type being of unexpected value).
It would have been "Unknown Image", had I not been overzealous replacing the initialization values in patch 5, as mentioned in that patch's thread. IMO "Unknown Image" carries about the same descriptive power as "image" alone though.
Best regards,
Alexey
Re: [PATCH v2 01/11] boot: image: Keep the image-type table out of xPL
In reply to Alexey CharkovQuoted 22 lines · Alexey Charkov
print_decomp_msg()names the image it is about to unpack, which drags uimage_type[] and its strings into any phase that linksimage_decomp(). That is about 2.5KB, measured on a Rockchip RK3576 SPL, spent on one line of progress output in a phase built for size.Name it "image" there instead. U-Boot proper is unchanged.
Reviewed-by Tom Rini <[email protected]>Signed-off-by Alexey Charkov <[email protected]>--- boot/image.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)boot/image.c +0
-0@@ -416,7 +416,12 @@ void image_print_contents(const void *ptr)static void print_decomp_msg (int comp_type,int type,bool is_xip,ulong load) {
boot/image.c void image_print_contents(const void *ptr) · line 427
Quoted 10 lines
boot/image.c +6
-1-const char *name =genimg_get_type_name (type); +/* +* The image-type table and its strings cost about 2.5KB, which is a +* lot to spend on a progress message in a phase built for size. +*/ +const char *name =IS_ENABLED (CONFIG_XPL_BUILD ) ?"image" : +genimg_get_type_name (type);/* Shows "Loading Kernel Image" for example */ if (comp_type ==IH_COMP_NONE )
The print_decomp_msg() output is irrelevant to end users.
Do we need print_decomp_msg() at all in XPL? Even for main U-Boot this should only be a debug message.
Best regards
Heinrich
Re: [PATCH v2 01/11] boot: image: Keep the image-type table out of xPL
Quoted 31 lines · Heinrich Schuchardt
Quoted 29 lines · Alexey Charkov
print_decomp_msg()names the image it is about to unpack, which drags uimage_type[] and its strings into any phase that linksimage_decomp(). That is about 2.5KB, measured on a Rockchip RK3576 SPL, spent on one line of progress output in a phase built for size.Name it "image" there instead. U-Boot proper is unchanged.
Reviewed-by Tom Rini <[email protected]>Signed-off-by Alexey Charkov <[email protected]>--- boot/image.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)boot/image.c +6
-1@@ -416,7 +416,12 @@ void image_print_contents(const void *ptr)static void print_decomp_msg (int comp_type,int type,bool is_xip,ulong load) { -const char *name =genimg_get_type_name (type); +/* +* The image-type table and its strings cost about 2.5KB, which is a +* lot to spend on a progress message in a phase built for size. +*/ +const char *name =IS_ENABLED (CONFIG_XPL_BUILD ) ?"image" : +genimg_get_type_name (type);
Quoted 8 lines
boot/image.c void image_print_contents(const void *ptr) · line 427
Quoted 3 lines
boot/image.c +0
-0/* Shows "Loading Kernel Image" for example */ if (comp_type ==IH_COMP_NONE )The
print_decomp_msg()output is irrelevant to end users.Do we need
print_decomp_msg()at all in XPL? Even for main U-Boot this should only be a debug message.
I believe it is a helpful progress indicator. End users would rarely stare at xPL console messages if everything goes well, and if they do stare at it (which requires having console output, a debug feature, enabled in the first place) they'll probably want to know where everything stopped going well without jumping through too many hoops.
Best regards,
Alexey
Re: [PATCH v2 01/11] boot: image: Keep the image-type table out of xPL
In reply to Alexey CharkovHi Alexey,
Quoted 6 lines · Alexey Charkov
boot: image: Keep the image-type table out of xPL
print_decomp_msg()names the image it is about to unpack, which drags uimage_type[] and its strings into any phase that linksimage_decomp(). That is about 2.5KB, measured on a Rockchip RK3576 SPL, spent on one line of progress output in a phase built for size.
Not quite. This only holds where nothing else in the phase needs the table. load_simple_fit() calls fit_image_get_type() when SPL_FPGA is enabled, or SPL_OS_BOOT plus a decompressor, and that uses genimg_get_type_id() which needs uimage_type[] too.
I tried xilinx_zynqmp_virt (SPL_FPGA and SPL_GZIP) with the whole series applied, with and without this patch:
text data bss dec hex filename
131556 6968 440 138964 21ed4 spl/u-boot-spl (with)
131650 6968 440 139058 21f32 spl/u-boot-spl (without)So that is 94 bytes saved and uimage_type[] (0x480 bytes plus its strings) is still in the map. Please can you update the commit message to say when the saving applies?
Quoted 11 lines
Name it "image" there instead. U-Boot proper is unchanged.
Reviewed-by Tom Rini <[email protected]>Signed-off-by Alexey Charkov <[email protected]>
boot/image.c| 7 ++++++-1 file changed, 6 insertions(+), 1 deletion(-)
boot/image.c void image_print_contents(const void *ptr) · line 421
Quoted 6 lines
boot/image.c +6
-0@@ -416,7 +416,12 @@ void image_print_contents(const void *ptr) +/* +* The image-type table and its strings cost about 2.5KB, which is a +* lot to spend on a progress message in a phase built for size. +*/ +const char *name =IS_ENABLED (CONFIG_XPL_BUILD ) ?"image" : +genimg_get_type_name (type);
The boards which keep the table are those where load_simple_fit() reads the type from the FIT, so the name would be correct there. On the others the type is never read, so the lookup can only produce 'Unknown Image' anyway. So this drops the name in the one case where it is useful and nearly free.
I suspect it would be better to key this off the same condition which load_simple_fit() uses to read the type, rather than CONFIG_XPL_BUILD, perhaps with a small helper in image.h shared by both. I am not sure how neat that would be, though, since any xPL build with LOAD_FIT_FULL also has the table, via fit_image_load(). What do you think?
Regards,
Simon
PATCH v2 2/11 lib: Build xxhash in the SPL phase
In reply to Alexey CharkovSPL_ZSTD selects XXHASH, but xxhash.o is built from inside the ifndef CONFIG_XPL_BUILD block, so it never reaches an SPL link. zstd's decompressor calls xxh64_* from code that survives --gc-sections, so today the option only builds because nothing in SPL calls zstd_decompress() and the whole library is discarded. The first caller would fail to link.
Give xxhash its own phase symbol and build rule, the way the other compression libraries already have, and note in the SPL_ZSTD help how much heap the decompressor wants, since that is the other thing which may stop it from working.
--- lib/Kconfig | 10 +++++++++- lib/Makefile | 3 ++- 2 files changed, 11 insertions(+), 2 deletions(-)
lib/Kconfig +9 -1
@@ -833,6 +833,9 @@ config CRC32C config XXHASH bool +config SPL_XXHASH + bool + endmenu menu "Compression Support"
@@ -1011,10 +1014,15 @@ config TPL_ZLIB config SPL_ZSTD bool "Enable Zstandard decompression support in SPL" depends on SPL - select XXHASH + select SPL_XXHASH help This enables Zstandard decompression library in the SPL. + Decompression allocates a 94KB context, and nothing else: the + single-shot API it uses decompresses straight into the caller's + buffer and takes its window from there, so the compression level + does not change what the SPL heap has to hold. + endmenu config ERRNO_STR
lib/Makefile +2 -1
@@ -45,7 +45,6 @@ endif obj-$(CONFIG_SMBIOS_PARSER) += smbios-parser.o obj-$(CONFIG_IMAGE_SPARSE) += image-sparse.o obj-y += ldiv.o -obj-$(CONFIG_XXHASH) += xxhash.o obj-y += net_utils.o obj-$(CONFIG_PHYSMEM) += physmem.o obj-y += rc4.o
@@ -87,6 +86,8 @@ obj-$(CONFIG_$(PHASE_)SM3) += sm3.o obj-$(CONFIG_CRYPT_PW) += crypt/ obj-$(CONFIG_$(PHASE_)ASN1_DECODER_LEGACY) += asn1_decoder.o +obj-$(CONFIG_$(PHASE_)XXHASH) += xxhash.o + obj-$(CONFIG_$(PHASE_)ZLIB) += zlib/ obj-$(CONFIG_$(PHASE_)ZSTD) += zstd/ obj-$(CONFIG_$(PHASE_)GZIP) += gunzip.o
Signature · 1 line
2.55.0
Re: [PATCH v2 02/11] lib: Build xxhash in the SPL phase
Quoted 7 lines · Alexey Charkov
SPL_ZSTDselects XXHASH, but xxhash.o is built from inside the ifndefCONFIG_XPL_BUILDblock, so it never reaches an SPL link. zstd's decompressor calls xxh64_* from code that survives --gc-sections, so today the option only builds because nothing in SPL callszstd_decompress()and the whole library is discarded. The first caller would fail to link.
Quoted 6 lines
Give xxhash its own phase symbol and build rule, the way the other compression libraries already have, and note in the
SPL_ZSTDhelp how much heap the decompressor wants, since that is the other thing which may stop it from working.Signed-off-by Alexey Charkov <[email protected]>
Signature · 1 line
Tom
Re: [PATCH v2 02/11] lib: Build xxhash in the SPL phase
In reply to Alexey CharkovQuoted 14 lines · Alexey Charkov
lib: Build xxhash in the SPL phase
SPL_ZSTDselects XXHASH, but xxhash.o is built from inside the ifndefCONFIG_XPL_BUILDblock, so it never reaches an SPL link. zstd's decompressor calls xxh64_* from code that survives --gc-sections, so today the option only builds because nothing in SPL callszstd_decompress()and the whole library is discarded. The first caller would fail to link.Give xxhash its own phase symbol and build rule, the way the other compression libraries already have, and note in the
SPL_ZSTDhelp how much heap the decompressor wants, since that is the other thing which may stop it from working.
Quoted 6 lines
Signed-off-by Alexey Charkov <[email protected]>Reviewed-by Tom Rini <[email protected]>lib/Kconfig | 10 +++++++++-
lib/Makefile | 3 ++- 2 files changed, 11 insertions(+), 2 deletions(-)
PATCH v2 3/11 lib: Let SPL minify zstd on its own
In reply to Alexey CharkovZSTD_LIB_MINIFY is offered only inside "if ZSTD", so a board which enables zstd for SPL alone gets the full-size library in the phase which can least afford it.
Add an SPL-scoped variant of this option and key the build flags off that.
--- lib/Kconfig | 12 ++++++++++++ lib/zstd/Makefile | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-)
lib/Kconfig +12 -0
@@ -1023,6 +1023,18 @@ config SPL_ZSTD buffer and takes its window from there, so the compression level does not change what the SPL heap has to hold. +config SPL_ZSTD_LIB_MINIFY + bool "Minify Zstandard code in SPL" + depends on SPL_ZSTD + default y + help + This disables various optional components and changes the + compilation flags to prioritize space-saving. + + For detailed info, see zstd's lib/README.md + + https://github.com/facebook/zstd/blob/dev/lib/README.md + endmenu config ERRNO_STR
lib/zstd/Makefile +1 -1
@@ -11,7 +11,7 @@ obj-y += zstd_decompress.o obj-y += zstd_common.o -ifeq ($(CONFIG_ZSTD_LIB_MINIFY),y) +ifeq ($(CONFIG_$(PHASE_)ZSTD_LIB_MINIFY),y) ccflags-y += -DHUF_FORCE_DECOMPRESS_X1 ccflags-y += -DZSTD_FORCE_DECOMPRESS_SEQUENCES_SHORT ccflags-y += -DZSTD_NO_INLINE
Signature · 1 line
2.55.0
Re: [PATCH v2 03/11] lib: Let SPL minify zstd on its own
Quoted 24 lines · Alexey Charkov
ZSTD_LIB_MINIFYis offered only inside "if ZSTD", so a board which enables zstd for SPL alone gets the full-size library in the phase which can least afford it.Add an SPL-scoped variant of this option and key the build flags off that.
Reviewed-by Tom Rini <[email protected]>Signed-off-by Alexey Charkov <[email protected]>--- lib/Kconfig | 12 ++++++++++++ lib/zstd/Makefile | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-)lib/Kconfig +3
-0@@ -1023,6 +1023,18 @@ config SPL_ZSTD buffer and takes its window from there, so the compression level does not change what the SPL heap has to hold. +config SPL_ZSTD_LIB_MINIFY + bool "Minify Zstandard code in SPL" + depends on SPL_ZSTD
lib/Kconfig config SPL_ZSTD · line 1038
Quoted 10 lines
lib/Kconfig +9
-0+ default y + help + This disables various optional components and changes the + compilation flags to prioritize space-saving. + + For detailed info, see zstd's lib/README.md + + https://github.com/facebook/zstd/blob/dev/lib/README.md + endmenu
Why wouldn't you want this in main U-Boot too?
Best regards
Heinrich
Quoted 16 lines
lib/Kconfig +0
-0config ERRNO_STRlib/zstd/Makefile +1
-1@@ -11,7 +11,7 @@ obj-y += zstd_decompress.o obj-y += zstd_common.o -ifeq ($(CONFIG_ZSTD_LIB_MINIFY),y) +ifeq ($(CONFIG_$(PHASE_)ZSTD_LIB_MINIFY),y) ccflags-y += -DHUF_FORCE_DECOMPRESS_X1 ccflags-y += -DZSTD_FORCE_DECOMPRESS_SEQUENCES_SHORT ccflags-y += -DZSTD_NO_INLINE
Re: [PATCH v2 03/11] lib: Let SPL minify zstd on its own
Quoted 23 lines · Heinrich Schuchardt
Quoted 21 lines · Alexey Charkov
ZSTD_LIB_MINIFYis offered only inside "if ZSTD", so a board which enables zstd for SPL alone gets the full-size library in the phase which can least afford it.Add an SPL-scoped variant of this option and key the build flags off that.
Reviewed-by Tom Rini <[email protected]>Signed-off-by Alexey Charkov <[email protected]>--- lib/Kconfig | 12 ++++++++++++ lib/zstd/Makefile | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-)lib/Kconfig +0
-0@@ -1023,6 +1023,18 @@ config SPL_ZSTD buffer and takes its window from there, so the compression level does not change what the SPL heap has to hold.
Quoted 15 lines
lib/Kconfig config SPL_ZSTD · line 1038
Quoted 13 lines
lib/Kconfig +12
-0+config SPL_ZSTD_LIB_MINIFY + bool "Minify Zstandard code in SPL" + depends on SPL_ZSTD + default y + help + This disables various optional components and changes the + compilation flags to prioritize space-saving. + + For detailed info, see zstd's lib/README.md + + https://github.com/facebook/zstd/blob/dev/lib/README.md + endmenuWhy wouldn't you want this in main U-Boot too?
U-Boot proper already has this symbol, so I'm only mirroring it for the SPL use here.
Best regards,
Alexey
Re: [PATCH v2 03/11] lib: Let SPL minify zstd on its own
In reply to Alexey CharkovQuoted 6 lines · Alexey Charkov
lib: Let SPL minify zstd on its own
ZSTD_LIB_MINIFYis offered only inside "if ZSTD", so a board which enables zstd for SPL alone gets the full-size library in the phase which can least afford it.
Quoted 8 lines
Add an SPL-scoped variant of this option and key the build flags off that.
Reviewed-by Tom Rini <[email protected]>Signed-off-by Alexey Charkov <[email protected]>lib/Kconfig | 12 ++++++++++++
lib/zstd/Makefile | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-)
PATCH v2 4/11 lib: Track whether a phase has a decompressor
In reply to Alexey Charkovspl_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.
--- common/spl/spl_fit.c | 6 +++--- include/spl.h | 10 ---------- lib/Kconfig | 30 ++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 13 deletions(-)
common/spl/spl_fit.c +3 -3
@@ -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)); }
include/spl.h +0 -10
@@ -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 *
lib/Kconfig +30 -0
@@ -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.
Signature · 1 line
2.55.0
Re: [PATCH v2 04/11] lib: Track whether a phase has a decompressor
Quoted 6 lines · Alexey Charkov
spl_decompression_enabled()names the two algorithms SPL happened to support, so every algorithm added toimage_decomp()requires editing the header. It also asks about CONFIG_SPL_* from a header included in every phase, so a VPL build withVPL_LZMAreadsSPL_LZMAand answers about the wrong phase.
Quoted 7 lines
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_BZIP2is out of scope: lib/bzip2 has no phase-aware build rule.Signed-off-by Alexey Charkov <[email protected]>
Signature · 1 line
Tom
Re: [PATCH v2 04/11] lib: Track whether a phase has a decompressor
In reply to Alexey CharkovHi Alexey,
Quoted 24 lines · Alexey Charkov
lib: Track whether a phase has a decompressor
spl_decompression_enabled()names the two algorithms SPL happened to support, so every algorithm added toimage_decomp()requires editing the header. It also asks about CONFIG_SPL_* from a header included in every phase, so a VPL build withVPL_LZMAreadsSPL_LZMAand 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_BZIP2is out of scope: lib/bzip2 has no phase-aware build rule.Signed-off-by Alexey Charkov <[email protected]>Reviewed-by Tom Rini <[email protected]>
common/spl/spl_fit.c| 6 +++---include/spl.h | 10 ---------- lib/Kconfig | 30 ++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 13 deletions(-)
common/spl/spl_fit.c static int load_simple_fit(struct spl_load_info *info, ulong fit_offset, · line 285
Quoted 4 lines
common/spl/spl_fit.c +2
-2@@ -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 ))) {
The FPGA and OS_BOOT conversions are a separate change, not mentioned in the commit message. The rest of this file still uses IS_ENABLED(CONFIG_SPL_FPGA) and IS_ENABLED(CONFIG_SPL_OS_BOOT), e.g. in spl_fit_image_is_fpga(), os_takes_devicetree() and spl_load_simple_fit(), so this leaves the file inconsistent. There is no TPL_FPGA, VPL_FPGA, TPL_OS_BOOT or VPL_OS_BOOT either, so in those phases the answer now differs from the other checks.
Please can you either leave those two as they are, or convert the whole file in a separate patch?
lib/Kconfig config SPL_LZMA_SIZE_OPTIMIZATION · line 981
Quoted 6 lines
lib/Kconfig +1
-0@@ -974,30 +978,35 @@ config SPL_LZMA_SIZE_OPTIMIZATION config VPL_LZMA bool "Enable LZMA decompression support for VPL build" default y if LZMA + select VPL_DECOMPRESSION
VPL_LZMA has no 'depends on VPL', so with this select every board with LZMA enabled gets CONFIG_VPL_DECOMPRESSION=y, even with no VPL. I tried sandbox, qemu_arm64 and evb-rk3399 and all three end up with it in their .config file.
Please can you add a preparatory patch to give VPL_LZMA a 'depends on VPL'? BTW SPL_GZIP and TPL_GZIP have the same problem, although they don't default to y so it matters less.
lib/Kconfig config TPL_ZLIB · line 1026
Quoted 9 lines
lib/Kconfig +7
-0@@ -1011,10 +1020,31 @@ config TPL_ZLIB +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.
Not quite, since SPL_BZIP2 does not select it. The commit message explains why, but please can you mention the exception here too, since this is where people will look?
Also, there is no symbol for U-Boot proper, so CONFIG_IS_ENABLED(DECOMPRESSION) is silently false there. That is fine for spl_fit.c but anyone following this advice in code shared between phases (e.g. in boot/) will get the wrong answer. I suspect it is worth either adding a DECOMPRESSION symbol for U-Boot proper, or saying in the help that this is only for xPL code. What do you think?
I wish it were DECOMP instead of the rather verbose DECOMPRESSION
Regards,
Simon
Re: [PATCH v2 04/11] lib: Track whether a phase has a decompressor
Quoted 40 lines · Simon Glass
Hi Alexey,
Quoted 24 lines · Alexey Charkov
lib: Track whether a phase has a decompressor
spl_decompression_enabled()names the two algorithms SPL happened to support, so every algorithm added toimage_decomp()requires editing the header. It also asks about CONFIG_SPL_* from a header included in every phase, so a VPL build withVPL_LZMAreadsSPL_LZMAand 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_BZIP2is out of scope: lib/bzip2 has no phase-aware build rule.Signed-off-by Alexey Charkov <[email protected]>Reviewed-by Tom Rini <[email protected]>
common/spl/spl_fit.c| 6 +++---include/spl.h | 10 ---------- lib/Kconfig | 30 ++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 13 deletions(-)common/spl/spl_fit.c static int load_simple_fit(struct spl_load_info *info, ulong fit_offset, · line 285
Quoted 4 lines
common/spl/spl_fit.c +2
-2@@ -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 ))) {The FPGA and
OS_BOOTconversions are a separate change, not mentioned in the commit message. The rest of this file still usesIS_ENABLED(CONFIG_SPL_FPGA)andIS_ENABLED(CONFIG_SPL_OS_BOOT), e.g. inspl_fit_image_is_fpga(),os_takes_devicetree()andspl_load_simple_fit(), so this leaves the file inconsistent. There is noTPL_FPGA,VPL_FPGA,TPL_OS_BOOTorVPL_OS_BOOTeither, so in those phases the answer now differs from the other checks.
Quoted 2 lines
Please can you either leave those two as they are, or convert the whole file in a separate patch?
No, it's fine to not worry about those others until a need comes up.
Quoted 12 lines
lib/Kconfig config SPL_LZMA_SIZE_OPTIMIZATION · line 981
Quoted 6 lines
lib/Kconfig +1
-0@@ -974,30 +978,35 @@ config SPL_LZMA_SIZE_OPTIMIZATION config VPL_LZMA bool "Enable LZMA decompression support for VPL build" default y if LZMA + select VPL_DECOMPRESSION
VPL_LZMAhas no 'depends on VPL', so with this select every board with LZMA enabled getsCONFIG_VPL_DECOMPRESSION=y, even with no VPL. I tried sandbox,qemu_arm64and evb-rk3399 and all three end up with it in their .config file.
Quoted 3 lines
Please can you add a preparatory patch to give
VPL_LZMAa 'depends on VPL'? BTWSPL_GZIPandTPL_GZIPhave the same problem, although they don't default to y so it matters less.
This is also further nice-to-have cleanup work that's not relevant here.
Quoted 14 lines
lib/Kconfig config TPL_ZLIB · line 1026
Quoted 9 lines
lib/Kconfig +7
-0@@ -1011,10 +1020,31 @@ config TPL_ZLIB +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.Not quite, since
SPL_BZIP2does not select it. The commit message explains why, but please can you mention the exception here too, since this is where people will look?
Quoted 6 lines
Also, there is no symbol for U-Boot proper, so
CONFIG_IS_ENABLED(DECOMPRESSION)is silently false there. That is fine forspl_fit.cbut anyone following this advice in code shared between phases (e.g. in boot/) will get the wrong answer. I suspect it is worth either adding a DECOMPRESSION symbol for U-Boot proper, or saying in the help that this is only for xPL code. What do you think?
The whole set of things we're doing here is xPL, so we don't need a symbol for full U-Boot at this time.
Quoted 1 line
I wish it were DECOMP instead of the rather verbose DECOMPRESSION
It's also not worth redoing the series over, either. DECOMPRESSION is fine.
Signature · 1 line
Tom
PATCH v2 5/11 spl: fit: Decompress any supported algorithm
In reply to Alexey Charkovload_simple_fit() open-codes gzip and lzma in two places, so a FIT built with any of the other five algorithms image_decomp() implements is silently copied to its load address without decompression and jumped into, causing a hang with nothing on the console to aid debugging.
Call image_decomp() instead, which can handle all compression algorigthms enabled in the config, and will abort on an unknown one instead of trying to silently jump into it.
--- common/spl/spl_fit.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-)
common/spl/spl_fit.c +9 -18
@@ -6,7 +6,6 @@#include <errno.h> #include <fpga.h> -#include <gzip.h> #include <image.h> #include <log.h> #include <memalign.h>
@@ -260,7 +259,7 @@ static int load_simple_fit(struct spl_load_info *info, ulong fit_offset,ulong load_addr;void *load_ptr;void *src; -uint8_t image_comp =-1 , type =-1 ; +u8 image_comp =IH_COMP_NONE , type =IH_TYPE_INVALID ;const void *data;const void *fit = ctx->fit;bool external_data = false;
@@ -364,8 +363,7 @@ static int load_simple_fit(struct spl_load_info *info, ulong fit_offset, } read_offset = fit_offset + aligned_offset; -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);
@@ -429,25 +427,18 @@ static int load_simple_fit(struct spl_load_info *info, ulong fit_offset,if (CONFIG_IS_ENABLED (FIT_IMAGE_POST_PROCESS ))board_fit_image_post_process (fit, node, &src, &length); - load_ptr =map_sysmem (load_addr, length); -if (IS_ENABLED (CONFIG_SPL_GZIP ) && image_comp ==IH_COMP_GZIP ) { - size = length; -if (gunzip (load_ptr,CONFIG_SYS_BOOTM_LEN , src, &size)) { -puts ("Uncompressing error\n" ); -return -EIO ; - } - length = size; - }else if (IS_ENABLED (CONFIG_SPL_LZMA ) && image_comp ==IH_COMP_LZMA ) { - size =CONFIG_SYS_BOOTM_LEN ; -ulong loadEnd; +if (image_comp !=IH_COMP_NONE ) { +ulong load_end; -if (image_decomp (IH_COMP_LZMA ,CONFIG_SYS_LOAD_ADDR ,0 ,0 , - load_ptr, src, length, size, &loadEnd)) { + load_ptr =map_sysmem (load_addr, max_size); +if (image_decomp (image_comp, load_addr, (ulong )src, type, + load_ptr, src, length, max_size, &load_end)) {puts ("Uncompressing error\n" );return -EIO ; } - length = loadEnd -CONFIG_SYS_LOAD_ADDR ; + length = load_end - load_addr; }else { + load_ptr =map_sysmem (load_addr, length);memmove (load_ptr, src, length); }
Signature · 1 line
2.55.0
Re: [PATCH v2 05/11] spl: fit: Decompress any supported algorithm
Quoted 10 lines · Alexey Charkov
load_simple_fit()open-codes gzip and lzma in two places, so a FIT built with any of the other five algorithmsimage_decomp()implements is silently copied to its load address without decompression and jumped into, causing a hang with nothing on the console to aid debugging.Call
image_decomp()instead, which can handle all compression algorigthms enabled in the config, and will abort on an unknown one instead of trying to silently jump into it.Signed-off-by Alexey Charkov <[email protected]>
Signature · 1 line
Tom
Re: [PATCH v2 05/11] spl: fit: Decompress any supported algorithm
In reply to Alexey CharkovHi Alexey,
Quoted 36 lines · Alexey Charkov
load_simple_fit()open-codes gzip and lzma in two places, so a FIT built with any of the other five algorithmsimage_decomp()implements is silently copied to its load address without decompression and jumped into, causing a hang with nothing on the console to aid debugging.Call
image_decomp()instead, which can handle all compression algorigthms enabled in the config, and will abort on an unknown one instead of trying to silently jump into it.Signed-off-by Alexey Charkov <[email protected]>--- common/spl/spl_fit.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-)common/spl/spl_fit.c +1
-2@@ -6,7 +6,6 @@#include <errno.h> #include <fpga.h> -#include <gzip.h> #include <image.h> #include <log.h> #include <memalign.h> @@ -260,7 +259,7 @@ static int load_simple_fit(struct spl_load_info *info, ulong fit_offset,ulong load_addr;void *load_ptr;void *src; -uint8_t image_comp =-1 , type =-1 ; +u8 image_comp =IH_COMP_NONE , type =IH_TYPE_INVALID ;const void *data;const void *fit = ctx->fit;bool external_data = false;
common/spl/spl_fit.c static int load_simple_fit(struct spl_load_info *info, ulong fit_offset, · line 367
Quoted 4 lines
common/spl/spl_fit.c +0
-1@@ -364,8 +363,7 @@ static int load_simple_fit(struct spl_load_info *info, ulong fit_offset, } read_offset = fit_offset + aligned_offset; - if (spl_decompression_enabled() &&
You remove this function in the previous patch so the previous patch is breaking bisectability. I'm guessing you want to replace it in the previous patch with CONFIG_IS_ENABLED(DECOMPRESSION).
Quoted 17 lines
common/spl/spl_fit.c +1
-9- (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);@@ -429,25 +427,18 @@ static int load_simple_fit(struct spl_load_info *info, ulong fit_offset,if (CONFIG_IS_ENABLED (FIT_IMAGE_POST_PROCESS ))board_fit_image_post_process (fit, node, &src, &length); - load_ptr =map_sysmem (load_addr, length); -if (IS_ENABLED (CONFIG_SPL_GZIP ) && image_comp ==IH_COMP_GZIP ) { - size = length; -if (gunzip (load_ptr,CONFIG_SYS_BOOTM_LEN , src, &size)) { -puts ("Uncompressing error\n" ); -return -EIO ; - } - length = size;
common/spl/spl_fit.c static int load_simple_fit(struct spl_load_info *info, ulong fit_offset, · line 434
Quoted 10 lines
common/spl/spl_fit.c +4
-5- }else if (IS_ENABLED (CONFIG_SPL_LZMA ) && image_comp ==IH_COMP_LZMA ) { - size =CONFIG_SYS_BOOTM_LEN ; -ulong loadEnd; +if (image_comp !=IH_COMP_NONE ) { +ulong load_end; -if (image_decomp (IH_COMP_LZMA ,CONFIG_SYS_LOAD_ADDR ,0 ,0 , - load_ptr, src, length, size, &loadEnd)) { + load_ptr =map_sysmem (load_addr, max_size); + if (image_decomp(image_comp, load_addr, (ulong)src, type,
Because type is only assigned when
if (CONFIG_IS_ENABLED(FPGA) ||
(CONFIG_IS_ENABLED(OS_BOOT) && CONFIG_IS_ENABLED(DECOMPRESSION)))
we may pass type=IH_TYPE_INVALID (as initialized at the top of the function) to that function. I know because I reverted patch 1 in this series to see what it would print and it printed Invalid Image instead of Standalone Program. I'm not sure this is an issue, but it's for sure a bit odd.
Cheers,
Quentin
Re: [PATCH v2 05/11] spl: fit: Decompress any supported algorithm
Hi Quentin,
Quoted 43 lines · Quentin Schulz
Hi Alexey,
Quoted 39 lines · Alexey Charkov
load_simple_fit()open-codes gzip and lzma in two places, so a FIT built with any of the other five algorithmsimage_decomp()implements is silently copied to its load address without decompression and jumped into, causing a hang with nothing on the console to aid debugging.Call
image_decomp()instead, which can handle all compression algorigthms enabled in the config, and will abort on an unknown one instead of trying to silently jump into it.Signed-off-by Alexey Charkov <[email protected]>--- common/spl/spl_fit.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-)common/spl/spl_fit.c +1
-2@@ -6,7 +6,6 @@#include <errno.h> #include <fpga.h> -#include <gzip.h> #include <image.h> #include <log.h> #include <memalign.h> @@ -260,7 +259,7 @@ static int load_simple_fit(struct spl_load_info *info, ulong fit_offset,ulong load_addr;void *load_ptr;void *src; -uint8_t image_comp =-1 , type =-1 ; +u8 image_comp =IH_COMP_NONE , type =IH_TYPE_INVALID ;const void *data;const void *fit = ctx->fit;bool external_data = false;@@ -364,8 +363,7 @@ static int load_simple_fit(struct spl_load_info *info, ulong fit_offset, } read_offset = fit_offset + aligned_offset;
Quoted 5 lines
common/spl/spl_fit.c static int load_simple_fit(struct spl_load_info *info, ulong fit_offset, · line 367
Quoted 1 line
common/spl/spl_fit.c +0
-1- if (spl_decompression_enabled() &&You remove this function in the previous patch so the previous patch is breaking bisectability. I'm guessing you want to replace it in the previous patch with
CONFIG_IS_ENABLED(DECOMPRESSION).
Right, thanks for spotting that. That was a somewhat careless fixup/autosquash combo.
Quoted 31 lines
Quoted 17 lines
common/spl/spl_fit.c +1
-9- (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);@@ -429,25 +427,18 @@ static int load_simple_fit(struct spl_load_info *info, ulong fit_offset,if (CONFIG_IS_ENABLED (FIT_IMAGE_POST_PROCESS ))board_fit_image_post_process (fit, node, &src, &length); - load_ptr =map_sysmem (load_addr, length); -if (IS_ENABLED (CONFIG_SPL_GZIP ) && image_comp ==IH_COMP_GZIP ) { - size = length; -if (gunzip (load_ptr,CONFIG_SYS_BOOTM_LEN , src, &size)) { -puts ("Uncompressing error\n" ); -return -EIO ; - } - length = size;common/spl/spl_fit.c static int load_simple_fit(struct spl_load_info *info, ulong fit_offset, · line 434
Quoted 10 lines
common/spl/spl_fit.c +4
-5- }else if (IS_ENABLED (CONFIG_SPL_LZMA ) && image_comp ==IH_COMP_LZMA ) { - size =CONFIG_SYS_BOOTM_LEN ; -ulong loadEnd; +if (image_comp !=IH_COMP_NONE ) { +ulong load_end; -if (image_decomp (IH_COMP_LZMA ,CONFIG_SYS_LOAD_ADDR ,0 ,0 , - load_ptr, src, length, size, &loadEnd)) { + load_ptr =map_sysmem (load_addr, max_size); + if (image_decomp(image_comp, load_addr, (ulong)src, type,Because type is only assigned when
if (CONFIG_IS_ENABLED(FPGA) || (CONFIG_IS_ENABLED(OS_BOOT) &&
Quoted 7 lines
CONFIG_IS_ENABLED(DECOMPRESSION)))we may pass type=IH_TYPE_INVALID (as initialized at the top of the function) to that function. I know because I reverted patch 1 in this series to see what it would print and it printed Invalid Image instead of Standalone Program. I'm not sure this is an issue, but it's for sure a bit odd.
I believe switching the initializer from -1 to IH_TYPE_INVALID is not warranted after all. Without that, your test should print "Unknown Image" instead of "Invalid Image", which probably makes more sense (nobody said the image is invalid, because nobody checked it without the CONFIG_IS_ENABLED(FPGA) || (CONFIG_IS_ENABLED(OS_BOOT) && CONFIG_IS_ENABLED(DECOMPRESSION)) combination).
I'll revert the type initialization to -1 in v3.
Best regards,
Alexey
Re: [PATCH v2 05/11] spl: fit: Decompress any supported algorithm
In reply to Alexey CharkovHi Alexey,
Quoted 4 lines · Alexey Charkov
spl: fit: Decompress any supported algorithm
load_simple_fit()open-codes gzip and lzma in two places, so a FIT built with any of the other five algorithmsimage_decomp()implements is
I count four others (bzip2, lzo, lz4 and zstd), and bzip2 is still not reachable here since SPL_BZIP2 does not select SPL_DECOMPRESSION
Quoted 6 lines
silently copied to its load address without decompression and jumped into, causing a hang with nothing on the console to aid debugging.
Call
image_decomp()instead, which can handle all compression algorigthms enabled in the config, and will abort on an unknown one instead of trying to silently jump into it.
'algorithms'
This only holds when the phase has at least one decompressor enabled. Without CONFIG_IS_ENABLED(DECOMPRESSION) the 'compression' property is never read, so image_comp stays at IH_COMP_NONE and a compressed image is still copied and jumped into with nothing on the console. Please can you mention that limitation here? Another option would be to check the property in that case and fail if it is anything other than 'none', although that costs a little code size. What do you think?
common/spl/spl_fit.c static int load_simple_fit(struct spl_load_info *info, ulong fit_offset, · line 429
Quoted 12 lines
Signed-off-by Alexey Charkov <[email protected]>Reviewed-by Tom Rini <[email protected]>
common/spl/spl_fit.c| 27 +++++++++------------------1 file changed, 9 insertions(+), 18 deletions(-)common/spl/spl_fit.c +3
-0@@ -429,25 +427,18 @@ static int load_simple_fit(struct spl_load_info *info, ulong fit_offset, + load_ptr =map_sysmem (load_addr, max_size); +if (image_decomp (image_comp, load_addr, (ulong )src, type, + load_ptr, src, length, max_size, &load_end)) {
The old code passed CONFIG_SYS_BOOTM_LEN as the output limit for both gzip and lzma, regardless of the caller. With max_size, a compressed overlay is now limited to CONFIG_SPL_LOAD_FIT_APPLY_OVERLAY_BUF_SZ rather than being able to run off the end of the heap buffer. That is a good fix, but it is a behaviour change which the commit message does not mention. Please can you add a sentence about it?
The image_start parameter is an address, not a pointer, and src is a host pointer on sandbox. It is only used to decide whether to print 'XIP' for the uncompressed case, so it has no effect here. Please can you use map_to_sysmem(src), or just pass 0 as the old code did?
Regards,
Simon
PATCH v2 6/11 test: spl: Keep the payload create_fit() is handed
In reply to Alexey Charkovfdt_create() clears the whole buffer it is given, and for a FIT with internal data that buffer covers the payload the caller has already written at the offset create_image() told it to use. So every FIT_INTERNAL test has been loading zeros and comparing them against the same zeroed memory, and would pass whatever the loader did with them.
Keep a copy of the payload across the call.
--- test/image/spl_load.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
test/image/spl_load.c +22 -1
@@ -164,6 +164,7 @@ static size_t create_fit(void *dst, struct spl_image_info *spl_image, size_t *data_offset, bool external) { size_t prop_size = 596, total_size = prop_size + spl_image->size; +void *payload =NULL ;size_t off, size;if (external) {
@@ -184,8 +185,28 @@ static size_t create_fit(void *dst, struct spl_image_info *spl_image,if (!dst) goto out; -if (start_fit (dst, size, spl_image->size, external) != off) +/* +* fdt_create() clears every byte of the buffer it is given. For +* internal data that buffer covers the payload our caller was asked to +* write beforehand, so keep a copy across the call. Nothing written +* after it reaches back that far. +*/ +if (!external && spl_image->size) { + payload =malloc (spl_image->size); +if (!payload) +return 0 ; +memcpy (payload, dst + off, spl_image->size); + } + +if (start_fit (dst, size, spl_image->size, external) != off) { +free (payload);return 0 ; + } + +if (payload) { +memcpy (dst + off, payload, spl_image->size); +free (payload); + }if (fdt_property_string (dst,FIT_DESC_PROP , spl_image->name))return 0 ;
Signature · 1 line
2.55.0
Re: [PATCH v2 06/11] test: spl: Keep the payload create_fit() is handed
Hi Alexey,
Quoted 7 lines · Alexey Charkov
test: spl: Keep the payload
create_fit()is handed
fdt_create()clears the whole buffer it is given, and for a FIT with internal data that buffer covers the payload the caller has already written at the offsetcreate_image()told it to use. So everyFIT_INTERNALtest has been loading zeros and comparing them against the same zeroed memory, and would pass whatever the loader did with them.
Nice catch!
Since this fixes a bug in the test, please can you add a tag:
Quoted 10 lines
Keep a copy of the payload across the call.
Signed-off-by Alexey Charkov <[email protected]>
test/image/spl_load.c| 23 ++++++++++++++++++++++-1 file changed, 22 insertions(+), 1 deletion(-)
test/image/spl_load.c static size_t create_fit(void *dst, struct spl_image_info *spl_image, · line 188
Quoted 4 lines
test/image/spl_load.c +4
-0@@ -184,8 +185,28 @@ static size_t create_fit(void *dst, struct spl_image_info *spl_image, +if (payload) { +memcpy (dst + off, payload, spl_image->size); +free (payload); + }
This fixes the problem, but nothing stops it coming back, since the callers compare the loaded data against the same buffer which create_fit() can clobber. It went unnoticed because both sides of ut_asserteq_mem() ended up as zeroes.
I suspect it is worth adding a check in the callers, e.g. in spl_test_image() and do_spl_test_load(), that the payload in the image is still what generate_data() produces after create_image() returns. Even just regenerating the data into a separate buffer and comparing against that would do. What do you think?
Regards,
Simon
PATCH v2 7/11 test: spl: Size the FIT properties for the image name
In reply to Alexey Charkovcreate_fit() budgets a flat 596 bytes for the properties it writes, but one of them is the image name (named after the test itself), which is used twice and can cause libfdt run out of room and create_fit() return 0 if a new test with a longer name is added.
Size the buffer accounting for the name explicitly.
--- test/image/spl_load.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
test/image/spl_load.c +8 -1
@@ -163,7 +163,14 @@ static size_t start_fit(void *dst, size_t fit_size, size_t data_size,static size_t create_fit (void *dst,struct spl_image_info *spl_image,size_t *data_offset,bool external) { -size_t prop_size =596 , total_size = prop_size + spl_image->size; +/* +* The name goes in twice, as the description of both the image and the +* configuration, and for external data this budget is exact: it is the +* whole buffer start_fit() gets, and where the data then starts, which +* the loader expects 4-byte aligned. +*/ +size_t prop_size =ALIGN (596 +2 *strlen (spl_image->name),4 ); +size_t total_size = prop_size + spl_image->size;void *payload =NULL ;size_t off, size;
Signature · 1 line
2.55.0
Re: [PATCH v2 07/11] test: spl: Size the FIT properties for the image name
Hi Alexey,
Quoted 6 lines · Alexey Charkov
test: spl: Size the FIT properties for the image name
create_fit()budgets a flat 596 bytes for the properties it writes, but one of them is the image name (named after the test itself), which is used twice and can cause libfdt run out of room andcreate_fit()return 0 if a new test with a longer name is added.
'can cause libfdt to run out of room'
Please can you make the motivation concrete? By my measurement on 64-bit sandbox, 596 bytes fits a name of up to 27 characters, which is exactly spl_test_image_FIT_INTERNAL, and the next patch adds 30-character names such as spl_test_nor_FIT_INTERNAL_LZMA. So this is needed by the series, rather than being a hypothetical problem.
Quoted 10 lines
Size the buffer accounting for the name explicitly.
Signed-off-by Alexey Charkov <[email protected]>
test/image/spl_load.c| 9 ++++++++-1 file changed, 8 insertions(+), 1 deletion(-)
test/image/spl_load.c static size_t start_fit(void *dst, size_t fit_size, size_t data_size, · line 168
Quoted 6 lines
test/image/spl_load.c +6
-0@@ -163,7 +163,14 @@ static size_t start_fit(void *dst, size_t fit_size, size_t data_size, +* The name goes in twice, as the description of both the image and the +* configuration, and for external data this budget is exact: it is the +* whole buffer start_fit() gets, and where the data then starts, which +* the loader expects 4-byte aligned. +*/ +size_t prop_size =ALIGN (596 +2 *strlen (spl_image->name),4 );
This works, but 596 already includes room for two copies of a 27-character name. With an empty name the FIT needs 548 bytes on 64-bit (540 on 32-bit), so the name is now counted twice and there are always at least 48 bytes spare. That is harmless, but 'exact' reads as though the figure is tight, when I think you mean that prop_size is also the data offset.
Also, each copy of the name takes ALIGN(strlen() + 1, 4) bytes in the FIT, so 2 * strlen() can be up to 8 bytes short; only the slack in 596 covers this. Please can you either reduce the base to what the fixed properties need and add 2 * ALIGN(strlen() + 1, 4), or reword the comment to say that 596 is the fixed part plus some margin? The first option is already a multiple of 4, so the outer ALIGN() could go.
Regards,
Simon
PATCH v2 8/11 test: spl: Cover FIT image decompression
In reply to Alexey CharkovNothing exercises the decompression in load_simple_fit(): create_fit() only ever writes compression = "none", and the canned LZMA blob is only used on the legacy uImage path.
Let create_fit() take a compression, and load a compressed FIT both ways:
with the data inside the FIT and beside it, since only the latter stages it through CONFIG_SYS_LOAD_ADDR. Point that address at the same offset sandbox_noinst uses, since otherwise the staging corrupts what's currently at 0x0.
--- configs/sandbox_spl_defconfig | 2 +- include/test/spl.h | 8 +++++++ test/image/spl_load.c | 52 ++++++++++++++++++++++++++++++------------- test/image/spl_load_nor.c | 2 ++ 4 files changed, 48 insertions(+), 16 deletions(-)
configs/sandbox_spl_defconfig +1 -1
@@ -6,7 +6,7 @@ CONFIG_ENV_SIZE=0x2000 CONFIG_SPL_SYS_MALLOC_F_LEN=0x8000 CONFIG_SPL_SERIAL=y CONFIG_SPL_DRIVERS_MISC=y -CONFIG_SYS_LOAD_ADDR=0x0 +CONFIG_SYS_LOAD_ADDR=0x1000000 CONFIG_SPL=y CONFIG_PCI=y CONFIG_SANDBOX_SPL=y
include/test/spl.h +8 -0
@@ -30,14 +30,18 @@ void generate_data(char *data, size_t size, const char *test_name);* @LEGACY_LZMA: "Legacy" uImages, LZMA compressed * @IMX8: i.MX8 Container images * @FIT_INTERNAL: FITs with internal data +* @FIT_INTERNAL_LZMA: FITs with internal data, LZMA compressed * @FIT_EXTERNAL: FITs with external data +* @FIT_EXTERNAL_LZMA: FITs with external data, LZMA compressed */ enum spl_test_image {LEGACY ,LEGACY_LZMA ,IMX8 ,FIT_INTERNAL , +FIT_INTERNAL_LZMA ,FIT_EXTERNAL , +FIT_EXTERNAL_LZMA , };/**
@@ -131,6 +135,10 @@ static inline bool image_supported(enum spl_test_image type)return IS_ENABLED (CONFIG_SPL_LEGACY_IMAGE_FORMAT );case IMX8 :return IS_ENABLED (CONFIG_SPL_LOAD_IMX_CONTAINER ); +case FIT_INTERNAL_LZMA : +case FIT_EXTERNAL_LZMA : +if (!IS_ENABLED (CONFIG_SPL_LZMA )) +return false;case FIT_INTERNAL :case FIT_EXTERNAL :return IS_ENABLED (CONFIG_SPL_LOAD_FIT );
test/image/spl_load.c +37 -15
134 lines not on this page · raw message
test/image/spl_load_nor.c +2 -0
@@ -35,6 +35,8 @@ SPL_IMG_TEST(spl_test_nor, LEGACY, 0);SPL_IMG_TEST (spl_test_nor,LEGACY_LZMA ,0 );SPL_IMG_TEST (spl_test_nor,IMX8 ,0 );SPL_IMG_TEST (spl_test_nor,FIT_INTERNAL ,0 ); +SPL_IMG_TEST (spl_test_nor,FIT_INTERNAL_LZMA ,0 );#if !IS_ENABLED (CONFIG_SPL_LOAD_FIT_FULL )SPL_IMG_TEST (spl_test_nor,FIT_EXTERNAL ,0 ); +SPL_IMG_TEST (spl_test_nor,FIT_EXTERNAL_LZMA ,0 );#endif
Signature · 1 line
2.55.0
Re: [PATCH v2 08/11] test: spl: Cover FIT image decompression
Hi Alexey,
Quoted 11 lines · Alexey Charkov
test: spl: Cover FIT image decompression
Nothing exercises the decompression in
load_simple_fit():create_fit()only ever writes compression = "none", and the canned LZMA blob is only used on the legacy uImage path.Let
create_fit()take a compression, and load a compressed FIT both ways:
with the data inside the FIT and beside it, since only the latter stages it throughCONFIG_SYS_LOAD_ADDR. Point that address at the same offsetsandbox_noinstuses, since otherwise the staging corrupts what's currently at0x0.
Please can you say what gets corrupted? I believe it is the bloblist, since CONFIG_BLOBLIST_ADDR is 0x100 and the LZMA blob is about 2.8K. With the address left at 0x0, running spl_test_nor_FIT_EXTERNAL_LZMA on its own passes, but then I see:
SPL: SPL hand-off write failed (err=-2)
Since this also changes loadaddr for U-Boot proper on sandbox_spl, please can you put the defconfig change in its own patch, before this one?
BTW sandbox_vpl still has CONFIG_SYS_LOAD_ADDR=0x0 and enables SPL_UNIT_TEST. It skips these tests only because it lacks SPL_LZMA, so it is probably worth changing that one too.
Quoted 11 lines
Signed-off-by Alexey Charkov <[email protected]>configs/sandbox_spl_defconfig | 2 +-
include/test/spl.h | 8 +++++++ test/image/spl_load.c | 52 ++++++++++++++++++++++++++++++------------- test/image/spl_load_nor.c | 2 ++ 4 files changed, 48 insertions(+), 16 deletions(-)
test/image/spl_load.c void *board_spl_fit_buffer_addr(ulong fit_size, int sectors, int bl_len) · line 46
Quoted 7 lines
test/image/spl_load.c +7
-0@@ -40,7 +40,25 @@ void *board_spl_fit_buffer_addr(ulong fit_size, int sectors, int bl_len) +static const char *image_compression (enum spl_test_image type) +{ +switch (type) { +case LEGACY_LZMA : +case FIT_INTERNAL_LZMA : +case FIT_EXTERNAL_LZMA : +return "lzma" ;
LZMA in a FIT already worked before patch 5, so as far as I can tell these tests would pass without it. See my comment on patch 9 about adding zstd cases.
This helper is only half general. It returns a name, but create_legacy() still turns SPL_COMPRESSED into IH_COMP_LZMA and do_spl_test_load() always copies in lzma_compressed with the 'lzma' seed. I suspect it would be cleaner to return an IH_COMP_... value, pass that to image_set_comp() for legacy and use genimg_get_comp_short_name() in create_fit(). Then IH_COMP_NONE gives you 'none' without the special case in create_image(). What do you think?
test/image/spl_load_nor.c SPL_IMG_TEST(spl_test_nor, LEGACY, 0); · line 38
Quoted 6 lines
test/image/spl_load_nor.c +2
-0@@ -35,6 +35,8 @@ SPL_IMG_TEST(spl_test_nor, LEGACY, 0); +SPL_IMG_TEST (spl_test_nor,FIT_INTERNAL_LZMA ,0 );#if !IS_ENABLED (CONFIG_SPL_LOAD_FIT_FULL )SPL_IMG_TEST (spl_test_nor,FIT_EXTERNAL ,0 ); +SPL_IMG_TEST (spl_test_nor,FIT_EXTERNAL_LZMA ,0 );
Why only NOR? It reads with a bl_len of 1, so the external case never has a non-zero get_aligned_image_overhead() when staging through CONFIG_SYS_LOAD_ADDR. The SPI, NAND and net tests already go through do_spl_test_load() so they should just need the extra lines.
The MMC test would cover the block-aligned read, but spl_load_fs.c has its own copy of the type == LEGACY_LZMA checks. Please can you export image_compression() in test/spl.h and use it there too?
Regards,
Simon
PATCH v2 9/11 sandbox: spl: Enable zstd
In reply to Alexey CharkovNothing in the tree had SPL_ZSTD set, so nothing noticed that it could not link. Turn it on where the SPL FIT loader is exercised, so a build says so next time.
--- configs/sandbox_spl_defconfig | 1 + 1 file changed, 1 insertion(+)
configs/sandbox_spl_defconfig +1 -0
@@ -230,6 +230,7 @@ CONFIG_RSA_VERIFY_WITH_PKEY=y CONFIG_TPM=y CONFIG_ZSTD=y CONFIG_SPL_LZMA=y +CONFIG_SPL_ZSTD=y CONFIG_ERRNO_STR=y CONFIG_SPL_HEXDUMP=y CONFIG_SPL_LMB=y
Signature · 1 line
2.55.0
Re: [PATCH v2 09/11] sandbox: spl: Enable zstd
Hi Alexey,
Quoted 13 lines · Alexey Charkov
sandbox: spl: Enable zstd
Nothing in the tree had
SPL_ZSTDset, so nothing noticed that it could not link. Turn it on where the SPL FIT loader is exercised, so a build says so next time.Signed-off-by Alexey Charkov <[email protected]>configs/sandbox_spl_defconfig | 1 +
1 file changed, 1 insertion(+)
configs/sandbox_spl_defconfig CONFIG_RSA_VERIFY_WITH_PKEY=y · line 232
Quoted 3 lines
configs/sandbox_spl_defconfig +1
-0@@ -230,6 +230,7 @@ CONFIG_RSA_VERIFY_WITH_PKEY=y CONFIG_ZSTD=y CONFIG_SPL_LZMA=y +CONFIG_SPL_ZSTD=y
I built sandbox_spl with this and it does what the commit message
says: zstd and xxhash end up in the SPL image via image_decomp() and the SPL tests still pass.
But this is only a link test. Nothing actually runs zstd_decompress() in SPL, so the 94KB workspace allocation and the SPL_ZSTD_LIB_MINIFY build are not exercised, and zstd is the main point of this series. The previous patch already has create_fit() taking a compression name, with image_compression() choosing it, so please can you add FIT_INTERNAL_ZSTD and FIT_EXTERNAL_ZSTD cases with a canned blob, as is done for lzma_compressed? That would also check the xxhash linkage at runtime. You would need image_supported() to check CONFIG_SPL_ZSTD for those, and do_spl_test_load() to pick the blob by type rather than assuming LZMA.
That could go in this patch, or a following one.
Regards,
Simon
Re: [PATCH v2 09/11] sandbox: spl: Enable zstd
Hi Simon,
Quoted 1 line · Simon Glass
FIT_INTERNAL_ZSTDandFIT_EXTERNAL_ZSTDcases with a canned blob
I sent that pair on 21 September on top of this v2, plus a gzip pair:
https://patch.msgid.link/[email protected]
The blob is picked by name in do_spl_test_load() and the zstd cases check CONFIG_SPL_ZSTD on their own. NOR only so far. I can add the SPI, NAND and net lines in a resend, or Alexey can fold it all into v3.
Cole
Re: [PATCH v2 09/11] sandbox: spl: Enable zstd
Quoted 11 lines · Cole Munz
Hi Simon,
Quoted 1 line · Simon Glass
FIT_INTERNAL_ZSTDandFIT_EXTERNAL_ZSTDcases with a canned blobI sent that pair on 21 September on top of this v2, plus a gzip pair:
https://patch.msgid.link/[email protected]The blob is picked by name in
do_spl_test_load()and the zstd cases checkCONFIG_SPL_ZSTDon their own. NOR only so far. I can add the SPI, NAND and net lines in a resend, or Alexey can fold it all into v3.
I'm not sure if there's value in repeating these tests on other load-froms.
Signature · 1 line
Tom
Re: [PATCH v2 09/11] sandbox: spl: Enable zstd
Hi Tom,
Quoted 2 lines · Tom Rini
I'm not sure if there's value in repeating these tests on other load-froms.
Fine by me. I will keep them NOR only and resend on top of v3.
Cole
PATCH v2 10/11 binman: Allow choosing the compression level
In reply to Alexey CharkovEvery compression algorithm binman drives has a level, and the best one to use depends on what the image is for: a payload sent over USB wants the smallest it can get, one read from fast storage would rather not wait for it. Today only the tool's own default is reachable.
Add a 'compress-level' property, passed through as -<level>, which is how all compressors want it except lzma: the LZMA SDK tool has no such option, and is controlled by the -lc/-lp/-pb values binman already passes.
--- tools/binman/binman.rst | 21 +++++++++++++ tools/binman/bintool.py | 10 +++++-- tools/binman/btool/lz4.py | 6 ++-- tools/binman/btool/lzma_alone.py | 6 +++- tools/binman/entry.py | 6 +++- tools/binman/ftest.py | 34 ++++++++++++++++++++++ tools/binman/test/entry/compress_level.dts | 12 ++++++++ tools/binman/test/entry/compress_level_gzip.dts | 12 ++++++++ tools/binman/test/entry/compress_level_lzma.dts | 12 ++++++++ .../test/entry/compress_level_no_compress.dts | 11 +++++++ 10 files changed, 124 insertions(+), 6 deletions(-)
tools/binman/binman.rst +21 -0
@@ -711,6 +711,11 @@ compress: Sets the compression algorithm to use (for blobs only). See the entry documentation for details. +compress-level: + Sets how hard the compression algorithm should try, as the level number + the tool itself uses. Requires 'compress'. See the entry documentation + for details. + missing-msg: Sets the tag of the message to show if this entry is missing. This is used for external blobs. When they are missing it is helpful to show
@@ -1182,6 +1187,22 @@ The entry will then contain the compressed data, using the 'lz4' compression algorithm. Currently this is the only one that is supported. The uncompressed size is written to the node in an 'uncomp-size' property, if -u is used. +Where an algorithm offers a choice of how hard to try, 'compress-level' passes +one through:: + + blob { + filename = "datafile"; + compress = "zstd"; + compress-level = <19>; + }; + +The number is the tool's own level, so its meaning and range follow that tool: +1 to 9 for gzip, bzip2, lzop and xz, 1 to 12 for lz4, 1 to 19 for zstd. Asking +for more than an algorithm offers usually gets a warning and its maximum +instead. Leaving the property out uses the tool's default, which is what binman +has always done. It cannot be used with 'lzma', whose LZMA SDK tool has no such +option. + Compression is also supported for sections. In that case the entire section is compressed in one block, including all its contents. This means that accessing an entry from the section requires decompressing the entire section. Also, the
tools/binman/bintool.py +8 -2
@@ -558,11 +558,14 @@ class BintoolPacker(Bintool): fetch_package = name self.fetch_package = fetch_package - def compress(self, indata): + def compress(self, indata, level=None): """Compress data Args: indata (bytes): Data to compress + level (int): Compression level to use, or None for the tool's own + default. Every packer tool spells this as -<level>; one asked + for a level it does not have generally warns and clamps it. Returns: bytes: Compressed data
@@ -570,7 +573,10 @@ class BintoolPacker(Bintool): with tempfile.NamedTemporaryFile(prefix='comp.tmp', dir=tools.get_output_dir()) as tmp: tools.write_file(tmp.name, indata) - args = self.compress_args + ['--stdout', tmp.name] + args = self.compress_args[:] + if level is not None: + args.append(f'-{level}') + args += ['--stdout', tmp.name] return self.run_cmd(*args, binary=True) def decompress(self, indata):
tools/binman/btool/lz4.py +4 -2
@@ -78,11 +78,13 @@ class Bintoollz4(bintool.Bintool): def __init__(self, name): super().__init__(name, 'lz4 compression', r'.* (v[0-9.]*),.*') - def compress(self, indata): + def compress(self, indata, level=None): """Compress data with lz4 Args: indata (bytes): Data to compress + level (int): Compression level (1 to 12), or None for the level + binman has always used here Returns: bytes: Compressed data
@@ -90,7 +92,7 @@ class Bintoollz4(bintool.Bintool): with tempfile.NamedTemporaryFile(prefix='comp.tmp', dir=tools.get_output_dir()) as tmp: tools.write_file(tmp.name, indata) - args = ['--no-frame-crc', '-B4', '-5', '-c', tmp.name] + args = ['--no-frame-crc', '-B4', f'-{level or 5}', '-c', tmp.name] return self.run_cmd(*args, binary=True) def decompress(self, indata):
tools/binman/btool/lzma_alone.py +5 -1
@@ -55,15 +55,19 @@ class Bintoollzma_alone(bintool.Bintool): def __init__(self, name): super().__init__(name, 'lzma_alone compression') - def compress(self, indata): + def compress(self, indata, level=None): """Compress data with lzma_alone Args: indata (bytes): Data to compress + level (int): Must be None: the LZMA SDK tool has no -<level> + option, it is steered by the -lc/-lp/-pb/-d values below Returns: bytes: Compressed data """ + if level is not None: + raise ValueError("lzma_alone does not support 'compress-level'") with tempfile.NamedTemporaryFile(prefix='comp.tmp', dir=tools.get_output_dir()) as inf: tools.write_file(inf.name, indata)
tools/binman/entry.py +5 -1
@@ -143,6 +143,7 @@ class Entry(object): self.image_pos = None self.extend_size = False self.compress = 'none' + self.compress_level = None self.missing = False self.faked = False self.external = False
@@ -325,6 +326,9 @@ class Entry(object): # This is only supported by blobs and sections at present self.compress = fdt_util.GetString(self._node, 'compress', 'none') + self.compress_level = fdt_util.GetInt(self._node, 'compress-level') + if self.compress_level is not None and self.compress == 'none': + self.Raise("'compress-level' requires 'compress'") self.offset_from_elf = fdt_util.GetPhandleNameOffset(self._node, 'offset-from-elf')
@@ -1222,7 +1226,7 @@ features to produce new behaviours. if self.compress != 'none': self.uncomp_size = len(indata) if self.comp_bintool.is_present(): - data = self.comp_bintool.compress(indata) + data = self.comp_bintool.compress(indata, self.compress_level) uniq = self.GetUniqueName() fname = tools.get_output_filename(f'comp.{uniq}') tools.write_file(fname, data)
tools/binman/ftest.py +34 -0
@@ -2168,6 +2168,40 @@ class TestFunctional(unittest.TestCase): bintool = self.comp_bintools['lz4'] return bintool.decompress(data) + def testCompressLevel(self): + """Test that a compression level reaches the tool and round-trips""" + self._CheckLz4() + data = self._DoReadFile('entry/compress_level.dts', use_real_dtb=True) + self.assertEqual(COMPRESS_DATA, self._decompress(data)) + + entry = control.images['image'].GetEntries()['blob'] + self.assertEqual(12, entry.compress_level) + + def testCompressLevelPacker(self): + """Test a compression level reaching a tool binman drives generically""" + bintool = self.comp_bintools['gzip'] + self._CheckBintool(bintool) + data = self._DoReadFile('entry/compress_level_gzip.dts', + use_real_dtb=True) + self.assertEqual(COMPRESS_DATA, bintool.decompress(data)) + + def testCompressLevelUnsupported(self): + """Test that lzma rejects a level its tool cannot express""" + bintool = self.comp_bintools['lzma_alone'] + self._CheckBintool(bintool) + with self.assertRaises(ValueError) as e: + self._DoReadFile('entry/compress_level_lzma.dts', + use_real_dtb=True) + self.assertIn("lzma_alone does not support 'compress-level'", + str(e.exception)) + + def testCompressLevelNoCompress(self): + """Test that a compression level without an algorithm is rejected""" + with self.assertRaises(ValueError) as e: + self._DoReadFile('entry/compress_level_no_compress.dts', + use_real_dtb=True) + self.assertIn("'compress-level' requires 'compress'", str(e.exception)) + def testCompress(self): """Test compression of blobs""" self._CheckLz4()
tools/binman/test/entry/compress_level.dts new file +12 -0
@@ -0,0 +1,12 @@ +// SPDX-License-Identifier: GPL-2.0+ +/dts-v1/; + +/ { + binman { + blob { + filename = "compress"; + compress = "lz4"; + compress-level = <12>; + }; + }; +};
tools/binman/test/entry/compress_level_gzip.dts new file +12 -0
@@ -0,0 +1,12 @@ +// SPDX-License-Identifier: GPL-2.0+ +/dts-v1/; + +/ { + binman { + blob { + filename = "compress"; + compress = "gzip"; + compress-level = <9>; + }; + }; +};
tools/binman/test/entry/compress_level_lzma.dts new file +12 -0
@@ -0,0 +1,12 @@ +// SPDX-License-Identifier: GPL-2.0+ +/dts-v1/; + +/ { + binman { + blob { + filename = "compress"; + compress = "lzma"; + compress-level = <5>; + }; + }; +};
tools/binman/test/entry/compress_level_no_compress.dts new file +11 -0
@@ -0,0 +1,11 @@ +// SPDX-License-Identifier: GPL-2.0+ +/dts-v1/; + +/ { + binman { + blob { + filename = "compress"; + compress-level = <9>; + }; + }; +};
Signature · 1 line
2.55.0
Re: [PATCH v2 10/11] binman: Allow choosing the compression level
Hi Alexey,
Quoted 27 lines · Alexey Charkov
binman: Allow choosing the compression level
Every compression algorithm binman drives has a level, and the best one to use depends on what the image is for: a payload sent over USB wants the smallest it can get, one read from fast storage would rather not wait for it. Today only the tool's own default is reachable.
Add a 'compress-level' property, passed through as -<level>, which is how all compressors want it except lzma: the LZMA SDK tool has no such option, and is controlled by the -lc/-lp/-pb values binman already passes.
Signed-off-by Alexey Charkov <[email protected]>
tools/binman/binman.rst| 21 +++++++++++++tools/binman/bintool.py | 10 +++++-- tools/binman/btool/lz4.py | 6 ++-- tools/binman/btool/lzma_alone.py | 6 +++- tools/binman/entry.py | 6 +++- tools/binman/ftest.py | 34 ++++++++++++++++++++++ tools/binman/test/entry/compress_level.dts | 12 ++++++++ tools/binman/test/entry/compress_level_gzip.dts | 12 ++++++++ tools/binman/test/entry/compress_level_lzma.dts | 12 ++++++++ .../test/entry/compress_level_no_compress.dts | 11 +++++++ 10 files changed, 124 insertions(+), 6 deletions(-)
tools/binman/binman.rst compress: · line 714
Quoted 4 lines
tools/binman/binman.rst +4
-0@@ -711,6 +711,11 @@ compress: +compress-level: + Sets how hard the compression algorithm should try, as the level number + the tool itself uses. Requires 'compress'. See the entry documentation + for details.
The entry documentation is generated from the docstring in etype/blob.py and that still only lists 'filename' and 'compress'. Please can you add 'compress-level' there too?
tools/binman/binman.rst The entry will then contain the compressed data, using the 'lz4' compression · line 1192
Quoted 8 lines
tools/binman/binman.rst +6
-0@@ -1182,6 +1187,22 @@ The entry will then contain the compressed data, using the 'lz4' compression +The number is the tool's own level, so its meaning and range follow that tool: +1 to 9 for gzip, bzip2, lzop and xz, 1 to 12 for lz4, 1 to 19 for zstd. Asking +for more than an algorithm offers usually gets a warning and its maximum +instead. Leaving the property out uses the tool's default, which is what binman +has always done. It cannot be used with 'lzma', whose LZMA SDK tool has no such +option.
Not quite. I tried this and only zstd warns and clamps. lz4 clamps silently. gzip, bzip2, xz and lzop read -12 as -1 followed by -2, so you silently get level 2, i.e. asking for more gives you much less. See below for a suggestion.
Also, with lz4 binman passes -5, which is not the tool's default (that is -1).
tools/binman/bintool.py class BintoolPacker(Bintool): · line 576
Quoted 6 lines
tools/binman/bintool.py +4
-0@@ -570,7 +573,10 @@ class BintoolPacker(Bintool): + args = self.compress_args[:] + if level is not None: + args.append(f'-{level}') + args += ['--stdout', tmp.name]
Given the above, I don't think binman can pass the number through unchecked. A typo in the level, or changing 'compress' from zstd to gzip while leaving the level at 19, produces a valid image that is larger than the default, with nothing to say why.
How about having each compression bintool declare the range it supports (e.g. a max_level passed to the BintoolPacker constructor, with None meaning that levels are not supported), then have Entry check the value against it and call self.Raise() if it is out of range? What do you think?
tools/binman/btool/lz4.py class Bintoollz4(bintool.Bintool): · line 92
Quoted 4 lines
tools/binman/btool/lz4.py +1
-1@@ -90,7 +92,7 @@ class Bintoollz4(bintool.Bintool): - args = ['--no-frame-crc', '-B4', '-5', '-c', tmp.name] + args = ['--no-frame-crc', '-B4', f'-{level or 5}', '-c', tmp.name]
This treats a level of 0 as 'not set', whereas BintoolPacker checks for None and passes -0 to the tool. gzip, bzip2 and lzop reject that as an invalid option, while xz and zstd accept it. Please can you make these consistent? Rejecting 0 in the range check would be fine, I think.
tools/binman/btool/lzma_alone.py class Bintoollzma_alone(bintool.Bintool): · line 56
Quoted 4 lines
tools/binman/btool/lzma_alone.py +2
-0@@ -55,15 +55,19 @@ class Bintoollzma_alone(bintool.Bintool): + if level is not None: + raise ValueError("lzma_alone does not support 'compress-level'")
This error does not include the node path, so with several compressed entries it is hard to tell which one is wrong. It also only fires if the tool is present, since otherwise CompressData() records a missing bintool and never gets here.
If the range lives in the bintool as suggested above, Entry can check this with self.Raise() (e.g. in AddBintools() where comp_bintool is set up), in the same way as the 'requires compress' check, and this special case goes away.
tools/binman/ftest.py class TestFunctional(unittest.TestCase): · line 2175
Quoted 10 lines
tools/binman/ftest.py +8
-0@@ -2168,6 +2168,40 @@ class TestFunctional(unittest.TestCase): + def testCompressLevel(self): + """Test that a compression level reaches the tool and round-trips""" + self._CheckLz4() + data = self._DoReadFile('entry/compress_level.dts', use_real_dtb=True) + self.assertEqual(COMPRESS_DATA, self._decompress(data)) + + entry = control.images['image'].GetEntries()['blob'] + self.assertEqual(12, entry.compress_level)
This checks that the property is parsed and that the data round-trips, but not that the level reaches the tool. The test would still pass if compress() dropped the level, and the same applies to testCompressLevelPacker().
Please can you check the arguments, e.g. by using unittest.mock.patch.object() on bintool.Bintool.run_cmd as the cst test does, recording the args and then calling the original?
Since you are adding range checks, you may need a test for an out-of-range level too.
Regards,
Simon
PATCH v2 11/11 rockchip: Choose FIT payload compression via Kconfig
In reply to Alexey CharkovThe 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.
--- arch/arm/dts/rockchip-u-boot.dtsi | 16 +++----- arch/arm/mach-rockchip/Kconfig | 78 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 10 deletions(-)
arch/arm/dts/rockchip-u-boot.dtsi +6 -10
@@ -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 {
arch/arm/mach-rockchip/Kconfig +78 -0
84 lines not on this page · raw message
Signature · 1 line
2.55.0
Re: [PATCH v2 11/11] rockchip: Choose FIT payload compression via Kconfig
Hi Alexey,
Quoted 5 lines · Alexey Charkov
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.
Thanks, this was something of an eye-sore to me for a while already :)
Quoted 34 lines
Move the selection to
Kconfiginstead, 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(-)arch/arm/dts/rockchip-u-boot.dtsi +0
-9@@ -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;
arch/arm/dts/rockchip-u-boot.dtsi line 64
Quoted 10 lines
arch/arm/dts/rockchip-u-boot.dtsi +6
-1+ 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
OK so the obvious question here is "why Rockchip-specific?". I appreciate you're mostly working with the RK3576 but I don't see why this (the kconfig symbol definition that happens later in this patch in arch/arm/mach-rockchip/Kconfig) needs to be Rockchip-specific, we have other architectures that are also building a FIT image with U-Boot proper in it, so I think it'd be nice to have this setting apply to all of them so that it's a more generic approach. I'm wondering whether a direct argument to binman would be more appropriate here instead of requiring all binman nodes to not forget to add these compression properties for the setting to actually apply. Of course this would still need some logic handling a binman argument and the compression properties both being set, and likely remove the properties from existing DTS.
arch/arm/mach-rockchip/Kconfig config ROCKCHIP_MASKROM_IMAGE · line 762
Quoted 13 lines
arch/arm/dts/rockchip-u-boot.dtsi +0
-0}; #ifdef FIT_HASH_ALGO hash {arch/arm/mach-rockchip/Kconfig +2
-0@@ -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"
It's not the SPL FIT.
arch/arm/mach-rockchip/Kconfig config ROCKCHIP_MASKROM_IMAGE · line 763
Quoted 1 line
arch/arm/mach-rockchip/Kconfig +1
-0+ depends on SPL_FIT
This only applies when we build a FIT image with binman for Rockchip, which happens only if HAS_FIT is defined, which is:
defined(CONFIG_SPL_FIT) && (defined(CONFIG_ARM64) || defined(CONFIG_SPL_OPTEE_IMAGE))
so you are missing:
depends on ARM64 || SPL_OPTEE_IMAGE
here.
arch/arm/mach-rockchip/Kconfig config ROCKCHIP_MASKROM_IMAGE · line 764
Quoted 1 line
arch/arm/mach-rockchip/Kconfig +1
-0+ default ROCKCHIP_UBOOT_COMP_NONE
This diverges from the current state, instead do:
default ROCKCHIP_UBOOT_COMP_GZIP if SPL_GZIP
default ROCKCHIP_UBOOT_COMP_LZMA if SPL_LZMA
default ROCKCHIP_UBOOT_COMP_NONE
to keep the same behavior (not tested but I believe this should work).
arch/arm/mach-rockchip/Kconfig config ROCKCHIP_MASKROM_IMAGE · line 766
Quoted 2 lines
arch/arm/mach-rockchip/Kconfig +2
-0+ help + Pick how U-Boot proper is stored in the FIT which SPL loads it from.
Don't like "how [it] is stored in the fit", I would prefer to make it explicit we're talking about compression here.
Maybe:
Compression algorithm for U-Boot proper as stored in the FIT loaded by SPL. ?
arch/arm/mach-rockchip/Kconfig config ROCKCHIP_MASKROM_IMAGE · line 768
Quoted 2 lines
arch/arm/mach-rockchip/Kconfig +2
-0+ + It is around a megabyte, so what SPL spends unpacking it is close to
Size depends on what you enable so I don't think it's relevant to put this in a help text.
arch/arm/mach-rockchip/Kconfig config ROCKCHIP_MASKROM_IMAGE · line 772
Quoted 4 lines
arch/arm/mach-rockchip/Kconfig +4
-0+ 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. +
I think what matters is the following:
- on space-constrained systems, enabling compression may help making sure the bootloader fits in the storage medium,
- compression could help with boot time if the storage medium is slow enough that reading a compressed image from it and uncompressing it is faster than reading the uncompressed image directly. Whether it's beneficial needs to be experimentally checked on each device as it depends on the SoC and selected storage medium.
arch/arm/mach-rockchip/Kconfig config ROCKCHIP_MASKROM_IMAGE · line 778
Quoted 6 lines
arch/arm/mach-rockchip/Kconfig +6
-0+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. +
Please add a proper help text that is understandable on its own. It is not uncommon (I do it more often than not) that people will look up a symbol with the search function in menuconfig and will only get this information, it's therefore important to know what we're talking about here without having to look up the choice help text. Ditto for other help texts below.
arch/arm/mach-rockchip/Kconfig config ROCKCHIP_MASKROM_IMAGE · line 790
Quoted 12 lines
arch/arm/mach-rockchip/Kconfig +12
-0+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
I'm not sure we need to specify the implementation detail of the tool used to generate the compressed binary? lzma_alone is also only available on Debian-based systems (e.g. Fedora doesn't have it), so I'm not entirely sure whether it'll stay this way forever (maybe we should switch to another implementation that is available on more/most distros?). I understand you probably did this because it's somewhat an important piece of information to then decide which level to use.
Quoted 13 lines
arch/arm/mach-rockchip/Kconfig +13
-0+ 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
arch/arm/mach-rockchip/Kconfig config ROCKCHIP_MASKROM_IMAGE · line 813
Quoted 10 lines
arch/arm/mach-rockchip/Kconfig +10
-0+ 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.
I don't like specifying numbers that aren't guaranteed to stay at that value. I understand the appeal to provide some number to give a rough idea of the size impact, so I don't think it needs to be a blocker, maybe Tom would have some opinion there, otherwise ignore this :)
arch/arm/mach-rockchip/Kconfig config ROCKCHIP_MASKROM_IMAGE · line 825
Quoted 12 lines
arch/arm/mach-rockchip/Kconfig +12
-0+ +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" +
I'm tempted to say this is not the place for this and rather should be in rockchip-u-boot.dtsi for example as a series of #ifdef (but if we go for a generic implementation that applies to other architectures, then maybe it's fine like this).
arch/arm/mach-rockchip/Kconfig config ROCKCHIP_MASKROM_IMAGE · line 837
Quoted 12 lines
arch/arm/mach-rockchip/Kconfig +12
-0+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.
The option won't be shown anyway and it's clear from the dependencies that it's not supported so I don't think it makes sense to have it in the help text, however the commit log would be a very good place to have this piece of information.
Cheers,
Quentin
Re: [PATCH v2 11/11] rockchip: Choose FIT payload compression via Kconfig
Hi Quentin,
Quoted 57 lines · Quentin Schulz
Hi Alexey,
Quoted 5 lines · Alexey Charkov
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.
Thanks, this was something of an eye-sore to me for a while already :)
Quoted 34 lines
Move the selection to
Kconfiginstead, 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(-)arch/arm/dts/rockchip-u-boot.dtsi +0
-9@@ -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;arch/arm/dts/rockchip-u-boot.dtsi line 64
Quoted 10 lines
arch/arm/dts/rockchip-u-boot.dtsi +6
-1+ 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
Quoted 7 lines
OK so the obvious question here is "why Rockchip-specific?". I appreciate you're mostly working with the RK3576 but I don't see why this (the kconfig symbol definition that happens later in this patch in
arch/arm/mach-rockchip/Kconfig) needs to be Rockchip-specific, we have other architectures that are also building a FIT image with U-Boot proper in it, so I think it'd be nice to have this setting apply to all of them so that it's a more generic approach.
The Kconfig selection itself is surely arch-agnostic, but I have no idea if the handling of the resulting images will work out fine on other architectures or what their constraints are, beyond what the build system can tell me. Rockchip is the only one I can test, so I'd rather start here :)
Quoted 7 lines
I'm wondering whether a
direct argument to binman would be more appropriate here instead of requiring all binman nodes to not forget to add these compression properties for the setting to actually apply. Of course this would still need some logic handling a binman argument and the compression properties both being set, and likely remove the properties from existing DTS.
Not sure that's a universally good idea: the FIT needs the compression attribute anyway, and it comes via the DTS. Passing the compression argument to binman via the same DTS reduces the chance of the two going out of sync. The alternative is passing the compression to binman via a separate back-channel and having it insert the FIT attributes based on that. To me, that sounds strictly worse than the current arrangement because it turns explicit settings visible in a textual config into automagic.
Quoted 11 lines
Quoted 11 lines
arch/arm/dts/rockchip-u-boot.dtsi +0
-0}; #ifdef FIT_HASH_ALGO hash {arch/arm/mach-rockchip/Kconfig +0
-0@@ -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.
Quoted 4 lines
arch/arm/mach-rockchip/Kconfig config ROCKCHIP_MASKROM_IMAGE · line 762
Quoted 2 lines
arch/arm/mach-rockchip/Kconfig +2
-0+choice + prompt "Compression for U-Boot proper in the SPL FIT"It's not the SPL FIT.
Right, thanks. The SPL_FIT symbol made my mind wander :-D
Quoted 11 lines
arch/arm/mach-rockchip/Kconfig config ROCKCHIP_MASKROM_IMAGE · line 763
Quoted 1 line
arch/arm/mach-rockchip/Kconfig +1
-0+ depends on SPL_FITThis only applies when we build a FIT image with binman for Rockchip, which happens only if
HAS_FITis defined, which is:
defined(CONFIG_SPL_FIT)&& (defined(CONFIG_ARM64)||defined(CONFIG_SPL_OPTEE_IMAGE))so you are missing:
depends on ARM64 ||SPL_OPTEE_IMAGE
here.
Ack
Quoted 9 lines
arch/arm/mach-rockchip/Kconfig config ROCKCHIP_MASKROM_IMAGE · line 764
Quoted 1 line
arch/arm/mach-rockchip/Kconfig +1
-0+ default ROCKCHIP_UBOOT_COMP_NONEThis diverges from the current state, instead do:
default
ROCKCHIP_UBOOT_COMP_GZIPifSPL_GZIP
defaultROCKCHIP_UBOOT_COMP_LZMAifSPL_LZMA
defaultROCKCHIP_UBOOT_COMP_NONEto keep the same behavior (not tested but I believe this should work).
That was my first attempt, but it introduced a circular dependency. I've checked the current defconfigs, and none of them enable compression. Worse, LZMA had been broken and couldn't link for some time until I fixed it separately (it's merged now), so I'm reasonably sure there have been no active users of these settings lately.
Quoted 9 lines
arch/arm/mach-rockchip/Kconfig config ROCKCHIP_MASKROM_IMAGE · line 766
Quoted 2 lines
arch/arm/mach-rockchip/Kconfig +2
-0+ help + Pick how U-Boot proper is stored in the FIT which SPL loads it from.Don't like "how [it] is stored in the fit", I would prefer to make it explicit we're talking about compression here.
Maybe:
Compression algorithm for U-Boot proper as stored in the FIT loaded by SPL. ?
Ack
Quoted 5 lines
arch/arm/mach-rockchip/Kconfig config ROCKCHIP_MASKROM_IMAGE · line 768
Quoted 2 lines
arch/arm/mach-rockchip/Kconfig +2
-0+ + It is around a megabyte, so what SPL spends unpacking it is close toSize depends on what you enable so I don't think it's relevant to put this in a help text.
Ack
Quoted 5 lines
arch/arm/mach-rockchip/Kconfig config ROCKCHIP_MASKROM_IMAGE · line 772
Quoted 4 lines
arch/arm/mach-rockchip/Kconfig +4
-0+ 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. +
Quoted 8 lines
I think what matters is the following:
- on space-constrained systems, enabling compression may help making sure the bootloader fits in the storage medium,
- compression could help with boot time if the storage medium is slow enough that reading a compressed image from it and uncompressing it is faster than reading the uncompressed image directly. Whether it's beneficial needs to be experimentally checked on each device as it depends on the SoC and selected storage medium.
Ack
Quoted 5 lines
Quoted 5 lines
arch/arm/mach-rockchip/Kconfig +5
-0+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.
Quoted 8 lines
arch/arm/mach-rockchip/Kconfig config ROCKCHIP_MASKROM_IMAGE · line 778
Quoted 1 line
arch/arm/mach-rockchip/Kconfig +1
-0+Please add a proper help text that is understandable on its own. It is not uncommon (I do it more often than not) that people will look up a symbol with the search function in menuconfig and will only get this information, it's therefore important to know what we're talking about here without having to look up the choice help text. Ditto for other help texts below.
Ack
Quoted 13 lines
arch/arm/mach-rockchip/Kconfig config ROCKCHIP_MASKROM_IMAGE · line 790
Quoted 12 lines
arch/arm/mach-rockchip/Kconfig +12
-0+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
Quoted 7 lines
I'm not sure we need to specify the implementation detail of the tool used to generate the compressed binary?
lzma_aloneis also only available on Debian-based systems (e.g. Fedora doesn't have it), so I'm not entirely sure whether it'll stay this way forever (maybe we should switch to another implementation that is available on more/most distros?). I understand you probably did this because it's somewhat an important piece of information to then decide which level to use.
The peculiar host binary which nobody ships these days is precisely why I decided to mention it by the name. On my main Gentoo system the legacy lzma container is only provided by the not-so-easy-to-figure-out lzmacon package, which then requires symlinking under a different name for the U-Boot build system to pick it up. With this help text, a user at least knows what weird binary to google for, or what substitutes might be available on their distro.
Quoted 20 lines
Quoted 20 lines
arch/arm/mach-rockchip/Kconfig +20
-0+ 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
Quoted 8 lines
arch/arm/mach-rockchip/Kconfig config ROCKCHIP_MASKROM_IMAGE · line 813
Quoted 3 lines
arch/arm/mach-rockchip/Kconfig +3
-0+ 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.I don't like specifying numbers that aren't guaranteed to stay at that value. I understand the appeal to provide some number to give a rough idea of the size impact, so I don't think it needs to be a blocker, maybe Tom would have some opinion there, otherwise ignore this :)
Tom acked a similar help text on the SPL_ZSTD option itself, but maybe duplicating it all over the place is an overkill. Happy to distill it in the next version.
Quoted 9 lines
Quoted 9 lines
arch/arm/mach-rockchip/Kconfig +9
-0+ +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
Quoted 8 lines
arch/arm/mach-rockchip/Kconfig config ROCKCHIP_MASKROM_IMAGE · line 825
Quoted 3 lines
arch/arm/mach-rockchip/Kconfig +3
-0+ default "zstd" if ROCKCHIP_UBOOT_COMP_ZSTD + default "none" +I'm tempted to say this is not the place for this and rather should be in
rockchip-u-boot.dtsifor example as a series of #ifdef (but if we go for a generic implementation that applies to other architectures, then maybe it's fine like this).
Noooo - do you really like #ifdefs? :) Having this here means one file to update when another algorithm gets added, as opposed to multiple, which I believe is a worthy quality in itself.
Quoted 9 lines
Quoted 9 lines
arch/arm/mach-rockchip/Kconfig +9
-0+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
Quoted 8 lines
arch/arm/mach-rockchip/Kconfig config ROCKCHIP_MASKROM_IMAGE · line 837
Quoted 3 lines
arch/arm/mach-rockchip/Kconfig +3
-0+ numbers it. Leave it at 0 to take the tool's default. + + lzma has no such knob, so it is not offered there.The option won't be shown anyway and it's clear from the dependencies that it's not supported so I don't think it makes sense to have it in the help text, however the commit log would be a very good place to have this piece of information.
Ack
Best regards,
Alexey
Re: [PATCH v2 11/11] rockchip: Choose FIT payload compression via Kconfig
Quoted 68 lines · Alexey Charkov
Hi Quentin,
Quoted 57 lines · Quentin Schulz
Hi Alexey,
Quoted 5 lines · Alexey Charkov
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.
Thanks, this was something of an eye-sore to me for a while already :)
Quoted 34 lines
Move the selection to
Kconfiginstead, 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(-)arch/arm/dts/rockchip-u-boot.dtsi +0
-9@@ -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;arch/arm/dts/rockchip-u-boot.dtsi line 64
Quoted 10 lines
arch/arm/dts/rockchip-u-boot.dtsi +6
-1+ 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>; +#endifQuoted 7 lines
OK so the obvious question here is "why Rockchip-specific?". I appreciate you're mostly working with the RK3576 but I don't see why this (the kconfig symbol definition that happens later in this patch in
arch/arm/mach-rockchip/Kconfig) needs to be Rockchip-specific, we have other architectures that are also building a FIT image with U-Boot proper in it, so I think it'd be nice to have this setting apply to all of them so that it's a more generic approach.
Quoted 5 lines
The
Kconfigselection itself is surely arch-agnostic, but I have no idea if the handling of the resulting images will work out fine on other architectures or what their constraints are, beyond what the build system can tell me. Rockchip is the only one I can test, so I'd rather start here :)
You don't need to implement it on other platforms, but yes, we should start this out generic-facing. That'll encourage someone else to look at what needs doing for another platform.
[snip]
Quoted 29 lines
Quoted 20 lines
Quoted 20 lines
arch/arm/dts/rockchip-u-boot.dtsi +20
-0+ 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 + helpQuoted 8 lines
arch/arm/dts/rockchip-u-boot.dtsi
Quoted 3 lines
arch/arm/dts/rockchip-u-boot.dtsi +3
-0+ 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.I don't like specifying numbers that aren't guaranteed to stay at that value. I understand the appeal to provide some number to give a rough idea of the size impact, so I don't think it needs to be a blocker, maybe Tom would have some opinion there, otherwise ignore this :)
Quoted 3 lines
Tom acked a similar help text on the
SPL_ZSTDoption itself, but maybe duplicating it all over the place is an overkill. Happy to distill it in the next version.
In this point, yes, perhaps the better answer is to not this stuff in documentation somewhere, rather than help text.
Signature · 1 line
Tom
Re: [PATCH v2 11/11] rockchip: Choose FIT payload compression via Kconfig
In reply to Alexey CharkovHi Alexey,
Quoted 68 lines · Alexey Charkov
Hi Quentin,
Quoted 57 lines · Quentin Schulz
Hi Alexey,
Quoted 5 lines · Alexey Charkov
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.
Thanks, this was something of an eye-sore to me for a while already :)
Quoted 34 lines
Move the selection to
Kconfiginstead, 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(-)arch/arm/dts/rockchip-u-boot.dtsi +0
-9@@ -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;arch/arm/dts/rockchip-u-boot.dtsi line 64
Quoted 10 lines
arch/arm/dts/rockchip-u-boot.dtsi +6
-1+ 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>; +#endifQuoted 7 lines
OK so the obvious question here is "why Rockchip-specific?". I appreciate you're mostly working with the RK3576 but I don't see why this (the kconfig symbol definition that happens later in this patch in
arch/arm/mach-rockchip/Kconfig) needs to be Rockchip-specific, we have other architectures that are also building a FIT image with U-Boot proper in it, so I think it'd be nice to have this setting apply to all of them so that it's a more generic approach.
Quoted 6 lines
The
Kconfigselection itself is surely arch-agnostic, but I have no idea if the handling of the resulting images will work out fine on other architectures or what their constraints are, beyond what the build system can tell me. Rockchip is the only one I can test, so I'd rather start here :)
If it's the same architecture(s) as Rockchip, I would assume that if the SPL loads a FIT image, it can load compressed images too and uncompress them on the fly as I don't see why anything would be different here (but maybe I'm wrong :) ).
I understand getting cold feet on enabling this U-Boot-wide but it would be nice to notify other architectures that this is now (well, will be) available and they can add support for it/test it. I'm thinking we (you) could do an RFC series that depend on this series here, that enables compression = CONFIG_FIT_UBOOT_COMP and compress-level = CONFIG_FIT_UBOOT_COMP_LEVEL for other architectures that use binman and generate a U-Boot FIT. Then you let the maintainers figure out the rest whether they want to take it or not (after testing themselves). This RFC series wouldn't be a blocker for this series, but I really think we should implement this in a generic way at least on the Kconfig-side so that other vendors can implement it similarly.
Quoted 8 lines
Quoted 7 lines
I'm wondering whether a
direct argument to binman would be more appropriate here instead of requiring all binman nodes to not forget to add these compression properties for the setting to actually apply. Of course this would still need some logic handling a binman argument and the compression properties both being set, and likely remove the properties from existing DTS.
Quoted 9 lines
Not sure that's a universally good idea: the FIT needs the compression attribute anyway, and it comes via the DTS. Passing the compression argument to binman via the same DTS reduces the chance of the two going out of sync. The alternative is passing the compression to binman via a separate back-channel and having it insert the FIT attributes based on that. To me, that sounds strictly worse than the current arrangement because it turns explicit settings visible in a textual config into automagic.
Yes, but at the same time, you get a truly generic solution without requiring architecture/vendor/board maintainers to implement the same details in their DTS (reducing boilerplate in essence). I'm not sold on my own idea anyway so not a blocker for me (and we can anyway decide to go this route later on).
[...]
Quoted 11 lines
Quoted 9 lines
arch/arm/dts/rockchip-u-boot.dtsi line 65
Quoted 1 line
arch/arm/dts/rockchip-u-boot.dtsi +1
-0+ default ROCKCHIP_UBOOT_COMP_NONEThis diverges from the current state, instead do:
default
ROCKCHIP_UBOOT_COMP_GZIPifSPL_GZIP
defaultROCKCHIP_UBOOT_COMP_LZMAifSPL_LZMA
defaultROCKCHIP_UBOOT_COMP_NONEto keep the same behavior (not tested but I believe this should work).
That was my first attempt, but it introduced a circular dependency.
Do you still have the dependency loop by any chance? I'm assuming this is something maybe some architecture/board maintainers will hit when wanting to default to something else than COMP_NONE?
Quoted 2 lines
I've checked the current defconfigs, and none of them enable compression. Worse, LZMA had been broken and couldn't link for some
confirmed with:
./tools/qconfig.py -b./tools/qconfig.py -f ARCH_ROCKCHIP SPL_GZIP./tools/qconfig.py -f ARCH_ROCKCHIP SPL_LZMA
Quoted 3 lines
time until I fixed it separately (it's merged now), so I'm reasonably sure there have been no active users of these settings lately.
We would "break" (change behavior for) existing users which use a non-upstreamed defconfig, but we generally don't care too much about those usecases.
Fine with me, but this needs to be documented in the commit log as from the diff itself one could think this was not done on purpose (and we're technically changing the behavior even if it doesn't apply to any of the upstreamed defconfigs).
[...]
Quoted 14 lines
Quoted 6 lines
arch/arm/dts/rockchip-u-boot.dtsi
Quoted 5 lines
arch/arm/dts/rockchip-u-boot.dtsi +5
-0+config ROCKCHIP_UBOOT_COMP_LZMA + bool "lzma" + select SPL_LZMA + help + Compress with LZMA, run from the host 'lzma_alone' binary. The bestQuoted 7 lines
I'm not sure we need to specify the implementation detail of the tool used to generate the compressed binary?
lzma_aloneis also only available on Debian-based systems (e.g. Fedora doesn't have it), so I'm not entirely sure whether it'll stay this way forever (maybe we should switch to another implementation that is available on more/most distros?). I understand you probably did this because it's somewhat an important piece of information to then decide which level to use.
Quoted 8 lines
The peculiar host binary which nobody ships these days is precisely why I decided to mention it by the name. On my main Gentoo system the legacy lzma container is only provided by the not-so-easy-to-figure-out lzmacon package, which then requires symlinking under a different name for the U-Boot build system to pick it up. With this help text, a user at least knows what weird binary to google for, or what substitutes might be available on their distro.
Can always be improved later on, so fine with me.
[...]
Quoted 18 lines
Quoted 9 lines
Quoted 9 lines
arch/arm/dts/rockchip-u-boot.dtsi +9
-0+ +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_LZ4Quoted 8 lines
arch/arm/dts/rockchip-u-boot.dtsi
Quoted 3 lines
arch/arm/dts/rockchip-u-boot.dtsi +3
-0+ default "zstd" if ROCKCHIP_UBOOT_COMP_ZSTD + default "none" +I'm tempted to say this is not the place for this and rather should be in
rockchip-u-boot.dtsifor example as a series of #ifdef (but if we go for a generic implementation that applies to other architectures, then maybe it's fine like this).
Quoted 4 lines
Noooo - do you really like #ifdefs? :) Having this here means one file to update when another algorithm gets added, as opposed to multiple, which I believe is a worthy quality in itself.
People have various different opinions on what can be part of Kconfig and the above will likely not make some happy. I don't like it, but I also don't have a strong opinion. Also, if we're going for a more generic approach, then this might become an issue rather quickly as all base DTS defining a U-Boot FIT to generate with binman would have to declare those strings again. Can always be changed later on in any case.
Cheers,
Quentin
Re: [PATCH v2 11/11] rockchip: Choose FIT payload compression via Kconfig
In reply to Alexey CharkovHi Alexey,
Quoted 19 lines · Alexey Charkov
rockchip: Choose FIT payload compression via
KconfigThe 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
Kconfiginstead, 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(-)
arch/arm/dts/rockchip-u-boot.dtsi line 56
Quoted 4 lines
arch/arm/dts/rockchip-u-boot.dtsi +4
-0@@ -61,11 +53,15 @@ +#if CONFIG_ROCKCHIP_UBOOT_COMP_LEVEL != 0 + compress-level = + <CONFIG_ROCKCHIP_UBOOT_COMP_LEVEL>; +#endif
No defconfig in the tree selects anything other than 'none', so CI never builds an image with 'compress' or 'compress-level' set here. Patch 9 enables SPL_ZSTD on sandbox for the same reason. Please can you enable one of the choices on a board you can test (your RK3576 one?), so the binman side gets some build coverage?
arch/arm/mach-rockchip/Kconfig config ROCKCHIP_MASKROM_IMAGE · line 760
Quoted 5 lines
arch/arm/mach-rockchip/Kconfig +3
-0@@ -758,6 +758,84 @@ config ROCKCHIP_MASKROM_IMAGE +config ROCKCHIP_UBOOT_COMP_GZIP + bool "gzip" + select SPL_GZIP
With this patch the choice is offered on every Rockchip board with SPL_FIT, but many of them cannot boot the result, as discussed on the cover letter. For example evb-rk3399 has CONFIG_TEXT_BASE=0x00800000 and CONFIG_SYS_LOAD_ADDR=0x800800, and 0x800800 is the most common value after 0xc00800 in the Rockchip defconfigs.
Since this is the patch which makes the option visible, please can you deal with that here, so that selecting gzip does not quietly produce an image which fails in SPL? I am not sure what the best approach is:
perhaps a separate staging address for SPL, or a build-time check that the two regions cannot overlap.
arch/arm/mach-rockchip/Kconfig config ROCKCHIP_MASKROM_IMAGE · line 760
Quoted 5 lines
arch/arm/mach-rockchip/Kconfig +3
-0@@ -758,6 +758,84 @@ config ROCKCHIP_MASKROM_IMAGE +config ROCKCHIP_UBOOT_COMP_LEVEL + int "Compression level for U-Boot proper" + depends on !ROCKCHIP_UBOOT_COMP_NONE && !ROCKCHIP_UBOOT_COMP_LZMA
When SPL_FIT is disabled the choice is hidden, so none of its symbols is set and this condition is true. The prompt then appears, with no range, on boards which have no FIT at all. For example, evb-rk3036_defconfig ends up with:
CONFIG_ROCKCHIP_UBOOT_COMP='none'
CONFIG_ROCKCHIP_UBOOT_COMP_LEVEL=0
Please can you list the algorithms which do take a level instead:
depends on ROCKCHIP_UBOOT_COMP_GZIP || ROCKCHIP_UBOOT_COMP_LZO || \
ROCKCHIP_UBOOT_COMP_LZ4 || ROCKCHIP_UBOOT_COMP_ZSTDThat also means a new algorithm has to opt in, rather than getting a level prompt with no range.
arch/arm/mach-rockchip/Kconfig config ROCKCHIP_MASKROM_IMAGE · line 759
Quoted 4 lines
arch/arm/mach-rockchip/Kconfig +2
-0@@ -758,6 +758,84 @@ config ROCKCHIP_MASKROM_IMAGE + How hard to compress, numbered the way the algorithm's own tool + numbers it. Leave it at 0 to take the tool's default.
Not quite. For lz4, binman passes -5 when no level is given (see patch 10), so this should say that 0 uses binman's default.
Regards,
Simon
Hi Alexey,
Quoted 8 lines · Alexey Charkov
SPL knows about multiple compression algorithms, but only two are hand-rolled into the simple FIT loading code, in spite of a nice ready made helper already being available right there.
Generalize the compressed FIT handling code to accept any compression algorithm compiled into the SPL, and fix up the
SPL_ZSTDlinkage which requires xxhash in the SPL but which was absent to date.
Quoted 9 lines
While here, also extend binman to support passing a compression level via its image templates, which helps squeeze additional ~15% size savings in my testing with Zstd level 19 without impacting decompression speed.
This is done with Rockchip RK3576 in mind, so a small Rockchip image template refactor is included.
CI passes all green: https://git.u-boot-project.org/u-boot/contributors/alchark/u-boot/-/pipelines/1319
Doesn't work on my PX30 Ringneck for any of the supported compression algorithms (didn't check lzma as I'm daily driving Fedora and it doesn't have lzma_alone binary).
Doesn't work on my RK3399 Puma as well (couldn't check zstd, SPL was too big and overlapped with U-Boot FIT, note that Puma is special in that it only allows (256-32)KiB for SPL, due to backward compatibility with older versions of U-Boot that had U-Boot FIT located at offset 256KiB).
On RK3588 Jaguar, all worked (still didn't check lzma due to reasons listed above).
Cheers,
Quentin
Hi Quentin,
Quoted 22 lines · Quentin Schulz
Hi Alexey,
Quoted 8 lines · Alexey Charkov
SPL knows about multiple compression algorithms, but only two are hand-rolled into the simple FIT loading code, in spite of a nice ready made helper already being available right there.
Generalize the compressed FIT handling code to accept any compression algorithm compiled into the SPL, and fix up the
SPL_ZSTDlinkage which requires xxhash in the SPL but which was absent to date.Quoted 9 lines
While here, also extend binman to support passing a compression level via its image templates, which helps squeeze additional ~15% size savings in my testing with Zstd level 19 without impacting decompression speed.
This is done with Rockchip RK3576 in mind, so a small Rockchip image template refactor is included.
CI passes all green: https://git.u-boot-project.org/u-boot/contributors/alchark/u-boot/-/pipelines/1319
Quoted 8 lines
Doesn't work on my PX30 Ringneck for any of the supported compression algorithms (didn't check lzma as I'm daily driving Fedora and it doesn't have
lzma_alonebinary).Doesn't work on my RK3399 Puma as well (couldn't check zstd, SPL was too big and overlapped with U-Boot FIT, note that Puma is special in that it only allows (256-32)KiB for SPL, due to backward compatibility with older versions of U-Boot that had U-Boot FIT located at offset 256KiB).
That's interesting. Does it work without my series though? With Gzip.
If it doesn't, the first thing I'd check is overlapping memory regions for the compressed data and the ultimate load address of any of the binaries involved.
Would you mind sharing your resulting FIT structure that binman produced for the failing boards, including all the ATF segments?
If it does work without my series, it would be great to try and bisect which patch breaks it. Not that there are many candidates besides patch 5, but I don't really see how it would break things, yet.
Quoted 2 lines
On RK3588 Jaguar, all worked (still didn't check lzma due to reasons listed above).
At least something! Thanks :)
Best regards,
Alexey
Hi Alexey,
Quoted 29 lines · Alexey Charkov
Hi Quentin,
Quoted 26 lines · Quentin Schulz
Hi Alexey,
Quoted 8 lines · Alexey Charkov
SPL knows about multiple compression algorithms, but only two are hand-rolled into the simple FIT loading code, in spite of a nice ready made helper already being available right there.
Generalize the compressed FIT handling code to accept any compression algorithm compiled into the SPL, and fix up the
SPL_ZSTDlinkage which requires xxhash in the SPL but which was absent to date.Quoted 9 lines
While here, also extend binman to support passing a compression level via its image templates, which helps squeeze additional ~15% size savings in my testing with Zstd level 19 without impacting decompression speed.
This is done with Rockchip RK3576 in mind, so a small Rockchip image template refactor is included.
CI passes all green: https://git.u-boot-project.org/u-boot/contributors/alchark/u-boot/-/pipelines/1319
Doesn't work on my PX30 Ringneck for any of the supported compression algorithms (didn't check lzma as I'm daily driving Fedora and it doesn't have
lzma_alonebinary).
Quoted 7 lines
Quoted 4 lines
Doesn't work on my RK3399 Puma as well (couldn't check zstd, SPL was too big and overlapped with U-Boot FIT, note that Puma is special in that it only allows (256-32)KiB for SPL, due to backward compatibility with older versions of U-Boot that had U-Boot FIT located at offset 256KiB).
That's interesting. Does it work without my series though? With Gzip.
It also doesn't work without your series.
Quoted 7 lines
If it doesn't, the first thing I'd check is overlapping memory regions for the compressed data and the ultimate load address of any of the binaries involved.
Would you mind sharing your resulting FIT structure that binman produced for the failing boards, including all the ATF segments?
BL31 for both come from upstream TF-A, seemingly from v2.13.0 (according to strings build/rk3399/release/bl31/bl31.elf | grep -E '^v').
ringneck-px30_defconfig + CONFIG_ROCKCHIP_UBOOT_COMP_GZIP=y
$ mkimage -l build/ringneck/u-boot.itb
Truncated file
FIT description: FIT image for U-Boot with bl31 (TF-A)
Created: Mon Sep 21 17:29:13 2026
Image 0 (u-boot)
Description: U-Boot
Created: Mon Sep 21 17:29:13 2026
Type: Standalone Program
Compression: gzip compressed
Data Size: 315656 Bytes = 308.26 KiB = 0.30 MiB
Architecture: AArch64
Load Address: 0x00800000
Entry Point: 0x00800000
Hash algo: sha256
Hash value:
1ab3cad555db60bcb81aa670798449758553a93100dccf0c08a4f9e426bb704c
Image 1 (atf-1)
Description: ARM Trusted Firmware
Created: Mon Sep 21 17:29:13 2026
Type: Firmware
Compression: uncompressed
Data Size: 106496 Bytes = 104.00 KiB = 0.10 MiB
Architecture: AArch64
OS: ARM Trusted Firmware
Load Address: 0x00040000
Hash algo: sha256
Hash value:
8ffbc6cfd2fe46ea218e5afaf76c3a4b57d80adacedd3e6d793e67f8433c5936
Image 2 (atf-2)
Description: ARM Trusted Firmware
Created: Mon Sep 21 17:29:13 2026
Type: Firmware
Compression: uncompressed
Data Size: 126 Bytes = 0.12 KiB = 0.00 MiB
Architecture: AArch64
OS: ARM Trusted Firmware
Load Address: 0x0005a000
Hash algo: sha256
Hash value:
b108492f1fc2fb0046ace3f683cdfb5f4dae3df7cc3b4ec9ba2a06ad3b194f4e
Image 3 (atf-3)
Description: ARM Trusted Firmware
Created: Mon Sep 21 17:29:13 2026
Type: Firmware
Compression: uncompressed
Data Size: 112 Bytes = 0.11 KiB = 0.00 MiB
Architecture: AArch64
OS: ARM Trusted Firmware
Load Address: 0xff020000
Hash algo: sha256
Hash value:
324fe45d21d49d4eef66d2edc3f69d15f3285c790e470db953976abc46ba6f94
Image 4 (fdt-1)
Description: fdt-rockchip/px30-ringneck-haikou
Created: Mon Sep 21 17:29:13 2026
Type: Flat Device Tree
Compression: uncompressed
Data Size: 73216 Bytes = 71.50 KiB = 0.07 MiB
Architecture: Unknown Architecture
Hash algo: sha256
Hash value:
5a17c482bc2f993bc8f971086cd4a173006236be79424dcec390a743580bcfdd
Default Configuration: 'config-1'
Configuration 0 (config-1)
Description: rockchip/px30-ringneck-haikou.dtb
Kernel: unavailable
Firmware: atf-1
FDT: fdt-1
Compatible: tsd,px30-ringneck-haikou
rockchip,px30
Loadables: u-boot
atf-2
atf-3Boot log:
U-Boot TPL board init
DDR4, 333MHz
BW=32 Col=10 Bk=4 BG=2 CS0 Row=16 CS=1 Die BW=16 Size=2048MB out
U-Boot SPL 2026.10-rc4-00496-gf94e3597ec41 (Sep 21 2026 - 17:29:10 +0200) Trying to boot from MMC1
## Checking hash(es) for config config-1 ... OK
## Checking hash(es) for Image atf-1 ... sha256+ OK
## Checking hash(es) for Image u-boot ... sha256+ OK
Uncompressing Invalid Image to 800000
Error: inflate() returned -3
Uncompressing errorspl_load_simple_fit: can't load image loadables index 0 (ret = -5)mmc_load_image_raw_sector: mmc block read error
Error: -38
SPL: Unsupported Boot Device!
puma-rk3399_defconfig + CONFIG_ROCKCHIP_UBOOT_COMP_GZIP=y
$ mkimage -l build/puma/u-boot.itb
Truncated file
FIT description: FIT image for U-Boot with bl31 (TF-A)
Created: Mon Sep 21 17:36:47 2026
Image 0 (u-boot)
Description: U-Boot
Created: Mon Sep 21 17:36:47 2026
Type: Standalone Program
Compression: gzip compressed
Data Size: 433877 Bytes = 423.71 KiB = 0.41 MiB
Architecture: AArch64
Load Address: 0x00800000
Entry Point: 0x00800000
Hash algo: sha256
Hash value:
2c24443bce4cffa899eb4e45e9903433f2cbc59b96d4b3dc98bf827544f2b252
Image 1 (atf-1)
Description: ARM Trusted Firmware
Created: Mon Sep 21 17:36:47 2026
Type: Firmware
Compression: uncompressed
Data Size: 147456 Bytes = 144.00 KiB = 0.14 MiB
Architecture: AArch64
OS: ARM Trusted Firmware
Load Address: 0x00040000
Hash algo: sha256
Hash value:
d737d2efb49d780d6cd72eb7e6c34c0cc5294753e6ac45f4495bab12f44b5a93
Image 2 (atf-2)
Description: ARM Trusted Firmware
Created: Mon Sep 21 17:36:47 2026
Type: Firmware
Compression: uncompressed
Data Size: 78 Bytes = 0.08 KiB = 0.00 MiB
Architecture: AArch64
OS: ARM Trusted Firmware
Load Address: 0x00064000
Hash algo: sha256
Hash value:
f59dc67a835f14d92d5bfee57920f5a8a68d06609481b5ede9492f4e2d379a21
Image 3 (atf-3)
Description: ARM Trusted Firmware
Created: Mon Sep 21 17:36:47 2026
Type: Firmware
Compression: uncompressed
Data Size: 8024 Bytes = 7.84 KiB = 0.01 MiB
Architecture: AArch64
OS: ARM Trusted Firmware
Load Address: 0xff3b0000
Hash algo: sha256
Hash value:
256c48c2a37faf72304b91d09daeee8442e70f06b2aae7c693e85f3d87662855
Image 4 (atf-4)
Description: ARM Trusted Firmware
Created: Mon Sep 21 17:36:47 2026
Type: Firmware
Compression: uncompressed
Data Size: 8192 Bytes = 8.00 KiB = 0.01 MiB
Architecture: AArch64
OS: ARM Trusted Firmware
Load Address: 0xff8c0000
Hash algo: sha256
Hash value:
c70fdb94f7bf6d48fb04ebd4f04b386323c41a6a796e0756beca23345ad3537f
Image 5 (atf-5)
Description: ARM Trusted Firmware
Created: Mon Sep 21 17:36:47 2026
Type: Firmware
Compression: uncompressed
Data Size: 0 Bytes = 0.00 KiB = 0.00 MiB
Architecture: AArch64
OS: ARM Trusted Firmware
Load Address: 0xff8c2000
Hash algo: sha256
Hash value:
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
Image 6 (fdt-1)
Description: fdt-rockchip/rk3399-puma-haikou
Created: Mon Sep 21 17:36:47 2026
Type: Flat Device Tree
Compression: uncompressed
Data Size: 97768 Bytes = 95.48 KiB = 0.09 MiB
Architecture: Unknown Architecture
Hash algo: sha256
Hash value:
70793f8f952644970f5e6b08f18a710276781023228ba9014b9a138ea8ceef18
Default Configuration: 'config-1'
Configuration 0 (config-1)
Description: rockchip/rk3399-puma-haikou.dtb
Kernel: unavailable
Firmware: atf-1
FDT: fdt-1
Compatible: tsd,rk3399-puma-haikou
rockchip,rk3399
Loadables: u-boot
atf-2
atf-3
atf-4
atf-5Boot log:
U-Boot TPL 2026.10-rc4-00496-gf94e3597ec41 (Sep 21 2026 - 17:36:45)
U-Boot TPL 2026.10-rc4-00496-gf94e3597ec41 (Sep 21 2026 - 17:36:45) Channel 0: DDR3, 666MHz
BW=32 Col=10 Bk=8 CS0 Row=16 CS=1 Die BW=16 Size=2048MB Channel 1: DDR3, 666MHz
BW=32 Col=10 Bk=8 CS0 Row=16 CS=1 Die BW=16 Size=2048MB 256B stride
Trying to boot from BOOTROM
Returning to boot ROM...
U-Boot SPL 2026.10-rc4-00496-gf94e3597ec41 (Sep 21 2026 - 17:36:45 +0200) Trying to boot from MMC1
## Checking hash(es) for config config-1 ... OK
## Checking hash(es) for Image atf-1 ... sha256+ OK
## Checking hash(es) for Image u-boot ... sha256+ OK
Uncompressing Invalid Image to 800000
Error: inflate() returned -3
Uncompressing errorspl_load_simple_fit: can't load image loadables index 0 (ret = -5)mmc_load_image_raw_sector: mmc block read error
Error: -38
SPL: Unsupported Boot Device!
Cheers,
Quentin
Quoted 56 lines · Quentin Schulz
Hi Alexey,
Quoted 29 lines · Alexey Charkov
Hi Quentin,
Quoted 26 lines · Quentin Schulz
Hi Alexey,
Quoted 8 lines · Alexey Charkov
SPL knows about multiple compression algorithms, but only two are hand-rolled into the simple FIT loading code, in spite of a nice ready made helper already being available right there.
Generalize the compressed FIT handling code to accept any compression algorithm compiled into the SPL, and fix up the
SPL_ZSTDlinkage which requires xxhash in the SPL but which was absent to date.Quoted 9 lines
While here, also extend binman to support passing a compression level via its image templates, which helps squeeze additional ~15% size savings in my testing with Zstd level 19 without impacting decompression speed.
This is done with Rockchip RK3576 in mind, so a small Rockchip image template refactor is included.
CI passes all green: https://git.u-boot-project.org/u-boot/contributors/alchark/u-boot/-/pipelines/1319
Doesn't work on my PX30 Ringneck for any of the supported compression algorithms (didn't check lzma as I'm daily driving Fedora and it doesn't have
lzma_alonebinary).Quoted 7 lines
Quoted 4 lines
Doesn't work on my RK3399 Puma as well (couldn't check zstd, SPL was too big and overlapped with U-Boot FIT, note that Puma is special in that it only allows (256-32)KiB for SPL, due to backward compatibility with older versions of U-Boot that had U-Boot FIT located at offset 256KiB).
That's interesting. Does it work without my series though? With Gzip.
It also doesn't work without your series.
Quoted 7 lines
If it doesn't, the first thing I'd check is overlapping memory regions for the compressed data and the ultimate load address of any of the binaries involved.
Would you mind sharing your resulting FIT structure that binman produced for the failing boards, including all the ATF segments?
BL31 for both come from upstream TF-A, seemingly from v2.13.0 (according to strings build/rk3399/release/bl31/bl31.elf | grep -E '^v').
ringneck-px30_defconfig +
CONFIG_ROCKCHIP_UBOOT_COMP_GZIP=y
Quoted 13 lines
$ mkimage -l build/ringneck/u-boot.itb Truncated file FIT description: FIT image for U-Boot with bl31 (TF-A) Created: Mon Sep 21 17:29:13 2026 Image 0 (u-boot) Description: U-Boot Created: Mon Sep 21 17:29:13 2026 Type: Standalone Program Compression: gzip compressed Data Size: 315656 Bytes = 308.26 KiB = 0.30 MiB Architecture: AArch64 Load Address: 0x00800000 Entry Point: 0x00800000
Right, so your decompression buffer at SYS_LOAD_ADDR is only 0x800 bytes behind the uncompressed U-Boot load address, so the decompression output almost immediately overwrites its own source and fails. Can you please try setting CONFIG_SYS_LOAD_ADDR to something further up?
It just needs to clear the TF-A and the uncompressed U-Boot proper region, so the kernel/fdt/ramdisk addresses U-Boot itself uses shouldn't matter, as the SPL's decompression buffer would have already been discarded by the time those are used.
Best regards,
Alexey
cover test: spl: Cover zstd and gzip FIT decompression
In reply to Alexey CharkovThese apply on top of Alexey's "spl: fit: Generalize compression support" v2:
https://patch.msgid.link/[email protected]
That series adds the FIT_*_LZMA test pair and enables CONFIG_SPL_ZSTD in sandbox_spl, but nothing decompresses a zstd or gzip payload through load_simple_fit() yet. These two patches add the same pair for each.
Each patch builds on its own with sandbox_spl_defconfig. ./spl/u-boot-spl -u runs 29 tests after the first patch and 31 after the second, no failures. Replacing the zstd_decompress() call in image_decomp() with ret = 0 fails the two zstd tests and nothing else, and doing the same to gunzip() fails the two gzip tests. With CONFIG_SPL_ZSTD and CONFIG_SPL_GZIP switched off the LZMA pair still runs.
Sandbox only, I have no Rockchip hardware.
Alexey, fold these into v3 if that is easier for you. Otherwise I will resend once the series lands.
Cole Munz (2):
test: spl: Cover FIT image decompression with zstd
test: spl: Cover FIT image decompression with gzip
configs/sandbox_spl_defconfig | 1 + include/test/spl.h | 20 + test/image/spl_load.c | 764 +++++++++++++++++++++++++++++++++- test/image/spl_load_nor.c | 4 + 4 files changed, 779 insertions(+), 10 deletions(-)
Signature · 1 line
2.55.0
PATCH 1/2 test: spl: Cover FIT image decompression with zstd
sandbox_spl enables CONFIG_SPL_ZSTD so that link errors show up, but no test feeds a zstd payload through load_simple_fit(), so the decoder itself never runs.
Add FIT_INTERNAL_ZSTD and FIT_EXTERNAL_ZSTD next to the LZMA pair and register them for the NOR loader the same way. do_spl_test_load() picks the canned blob by compression name instead of assuming LZMA. The plain payload was already seeded with that name.
image_supported() gives the new pair its own return instead of joining the LZMA fallthrough, so the LZMA tests do not start depending on CONFIG_SPL_ZSTD.
The blob is generate_data() output for the seed "zstd", compressed with the same arguments binman's zstd bintool uses:
zstd --compress --stdout plain.bin (zstd v1.5.7)
--- include/test/spl.h | 10 + test/image/spl_load.c | 403 +++++++++++++++++++++++++++++++++++++- test/image/spl_load_nor.c | 2 + 3 files changed, 405 insertions(+), 10 deletions(-)
include/test/spl.h +10 -0
@@ -31,8 +31,10 @@ void generate_data(char *data, size_t size, const char *test_name);* @IMX8: i.MX8 Container images * @FIT_INTERNAL: FITs with internal data * @FIT_INTERNAL_LZMA: FITs with internal data, LZMA compressed +* @FIT_INTERNAL_ZSTD: FITs with internal data, Zstandard compressed * @FIT_EXTERNAL: FITs with external data * @FIT_EXTERNAL_LZMA: FITs with external data, LZMA compressed +* @FIT_EXTERNAL_ZSTD: FITs with external data, Zstandard compressed */ enum spl_test_image {LEGACY ,
@@ -40,8 +42,10 @@ enum spl_test_image {IMX8 ,FIT_INTERNAL ,FIT_INTERNAL_LZMA , +FIT_INTERNAL_ZSTD ,FIT_EXTERNAL ,FIT_EXTERNAL_LZMA , + FIT_EXTERNAL_ZSTD, };/**
@@ -88,6 +92,8 @@ int check_image_info(struct unit_test_state *uts, struct spl_image_info *info1,/* Some compressed data and it size */ extern const char lzma_compressed[];extern const size_t lzma_compressed_size; +extern const char zstd_compressed[]; +extern const size_t zstd_compressed_size;/** * typedef write_image_t - Callback for writing an image
@@ -135,6 +141,10 @@ static inline bool image_supported(enum spl_test_image type)return IS_ENABLED (CONFIG_SPL_LEGACY_IMAGE_FORMAT );case IMX8 :return IS_ENABLED (CONFIG_SPL_LOAD_IMX_CONTAINER ); +case FIT_INTERNAL_ZSTD : +case FIT_EXTERNAL_ZSTD : +return IS_ENABLED (CONFIG_SPL_ZSTD ) && +IS_ENABLED (CONFIG_SPL_LOAD_FIT );case FIT_INTERNAL_LZMA :case FIT_EXTERNAL_LZMA :if (!IS_ENABLED (CONFIG_SPL_LZMA ))
test/image/spl_load.c +393 -10
456 lines not on this page · raw message
test/image/spl_load_nor.c +2 -0
@@ -36,7 +36,9 @@ SPL_IMG_TEST(spl_test_nor, LEGACY_LZMA, 0);SPL_IMG_TEST (spl_test_nor,IMX8 ,0 );SPL_IMG_TEST (spl_test_nor,FIT_INTERNAL ,0 );SPL_IMG_TEST (spl_test_nor,FIT_INTERNAL_LZMA ,0 ); +SPL_IMG_TEST (spl_test_nor,FIT_INTERNAL_ZSTD ,0 );#if !IS_ENABLED (CONFIG_SPL_LOAD_FIT_FULL )SPL_IMG_TEST (spl_test_nor,FIT_EXTERNAL ,0 );SPL_IMG_TEST (spl_test_nor,FIT_EXTERNAL_LZMA ,0 ); +SPL_IMG_TEST (spl_test_nor,FIT_EXTERNAL_ZSTD ,0 );#endif
Signature · 1 line
2.55.0
PATCH 2/2 test: spl: Cover FIT image decompression with gzip
In reply to Cole Munzsandbox_spl does not enable CONFIG_SPL_GZIP, so load_simple_fit() has no gzip coverage either.
Enable it and add FIT_INTERNAL_GZIP and FIT_EXTERNAL_GZIP the same way as the LZMA and zstd pairs, registered for the NOR loader.
The blob is generate_data() output for the seed "gzip", compressed with:
gzip -9n -c plain.bin (gzip 1.14)
-n keeps the timestamp and file name out of the header so the blob is reproducible.
--- configs/sandbox_spl_defconfig | 1 + include/test/spl.h | 10 + test/image/spl_load.c | 361 ++++++++++++++++++++++++++++++++++ test/image/spl_load_nor.c | 2 + 4 files changed, 374 insertions(+)
configs/sandbox_spl_defconfig +1 -0
@@ -230,6 +230,7 @@ CONFIG_RSA_VERIFY_WITH_PKEY=y CONFIG_TPM=y CONFIG_ZSTD=y CONFIG_SPL_LZMA=y +CONFIG_SPL_GZIP=y CONFIG_SPL_ZSTD=y CONFIG_ERRNO_STR=y CONFIG_SPL_HEXDUMP=y
include/test/spl.h +10 -0
@@ -32,9 +32,11 @@ void generate_data(char *data, size_t size, const char *test_name);* @FIT_INTERNAL: FITs with internal data * @FIT_INTERNAL_LZMA: FITs with internal data, LZMA compressed * @FIT_INTERNAL_ZSTD: FITs with internal data, Zstandard compressed +* @FIT_INTERNAL_GZIP: FITs with internal data, gzip compressed * @FIT_EXTERNAL: FITs with external data * @FIT_EXTERNAL_LZMA: FITs with external data, LZMA compressed * @FIT_EXTERNAL_ZSTD: FITs with external data, Zstandard compressed +* @FIT_EXTERNAL_GZIP: FITs with external data, gzip compressed */ enum spl_test_image {LEGACY ,
@@ -43,9 +45,11 @@ enum spl_test_image {FIT_INTERNAL ,FIT_INTERNAL_LZMA ,FIT_INTERNAL_ZSTD , +FIT_INTERNAL_GZIP ,FIT_EXTERNAL ,FIT_EXTERNAL_LZMA ,FIT_EXTERNAL_ZSTD , + FIT_EXTERNAL_GZIP, };/**
@@ -94,6 +98,8 @@ extern const char lzma_compressed[];extern const size_t lzma_compressed_size;extern const char zstd_compressed[];extern const size_t zstd_compressed_size; +extern const char gzip_compressed[]; +extern const size_t gzip_compressed_size;/** * typedef write_image_t - Callback for writing an image
@@ -145,6 +151,10 @@ static inline bool image_supported(enum spl_test_image type)case FIT_EXTERNAL_ZSTD :return IS_ENABLED (CONFIG_SPL_ZSTD ) &&IS_ENABLED (CONFIG_SPL_LOAD_FIT ); +case FIT_INTERNAL_GZIP : +case FIT_EXTERNAL_GZIP : +return IS_ENABLED (CONFIG_SPL_GZIP ) && +IS_ENABLED (CONFIG_SPL_LOAD_FIT );case FIT_INTERNAL_LZMA :case FIT_EXTERNAL_LZMA :if (!IS_ENABLED (CONFIG_SPL_LZMA ))
test/image/spl_load.c +361 -0
391 lines not on this page · raw message
test/image/spl_load_nor.c +2 -0
@@ -37,8 +37,10 @@ SPL_IMG_TEST(spl_test_nor, IMX8, 0);SPL_IMG_TEST (spl_test_nor,FIT_INTERNAL ,0 );SPL_IMG_TEST (spl_test_nor,FIT_INTERNAL_LZMA ,0 );SPL_IMG_TEST (spl_test_nor,FIT_INTERNAL_ZSTD ,0 ); +SPL_IMG_TEST (spl_test_nor,FIT_INTERNAL_GZIP ,0 );#if !IS_ENABLED (CONFIG_SPL_LOAD_FIT_FULL )SPL_IMG_TEST (spl_test_nor,FIT_EXTERNAL ,0 );SPL_IMG_TEST (spl_test_nor,FIT_EXTERNAL_LZMA ,0 );SPL_IMG_TEST (spl_test_nor,FIT_EXTERNAL_ZSTD ,0 ); +SPL_IMG_TEST (spl_test_nor,FIT_EXTERNAL_GZIP ,0 );#endif
Signature · 1 line
2.55.0
Hi Alexey,
Quoted 3 lines · Alexey Charkov
SPL knows about multiple compression algorithms, but only two are hand-rolled into the simple FIT loading code, in spite of a nice ready made helper already being available right there.
The approach looks right to me. Do you have buildman size numbers for a board which enables only SPL_GZIP with SPL_LOAD_FIT? Until now the image_decomp() call was dropped at compile time on those boards, so they pick up that function and its messages for the first time. I suspect the growth is small, with the first patch helping, but please can you put the numbers in the cover letter?
Quoted 3 lines
Generalize the compressed FIT handling code to accept any compression algorithm compiled into the SPL, and fix up the
SPL_ZSTDlinkage which requires xxhash in the SPL but which was absent to date.
The tests don't quite match this. Nothing in the series actually runs zstd_decompress() in SPL, so the green CI run cannot tell us whether the heap is big enough there. See my comments on patches 8 and 9.
A gzip case would be worthwhile too, since that path changes from calling gunzip() directly to going through image_decomp() with a different output limit.
Quoted 2 lines
This is done with Rockchip RK3576 in mind, so a small Rockchip image template refactor is included.
Quentin's failures on PX30 and RK3399 come from the staging buffer at CONFIG_SYS_LOAD_ADDR overlapping the load address of U-Boot proper, e.g. ringneck-px30 has it only 0x800 above the text base (as you say below). That predates your series, but the last patch now offers the choice on every Rockchip board, and on quite a few of them the result is an inflate error with no hint as to the cause.
I think the series should include a patch which makes the loader detect that the staging region overlaps the destination and report it clearly, even if that can only be done once the decompressed size is known. What do you think?
Regards,
Simon