mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Andrey Smirnov <andrew.smirnov@gmail.com>
To: barebox@lists.infradead.org
Cc: Andrey Smirnov <andrew.smirnov@gmail.com>
Subject: [PATCH v2 1/2] arm/cpu/start.c: Distil some common code in __start().
Date: Wed, 28 Oct 2015 11:34:37 -0700	[thread overview]
Message-ID: <1446057278-20538-2-git-send-email-andrew.smirnov@gmail.com> (raw)
In-Reply-To: <1446057278-20538-1-git-send-email-andrew.smirnov@gmail.com>

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 v1:
	- Unified barebox_boarddata and barebox_boot_dtb into
          barebox_private_data which allowed to simplify distilled code
          and avoid using double star pointers


 arch/arm/cpu/start.c | 58 +++++++++++++++++++++++++++++++++-------------------
 1 file changed, 37 insertions(+), 21 deletions(-)

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

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

 u32 barebox_arm_machine(void)
 {
 	struct barebox_arm_boarddata *bd;

-	if (!barebox_boarddata)
+	if (!barebox_private_data)
 		return 0;

-	bd = barebox_boarddata;
+	bd = barebox_private_data;

 	return bd->machine;
 }

-static void *barebox_boot_dtb;
-
 void *barebox_arm_boot_dtb(void)
 {
-	return barebox_boot_dtb;
+	return barebox_private_data;
+}
+
+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,
@@ -70,7 +80,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 +98,28 @@ 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;
+
+		switch (get_any_boarddata_magic(boarddata)) {
+		case FDT_MAGIC:
+			totalsize = get_unaligned_be32(boarddata + 4);
+			name = "DTB";
+			break;
+		case BAREBOX_ARM_BOARDDATA_MAGIC:
+			totalsize = sizeof(struct barebox_arm_boarddata);
+			name = "machine type";
+			break;
+		default:
+			break;
+		}
+
+		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

  reply	other threads:[~2015-10-28 18:35 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-28 18:34 [PATCH v2] ARM: Add support for semihosting Andrey Smirnov
2015-10-28 18:34 ` Andrey Smirnov [this message]
2015-10-30  7:20   ` [PATCH v2 1/2] arm/cpu/start.c: Distil some common code in __start() Sascha Hauer
2015-10-30 16:16     ` Andrey Smirnov
2015-10-28 18:34 ` [PATCH v2 2/2] arm/cpu: Avoid multiple definitions of barebox_arm_entry Andrey Smirnov
2015-10-30  7:10 ` [PATCH v2] ARM: Add support for semihosting 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=1446057278-20538-2-git-send-email-andrew.smirnov@gmail.com \
    --to=andrew.smirnov@gmail.com \
    --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