mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/3] kbuild: gen-dtb-s: refactor to allow different compression methods
@ 2022-07-11 13:15 Ahmad Fatoum
  2022-07-11 13:15 ` [PATCH 2/3] scripts: gen-dtb-s: fallback to LZ4 if lzop is unavailable Ahmad Fatoum
  2022-07-11 13:15 ` [PATCH 3/3] common: don't allow compressing in-barebox binaries again Ahmad Fatoum
  0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2022-07-11 13:15 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

We unconditonally use LZO for __dtb_z symbols when
CONFIG_USE_COMPRESSED_DTB=y. Refactor the code to allow different
compression methods. The immediate benefit is allowing LZ4 as an
alternative, as lzop is dormant and in future, we may want to reuse the
same compression method used for barebox proper for the device tree as
well.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/Kconfig       |  6 +++++-
 scripts/Makefile.lib |  2 +-
 scripts/gen-dtb-s    | 18 +++++++++++++++---
 3 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/common/Kconfig b/common/Kconfig
index f7a6a96e877c..076fe455f8ac 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -45,7 +45,11 @@ config USE_COMPRESSED_DTB
 	bool
 	depends on ARM || RISCV
 	select UNCOMPRESS
-	select LZO_DECOMPRESS
+	select LZO_DECOMPRESS if DTB_COMPRESSION = "lzo"
+
+config DTB_COMPRESSION
+	string
+	default "lzo"
 
 config FILETYPE
 	bool
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index a830364a8bab..18abeebdc0a9 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -332,7 +332,7 @@ endif
 
 # Generate an assembly file to wrap the output of the device tree compiler
 quiet_cmd_dt_S_dtb = DTB     $@
-cmd_dt_S_dtb = $(srctree)/scripts/gen-dtb-s $(subst -,_,$(*F)) $< $(CONFIG_IMD) > $@
+cmd_dt_S_dtb = $(srctree)/scripts/gen-dtb-s $(subst -,_,$(*F)) $< $(CONFIG_IMD) $(CONFIG_DTB_COMPRESSION) > $@
 $(obj)/%.dtb.S: $(obj)/%.dtb $(srctree)/scripts/gen-dtb-s FORCE
 	$(call if_changed,dt_S_dtb)
 
diff --git a/scripts/gen-dtb-s b/scripts/gen-dtb-s
index 1027db28044f..da0b593da4eb 100755
--- a/scripts/gen-dtb-s
+++ b/scripts/gen-dtb-s
@@ -3,6 +3,7 @@
 name=$1
 dtb=$2
 imd=$3
+compression=$4
 
 echo "#include <asm-generic/barebox.lds.h>"
 
@@ -51,11 +52,22 @@ echo "__dtb_${name}_end:"
 echo ".global __dtb_${name}_end"
 echo ".balign STRUCT_ALIGNMENT"
 
-lzop -f -9 $dtb -o $dtb.lzo
+case $compression in
+	none)
+		exit 0
+		;;
+	lzo)
+		lzop -f -9 $dtb -o $dtb.$compression
+		;;
+	*)
+		echo Unsupported compression algorithm: $compression >&2
+		exit 1
+		;;
+esac
 if [ $? != 0 ]; then
 	exit 1
 fi
-compressed=$(${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" $dtb.lzo)
+compressed=$(${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" $dtb.$compression)
 uncompressed=$(${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" $dtb)
 
 echo "#ifdef CONFIG_USE_COMPRESSED_DTB"
@@ -66,7 +78,7 @@ echo "__dtb_z_${name}_start:"
 printf ".int 0x%08x\n"  0x7b66bcbd
 printf ".int 0x%08x\n"  $compressed
 printf ".int 0x%08x\n"  $uncompressed
-echo ".incbin \"$dtb.lzo\""
+echo ".incbin \"$dtb.$compression\""
 echo "__dtb_z_${name}_end:"
 echo ".global __dtb_z_${name}_end"
 echo ".balign STRUCT_ALIGNMENT"
-- 
2.30.2




^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/3] scripts: gen-dtb-s: fallback to LZ4 if lzop is unavailable
  2022-07-11 13:15 [PATCH 1/3] kbuild: gen-dtb-s: refactor to allow different compression methods Ahmad Fatoum
@ 2022-07-11 13:15 ` Ahmad Fatoum
  2022-07-11 13:15 ` [PATCH 3/3] common: don't allow compressing in-barebox binaries again Ahmad Fatoum
  1 sibling, 0 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2022-07-11 13:15 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

lzop hasn't seen any activity since 2017 and has been recently removed
from OpenEmbedded, which is unfortunate as we unconditonally use LZO for
compressing device trees that are referenced via __dtb_z_.

As a fallback, use LZ4 as compression if lzop is not available.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/Kconfig    | 7 ++++++-
 scripts/gen-dtb-s | 6 ++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/common/Kconfig b/common/Kconfig
index 076fe455f8ac..f1f0b4fab91c 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
 
+source "scripts/Kconfig.include"
 source "common/boards/Kconfig"
 
 config GREGORIAN_CALENDER
@@ -46,10 +47,14 @@ config USE_COMPRESSED_DTB
 	depends on ARM || RISCV
 	select UNCOMPRESS
 	select LZO_DECOMPRESS if DTB_COMPRESSION = "lzo"
+	select LZ4_DECOMPRESS if DTB_COMPRESSION = "lz4"
 
 config DTB_COMPRESSION
 	string
-	default "lzo"
+	default "none" if !USE_COMPRESSED_DTB
+	default "lzo" if $(success,lzop -V)
+	default "lz4" if $(success,lz4c -V)
+	default "none"
 
 config FILETYPE
 	bool
diff --git a/scripts/gen-dtb-s b/scripts/gen-dtb-s
index da0b593da4eb..1d70f260f677 100755
--- a/scripts/gen-dtb-s
+++ b/scripts/gen-dtb-s
@@ -59,6 +59,12 @@ case $compression in
 	lzo)
 		lzop -f -9 $dtb -o $dtb.$compression
 		;;
+	lz4)
+		lz4c -fql $dtb $dtb.$compression
+		# LZ4 decompressor strips away last 4 bytes, but doesn't
+		# consume them, so increase size accordingly
+		printf '\0\0\0\0' >>$dtb.$compression
+		;;
 	*)
 		echo Unsupported compression algorithm: $compression >&2
 		exit 1
-- 
2.30.2




^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 3/3] common: don't allow compressing in-barebox binaries again
  2022-07-11 13:15 [PATCH 1/3] kbuild: gen-dtb-s: refactor to allow different compression methods Ahmad Fatoum
  2022-07-11 13:15 ` [PATCH 2/3] scripts: gen-dtb-s: fallback to LZ4 if lzop is unavailable Ahmad Fatoum
@ 2022-07-11 13:15 ` Ahmad Fatoum
  1 sibling, 0 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2022-07-11 13:15 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

For barebox with a prebootloader, we can compress barebox proper as a
whole and it makes no sense to compress the environment on its own
again. The choice already defaulted to this, but the user could still
override it. Ensure that this double compression can't happen.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/Kconfig | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/common/Kconfig b/common/Kconfig
index f1f0b4fab91c..ac23fa7f4419 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -869,29 +869,30 @@ choice
 	default DEFAULT_COMPRESSION_LZ4 if LZ4_DECOMPRESS
 	default DEFAULT_COMPRESSION_BZIP2 if BZLIB
 	help
-	  Select the default compression for in-barebox binary files. Files
-	  compiled into barebox like for example the default environment will
-	  be compressed with this compression type.
+	  For barebox builds without a prebootloader, select here the default
+	  compression for in-barebox binary files. barebox itself can't be
+	  compressed without a prebootloader, but for example the default
+	  environment will be compressed with this compression type.
 
 config DEFAULT_COMPRESSION_GZIP
 	bool "gzip"
-	depends on ZLIB
+	depends on !PBL_IMAGE && ZLIB
 
 config DEFAULT_COMPRESSION_BZIP2
 	bool "bzip2"
-	depends on BZLIB
+	depends on !PBL_IMAGE && BZLIB
 
 config DEFAULT_COMPRESSION_LZO
 	bool "lzo"
-	depends on LZO_DECOMPRESS
+	depends on !PBL_IMAGE && LZO_DECOMPRESS
 
 config DEFAULT_COMPRESSION_LZ4
 	bool "lz4"
-	depends on LZ4_DECOMPRESS
+	depends on !PBL_IMAGE && LZ4_DECOMPRESS
 
 config DEFAULT_COMPRESSION_XZ
 	bool "xz"
-	depends on XZ_DECOMPRESS
+	depends on !PBL_IMAGE && XZ_DECOMPRESS
 
 config DEFAULT_COMPRESSION_NONE
 	bool "no compression"
-- 
2.30.2




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-07-11 13:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-11 13:15 [PATCH 1/3] kbuild: gen-dtb-s: refactor to allow different compression methods Ahmad Fatoum
2022-07-11 13:15 ` [PATCH 2/3] scripts: gen-dtb-s: fallback to LZ4 if lzop is unavailable Ahmad Fatoum
2022-07-11 13:15 ` [PATCH 3/3] common: don't allow compressing in-barebox binaries again Ahmad Fatoum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox