public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [RFC PATCH] arm: provide a CONFIG flag for disabling relocation
@ 2011-09-20 14:22 GROYER, Anthony
  2011-09-20 18:09 ` Wolfgang Denk
  2011-09-20 21:34 ` Simon Glass
  0 siblings, 2 replies; 28+ messages in thread
From: GROYER, Anthony @ 2011-09-20 14:22 UTC (permalink / raw)
  To: u-boot


Hello,

I came back on a discussion started on April 2011.

The use of the initial patches for the CONFIG_SYS_SKIP_ARM_RELOCATION features has revealed two issues.

First issue: the calculation of the relocation offset was done only if the relocation is actually done. So we could reach a point where r9 has a wrong value, since it has never been used before (in my case, this bug happens without JTAG). The first diff moves the relocation offset calculation before the test of a relocation need.

Second issue: board_init_r was thinking the memory area for the malloc is just below the code, whereas the board_init_f had allocated some space for the malloc at the end of the SDRAM. If the code is located at the base of the SDRAM with CONFIG_SYS_SKIP_ARM_RELOCATION defined, the malloc area does not point to a correct memory address.
The 2 other diff store the calculated malloc start address in a global data member so that it can be used in board_init_r().

Index: arch/arm/cpu/arm926ejs/start.S
===================================================================
--- arch/arm/cpu/arm926ejs/start.S	(r?vision 1083)
+++ arch/arm/cpu/arm926ejs/start.S	(r?vision 1113)
@@ -196,6 +196,10 @@
 	mov	r4, r0	/* save addr_sp */
 	mov	r5, r1	/* save addr of gd */
 	mov	r6, r2	/* save addr of destination */
+    /* set relocation offset here for all cases:
+        relocation or not */
+	ldr	r0, _TEXT_BASE	/* r0 <- Text base */
+	sub	r9, r6, r0		/* r9 <- relocation offset */
 
 	/* Set up the stack						    */
 stack_setup:
@@ -218,8 +222,6 @@
 	/*
 	 * fix .rel.dyn relocations
 	 */
-	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
-	sub	r9, r6, r0		/* r9 <- relocation offset */
 	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
 	add	r10, r10, r0		/* r10 <- sym table in FLASH */
 	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
Index: arch/arm/include/asm/global_data.h
===================================================================
--- arch/arm/include/asm/global_data.h	(r?vision 1083)
+++ arch/arm/include/asm/global_data.h	(copie de travail)
@@ -69,6 +69,7 @@
 	unsigned long	mon_len;	/* monitor len */
 	unsigned long	irq_sp;		/* irq stack pointer */
 	unsigned long	start_addr_sp;	/* start_addr_stackpointer */
+	unsigned long	start_addr_malloc;	/* start_addr_malloc */
 	unsigned long	reloc_off;
 #if !(defined(CONFIG_SYS_NO_ICACHE) && defined(CONFIG_SYS_NO_DCACHE))
 	unsigned long	tlb_addr;
Index: arch/arm/lib/board.c
===================================================================
--- arch/arm/lib/board.c	(r?vision 1138)
+++ arch/arm/lib/board.c	(copie de travail)
@@ -367,6 +367,7 @@
 	 * reserve memory for malloc() arena
 	 */
 	addr_sp = addr - TOTAL_MALLOC_LEN;
+    gd->start_addr_malloc = addr_sp;
 	debug ("Reserving %dk for malloc() at: %08lx\n",
 			TOTAL_MALLOC_LEN >> 10, addr_sp);
 	/*
@@ -445,7 +446,6 @@
 {
 	char *s;
 	bd_t *bd;
-	ulong malloc_start;
 #if !defined(CONFIG_SYS_NO_FLASH)
 	ulong flash_size;
 #endif
@@ -473,9 +473,7 @@
 	post_output_backlog ();
 #endif
 
-	/* The Malloc area is immediately below the monitor copy in DRAM */
-	malloc_start = dest_addr - TOTAL_MALLOC_LEN;
-	mem_malloc_init (malloc_start, TOTAL_MALLOC_LEN);
+	mem_malloc_init (gd->start_addr_malloc, TOTAL_MALLOC_LEN);
 
 #if !defined(CONFIG_SYS_NO_FLASH)
 	puts ("Flash: ");

Regards,
Anthony Groyer

>On Wed, Apr 20, 2011 at 11:56 PM, Aneesh V <ane...@ti.com> wrote:
>> Hi Simon, Wolfgang,
>>
>> On Thursday 21 April 2011 12:04 AM, Simon Glass wrote:
>>>
>>> On Fri, Mar 25, 2011 at 11:35 AM, Albert ARIBAUD<albert.arib...@free.fr>
>>>  wrote:
>>>>
>>>> Le 25/03/2011 17:12, Aneesh V a ?crit :
>>>>
>>>>> Another problem I have with relocation is that it makes debugging with
>>>>> JTAG debugers more difficult. The addresses of symbols in the ELF
>>>>> target are no longer valid. Of course, you can load the symbols at an
>>>>> offset from the original location. But one has to first enable debug
>>>>> prints, find the relocation offset, use it while loading the symbols
>>>>> before you can do source level debugging.
>>>>
>>>> Actually you don't need recompiling: simply set a breakpoint at the
>>>> entry of relocate_code and once you hit the bp, look up r2: it contains
>>>> the destination. If you want the offset rather than the absolute
>>>> address, set the breakpoint right after the 'sub r9, r6, r0' round line
>>>> 222: r9 will then give you the offset. Unload the current symbols,
>>>> reload the symbols with the relevant offset, and there you go.
>>>
>>> I would like to revisit this thread. I'm not sure how other people do
>>> development in U-Boot but I like to use an ICE and a source-level
>>> debugger for any significant effort. I think it should be possible to
>>> use a JTAG debugging just by loading the u-boot ELF file and running.
>>>
>>> With this patch (or something similar) this is possible. Without it,
>>> it is painful.
>>>
>>> To be clear, we are not talking here about creating a platform that
>>> doesn't use relocation, just that for development purposes it is
>>> convenient to be able to disable it.
>>
>> Actually, I am not even sure why relocation shouldn't be disabled in my
>> platform for good. It may be useful to have things such as the frame
>> buffer at the end of available memory. But, IMHO, that can still be
>> done without relocating u-boot. That's what the patch does.Am I missing
>> something?
>
>Well relocation does remove a lot of this ad-hoc positioning of things
>at compile time. I think it is desirable. My point is that it is not
>engineer-friendly during development, and we should have an easy way
>to disable it for debugging / JTAG purposes.
>
>Regards,
>Simon
>
>>
>>>
>>> Looking at the December thread
>>> http://thread.gmane.org/gmane.comp.boot-loaders.u-boot/88067/focus=88262
>>>
>>> Aneesh:
>>>>>
>>>>> Shouldn't we provide a CONFIG option by which users can disable
>>>>> Elf relocation?
>>>
>>> Wolfgang:
>>>>
>>>> Why should we?  It would just make the code even more complicated, and
>>>> require a lot of additional test cases.
>>>
>>>  From what I can see this is a new CONFIG option, two ifdefs in the
>>> board.c file, and optionally disabling the -pie position-independent
>>> executable option to reduce size. It is pretty trivial:
>>>
>>>  arch/arm/config.mk   |    2 ++
>>>  arch/arm/lib/board.c |    5 +++++
>>>  2 files changed, 7 insertions(+), 0 deletions(-)
>>>
>>> Regards,
>>> Simon
>>>
>>>>
>>>> Amicalement,
>>>> --
>>>> Albert.
>>>> _______________________________________________
>>>> U-Boot mailing list
>>>> U-Boot at lists.denx.de
>>>> http://lists.denx.de/mailman/listinfo/u-boot
>>>>
>>
>_______________________________________________
>U-Boot mailing list
>U-Boot at lists.denx.de
>http://lists.denx.de/mailman/listinfo/u-boot
>

^ permalink raw reply	[flat|nested] 28+ messages in thread
* [U-Boot] [RFC PATCH] arm: provide a CONFIG flag for disabling relocation
@ 2011-03-25 13:12 Aneesh V
  2011-03-25 13:27 ` Aneesh V
  2011-03-25 14:12 ` Wolfgang Denk
  0 siblings, 2 replies; 28+ messages in thread
From: Aneesh V @ 2011-03-25 13:12 UTC (permalink / raw)
  To: u-boot

Relocation may not be needed and desirable in many cases:
 * For many boards the amount of SDRAM is fixed.
   So relocation is not needed.
 * Relocation adds un-necessary additional overhead when
   it's not needed. This delay is singificant on slower
   platforms such as FPGA
 * Many boards have ample memory. So reserving enough memory
   for Linux in the first half is not a challenge even without
   relocation

Add a CONFIG option to disable relocation on platforms that
do not need it. When this flag is enabled allocate memory
for stack heap etc at the end of memory as usual, but U-Boot
itself is not moved from TEXT_BASE.

Additionally, -pie is removed from the final link step because
it was causing the absolute value of all symbols coming from
the linker script to be 0. This affects find_cmd()

Tested on OMAP4430 SDP

Cc: Albert Aribaud <albert.aribaud@free.fr>
Cc: Wolfgang Denk <wd@denx.de>

Signed-off-by: Aneesh V <aneesh@ti.com>
---
 arch/arm/config.mk              |    2 ++
 arch/arm/lib/board.c            |    5 +++++
 board/ti/sdp4430/config.mk      |    9 +++++++--
 include/configs/omap4_sdp4430.h |    2 ++
 4 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/arch/arm/config.mk b/arch/arm/config.mk
index 1785e73..2315bcb 100644
--- a/arch/arm/config.mk
+++ b/arch/arm/config.mk
@@ -71,5 +71,7 @@ LDSCRIPT := $(SRCTREE)/$(CPUDIR)/u-boot.lds
 
 # needed for relocation
 ifndef CONFIG_NAND_SPL
+ifndef CONFIG_SYS_SKIP_ARM_RELOCATION
 LDFLAGS_u-boot += -pie
 endif
+endif
diff --git a/arch/arm/lib/board.c b/arch/arm/lib/board.c
index 72ee108..ed3898f 100644
--- a/arch/arm/lib/board.c
+++ b/arch/arm/lib/board.c
@@ -361,6 +361,7 @@ void board_init_f (ulong bootflag)
 	gd->fb_base = addr;
 #endif /* CONFIG_LCD */
 
+#ifndef CONFIG_SYS_SKIP_ARM_RELOCATION
 	/*
 	 * reserve memory for U-Boot code, data & bss
 	 * round down to next 4 kB limit
@@ -369,6 +370,7 @@ void board_init_f (ulong bootflag)
 	addr &= ~(4096 - 1);
 
 	debug ("Reserving %ldk for U-Boot at: %08lx\n", gd->mon_len >> 10, addr);
+#endif
 
 #ifndef CONFIG_PRELOADER
 	/*
@@ -420,6 +422,9 @@ void board_init_f (ulong bootflag)
 	dram_init_banksize();
 	display_dram_config();	/* and display it */
 
+#ifdef CONFIG_SYS_SKIP_ARM_RELOCATION
+	addr = _TEXT_BASE;
+#endif
 	gd->relocaddr = addr;
 	gd->start_addr_sp = addr_sp;
 	gd->reloc_off = addr - _TEXT_BASE;
diff --git a/board/ti/sdp4430/config.mk b/board/ti/sdp4430/config.mk
index c62965d..8846732 100644
--- a/board/ti/sdp4430/config.mk
+++ b/board/ti/sdp4430/config.mk
@@ -28,5 +28,10 @@
 # Linux-Kernel is expected to be at 8000'8000, entry 8000'8000
 # (mem base + reserved)
 
-# 1MB into the SDRAM to allow for SPL's bss at the beginning of SDRAM
-CONFIG_SYS_TEXT_BASE = 0x80100000
+# 64MB into the SDRAM
+# Assuming a minimum of 128 MB on the board:
+# - 64MB before U-Boot is more than enough for Linux when relocation is
+#   disabled
+# - ~63MB after the U-Boot is more than enough for U-Boot to relocate
+#   itself without stepping on itself
+CONFIG_SYS_TEXT_BASE = 0x84000000
diff --git a/include/configs/omap4_sdp4430.h b/include/configs/omap4_sdp4430.h
index fff67d8..e9f76d3 100644
--- a/include/configs/omap4_sdp4430.h
+++ b/include/configs/omap4_sdp4430.h
@@ -278,4 +278,6 @@
 #define CONFIG_SYS_SPL_BSS_MAX_SIZE		0x80000		/* 512 KB */
 
 #define CONFIG_SYS_THUMB_BUILD
+
+#define CONFIG_SYS_SKIP_ARM_RELOCATION
 #endif /* __CONFIG_H */
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2011-10-03  3:34 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-20 14:22 [U-Boot] [RFC PATCH] arm: provide a CONFIG flag for disabling relocation GROYER, Anthony
2011-09-20 18:09 ` Wolfgang Denk
2011-09-20 19:13   ` Albert ARIBAUD
2011-09-21  9:29     ` GROYER, Anthony
2011-09-21 10:45       ` Wolfgang Denk
2011-09-21 11:44         ` Albert ARIBAUD
2011-09-21 10:51       ` Albert ARIBAUD
2011-09-21 11:20         ` Andreas Bießmann
2011-09-21 12:03           ` Albert ARIBAUD
2011-09-21 12:31             ` Andreas Bießmann
2011-09-21 14:23               ` Albert ARIBAUD
2011-09-22  7:10                 ` Andreas Bießmann
2011-09-29 16:14               ` Andreas Bießmann
2011-09-30  7:21                 ` Simon Schwarz
2011-10-01  6:48                   ` Albert ARIBAUD
2011-09-20 21:34 ` Simon Glass
2011-09-21 14:21   ` Aneesh V
2011-09-23 16:04     ` Simon Glass
2011-10-01  7:01       ` Albert ARIBAUD
2011-10-03  3:34         ` Simon Glass
  -- strict thread matches above, loose matches on Subject: below --
2011-03-25 13:12 Aneesh V
2011-03-25 13:27 ` Aneesh V
2011-03-25 14:12 ` Wolfgang Denk
2011-03-25 16:12   ` Aneesh V
2011-03-25 18:35     ` Albert ARIBAUD
2011-04-20 18:34       ` Simon Glass
2011-04-21  6:56         ` Aneesh V
2011-04-21 15:18           ` Simon Glass

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