All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kumar Gala <galak@kernel.crashing.org>
To: u-boot@lists.denx.de
Subject: [U-Boot-Users] [PATCH 8/9] [new uImage] Provide ability to restrict region used for boot images
Date: Tue, 19 Feb 2008 22:03:50 -0600	[thread overview]
Message-ID: <1203480231-30185-9-git-send-email-galak@kernel.crashing.org> (raw)
In-Reply-To: <1203480231-30185-8-git-send-email-galak@kernel.crashing.org>

Allow the user to set 'bootm_low' and 'bootm_size' env vars as a way
to restrict what memory range is used for bootm.

Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
---
 common/cmd_bootm.c |   10 +++++-----
 common/image.c     |   26 ++++++++++++++++++++++++++
 include/image.h    |    2 ++
 lib_m68k/bootm.c   |    2 +-
 lib_ppc/bootm.c    |   26 ++++++++++++++++++++++++--
 5 files changed, 58 insertions(+), 8 deletions(-)

diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c
index 9b77518..520ac2f 100644
--- a/common/cmd_bootm.c
+++ b/common/cmd_bootm.c
@@ -138,16 +138,16 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 
 	ulong		image_start, image_end;
 	ulong		load_start, load_end;
+	ulong		mem_start, mem_size;
 
 	struct lmb lmb;
 
 	lmb_init(&lmb);
 
-#ifdef CFG_SDRAM_BASE
-	lmb_add(&lmb, CFG_SDRAM_BASE, gd->bd->bi_memsize);
-#else
-	lmb_add(&lmb, 0, gd->bd->bi_memsize);
-#endif
+	mem_start = getenv_bootm_low();
+	mem_size = getenv_bootm_size();
+
+	lmb_add(&lmb, mem_start, mem_size);
 
 	board_lmb_reserve(&lmb);
 
diff --git a/common/image.c b/common/image.c
index b5f7a7a..7ad1140 100644
--- a/common/image.c
+++ b/common/image.c
@@ -118,6 +118,32 @@ int getenv_autostart (void)
 	return (s && (*s == 'n')) ? 0 : 1;
 }
 
+ulong getenv_bootm_low(void)
+{
+	char *s = getenv ("bootm_low");
+	if (s) {
+		ulong tmp = simple_strtoul (s, NULL, 16);
+		return tmp;
+	}
+
+#ifdef CFG_SDRAM_BASE
+	return CFG_SDRAM_BASE;
+#else
+	return 0;
+#endif
+}
+
+ulong getenv_bootm_size(void)
+{
+	char *s = getenv ("bootm_size");
+	if (s) {
+		ulong tmp = simple_strtoul (s, NULL, 16);
+		return tmp;
+	}
+
+	return gd->bd->bi_memsize;
+}
+
 void memmove_wd (void *to, void *from, size_t len, ulong chunksz)
 {
 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
diff --git a/include/image.h b/include/image.h
index f26b7e6..6f7df4f 100644
--- a/include/image.h
+++ b/include/image.h
@@ -274,6 +274,8 @@ int image_check_dcrc (image_header_t *hdr);
 int image_check_dcrc_wd (image_header_t *hdr, ulong chunksize);
 int getenv_verify (void);
 int getenv_autostart (void);
+ulong getenv_bootm_low(void);
+ulong getenv_bootm_size(void);
 void memmove_wd (void *to, void *from, size_t len, ulong chunksz);
 #endif
 
diff --git a/lib_m68k/bootm.c b/lib_m68k/bootm.c
index 5aedb99..91cf5b1 100644
--- a/lib_m68k/bootm.c
+++ b/lib_m68k/bootm.c
@@ -60,7 +60,7 @@ void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
 	bd_t *kbd;
 	void (*kernel) (bd_t *, ulong, ulong, ulong, ulong);
 
-	bootmap_base = 0;
+	bootmap_base = getenv_bootm_low();
 
 	/*
 	 * Booting a (Linux) kernel image
diff --git a/lib_ppc/bootm.c b/lib_ppc/bootm.c
index c8d6935..b0a30a0 100644
--- a/lib_ppc/bootm.c
+++ b/lib_ppc/bootm.c
@@ -58,6 +58,10 @@ extern ulong get_effective_memsize(void);
 static ulong get_sp (void);
 static void set_clocks_in_mhz (bd_t *kbd);
 
+#ifndef CFG_LINUX_LOWMEM_MAX_SIZE
+#define CFG_LINUX_LOWMEM_MAX_SIZE	(768*1024*1024)
+#endif
+
 void  __attribute__((noinline))
 do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
 		image_header_t *hdr, int verify, int autostart,
@@ -67,6 +71,7 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
 
 	ulong	initrd_start, initrd_end;
 	ulong	rd_data_start, rd_data_end, rd_len;
+	ulong	size;
 
 	ulong	cmd_start, cmd_end, bootmap_base;
 	bd_t	*kbd;
@@ -90,7 +95,24 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
 	}
 #endif
 
-	bootmap_base = 0;
+	bootmap_base = getenv_bootm_low();
+	size = getenv_bootm_size();
+
+#ifdef DEBUG
+	if (((u64)bootmap_base + size) > (CFG_SDRAM_BASE + (u64)gd->ram_size))
+		puts("WARNING: bootm_low + bootm_size exceed total memory\n");
+	if ((bootmap_base + size) > get_effective_memsize())
+		puts("WARNING: bootm_low + bootm_size exceed eff. memory\n");
+#endif
+
+	size = min(size, get_effective_memsize());
+	size = min(size, CFG_LINUX_LOWMEM_MAX_SIZE);
+
+	if (size < getenv_bootm_size()) {
+		ulong base = bootmap_base + size;
+		printf("WARNING: adjusting available memory to %x\n", size);
+		lmb_reserve(lmb, base, getenv_bootm_size() - size);
+	}
 
 	/*
 	 * Booting a (Linux) kernel image
@@ -102,7 +124,7 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
 	 * pointer.
 	 */
 	sp = get_sp();
-	debug ("## Current stack ends at 0x%08lx ", sp);
+	debug ("## Current stack ends@0x%08lx\n", sp);
 
 	/* adjust sp by 1K to be safe */
 	sp -= 1024;
-- 
1.5.3.8

  reply	other threads:[~2008-02-20  4:03 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-20  4:03 [U-Boot-Users] [PATCH 0/9] [new uImage] Add support for booting images at non-zero addresses Kumar Gala
2008-02-20  4:03 ` [U-Boot-Users] [PATCH 1/9] [new uImage] Don't pass kdb to ramdisk_high since we may not have one Kumar Gala
2008-02-20  4:03   ` [U-Boot-Users] [PATCH 2/9] [new uImage] ppc: Determine if we are booting an OF style Kumar Gala
2008-02-20  4:03     ` [U-Boot-Users] [PATCH 3/9] [new uImage] ppc: Re-order ramdisk/fdt handling sequence Kumar Gala
2008-02-20  4:03       ` [U-Boot-Users] [PATCH 4/9] [new uImage] rework error handling so common functions don't reset Kumar Gala
2008-02-20  4:03         ` [U-Boot-Users] [PATCH 5/9] [new uImage] ppc: Allow boards to specify effective amount of memory Kumar Gala
2008-02-20  4:03           ` [U-Boot-Users] [PATCH 6/9] [new uImage] Introduce lmb from linux kernel for memory mgmt of boot images Kumar Gala
2008-02-20  4:03             ` [U-Boot-Users] [PATCH 7/9] [new uImage] Use lmb for bootm allocations Kumar Gala
2008-02-20  4:03               ` Kumar Gala [this message]
2008-02-20  4:03                 ` [U-Boot-Users] [PATCH 9/9] [new uImage] Respect autostart setting in linux bootm Kumar Gala
2008-02-29 14:36           ` [U-Boot-Users] [PATCH 5/9] [new uImage] ppc: Allow boards to specify effective amount of memory Marian Balakowicz
  -- strict thread matches above, loose matches on Subject: below --
2008-02-28  3:51 [U-Boot-Users] [PATCH 0/9] [new uImage] Add support for booting images at non-zero addresses Kumar Gala
2008-02-28  3:51 ` [U-Boot-Users] [PATCH 1/9] [new uImage] Don't pass kdb to ramdisk_high since we may not have one Kumar Gala
2008-02-28  3:51   ` [U-Boot-Users] [PATCH 2/9] [new uImage] ppc: Determine if we are booting an OF style Kumar Gala
2008-02-28  3:51     ` [U-Boot-Users] [PATCH 3/9] [new uImage] ppc: Re-order ramdisk/fdt handling sequence Kumar Gala
2008-02-28  3:51       ` [U-Boot-Users] [PATCH 4/9] [new uImage] rework error handling so common functions don't reset Kumar Gala
2008-02-28  3:51         ` [U-Boot-Users] [PATCH 5/9] [new uImage] Introduce lmb from linux kernel for memory mgmt of boot images Kumar Gala
2008-02-28  3:51           ` [U-Boot-Users] [PATCH 6/9] [new uImage] Add autostart flag to bootm_headers structure Kumar Gala
2008-02-28  3:51             ` [U-Boot-Users] [PATCH 7/9] [new uImage] Use lmb for bootm allocations Kumar Gala
2008-02-28  3:51               ` [U-Boot-Users] [PATCH 8/9] [new uImage] Provide ability to restrict region used for boot images Kumar Gala
2008-02-29 14:34                 ` Marian Balakowicz

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=1203480231-30185-9-git-send-email-galak@kernel.crashing.org \
    --to=galak@kernel.crashing.org \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.