From b8b1385c1ffa90956a67207583c91f36971125e9 Mon Sep 17 00:00:00 2001 From: Edvard Pettersen Date: Fri, 3 Aug 2018 15:34:20 +0200 Subject: [PATCH] Extract changes to cpu/cc13xx-cc26xx --- Makefile.identify-target | 2 - Makefile.include | 23 ++------- arch/cpu/arm/Makefile.arm | 6 --- arch/cpu/arm/cortex-m/cm3/Makefile.cm3 | 19 ++++--- arch/cpu/arm/cortex-m/cm4/Makefile.cm4 | 19 ++++--- arch/cpu/cc13xx-cc26xx/Makefile.cc13xx-cc26xx | 49 +++++++++++++------ os/sys/timer.c | 4 +- 7 files changed, 57 insertions(+), 65 deletions(-) diff --git a/Makefile.identify-target b/Makefile.identify-target index 22b8974217..86e06c0936 100644 --- a/Makefile.identify-target +++ b/Makefile.identify-target @@ -11,6 +11,4 @@ ifeq ($(TARGET),) else ${info using saved target '$(TARGET)'} endif -else - ${info using set target '$(TARGET)'} endif diff --git a/Makefile.include b/Makefile.include index 27a65a0f69..319ae29d74 100644 --- a/Makefile.include +++ b/Makefile.include @@ -39,15 +39,13 @@ ifdef CI endif endif -OBJECTDIR := obj_$(TARGET) +OBJECTDIR = obj_$(TARGET) LOWERCASE = -abcdefghijklmnopqrstuvwxyz/ UPPERCASE = _ABCDEFGHIJKLMNOPQRSTUVWXYZ_ TARGET_UPPERCASE := ${strip ${shell echo $(TARGET) | sed y!$(LOWERCASE)!$(UPPERCASE)!}} -CFLAGS += -DCONTIKI=1 -CFLAGS += -DCONTIKI_TARGET_$(TARGET_UPPERCASE)=1 +CFLAGS += -DCONTIKI=1 -DCONTIKI_TARGET_$(TARGET_UPPERCASE)=1 CFLAGS += -DCONTIKI_TARGET_STRING=\"$(TARGET)\" - ifneq ($(BOARD),) TARGET_BOARD_UPPERCASE := ${strip ${shell echo $(BOARD) | sed y!$(LOWERCASE)!$(UPPERCASE)!}} CFLAGS += -DCONTIKI_BOARD_$(TARGET_BOARD_UPPERCASE)=1 @@ -264,10 +262,8 @@ CONTIKI_CPU_DIRS_CONCAT = ${addprefix $(CONTIKI_CPU)/, \ $(CONTIKI_CPU_DIRS)} CONTIKI_ARCH_DIRS = ${addprefix $(CONTIKI)/, arch} -SOURCEDIRS = . $(PROJECTDIRS) $(CONTIKI_TARGET_DIRS_CONCAT) \ - $(CONTIKI_ARCH_DIRS) $(CONTIKI_CPU_DIRS_CONCAT) \ - $(CONTIKIDIRS) $(MODULEDIRS) $(EXTERNALDIRS) \ - $(dir $(target_makefile)) +SOURCEDIRS = . $(PROJECTDIRS) $(CONTIKI_TARGET_DIRS_CONCAT) $(CONTIKI_ARCH_DIRS) \ + $(CONTIKI_CPU_DIRS_CONCAT) $(CONTIKIDIRS) $(MODULEDIRS) $(EXTERNALDIRS) ${dir $(target_makefile)} vpath %.c $(SOURCEDIRS) vpath %.S $(SOURCEDIRS) @@ -323,10 +319,7 @@ distclean: $(MAKE) TARGET=$$TARG clean; \ done -custom_rules := $(CONTIKI)/arch/platform/$(TARGET)/Makefile.customrules-$(TARGET) -ifneq ("$(wildcard $(custom_rules))","") --include $(custom_rules) -endif +-include $(CONTIKI)/arch/platform/$(TARGET)/Makefile.customrules-$(TARGET) ifndef CUSTOM_RULE_C_TO_OBJECTDIR_O $(OBJECTDIR)/%.o: %.c | $(OBJECTDIR) @@ -488,12 +481,6 @@ endif # the match-anything rule below instead. %: %.c -# Prevent Make from remaking any makefiles. This was particularly an -# issue when you had a Makefile with a suffix equal to that of $(TARGET), -# as it managed to match with the %.$(TARGET) rule, which in turn screwed -# everything up. -Makefile.%: ; - ifeq ($(PLATFORM_ACTION),skip) # Skip this target. $(CONTIKI_PROJECT): diff --git a/arch/cpu/arm/Makefile.arm b/arch/cpu/arm/Makefile.arm index ab3c5116f1..0b26624235 100644 --- a/arch/cpu/arm/Makefile.arm +++ b/arch/cpu/arm/Makefile.arm @@ -12,12 +12,6 @@ CFLAGS += -mthumb -mabi=aapcs -mlittle-endian CFLAGS += -Werror -Wall CFLAGS += -std=c99 CFLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing -# A weird behaviour of GCC garbage collection has been observed, where unitialized -# global variables put in the COMMON section weren't analyzed by the garbage collector -# at all. No idea why. The fix is to dissallow the common section, which subsequently -# places all unitialized global variables in the .bss section and enables the -# garbage collector to analyze the variables. -CFLAGS += -fno-common CFLAGS += -fshort-enums -fomit-frame-pointer -fno-builtin LDFLAGS += -mthumb -mlittle-endian diff --git a/arch/cpu/arm/cortex-m/cm3/Makefile.cm3 b/arch/cpu/arm/cortex-m/cm3/Makefile.cm3 index 24add9c07a..6bd76135cb 100644 --- a/arch/cpu/arm/cortex-m/cm3/Makefile.cm3 +++ b/arch/cpu/arm/cortex-m/cm3/Makefile.cm3 @@ -3,29 +3,28 @@ CONTIKI_ARM_DIRS += cortex-m/cm3 CFLAGS += -mcpu=cortex-m3 LDFLAGS += -mcpu=cortex-m3 -nostartfiles -LDFLAGS += -Wl,--gc-sections -LDFLAGS += -Wl,--sort-section=alignment -LDFLAGS += -Wl,-Map=$(@:.elf=-$(TARGET).map) -LDFLAGS += -Wl,--cref -LDFLAGS += -Wl,--no-warn-mismatch LDFLAGS += -T $(LDSCRIPT) - -TARGET_LIBFLAGS := -Wl,--start-group $(TARGET_LIBFILES) -lc -lgcc -lm -lnosys -Wl,--end-group +LDFLAGS += -Wl,--gc-sections,--sort-section=alignment +LDFLAGS += -Wl,-Map=$(CONTIKI_NG_PROJECT_MAP),--cref,--no-warn-mismatch OBJCOPY_FLAGS += --gap-fill 0xff ### Build syscalls for newlib MODULES += os/lib/newlib -CPU_STARTFILES := ${addprefix $(OBJECTDIR)/,${call oname, $(CPU_START_SOURCEFILES)}} +CPU_STARTFILES = ${addprefix $(OBJECTDIR)/,${call oname, $(CPU_START_SOURCEFILES)}} ### Compilation rules CUSTOM_RULE_LINK = 1 +### Resolve any potential circular dependencies between the linked libraries +### See: https://stackoverflow.com/questions/5651869/gcc-what-are-the-start-group-and-end-group-command-line-options/5651895 +TARGET_LIBFLAGS := -Wl,--start-group $(TARGET_LIBFILES) -lm -Wl,--end-group + .SECONDEXPANSION: -%.elf: $(CPU_STARTFILES) $$(CONTIKI_OBJECTFILES) %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(TARGET_LIBS) $(LDSCRIPT) +%.elf: $(CPU_STARTFILES) $$(CONTIKI_OBJECTFILES) %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(LDSCRIPT) $(TRACE_LD) - $(Q)$(LD) $(LDFLAGS) ${filter %.o %.a,$^} $(TARGET_LIBFLAGS) -o $@ + $(Q)$(LD) $(LDFLAGS) ${filter-out $(LDSCRIPT) %.a,$^} ${filter %.a,$^} $(TARGET_LIBFLAGS) -o $@ include $(CONTIKI)/arch/cpu/arm/cortex-m/Makefile.cortex-m diff --git a/arch/cpu/arm/cortex-m/cm4/Makefile.cm4 b/arch/cpu/arm/cortex-m/cm4/Makefile.cm4 index f6548fd416..0635a3148e 100644 --- a/arch/cpu/arm/cortex-m/cm4/Makefile.cm4 +++ b/arch/cpu/arm/cortex-m/cm4/Makefile.cm4 @@ -3,29 +3,28 @@ CONTIKI_ARM_DIRS += cortex-m/cm4 CFLAGS += -mcpu=cortex-m4 LDFLAGS += -mcpu=cortex-m4 -nostartfiles -LDFLAGS += -Wl,--gc-sections -LDFLAGS += -Wl,--sort-section=alignment -LDFLAGS += -Wl,-Map=$(@:.elf=-$(TARGET).map) -LDFLAGS += -Wl,--cref -LDFLAGS += -Wl,--no-warn-mismatch LDFLAGS += -T $(LDSCRIPT) - -TARGET_LIBFLAGS := -Wl,--start-group $(TARGET_LIBFILES) -lc -lgcc -lm -lnosys -Wl,--end-group +LDFLAGS += -Wl,--gc-sections,--sort-section=alignment +LDFLAGS += -Wl,-Map=$(CONTIKI_NG_PROJECT_MAP),--cref,--no-warn-mismatch OBJCOPY_FLAGS += --gap-fill 0xff ### Build syscalls for newlib MODULES += os/lib/newlib -CPU_STARTFILES := ${addprefix $(OBJECTDIR)/,${call oname, $(CPU_START_SOURCEFILES)}} +CPU_STARTFILES = ${addprefix $(OBJECTDIR)/,${call oname, $(CPU_START_SOURCEFILES)}} ### Compilation rules CUSTOM_RULE_LINK = 1 +### Resolve any potential circular dependencies between the linked libraries +### See: https://stackoverflow.com/questions/5651869/gcc-what-are-the-start-group-and-end-group-command-line-options/5651895 +TARGET_LIBFLAGS := -Wl,--start-group $(TARGET_LIBFILES) -lm -Wl,--end-group + .SECONDEXPANSION: -%.elf: $(CPU_STARTFILES) $$(CONTIKI_OBJECTFILES) %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(TARGET_LIBS) $(LDSCRIPT) +%.elf: $(CPU_STARTFILES) $$(CONTIKI_OBJECTFILES) %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(LDSCRIPT) $(TRACE_LD) - $(Q)$(LD) $(LDFLAGS) ${filter %.o %.a,$^} $(TARGET_LIBFLAGS) -o $@ + $(Q)$(LD) $(LDFLAGS) ${filter-out $(LDSCRIPT) %.a,$^} ${filter %.a,$^} $(TARGET_LIBFLAGS) -o $@ include $(CONTIKI)/arch/cpu/arm/cortex-m/Makefile.cortex-m diff --git a/arch/cpu/cc13xx-cc26xx/Makefile.cc13xx-cc26xx b/arch/cpu/cc13xx-cc26xx/Makefile.cc13xx-cc26xx index c6eeae9d11..19b3689e87 100644 --- a/arch/cpu/cc13xx-cc26xx/Makefile.cc13xx-cc26xx +++ b/arch/cpu/cc13xx-cc26xx/Makefile.cc13xx-cc26xx @@ -24,10 +24,6 @@ else endif endif -# Both ccfg-conf.c and startup_cc13xx_cc26xx_gcc.c is located locally in -# the arch/cpu/cc13xx-cc26xx folder. -CPU_START_SOURCEFILES += ccfg-conf.c startup_cc13xx_cc26xx_gcc.c - ################################################################################ ### Device Family @@ -52,20 +48,13 @@ else SDK_LIB_NAME := $(DEVICE_FAMILY_LC) endif -################################################################################ -### Core SDK paths - -SDK_NORTOS := $(CORE_SDK)/kernel/nortos -SDK_SOURCE := $(CORE_SDK)/source -SDK_DRIVERS := $(CORE_SDK)/source/ti/drivers -SDK_DEVICES := $(CORE_SDK)/source/ti/devices/$(SDK_DEVICES_NAME) - -EXTERNALDIRS += $(SDK_SOURCE) -EXTERNALDIRS += $(SDK_NORTOS) - ################################################################################ ### CC13xx/CC26xx CPU files +# Both ccfg-conf.c and startup_cc13xx_cc26xx_gcc.c is located locally in +# the arch/cpu/cc13xx-cc26xx folder. +CPU_START_SOURCEFILES += ccfg-conf.c startup_cc13xx_cc26xx_gcc.c + # CPU-dependent source files CONTIKI_CPU_SOURCEFILES += rtimer-arch.c clock-arch.c CONTIKI_CPU_SOURCEFILES += watchdog-arch.c dbg-arch.c @@ -94,6 +83,14 @@ endif ################################################################################ ### Modules and paths +# Core SDK paths +SDK_NORTOS := $(CORE_SDK)/kernel/nortos +SDK_SOURCE := $(CORE_SDK)/source +SDK_DRIVERS := $(CORE_SDK)/source/ti/drivers +SDK_DEVICES := $(CORE_SDK)/source/ti/devices/$(SDK_DEVICES_NAME) + +EXTERNALDIRS += $(SDK_SOURCE) $(SDK_NORTOS) + # CPU-dependent debug source files MODULES += os/lib/dbg-io @@ -103,6 +100,19 @@ CONTIKI_CPU_DIRS += rf rf-settings rf-settings/$(DEVICE_FAMILY_LC) CONTIKI_SOURCEFILES += $(CONTIKI_CPU_SOURCEFILES) $(DEBUG_IO_SOURCEFILES) +################################################################################ +### Compiler configuration + +# A weird behaviour of GCC garbage collector has been observed, where +# unitialized global variables with global linkage (aka non-static) put in the +# COMMON section weren't analyzed by the garbage collector at all. No idea why. +# The solution is to disable the common section, which subsequently places all +# unitialized global variables with global linkage in the .bss section, +# allowing the GC to analyze the variables. This is especially an issue with +# Board.h files, as they rely heavily on global variables placed in COMMON to +# be garbage collected if unused. +CFLAGS += -fno-common + ################################################################################ ### Linker configuration @@ -111,8 +121,12 @@ LDFLAGS += --entry resetISR LDFLAGS += -static LDFLAGS += --specs=nano.specs +# Linker script LDSCRIPT := $(CONTIKI_CPU)/$(SUBFAMILY)/$(SUBFAMILY).lds +# Globally linked libraries +TARGET_LIBFILES += -lc -lgcc -lnosys + ################################################################################ ### Specialized build targets @@ -130,5 +144,8 @@ $(OBJECTDIR)/ccfg-conf.o: ccfg-conf.c FORCE | $(OBJECTDIR) $(TRACE_CC) $(Q)$(CC) $(CFLAGS) -c $< -o $@ -# Include the Sub-family specific Makefile +################################################################################ +### Sub-family Makefile + +# Include the Sub-family Makefile specific for the specified device include $(CONTIKI_CPU)/$(SUBFAMILY)/Makefile.$(SUBFAMILY) diff --git a/os/sys/timer.c b/os/sys/timer.c index 068d57777f..1eeae64de7 100644 --- a/os/sys/timer.c +++ b/os/sys/timer.c @@ -84,9 +84,7 @@ timer_set(struct timer *t, clock_time_t interval) void timer_reset(struct timer *t) { - if(timer_expired(t)) { - t->start += t->interval; - } + t->start += t->interval; } /*---------------------------------------------------------------------------*/ /**