Patchwork [U-Boot] MIPS: board.c: fix monitor length calculations

login
register
mail settings
Submitter Gabor Juhos
Date Jan. 16, 2013, 2:39 p.m.
Message ID <1358347153-31678-1-git-send-email-juhosg@openwrt.org>
Download mbox | patch
Permalink /patch/212539/
State Superseded
Delegated to: Daniel Schwierzeck
Headers show

Comments

Gabor Juhos - Jan. 16, 2013, 2:39 p.m.
The current code uses the CONFIG_SYS_MONITOR_BASE
constant to calculate the size of the reserved
memory for U-Boot. The constant is also used
explicitly to calcualte the value of the
monitor_flash_len variable.

However this leads to miscalculated values if
CONFIG_SYS_TEXT_BASE != CONFIG_SYS_MONITOR_BASE.

Use the linked address of the _start symbol in
the calculations to fix the miscalculated values.

Also print the calculated monitor length if
debug is enabled.

Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
Cc: Daniel Schwierzeck <daniel.schwierzeck@googlemail.com>
---
 arch/mips/include/asm/u-boot-mips.h |    1 +
 arch/mips/lib/board.c               |    5 +++--
 2 files changed, 4 insertions(+), 2 deletions(-)
Gabor Juhos - Jan. 16, 2013, 5:43 p.m.
2013.01.16. 15:39 keltezéssel, Gabor Juhos írta:
> The current code uses the CONFIG_SYS_MONITOR_BASE
> constant to calculate the size of the reserved
> memory for U-Boot. The constant is also used
> explicitly to calcualte the value of the
> monitor_flash_len variable.
> 
> However this leads to miscalculated values if
> CONFIG_SYS_TEXT_BASE != CONFIG_SYS_MONITOR_BASE.
> 
> Use the linked address of the _start symbol in
> the calculations to fix the miscalculated values.
> 
> Also print the calculated monitor length if
> debug is enabled.
> 
> Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
> Cc: Daniel Schwierzeck <daniel.schwierzeck@googlemail.com>

Forget this. It still does not work as expected.

-Gabor

Patch

diff --git a/arch/mips/include/asm/u-boot-mips.h b/arch/mips/include/asm/u-boot-mips.h
index 6f26dfa..4421696 100644
--- a/arch/mips/include/asm/u-boot-mips.h
+++ b/arch/mips/include/asm/u-boot-mips.h
@@ -5,6 +5,7 @@ 
  * Copyright (C) 2003 Wolfgang Denk, DENX Software Engineering, wd@denx.de
  */
 
+extern ulong _start;
 extern ulong uboot_end_data;
 extern ulong uboot_end;
 
diff --git a/arch/mips/lib/board.c b/arch/mips/lib/board.c
index d79e183..5c4d0eb 100644
--- a/arch/mips/lib/board.c
+++ b/arch/mips/lib/board.c
@@ -143,7 +143,7 @@  void board_init_f(ulong bootflag)
 	gd_t gd_data, *id;
 	bd_t *bd;
 	init_fnc_t **init_fnc_ptr;
-	ulong addr, addr_sp, len = (ulong)&uboot_end - CONFIG_SYS_MONITOR_BASE;
+	ulong addr, addr_sp, len = (ulong)&uboot_end - (ulong)&_start;
 	ulong *s;
 
 	/* Pointer is writable since we allocated a register for it.
@@ -261,7 +261,8 @@  void board_init_r(gd_t *id, ulong dest_addr)
 
 	gd->reloc_off = dest_addr - CONFIG_SYS_MONITOR_BASE;
 
-	monitor_flash_len = (ulong)&uboot_end_data - dest_addr;
+	monitor_flash_len = (ulong)&uboot_end_data - (ulong)&_start;
+	debug("Monitor flash len: %08lX\n", monitor_flash_len);
 
 	serial_initialize();