mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] arm/cpu/start.c: Distil some common code in __start().
@ 2015-09-26  6:02 Andrey Smirnov
  2015-09-26  6:02 ` [PATCH 2/2] arm/cpu/start.c: Avoid copying device-tree when possible Andrey Smirnov
  0 siblings, 1 reply; 8+ messages in thread
From: Andrey Smirnov @ 2015-09-26  6:02 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 arch/arm/cpu/start.c | 49 +++++++++++++++++++++++++++++++++++--------------
 1 file changed, 35 insertions(+), 14 deletions(-)

diff --git a/arch/arm/cpu/start.c b/arch/arm/cpu/start.c
index 8e5097b..7ffde7c 100644
--- a/arch/arm/cpu/start.c
+++ b/arch/arm/cpu/start.c
@@ -53,6 +53,18 @@ void *barebox_arm_boot_dtb(void)
 	return barebox_boot_dtb;
 }

+static uint32_t get_any_boarddata_magic(const void *boarddata)
+{
+	if (get_unaligned_be32(boarddata) == FDT_MAGIC)
+		return FDT_MAGIC;
+
+	if (((struct barebox_arm_boarddata *)boarddata)->magic ==
+	    BAREBOX_ARM_BOARDDATA_MAGIC)
+		return BAREBOX_ARM_BOARDDATA_MAGIC;
+
+	return 0;
+}
+
 static noinline __noreturn void __start(unsigned long membase,
 		unsigned long memsize, void *boarddata)
 {
@@ -89,21 +101,30 @@ static noinline __noreturn void __start(unsigned long membase,
 	}

 	if (boarddata) {
-		if (get_unaligned_be32(boarddata) == FDT_MAGIC) {
-			uint32_t totalsize = get_unaligned_be32(boarddata + 4);
+		uint32_t totalsize;
+		void **var = NULL;
+		const char *name;
+
+		switch (get_any_boarddata_magic(boarddata)) {
+		case FDT_MAGIC:
+			totalsize = get_unaligned_be32(boarddata + 4);
+			var = &barebox_boot_dtb;
+			name = "DTB";
+			break;
+		case BAREBOX_ARM_BOARDDATA_MAGIC:
+			totalsize = sizeof(struct barebox_arm_boarddata);
+			var = &barebox_boarddata;
+			name = "machine type";
+			break;
+		default:
+			break;
+		}
+
+		if (var) {
 			endmem -= ALIGN(totalsize, 64);
-			barebox_boot_dtb = (void *)endmem;
-			pr_debug("found DTB in boarddata, copying to 0x%p\n",
-					barebox_boot_dtb);
-			memcpy(barebox_boot_dtb, boarddata, totalsize);
-		} else if (((struct barebox_arm_boarddata *)boarddata)->magic ==
-				BAREBOX_ARM_BOARDDATA_MAGIC) {
-			endmem -= ALIGN(sizeof(struct barebox_arm_boarddata), 64);
-			barebox_boarddata = (void *)endmem;
-			pr_debug("found machine type in boarddata, copying to 0x%p\n",
-					barebox_boarddata);
-			memcpy(barebox_boarddata, boarddata,
-					sizeof(struct barebox_arm_boarddata));
+			pr_debug("found %s in boarddata, copying to 0x%lu\n",
+				 name, endmem);
+			*var = memcpy((void *)endmem, boarddata, totalsize);
 		}
 	}

--
2.1.4

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-10-06 17:35 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-26  6:02 [PATCH 1/2] arm/cpu/start.c: Distil some common code in __start() Andrey Smirnov
2015-09-26  6:02 ` [PATCH 2/2] arm/cpu/start.c: Avoid copying device-tree when possible Andrey Smirnov
2015-09-29  6:58   ` Sascha Hauer
2015-09-29 17:52     ` Andrey Smirnov
2015-09-30  7:00       ` Sascha Hauer
2015-09-30 17:56         ` Andrey Smirnov
2015-10-01  6:22           ` Sascha Hauer
2015-10-06 17:35             ` Andrey Smirnov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox