Skip to content

Commit 6c0bb9d

Browse files
committed
clean up makefile
- rename target sd -> flash-sd, mbr -> flash-mbr, dfu-flash -> flash-dfu - update readme - clean up python script, add multiprocess build
1 parent 597dc6f commit 6c0bb9d

File tree

5 files changed

+126
-229
lines changed

5 files changed

+126
-229
lines changed

Makefile

Lines changed: 55 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# - SD_HEX : to bootloader hex binary
88
#------------------------------------------------------------------------------
99

10+
# local customization
1011
-include Makefile.user
1112

1213
SDK_PATH = lib/sdk/components
@@ -37,7 +38,7 @@ OUT_NAME = $(BOARD)_bootloader-$(GIT_VERSION)
3738
MERGED_FILE = $(OUT_NAME)_$(SD_NAME)_$(SD_VERSION)
3839

3940
#------------------------------------------------------------------------------
40-
# Tool configure
41+
# Tool Configure
4142
#------------------------------------------------------------------------------
4243

4344
# Toolchain commands
@@ -208,39 +209,46 @@ ASM_SRC = $(NRFX_PATH)/mdk/gcc_startup_$(MCU_SUB_VARIANT).S
208209
#------------------------------------------------------------------------------
209210

210211
# src
211-
IPATH += src
212-
IPATH += src/boards
213-
IPATH += src/boards/$(BOARD)
214-
IPATH += src/cmsis/include
215-
IPATH += src/usb
216-
IPATH += $(TUSB_PATH)
212+
IPATH += \
213+
src \
214+
src/boards \
215+
src/boards/$(BOARD) \
216+
src/cmsis/include \
217+
src/usb \
218+
$(TUSB_PATH)
217219

218220
# nrfx
219-
IPATH += $(NRFX_PATH)
220-
IPATH += $(NRFX_PATH)/mdk
221-
IPATH += $(NRFX_PATH)/hal
222-
IPATH += $(NRFX_PATH)/drivers/include
223-
IPATH += $(NRFX_PATH)/drivers/src
224-
225-
IPATH += $(SDK11_PATH)/libraries/bootloader_dfu/hci_transport
226-
IPATH += $(SDK11_PATH)/libraries/bootloader_dfu
227-
IPATH += $(SDK11_PATH)/drivers_nrf/pstorage
228-
IPATH += $(SDK11_PATH)/ble/common
229-
IPATH += $(SDK11_PATH)/ble/ble_services/ble_dfu
230-
IPATH += $(SDK11_PATH)/ble/ble_services/ble_dis
231-
232-
IPATH += $(SDK_PATH)/libraries/timer
233-
IPATH += $(SDK_PATH)/libraries/scheduler
234-
IPATH += $(SDK_PATH)/libraries/crc16
235-
IPATH += $(SDK_PATH)/libraries/util
236-
IPATH += $(SDK_PATH)/libraries/hci/config
237-
IPATH += $(SDK_PATH)/libraries/uart
238-
IPATH += $(SDK_PATH)/libraries/hci
239-
IPATH += $(SDK_PATH)/drivers_nrf/delay
240-
241-
# Softdevice
242-
IPATH += $(SD_PATH)/$(SD_FILENAME)_API/include
243-
IPATH += $(SD_PATH)/$(SD_FILENAME)_API/include/nrf52
221+
IPATH += \
222+
$(NRFX_PATH) \
223+
$(NRFX_PATH)/mdk \
224+
$(NRFX_PATH)/hal \
225+
$(NRFX_PATH)/drivers/include \
226+
$(NRFX_PATH)/drivers/src
227+
228+
# sdk11 for cdc/ble dfu
229+
IPATH += \
230+
$(SDK11_PATH)/libraries/bootloader_dfu/hci_transport \
231+
$(SDK11_PATH)/libraries/bootloader_dfu \
232+
$(SDK11_PATH)/drivers_nrf/pstorage \
233+
$(SDK11_PATH)/ble/common \
234+
$(SDK11_PATH)/ble/ble_services/ble_dfu \
235+
$(SDK11_PATH)/ble/ble_services/ble_dis
236+
237+
# later sdk with updated drivers
238+
IPATH += \
239+
$(SDK_PATH)/libraries/timer \
240+
$(SDK_PATH)/libraries/scheduler \
241+
$(SDK_PATH)/libraries/crc16 \
242+
$(SDK_PATH)/libraries/util \
243+
$(SDK_PATH)/libraries/hci/config \
244+
$(SDK_PATH)/libraries/uart \
245+
$(SDK_PATH)/libraries/hci \
246+
$(SDK_PATH)/drivers_nrf/delay
247+
248+
# SoftDevice
249+
IPATH += \
250+
$(SD_PATH)/$(SD_FILENAME)_API/include \
251+
$(SD_PATH)/$(SD_FILENAME)_API/include/nrf52
244252

245253
#------------------------------------------------------------------------------
246254
# Compiler Flags
@@ -278,9 +286,6 @@ CFLAGS += \
278286
# Suppress warning caused by SDK
279287
CFLAGS += -Wno-unused-parameter -Wno-expansion-to-defined
280288

281-
# TinyUSB tusb_hal_nrf_power_event
282-
CFLAGS += -Wno-cast-function-type
283-
284289
# Nordic Softdevice SDK header files contains inline assembler that has
285290
# broken constraints. As a result the IPA-modref pass, introduced in gcc-11,
286291
# is able to "prove" that arguments to wrapper functions generated with
@@ -332,6 +337,7 @@ LIBS += -lm -lc
332337
#------------------------------------------------------------------------------
333338
# Assembler flags
334339
#------------------------------------------------------------------------------
340+
335341
ASFLAGS += $(CFLAGS)
336342

337343
#function for removing duplicates in a list
@@ -356,7 +362,7 @@ INC_PATHS = $(addprefix -I,$(IPATH))
356362
# BUILD TARGETS
357363
#------------------------------------------------------------------------------
358364

359-
.PHONY: all clean flash dfu-flash sd gdbflash gdb
365+
.PHONY: all clean flash dfu-flash flash-dfu flash-sd flash-mbr gdbflash gdb
360366

361367
# default target to build
362368
all: $(BUILD)/$(OUT_NAME).out $(BUILD)/$(OUT_NAME)_nosd.hex $(BUILD)/update-$(OUT_NAME)_nosd.uf2 $(BUILD)/$(MERGED_FILE).hex $(BUILD)/$(MERGED_FILE).zip
@@ -431,7 +437,9 @@ copy-artifact: $(BIN)
431437
@$(CP) $(BUILD)/$(MERGED_FILE).hex $(BIN)
432438
@$(CP) $(BUILD)/$(MERGED_FILE).zip $(BIN)
433439

434-
#------------------- Flash target -------------------
440+
#--------------------------------------
441+
# Flash Target
442+
#--------------------------------------
435443

436444
check_defined = \
437445
$(strip $(foreach 1,$1, \
@@ -440,29 +448,29 @@ __check_defined = \
440448
$(if $(value $1),, \
441449
$(error Undefined make flag: $1$(if $2, ($2))))
442450

451+
# erase chip
452+
erase:
453+
@echo Erasing flash
454+
$(call FLASH_ERASE_CMD)
455+
443456
# Flash the compiled
444457
flash: $(BUILD)/$(OUT_NAME)_nosd.hex
445458
@echo Flashing: $(notdir $<)
446459
$(call FLASH_CMD,$<)
447460

448-
erase:
449-
@echo Erasing flash
450-
$(call FLASH_ERASE_CMD)
451-
452461
# flash SD only
453-
sd:
462+
flash-sd:
454463
@echo Flashing: $(SD_HEX)
455464
$(call FLASH_NOUICR_CMD,$(SD_HEX))
456465

457466
# flash MBR only
458-
mbr:
467+
flash-mbr:
459468
@echo Flashing: $(MBR_HEX)
460469
$(call FLASH_NOUICR_CMD,$(MBR_HEX))
461470

462-
#------------------- Flash with NRFUTIL via DFU -------------------
463-
464-
# dfu using CDC interface
465-
dfu-flash: $(BUILD)/$(MERGED_FILE).zip
471+
# dfu with adafruit-nrfutil using CDC interface
472+
dfu-flash: flash-dfu
473+
flash-dfu: $(BUILD)/$(MERGED_FILE).zip
466474
@:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyACM0)
467475
$(NRFUTIL) --verbose dfu serial --package $< -p $(SERIAL) -b 115200 --singlebank --touch 1200
468476

README.md

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -121,57 +121,62 @@ both bootloader and the Nordic SoftDevice, you can freely upgrade/downgrade to a
121121
You should only continue if you are looking to develop bootloader for your own.
122122
You must have have a J-Link available to "unbrick" your device.
123123
124-
Prerequisites
124+
### Prerequisites
125125
126126
- ARM GCC
127-
128-
To install for macos
129-
130-
```bash
131-
brew tap ArmMbed/homebrew-formulae
132-
brew install arm-none-eabi-gcc
133-
brew link --overwrite arm-none-eabi-gcc # if a prior version was present
134-
```
135-
136127
- Nordic's [nRF5x Command Line Tools](https://www.nordicsemi.com/Software-and-Tools/Development-Tools/nRF-Command-Line-Tools)
137128
- [Python IntelHex](https://pypi.org/project/IntelHex/)
138129
139-
To build:
130+
### Build:
140131
141132
```
142133
make BOARD=feather_nrf52840_express all
143134
```
144135
145-
To flash the bootloader with JLink:
136+
For the list of supported boards, run `make` without `BOARD=` :
137+
138+
```
139+
$ make
140+
You must provide a BOARD parameter with 'BOARD='
141+
Supported boards are: feather_nrf52840_express feather_nrf52840_express pca10056
142+
Makefile:90: *** BOARD not defined. Stop
143+
```
144+
145+
### Flash
146+
147+
To flash the bootloader (without softdevice/mbr) using JLink:
146148
147149
```
148150
make BOARD=feather_nrf52840_express flash
149151
```
150152
153+
If you are using pyocd as debugger, add `FLASHER=pyocd` to make command:
154+
155+
```
156+
make BOARD=feather_nrf52840_express FLASHER=pyocd flash
157+
```
158+
151159
To upgrade the bootloader using DFU Serial via port /dev/ttyACM0
152160
153161
```
154-
make BOARD=feather_nrf52840_express SERIAL=/dev/ttyACM0 dfu-flash
162+
make BOARD=feather_nrf52840_express SERIAL=/dev/ttyACM0 flash-dfu
155163
```
156164
157-
To flash SoftDevice (and chip erase):
165+
To flash SoftDevice (will also erase chip):
158166
159167
```
160-
make BOARD=feather_nrf52840_express sd
168+
make BOARD=feather_nrf52840_express flash-sd
161169
```
162170
163-
For the list of supported boards, run `make` without `BOARD=` :
171+
To flash MBR only
164172
165173
```
166-
$ make
167-
You must provide a BOARD parameter with 'BOARD='
168-
Supported boards are: feather_nrf52840_express feather_nrf52840_express pca10056
169-
Makefile:90: *** BOARD not defined. Stop
174+
make BOARD=feather_nrf52840_express flash-mbr
170175
```
171176
172177
### Common makefile problems
173178
174-
#### 1. `arm-none-eabi-gcc`: No such file or directory
179+
#### `arm-none-eabi-gcc`: No such file or directory
175180
176181
If you get the following error ...
177182
@@ -190,16 +195,15 @@ $ make CROSS_COMPILE=/opt/gcc-arm-none-eabi-9-2019-q4-major/bin/arm-none-eabi- B
190195
191196
For other compile errors, check the gcc version with `arm-none-eabi-gcc --version` to insure it is at least 9.x.
192197
193-
#### 2. `ModuleNotFoundError: No module named 'intelhex'`
198+
#### `ModuleNotFoundError: No module named 'intelhex'`
194199
195200
Install python-intelhex with
196201
197202
```
198203
pip install intelhex
199204
```
200205
201-
202-
#### 3. `make: nrfjprog: No such file or directory`
206+
#### `make: nrfjprog: No such file or directory`
203207
204208
Make sure that `nrfjprog` is available from the command-line. This binary is
205209
part of Nordic's nRF5x Command Line Tools.

tools/build_all.py

Lines changed: 43 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,73 @@
11
import os
2-
import shutil
32
import glob
43
import sys
54
import subprocess
65
import time
7-
8-
subprocess.run("rm -rf _build/", shell=True)
9-
subprocess.run("rm -rf bin/", shell=True)
6+
from multiprocessing import Pool
107

118
SUCCEEDED = "\033[32msucceeded\033[0m"
129
FAILED = "\033[31mfailed\033[0m"
1310

14-
success_count = 0
15-
fail_count = 0
16-
exit_status = 0
17-
1811
build_format = '| {:32} | {:18} | {:5} | {:6} | {:6} |'
1912
build_separator = '-' * 74
2013

21-
# All supported boards
22-
all_boards = []
23-
for entry in os.scandir("src/boards"):
24-
if entry.is_dir():
25-
all_boards.append(entry.name)
26-
all_boards.sort()
27-
28-
#sha, version = build_info.get_version_info()
29-
30-
total_time = time.monotonic()
31-
32-
print(build_separator)
33-
print(build_format.format('Board', '\033[39mResult\033[0m', 'Time', 'Flash', 'SRAM'))
34-
print(build_separator)
35-
36-
for board in all_boards:
37-
bin_directory = "bin/{}/".format(board)
38-
os.makedirs(bin_directory, exist_ok=True)
3914

15+
def build_board(board):
4016
start_time = time.monotonic()
41-
make_result = subprocess.run("make -j 4 BOARD={} all".format(board), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
17+
make_result = subprocess.run("make -j BOARD={} all".format(board), shell=True, stdout=subprocess.PIPE,
18+
stderr=subprocess.STDOUT)
4219
build_duration = time.monotonic() - start_time
4320

4421
flash_size = "-"
4522
sram_size = "-"
23+
succeeded = 0
4624

4725
if make_result.returncode == 0:
48-
success = SUCCEEDED
49-
success_count += 1
50-
26+
succeeded = 1
5127
out_file = glob.glob('_build/build-{}/*.out'.format(board))[0]
52-
size_output = subprocess.run('size {}'.format(out_file), shell=True, stdout=subprocess.PIPE).stdout.decode("utf-8")
28+
size_output = subprocess.run('size {}'.format(out_file), shell=True, stdout=subprocess.PIPE).stdout.decode(
29+
"utf-8")
5330
size_list = size_output.split('\n')[1].split('\t')
5431
flash_size = int(size_list[0])
5532
sram_size = int(size_list[1]) + int(size_list[2])
56-
else:
57-
exit_status = make_result.returncode
58-
success = FAILED
59-
fail_count += 1
6033

61-
for entry in os.scandir("_build/build-{}".format(board)):
62-
for extension in ["zip", "hex", "uf2"]:
63-
if entry.name.endswith(extension):
64-
if ("nosd" in entry.name) or ("s140" in entry.name) or ("s132" in entry.name):
65-
shutil.copy(entry.path, bin_directory)
66-
67-
print(build_format.format(board, success, "{:.2f}s".format(build_duration), flash_size, sram_size))
34+
print(build_format.format(board, SUCCEEDED if succeeded else FAILED, "{:.2f}s".format(build_duration), flash_size,
35+
sram_size))
6836

6937
if make_result.returncode != 0:
7038
print(make_result.stdout.decode("utf-8"))
7139

72-
# Build Summary
73-
total_time = time.monotonic() - total_time
74-
print(build_separator)
75-
print("Build Sumamary: {} {}, {} {} and took {:.2f}s".format(success_count, SUCCEEDED, fail_count, FAILED, total_time))
76-
print(build_separator)
40+
return succeeded
41+
42+
43+
if __name__ == '__main__':
44+
# remove build folder first
45+
subprocess.run("rm -rf _build/", shell=True)
46+
47+
# All supported boards
48+
all_boards = []
49+
for entry in os.scandir("src/boards"):
50+
if entry.is_dir():
51+
all_boards.append(entry.name)
52+
all_boards.sort()
53+
54+
print(build_separator)
55+
print(build_format.format('Board', '\033[39mResult\033[0m', 'Time', 'Flash', 'SRAM'))
56+
print(build_separator)
57+
58+
success_count = 0
59+
total_time = time.monotonic()
60+
61+
with Pool(processes=os.cpu_count()) as pool:
62+
success_count = sum(pool.map(build_board, all_boards))
63+
64+
total_time = time.monotonic() - total_time
65+
fail_count = len(all_boards) - success_count
66+
67+
# Build Summary
68+
print(build_separator)
69+
print(
70+
"Build Summary: {} {}, {} {} and took {:.2f}s".format(success_count, SUCCEEDED, fail_count, FAILED, total_time))
71+
print(build_separator)
7772

78-
sys.exit(exit_status)
73+
sys.exit(fail_count)

0 commit comments

Comments
 (0)