diff --git a/ld/devices.data b/ld/devices.data index c86f1165..30797b58 100644 --- a/ld/devices.data +++ b/ld/devices.data @@ -333,75 +333,63 @@ sam3xnfc sam3x NFCRAM=4K NFCRAM_OFF=0x20100000 # the lpc family groups -lpc13u lpc13 USBRAM_OFF=0x20004000 +lpc13u lpc13xx USBRAM_OFF=0x20004000 -lpc17[56]x lpc17 RAM1_OFF=0x2007C000 RAM2_OFF=0x20080000 -lpc17[78]x lpc17 RAM1_OFF=0x20000000 RAM2_OFF=0x20040000 +lpc17[56]x lpc17xx RAM1_OFF=0x2007C000 RAM2_OFF=0x20080000 +lpc17[78]x lpc17xx RAM1_OFF=0x20000000 RAM2_OFF=0x20040000 ################################################################################ ################################################################################ ################################################################################ # the STM32 families -stm32f0 stm32 ROM_OFF=0x08000000 RAM_OFF=0x20000000 -mcpu=cortex-m0 -mthumb -DSTM32F0 -lopencm3_stm32f0 -msoft-float -stm32f1 stm32 ROM_OFF=0x08000000 RAM_OFF=0x20000000 -mcpu=cortex-m3 -mthumb -DSTM32F1 -lopencm3_stm32f1 -msoft-float -stm32f2 stm32 ROM_OFF=0x08000000 RAM_OFF=0x20000000 -mcpu=cortex-m3 -mthumb -DSTM32F2 -lopencm3_stm32f2 -msoft-float -stm32f3 stm32 ROM_OFF=0x08000000 RAM_OFF=0x20000000 -mcpu=cortex-m4 -mthumb -DSTM32F3 -lopencm3_stm32f3 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -stm32f4 stm32 ROM_OFF=0x08000000 RAM_OFF=0x20000000 -mcpu=cortex-m4 -mthumb -DSTM32F4 -lopencm3_stm32f4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 +stm32f0 END ROM_OFF=0x08000000 RAM_OFF=0x20000000 CPU=cortex-m0 FPU=soft +stm32f1 END ROM_OFF=0x08000000 RAM_OFF=0x20000000 CPU=cortex-m3 FPU=soft +stm32f2 END ROM_OFF=0x08000000 RAM_OFF=0x20000000 CPU=cortex-m3 FPU=soft +stm32f3 END ROM_OFF=0x08000000 RAM_OFF=0x20000000 CPU=cortex-m4 FPU=hard-fpv4-sp-d16 +stm32f4 END ROM_OFF=0x08000000 RAM_OFF=0x20000000 CPU=cortex-m4 FPU=hard-fpv4-sp-d16 #stm32f7 is supported on GCC-arm-embedded 4.8 2014q4 -stm32f7 stm32 ROM_OFF=0x08000000 RAM_OFF=0x20010000 -mcpu=cortex-m7 -mthumb -DSTM32F7 -lopencm3_stm32f7 -mfloat-abi=hard -mfpu=fpv5-sp-d16 -stm32l0 stm32 ROM_OFF=0x08000000 RAM_OFF=0x20000000 -mcpu=cortex-m0plus -mthumb -DSTM32L0 -lopencm3_stm32l0 -msoft-float -stm32l1 stm32 ROM_OFF=0x08000000 RAM_OFF=0x20000000 -mcpu=cortex-m3 -mthumb -DSTM32L1 -lopencm3_stm32l1 -msoft-float -stm32l4 stm32 ROM_OFF=0x08000000 RAM_OFF=0x20000000 -mcpu=cortex-m4 -mthumb -DSTM32L4 -lopencm3_stm32l4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -stm32w stm32 ROM_OFF=0x08000000 RAM_OFF=0x20000000 -mcpu=cortex-m3 -mthumb -stm32t stm32 ROM_OFF=0x08000000 RAM_OFF=0x20000000 -mcpu=cortex-m3 -mthumb +stm32f7 END ROM_OFF=0x08000000 RAM_OFF=0x20010000 CPU=cortex-m7 FPU=hard-fpv5-sp-d16 +stm32l0 END ROM_OFF=0x08000000 RAM_OFF=0x20000000 CPU=cortex-m0plus FPU=soft +stm32l1 END ROM_OFF=0x08000000 RAM_OFF=0x20000000 CPU=cortex-m3 FPU=soft +stm32l4 END ROM_OFF=0x08000000 RAM_OFF=0x20000000 CPU=cortex-m4 FPU=hard-fpv4-sp-d16 +stm32w END ROM_OFF=0x08000000 RAM_OFF=0x20000000 CPU=cortex-m3 FPU=soft +stm32t END ROM_OFF=0x08000000 RAM_OFF=0x20000000 CPU=cortex-m3 FPU=soft ################################################################################ # the SAM3 families -sam3a sam3 ROM_OFF=0x00080000 RAM_OFF=0x20000000 RAM1_OFF=0x20080000 -sam3n sam3 ROM_OFF=0x00400000 RAM_OFF=0x20000000 -sam3s sam3 ROM_OFF=0x00400000 RAM_OFF=0x20000000 -sam3u sam3 ROM_OFF=0x00080000 RAM_OFF=0x20000000 RAM1_OFF=0x20080000 NFCRAM=4K NFCRAM_OFF=0x20100000 -sam3x sam3 ROM_OFF=0x00080000 RAM_OFF=0x20000000 RAM1_OFF=0x20080000 +sam3a END ROM_OFF=0x00080000 RAM_OFF=0x20000000 RAM1_OFF=0x20080000 CPU=cortex-m3 FPU=soft +sam3n END ROM_OFF=0x00400000 RAM_OFF=0x20000000 CPU=cortex-m3 FPU=soft +sam3s END ROM_OFF=0x00400000 RAM_OFF=0x20000000 CPU=cortex-m3 FPU=soft +sam3u END ROM_OFF=0x00080000 RAM_OFF=0x20000000 RAM1_OFF=0x20080000 NFCRAM=4K NFCRAM_OFF=0x20100000 CPU=cortex-m3 FPU=soft +sam3x END ROM_OFF=0x00080000 RAM_OFF=0x20000000 RAM1_OFF=0x20080000 CPU=cortex-m3 FPU=soft ################################################################################ # the lpc families -lpc13 lpc ROM_OFF=0x00000000 RAM_OFF=0x10000000 RAM1_OFF=0x20000000 -lpc17 lpc ROM_OFF=0x00000000 RAM_OFF=0x10000000 +lpc13xx END ROM_OFF=0x00000000 RAM_OFF=0x10000000 RAM1_OFF=0x20000000 CPU=cortex-m3 FPU=soft +lpc17xx END ROM_OFF=0x00000000 RAM_OFF=0x10000000 CPU=cortex-m3 FPU=soft ################################################################################ # the efm32 Gecko families -efm32zg efm32 ROM_OFF=0x00000000 RAM_OFF=0x20000000 RAM1_OFF=0x10000000 -efm32tg efm32 ROM_OFF=0x00000000 RAM_OFF=0x20000000 RAM1_OFF=0x10000000 -efm32g efm32 ROM_OFF=0x00000000 RAM_OFF=0x20000000 RAM1_OFF=0x10000000 -efm32lg efm32 ROM_OFF=0x00000000 RAM_OFF=0x20000000 RAM1_OFF=0x10000000 -efm32gg efm32 ROM_OFF=0x00000000 RAM_OFF=0x20000000 RAM1_OFF=0x10000000 -efm32wg efm32 ROM_OFF=0x00000000 RAM_OFF=0x20000000 RAM1_OFF=0x10000000 +efm32zg END ROM_OFF=0x00000000 RAM_OFF=0x20000000 RAM1_OFF=0x10000000 CPU=cortex-m0plus FPU=soft +efm32tg END ROM_OFF=0x00000000 RAM_OFF=0x20000000 RAM1_OFF=0x10000000 CPU=cortex-m3 FPU=soft +efm32g END ROM_OFF=0x00000000 RAM_OFF=0x20000000 RAM1_OFF=0x10000000 CPU=cortex-m3 FPU=soft +efm32lg END ROM_OFF=0x00000000 RAM_OFF=0x20000000 RAM1_OFF=0x10000000 CPU=cortex-m3 FPU=soft +efm32gg END ROM_OFF=0x00000000 RAM_OFF=0x20000000 RAM1_OFF=0x10000000 CPU=cortex-m3 FPU=soft +efm32wg END ROM_OFF=0x00000000 RAM_OFF=0x20000000 RAM1_OFF=0x10000000 CPU=cortex-m4 FPU=hard-fpv4-sp-d16 ################################################################################ # Cortex LM3 families -lm3fury lm3 ROM_OFF=0x00000000 RAM_OFF=0x20000000 -lm3sandstorm lm3 ROM_OFF=0x00000000 RAM_OFF=0x20000000 +lm3fury lm3s +lm3sandstorm lm3s +lm3s END ROM_OFF=0x00000000 RAM_OFF=0x20000000 CPU=cortex-m3 FPU=soft ################################################################################ # Cortex R4F families -rm46l rm4 ROM_OFF=0x00000000 RAM_OFF=0x08000000 RAM1_OFF=0x08400000 - -################################################################################ -################################################################################ -################################################################################ -# the architectures - -stm32 END -sam3 END -lpc END -efm32 END -lm3 END -rm4 END - +rm46l END ROM_OFF=0x00000000 RAM_OFF=0x08000000 RAM1_OFF=0x08400000 diff --git a/mk/README b/mk/README index cb792c3d..87e37e01 100644 --- a/mk/README +++ b/mk/README @@ -15,34 +15,31 @@ where you are defining variables (near the beginning of the file), and file -rules.mk should be included in the rules part of makefile (somewhere near to the end of file). -Example makefile using gcc compiler module: +Example makefile using the gcc compiler module together with the linker script +generator module: >>>>>> -OBJS += foo.o bar.o +DEVICE = +OPENCM3_DIR = +OBJS += foo.o -CFLAGS += -O0 -g -CPPFLAGS += -MD -MP $(@F).d -CPPFLAGS += $(DEFS) -CPPFLAGS += $(INCS) -LDFLAGS += --static --nostartfiles -LDLIBS += -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group -# parameters for gcc module -PREFIX = arm-elf +CFLAGS += -Os -ggdb3 +CPPFLAGS += -MD +LDFLAGS += -static -nostartfiles +LDLIBS += -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group +include $(OPENCM3_DIR)/mk/genlink-config.mk include $(OPENCM3_DIR)/mk/gcc-config.mk .PHONY: clean all -all: binary.images - -%.images: %.elf %.hex - -include $(OPENCM3_DIR)/mk/gcc-rules.mk +all: binary.elf binary.hex clean: - $(Q)$(RM) -rf binary.* *.o *.d + $(Q)$(RM) -rf binary.* *.o --include $(OBJS:.o=.d) +include $(OPENCM3_DIR)/mk/genlink-rules.mk +include $(OPENCM3_DIR)/mk/gcc-rules.mk <<<<<< @@ -81,7 +78,8 @@ genlink This module adds an support for the user to the linker script generator. The linker script will be generated as the file $(DEVICE).ld in the project folder, -and automatically used for the linking process. +and automatically be used for the linking process. +Additionally the matching library is added to the LDLIBS variable. Variables to control the build process (should be set in your makefile): ------------------------------------------------------------------------ @@ -92,9 +90,9 @@ OPENCM3_DIR The root path of libopencm3 library. Output variables from this module: ---------------------------------- -DEFS (appended) - - Appended definitions specified in chip database file. - ! Ensure that you have line 'CPPFLAGS += $(DEFS)' in your makefile. +CPPFLAGS (appended) + - Appends the chip family to the CPPFLAGS. For example -DSTM32F1 + - Appends the include path for libopencm3 ARCH_FLAGS (replaced) - Architecture build flags for specified chip. @@ -104,12 +102,16 @@ LDSCRIPT (replaced) - Linker script generated file. * No needed to handle this variable if you use module too. -OPENCM3_LIBNAME (replaced) - - The right libopencm3 library base name to be linked with. - ! Ensure that you have line 'LDLIBS += -l$(OPENCM3_LIBNAME)' in your makefile. - ! Ensure that you have line 'LDFLAGS += -L$(OPENCM3_DIR)/lib' in your makefile. - ! Ensure that you have rule '$(OPENCM3_DIR)/lib/lib$(OPENCM3_LIBNAME).a:' - to be the library archive successfully built when needed. +LDLIBS (appended) + - LDLIBS += -lopencm3_$(family) is appended to link against the + matching library. + +LDFLAGS (appended) + - LDFLAGS += -L$(OPENCM3_DIR)/lib is appended to make sure the + matching library can be found. + +family,cpu,fpu (replaced) + - these are used internally to create the above variables Temporary variables that you should not use in your makefile: ------------------------------------------------------------- diff --git a/mk/genlink-config.mk b/mk/genlink-config.mk index 69949344..5c2367f6 100644 --- a/mk/genlink-config.mk +++ b/mk/genlink-config.mk @@ -18,17 +18,62 @@ ## ifeq ($(DEVICE),) -$(error no DEVICE specified for linker script generator) +$(warning no DEVICE specified for linker script generator) endif LDSCRIPT = $(DEVICE).ld +DEVICES_DATA = $(OPENCM3_DIR)/ld/devices.data -GENLINK_DEFS :=$(shell awk -v PAT="$(DEVICE)" -v MODE="DEFS" -f $(OPENCM3_DIR)/scripts/genlink.awk $(OPENCM3_DIR)/ld/devices.data 2>/dev/null) -GENLINK_ARCH :=$(shell awk -v PAT="$(DEVICE)" -v MODE="ARCH" -f $(OPENCM3_DIR)/scripts/genlink.awk $(OPENCM3_DIR)/ld/devices.data 2>/dev/null) -GENLINK_LIB :=$(shell awk -v PAT="$(DEVICE)" -v MODE="LIB" -f $(OPENCM3_DIR)/scripts/genlink.awk $(OPENCM3_DIR)/ld/devices.data 2>/dev/null) +genlink_family :=$(shell awk -v PAT="$(DEVICE)" -v MODE="FAMILY" -f $(OPENCM3_DIR)/scripts/genlink.awk $(DEVICES_DATA) 2>/dev/null) +genlink_subfamily :=$(shell awk -v PAT="$(DEVICE)" -v MODE="SUBFAMILY" -f $(OPENCM3_DIR)/scripts/genlink.awk $(DEVICES_DATA) 2>/dev/null) +genlink_cpu :=$(shell awk -v PAT="$(DEVICE)" -v MODE="CPU" -f $(OPENCM3_DIR)/scripts/genlink.awk $(DEVICES_DATA) 2>/dev/null) +genlink_fpu :=$(shell awk -v PAT="$(DEVICE)" -v MODE="FPU" -f $(OPENCM3_DIR)/scripts/genlink.awk $(DEVICES_DATA) 2>/dev/null) +genlink_cppflags :=$(shell awk -v PAT="$(DEVICE)" -v MODE="CPPFLAGS" -f $(OPENCM3_DIR)/scripts/genlink.awk $(DEVICES_DATA) 2>/dev/null) -DEFS += $(GENLINK_DEFS) -ARCH_FLAGS := $(GENLINK_ARCH) -OPENCM3_LIBNAME := $(strip $(subst -l,,$(GENLINK_LIB))) +CPPFLAGS += $(genlink_cppflags) -GENFILES += $(LDSCRIPT) +ARCH_FLAGS :=-mcpu=$(genlink_cpu) +ifeq ($(genlink_cpu),$(filter $(genlink_cpu),cortex-m0 cortex-m0plus cortex-m3 cortex-m4 cortex-m7)) +ARCH_FLAGS +=-mthumb +endif + +ifeq ($(genlink_fpu),soft) +ARCH_FLAGS += -msoft-float +else ifeq ($(genlink_fpu),hard-fpv4-sp-d16) +ARCH_FLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 +else ifeq ($(genlink_fpu),hard-fpv5-sp-d16) +ARCH_FLAGS += -mfloat-abi=hard -mfpu=fpv5-sp-d16 +else +$(warning No match for the FPU flags) +endif + + +ifeq ($(genlink_family),) +$(warning $(DEVICE) not found in $(DEVICES_DATA)) +endif + +# only append to LDFLAGS if the library file exists to not break builds +# where those are provided by different means +ifneq (,$(wildcard $(OPENCM3_DIR)/lib/libopencm3_$(genlink_family).a)) +LDLIBS += -lopencm3_$(genlink_family) +else +ifneq (,$(wildcard $(OPENCM3_DIR)/lib/libopencm3_$(genlink_subfamily).a)) +LDLIBS += -lopencm3_$(genlink_subfamily) +else +$(warning $(OPENCM3_DIR)/lib/libopencm3_$(genlink_subfamily).a library variant for the selected device does not exist.) +endif +endif + +# only append to LDLIBS if the directory exists +ifneq (,$(wildcard $(OPENCM3_DIR)/lib)) +LDFLAGS += -L$(OPENCM3_DIR)/lib +else +$(warning $(OPENCM3_DIR)/lib as given be OPENCM3_DIR does not exist.) +endif + +# only append include path to CPPFLAGS if the directory exists +ifneq (,$(wildcard $(OPENCM3_DIR)/include)) +CPPFLAGS += -I$(OPENCM3_DIR)/include +else +$(warning $(OPENCM3_DIR)/include as given be OPENCM3_DIR does not exist.) +endif diff --git a/mk/genlink-rules.mk b/mk/genlink-rules.mk index 99bd1f38..6913d7e8 100644 --- a/mk/genlink-rules.mk +++ b/mk/genlink-rules.mk @@ -18,8 +18,5 @@ ## $(LDSCRIPT):$(OPENCM3_DIR)/ld/linker.ld.S -ifeq ($(GENLINK_DEFS),) - $(error unknown device $(DEVICE) for the linker. Cannot generate ldscript) -endif @printf " GENLNK $@\n" - $(Q)$(CPP) $(GENLINK_DEFS) -P -E $< > $@ + $(Q)$(CPP) $(ARCH_FLAGS) $(shell awk -v PAT="$(basename $@)" -v MODE="DEFS" -f $(OPENCM3_DIR)/scripts/genlink.awk $(OPENCM3_DIR)/ld/devices.data 2>/dev/null) -P -E $< > $@ diff --git a/scripts/genlink.awk b/scripts/genlink.awk index d2e03cf7..0eca62d6 100644 --- a/scripts/genlink.awk +++ b/scripts/genlink.awk @@ -39,27 +39,40 @@ BEGIN { if (PAT ~ tmp) { if ($2 != "+") PAT=$2; - - for (i = 3; i <= NF; i = i + 1) { - if ($i ~ /^-l/) { - if ("LIB" ~ MODE) - printf "%s ",$i; + for (i = 3; i <= NF; i = i + 1) { + if ($i ~ /^CPU=/) { + if ("CPU" ~ MODE){ + sub(/[^=]*=/,"",$i); + printf "%s",$i; + exit; + } } - else if ($i ~ /^-m/) { - if ("ARCH" ~ MODE) - printf "%s ",$i; + else if ($i ~ /^FPU=/) { + if ("FPU" ~ MODE){ + sub(/[^=]*=/,"",$i); + printf "%s",$i; + exit; + } } - else if ($i ~ /^-D/) { - if ("DEFS" ~ MODE) - printf "%s ",$i; - } - else { + else if ($i ~ /[[:upper:]]*=/) { if ("DEFS" ~ MODE) printf "-D_%s ",$i; } } - - if (PAT=="END") + if (PAT=="END"){ + if ("FAMILY" ~ MODE) + printf "%s",family; + else if ("SUBFAMILY" ~ MODE) + printf "%s",subfamily; exit; + } + else{ + subfamily = family; + family = PAT; + if ("CPPFLAGS" ~ MODE) + printf "-D%s ",toupper(PAT); + else if("DEFS" ~ MODE) + printf "-D%s ",toupper(PAT); + } } }