mk/genlink: change devices.data format to remove gcc specific options

As discussed with karlp on irc the devices.data file should not contain
gcc specific command line options.

For that reason the command line options for gcc are now generated from
the variables CPU and FPU by the rules in the mk directory.

This breaks the genlink tests.

genlink: simplified devices.data

devices.data already had the information about the family name.
By using the first field (by the pattern used to match it) as family name information that data doesn't
have to be provided explicitly. The same data is used to generate the
CPPFLAGS, such as -DSTM32F1

The architectures block of the devices.data file was redundant.

genlink-config.mk uses family and subfamily to figure out which libopencm3
variant actually exists.
This commit is contained in:
Jonas Meyer 2016-02-06 02:03:57 +01:00 committed by Karl Palsson
parent 2db3d290e7
commit c025dc0327
5 changed files with 142 additions and 97 deletions

View File

@ -333,75 +333,63 @@ sam3xnfc sam3x NFCRAM=4K NFCRAM_OFF=0x20100000
# the lpc family groups # 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[56]x lpc17xx RAM1_OFF=0x2007C000 RAM2_OFF=0x20080000
lpc17[78]x lpc17 RAM1_OFF=0x20000000 RAM2_OFF=0x20040000 lpc17[78]x lpc17xx RAM1_OFF=0x20000000 RAM2_OFF=0x20040000
################################################################################ ################################################################################
################################################################################ ################################################################################
################################################################################ ################################################################################
# the STM32 families # the STM32 families
stm32f0 stm32 ROM_OFF=0x08000000 RAM_OFF=0x20000000 -mcpu=cortex-m0 -mthumb -DSTM32F0 -lopencm3_stm32f0 -msoft-float stm32f0 END ROM_OFF=0x08000000 RAM_OFF=0x20000000 CPU=cortex-m0 FPU=soft
stm32f1 stm32 ROM_OFF=0x08000000 RAM_OFF=0x20000000 -mcpu=cortex-m3 -mthumb -DSTM32F1 -lopencm3_stm32f1 -msoft-float stm32f1 END ROM_OFF=0x08000000 RAM_OFF=0x20000000 CPU=cortex-m3 FPU=soft
stm32f2 stm32 ROM_OFF=0x08000000 RAM_OFF=0x20000000 -mcpu=cortex-m3 -mthumb -DSTM32F2 -lopencm3_stm32f2 -msoft-float stm32f2 END ROM_OFF=0x08000000 RAM_OFF=0x20000000 CPU=cortex-m3 FPU=soft
stm32f3 stm32 ROM_OFF=0x08000000 RAM_OFF=0x20000000 -mcpu=cortex-m4 -mthumb -DSTM32F3 -lopencm3_stm32f3 -mfloat-abi=hard -mfpu=fpv4-sp-d16 stm32f3 END ROM_OFF=0x08000000 RAM_OFF=0x20000000 CPU=cortex-m4 FPU=hard-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 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 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 stm32f7 END ROM_OFF=0x08000000 RAM_OFF=0x20010000 CPU=cortex-m7 FPU=hard-fpv5-sp-d16
stm32l0 stm32 ROM_OFF=0x08000000 RAM_OFF=0x20000000 -mcpu=cortex-m0plus -mthumb -DSTM32L0 -lopencm3_stm32l0 -msoft-float stm32l0 END ROM_OFF=0x08000000 RAM_OFF=0x20000000 CPU=cortex-m0plus FPU=soft
stm32l1 stm32 ROM_OFF=0x08000000 RAM_OFF=0x20000000 -mcpu=cortex-m3 -mthumb -DSTM32L1 -lopencm3_stm32l1 -msoft-float stm32l1 END ROM_OFF=0x08000000 RAM_OFF=0x20000000 CPU=cortex-m3 FPU=soft
stm32l4 stm32 ROM_OFF=0x08000000 RAM_OFF=0x20000000 -mcpu=cortex-m4 -mthumb -DSTM32L4 -lopencm3_stm32l4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 stm32l4 END ROM_OFF=0x08000000 RAM_OFF=0x20000000 CPU=cortex-m4 FPU=hard-fpv4-sp-d16
stm32w stm32 ROM_OFF=0x08000000 RAM_OFF=0x20000000 -mcpu=cortex-m3 -mthumb stm32w END ROM_OFF=0x08000000 RAM_OFF=0x20000000 CPU=cortex-m3 FPU=soft
stm32t stm32 ROM_OFF=0x08000000 RAM_OFF=0x20000000 -mcpu=cortex-m3 -mthumb stm32t END ROM_OFF=0x08000000 RAM_OFF=0x20000000 CPU=cortex-m3 FPU=soft
################################################################################ ################################################################################
# the SAM3 families # the SAM3 families
sam3a 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 sam3 ROM_OFF=0x00400000 RAM_OFF=0x20000000 sam3n END ROM_OFF=0x00400000 RAM_OFF=0x20000000 CPU=cortex-m3 FPU=soft
sam3s sam3 ROM_OFF=0x00400000 RAM_OFF=0x20000000 sam3s END ROM_OFF=0x00400000 RAM_OFF=0x20000000 CPU=cortex-m3 FPU=soft
sam3u sam3 ROM_OFF=0x00080000 RAM_OFF=0x20000000 RAM1_OFF=0x20080000 NFCRAM=4K NFCRAM_OFF=0x20100000 sam3u END ROM_OFF=0x00080000 RAM_OFF=0x20000000 RAM1_OFF=0x20080000 NFCRAM=4K NFCRAM_OFF=0x20100000 CPU=cortex-m3 FPU=soft
sam3x sam3 ROM_OFF=0x00080000 RAM_OFF=0x20000000 RAM1_OFF=0x20080000 sam3x END ROM_OFF=0x00080000 RAM_OFF=0x20000000 RAM1_OFF=0x20080000 CPU=cortex-m3 FPU=soft
################################################################################ ################################################################################
# the lpc families # the lpc families
lpc13 lpc ROM_OFF=0x00000000 RAM_OFF=0x10000000 RAM1_OFF=0x20000000 lpc13xx END ROM_OFF=0x00000000 RAM_OFF=0x10000000 RAM1_OFF=0x20000000 CPU=cortex-m3 FPU=soft
lpc17 lpc ROM_OFF=0x00000000 RAM_OFF=0x10000000 lpc17xx END ROM_OFF=0x00000000 RAM_OFF=0x10000000 CPU=cortex-m3 FPU=soft
################################################################################ ################################################################################
# the efm32 Gecko families # the efm32 Gecko families
efm32zg 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 efm32 ROM_OFF=0x00000000 RAM_OFF=0x20000000 RAM1_OFF=0x10000000 efm32tg END ROM_OFF=0x00000000 RAM_OFF=0x20000000 RAM1_OFF=0x10000000 CPU=cortex-m3 FPU=soft
efm32g efm32 ROM_OFF=0x00000000 RAM_OFF=0x20000000 RAM1_OFF=0x10000000 efm32g END ROM_OFF=0x00000000 RAM_OFF=0x20000000 RAM1_OFF=0x10000000 CPU=cortex-m3 FPU=soft
efm32lg efm32 ROM_OFF=0x00000000 RAM_OFF=0x20000000 RAM1_OFF=0x10000000 efm32lg END ROM_OFF=0x00000000 RAM_OFF=0x20000000 RAM1_OFF=0x10000000 CPU=cortex-m3 FPU=soft
efm32gg efm32 ROM_OFF=0x00000000 RAM_OFF=0x20000000 RAM1_OFF=0x10000000 efm32gg END ROM_OFF=0x00000000 RAM_OFF=0x20000000 RAM1_OFF=0x10000000 CPU=cortex-m3 FPU=soft
efm32wg efm32 ROM_OFF=0x00000000 RAM_OFF=0x20000000 RAM1_OFF=0x10000000 efm32wg END ROM_OFF=0x00000000 RAM_OFF=0x20000000 RAM1_OFF=0x10000000 CPU=cortex-m4 FPU=hard-fpv4-sp-d16
################################################################################ ################################################################################
# Cortex LM3 families # Cortex LM3 families
lm3fury lm3 ROM_OFF=0x00000000 RAM_OFF=0x20000000 lm3fury lm3s
lm3sandstorm lm3 ROM_OFF=0x00000000 RAM_OFF=0x20000000 lm3sandstorm lm3s
lm3s END ROM_OFF=0x00000000 RAM_OFF=0x20000000 CPU=cortex-m3 FPU=soft
################################################################################ ################################################################################
# Cortex R4F families # Cortex R4F families
rm46l rm4 ROM_OFF=0x00000000 RAM_OFF=0x08000000 RAM1_OFF=0x08400000 rm46l END ROM_OFF=0x00000000 RAM_OFF=0x08000000 RAM1_OFF=0x08400000
################################################################################
################################################################################
################################################################################
# the architectures
stm32 END
sam3 END
lpc END
efm32 END
lm3 END
rm4 END

View File

@ -15,34 +15,31 @@ where you are defining variables (near the beginning of the file), and file
<module>-rules.mk should be included in the rules part of makefile (somewhere <module>-rules.mk should be included in the rules part of makefile (somewhere
near to the end of file). 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 CFLAGS += -Os -ggdb3
CPPFLAGS += -MD -MP $(@F).d CPPFLAGS += -MD
CPPFLAGS += $(DEFS) LDFLAGS += -static -nostartfiles
CPPFLAGS += $(INCS) LDLIBS += -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group
LDFLAGS += --static --nostartfiles
LDLIBS += -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group
# parameters for gcc module
PREFIX = arm-elf
include $(OPENCM3_DIR)/mk/genlink-config.mk
include $(OPENCM3_DIR)/mk/gcc-config.mk include $(OPENCM3_DIR)/mk/gcc-config.mk
.PHONY: clean all .PHONY: clean all
all: binary.images all: binary.elf binary.hex
%.images: %.elf %.hex
include $(OPENCM3_DIR)/mk/gcc-rules.mk
clean: 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 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, 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): 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: Output variables from this module:
---------------------------------- ----------------------------------
DEFS (appended) CPPFLAGS (appended)
- Appended definitions specified in chip database file. - Appends the chip family to the CPPFLAGS. For example -DSTM32F1
! Ensure that you have line 'CPPFLAGS += $(DEFS)' in your makefile. - Appends the include path for libopencm3
ARCH_FLAGS (replaced) ARCH_FLAGS (replaced)
- Architecture build flags for specified chip. - Architecture build flags for specified chip.
@ -104,12 +102,16 @@ LDSCRIPT (replaced)
- Linker script generated file. - Linker script generated file.
* No needed to handle this variable if you use module <gcc> too. * No needed to handle this variable if you use module <gcc> too.
OPENCM3_LIBNAME (replaced) LDLIBS (appended)
- The right libopencm3 library base name to be linked with. - LDLIBS += -lopencm3_$(family) is appended to link against the
! Ensure that you have line 'LDLIBS += -l$(OPENCM3_LIBNAME)' in your makefile. matching library.
! 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:' LDFLAGS (appended)
to be the library archive successfully built when needed. - 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: Temporary variables that you should not use in your makefile:
------------------------------------------------------------- -------------------------------------------------------------

View File

@ -18,17 +18,62 @@
## ##
ifeq ($(DEVICE),) ifeq ($(DEVICE),)
$(error no DEVICE specified for linker script generator) $(warning no DEVICE specified for linker script generator)
endif endif
LDSCRIPT = $(DEVICE).ld 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_family :=$(shell awk -v PAT="$(DEVICE)" -v MODE="FAMILY" -f $(OPENCM3_DIR)/scripts/genlink.awk $(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_subfamily :=$(shell awk -v PAT="$(DEVICE)" -v MODE="SUBFAMILY" -f $(OPENCM3_DIR)/scripts/genlink.awk $(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_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) CPPFLAGS += $(genlink_cppflags)
ARCH_FLAGS := $(GENLINK_ARCH)
OPENCM3_LIBNAME := $(strip $(subst -l,,$(GENLINK_LIB)))
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

View File

@ -18,8 +18,5 @@
## ##
$(LDSCRIPT):$(OPENCM3_DIR)/ld/linker.ld.S $(LDSCRIPT):$(OPENCM3_DIR)/ld/linker.ld.S
ifeq ($(GENLINK_DEFS),)
$(error unknown device $(DEVICE) for the linker. Cannot generate ldscript)
endif
@printf " GENLNK $@\n" @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 $< > $@

View File

@ -39,27 +39,40 @@ BEGIN {
if (PAT ~ tmp) { if (PAT ~ tmp) {
if ($2 != "+") if ($2 != "+")
PAT=$2; PAT=$2;
for (i = 3; i <= NF; i = i + 1) {
for (i = 3; i <= NF; i = i + 1) { if ($i ~ /^CPU=/) {
if ($i ~ /^-l/) { if ("CPU" ~ MODE){
if ("LIB" ~ MODE) sub(/[^=]*=/,"",$i);
printf "%s ",$i; printf "%s",$i;
exit;
}
} }
else if ($i ~ /^-m/) { else if ($i ~ /^FPU=/) {
if ("ARCH" ~ MODE) if ("FPU" ~ MODE){
printf "%s ",$i; sub(/[^=]*=/,"",$i);
printf "%s",$i;
exit;
}
} }
else if ($i ~ /^-D/) { else if ($i ~ /[[:upper:]]*=/) {
if ("DEFS" ~ MODE)
printf "%s ",$i;
}
else {
if ("DEFS" ~ MODE) if ("DEFS" ~ MODE)
printf "-D_%s ",$i; printf "-D_%s ",$i;
} }
} }
if (PAT=="END"){
if (PAT=="END") if ("FAMILY" ~ MODE)
printf "%s",family;
else if ("SUBFAMILY" ~ MODE)
printf "%s",subfamily;
exit; exit;
}
else{
subfamily = family;
family = PAT;
if ("CPPFLAGS" ~ MODE)
printf "-D%s ",toupper(PAT);
else if("DEFS" ~ MODE)
printf "-D%s ",toupper(PAT);
}
} }
} }