Commit e14ba8a57703457e31248eccd4959cead92e2063

Authored by Michal Simek
Committed by Tom Rini
1 parent 740370282e

arch: Add explicit linker script for u-boot-elf

Commit f4dc714aaa2d ("arm64: Turn u-boot.bin back into an ELF file after
relocate-rela")
introduce REMAKE_ELF option to recreate u-boot.elf from u-boot ->
u-boot.bin + DT -> u-boot.elf.

The best is to ilustrate it from make V=1 output
  cat u-boot-nodtb.bin dts/dt.dtb > u-boot-dtb.bin
  cp u-boot-dtb.bin u-boot.bin
aarch64-linux-gnu-objcopy -I binary -B aarch64 -O elf64-littleaarch64  u-boot.bin u-boot-elf.o
  aarch64-linux-gnu-ld.bfd u-boot-elf.o -o u-boot.elf --defsym="_start"=0x8000000 -Ttext=0x8000000

Last command has no explicit linker script passed that's why toolchain
internal linker script is used.
In Binutils 2.32 case it contains SIZEOF_HEADERS symbol which has changed
behavior by commit
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=64029e93683a266c38d19789e780f3748bd6a188
which result in situation that program headers has changed from
(xilinx_zynqmp_mini_defconfig)

Program Headers:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  LOAD           0x0000000000010000 0x00000000fffc0000 0x00000000fffc0000
                 0x0000000000018918 0x0000000000018918  RW     0x10000

to

Program Headers:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  LOAD           0x0000000000000000 0x00000000fffb0000 0x00000000fffb0000
                 0x0000000000028918 0x0000000000028918  RW     0x10000

Xilinx tools like XSDB or Bootgen are using program headers for loading ELF
to the right location and by above binutils change ELF is loaded to
incorrect location.

The patch is explicitly use u-boot-elf.lds (just cat now) for u-boot.elf
recreation which is called when REMAKE_ELF is setup.
By purpose u-boot-elf.lds doesn't contain OUTPUT_FORMAT/OUTPUT_ARCH to be
able to use by all archs.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
Tested-By: Álvaro Fernández Rojas <noltari@gmail.com>

Showing 4 changed files with 19 additions and 7 deletions Side-by-side Diff

... ... @@ -299,6 +299,11 @@
299 299 pointer values - up to 'MAX_ERRNO' bytes below this value must be
300 300 unused/invalid addresses.
301 301  
  302 +config PLATFORM_ELFENTRY
  303 + string
  304 + default "__start" if MIPS
  305 + default "_start"
  306 +
302 307 endmenu # General setup
303 308  
304 309 menu "Boot images"
... ... @@ -1647,17 +1647,16 @@
1647 1647 u-boot-img-spl-at-end.bin: u-boot.img spl/u-boot-spl.bin FORCE
1648 1648 $(call if_changed,pad_cat)
1649 1649  
1650   -# Create a new ELF from a raw binary file.
1651   -ifndef PLATFORM_ELFENTRY
1652   - PLATFORM_ELFENTRY = "_start"
1653   -endif
1654 1650 quiet_cmd_u-boot-elf ?= LD $@
1655 1651 cmd_u-boot-elf ?= $(LD) u-boot-elf.o -o $@ \
1656   - --defsym=$(PLATFORM_ELFENTRY)=$(CONFIG_SYS_TEXT_BASE) \
  1652 + -T u-boot-elf.lds --defsym=$(CONFIG_PLATFORM_ELFENTRY)=$(CONFIG_SYS_TEXT_BASE) \
1657 1653 -Ttext=$(CONFIG_SYS_TEXT_BASE)
1658   -u-boot.elf: u-boot.bin
  1654 +u-boot.elf: u-boot.bin u-boot-elf.lds
1659 1655 $(Q)$(OBJCOPY) -I binary $(PLATFORM_ELFFLAGS) $< u-boot-elf.o
1660 1656 $(call if_changed,u-boot-elf)
  1657 +
  1658 +u-boot-elf.lds: arch/u-boot-elf.lds prepare FORCE
  1659 + $(call if_changed_dep,cpp_lds)
1661 1660  
1662 1661 # MediaTek's ARM-based u-boot needs a header to contains its load address
1663 1662 # which is parsed by the BootROM.
... ... @@ -36,7 +36,6 @@
36 36 endif
37 37  
38 38 PLATFORM_CPPFLAGS += -D__MIPS__
39   -PLATFORM_ELFENTRY = "__start"
40 39 PLATFORM_ELFFLAGS += -B mips $(OBJCOPYFLAGS)
41 40  
42 41 #
  1 +ENTRY(CONFIG_PLATFORM_ELFENTRY)
  2 +SECTIONS
  3 +{
  4 + . = CONFIG_PLATFORM_ELFENTRY;
  5 +
  6 + .data : {
  7 + *(.data*)
  8 + }
  9 +}