From cf84236724ed6ae20667d55f119d0b6829234932 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Tue, 12 Apr 2022 14:19:22 +0100 Subject: [PATCH] make hello_world relocatable with BOOT_INIT_BASE define --- hello_world/Makefile | 20 ++++++++++++++++---- hello_world/powerpc.lds.S | 16 ++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 hello_world/powerpc.lds.S diff --git a/hello_world/Makefile b/hello_world/Makefile index 230b265..180f7b9 100644 --- a/hello_world/Makefile +++ b/hello_world/Makefile @@ -5,21 +5,33 @@ ifneq ("$(ARCH)", "ppc64le") endif endif +BOOT_INIT_BASE ?= 0xf0000000 # at QSPI address +# BOOT_INIT_BASE ?= 0xff000000 # at ROM hi address (with coldboot firmware) +# BOOT_INIT_BASE ?= 0x0 # start at zero (usual) + CC = $(CROSS_COMPILE)gcc LD = $(CROSS_COMPILE)ld OBJCOPY = $(CROSS_COMPILE)objcopy -CFLAGS = -Os -g -Wall -std=c99 -mabi=elfv2 -msoft-float -mno-string -mno-multiple -mno-vsx -mno-altivec -mlittle-endian -fno-stack-protector -mstrict-align -ffreestanding -fdata-sections -ffunction-sections -I../include +CFLAGS = -Os -g -Wall -std=c99 -mabi=elfv2 -msoft-float -mno-string \ + -mno-multiple -mno-vsx -mno-altivec -mlittle-endian \ + -fno-stack-protector -mstrict-align -ffreestanding \ + -fdata-sections -ffunction-sections -I../include \ + -DBOOT_INIT_BASE=$(BOOT_INIT_BASE) + ASFLAGS = $(CFLAGS) -LDFLAGS = -T powerpc.lds +LDFLAGS = -static -nostdlib -T powerpc.lds --gc-sections all: hello_world.hex +powerpc.lds: powerpc.lds.S + $(CC) $(CFLAGS) -P -E powerpc.lds.S -o powerpc.lds + console.o: ../lib/console.c $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@ -hello_world.elf: hello_world.o head.o console.o - $(LD) $(LDFLAGS) -o $@ $^ +hello_world.elf: hello_world.o head.o console.o powerpc.lds + $(LD) $(LDFLAGS) -o $@ hello_world.o head.o console.o hello_world.bin: hello_world.elf $(OBJCOPY) -O binary $^ $@ diff --git a/hello_world/powerpc.lds.S b/hello_world/powerpc.lds.S new file mode 100644 index 0000000..06cae4c --- /dev/null +++ b/hello_world/powerpc.lds.S @@ -0,0 +1,16 @@ +SECTIONS +{ + . = BOOT_INIT_BASE; + _start = .; + start = _start; + . = BOOT_INIT_BASE; + .head : { + KEEP(*(.head)) + } + . = BOOT_INIT_BASE + 0x1000; + .text : { *(.text) } + . = BOOT_INIT_BASE + 0x1800; + .data : { *(.data) } + .bss : { *(.bss) } +} + -- 2.30.2