U-Boot on QEMU-arm64 can be used in two configurations: Loaded directly
via QEMU's -bios option, or as a non-secure payload (BL33) via
ARM Trusted Firmware-A (TF-A).
In the latter case we need to define CONFIG_TFABOOT, to accommodate
the first flash bank being secure only, and manually set SYS_TEXT_BASE
to the address configured in TF-A (currently 0x60000000).

To avoid this poorly documented adventure, we enable a position
independent build, and also let the flash regions be always detected
through the DTB. This results in a single build to work under both
scenarios, and also allows to move the BL33 load address in TF-A to
something lower in the future.

For this to work, we have to first make PIE work when booted from ROM.
While writing to ROM should not hurt, it might trigger CFI flash
sequences, and indeed crashes for me in the middle of the fixup routine.
This is covered by patch 1/5, which skips the whole fixup routine if the
offset is actually 0 (as it is in our case).
Also we have to decouple the relative initial stack pointer from the
PIE option, as we always need to use the fixed version, pointing to
RAM (patch 2/5).
Patch 3/5 drops the hard-coded flash address, instead U-Boot can already
read all required information from QEMU's DTB.
Patch 4/5 is a cleanup, while the last patch enables the PIE build.

With this series the very same u-boot.bin file works when directly loaded
from the QEMU command line (-bios), but also when embedded into TF-A's
fip.bin, removing the need for case-specific build options.

Please have a look!

Cheers,
Andre

Andre Przywara (5):
  arm64: PIE: Skip fixups if distance is zero
  arm64: PIE: Allow fixed stack pointer
  qemu-arm: Remove need to specify flash banks
  qemu: Drop ARCH_SUPPORT_TFABOOT
  qemu/arm64: Enable POSITION_INDEPENDENT

 arch/arm/Kconfig             | 4 ++--
 arch/arm/cpu/armv8/start.S   | 3 ++-
 configs/qemu_arm64_defconfig | 1 +
 include/configs/qemu-arm.h   | 8 +-------
 4 files changed, 6 insertions(+), 10 deletions(-)

-- 
2.17.5

Reply via email to