mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v3 1/2] arm/cpu/start.c: Distil some common code in __start().
@ 2015-10-31  3:12 Andrey Smirnov
  2015-10-31  3:12 ` [PATCH v3 2/2] arm/cpu: Avoid multiple definitions of barebox_arm_entry Andrey Smirnov
  2015-11-02  7:33 ` [PATCH v3 1/2] arm/cpu/start.c: Distil some common code in __start() Sascha Hauer
  0 siblings, 2 replies; 4+ messages in thread
From: Andrey Smirnov @ 2015-10-31  3:12 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Both barebox_boarddata and barebox_boot_dtb perform essentially the
same function -- hold a pointer to a chunk of private data. Since only
one variable is ever used at any given time we may as well merge those
two variable into one. This also allows us to share more code between
two boot paths (board data vs. device tree)

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---

Changes since v2:

	- Restored original function semantics for
          barebox_arm_machine() and barebox_arm_boot_dtb()

	- Removed now unnecessary swith statement and auxiliary
          function that was needed to support its usage


 arch/arm/cpu/start.c | 65 +++++++++++++++++++++++++++++++---------------------
 1 file changed, 39 insertions(+), 26 deletions(-)

diff --git a/arch/arm/cpu/start.c b/arch/arm/cpu/start.c
index 8e5097b..bfe08cc 100644
--- a/arch/arm/cpu/start.c
+++ b/arch/arm/cpu/start.c
@@ -32,25 +32,37 @@
 #include "mmu-early.h"

 unsigned long arm_stack_top;
-static void *barebox_boarddata;
+static void *barebox_private_data;

-u32 barebox_arm_machine(void)
+static bool blob_is_fdt(const void *blob)
 {
-	struct barebox_arm_boarddata *bd;
-
-	if (!barebox_boarddata)
-		return 0;
-
-	bd = barebox_boarddata;
+	return get_unaligned_be32(blob) == FDT_MAGIC;
+}

-	return bd->machine;
+static bool blob_is_arm_boarddata(const void *blob)
+{
+	const struct barebox_arm_boarddata *bd = blob;
+	return bd->magic == BAREBOX_ARM_BOARDDATA_MAGIC;
 }

-static void *barebox_boot_dtb;
+u32 barebox_arm_machine(void)
+{
+	if (barebox_private_data &&
+	    blob_is_arm_boarddata(barebox_private_data)) {
+		const struct barebox_arm_boarddata *bd = barebox_private_data;
+		return bd->machine;
+	} else {
+		return 0;
+	}
+}

 void *barebox_arm_boot_dtb(void)
 {
-	return barebox_boot_dtb;
+	if (barebox_private_data &&
+	    blob_is_fdt(barebox_private_data))
+		return barebox_private_data;
+	else
+		return NULL;
 }

 static noinline __noreturn void __start(unsigned long membase,
@@ -70,7 +82,6 @@ static noinline __noreturn void __start(unsigned long membase,

 	pr_debug("memory at 0x%08lx, size 0x%08lx\n", membase, memsize);

-	barebox_boarddata = boarddata;
 	arm_stack_top = endmem;
 	endmem -= STACK_SIZE; /* Stack */

@@ -89,21 +100,23 @@ 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 = 0;
+		const char *name;
+
+		if (blob_is_fdt(boarddata)) {
+			totalsize = get_unaligned_be32(boarddata + 4);
+			name = "DTB";
+		} else if (blob_is_arm_boarddata(boarddata)) {
+			totalsize = sizeof(struct barebox_arm_boarddata);
+			name = "machine type";
+		}
+
+		if (totalsize) {
 			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);
+			barebox_private_data = 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] 4+ messages in thread

end of thread, other threads:[~2015-11-02  7:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-31  3:12 [PATCH v3 1/2] arm/cpu/start.c: Distil some common code in __start() Andrey Smirnov
2015-10-31  3:12 ` [PATCH v3 2/2] arm/cpu: Avoid multiple definitions of barebox_arm_entry Andrey Smirnov
2015-11-02  7:46   ` Sascha Hauer
2015-11-02  7:33 ` [PATCH v3 1/2] arm/cpu/start.c: Distil some common code in __start() Sascha Hauer

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