diff --git a/boards/native/Makefile.features b/boards/native/Makefile.features index c3242a2fc24ca..a7fbc80d145fe 100644 --- a/boards/native/Makefile.features +++ b/boards/native/Makefile.features @@ -1,14 +1,6 @@ CPU = native -# Put defined MCU peripherals here (in alphabetical order) -FEATURES_PROVIDED += periph_rtc -FEATURES_PROVIDED += periph_rtc_ms -FEATURES_PROVIDED += periph_timer -FEATURES_PROVIDED += periph_uart -FEATURES_PROVIDED += periph_gpio -FEATURES_PROVIDED += periph_pwm -FEATURES_PROVIDED += periph_qdec +FEATURES_PROVIDED += arch_32bit +NATIVE_ARCH_BIT = 32 -# Various other features (if any) -FEATURES_PROVIDED += ethernet -FEATURES_PROVIDED += motor_driver +include $(RIOTBOARD)/native/common_features.inc.mk diff --git a/boards/native/Makefile.include b/boards/native/Makefile.include index 14a06f7a503b2..de59d78294bbb 100644 --- a/boards/native/Makefile.include +++ b/boards/native/Makefile.include @@ -1,236 +1 @@ -NATIVEINCLUDES += -DNATIVE_INCLUDES NATIVEINCLUDES += -I$(RIOTBOARD)/native/include/ -NATIVEINCLUDES += -I$(RIOTBASE)/core/lib/include/ -NATIVEINCLUDES += -I$(RIOTBASE)/core/include/ -NATIVEINCLUDES += -I$(RIOTBASE)/drivers/include/ - -ifeq ($(OS),Darwin) - DEBUGGER ?= lldb -else - DEBUGGER ?= gdb -endif - -# only use pyterm wrapper if term target is requested -ifeq (,$(filter term,$(MAKECMDGOALS))) - RIOT_TERMINAL ?= native -else - RIOT_TERMINAL ?= pyterm -endif - -RESET ?= $(RIOTBOARD)/native/dist/reset.sh -FLASHER ?= -FLASHFILE ?= $(ELFFILE) - -ifeq (pyterm,$(RIOT_TERMINAL)) - TERMFLAGS += -ps $(FLASHFILE) - PROCARGS := --process-args -else - TERMPROG ?= $(FLASHFILE) -endif - -ZEP_IP ?= [::1] -ZEP_PORT_BASE ?= 17754 -ifeq (1,$(USE_ZEP)) -ifeq (pyterm,$(RIOT_TERMINAL)) - TERMFLAGS += --process-args '-z $(ZEP_IP):$(ZEP_PORT_BASE)' -else - TERMFLAGS += -z $(ZEP_IP):$(ZEP_PORT_BASE) -endif -endif -ifneq (,$(ZEP_MAC)) -ifeq (pyterm,$(RIOT_TERMINAL)) - TERMFLAGS += --process-args '\-\-eui64=$(ZEP_MAC)' -else - TERMFLAGS += --eui64=$(ZEP_MAC) -endif -endif - -export VALGRIND ?= valgrind -export CGANNOTATE ?= cg_annotate -export GPROF ?= gprof - -# basic cflags: -CFLAGS += -Wall -Wextra -pedantic $(CFLAGS_DBG) $(CFLAGS_OPT) -CFLAGS += -U_FORTIFY_SOURCE -CFLAGS_DBG ?= -g3 - -ifneq (,$(filter backtrace,$(USEMODULE))) - $(warning module backtrace is used, do not omit frame pointers) - CFLAGS_OPT ?= -Og -fno-omit-frame-pointer -else - CFLAGS_OPT ?= -Og -endif - -# default std set to gnu11 if not overwritten by user -ifeq (,$(filter -std=%, $(CFLAGS))) - CFLAGS += -std=gnu11 -endif - -ifeq ($(OS_ARCH),x86_64) - ifeq ($(BOARD),native64) - CFLAGS += -m64 - else - CFLAGS += -m32 - endif -endif -ifneq (,$(filter -DDEVELHELP,$(CFLAGS))) - CFLAGS += -fstack-protector-all -endif -ifeq ($(OS),FreeBSD) - ifeq ($(OS_ARCH),amd64) - ifeq ($(BOARD),native64) - CFLAGS += -m64 - else - CFLAGS += -m32 -DCOMPAT_32BIT -B/usr/lib32 - endif - endif -endif -ifeq ($(OS),Darwin) - CFLAGS += -Wno-deprecated-declarations -endif - -# unwanted (CXXUWFLAGS) and extra (CXXEXFLAGS) flags for c++ -CXXUWFLAGS += -CXXEXFLAGS += - -ifeq ($(OS_ARCH),x86_64) - ifeq ($(BOARD),native64) - LINKFLAGS += -m64 - else - LINKFLAGS += -m32 - endif -endif -ifeq ($(OS),FreeBSD) - ifeq ($(OS_ARCH),amd64) - ifeq ($(BOARD),native64) - LINKFLAGS += -m64 - else - LINKFLAGS += -m32 -DCOMPAT_32BIT -L/usr/lib32 -B/usr/lib32 - endif - endif - LINKFLAGS += -L $(BINDIR) -else - LINKFLAGS += -ldl -endif - -# XFA (cross file array) support -LINKFLAGS += -T$(RIOTBASE)/cpu/native/ldscripts/xfa.ld - -# fix this warning: -# ``` -# /usr/bin/ld: examples/hello-world/bin/native/cpu/tramp.o: warning: relocation against `_native_saved_eip' in read-only section `.text' -# /usr/bin/ld: warning: creating DT_TEXTREL in a PIE -# ``` -LINKFLAGS += -no-pie - -# clean up unused functions -CFLAGS += -ffunction-sections -fdata-sections -ifeq ($(OS),Darwin) - LINKFLAGS += -Wl,-dead_strip -else - LINKFLAGS += -Wl,--gc-sections -endif -LINKFLAGS += -ffunction-sections - -# set the tap interface for term/valgrind -PORT ?= tap0 -TERMFLAGS += $(PROCARGS) $(PORT) - -# Configure default eeprom file -EEPROM_FILE ?= $(BINDIR)/native.eeprom - -# set the eeprom file flags only when the periph_eeprom feature is used. -ifneq (,$(filter periph_eeprom,$(FEATURES_USED))) - EEPROM_FILE_FLAGS = --eeprom $(EEPROM_FILE) - ifeq (pyterm,$(RIOT_TERMINAL)) - TERMFLAGS += --process-args '$(EEPROM_FILE_FLAGS)' - else - TERMFLAGS += $(EEPROM_FILE_FLAGS) - endif -endif - -VCAN_IFNUM ?= 0 -VCAN_IFNAME ?= vcan0 -VCAN_IFACE ?= $(VCAN_IFNUM):$(VCAN_IFNAME) -# set the default vcan interface -ifneq (,$(filter periph_can,$(FEATURES_USED))) - PERIPH_CAN_FLAGS ?= --can $(VCAN_IFACE) - TERMFLAGS += $(PERIPH_CAN_FLAGS) -endif - - -ASFLAGS = -ifeq ($(shell basename $(DEBUGGER)),lldb) - DEBUGGER_FLAGS = -- $(ELFFILE) $(TERMFLAGS) -else - DEBUGGER_FLAGS = -q --args $(ELFFILE) $(TERMFLAGS) -endif -term-valgrind: export VALGRIND_FLAGS ?= \ - --leak-check=full \ - --track-origins=yes \ - --fullpath-after=$(RIOTBASE)/ \ - --read-var-info=yes -debug-valgrind-server: export VALGRIND_FLAGS ?= --vgdb=yes --vgdb-error=0 -v \ - --leak-check=full --track-origins=yes --fullpath-after=$(RIOTBASE) \ - --read-var-info=yes -term-cachegrind: export CACHEGRIND_FLAGS += --tool=cachegrind -term-gprof: TERMPROG = GMON_OUT_PREFIX=gmon.out $(ELFFILE) -all-valgrind: CFLAGS += -DHAVE_VALGRIND_H -all-valgrind: NATIVEINCLUDES += $(shell pkg-config valgrind --cflags) -all-gprof: CFLAGS += -pg -all-gprof: LINKFLAGS += -pg - -CFLAGS_ASAN += -fsanitize=address -fno-omit-frame-pointer -DNATIVE_MEMORY -LINKFLAGS_ASAN += -fsanitize=address -fno-omit-frame-pointer -all-asan: CFLAGS += $(CFLAGS_ASAN) -all-asan: LINKFLAGS += $(LINKFLAGS_ASAN) -all-asan: export AFL_USE_ASAN=1 - -INCLUDES += $(NATIVEINCLUDES) - -CFLAGS += -DDEBUG_ASSERT_VERBOSE - -# workaround for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52624 -ifneq ($(shell gcc --version | head -1 | grep -E ' (4.6|4.7)'),) - CFLAGS += -DHAVE_NO_BUILTIN_BSWAP16 -endif - -# clumsy way to enable building native on osx: -BUILDOSXNATIVE = 0 -ifeq ($(CPU),native) - ifeq ($(OS),Darwin) - BUILDOSXNATIVE = 1 - endif -endif - -all: # do not override first target - -all-gprof: all - -all-asan: all - -all-valgrind: all - -all-cachegrind: all - -term-valgrind: - $(VALGRIND) $(VALGRIND_FLAGS) $(ELFFILE) $(PORT) - -debug-valgrind-server: - $(VALGRIND) $(VALGRIND_FLAGS) $(ELFFILE) $(PORT) - -debug-valgrind: - $(eval VALGRIND_PID ?= $(shell pgrep -n memcheck-x86-li -u $(USER) | cut -d" " -f1)) - $(eval DEBUGGER_FLAGS := -ex "target remote | vgdb --pid=$(VALGRIND_PID)" $(DEBUGGER_FLAGS)) - $(DEBUGGER) $(DEBUGGER_FLAGS) - -term-cachegrind: - $(VALGRIND) $(CACHEGRIND_FLAGS) $(ELFFILE) $(PORT) - -term-gprof: term - -eval-gprof: - $(GPROF) $(ELFFILE) $(shell ls -rt gmon.out* | tail -1) - -eval-cachegrind: - $(CGANNOTATE) $(shell ls -rt cachegrind.out* | tail -1) diff --git a/boards/native/common_features.inc.mk b/boards/native/common_features.inc.mk new file mode 100644 index 0000000000000..cbebc11020625 --- /dev/null +++ b/boards/native/common_features.inc.mk @@ -0,0 +1,12 @@ +# Put defined MCU peripherals here (in alphabetical order) +FEATURES_PROVIDED += periph_rtc +FEATURES_PROVIDED += periph_rtc_ms +FEATURES_PROVIDED += periph_timer +FEATURES_PROVIDED += periph_uart +FEATURES_PROVIDED += periph_gpio +FEATURES_PROVIDED += periph_pwm +FEATURES_PROVIDED += periph_qdec + +# Various other features (if any) +FEATURES_PROVIDED += ethernet +FEATURES_PROVIDED += motor_driver diff --git a/boards/native64/Makefile b/boards/native64/Makefile index 1a43c1422dec5..23014a2c68255 100644 --- a/boards/native64/Makefile +++ b/boards/native64/Makefile @@ -1,2 +1,3 @@ DIRS = $(RIOTBOARD)/native + include $(RIOTBASE)/Makefile.base diff --git a/boards/native64/Makefile.features b/boards/native64/Makefile.features index a49f05c741527..ef67048084c69 100644 --- a/boards/native64/Makefile.features +++ b/boards/native64/Makefile.features @@ -1 +1,6 @@ -include $(RIOTBOARD)/native/Makefile.features +CPU = native + +FEATURES_PROVIDED += arch_64bit +NATIVE_ARCH_BIT = 64 + +include $(RIOTBOARD)/native/common_features.inc.mk diff --git a/cpu/native/Makefile.features b/cpu/native/Makefile.features index 4683405e51f05..2fdde8697a726 100644 --- a/cpu/native/Makefile.features +++ b/cpu/native/Makefile.features @@ -2,11 +2,6 @@ ifeq (FreeBSD,$(OS)) DISABLE_LIBSTDCPP ?= 1 endif -ifeq ($(BOARD),native64) - FEATURES_PROVIDED += arch_64bit -else - FEATURES_PROVIDED += arch_32bit -endif FEATURES_PROVIDED += arch_native FEATURES_PROVIDED += cpp ifneq ($(DISABLE_LIBSTDCPP),1) diff --git a/cpu/native/Makefile.include b/cpu/native/Makefile.include index c664b9cb15a34..63b2fa3a9a010 100644 --- a/cpu/native/Makefile.include +++ b/cpu/native/Makefile.include @@ -1,4 +1,4 @@ -NATIVEINCLUDES += -I$(RIOTCPU)/native/include -I$(RIOTBASE)/sys/include +NATIVEINCLUDES += -I$(RIOTCPU)/native/include/ ifneq (,$(filter periph_can,$(USEMODULE))) ifeq (,$(filter libsocketcan,$(USEPKG))) @@ -17,3 +17,5 @@ ifeq ($(OS) $(OS_ARCH),Linux x86_64) RUST_TARGET = x86_64-unknown-linux-gnu endif endif + +include $(RIOTMAKE)/arch/native.inc.mk diff --git a/makefiles/arch/native.inc.mk b/makefiles/arch/native.inc.mk new file mode 100644 index 0000000000000..c37aef87fab30 --- /dev/null +++ b/makefiles/arch/native.inc.mk @@ -0,0 +1,224 @@ +NATIVEINCLUDES += -DNATIVE_INCLUDES +NATIVEINCLUDES += -I$(RIOTBASE)/core/lib/include/ +NATIVEINCLUDES += -I$(RIOTBASE)/core/include/ +NATIVEINCLUDES += -I$(RIOTBASE)/sys/include/ +NATIVEINCLUDES += -I$(RIOTBASE)/drivers/include/ + +ifeq ($(OS),Darwin) + DEBUGGER ?= lldb +else + DEBUGGER ?= gdb +endif + +# only use pyterm wrapper if term target is requested +ifeq (,$(filter term,$(MAKECMDGOALS))) + RIOT_TERMINAL ?= native +else + RIOT_TERMINAL ?= pyterm +endif + +RESET ?= $(RIOTBOARD)/native/dist/reset.sh +FLASHER ?= +FLASHFILE ?= $(ELFFILE) + +ifeq (pyterm,$(RIOT_TERMINAL)) + TERMFLAGS += -ps $(FLASHFILE) + PROCARGS := --process-args +else + TERMPROG ?= $(FLASHFILE) +endif + +ZEP_IP ?= [::1] +ZEP_PORT_BASE ?= 17754 +ifeq (1,$(USE_ZEP)) +ifeq (pyterm,$(RIOT_TERMINAL)) + TERMFLAGS += --process-args '-z $(ZEP_IP):$(ZEP_PORT_BASE)' +else + TERMFLAGS += -z $(ZEP_IP):$(ZEP_PORT_BASE) +endif +endif +ifneq (,$(ZEP_MAC)) +ifeq (pyterm,$(RIOT_TERMINAL)) + TERMFLAGS += --process-args '\-\-eui64=$(ZEP_MAC)' +else + TERMFLAGS += --eui64=$(ZEP_MAC) +endif +endif + +export VALGRIND ?= valgrind +export CGANNOTATE ?= cg_annotate +export GPROF ?= gprof + +# basic cflags: +CFLAGS += -Wall -Wextra -pedantic $(CFLAGS_DBG) $(CFLAGS_OPT) +CFLAGS += -U_FORTIFY_SOURCE +CFLAGS_DBG ?= -g3 + +ifneq (,$(filter backtrace,$(USEMODULE))) + $(warning module backtrace is used, do not omit frame pointers) + CFLAGS_OPT ?= -Og -fno-omit-frame-pointer +else + CFLAGS_OPT ?= -Og +endif + +# default std set to gnu11 if not overwritten by user +ifeq (,$(filter -std=%, $(CFLAGS))) + CFLAGS += -std=gnu11 +endif + +ifeq ($(NATIVE_ARCH_BIT),64) + CFLAGS += -m64 + LINKFLAGS += -m64 +else ifeq ($(NATIVE_ARCH_BIT),32) + CFLAGS += -m32 + LINKFLAGS += -m32 +else + $(error Unsupported native architecture) +endif + +ifneq (,$(filter -DDEVELHELP,$(CFLAGS))) + CFLAGS += -fstack-protector-all +endif +ifeq ($(OS),FreeBSD) + ifeq ($(OS_ARCH),amd64) + ifeq ($(NATIVE_ARCH_BIT),32) + CFLAGS += -DCOMPAT_32BIT -B/usr/lib32 + LINKFLAGS += -DCOMPAT_32BIT -L/usr/lib32 -B/usr/lib32 + endif + endif +endif +ifeq ($(OS),Darwin) + CFLAGS += -Wno-deprecated-declarations +endif + +# unwanted (CXXUWFLAGS) and extra (CXXEXFLAGS) flags for c++ +CXXUWFLAGS += +CXXEXFLAGS += + +ifeq ($(OS),FreeBSD) + LINKFLAGS += -L $(BINDIR) +else + LINKFLAGS += -ldl +endif + +# XFA (cross file array) support +LINKFLAGS += -T$(RIOTBASE)/cpu/native/ldscripts/xfa.ld + +# fix this warning: +# ``` +# /usr/bin/ld: examples/hello-world/bin/native/cpu/tramp.o: warning: relocation against `_native_saved_eip' in read-only section `.text' +# /usr/bin/ld: warning: creating DT_TEXTREL in a PIE +# ``` +LINKFLAGS += -no-pie + +# clean up unused functions +CFLAGS += -ffunction-sections -fdata-sections +ifeq ($(OS),Darwin) + LINKFLAGS += -Wl,-dead_strip +else + LINKFLAGS += -Wl,--gc-sections +endif +LINKFLAGS += -ffunction-sections + +# set the tap interface for term/valgrind +PORT ?= tap0 +TERMFLAGS += $(PROCARGS) $(PORT) + +# Configure default eeprom file +EEPROM_FILE ?= $(BINDIR)/native.eeprom + +# set the eeprom file flags only when the periph_eeprom feature is used. +ifneq (,$(filter periph_eeprom,$(FEATURES_USED))) + EEPROM_FILE_FLAGS = --eeprom $(EEPROM_FILE) + ifeq (pyterm,$(RIOT_TERMINAL)) + TERMFLAGS += --process-args '$(EEPROM_FILE_FLAGS)' + else + TERMFLAGS += $(EEPROM_FILE_FLAGS) + endif +endif + +VCAN_IFNUM ?= 0 +VCAN_IFNAME ?= vcan0 +VCAN_IFACE ?= $(VCAN_IFNUM):$(VCAN_IFNAME) +# set the default vcan interface +ifneq (,$(filter periph_can,$(FEATURES_USED))) + PERIPH_CAN_FLAGS ?= --can $(VCAN_IFACE) + TERMFLAGS += $(PERIPH_CAN_FLAGS) +endif + + +ASFLAGS = +ifeq ($(shell basename $(DEBUGGER)),lldb) + DEBUGGER_FLAGS = -- $(ELFFILE) $(TERMFLAGS) +else + DEBUGGER_FLAGS = -q --args $(ELFFILE) $(TERMFLAGS) +endif +term-valgrind: export VALGRIND_FLAGS ?= \ + --leak-check=full \ + --track-origins=yes \ + --fullpath-after=$(RIOTBASE)/ \ + --read-var-info=yes +debug-valgrind-server: export VALGRIND_FLAGS ?= --vgdb=yes --vgdb-error=0 -v \ + --leak-check=full --track-origins=yes --fullpath-after=$(RIOTBASE) \ + --read-var-info=yes +term-cachegrind: export CACHEGRIND_FLAGS += --tool=cachegrind +term-gprof: TERMPROG = GMON_OUT_PREFIX=gmon.out $(ELFFILE) +all-valgrind: CFLAGS += -DHAVE_VALGRIND_H +all-valgrind: NATIVEINCLUDES += $(shell pkg-config valgrind --cflags) +all-gprof: CFLAGS += -pg +all-gprof: LINKFLAGS += -pg + +CFLAGS_ASAN += -fsanitize=address -fno-omit-frame-pointer -DNATIVE_MEMORY +LINKFLAGS_ASAN += -fsanitize=address -fno-omit-frame-pointer +all-asan: CFLAGS += $(CFLAGS_ASAN) +all-asan: LINKFLAGS += $(LINKFLAGS_ASAN) +all-asan: export AFL_USE_ASAN=1 + +INCLUDES += $(NATIVEINCLUDES) + +CFLAGS += -DDEBUG_ASSERT_VERBOSE + +# workaround for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52624 +ifneq ($(shell gcc --version | head -1 | grep -E ' (4.6|4.7)'),) + CFLAGS += -DHAVE_NO_BUILTIN_BSWAP16 +endif + +# clumsy way to enable building native on osx: +BUILDOSXNATIVE = 0 +ifeq ($(CPU),native) + ifeq ($(OS),Darwin) + BUILDOSXNATIVE = 1 + endif +endif + +all: # do not override first target + +all-gprof: all + +all-asan: all + +all-valgrind: all + +all-cachegrind: all + +term-valgrind: + $(VALGRIND) $(VALGRIND_FLAGS) $(ELFFILE) $(PORT) + +debug-valgrind-server: + $(VALGRIND) $(VALGRIND_FLAGS) $(ELFFILE) $(PORT) + +debug-valgrind: + $(eval VALGRIND_PID ?= $(shell pgrep -n memcheck-x86-li -u $(USER) | cut -d" " -f1)) + $(eval DEBUGGER_FLAGS := -ex "target remote | vgdb --pid=$(VALGRIND_PID)" $(DEBUGGER_FLAGS)) + $(DEBUGGER) $(DEBUGGER_FLAGS) + +term-cachegrind: + $(VALGRIND) $(CACHEGRIND_FLAGS) $(ELFFILE) $(PORT) + +term-gprof: term + +eval-gprof: + $(GPROF) $(ELFFILE) $(shell ls -rt gmon.out* | tail -1) + +eval-cachegrind: + $(CGANNOTATE) $(shell ls -rt cachegrind.out* | tail -1)