@@ -28,10 +28,10 @@ GIT_VERSION := $(shell git describe --dirty --always --tags)
2828GIT_SUBMODULE_VERSIONS := $(shell git submodule status | cut -d" " -f3,4 | paste -s -d" " -)
2929
3030# compiled file name
31- OUT_FILE = $(BOARD ) _bootloader-$(GIT_VERSION )
31+ OUT_NAME = $(BOARD ) _bootloader-$(GIT_VERSION )
3232
3333# merged file = compiled + sd
34- MERGED_FILE = $(OUT_FILE ) _$(SD_NAME ) _$(SD_VERSION )
34+ MERGED_FILE = $(OUT_NAME ) _$(SD_NAME ) _$(SD_VERSION )
3535
3636# ------------------------------------------------------------------------------
3737# Tool configure
@@ -46,6 +46,16 @@ OBJCOPY = $(CROSS_COMPILE)objcopy
4646SIZE = $(CROSS_COMPILE ) size
4747GDB = $(CROSS_COMPILE ) gdb
4848
49+ # Set make directory command, Windows tries to create a directory named "-p" if that flag is there.
50+ ifneq ($(OS ) , Windows_NT)
51+ MKDIR = mkdir -p
52+ else
53+ MKDIR = mkdir
54+ endif
55+
56+ RM = rm -rf
57+ CP = cp
58+
4959# Flasher utility options
5060NRFUTIL = adafruit-nrfutil
5161NRFJPROG = nrfjprog
6676 $(error Unsupported flash utility : "$(FLASHER ) ")
6777endif
6878
69- # Set make directory command, Windows tries to create a directory named "-p" if that flag is there.
70- ifneq ($(OS ) , Windows_NT)
71- MK = mkdir -p
72- else
73- MK = mkdir
74- endif
75-
76- RM = rm -rf
77-
7879# auto-detect BMP on macOS, otherwise have to specify
7980BMP_PORT ?= $(shell ls -1 /dev/cu.usbmodem????????1 | head -1)
8081GDB_BMP = $(GDB ) -ex 'target extended-remote $(BMP_PORT ) ' -ex 'monitor swdp_scan' -ex 'attach 1'
9394
9495# Build directory
9596BUILD = _build/build-$(BOARD )
97+ BIN = _bin/$(BOARD )
9698
9799# Board specific
98100-include src/boards/$(BOARD ) /board.mk
@@ -334,7 +336,7 @@ INC_PATHS = $(addprefix -I,$(IPATH))
334336.PHONY : all clean flash dfu-flash sd gdbflash gdb
335337
336338# default target to build
337- all : $(BUILD ) /$(OUT_FILE ) .out $(BUILD ) /$(OUT_FILE ) -nosd .hex $(BUILD ) /$( OUT_FILE ) -nosd .uf2 $(BUILD ) /$(MERGED_FILE ) .hex $(BUILD ) /$(MERGED_FILE ) .zip
339+ all : $(BUILD ) /$(OUT_NAME ) .out $(BUILD ) /$(OUT_NAME ) _nosd .hex $(BUILD ) /update- $( OUT_NAME ) _nosd .uf2 $(BUILD ) /$(MERGED_FILE ) .hex $(BUILD ) /$(MERGED_FILE ) .zip
338340
339341# Print out the value of a make variable.
340342# https://stackoverflow.com/questions/16467718/how-to-print-out-a-variable-in-makefile
@@ -345,10 +347,11 @@ print-%:
345347
346348# Create build directories
347349$(BUILD ) :
348- @$(MK ) " $@ "
350+ @$(MKDIR ) " $@ "
349351
350352clean :
351353 @$(RM ) $(BUILD )
354+ @$(RM ) $(BIN )
352355
353356# Create objects from C SRC files
354357$(BUILD ) /% .o : % .c
@@ -361,37 +364,46 @@ $(BUILD)/%.o: %.S
361364 @$(CC ) -x assembler-with-cpp $(ASFLAGS ) $(INC_PATHS ) -c -o $@ $<
362365
363366# Link
364- $(BUILD ) /$(OUT_FILE ) .out : $(BUILD ) $(OBJECTS )
367+ $(BUILD ) /$(OUT_NAME ) .out : $(BUILD ) $(OBJECTS )
365368 @echo LD $(notdir $@ )
366369 @$(CC ) -o $@ $(LDFLAGS ) $(OBJECTS ) -Wl,--start-group $(LIBS ) -Wl,--end-group
367370 @$(SIZE ) $@
368371
369372# ------------------- Binary generator -------------------
370373
371374# Create hex file (no sd, no mbr)
372- $(BUILD ) /$(OUT_FILE ) .hex : $(BUILD ) /$(OUT_FILE ) .out
375+ $(BUILD ) /$(OUT_NAME ) .hex : $(BUILD ) /$(OUT_NAME ) .out
373376 @echo Create $(notdir $@ )
374377 @$(OBJCOPY ) -O ihex $< $@
375378
376379# Hex file with mbr (still no SD)
377- $(BUILD ) /$(OUT_FILE ) -nosd .hex : $(BUILD ) /$(OUT_FILE ) .hex
380+ $(BUILD ) /$(OUT_NAME ) _nosd .hex : $(BUILD ) /$(OUT_NAME ) .hex
378381 @echo Create $(notdir $@ )
379382 @python3 tools/hexmerge.py --overlap=replace -o $@ $< $(MBR_HEX )
380383
381- # Bootolader only uf2
382- $(BUILD ) /$( OUT_FILE ) -nosd .uf2 : $(BUILD ) /$(OUT_FILE ) -nosd .hex
384+ # Bootolader self-update uf2
385+ $(BUILD ) /update- $( OUT_NAME ) _nosd .uf2 : $(BUILD ) /$(OUT_NAME ) _nosd .hex
383386 @echo Create $(notdir $@ )
384387 @python3 lib/uf2/utils/uf2conv.py -f 0xd663823c -c -o $@ $^
385388
386389# merge bootloader and sd hex together
387- $(BUILD ) /$(MERGED_FILE ) .hex : $(BUILD ) /$(OUT_FILE ) .hex
390+ $(BUILD ) /$(MERGED_FILE ) .hex : $(BUILD ) /$(OUT_NAME ) .hex
388391 @echo Create $(notdir $@ )
389392 @python3 tools/hexmerge.py -o $@ $< $(SD_HEX )
390393
391394# Create pkg zip file for bootloader+SD combo to use with DFU CDC
392- $(BUILD ) /$(MERGED_FILE ) .zip : $(BUILD ) /$(OUT_FILE ) .hex
395+ $(BUILD ) /$(MERGED_FILE ) .zip : $(BUILD ) /$(OUT_NAME ) .hex
393396 @$(NRFUTIL ) dfu genpkg --dev-type 0x0052 --dev-revision $(DFU_DEV_REV ) --bootloader $< --softdevice $(SD_HEX ) $@
394397
398+ # -------------- Artifacts --------------
399+ $(BIN ) :
400+ @$(MKDIR ) -p $@
401+
402+ copy-artifact : $(BIN )
403+ @$(CP ) $(BUILD ) /update-$(OUT_NAME ) _nosd.uf2 $(BIN )
404+ @$(CP ) $(BUILD ) /$(MERGED_FILE ) .hex $(BIN )
405+ @$(CP ) $(BUILD ) /$(MERGED_FILE ) .zip $(BIN )
406+
395407# ------------------- Flash target -------------------
396408
397409check_defined = \
@@ -402,7 +414,7 @@ __check_defined = \
402414 $(error Undefined make flag : $1$(if $2, ($2) )))
403415
404416# Flash the compiled
405- flash : $(BUILD ) /$(OUT_FILE ) -nosd .hex
417+ flash : $(BUILD ) /$(OUT_NAME ) _nosd .hex
406418 @echo Flashing: $(notdir $< )
407419 $(call FLASH_CMD,$< )
408420
@@ -433,5 +445,5 @@ gdbflash: $(BUILD)/$(MERGED_FILE).hex
433445 @echo Flashing: $<
434446 @$(GDB_BMP ) -nx --batch -ex ' load $<' -ex ' compare-sections' -ex ' kill'
435447
436- gdb : $(BUILD ) /$(OUT_FILE ) .out
448+ gdb : $(BUILD ) /$(OUT_NAME ) .out
437449 $(GDB_BMP ) $<
0 commit comments