[PATCH 1/3] kbuild: gen-dtb-s: refactor to allow different compression methods

Ahmad Fatoum a.fatoum at pengutronix.de
Mon Jul 11 06:15:54 PDT 2022


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 at 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




More information about the barebox mailing list