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 7/8] ARM: bootm: determine RAM start in separate function
Date: Fri, 10 Jan 2014 12:05:58 +0100	[thread overview]
Message-ID: <1389351959-20448-8-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1389351959-20448-1-git-send-email-s.hauer@pengutronix.de>

We have two places in which we determine the RAM start address.
Put the code in a separate function. Let this function also figure
out the space available from beginning of RAM.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/lib/bootm.c | 55 ++++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 45 insertions(+), 10 deletions(-)

diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
index 11ff98c..5a2780a 100644
--- a/arch/arm/lib/bootm.c
+++ b/arch/arm/lib/bootm.c
@@ -22,6 +22,38 @@
 #include <asm/armlinux.h>
 #include <asm/system.h>
 
+/*
+ * sdram_start_and_size() - determine place for putting the kernel/oftree/initrd
+ *
+ * @start:	returns the start address of the first RAM bank
+ * @size:	returns the usable space at the beginning of the first RAM bank
+ *
+ * This function returns the base address of the first RAM bank and the free
+ * space found there.
+ *
+ * return: 0 for success, negative error code otherwise
+ */
+static int sdram_start_and_size(unsigned long *start, unsigned long *size)
+{
+	struct memory_bank *bank;
+	struct resource *res;
+
+	bank = list_first_entry_or_null(&memory_banks, struct memory_bank,
+			list);
+	if (!bank)
+		return -EINVAL;
+
+	res = list_first_entry_or_null(&bank->res->children, struct resource,
+			sibling);
+	if (!res)
+		return -EINVAL;
+
+	*start = bank->start;
+	*size = res->start - bank->start;
+
+	return 0;
+}
+
 static int __do_bootm_linux(struct image_data *data, int swap)
 {
 	unsigned long kernel;
@@ -79,16 +111,17 @@ static int __do_bootm_linux(struct image_data *data, int swap)
 
 static int do_bootm_linux(struct image_data *data)
 {
-	struct memory_bank *bank;
-	unsigned long load_address;
+	unsigned long load_address, mem_start, mem_size;
 	int ret;
 
+	ret = sdram_start_and_size(&mem_start, &mem_size);
+	if (ret)
+		return ret;
+
 	load_address = data->os_address;
 
 	if (load_address == UIMAGE_INVALID_ADDRESS) {
-		bank = list_first_entry(&memory_banks,
-				struct memory_bank, list);
-		load_address = bank->start + SZ_32K;
+		load_address = mem_start + SZ_32K;
 		if (bootm_verbose(data))
 			printf("no os load address, defaulting to 0x%08lx\n",
 				load_address);
@@ -191,20 +224,22 @@ static int do_bootz_linux(struct image_data *data)
 	void *zimage;
 	u32 end;
 	unsigned long load_address = data->os_address;
+	unsigned long mem_start, mem_size;
 
-	if (load_address == UIMAGE_INVALID_ADDRESS) {
-		struct memory_bank *bank = list_first_entry(&memory_banks,
-				struct memory_bank, list);
+	ret = sdram_start_and_size(&mem_start, &mem_size);
+	if (ret)
+		return ret;
 
+	if (load_address == UIMAGE_INVALID_ADDRESS) {
 		/*
 		 * The kernel should stay in the first 128MiB of RAM, recommended
 		 * is 32MiB into RAM so that relocation prior to decompression
 		 * can be avoided.
 		 */
 		if (mem_size > SZ_64M)
-			data->os_address = bank->start + SZ_32M;
+			data->os_address = mem_start + SZ_32M;
 		else
-			data->os_address = bank->start + SZ_8M;
+			data->os_address = mem_start + SZ_8M;
 
 		load_address = data->os_address;
 		if (bootm_verbose(data))
-- 
1.8.5.2


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

  parent reply	other threads:[~2014-01-10 11:06 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-10 11:05 bootm + devicetree + much memory Sascha Hauer
2014-01-10 11:05 ` [PATCH 1/8] list: add list_first_entry_or_null() Sascha Hauer
2014-01-10 11:05 ` [PATCH 2/8] bootm: introduce bootm_load_os helper Sascha Hauer
2014-01-10 11:05 ` [PATCH 3/8] ARM: bootm: move os loading to do_bootm_linux Sascha Hauer
2014-01-10 11:05 ` [PATCH 4/8] bootm: introduce bootm_load_initrd helper Sascha Hauer
2014-01-10 11:05 ` [PATCH 5/8] bootm: introduce bootm_load_devicetree helper Sascha Hauer
2014-01-10 11:05 ` [PATCH 6/8] ARM: bootm: locate zImage higher into RAM Sascha Hauer
2014-01-10 11:05 ` Sascha Hauer [this message]
2014-01-10 11:05 ` [PATCH 8/8] ARM: bootm: pass free memory to __do_bootm_linux 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=1389351959-20448-8-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