[U-Boot] [PATCH] arm: Allow u-boot to run from offset base address

Wolfgang Denk
2014-06-11T04:38:06Z

Dear Albert,

In message <E1WuTT8-0007AF-9l@janus> you wrote:
>
> 1. A typical ARM binary image is linked to a base address, defined by
> preprocessor macro (aka U-Boot config option) CONFIG_SYS_TEXT_BASE.

We shoul specifically keep in mind here that the "base address" is
defined as the start address of the text segment, which may or may not
be the same as the entry point address _start. In general, these are
not the same.

> 2. A typical ARM target defines CONFIG_SYS_TEXT_BASE so that the image,
> and especially its exception vectors table, is properly aligned upon
> loading the image in RAM.
>
> 3. When the ARM image relocates itself, it does so to a destination
> address which is computed so that the image and its vectors table
> are still properly aligned after relocation.

These items are not ARM specific.

> 4. Some targets require that the image stored in MMC be prepended with
> a 32-byte header (and aligned to a sector-related boundary).

Why would such headers have to be part of the text segment?

> 5. For some targets (if not all) the header is not separate from the
> image, i.e., it will also be copied from MMC to RAM. Such headers
> must be prepended at the link stage or earlier, so that the
> link-time and run-time values of all image symbols are consistent.

If the headers are in their own segment, this should be trivial.

> 6. However, because the header is put at the start of the image before
> the vectors table, the image is still properly aligned but th
> vectors tabled is not any more, both when the image is loaded from
> MMC to RAM, and when it is relocated.

This would be a bug, then. If we have an alignment requirement for
the text segment, and we load other data (or code) in front of the
text segment, then the size of such additional data must be made such
that the text segment is still properly aligned. Usually I would
expect that the heaer is in a separate segment, and the linker script
would take care of the required alignment for the text segment and
insert the necessary gap to keep it properly aligned.

> Instead of prepending a 32-byte header to the image, prepend the header
> then a block of 2048-32 bytes. This way, the MMC image base address
> (the header address) is aligned, and the alignment of any address in
> the image itself is preserved.

Agreed. Or should .text be aligned on a 4 k boundary?

Best regards,

Wolfgang Denk

--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
I used to be indecisive, now I'm not sure.