diff --git a/Makefile b/Makefile index 6ce1c777..9bd6f9b3 100644 --- a/Makefile +++ b/Makefile @@ -66,6 +66,10 @@ $(OUT)%.o: %.c $(OUT)autoconf.h $(OUT)board-link @echo " Compiling $@" $(Q)$(CC) $(CFLAGS) -c $< -o $@ +$(OUT)%.ld: %.lds.S $(OUT)board-link + @echo " Preprocessing $@" + $(Q)$(CPP) -I$(OUT) -P -MD -MT $@ $< -o $@ + ################ Main build rules $(OUT)board-link: $(KCONFIG_CONFIG) diff --git a/src/atsamd/Makefile b/src/atsamd/Makefile index 2ed3a6b4..8bc4d378 100644 --- a/src/atsamd/Makefile +++ b/src/atsamd/Makefile @@ -14,7 +14,9 @@ CFLAGS-$(CONFIG_MACH_SAMD51) += -mcpu=cortex-m4 -Ilib/samd51/samd51a/include CFLAGS-$(CONFIG_MACH_SAMD51) += -mfpu=fpv4-sp-d16 -mfloat-abi=hard CFLAGS += $(CFLAGS-y) -D__$(MCU)__ -mthumb -Ilib/cmsis-core -CFLAGS_klipper.elf += -T $(OUT)samd.ld --specs=nano.specs --specs=nosys.specs +CFLAGS_klipper.elf += --specs=nano.specs --specs=nosys.specs +CFLAGS_klipper.elf += -T $(OUT)src/atsamd/samd.ld +$(OUT)klipper.elf: $(OUT)src/atsamd/samd.ld # Add source files src-y += atsamd/main.c atsamd/gpio.c generic/crc16_ccitt.c generic/armcm_irq.c @@ -32,15 +34,6 @@ src-$(CONFIG_MACH_SAMD51) += atsamd/samd51_watchdog.c src-$(CONFIG_MACH_SAMD51) += atsamd/samd51_clock.c generic/armcm_timer.c src-$(CONFIG_MACH_SAMD51) += ../lib/samd51/samd51a/gcc/gcc/startup_samd51.c -# Support bootloader offset address -target-y := $(target-y) - -$(OUT)samd.ld: src/atsamd/samd.lds.S $(OUT)board-link - @echo " Preprocessing $@" - $(Q)$(CPP) -I$(OUT) -P -MD -MT $@ $< -o $@ - -$(OUT)klipper.elf: $(OUT)samd.ld - # Build the additional hex and bin output files target-y += $(OUT)klipper.bin $(OUT)klipper.elf.hex diff --git a/src/stm32/Makefile b/src/stm32/Makefile index f7df2a4d..016c281e 100644 --- a/src/stm32/Makefile +++ b/src/stm32/Makefile @@ -13,9 +13,11 @@ MCU_UPPER := $(shell echo $(CONFIG_MCU) | tr a-z A-Z | tr X x) CFLAGS-$(CONFIG_MACH_STM32F1) += -mcpu=cortex-m3 -Ilib/stm32f1/include CFLAGS-$(CONFIG_MACH_STM32F4) += -mcpu=cortex-m4 -Ilib/stm32f4/include CFLAGS-$(CONFIG_MACH_STM32F4) += -mfpu=fpv4-sp-d16 -mfloat-abi=hard - CFLAGS += $(CFLAGS-y) -D$(MCU_UPPER) -mthumb -Ilib/cmsis-core -CFLAGS_klipper.elf += -T $(OUT)stm32.ld --specs=nano.specs --specs=nosys.specs + +CFLAGS_klipper.elf += --specs=nano.specs --specs=nosys.specs +CFLAGS_klipper.elf += -T $(OUT)src/stm32/stm32.ld +$(OUT)klipper.elf: $(OUT)src/stm32/stm32.ld # Add source files src-y += stm32/main.c stm32/watchdog.c stm32/gpio.c @@ -41,12 +43,6 @@ asmsrc-$(CONFIG_MACH_STM32F1) := ../lib/stm32f1/gcc/startup_$(MCU).s asmsrc-$(CONFIG_MACH_STM32F4) := ../lib/stm32f4/gcc/startup_$(MCU).s OBJS_klipper.elf += $(patsubst %.s, $(OUT)src/%.o,$(asmsrc-y)) -# Build the linker script -$(OUT)stm32.ld: src/stm32/stm32.lds.S $(OUT)board-link - @echo " Preprocessing $@" - $(Q)$(CPP) -I$(OUT) -P -MD -MT $@ $< -o $@ -$(OUT)klipper.elf: $(OUT)stm32.ld - # Binary output file rules target-y += $(OUT)klipper.bin @@ -54,6 +50,7 @@ $(OUT)klipper.bin: $(OUT)klipper.elf @echo " Creating hex file $@" $(Q)$(OBJCOPY) -O binary $< $@ +# Flash rules FLASH_TYPE-$(CONFIG_MACH_STM32F1) := stm32f1 FLASH_TYPE-$(CONFIG_MACH_STM32F4) := stm32f4