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>, rcz@pengutronix.de
Subject: [PATCH v3 03/21] ARM: make ARM_USE_COMPRESSED_DTB available for other arches
Date: Sun, 21 Mar 2021 16:13:26 +0100	[thread overview]
Message-ID: <20210321151344.5810-4-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20210321151344.5810-1-a.fatoum@pengutronix.de>

Other PBL-enabled architecture can benefit from compressed dtbs as well.
Move symbol and code to a comm place to be able to use it from RISC-V
in a later commit. In order not to break out of tree boards at runtime,
the old symbol name is maintained for ARM.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 arch/arm/Kconfig                   |  5 ++---
 arch/arm/cpu/start.c               | 20 ++++--------------
 arch/arm/include/asm/barebox-arm.h |  7 -------
 common/Kconfig                     |  6 ++++++
 include/compressed-dtb.h           | 33 ++++++++++++++++++++++++++++++
 5 files changed, 45 insertions(+), 26 deletions(-)
 create mode 100644 include/compressed-dtb.h

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 3b983c8b3d0a..faf5050eaf23 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -18,9 +18,8 @@ config HAVE_MACH_ARM_HEAD
 	bool
 
 config ARM_USE_COMPRESSED_DTB
-	bool
-	select UNCOMPRESS
-	select LZO_DECOMPRESS
+       bool
+       select USE_COMPRESSED_DTB
 
 config TEXT_BASE
 	hex
diff --git a/arch/arm/cpu/start.c b/arch/arm/cpu/start.c
index f48f5beea807..c61db668658b 100644
--- a/arch/arm/cpu/start.c
+++ b/arch/arm/cpu/start.c
@@ -18,6 +18,7 @@
 #include <linux/kasan.h>
 #include <memory.h>
 #include <uncompress.h>
+#include <compressed-dtb.h>
 #include <malloc.h>
 
 #include <debug_ll.h>
@@ -30,18 +31,6 @@ static unsigned long arm_endmem;
 static void *barebox_boarddata;
 static unsigned long barebox_boarddata_size;
 
-static bool blob_is_fdt(const void *blob)
-{
-	return get_unaligned_be32(blob) == FDT_MAGIC;
-}
-
-static bool blob_is_compressed_fdt(const void *blob)
-{
-	const struct barebox_arm_boarddata_compressed_dtb *dtb = blob;
-
-	return dtb->magic == BAREBOX_ARM_BOARDDATA_COMPRESSED_DTB_MAGIC;
-}
-
 static bool blob_is_arm_boarddata(const void *blob)
 {
 	const struct barebox_arm_boarddata *bd = blob;
@@ -64,7 +53,7 @@ void *barebox_arm_boot_dtb(void)
 	void *dtb;
 	void *data;
 	int ret;
-	struct barebox_arm_boarddata_compressed_dtb *compressed_dtb;
+	struct barebox_boarddata_compressed_dtb *compressed_dtb;
 	static void *boot_dtb;
 
 	if (boot_dtb)
@@ -75,8 +64,7 @@ void *barebox_arm_boot_dtb(void)
 		return barebox_boarddata;
 	}
 
-	if (!IS_ENABLED(CONFIG_ARM_USE_COMPRESSED_DTB) || !barebox_boarddata
-			|| !blob_is_compressed_fdt(barebox_boarddata))
+	if (!fdt_blob_can_be_decompressed(barebox_boarddata))
 		return NULL;
 
 	compressed_dtb = barebox_boarddata;
@@ -185,7 +173,7 @@ __noreturn __no_sanitize_address void barebox_non_pbl_start(unsigned long membas
 			totalsize = get_unaligned_be32(boarddata + 4);
 			name = "DTB";
 		} else if (blob_is_compressed_fdt(boarddata)) {
-			struct barebox_arm_boarddata_compressed_dtb *bd = boarddata;
+			struct barebox_boarddata_compressed_dtb *bd = boarddata;
 			totalsize = bd->datalen + sizeof(*bd);
 			name = "Compressed DTB";
 		} else if (blob_is_arm_boarddata(boarddata)) {
diff --git a/arch/arm/include/asm/barebox-arm.h b/arch/arm/include/asm/barebox-arm.h
index f81257f896a9..348a55e8040f 100644
--- a/arch/arm/include/asm/barebox-arm.h
+++ b/arch/arm/include/asm/barebox-arm.h
@@ -84,13 +84,6 @@ u32 barebox_arm_machine(void);
 unsigned long arm_mem_ramoops_get(void);
 unsigned long arm_mem_endmem_get(void);
 
-struct barebox_arm_boarddata_compressed_dtb {
-#define BAREBOX_ARM_BOARDDATA_COMPRESSED_DTB_MAGIC 0x7b66bcbd
-	u32 magic;
-	u32 datalen;
-	u32 datalen_uncompressed;
-};
-
 struct barebox_arm_boarddata *barebox_arm_get_boarddata(void);
 
 #if defined(CONFIG_RELOCATABLE) && defined(CONFIG_ARM_EXCEPTIONS)
diff --git a/common/Kconfig b/common/Kconfig
index 56064d12c5f3..ede26cec081a 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -42,6 +42,12 @@ config BLOCK
 config BLOCK_WRITE
 	bool
 
+config USE_COMPRESSED_DTB
+	bool
+	depends on ARM
+	select UNCOMPRESS
+	select LZO_DECOMPRESS
+
 config ELF
 	bool "ELF Support" if COMPILE_TEST
 
diff --git a/include/compressed-dtb.h b/include/compressed-dtb.h
new file mode 100644
index 000000000000..1ba98a7e2b92
--- /dev/null
+++ b/include/compressed-dtb.h
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef COMPRESSED_DTB_H_
+#define COMPRESSED_DTB_H_
+
+#include <linux/types.h>
+#include <asm/unaligned.h>
+
+struct barebox_boarddata_compressed_dtb {
+#define BAREBOX_BOARDDATA_COMPRESSED_DTB_MAGIC 0x7b66bcbd
+	u32 magic;
+	u32 datalen;
+	u32 datalen_uncompressed;
+};
+
+static inline bool blob_is_compressed_fdt(const void *blob)
+{
+	const struct barebox_boarddata_compressed_dtb *dtb = blob;
+
+	return dtb->magic == BAREBOX_BOARDDATA_COMPRESSED_DTB_MAGIC;
+}
+
+static inline bool fdt_blob_can_be_decompressed(const void *blob)
+{
+	return IS_ENABLED(CONFIG_USE_COMPRESSED_DTB) && blob
+			&& blob_is_compressed_fdt(blob);
+}
+
+static inline bool blob_is_fdt(const void *blob)
+{
+	return get_unaligned_be32(blob) == FDT_MAGIC;
+}
+
+#endif
-- 
2.29.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


  parent reply	other threads:[~2021-03-21 15:21 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-21 15:13 [PATCH v3 00/21] RISC-V: erizo: migrate to PBL Ahmad Fatoum
2021-03-21 15:13 ` [PATCH v3 01/21] partitions: don't allocate dma capable memory Ahmad Fatoum
2021-03-21 15:13 ` [PATCH v3 02/21] images: make BOARD_ARM_GENERIC_DT available for other arches Ahmad Fatoum
2021-03-21 15:13 ` Ahmad Fatoum [this message]
2021-03-21 15:13 ` [PATCH v3 04/21] ARM: aarch64: omit unused label in assembly Ahmad Fatoum
2021-03-21 15:13 ` [PATCH v3 05/21] serial: virtio-console: depend on, but don't select VIRTIO Ahmad Fatoum
2021-03-21 15:13 ` [PATCH v3 06/21] RISC-V: <asm/unaligned.h>: don't do unaligned accesses Ahmad Fatoum
2021-03-21 15:13 ` [PATCH v3 07/21] RISC-V: debug_ll: ns16550: align C access size with assembly's Ahmad Fatoum
2021-03-21 15:13 ` [PATCH v3 08/21] RISC-V: drop duplicate or unneeded cflags Ahmad Fatoum
2021-03-21 15:13 ` [PATCH v3 09/21] RISC-V: add cacheless HAS_DMA support Ahmad Fatoum
2021-03-21 15:13 ` [PATCH v3 10/21] RISC-V: erizo: move to arch/riscv/boards/erizo Ahmad Fatoum
2021-03-21 15:13 ` [PATCH v3 11/21] RISC-V: import Linux' optimized string functions Ahmad Fatoum
2021-03-21 15:13 ` [PATCH v3 12/21] filetype: detect RISC-V images Ahmad Fatoum
2021-03-21 15:13 ` [PATCH v3 13/21] RISC-V: implement PBL image header Ahmad Fatoum
2021-03-21 15:13 ` [PATCH v3 14/21] RISC-V: implement PBL and relocation support Ahmad Fatoum
2021-03-21 22:26   ` Antony Pavlov
2021-03-22  7:20   ` [PATCH] fixup! " Ahmad Fatoum
2021-03-21 15:13 ` [PATCH v3 15/21] RISC-V: erizo: migrate to PBL Ahmad Fatoum
2021-03-23 21:43   ` Antony Pavlov
2021-03-24  8:27     ` Ahmad Fatoum
2021-03-21 15:13 ` [PATCH v3 16/21] RISC-V: support symbol names in barebox image Ahmad Fatoum
2021-03-21 15:13 ` [PATCH v3 17/21] RISC-V: add 64-bit support Ahmad Fatoum
2021-03-21 15:13 ` [PATCH v3 18/21] RISC-V: add generic DT image Ahmad Fatoum
2021-03-21 15:13 ` [PATCH v3 19/21] clocksource: add driver for RISC-V and CLINT timers Ahmad Fatoum
2021-03-21 15:13 ` [PATCH v3 20/21] power: reset: add drivers for generic syscon reset and poweroff Ahmad Fatoum
2021-03-22  7:21   ` [PATCH] fixup! clocksource: add driver for RISC-V and CLINT timers Ahmad Fatoum
2021-03-22  7:39     ` Ahmad Fatoum
2021-03-21 15:13 ` [PATCH v3 21/21] RISC-V: add Qemu virt support Ahmad Fatoum

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=20210321151344.5810-4-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=rcz@pengutronix.de \
    /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