mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH v2 6/6] kbuild: pbl: use same compression algo for both barebox and DTB
Date: Wed, 13 Jul 2022 11:57:30 +0200	[thread overview]
Message-ID: <20220713095730.1878941-6-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20220713095730.1878941-1-a.fatoum@pengutronix.de>

From: Ahmad Fatoum <ahmad@a3f.at>

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

To make barebox easier to integrate, use the same compression algorithm
for both barebox and compressed DTB.

Note that the decompressor code will be in the image twice: Once in PBL
in uncompressed form to decompress barebox proper and once in compressed
form to decompress the DTB.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
v1 -> v2:
  - drop LZO/LZ4 hardcoding with autodetection, instead use same algo for both
---
 arch/arm/cpu/start.c | 11 ++++++++---
 images/Makefile      |  6 ------
 pbl/Kconfig          |  5 ++++-
 scripts/Makefile.lib | 11 ++++++++++-
 4 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/arch/arm/cpu/start.c b/arch/arm/cpu/start.c
index 755d48851956..5861c15d43df 100644
--- a/arch/arm/cpu/start.c
+++ b/arch/arm/cpu/start.c
@@ -52,7 +52,7 @@ u32 barebox_arm_machine(void)
 void *barebox_arm_boot_dtb(void)
 {
 	void *dtb;
-	int ret;
+	int ret = 0;
 	struct barebox_boarddata_compressed_dtb *compressed_dtb;
 	static void *boot_dtb;
 
@@ -75,8 +75,13 @@ void *barebox_arm_boot_dtb(void)
 	if (!dtb)
 		return NULL;
 
-	ret = uncompress(compressed_dtb->data, compressed_dtb->datalen,
-			 NULL, NULL, dtb, NULL, NULL);
+	if (IS_ENABLED(CONFIG_IMAGE_COMPRESSION_NONE))
+		memcpy(dtb, compressed_dtb->data,
+		       compressed_dtb->datalen_uncompressed);
+	else
+		ret = uncompress(compressed_dtb->data, compressed_dtb->datalen,
+				 NULL, NULL, dtb, NULL, NULL);
+
 	if (ret) {
 		pr_err("uncompressing dtb failed\n");
 		free(dtb);
diff --git a/images/Makefile b/images/Makefile
index a148cf41766b..c79f1a272e9c 100644
--- a/images/Makefile
+++ b/images/Makefile
@@ -108,12 +108,6 @@ $(obj)/%.pblb: $(obj)/%.pbl FORCE
 $(obj)/%.s: $(obj)/% FORCE
 	$(call if_changed,disasm)
 
-suffix_$(CONFIG_IMAGE_COMPRESSION_GZIP) = gzip
-suffix_$(CONFIG_IMAGE_COMPRESSION_LZO)  = lzo
-suffix_$(CONFIG_IMAGE_COMPRESSION_LZ4)	= lz4
-suffix_$(CONFIG_IMAGE_COMPRESSION_XZKERN) = xzkern
-suffix_$(CONFIG_IMAGE_COMPRESSION_NONE) = comp_copy
-
 $(obj)/piggy.o: $(obj)/barebox.z FORCE
 
 $(obj)/sha_sum.o: $(obj)/barebox.sha.bin FORCE
diff --git a/pbl/Kconfig b/pbl/Kconfig
index 4dfa9553f786..ba809af2d5b9 100644
--- a/pbl/Kconfig
+++ b/pbl/Kconfig
@@ -31,7 +31,10 @@ if PBL_IMAGE
 config USE_COMPRESSED_DTB
 	bool
 	depends on ARM || RISCV
-	select LZO_DECOMPRESS
+	select LZ4_DECOMPRESS if IMAGE_COMPRESSION_LZ4
+	select LZO_DECOMPRESS if IMAGE_COMPRESSION_LZO
+	select ZLIB if IMAGE_COMPRESSION_GZIP
+	select XZ_DECOMPRESS if IMAGE_COMPRESSION_XZKERN
 
 config PBL_RELOCATABLE
 	depends on ARM || MIPS || RISCV
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index c2301b5370da..61617bd9dcba 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -272,6 +272,15 @@ cmd_ld = $(LD) $(KBUILD_LDFLAGS) $(EXTRA_LDFLAGS) $(LDFLAGS_$(@F)) \
 quiet_cmd_objcopy = OBJCOPY $@
 cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@
 
+# Decompressor for barebox proper binary when using PBL
+# ---------------------------------------------------------------------------
+
+suffix_$(CONFIG_IMAGE_COMPRESSION_GZIP) = gzip
+suffix_$(CONFIG_IMAGE_COMPRESSION_LZO)  = lzo
+suffix_$(CONFIG_IMAGE_COMPRESSION_LZ4)	= lz4
+suffix_$(CONFIG_IMAGE_COMPRESSION_XZKERN) = xzkern
+suffix_$(CONFIG_IMAGE_COMPRESSION_NONE) = comp_copy
+
 # Gzip
 # ---------------------------------------------------------------------------
 
@@ -337,7 +346,7 @@ $(obj)/%.dtb.S: $(obj)/%.dtb $(obj)/%.dtb.z $(srctree)/scripts/gen-dtb-s FORCE
 	$(call if_changed,dt_S_dtb)
 
 $(obj)/%.dtb.z: $(obj)/%.dtb FORCE
-	$(call if_changed,lzo)
+	$(call if_changed,$(suffix_y))
 
 dts-frags = $(subst $(quote),,$(CONFIG_EXTERNAL_DTS_FRAGMENTS))
 quiet_cmd_dtc = DTC     $@
-- 
2.30.2




  parent reply	other threads:[~2022-07-13  9:59 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-13  9:57 [PATCH v2 1/6] common: don't allow compressing in-barebox binaries again Ahmad Fatoum
2022-07-13  9:57 ` [PATCH v2 2/6] pbl: make USE_COMPRESSED_DTB a PBL-only feature Ahmad Fatoum
2022-07-13  9:57 ` [PATCH v2 3/6] pbl: remove redundant select UNCOMRPESS Ahmad Fatoum
2022-07-13  9:57 ` [PATCH v2 4/6] kbuild: gen-dtb-s: use Makefile.lib instead of duplicating cmd_lzo Ahmad Fatoum
2022-07-13  9:57 ` [PATCH v2 5/6] pbl: compressed-dtb: use flexible array member to access data Ahmad Fatoum
2022-07-13  9:57 ` Ahmad Fatoum [this message]
2022-07-15 10:53   ` [PATCH v2 6/6] kbuild: pbl: use same compression algo for both barebox and DTB Sascha Hauer
2022-07-15 15:57     ` [PATCH] fixup! " Ahmad Fatoum
2022-07-14  8:08 ` [PATCH v2 1/6] common: don't allow compressing in-barebox binaries again Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220713095730.1878941-6-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox