mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 1/2] ARM: Allow to pass a devicetree via boarddata
Date: Wed, 26 Jun 2013 07:27:42 +0200	[thread overview]
Message-ID: <1372224463-13629-2-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1372224463-13629-1-git-send-email-s.hauer@pengutronix.de>

Addionally to having a builtin DTB provide the possibility for
the board to provide a dtb via boarddata.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/cpu/Makefile              |  2 +-
 arch/arm/cpu/dtb.c                 | 22 ++++++++++++++++++++--
 arch/arm/cpu/start.c               | 20 ++++++++++++++++++++
 arch/arm/include/asm/barebox-arm.h |  2 ++
 4 files changed, 43 insertions(+), 3 deletions(-)

diff --git a/arch/arm/cpu/Makefile b/arch/arm/cpu/Makefile
index c442b35..99973ae 100644
--- a/arch/arm/cpu/Makefile
+++ b/arch/arm/cpu/Makefile
@@ -8,7 +8,7 @@ obj-y += start.o setupc.o
 #
 obj-$(CONFIG_CMD_ARM_CPUINFO) += cpuinfo.o
 obj-$(CONFIG_CMD_ARM_MMUINFO) += mmuinfo.o
-obj-$(CONFIG_BUILTIN_DTB) += dtb.o
+obj-$(CONFIG_OFDEVICE) += dtb.o
 obj-$(CONFIG_MMU) += mmu.o cache.o mmu-early.o
 pbl-$(CONFIG_MMU) += cache.o mmu-early.o
 obj-$(CONFIG_CPU_32v4T) += cache-armv4.o
diff --git a/arch/arm/cpu/dtb.c b/arch/arm/cpu/dtb.c
index 10b73bd..a5881dd 100644
--- a/arch/arm/cpu/dtb.c
+++ b/arch/arm/cpu/dtb.c
@@ -17,20 +17,38 @@
 #include <common.h>
 #include <init.h>
 #include <of.h>
+#include <asm/barebox-arm.h>
 
 extern char __dtb_start[];
 
 static int of_arm_init(void)
 {
 	struct device_node *root;
+	void *fdt;
 
+	/* See if we already have a dtb */
 	root = of_get_root_node();
 	if (root)
 		return 0;
 
-	root = of_unflatten_dtb(NULL, __dtb_start);
-	if (root) {
+	/* See if we are provided a dtb in boarddata */
+	fdt = barebox_arm_boot_dtb();
+	if (fdt)
+		pr_debug("using boarddata provided DTB\n");
+
+	/* Next see if we have a builtin dtb */
+	if (!fdt && IS_ENABLED(CONFIG_BUILTIN_DTB)) {
+		fdt = __dtb_start;
 		pr_debug("using internal DTB\n");
+	}
+
+	if (!fdt) {
+		pr_debug("No DTB found\n");
+		return 0;
+	}
+
+	root = of_unflatten_dtb(NULL, fdt);
+	if (root) {
 		of_set_root_node(root);
 		if (IS_ENABLED(CONFIG_OFDEVICE))
 			of_probe();
diff --git a/arch/arm/cpu/start.c b/arch/arm/cpu/start.c
index 5a3c629..1f397ec 100644
--- a/arch/arm/cpu/start.c
+++ b/arch/arm/cpu/start.c
@@ -24,6 +24,7 @@
 #include <asm/barebox-arm-head.h>
 #include <asm-generic/memory_layout.h>
 #include <asm/sections.h>
+#include <asm/unaligned.h>
 #include <asm/cache.h>
 #include <memory.h>
 
@@ -40,6 +41,13 @@ unsigned long barebox_arm_boarddata(void)
 	return barebox_boarddata;
 }
 
+static void *barebox_boot_dtb;
+
+void *barebox_arm_boot_dtb(void)
+{
+	return barebox_boot_dtb;
+}
+
 static noinline __noreturn void __start(uint32_t membase, uint32_t memsize,
 		uint32_t boarddata)
 {
@@ -66,6 +74,18 @@ static noinline __noreturn void __start(uint32_t membase, uint32_t memsize,
 			mmu_early_enable(membase, memsize, endmem);
 	}
 
+	/*
+	 * If boarddata is a pointer inside valid memory and contains a
+	 * FDT magic then use it as later to probe devices
+	 */
+	if (boarddata > membase && boarddata < membase + memsize &&
+			get_unaligned_be32((void *)boarddata) == FDT_MAGIC) {
+		uint32_t totalsize = get_unaligned_be32((void *)boarddata + 4);
+		endmem -= ALIGN(totalsize, 64);
+		barebox_boot_dtb = (void *)endmem;
+		memcpy(barebox_boot_dtb, (void *)boarddata, totalsize);
+	}
+
 	if ((unsigned long)_text > membase + memsize ||
 			(unsigned long)_text < membase)
 		/*
diff --git a/arch/arm/include/asm/barebox-arm.h b/arch/arm/include/asm/barebox-arm.h
index cd8decf..ddcafd1 100644
--- a/arch/arm/include/asm/barebox-arm.h
+++ b/arch/arm/include/asm/barebox-arm.h
@@ -54,6 +54,8 @@ static inline void arm_fixup_vectors(void)
 }
 #endif
 
+void *barebox_arm_boot_dtb(void);
+
 /*
  * For relocatable binaries find a suitable start address for the
  * relocated binary. Beginning at the memory end substract the reserved
-- 
1.8.3.1


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

  reply	other threads:[~2013-06-26  5:28 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-25  9:20 [PATCH] barebox multi image support Sascha Hauer
2013-06-25  9:20 ` [PATCH 01/12] ARM: split barebox_arm_head in two separate functions Sascha Hauer
2013-06-25  9:20 ` [PATCH 02/12] ARM: pbl: move linker script to lib Sascha Hauer
2013-06-25  9:20 ` [PATCH 03/12] ARM: build dtbs unconditionally Sascha Hauer
2013-06-25  9:20 ` [PATCH 04/12] ARM: Add image end section Sascha Hauer
2013-06-25  9:20 ` [PATCH 05/12] imx-image: fix path to imx-image binary Sascha Hauer
2013-06-25  9:20 ` [PATCH 06/12] Add multi images support Sascha Hauer
2013-06-25  9:20 ` [PATCH 07/12] ARM: i.MX: Add multi images support Makefile Sascha Hauer
2013-06-25  9:20 ` [PATCH 08/12] ARM: i.MX27 pcm038: switch to multi image Sascha Hauer
2013-06-25  9:20 ` [PATCH 09/12] ARM: i.MX53 loco: Switch to imximage Sascha Hauer
2013-06-25  9:20 ` [PATCH 10/12] ARM: i.MX53 loco: Switch to multi image support Sascha Hauer
2013-06-25  9:20 ` [PATCH 11/12] ARM: dmo realq7: switch " Sascha Hauer
2013-06-25  9:20 ` [PATCH 12/12] ARM: i.MX51 babbage: " Sascha Hauer
2013-06-25  9:26 ` [PATCH] barebox " Sascha Hauer
2013-06-26  5:27 ` Sascha Hauer
2013-06-26  5:27   ` Sascha Hauer [this message]
2013-06-26  5:27   ` [PATCH 2/2] ARM: dts: Add .S files as secondary target 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=1372224463-13629-2-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@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