-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
244 lines (194 loc) · 8.65 KB
/
Copy pathMakefile
File metadata and controls
244 lines (194 loc) · 8.65 KB
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# Root directory variables
MAKEFILE_PATH := $(abspath $(firstword $(MAKEFILE_LIST)))
MAKEFILE_DIR := $(abspath $(dir $(MAKEFILE_PATH)))
ROOT_DIR := $(abspath $(MAKEFILE_DIR))
# This is the path where your compute module is located (e.g. /dev/disk4).
# Can be overridden with `make DEVICE=<your-device> target...`.
DEVICE ?= /dev/disk4
SUDO := $(shell OWNER=$$(stat -c '%U' $(DEVICE) 2>/dev/null || stat -f '%Su' $(DEVICE) 2>/dev/null); [ "$$OWNER" = "root" ] && echo "sudo" || echo "")
# This is the compute module hardware variant you are using.
# The supported options are:
# - `SIGNALOID_C0_MICROSD`
# - `SIGNALOID_C0_MICROSD_PLUS`
# - `SIGNALOID_C0_SD`.
#
# Can be overridden with `make DEVICE_TYPE=<your-device-type> target...`.
DEVICE_TYPE ?= SIGNALOID_C0_MICROSD_PLUS
PYTHON := python3 -u
VENV_DIR ?= $(ROOT_DIR)/.venv
SIGNALOID_CLI ?= signaloid-cli
# Set variables based on DEVICE_TYPE
ifeq ($(DEVICE_TYPE),SIGNALOID_C0_MICROSD)
# Signaloid C0-microSD core IDs
CORE_ID_C0_microSD_N := cor_271d544c73a8544d9026252652342972
CORE_ID_C0_microSD_N_plus := cor_c1cde893b0d75bb6a8941e9caf90f2a6
CORE_ID_C0_microSD_XS := cor_808bbbb9932c5d29a58370a1ec9a859f
CORE_ID_C0_microSD_XS_plus := cor_3d8dfc5d4f305e16b867716fe6aba1e9
# Set the core ID to use for the build
CORE_ID :=$(CORE_ID_C0_microSD_N)
FLASH_TARGET := flash-C0-microSD
DEVICE_VARIANT := C0-microSD
else ifeq ($(DEVICE_TYPE),SIGNALOID_C0_MICROSD_PLUS)
# Signaloid C0-microSD+ core IDs
CORE_ID_C0_microSD_plus_N := cor_1faf6bb2d7d5522ea7fa8d0abb5f8287
CORE_ID_C0_microSD_plus_N_plus := cor_47178d2437f95276961d2b1311f6efb7
CORE_ID_C0_microSD_plus_XS := cor_fec16af93c525850a49abe6ddbe9a434
CORE_ID_C0_microSD_plus_XS_plus := cor_28cfadb7a9535ddf9dffbdeaa41b0f20
CORE_ID_C0_microSD_plus_S := cor_b4bca7fa91c95e17bba1c210d2485eb1
CORE_ID_C0_microSD_plus_S_plus := cor_b3d7e24ecca45da7b3752304e1230f02
# Set the core ID to use for the build
CORE_ID := $(CORE_ID_C0_microSD_plus_N)
FLASH_TARGET := flash-C0-microSD-Plus
DEVICE_VARIANT := C0-microSD+
else ifeq ($(DEVICE_TYPE),SIGNALOID_C0_SD)
# Signaloid C0-SD core IDs
CORE_ID_C0_SD_N := cor_619f4edfb5105bb39dd50c115c2796d2
CORE_ID_C0_SD_N_plus := cor_bc2312a696d356d3bab92ff5fbfe7520
CORE_ID_C0_SD_XS := cor_aeafaef723f156f898e5826c9c4631bf
CORE_ID_C0_SD_XS_plus := cor_ee31a158687a5c3c85f13f9000937ad2
CORE_ID_C0_SD_S := cor_d446925a40fc53ec90b805c7cea736f9
CORE_ID_C0_SD_S_plus := cor_a378e7ea331e53ed83f760bbe2c6a04c
# Set the core ID to use for the build
CORE_ID := $(CORE_ID_C0_SD_N)
FLASH_TARGET := flash-C0-SD
DEVICE_VARIANT := C0-SD
else
$(error "Invalid DEVICE_TYPE specified. Please set DEVICE_TYPE to one of: SIGNALOID_C0_MICROSD, SIGNALOID_C0_MICROSD_PLUS, SIGNALOID_C0_SD")
endif
# Repo URL and branch to build
REPO_URL := $(shell git remote get-url origin | sed s,git@github.com:,https://github.com/,)
REPO_BRANCH := $(shell git branch --show-current)
# Signaloid-Compute-Module-Utilities submodule directory
UTILITIES_DIR := $(ROOT_DIR)/submodules/Signaloid-Compute-Module-Utilities
# Build directory
BUILD_DIR := signaloid-soc-application
REPO_ID_FILE := $(ROOT_DIR)/.repo_id
REPO_ID=$(shell cat $(REPO_ID_FILE) 2> /dev/null)
BUILD_ID_FILE := $(ROOT_DIR)/.build_id
BUILD_ID=$(shell cat $(BUILD_ID_FILE) 2> /dev/null)
BINARY_FILENAME = $(BUILD_ID).main.bin
BINARY_FILE = $(ROOT_DIR)/$(BUILD_DIR)/$(BINARY_FILENAME)
# Toolkits
MICROSD_TOOLKIT := $(SUDO) $(PYTHON) $(UTILITIES_DIR)/C0_microSD_toolkit.py -t $(DEVICE)
SD_TOOLKIT := $(SUDO) $(PYTHON) $(UTILITIES_DIR)/C0_SD_toolkit.py $(DEVICE) --variant=$(DEVICE_VARIANT)
C0_LOGGER := $(SUDO) $(PYTHON) $(UTILITIES_DIR)/C0_debug_logger.py $(DEVICE) --variant=$(DEVICE_VARIANT)
# Enable Global "Exit on Error" for shell commands
.SHELLFLAGS := -ec
all: download
print-% : ; @echo $* = $($*)
# Search for the repo in Signaloid Cloud Developer Platform.
# If it doesn't exist, connect it.
connect $(REPO_ID_FILE):
@RESPONSE=$$($(SIGNALOID_CLI) repos lookup \
--url $(REPO_URL) \
--branch $(REPO_BRANCH)); \
REPO_ID=$$(echo $$RESPONSE | jq -r '.RepositoryID'); \
if [ "$$REPO_ID" = "null" ]; then \
RESPONSE=$$($(SIGNALOID_CLI) repos connect \
--url $(REPO_URL) \
--branch $(REPO_BRANCH) \
--dir $(BUILD_DIR) \
--core-id $(CORE_ID)); \
REPO_ID=$$(echo $$RESPONSE | jq -r '.RepositoryID'); \
fi; \
echo $$REPO_ID > $(REPO_ID_FILE)
# Update an already connected repo:
# - Update branch and fetch latest commit
# - Update build directory
# - Update selected Core ID
update: $(REPO_ID_FILE)
@RESPONSE=$$($(SIGNALOID_CLI) repos update \
--repo-id $(REPO_ID) \
--branch $(REPO_BRANCH) \
--dir $(BUILD_DIR) \
--core-id $(CORE_ID))
# Create a build for the repo
build $(BUILD_ID_FILE): $(REPO_ID_FILE)
@RESPONSE=$$($(SIGNALOID_CLI) builds create:repo --repo-id $(REPO_ID)); \
BUILD_ID=$$(echo $$RESPONSE | jq -r '.BuildID'); \
echo $$BUILD_ID > $(BUILD_ID_FILE); \
$(SIGNALOID_CLI) builds watch --build-id $$BUILD_ID; \
$(SIGNALOID_CLI) builds output --build-id $$BUILD_ID;
# Download the build binary
download $(BINARY_FILE): $(BUILD_ID_FILE)
@$(SIGNALOID_CLI) builds binary \
--build-id $(BUILD_ID) \
--out $(BUILD_DIR) \
--filename $(BINARY_FILENAME)
# Delete the build id and its binary
clean:
@$(RM) $(BINARY_FILE)
@$(RM) $(BUILD_ID_FILE)
# Delete the build id, its binary, and the connected repo id
clean-all: clean
@$(RM) $(REPO_ID_FILE)
# Flashing targets
flash: $(FLASH_TARGET)
flash-C0-microSD: $(BINARY_FILE)
@echo "\n- Flashing: Signaloid C0-microSD [$(DEVICE)]"
@file_size=$$(ls -l $(BINARY_FILE) | awk '{print $$5}'); \
if [ "$${file_size}" -gt 131072 ]; then \
echo "Error: Binary file is too large ($$file_size bytes)."; \
exit 1; \
fi
@$(MICROSD_TOOLKIT) -b $(BINARY_FILE) -U -p 128K
flash-C0-microSD-Plus: $(BINARY_FILE) stop
@echo "\n- Flashing: Signaloid C0-microSD+ [$(DEVICE)]"
@$(SD_TOOLKIT) flash-application $(BINARY_FILE)
flash-C0-SD: $(BINARY_FILE) stop
@echo "\n- Flashing: Signaloid C0-SD [$(DEVICE)]"
@$(SD_TOOLKIT) flash-application $(BINARY_FILE)
# Switch mode (Bootloader - Signaloid SoC) of the C0-microSD
switch:
@echo "\n- Switching: Signaloid C0-microSD [$(DEVICE)]"
@$(MICROSD_TOOLKIT) -s
# Start the Signaloid SoC core
start:
@$(SD_TOOLKIT) config core-start
# Stop the Signaloid SoC core
stop:
@$(SD_TOOLKIT) config core-stop
# Reset the Signaloid SoC core
reset: stop start
# Print the compute module debug logs continuously
POLLING_RATE ?= 1
log:
$(C0_LOGGER) --polling-rate=$(POLLING_RATE);
# Print the compute module debug logs
log-once:
@echo "- Device logs:"
$(C0_LOGGER) --one-shot --no-clear;
# Print the compute module debug logs as a hex-dump
hex-dump:
@echo "- Device log hex-dump:"
$(C0_LOGGER) --hex-dump --one-shot --no-clear;
# Print the compute module debug logs as a list of uint32_t hex numbers
uint-dump:
@echo "- Device log uint-dump:"
$(C0_LOGGER) --uint-dump --one-shot --no-clear;
# Print the compute module info
info:
@echo "- Device info:"
$(SD_TOOLKIT) info
# Create the virtual environment needed for running the host application
venv $(VENV_DIR):
@echo "\n- Creating virtual environment in $(VENV_DIR)"
@$(PYTHON) -m venv $(VENV_DIR)
@$(VENV_DIR)/bin/pip install --upgrade pip
@$(VENV_DIR)/bin/pip install -r $(ROOT_DIR)/python-host-application/requirements.txt
# Base command to run the host application
RUN_CMD=$(SUDO) $(VENV_DIR)/bin/python3 -u $(ROOT_DIR)/python-host-application/host_application.py --device-path $(DEVICE) --variant $(DEVICE_VARIANT)
SELECTED_RUN_CMD?=$(RUN_CMD)
# Run multiple host application commands. Useful for testing.
run-all: $(VENV_DIR)
@echo "\n- Running the host application"
$(SELECTED_RUN_CMD) CalculateAddition 5.0 6.0 4.0 7.5
@echo "\n- Finished successfully"
# Iterations to use for benchmarking
ITERATIONS ?= 20
# Base command to run the host application in benchmark mode
RUN_BENCH_CMD=$(RUN_CMD) --benchmark --iterations "${ITERATIONS}"
# Benchmark application commands. Useful for testing.
bench-all:
@echo "\n- Start benchmarking"
@$(MAKE) -e SELECTED_RUN_CMD="$(RUN_BENCH_CMD)" run-all