[PATCH v3 03/21] ARM: make ARM_USE_COMPRESSED_DTB available for other arches
Ahmad Fatoum
a.fatoum at pengutronix.de
Sun Mar 21 15:13:26 GMT 2021
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 at 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
More information about the barebox
mailing list