-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
340 lines (296 loc) · 13 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
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
# By default, let's print out some help
.PHONY: usage
usage:
@echo "$$(tput bold)Welcome to libtock-rs!$$(tput sgr0)"
@echo
@echo "First things first, if you haven't yet, check out Tocks's doc/Getting_Started."
@echo "After that read the README from libtock-rs"
@echo "You'll need to install a few requirements before we get going."
@echo
@echo "The next step is to choose a board to build Tock for. Mainline"
@echo "libtock-rs currently includes support for the following platforms:"
@echo " - hail"
@echo " - nrf52840"
@echo " - microbit_v2"
@echo " - nucleo_f429zi"
@echo " - nucleo_f446re"
@echo " - opentitan"
@echo " - hifive1"
@echo " - nrf52"
@echo " - imxrt1050"
@echo " - apollo3"
@echo " - stm32f3discovery"
@echo " - stm32f412gdiscovery"
@echo " - esp32_c3_devkitm_1"
@echo " - clue_nrf52840"
@echo
@echo "Run 'make setup' to setup Rust to build libtock-rs."
@echo "Run 'make <board> EXAMPLE=<>' to build EXAMPLE for that board."
@echo "Run 'make flash-<board> EXAMPLE=<>' to flash EXAMPLE to a tockloader-supported board."
@echo "Run 'make qemu-example EXAMPLE=<>' to run EXAMPLE in QEMU"
@echo "Run 'make test' to test any local changes you have made"
@echo "Run 'make print-sizes' to print size data for the example binaries"
ifdef FEATURES
features=--features=$(FEATURES)
endif
ifndef DEBUG
release=--release
endif
.PHONY: setup
setup: setup-qemu
cargo install elf2tab
cargo miri setup
rustup target add --toolchain stable thumbv7em-none-eabi
# Sets up QEMU in the tock/ directory. We use Tock's QEMU which may contain
# patches to better support boards that Tock supports.
.PHONY: setup-qemu
setup-qemu:
CI=true $(MAKE) -C tock ci-setup-qemu
# Builds a Tock 2.0 kernel for the HiFive board for use by QEMU tests.
.PHONY: kernel-hifive
kernel-hifive:
$(MAKE) -C tock/boards/hifive1 \
$(CURDIR)/tock/target/riscv32imac-unknown-none-elf/release/hifive1.elf
# Builds a Tock kernel for the OpenTitan board on the cw310 FPGA for use by QEMU
# tests.
.PHONY: kernel-opentitan
kernel-opentitan:
CARGO_TARGET_RISCV32IMC_UNKNOWN_NONE_ELF_RUNNER="[]" \
$(MAKE) -C tock/boards/opentitan/earlgrey-cw310 \
$(CURDIR)/tock/target/riscv32imc-unknown-none-elf/release/earlgrey-cw310.elf
# Prints out the sizes of the example binaries.
.PHONY: print-sizes
print-sizes: examples
cargo run --release -p print_sizes
# Runs a libtock example in QEMU on a simulated HiFive board.
.PHONY: qemu-example
qemu-example: kernel-hifive
LIBTOCK_PLATFORM="hifive1" cargo run --example "$(EXAMPLE)" -p libtock \
--release --target=riscv32imac-unknown-none-elf -- --deploy qemu
# Build the examples on both a RISC-V target and an ARM target. We pick
# opentitan as the RISC-V target because it lacks atomics.
.PHONY: examples
examples:
LIBTOCK_PLATFORM=nrf52 cargo build --examples --release \
--target=thumbv7em-none-eabi
LIBTOCK_PLATFORM=opentitan cargo build --examples --release \
--target=riscv32imc-unknown-none-elf
# Arguments to pass to cargo to exclude crates that require a Tock runtime.
# This is largely libtock_runtime and crates that depend on libtock_runtime.
# Used when we need to build a crate for the host OS, as libtock_runtime only
# supports running on Tock.
EXCLUDE_RUNTIME := --exclude libtock --exclude libtock_runtime \
--exclude libtock_debug_panic --exclude libtock_small_panic
# Arguments to pass to cargo to exclude crates that cannot be tested by Miri. In
# addition to excluding libtock_runtime, Miri also cannot test proc macro crates
# (and in fact will generate broken data that causes cargo test to fail).
EXCLUDE_MIRI := $(EXCLUDE_RUNTIME) --exclude ufmt-macros
# Arguments to pass to cargo to exclude `std` and crates that depend on it. Used
# when we build a crate for an embedded target, as those targets lack `std`.
EXCLUDE_STD := --exclude libtock_unittest --exclude print_sizes \
--exclude runner --exclude syscalls_tests
# Currently, all of our crates should build with a stable toolchain. This
# verifies our crates don't depend on unstable features by using cargo check. We
# specify a different target directory so this doesn't flush the cargo cache of
# the primary toolchain.
.PHONY: test-stable
test-stable:
CARGO_TARGET_DIR="target/stable-toolchain" cargo +stable check --workspace \
$(EXCLUDE_RUNTIME)
CARGO_TARGET_DIR="target/stable-toolchain" LIBTOCK_PLATFORM=nrf52 cargo \
+stable check $(EXCLUDE_STD) --target=thumbv7em-none-eabi --workspace
.PHONY: test
test: examples test-stable
cargo test $(EXCLUDE_RUNTIME) --workspace
LIBTOCK_PLATFORM=nrf52 cargo fmt --all -- --check
cargo clippy --all-targets $(EXCLUDE_RUNTIME) --workspace
LIBTOCK_PLATFORM=nrf52 cargo clippy $(EXCLUDE_STD) \
--target=thumbv7em-none-eabi --workspace
LIBTOCK_PLATFORM=hifive1 cargo clippy $(EXCLUDE_STD) \
--target=riscv32imac-unknown-none-elf --workspace
MIRIFLAGS="-Zmiri-strict-provenance -Zmiri-symbolic-alignment-check" \
cargo miri test $(EXCLUDE_MIRI) --workspace
echo '[ SUCCESS ] libtock-rs tests pass'
.PHONY: apollo3
apollo3:
LIBTOCK_PLATFORM=apollo3 cargo run --example $(EXAMPLE) $(features) \
--target=thumbv7em-none-eabi $(release)
mkdir -p target/tbf/apollo3
cp target/thumbv7em-none-eabi/release/examples/$(EXAMPLE).tab \
target/thumbv7em-none-eabi/release/examples/$(EXAMPLE).tbf \
target/tbf/apollo3
.PHONY: esp32_c3_devkitm_1
esp32_c3_devkitm_1:
LIBTOCK_PLATFORM=esp32_c3_devkitm_1 cargo run --example $(EXAMPLE) $(features) \
--target=riscv32imc-unknown-none-elf $(release)
mkdir -p target/tbf/esp32_c3_devkitm_1
cp target/riscv32imc-unknown-none-elf/release/examples/$(EXAMPLE).tab \
target/riscv32imc-unknown-none-elf/release/examples/$(EXAMPLE).tbf \
target/tbf/esp32_c3_devkitm_1
.PHONY: hail
hail:
LIBTOCK_PLATFORM=hail cargo run --example $(EXAMPLE) $(features) \
--target=thumbv7em-none-eabi $(release)
mkdir -p target/tbf/hail
cp target/thumbv7em-none-eabi/release/examples/$(EXAMPLE).tab \
target/thumbv7em-none-eabi/release/examples/$(EXAMPLE).tbf \
target/tbf/hail
.PHONY: flash-hail
flash-hail:
LIBTOCK_PLATFORM=hail cargo run --example $(EXAMPLE) $(features) \
--target=thumbv7em-none-eabi $(release) -- --deploy=tockloader
.PHONY: microbit_v2
microbit_v2:
LIBTOCK_PLATFORM=microbit_v2 cargo run --example $(EXAMPLE) $(features) \
--target=thumbv7em-none-eabi $(release)
mkdir -p target/tbf/microbit_v2
cp target/thumbv7em-none-eabi/release/examples/$(EXAMPLE).tab \
target/thumbv7em-none-eabi/release/examples/$(EXAMPLE).tbf \
target/tbf/microbit_v2
.PHONY: flash-microbit_v2
flash-microbit_v2:
LIBTOCK_PLATFORM=microbit_v2 cargo run --example $(EXAMPLE) $(features) \
--target=thumbv7em-none-eabi $(release) -- --deploy=tockloader
.PHONY: nucleo_f429zi
nucleo_f429zi:
LIBTOCK_PLATFORM=nucleo_f429zi cargo run --example $(EXAMPLE) $(features) \
--target=thumbv7em-none-eabi $(release)
mkdir -p target/tbf/nucleo_f429zi
cp target/thumbv7em-none-eabi/release/examples/$(EXAMPLE).tab \
target/thumbv7em-none-eabi/release/examples/$(EXAMPLE).tbf \
target/tbf/nucleo_f429zi
.PHONY: nucleo_f446re
nucleo_f446re:
LIBTOCK_PLATFORM=nucleo_f446re cargo run --example $(EXAMPLE) $(features) \
--target=thumbv7em-none-eabi $(release)
mkdir -p target/tbf/nucleo_f446re
cp target/thumbv7em-none-eabi/release/examples/$(EXAMPLE).tab \
target/thumbv7em-none-eabi/release/examples/$(EXAMPLE).tbf \
target/tbf/nucleo_f446re
.PHONY: nrf52840
nrf52840:
LIBTOCK_PLATFORM=nrf52840 cargo run --example $(EXAMPLE) $(features) \
--target=thumbv7em-none-eabi $(release)
mkdir -p target/tbf/nrf52840
cp target/thumbv7em-none-eabi/release/examples/$(EXAMPLE).tab \
target/thumbv7em-none-eabi/release/examples/$(EXAMPLE).tbf \
target/tbf/nrf52840
.PHONY: flash-nrf52840
flash-nrf52840:
LIBTOCK_PLATFORM=nrf52840 cargo run --example $(EXAMPLE) $(features) \
--target=thumbv7em-none-eabi $(release) -- --deploy=tockloader
.PHONY: raspberrypi_pico
raspberrypi_pico:
LIBTOCK_PLATFORM=raspberrypi_pico cargo run --example $(EXAMPLE) $(features) \
--target=thumbv6m-none-eabi $(release)
mkdir -p target/tbf/raspberrypi_pico
cp target/thumbv6m-none-eabi/release/examples/$(EXAMPLE).tab \
target/thumbv6m-none-eabi/release/examples/$(EXAMPLE).tbf \
target/tbf/raspberrypi_pico
.PHONY: nano_rp2040_connect
nano_rp2040_connect:
LIBTOCK_PLATFORM=nano_rp2040_connect cargo run --example $(EXAMPLE) $(features) \
--target=thumbv6m-none-eabi $(release)
mkdir -p target/tbf/nano_rp2040_connect
cp target/thumbv6m-none-eabi/release/examples/$(EXAMPLE).tab \
target/thumbv6m-none-eabi/release/examples/$(EXAMPLE).tbf \
target/tbf/nano_rp2040_connect
.PHONY: stm32f3discovery
stm32f3discovery:
LIBTOCK_PLATFORM=stm32f3discovery cargo run --example $(EXAMPLE) \
$(features) --target=thumbv7em-none-eabi $(release)
mkdir -p target/tbf/stm32f3discovery
cp target/thumbv7em-none-eabi/release/examples/$(EXAMPLE).tab \
target/thumbv7em-none-eabi/release/examples/$(EXAMPLE).tbf \
target/tbf/stm32f3discovery
.PHONY: stm32f412gdiscovery
stm32f412gdiscovery:
LIBTOCK_PLATFORM=stm32f412gdiscovery cargo run --example $(EXAMPLE) \
$(features) --target=thumbv7em-none-eabi $(release)
mkdir -p target/tbf/stm32f412gdiscovery
cp target/thumbv7em-none-eabi/release/examples/$(EXAMPLE).tab \
target/thumbv7em-none-eabi/release/examples/$(EXAMPLE).tbf \
target/tbf/stm32f412gdiscovery
.PHONY: opentitan
opentitan:
LIBTOCK_PLATFORM=opentitan cargo run --example $(EXAMPLE) $(features) \
--target=riscv32imc-unknown-none-elf $(release)
mkdir -p target/tbf/opentitan
cp target/riscv32imc-unknown-none-elf/release/examples/$(EXAMPLE).tab \
target/riscv32imc-unknown-none-elf/release/examples/$(EXAMPLE).tbf \
target/tbf/opentitan
.PHONY: hifive1
hifive1:
LIBTOCK_PLATFORM=hifive1 cargo run --example $(EXAMPLE) $(features) \
--target=riscv32imac-unknown-none-elf $(release)
mkdir -p target/tbf/hifive1
cp target/riscv32imac-unknown-none-elf/release/examples/$(EXAMPLE).tab \
target/riscv32imac-unknown-none-elf/release/examples/$(EXAMPLE).tbf \
target/tbf/hifive1
.PHONY: nrf52
nrf52:
LIBTOCK_PLATFORM=nrf52 cargo run --example $(EXAMPLE) $(features) \
--target=thumbv7em-none-eabi $(release)
mkdir -p target/tbf/nrf52
cp target/thumbv7em-none-eabi/release/examples/$(EXAMPLE).tab \
target/thumbv7em-none-eabi/release/examples/$(EXAMPLE).tbf \
target/tbf/nrf52
.PHONY: flash-nrf52
flash-nrf52:
LIBTOCK_PLATFORM=nrf52 cargo run --example $(EXAMPLE) $(features) \
--target=thumbv7em-none-eabi $(release) -- --deploy=tockloader
.PHONY: imxrt1050
imxrt1050:
LIBTOCK_PLATFORM=imxrt1050 cargo run --example $(EXAMPLE) $(features) \
--target=thumbv7em-none-eabi $(release)
mkdir -p target/tbf/imxrt1050
cp target/thumbv7em-none-eabi/release/examples/$(EXAMPLE).tab \
target/thumbv7em-none-eabi/release/examples/$(EXAMPLE).tbf \
target/tbf/imxrt1050
.PHONY: msp432
msp432:
LIBTOCK_PLATFORM=msp432 cargo run --example $(EXAMPLE) $(features) \
--target=thumbv7em-none-eabi $(release)
mkdir -p target/tbf/msp432
cp target/thumbv7em-none-eabi/release/examples/$(EXAMPLE).tab \
target/thumbv7em-none-eabi/release/examples/$(EXAMPLE).tbf \
target/tbf/msp432
.PHONY: clue_nrf52840
clue_nrf52840:
LIBTOCK_PLATFORM=clue_nrf52840 cargo run --example $(EXAMPLE) $(features) \
--target=thumbv7em-none-eabi $(release)
mkdir -p target/tbf/clue_nrf52840
cp target/thumbv7em-none-eabi/release/examples/$(EXAMPLE).tab \
target/thumbv7em-none-eabi/release/examples/$(EXAMPLE).tbf \
target/tbf/clue_nrf52840
.PHONY: flash-clue_nrf52840
flash-clue_nrf52840:
LIBTOCK_PLATFORM=clue_nrf52840 cargo run --example $(EXAMPLE) $(features) \
--target=thumbv7em-none-eabi $(release) -- --deploy=tockloader
THIS_FILE := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
CHERI_SDK ?= $(abspath ${HOME}/cheri/output/sdk)
CHERI_LIBC ?= $(CHERI_SDK)/baremetal/baremetal-newlib-riscv$(BITS)-hybrid/riscv$(BITS)-unknown-elf
# We need to expand the linker path here
# For whatever reason, the cfg target.'cfg(any(target_arch = \"riscv32\", target_arch = \"riscv64\"))' fails here,
# So I wrote out all the expected targets.
CHERI_CARGO_FLAGS := -Z build-std=core,compiler_builtins,alloc \
--config "target.riscv32imac-unknown-none-elf.linker='${CHERI_SDK}/bin/lld'" \
--config "target.riscv64imac-unknown-none-elf.linker='${CHERI_SDK}/bin/lld'" \
--config "target.riscv32imac-unknown-none-cheri-hybrid-elf.linker='${CHERI_SDK}/bin/lld'" \
--config "target.riscv64imac-unknown-none-cheri-hybrid-elf.linker='${CHERI_SDK}/bin/lld'" \
CHERI_CARGO_PARAMS := LIBTOCK_PLATFORM=riscv CHERI_SDK=${CHERI_SDK} CHERI_LIBC=${CHERI_LIBC}
.PHONY: qemu_rv64
qemu_rv64:
${CHERI_CARGO_PARAMS} ABI=riscv64 cargo run --example $(EXAMPLE) $(features) $(CHERI_CARGO_FLAGS) \
--target=riscv64imac-unknown-none-elf $(release)
.PHONY: qemu_rv64xcheri
qemu_rv64xcheri:
${CHERI_CARGO_PARAMS} ABI=riscv64-hybrid cargo run --example $(EXAMPLE) $(features) $(CHERI_CARGO_FLAGS) \
--target=riscv64imac-unknown-none-cheri-hybrid-elf $(release)
.PHONY: run_qemu_rv64xcheri
run_qemu_rv64xcheri: qemu_rv64xcheri
APP_BIN=$(abspath target/riscv64imac-unknown-none-cheri-hybrid-elf/release/examples/$(EXAMPLE).tbf) make -C tock/boards/qemu_cheri_virt run_app
.PHONY: clean
clean:
cargo clean
$(MAKE) -C tock clean