-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
219 lines (184 loc) · 7.17 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
PROJ_DIR := $(shell pwd)
SDK_ROOT := ./_sdk
SDK_TEMP := ./_sdk_temp
OTA_DIR := ./_ota
BUILD_DIR := ./_build
OUT_DIR := ./_out
TOOLCHAIN_DIR := ./_toolchain
BOOTLOADER_DIR := ./bootloader
DFU_DIR := ./dfu
SDK_CONFIG_DIR := ./sdk_config
MAIN_DIR := ./main
BIN_DIR := ./bin
SOURCE_DIR := ./src
INCLUDE_DIR := ./include
EXTERNAL_DIR := ./external
PROTO_DIR := ./proto
SETTINGS := settings
BL_SETTINGS := bl_settings
BL_SETTINGS_SD := bl_settings_sd
NANOPB_DIR := $(EXTERNAL_DIR)/nanopb
NANOPB_GEN := $(NANOPB_DIR)/generator/nanopb_generator.py
# Board definition and Git versioning
include Makefile.ver
include Makefile.bid
# Check for errors. These should be set in the app.
ifndef PROG_SERIAL
$(info PROG_SERIAL not set. Using default of 1234)
PROG_SERIAL := 682978319
endif
ifndef PROG_PORT
$(info PROG_PORT not set. Using default of 19020)
PROG_PORT := 19021
endif
ifndef APP_FILENAME
$(info APP_FILENAME not set. Using default of 19020)
APP_FILENAME := pyrinas
endif
msg = Building app for $(BOARD_DESC).
$(info )
$(info $(msg))
$(info )
# Cert for DFU
DFU_CERT := private.pem
# Commands
NRFJPROG := $(BIN_DIR)/nrfjprog/nrfjprog
MERGEHEX := $(BIN_DIR)/mergehex/mergehex
NRFUTIL := $(BIN_DIR)/nrfutil/nrfutil-mac
# Download and install SDK deps
SDK_ZIP := .nrf_sdk.zip
NRF_SDK_FOLDER_NAME := nRF5_SDK_16.0.0_98a08e2.zip
NRF_SDK_URL := https://developer.nordicsemi.com/nRF5_SDK/nRF5_SDK_v16.x.x/nRF5_SDK_16.0.0_98a08e2.zip
NRF_SDK_MD5 := cc2ccb57d2c7159fd37f9e04fca6cc64
GCC_ARCHIVE := .gcc-arm-none-eabi-6-2017-q2-update-mac.tar.bz2
GCC_OUTPUT_FOLDER := gcc-arm-none-eabi-6-2017-q2-update
GCC_URL := https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-rm/6-2017q2/gcc-arm-none-eabi-6-2017-q2-update-mac.tar.bz2
GCC_MD5 := d536d7fb167c04b24f7f0d40cd739cac
# Soft device info
SOFT_DEVICE := $(SDK_ROOT)/components/softdevice/$(BUILD_SD)/hex/$(BUILD_SD)_$(BUILD_SD_VER)_softdevice.hex
# Protocol Buffers
PROTO_SRC := $(wildcard $(PROTO_DIR)/*.proto)
PROTO_PB := $(PROTO_SRC:.proto=.pb)
.PHONY: sdk sdk_clean setup clean build debug merge merge_all erase flash flash_all flash_softdevice ota settings default gen_key toolchain toolchain_clean sdk sdk_clean
default: build
gen_key:
@echo Generating pem key. You should only run this once!
cd $(DFU_DIR) && ../$(NRFUTIL) keys generate private.pem
cd $(DFU_DIR) && ../$(NRFUTIL) keys display --key pk --format code private.pem > dfu_public_key.c
settings:
@echo Generating settings .hex file
@mkdir -p $(BUILD_DIR)
$(NRFUTIL) settings generate --family $(BOARD_FAM) --application $(MAIN_DIR)/_build/$(BUILD_IDENT).hex --application-version-string $(VER_STRING) --bootloader-version 1 --bl-settings-version 1 $(BUILD_DIR)/$(SETTINGS).hex
build:
@export GCC_ARM_TOOLCHAIN=$(PROJ_DIR)/$(TOOLCHAIN_DIR) DEBUG=$(DEBUG) && make -C $(MAIN_DIR) clean_app
@export GCC_ARM_TOOLCHAIN=$(PROJ_DIR)/$(TOOLCHAIN_DIR) DEBUG=$(DEBUG) && make -C $(BOOTLOADER_DIR) -j
@export GCC_ARM_TOOLCHAIN=$(PROJ_DIR)/$(TOOLCHAIN_DIR) DEBUG=$(DEBUG) && make -C $(MAIN_DIR) -j
merge: build settings
@mkdir -p $(BUILD_DIR)
@mkdir -p $(OUT_DIR)
@echo Merging settings with bootloader
@$(MERGEHEX) -m $(BOOTLOADER_DIR)/_build/$(BUILD_IDENT)_$(BUILD_SD).hex $(BUILD_DIR)/$(SETTINGS).hex -o $(BUILD_DIR)/$(BL_SETTINGS).hex
@echo Merging app with bootloader + settings
@$(MERGEHEX) -m $(BUILD_DIR)/$(BL_SETTINGS).hex $(MAIN_DIR)/_build/$(BUILD_IDENT).hex -o $(OUT_DIR)/$(APP_FILENAME).app.$(VER_STRING_W_GITHASH).combined.hex
merge_all: merge
@echo Merging all files
@$(MERGEHEX) -m $(SOFT_DEVICE) $(OUT_DIR)/$(APP_FILENAME).app.$(VER_STRING_W_GITHASH).combined.hex -o $(OUT_DIR)/$(APP_FILENAME).app.$(VER_STRING_W_GITHASH).full.hex
flash_all: merge_all
@echo Flashing all
$(NRFJPROG) -f nrf52 --program $(OUT_DIR)/$(APP_FILENAME).app.$(VER_STRING_W_GITHASH).full.hex --chiperase -s $(PROG_SERIAL)
@$(NRFJPROG) -f nrf52 --reset -s $(PROG_SERIAL)
flash: merge
@echo Flashing firmware
$(NRFJPROG) -f nrf52 --program $(OUT_DIR)/$(APP_FILENAME).app.$(VER_STRING_W_GITHASH).combined.hex --sectoranduicrerase -s $(PROG_SERIAL)
@$(NRFJPROG) -f nrf52 --reset -s $(PROG_SERIAL)
flash_softdevice:
@echo Flashing softdevice
$(NRFJPROG) -f nrf52 --program $(SOFT_DEVICE) --sectorerase -s $(PROG_SERIAL)
@$(NRFJPROG) -f nrf52 --reset -s $(PROG_SERIAL)
erase:
@echo Erasing device
$(NRFJPROG) -e -s $(PROG_SERIAL)
ota: build
@echo Generating OTA package
@mkdir -p $(OTA_DIR)
$(NRFUTIL) pkg generate --sd-req $(NRFUTIL_SD_REQ) --hw-version 52 --key-file $(DFU_DIR)/$(DFU_CERT) \
--application-version-string $(VER_STRING) --application $(MAIN_DIR)/_build/$(BUILD_IDENT).hex \
$(OTA_DIR)/$(APP_FILENAME).app.$(VER_STRING_W_GITHASH).zip
debug:
@echo Debug using JLinkExe
JLinkExe -device NRF52 -speed 4000 -if SWD -autoconnect 1 -SelectEmuBySN $(PROG_SERIAL) -RTTTelnetPort $(PROG_PORT)
rtt:
jlinkrttclient -RTTTelnetPort $(PROG_PORT)
setup: toolchain sdk
@git submodule update --init --recursive
@echo Pyrinas setup complete!
sdk:
@echo Installing NRF SDK
@if [ ! -d $(SDK_ROOT) ]; then \
if [ ! -f $(SDK_ZIP) ]; then \
echo Downloading sdk deps...; \
curl -o $(SDK_ZIP) $(NRF_SDK_URL); \
fi; \
if [ "`md5 -q $(SDK_ZIP)`" != "$(NRF_SDK_MD5)" ]; then \
echo SDK archive MD5 does not match. Please re-run make setup.; \
rm -f $(SDK_ZIP); \
exit 1; \
fi; \
if [ ! -f $(SDK_ROOT) ]; then \
unzip $(SDK_ZIP) -d $(SDK_ROOT); \
fi; \
fi;
@echo Copyiing toolchain configuration file..
@cp -f $(SDK_CONFIG_DIR)/Makefile.posix $(SDK_ROOT)/components/toolchain/gcc/
@echo Building Microecc
@cp -f $(SDK_CONFIG_DIR)/build_all.sh $(SDK_ROOT)/external/micro-ecc/
@cd $(SDK_ROOT)/external/micro-ecc/ && export GCC_ARM_TOOLCHAIN=$(PROJ_DIR)/$(TOOLCHAIN_DIR) && sh build_all.sh
@echo SDK deps download and install complete.
@rm -rf $(SDK_ZIP) $(SDK_TEMP) $(GCC_ARCHIVE)
toolchain:
@echo Installing OSX tools
@if [ ! -d $(TOOLCHAIN_DIR) ]; then \
if [ ! -f $(GCC_ARCHIVE) ]; then \
echo Downloading gcc...; \
curl -o $(GCC_ARCHIVE) $(GCC_URL); \
fi; \
if [ "`md5 -q $(GCC_ARCHIVE)`" != "$(GCC_MD5)" ]; then \
echo GCC archive MD5 does not match. Please re-run make setup.; \
rm -f $(GCC_ARCHIVE); \
exit 1; \
fi; \
if [ ! -d $(GCC_OUTPUT_FOLDER) ]; then \
tar jxfkv $(GCC_ARCHIVE); \
fi; \
if [ -d $(GCC_OUTPUT_FOLDER) ]; then \
mv $(GCC_OUTPUT_FOLDER) $(TOOLCHAIN_DIR); \
fi; \
fi;
@echo Removing temporary files.
@rm -rf $(GCC_ARCHIVE)
%.pb: %.proto
protoc -I$(PROTO_DIR) --go_out=$(PROTO_DIR) $<
protoc -I$(PROTO_DIR) -o$*.pb $<
@$(NANOPB_GEN) -I$(PROTO_DIR) $@
pbjs -t static-module -p$(PROTO_DIR) $*.proto > $@.js
@mkdir -p $(SOURCE_DIR)/proto
@mkdir -p $(INCLUDE_DIR)/proto
@mv $*.pb.c $(SOURCE_DIR)/proto
@mv $*.pb.h $(INCLUDE_DIR)/proto
protoc -I$(PROTO_DIR) --cpp_out=$(PROTO_DIR) $<
protobuf: protoclean $(PROTO_PB)
@echo building the protocol buffers $(PROTO_PB)
protoclean:
@rm -fr $(PROTO_DIR)/*.pb
sdk_clean:
@echo SDK Clean..
@rm -rf $(SDK_ROOT)
@rm -f $(SDK_ZIP)
toolchain_clean:
@echo Toolchain Clean..
@rm -rf $(TOOLCHAIN_DIR)
@rm -f $(GCC_ARCHIVE)
clean:
@echo Cleaning..
@rm -rf $(BUILD_DIR)
@make -C $(MAIN_DIR) clean