[U-Boot] Question about relocation

Alessandro Rubini
2011-04-18T09:16:56Z

Me:
>> but the calculation is done to move to end of ram, so dest is always
>> higher than source.

Albert:
> I guess I can live with this if you put a big fat comment in the code to
> explain *why* the copy is done end-to-beginning, so that if one day the
> assumption stops holding, readers of the code can tell if they should
> keep or change the direction.

Actually, I was wrong. Since the display buffer is allocated over
u-boot, we may already be too high. This never happens for current
boards, which lived before relocation was there (I rember having
lowered the u-boot address to fit a bigger display buffer above it)
but may happen in the future.

So, with the comment the thing may work (like "please for new boards
load it low now that it relocates high by itself").

However, the copy is made in 35 assembly files. Only ARM has 14
almost-identical copies of the code (some of them are really
identical), so I won't dare touching it.

The only thing I can do is not making the copy by forcing dest =
source if we will overlap ourselves, because the assembly will detect
this:

adr r0, _start
cmp r0, r6
beq clear_bss /* skip relocation */

[I don't understand why here is _start and in C is _TEXT_BASE, which
are different by 0x40 bytes, but it unexpectedly works]

For me it is working, but the code is not clean at all. I'm sending
the patches anyways. I found the the overwrite was only for the
stack, which is the lowest address in the relocated place, so I
compared some space below the would-be stack with bss_start.

/alessandro