enhance Makefile

This commit is contained in:
hathach 2018-08-06 17:41:02 +07:00
parent aa577b4cdf
commit aa040652ee
6 changed files with 103 additions and 120 deletions

View File

@ -31,7 +31,24 @@ SD_PATH = ../lib/softdevice/$(SD_VERSION)
SD_HEX = $(SD_PATH)/$(SD_NAME)/hex/$(SD_NAME)_nrf52_$(SD_VERSION)_softdevice.hex SD_HEX = $(SD_PATH)/$(SD_NAME)/hex/$(SD_NAME)_nrf52_$(SD_VERSION)_softdevice.hex
LINKER_SCRIPT = $(SRC_PATH)/$(SD_NAME)_$(SD_VERSION).ld LINKER_SCRIPT = $(SRC_PATH)/$(SD_NAME)_$(SD_VERSION).ld
BOOTLOADER_SD_SUFFIX = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_REVISION)_$(SD_NAME) BOOT_SD_NAME = $(OUTPUT_FILENAME)_$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_REVISION)_$(SD_NAME)
BETA_DIR = ../bin/$(BOARD)/beta
RELEASE_DIR = ../bin/$(BOARD)/$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_REVISION)
# Select the board to build for.
ifeq ($(BOARD),)
$(info You must provide a BOARD parameter with 'BOARD=')
$(info Possible values are:)
$(info $(sort $(subst .h,,$(subst boards/,,$(wildcard boards/*)))))
$(error BOARD not defined)
else
ifeq ($(wildcard boards/$(BOARD).h),)
$(error Invalid BOARD specified)
endif
endif
BUILD = _build-$(BOARD)
#****************************************************************************** #******************************************************************************
# Tool configure # Tool configure
@ -48,10 +65,10 @@ endif
MK := mkdir MK := mkdir
RM := rm -rf RM := rm -rf
ifeq ("$(VERBOSE)","1") ifeq ("$(V)","2")
NO_ECHO := QUIET :=
else else
NO_ECHO := @ QUIET := @
endif endif
GNU_PREFIX = arm-none-eabi GNU_PREFIX = arm-none-eabi
@ -171,25 +188,22 @@ INC_PATHS += -I$(SD_PATH)/common
INC_PATHS += -I$(SD_PATH)/$(SD_NAME)/headers INC_PATHS += -I$(SD_PATH)/$(SD_NAME)/headers
INC_PATHS += -I$(SD_PATH)/$(SD_NAME)/headers/nrf52 INC_PATHS += -I$(SD_PATH)/$(SD_NAME)/headers/nrf52
OBJECT_DIRECTORY = _build
LISTING_DIRECTORY = $(OBJECT_DIRECTORY)
OUTPUT_BINARY_DIRECTORY = $(OBJECT_DIRECTORY)
# Sorting removes duplicates
BUILD_DIRECTORIES := $(sort $(OBJECT_DIRECTORY) $(OUTPUT_BINARY_DIRECTORY) $(LISTING_DIRECTORY))
#****************************************************************************** #******************************************************************************
# Compiler Flags # Compiler Flags
# - Additional compiler flags # - Additional compiler flags
#****************************************************************************** #******************************************************************************
#flags common to all targets #flags common to all targets
#CFLAGS += -DENABLE_SWO CFLAGS += -mcpu=cortex-m4
CFLAGS += -mthumb -mabi=aapcs --std=gnu99
CFLAGS += -Wall -Werror -Os -g3
CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
# keep every function in separate section. This will allow linker to dump unused functions
CFLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing
CFLAGS += -fno-builtin --short-enums
#*************************
# Defined Symbol (MACROS) # Defined Symbol (MACROS)
#*************************
CFLAGS += -DBOOTLOADER_VERSION=0x0$(VERSION_MAJOR)0$(VERSION_MINOR)0$(VERSION_REVISION)0$(VERSION_SINGLEBANK)UL CFLAGS += -DBOOTLOADER_VERSION=0x0$(VERSION_MAJOR)0$(VERSION_MINOR)0$(VERSION_REVISION)0$(VERSION_SINGLEBANK)UL
CFLAGS += -DNRF52840_XXAA CFLAGS += -DNRF52840_XXAA
CFLAGS += -D__HEAP_SIZE=0 CFLAGS += -D__HEAP_SIZE=0
@ -201,17 +215,10 @@ CFLAGS += -DSWI_DISABLE0
CFLAGS += -DSOFTDEVICE_PRESENT CFLAGS += -DSOFTDEVICE_PRESENT
CFLAGS += -DFLOAT_ABI_HARD CFLAGS += -DFLOAT_ABI_HARD
CFLAGS += -DMK_DIS_FIRMWARE='$(MK_DIS_FIRMWARE)' CFLAGS += -DMK_DIS_FIRMWARE='$(MK_DIS_FIRMWARE)'
CFLAGS += -DDFU_APP_DATA_RESERVED=7*4096 CFLAGS += -DDFU_APP_DATA_RESERVED=7*4096
CFLAGS += -mcpu=cortex-m4 CFLAGS += -DBOARD_$(shell echo $(BOARD) | tr '[:lower:]' '[:upper:]')
CFLAGS += -mthumb -mabi=aapcs --std=gnu99
CFLAGS += -Wall -Werror -Os -g3
CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
# keep every function in separate section. This will allow linker to dump unused functions
CFLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing
CFLAGS += -fno-builtin --short-enums
#****************************************************************************** #******************************************************************************
# Linker Flags # Linker Flags
@ -219,7 +226,7 @@ CFLAGS += -fno-builtin --short-enums
#****************************************************************************** #******************************************************************************
# keep every function in separate section. This will allow linker to dump unused functions # keep every function in separate section. This will allow linker to dump unused functions
LDFLAGS += -Xlinker -Map=$(LISTING_DIRECTORY)/$(OUTPUT_FILENAME).map LDFLAGS += -Xlinker -Map=$(BUILD)/$(OUTPUT_FILENAME).map
LDFLAGS += -mthumb -mabi=aapcs -L$(SRC_PATH)/ -T$(LINKER_SCRIPT) LDFLAGS += -mthumb -mabi=aapcs -L$(SRC_PATH)/ -T$(LINKER_SCRIPT)
LDFLAGS += -mcpu=cortex-m4 LDFLAGS += -mcpu=cortex-m4
LDFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 LDFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
@ -243,138 +250,114 @@ ASMFLAGS += -DBLE_STACK_SUPPORT_REQD
ASMFLAGS += -DBSP_DEFINES_ONLY ASMFLAGS += -DBSP_DEFINES_ONLY
ASMFLAGS += -DSWI_DISABLE0 ASMFLAGS += -DSWI_DISABLE0
ASMFLAGS += -DSOFTDEVICE_PRESENT ASMFLAGS += -DSOFTDEVICE_PRESENT
ASMFLAGS += -DFLOAT_ABI_HARD ASMFLAGS += -DFLOAT_ABI_HARD
MAKEFILE_NAME := $(MAKEFILE_LIST)
MAKEFILE_DIR := $(dir $(MAKEFILE_NAME) )
#****************************************************************************** #******************************************************************************
# BUILD TARGETS # BUILD TARGETS
# - BOARD
# - V
#****************************************************************************** #******************************************************************************
ifeq ("$(VERBOSE)","1") ifeq ("$(V)","1")
$(info CFLAGS $(CFLAGS)) $(info CFLAGS $(CFLAGS))
$(info ) $(info )
$(info LDFLAGS $(LDFLAGS)) $(info LDFLAGS $(LDFLAGS))
$(info ) $(info )
endif endif
#default target - first one defined
default: all
#building all targets
all:
@$(MAKE) -s -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e clean
@echo Making feather52840 board
@echo ----------------------
@$(MAKE) -s -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e feather52840
@$(MAKE) -s -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e clean
@echo Making pca10056 board
@echo --------------------
@$(MAKE) -s -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e pca10056
#target for printing all targets
help:
@echo following targets are available:
@echo - feather52840 : build for Feather nRF52840
@echo - flash_feather52840 : flash Feather nRF52840
@echo - pca10056 : build for pca10056 DK
@echo - flash_pca10056 : flash pca10056 DK
@echo - flash_sd : flash SoftDevice only
C_SOURCE_FILE_NAMES = $(notdir $(C_SOURCE_FILES)) C_SOURCE_FILE_NAMES = $(notdir $(C_SOURCE_FILES))
C_PATHS = $(call remduplicates, $(dir $(C_SOURCE_FILES) ) ) C_PATHS = $(call remduplicates, $(dir $(C_SOURCE_FILES) ) )
C_OBJECTS = $(addprefix $(OBJECT_DIRECTORY)/, $(C_SOURCE_FILE_NAMES:.c=.o) ) C_OBJECTS = $(addprefix $(BUILD)/, $(C_SOURCE_FILE_NAMES:.c=.o) )
ASM_SOURCE_FILE_NAMES = $(notdir $(ASM_SOURCE_FILES)) ASM_SOURCE_FILE_NAMES = $(notdir $(ASM_SOURCE_FILES))
ASM_PATHS = $(call remduplicates, $(dir $(ASM_SOURCE_FILES) )) ASM_PATHS = $(call remduplicates, $(dir $(ASM_SOURCE_FILES) ))
ASM_OBJECTS = $(addprefix $(OBJECT_DIRECTORY)/, $(ASM_SOURCE_FILE_NAMES:.S=.o) ) ASM_OBJECTS = $(addprefix $(BUILD)/, $(ASM_SOURCE_FILE_NAMES:.S=.o) )
vpath %.c $(C_PATHS) vpath %.c $(C_PATHS)
vpath %.S $(ASM_PATHS) vpath %.S $(ASM_PATHS)
OBJECTS = $(C_OBJECTS) $(ASM_OBJECTS) OBJECTS = $(C_OBJECTS) $(ASM_OBJECTS)
export OUTPUT_FILENAME
export FINAL_BIN_DIR
BOOTLOADER_WITH_SD_NAME := $(OUTPUT_FILENAME)_$(BOOTLOADER_SD_SUFFIX)
# Target for Feather nrf52 board
feather52840: OUTPUT_FILENAME := feather52840_bootloader
feather52840: FINAL_BIN_DIR := ../bin/feather52840/$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_REVISION)
feather52840: CFLAGS += -DBOARD_FEATHER52840
feather52840: $(BUILD_DIRECTORIES) $(OBJECTS)
@echo Linking target: $(OUTPUT_FILENAME).out
$(NO_ECHO)$(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -lm -o $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
$(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e finalize
# Target for Metro nrf52 board
pca10056: OUTPUT_FILENAME := pca10056_bootloader
pca10056: FINAL_BIN_DIR := ../bin/pca10056/$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_REVISION)
pca10056: CFLAGS += -DBOARD_PCA10056
pca10056: $(BUILD_DIRECTORIES) $(OBJECTS)
@echo Linking target: $(OUTPUT_FILENAME).out
$(NO_ECHO)$(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -lm -o $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
$(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e finalize
## Create build directories OUTPUT_FILENAME = $(BOARD)_bootloader
$(BUILD_DIRECTORIES):
@$(MK) $@
# Create objects from C SRC files
$(OBJECT_DIRECTORY)/%.o: %.c
@echo Compiling file: $(notdir $<)
$(NO_ECHO)$(CC) $(CFLAGS) $(INC_PATHS) -c -o $@ $<
# Assemble files all: $(BUILD)/$(OUTPUT_FILENAME).out size
$(OBJECT_DIRECTORY)/%.o: %.S
@echo Assembly file: $(notdir $<)
$(NO_ECHO)$(CC) $(ASMFLAGS) $(INC_PATHS) -c -o $@ $<
# Link
$(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out: $(BUILD_DIRECTORIES) $(OBJECTS)
@echo Linking target: $(OUTPUT_FILENAME).out
$(NO_ECHO)$(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -lm -o $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
finalize: genhex genbin genpkg echosize ######## FLASH tagert #######
.phony: flash sd
## Create binary .hex file from the .out file flash: $(BUILD)/$(OUTPUT_FILENAME).hex
genhex: @echo Flashing: $<
@echo Preparing: $(OUTPUT_FILENAME).hex $(BOOTLOADER_WITH_SD_NAME).hex nrfjprog --program $< --sectoranduicrerase -f nrf52 --reset
$(NO_ECHO)$(OBJCOPY) -O ihex $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex
@mergehex -q -m $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex $(SD_HEX) -o $(OUTPUT_BINARY_DIRECTORY)/$(BOOTLOADER_WITH_SD_NAME).hex
@mkdir -p $(FINAL_BIN_DIR)
@cp $(OUTPUT_BINARY_DIRECTORY)/$(BOOTLOADER_WITH_SD_NAME).hex $(FINAL_BIN_DIR)/
## Create .bin file sd:
genbin:
@echo Preparing: $(BOOTLOADER_WITH_SD_NAME).bin
$(NO_ECHO)$(OBJCOPY) -j .text -j .data -j .bss -O binary $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(FINAL_BIN_DIR)/$(BOOTLOADER_WITH_SD_NAME).bin
## Create pkg file for bootloader only and bootloader+SD combo to use with DFU
genpkg:
@echo Preparing: $(BOOTLOADER_WITH_SD_NAME).zip
@$(NRFUTIL) dfu genpkg --dev-type 0x0052 --dev-revision 0xADAF --bootloader $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex --softdevice $(SD_HEX) $(FINAL_BIN_DIR)/$(BOOTLOADER_WITH_SD_NAME).zip
echosize:
-@echo ''
$(NO_ECHO)$(SIZE) $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
-@echo ''
clean:
@$(RM) $(BUILD_DIRECTORIES)
flash_feather52840: BOOTLOADER_WITH_SD_NAME := feather52840_bootloader_$(BOOTLOADER_SD_SUFFIX)
flash_feather52840: feather52840
@echo Flashing: $(OUTPUT_BINARY_DIRECTORY)/$(BOOTLOADER_WITH_SD_NAME).hex
nrfjprog --program $(OUTPUT_BINARY_DIRECTORY)/$(BOOTLOADER_WITH_SD_NAME).hex -f nrf52 --chiperase --reset
flash_pca10056: BOOTLOADER_WITH_SD_NAME := pca10056_bootloader_$(BOOTLOADER_SD_SUFFIX)
flash_pca10056: pca10056
@echo Flashing: $(OUTPUT_BINARY_DIRECTORY)/$(BOOTLOADER_WITH_SD_NAME).hex
nrfjprog --program $(OUTPUT_BINARY_DIRECTORY)/$(BOOTLOADER_WITH_SD_NAME).hex -f nrf52 --chiperase --reset
flash_sd:
@echo Flashing: $(SD_HEX) @echo Flashing: $(SD_HEX)
nrfjprog --program $(SD_HEX) -f nrf52 --chiperase --reset nrfjprog --program $(SD_HEX) -f nrf52 --chiperase --reset
## Create build directories
.phony: $(BUILD) clean size
$(BUILD):
@$(MK) $@
clean:
@$(RM) $(BUILD)
# Create objects from C SRC files
$(BUILD)/%.o: %.c
@echo CC $(notdir $<)
$(QUIET)$(CC) $(CFLAGS) $(INC_PATHS) -c -o $@ $<
# Assemble files
$(BUILD)/%.o: %.S
@echo AS $(notdir $<)
$(QUIET)$(CC) $(ASMFLAGS) $(INC_PATHS) -c -o $@ $<
# Link
$(BUILD)/$(OUTPUT_FILENAME).out: $(BUILD) $(OBJECTS)
@echo LD $(OUTPUT_FILENAME).out
$(QUIET)$(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -lm -o $(BUILD)/$(OUTPUT_FILENAME).out
size: $(BUILD)/$(OUTPUT_FILENAME).out
-@echo ''
$(QUIET)$(SIZE) $<
-@echo ''
.phony: genhex genpkg beta release
## Create binary .hex file from the .out file
genhex: $(BUILD)/$(OUTPUT_FILENAME).hex
$(BUILD)/$(OUTPUT_FILENAME).hex: $(BUILD)/$(OUTPUT_FILENAME).out
@echo CR $(OUTPUT_FILENAME).hex
@echo CR $(BOOT_SD_NAME).hex
$(QUIET)$(OBJCOPY) -O ihex $< $@
@mergehex -q -m $@ $(SD_HEX) -o $(BUILD)/$(BOOT_SD_NAME).hex
## Create pkg file for bootloader+SD combo to use with DFU
genpkg: $(BUILD)/$(BOOT_SD_NAME).zip
$(BUILD)/$(BOOT_SD_NAME).zip: $(BUILD)/$(OUTPUT_FILENAME).hex
@$(NRFUTIL) dfu genpkg --dev-type 0x0052 --dev-revision 0xADAF --bootloader $< --softdevice $(SD_HEX) $@
# Create SD+bootloader combo with hex & dfu package at beta folder
beta: genhex genpkg
@echo CR $(BETA_DIR)/$(BOOT_SD_NAME).hex
@echo CR $(BETA_DIR)/$(BOOT_SD_NAME).zip
@mkdir -p $(BETA_DIR)
@cp $(BUILD)/$(BOOT_SD_NAME).hex $(BETA_DIR)/$(BOOT_SD_NAME).hex
@cp $(BUILD)/$(BOOT_SD_NAME).zip $(BETA_DIR)/$(BOOT_SD_NAME).zip
release: genhex genpkg
@echo CR $(RELEASE_DIR)/$(BOOT_SD_NAME).hex
@echo CR $(RELEASE_DIR)/$(BOOT_SD_NAME).zip
@mkdir -p $(RELEASE_DIR)
@cp $(BUILD)/$(BOOT_SD_NAME).hex $(RELEASE_DIR)/$(BOOT_SD_NAME).hex
@cp $(BUILD)/$(BOOT_SD_NAME).zip $(RELEASE_DIR)/$(BOOT_SD_NAME).zip

View File

@ -17,9 +17,9 @@
#include "nrf_gpio.h" #include "nrf_gpio.h"
#if defined BOARD_FEATHER52840 #if defined BOARD_FEATHER52840
#include "feather52840.h" #include "boards/feather52840.h"
#elif defined BOARD_PCA10056 #elif defined BOARD_PCA10056
#include "pca10056.h" #include "boards/pca10056.h"
#else #else
#error No boards defined #error No boards defined
#endif #endif