Commit ab83de31 authored by Hugo Grostabussiat's avatar Hugo Grostabussiat

Fix various Makefile and ldscript issues

1) Compile all the C files using the same compiler options

Some C files were compiled in the recipe to link the final .elf, while
the others were compiled using make implicit rules. This caused all the
.o files specified in the OBJS variable to be compiled without the
-fno-zero-initialized-in-bss option, potentially leading to the use of
uninitialized memory.

This commit puts all the C-compiler-specific options in the CFLAGS
variable, as well as clearly separating the compilation and linking
phases, relying on implicit make rules for the compilation part.

2) Explcitly put the output of m4_start.S first in the output .elf

The .text section of m4_start.o was output at the lowest address only
because the file was placed first in the OBJS variable.

This commit changes the ldscript to always place the .text section of
m4_start.o first in the output, no matter the order of the input files
on the command line.

3) Move all data in .bss sections into the .data section

Since the final .elf is linked with -nostartfiles, the .bss section is
not initialized, causing code expecting data to be initialized to 0 to
use uninitialized memory.

This commit changes the ldscript to put the common symbols, which were
previously put in the .bss section, in the .data section to ensure the
data is initialized. This has the side-effect of allocating the space
for that data in the binary, increasing its size by 54 bytes.

4) Group all common linker options in the LDFLAGS variable

Most linker options were duplicated in the recipes for m4_tcm.elf and
m4_ocram.elf.

This commit puts all the common linker options in the LDFLAGS variable
for the sake of clarity, in addition to other minor cosmetic changes.
parent 82a75144
CC = arm-none-eabi-gcc
OBJCOPY = arm-none-eabi-objcopy
# AFLAGS = -nostdinc -nostdlib
# CFLAGS = -nostdinc -nostdlib -W -Wall
CFLAGS += -g
CFLAGS += -march=armv7e-m -mthumb
AFLAGS += -march=armv7e-m -mthumb
OBJS = m4_start.o m4_main.o iomux-v3.o ddr_loader.o gpio.o timer.o uart.o usdhc.c spi.c
CFLAGS += -g
CFLAGS += -march=armv7e-m -mthumb -mcpu=cortex-m4 \
-mlittle-endian -mfloat-abi=softfp \
-fno-zero-initialized-in-bss
LDFLAGS := -T ldscript -nostartfiles -Wl,-Map,m4.map,--cref,-n
OBJS := m4_start.o \
m4_main.o \
iomux-v3.o \
ddr_loader.o \
gpio.o \
timer.o \
uart.o \
usdhc.o \
spi.o
all: m4.bin
......@@ -15,10 +24,10 @@ m4.bin: m4_ocram.elf
${OBJCOPY} -O binary $^ m4.bin
m4_tcm.elf: $(OBJS)
${CC} $(CXXFLAGS) -o $@ $^ -fno-zero-initialized-in-bss -mcpu=cortex-m4 -mfloat-abi=softfp -mthumb -mlittle-endian -T ldscript -nostartfiles -Wl,-Map,m4.map,--cref,-n
${CC} $(CXXFLAGS) -o $@ $^ $(LDFLAGS)
m4_ocram.elf: $(OBJS)
${CC} $(CXXFLAGS) -g -o $@ $^ -fno-zero-initialized-in-bss -mcpu=cortex-m4 -mfloat-abi=softfp -mthumb -mlittle-endian -T ldscript -nostartfiles -Wl,-Ttext,0x00900000,-Map,m4.map,--cref,-n
${CC} $(CXXFLAGS) -g -o $@ $^ $(LDFLAGS) -Wl,-Ttext,0x00900000
clean:
rm -f *.o m4.bin m4_ocram.elf m4_tcm.elf m4.map
......
......@@ -3,20 +3,16 @@ SECTIONS
{
.text :
{
*(.text)
*(.text.*)
*m4_start.o(.text)
*(.text .text.*)
}
. = ALIGN(32);
.data :
{
*(.data .data.* COMMON)
}
. = ALIGN(32);
.sbss :
{
}
. = ALIGN(32);
.bss :
.rodata :
{
*(.rodata .rodata.*)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment