Skip to contentSkip to conversation

decompressors: Update xz to include ARM64 BCJ decoder

PATCH In review Jules Maselbas 2 participants 6 messages Sep 7, 2023 – Sep 8, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/3 decompressors: Update xz to include ARM64 BCJ decoder

Update lib/xz/xz_dec_bcj.c and lib/xz/xz_private.h files from xz-embedded [1], which include spelling fixes and the new ARM64 BCJ decoder which was recently introduced into .xz file format version 1.1.0 (2022-12-11) [2].

[1] https://git.tukaani.org/?p=xz-embedded.git
[2] https://tukaani.org/xz/xz-file-format-1.1.0.txt

---
v2:
- only select ARM64 BCJ on aarch64 (previously was ARM and ARM64)
- fix condition in xz_private.h to enable BCJ decoders when only ARM64 BCJ decoder is selected (https://www.mail-archive.com/[email protected]/msg00638.html)

---
 lib/Kconfig           |  4 ++++
 lib/decompress_unxz.c |  6 ++++-
 lib/xz/xz_dec_bcj.c   | 54 ++++++++++++++++++++++++++++++++++++++++---
 lib/xz/xz_private.h   |  5 +++-
 4 files changed, 64 insertions(+), 5 deletions(-)
lib/Kconfig +4 -0
index 758197b608..9291e5a8ff 100644
@@ -42,6 +42,7 @@ config XZ_DECOMPRESS
 	select XZ_DEC_ARM
 	select XZ_DEC_ARMTHUMB
 	select XZ_DEC_SPARC
+	select XZ_DEC_ARM64
 
 config XZ_DEC_X86
         bool
@@ -61,6 +62,9 @@ config XZ_DEC_ARMTHUMB
 config XZ_DEC_SPARC
         bool
 
+config XZ_DEC_ARM64
+	bool "ARM64 BCJ filter decoder"
+
 config REED_SOLOMON
 	bool
 
lib/decompress_unxz.c +5 -1
index a7e2d331ab..132ab4a239 100644
@@ -131,7 +131,11 @@
 #	define XZ_DEC_POWERPC
 #endif
 #ifdef CONFIG_ARM
-#	define XZ_DEC_ARM
+#	ifdef CONFIG_CPU_64
+#		define XZ_DEC_ARM64
+#	else
+#		define XZ_DEC_ARM
+#	endif
 #endif
 #ifdef CONFIG_IA64
 #	define XZ_DEC_IA64
lib/xz/xz_dec_bcj.c +51 -3

90 lines not on this page · raw message

lib/xz/xz_private.h +4 -1
index 85f79635f0..b14a262c92 100644
@@ -37,6 +37,9 @@
 #		ifdef CONFIG_XZ_DEC_SPARC
 #			define XZ_DEC_SPARC
 #		endif
+#		ifdef CONFIG_XZ_DEC_ARM64
+#			define XZ_DEC_ARM64
+#		endif
 #		define memeq(a, b, size) (memcmp(a, b, size) == 0)
 #		define memzero(buf, size) memset(buf, 0, size)
 #		define FREE free
@@ -98,7 +101,7 @@
 #ifndef XZ_DEC_BCJ
 #	if defined(XZ_DEC_X86) || defined(XZ_DEC_POWERPC) \
 			|| defined(XZ_DEC_IA64) || defined(XZ_DEC_ARM) \
-			|| defined(XZ_DEC_ARM) || defined(XZ_DEC_ARMTHUMB) \
+			|| defined(XZ_DEC_ARM64) || defined(XZ_DEC_ARMTHUMB) \
 			|| defined(XZ_DEC_SPARC)
 #		define XZ_DEC_BCJ
 #	endif
Signature · 1 line
2.42.0
#1 lore raw

PATCH v2 2/3 scripts: Select XZ --arm64 BCJ filter for 64-bit arm

This change will select the arm64 BCJ filter for aarch64 instead of the arm filter which was always selected for arm based architectures.

The selected filter is also tested, by looking if it is present in the long help message of xz, this is because the arm64 BCJ filter is a recent addition to xz.

---
v2: no changes

---
 scripts/xz_wrap.sh | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
scripts/xz_wrap.sh +4 -1
index 7a2d372f48..5b5f3adcff 100755
@@ -16,8 +16,11 @@ case $SRCARCH in
 	x86)            BCJ=--x86 ;;
 	powerpc)        BCJ=--powerpc ;;
 	ia64)           BCJ=--ia64; LZMA2OPTS=pb=4 ;;
-	arm)            BCJ=--arm ;;
+	arm)            BCJ=--arm$S64 ;;
 	sparc)          BCJ=--sparc ;;
 esac
 
+# clear BCJ filter if unsupported
+xz -H | grep -q -- $BCJ || BCJ=
+
 exec xz --check=crc32 $BCJ --lzma2=$LZMA2OPTS,dict=32MiB
Signature · 1 line
2.42.0
#2 lore raw

PATCH v2 3/3 kbuild: remove duplicated xz compressions target

In reply to Jules Maselbas

Both cmd_xzkern and cmd_xzmisc where already defined in the same file

---
v2: no changes

---
 scripts/Makefile.lib | 28 ----------------------------
 1 file changed, 28 deletions(-)
scripts/Makefile.lib +0 -28
index f04c09f9e2..6baa618f15 100644
@@ -470,34 +470,6 @@ cmd_lzo = (cat $(filter-out FORCE,$^) | \
 %.lzo: %
 	$(call if_changed,lzo)
 
-# XZ
-# ---------------------------------------------------------------------------
-# Use xzkern to compress the kernel image and xzmisc to compress other things.
-#
-# xzkern uses a big LZMA2 dictionary since it doesn't increase memory usage
-# of the kernel decompressor. A BCJ filter is used if it is available for
-# the target architecture. xzkern also appends uncompressed size of the data
-# using size_append. The .xz format has the size information available at
-# the end of the file too, but it's in more complex format and it's good to
-# avoid changing the part of the boot code that reads the uncompressed size.
-# Note that the bytes added by size_append will make the xz tool think that
-# the file is corrupt. This is expected.
-#
-# xzmisc doesn't use size_append, so it can be used to create normal .xz
-# files. xzmisc uses smaller LZMA2 dictionary than xzkern, because a very
-# big dictionary would increase the memory usage too much in the multi-call
-# decompression mode. A BCJ filter isn't used either.
-quiet_cmd_xzkern = XZKERN  $@
-cmd_xzkern = (cat $(filter-out FORCE,$^) | \
-	sh $(srctree)/scripts/xz_wrap.sh && \
-	$(call size_append, $(filter-out FORCE,$^))) > $@ || \
-	(rm -f $@ ; false)
-
-quiet_cmd_xzmisc = XZMISC  $@
-cmd_xzmisc = (cat $(filter-out FORCE,$^) | \
-	xz --check=crc32 --lzma2=dict=1MiB) > $@ || \
-	(rm -f $@ ; false)
-
 # lz4
 # ---------------------------------------------------------------------------
 
Signature · 1 line
2.42.0
#3 lore raw
In reply to Jules Maselbas

lib/Kconfig config XZ_DEC_ARMTHUMB · line 66

Quoted 2 lines
lib/Kconfig +2 -0
+config XZ_DEC_ARM64
+	bool "ARM64 BCJ filter decoder"

I've just noticied that this string makes this config entry visible in menuconfig, while all others are not.
It should be only: bool without anything else afterward.

cheers
Jules

#4 lore raw
Quoted 5 lines · Jules Maselbas

lib/Kconfig config XZ_DEC_ARMTHUMB · line 66

Quoted 2 lines
lib/Kconfig +2 -0
+config XZ_DEC_ARM64
+	bool "ARM64 BCJ filter decoder"

I've just noticied that this string makes this config entry visible in menuconfig, while all others are not.
It should be only: bool without anything else afterward.

Fixed that while applying.

Thanks
Sascha

Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
#5 lore raw
Quoted 8 lines · Sascha Hauer
Quoted 5 lines · Jules Maselbas

lib/Kconfig config XZ_DEC_ARMTHUMB · line 66

Quoted 2 lines
lib/Kconfig +2 -0
+config XZ_DEC_ARM64
+	bool "ARM64 BCJ filter decoder"

I've just noticied that this string makes this config entry visible in menuconfig, while all others are not.
It should be only: bool without anything else afterward.

Fixed that while applying.

thanks

Quoted 4 lines

Thanks
Sascha