@@ -28,10 +28,10 @@ GIT_VERSION := $(shell git describe --dirty --always --tags)
28
28
GIT_SUBMODULE_VERSIONS := $(shell git submodule status | cut -d" " -f3,4 | paste -s -d" " -)
29
29
30
30
# compiled file name
31
- OUT_FILE = $(BOARD ) _bootloader-$(GIT_VERSION )
31
+ OUT_NAME = $(BOARD ) _bootloader-$(GIT_VERSION )
32
32
33
33
# merged file = compiled + sd
34
- MERGED_FILE = $(OUT_FILE ) _$(SD_NAME ) _$(SD_VERSION )
34
+ MERGED_FILE = $(OUT_NAME ) _$(SD_NAME ) _$(SD_VERSION )
35
35
36
36
# ------------------------------------------------------------------------------
37
37
# Tool configure
@@ -46,6 +46,16 @@ OBJCOPY = $(CROSS_COMPILE)objcopy
46
46
SIZE = $(CROSS_COMPILE ) size
47
47
GDB = $(CROSS_COMPILE ) gdb
48
48
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
+
49
59
# Flasher utility options
50
60
NRFUTIL = adafruit-nrfutil
51
61
NRFJPROG = nrfjprog
66
76
$(error Unsupported flash utility : "$(FLASHER ) ")
67
77
endif
68
78
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
-
78
79
# auto-detect BMP on macOS, otherwise have to specify
79
80
BMP_PORT ?= $(shell ls -1 /dev/cu.usbmodem????????1 | head -1)
80
81
GDB_BMP = $(GDB ) -ex 'target extended-remote $(BMP_PORT ) ' -ex 'monitor swdp_scan' -ex 'attach 1'
93
94
94
95
# Build directory
95
96
BUILD = _build/build-$(BOARD )
97
+ BIN = _bin/$(BOARD )
96
98
97
99
# Board specific
98
100
-include src/boards/$(BOARD ) /board.mk
@@ -334,7 +336,7 @@ INC_PATHS = $(addprefix -I,$(IPATH))
334
336
.PHONY : all clean flash dfu-flash sd gdbflash gdb
335
337
336
338
# 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
338
340
339
341
# Print out the value of a make variable.
340
342
# https://stackoverflow.com/questions/16467718/how-to-print-out-a-variable-in-makefile
@@ -345,10 +347,11 @@ print-%:
345
347
346
348
# Create build directories
347
349
$(BUILD ) :
348
- @$(MK ) " $@ "
350
+ @$(MKDIR ) " $@ "
349
351
350
352
clean :
351
353
@$(RM ) $(BUILD )
354
+ @$(RM ) $(BIN )
352
355
353
356
# Create objects from C SRC files
354
357
$(BUILD ) /% .o : % .c
@@ -361,37 +364,46 @@ $(BUILD)/%.o: %.S
361
364
@$(CC ) -x assembler-with-cpp $(ASFLAGS ) $(INC_PATHS ) -c -o $@ $<
362
365
363
366
# Link
364
- $(BUILD ) /$(OUT_FILE ) .out : $(BUILD ) $(OBJECTS )
367
+ $(BUILD ) /$(OUT_NAME ) .out : $(BUILD ) $(OBJECTS )
365
368
@echo LD $(notdir $@ )
366
369
@$(CC ) -o $@ $(LDFLAGS ) $(OBJECTS ) -Wl,--start-group $(LIBS ) -Wl,--end-group
367
370
@$(SIZE ) $@
368
371
369
372
# ------------------- Binary generator -------------------
370
373
371
374
# 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
373
376
@echo Create $(notdir $@ )
374
377
@$(OBJCOPY ) -O ihex $< $@
375
378
376
379
# 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
378
381
@echo Create $(notdir $@ )
379
382
@python3 tools/hexmerge.py --overlap=replace -o $@ $< $(MBR_HEX )
380
383
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
383
386
@echo Create $(notdir $@ )
384
387
@python3 lib/uf2/utils/uf2conv.py -f 0xd663823c -c -o $@ $^
385
388
386
389
# merge bootloader and sd hex together
387
- $(BUILD ) /$(MERGED_FILE ) .hex : $(BUILD ) /$(OUT_FILE ) .hex
390
+ $(BUILD ) /$(MERGED_FILE ) .hex : $(BUILD ) /$(OUT_NAME ) .hex
388
391
@echo Create $(notdir $@ )
389
392
@python3 tools/hexmerge.py -o $@ $< $(SD_HEX )
390
393
391
394
# 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
393
396
@$(NRFUTIL ) dfu genpkg --dev-type 0x0052 --dev-revision $(DFU_DEV_REV ) --bootloader $< --softdevice $(SD_HEX ) $@
394
397
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
+
395
407
# ------------------- Flash target -------------------
396
408
397
409
check_defined = \
@@ -402,7 +414,7 @@ __check_defined = \
402
414
$(error Undefined make flag : $1$(if $2, ($2) )))
403
415
404
416
# Flash the compiled
405
- flash : $(BUILD ) /$(OUT_FILE ) -nosd .hex
417
+ flash : $(BUILD ) /$(OUT_NAME ) _nosd .hex
406
418
@echo Flashing: $(notdir $< )
407
419
$(call FLASH_CMD,$< )
408
420
@@ -433,5 +445,5 @@ gdbflash: $(BUILD)/$(MERGED_FILE).hex
433
445
@echo Flashing: $<
434
446
@$(GDB_BMP ) -nx --batch -ex ' load $<' -ex ' compare-sections' -ex ' kill'
435
447
436
- gdb : $(BUILD ) /$(OUT_FILE ) .out
448
+ gdb : $(BUILD ) /$(OUT_NAME ) .out
437
449
$(GDB_BMP ) $<
0 commit comments