Patchwork [U-Boot] CONFIG_SYS_TEXT_BASE and relocaddr

mail settings
Submitter Luca Ellero
Date Jan. 29, 2013, 3:16 p.m.
Message ID <>
Download mbox | patch
Permalink /patch/216570/
State Not Applicable
Delegated to: Tom Rini
Headers show


Luca Ellero - Jan. 29, 2013, 3:16 p.m.
Dear Wolfgang,

On 29/01/2013 10.48, Wolfgang Denk wrote:
> Dear Luca Ellero,
> In message <> you wrote:
>> in U-Boot version 2012.10 I used to skip "relocate_code" setting
>> CONFIG_SYS_TEXT_BASE to relocaddr (obtained from bdinfo command).
>> This since some hardware is able to configure SDRAM and load U-Boot
>> directly to SDRAM, so relocation is useless and time consuming.
> You are wrong.  relocation is not useless, even in your case.  there
> are quite a number of configuration options that will put stuff above
> the U-Boot image, directly at the end of RAM (things like protected
> RAM, shared frame buffer, shared log buffer, etc.).  In these cases,
> the relocation address may even be dynamic (i. e. depending on
> settings of environment variables, and thus unknown at compile time).
>> Now I'm using latest git version and this isn't working anymore.
>> Can someone explain me way? And what is the suggested way to skip
>> relocation now.
> Don't.

Got your point ;-)
I'm asking that since I'm digging on ARM SDRAM configuration and found a 
bug on getting top of SDRAM (where u-boot will be relocated).

On ARM architectures top of SDRAM will always be:

CONFIG_SYS_SDRAM_BASE + gd->ram_size

anyway this can be wrong since SDRAM can be composed by more that one 
bank in not-contiguous address space.
(CONFIG_SYS_SDRAM_BASE + gd->ram_size) can land to not existent SDRAM 
addresses and can be very dangerous since it can potentially corrupt 
real SDRAM (in most cases SDRAM is aliased so writing to some 
not-existent address can write to real address).

My proposed patch is something like this:

if (n banks > 2) and they are not contiguous, relocate u-boot at the end 
of 2nd bank even if there are more than 2 banks.

Please suggest me if this is the right way to follow or suggest me some 
more appropriate way to correct this bug
Thanks again
Luca Ellero


diff --git a/arch/arm/lib/board.c b/arch/arm/lib/board.c
index cfe32cc..7525caf 100644
--- a/arch/arm/lib/board.c
+++ b/arch/arm/lib/board.c
@@ -333,7 +333,18 @@  void board_init_f(ulong bootflag)
  	gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE;

+#if defined(PHYS_SDRAM_2) && defined(PHYS_SDRAM_2_SIZE)
+	if ( CONFIG_NR_DRAM_BANKS > 1 &&
+		addr =  PHYS_SDRAM_2 + PHYS_SDRAM_2_SIZE;
+	else
+		addr = CONFIG_SYS_SDRAM_BASE + gd->ram_size;
  	addr = CONFIG_SYS_SDRAM_BASE + gd->ram_size;


I know that some arch use more than 2 banks but implementing all macros 
checks to PHYS_SDRAM_* leads to some macro hell. So the point here is: