Hi Cole,

On 8/15/26 1:30 AM, Cole Munz wrote:
[You don't often get email from [email protected]. Learn why this is important 
at https://aka.ms/LearnAboutSenderIdentification ]

Update the zstd implementation to match Linux zstd 1.5.7 from commit
65d1f5507ed2 ("zstd: Import upstream v1.5.7").

U-Boot has carried zstd 1.5.2 since commit 4b9b25d943ff ("lib: zstd: update
to latest Linux zstd 1.5.2"), which mirrored Linux commit 2aa14b1ab2c4.
Linux has since moved to 1.5.7, which carries decode robustness and
correctness fixes.

This is a straight mirror of the Linux zstd code, keeping the same
adaptations the 1.5.2 import documented:
- update a few #include that do not translate cleanly
   - linux/swab.h -> asm/byteorder.h
   - linux/limits.h -> linux/kernel.h
   - linux/module.h -> linux/compat.h
- remove assert() from debug.h so it doesn't conflict with u-boot's
   assert()
- strip out the compressor code as was done in the previous u-boot zstd
- change the #define for MEM_STATIC to use INLINE_KEYWORD for codesize

Two adaptations are new to this update:
- linux/unaligned.h -> asm/unaligned.h. Linux renamed asm/unaligned.h to
   linux/unaligned.h and 1.5.7's mem.h picks up the new path, while
   U-Boot still provides the asm/ one.
- collapse duplicate newlines. Commit 2f8c004a5ae5 ("lib: Remove duplicate
   newlines") stripped those tree-wide after the 1.5.2 import, so mirroring
   Linux verbatim would re-add 137 of them.

1.5.7 adds a faster Huffman decode path, and buildman -B shows it is where
nearly all the growth lands, mostly in HUF_decompress4X1_usingDTable_internal,
HUF_readDTableX1_wksp and the new fast_c_loop. Upstream guards that path with
HUF_DISABLE_FAST_DECODE, so add it to the CONFIG_ZSTD_LIB_MINIFY flags beside
the HUF_FORCE_DECOMPRESS_X1 and DYNAMIC_BMI2=0 already there. It recovers 1684
bytes on turris_mox. Giving up decode speed for size is what that option is
for.

Tested on sandbox: "ut lib" passes 133 tests with no failures, including
compression_test_zstd and compression_test_bootm_zstd. Also cross-built
for aarch64 (turris_mox with CONFIG_ZSTD=y) with no new warnings.
Size delta with CONFIG_ZSTD_LIB_MINIFY=y is text +1088 bytes on sandbox and
text +236 bytes on turris_mox, with data and bss unchanged on both. Without
HUF_DISABLE_FAST_DECODE those are +2888 and +1920.

Signed-off-by: Cole Munz <[email protected]>
---

Changes in v2:
- Add HUF_DISABLE_FAST_DECODE to the CONFIG_ZSTD_LIB_MINIFY flags, per Tom.
   turris_mox goes from +1920 to +236 bytes against 1.5.2, sandbox from +2888
   to +1088.

checkpatch is loud on this one, but that comes from mirroring the Linux
sources, not from the change itself. Running checkpatch --file over lib/zstd
gives 5127 errors on the 1.5.2 code already in tree and 5283 on 1.5.7, over
28 and 30 files, so the per-line density is flat.

The import is scripted against a Linux tree at 65d1f5507ed2 rather than done
by hand. Happy to post the script if it would help the next refresh.


If it fits reasonably well into a commit log, that would even be a nice place to store the info for the next person bumping libzstd to look at. It would also help us identify shortcomings if any, even after this gets merged (if it does :) ).

Cheers,
Quentin

Reply via email to