forked from CHERIoT-Platform/cheriot-rtos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrules.build2
369 lines (286 loc) · 9.68 KB
/
rules.build2
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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
# Make sure we have build2 0.17.0-a.0.20240522060352.5a791d140e30 or later.
#
if! ($build.version.major > 0 || \
$build.version.minor > 17 || \
($build.version.minor == 17 && (!$build.version.snapshot || \
$build.version.snapshot_sn >= 20240522060352)))
fail "build2 version $build.version is too old"
config [string] config.cheriot_rtos.board
if! $defined(config.cheriot_rtos.board)
fail 'config.cheriot_rtos.board must be specified'
import! [dir_path] sdk = cheriot-rtos%dir{sdk}
board_file = $sdk/boards/$(config.cheriot_rtos.board).json
if! $file_exists($board_file)
fail "unknown board '$config.cheriot_rtos.board': file $board_file does not exist"
[json_object] board = $json.load($board_file)
# Dump the board JSON if running with -V or higher (useful for debugging).
#
if ($build.verbosity >= 3)
info $serialize($board)
revoker = ($board[revoker])
devices = $object_names($board[devices])
simulation = ($board[simulation] != [null] ? $board[simulation] : false)
stack_hwm = ($board[stack_high_water_mark] != [null] ? $board[stack_high_water_mark] : false)
revokable_memory_start = ($board[revokable_memory_start])
if ($revokable_memory_start == [null])
revokable_memory_start = ($board[instruction_memory][start])
interrupt_names = [string, null]
interrupt_config = [string, null]
for i: ($board[interrupts])
{
na = ($i[name])
nu = ($i[number])
pr = ($i[priority])
et = ($i[edge_triggered] != [null] ? $i[edge_triggered] : false)
interrupt_names += "($interrupt_names != [null] ? ', ' : )$na=$nu"
interrupt_config += "($interrupt_config != [null] ? ', ' : ){$nu,$pr,$et}"
}
# Report key information about the board.
#
config [config.report.module=cheriot-rtos] revoker
config [config.report.module=cheriot-rtos] devices
config [config.report.module=cheriot-rtos] simulation
# Load the `in` module for firmware.ldscript.in processing.
#
using in
cxx.std = 20
c.std = 2x
# Specify these options as compiler mode (as opposed to in cc.coptions below)
# so that they are taken into account when detecting target, search paths,
# etc.
#
cxx.mode = -target riscv32-unknown-unknown -nostdinc
c.mode = -target riscv32-unknown-unknown -nostdinc
using cxx
using c
using c.as-cpp
hxx{*}: extension = h
cxx{*}: extension = cc
# Toolchain.
#
[dir_path] toolchain = $directory($effect($cxx.path))
[path] ld = $toolchain/ld.lld
[path] objdump = $toolchain/llvm-objdump
# Default and board options.
#
cc.coptions += \
-Qunused-arguments \
-mcpu=cheriot -mabi=cheriot -mxcheri-rvc -mrelax \
-fshort-wchar -fomit-frame-pointer -fno-builtin -fno-exceptions \
-fno-asynchronous-unwind-tables -fno-c++-static-destructors -fno-rtti \
-Oz -g \
-Werror
cxx.poptions += "-I$sdk/include/c++-config" "-I$sdk/include/libc++"
cc.poptions += "-I$sdk/include"
for i: ($board[driver_includes])
cc.poptions += "-I$sdk/include/$i"
cc.poptions += -DTEMPORAL_SAFETY
for d: ($board[defines])
cc.poptions += "-D$d"
# These come from the board JSON file.
#
cc.poptions += \
"-DCPU_TIMER_HZ=($board[timer_hz])" \
"-DTICK_RATE_HZ=($board[tickrate_hz])" \
"-DREVOKABLE_MEMORY_START=$string($revokable_memory_start, 16, 8)"
if $stack_hwm
cc.poptions += -DCONFIG_MSHWM
if ($interrupt_names != [null])
cc.poptions += "-DCHERIOT_INTERRUPT_NAMES=$interrupt_names"
if $simulation
cc.poptions += -DSIMULATION
for d: $devices
cc.poptions += "-DDEVICE_EXISTS_$d"
# Note: alias the ldscript{} target type from cheriot-rtos instead of deriving
# a new one since some of the scripts come from there.
#
define ldscript = $sdk/ldscript
ldscript{*}: extension = ldscript
# Pre-enter variables used in firmware.ldscript.in.
#
# @@ It would be better to give them names that are private to cheriot-rtos,
# say cheriot_rtos.mmio. Then we could fix their types and make them
# target-specific.
#
ldscript{*}:
{
mmio = [null]
}
define library: file
library{*}: extension = library
[rule_name=link_library] library{~'/(.+)/'}: $sdk/ldscript{library} $ld
% update clean
recipe c++ link-compartment.cxx
define privileged_library: file
privileged_library{*}: extension = library
# Note: linked with the privileged compartment linker script.
#
[rule_name=link_privileged_library] privileged_library{~'/(.+)/'}: \
$sdk/ldscript{privileged-compartment} $ld
% update clean
recipe c++ link-compartment.cxx
define compartment: file
compartment{*}: extension = compartment
[rule_name=link_compartment] compartment{~'/(.+)/'}: \
$sdk/ldscript{compartment} $ld
% update clean
recipe c++ link-compartment.cxx
define privileged_compartment: file
privileged_compartment{*}: extension = compartment
[rule_name=link_privileged_compartment] privileged_compartment{~'/(.+)/'}: \
$sdk/ldscript{privileged-compartment} $ld
% update clean
recipe c++ link-compartment.cxx
# Place all the cheriot-rtos-supplied targets into the cheriot-rtos/ so that
# they don't clash with user's. Inside mimic the source directory structure.
#
# @@ TODO: tighten linker script to only recognize special compartments
# (allocator, scheduler, etc) inside cheriot-rtos/?
#
cheriot-rtos/
{
core/
{
# @@ TODO: comes from somewhere?
#
cc.poptions += -DCHERIOT_AVOID_CAPRELOCS
# The scheduler compartment is specific to the firmware (depends on the
# number of threads) and we assume a project may want to produce multiple
# firmwares in the same build. So we synthesize the appropriate
# dependecies in the link_firmware rule to include the firmware name into
# this compartment's name and its object file names.
#
scheduler/
{
# @@ TODO: some come from board JSON and user's firmware configuration.
#
cc.poptions += \
-DSCHEDULER_ACCOUNTING=false \
-DDEBUG_SCHEDULER=false
if ($interrupt_config != [null])
cc.poptions += "-DCHERIOT_INTERRUPT_CONFIGURATION=$interrupt_config"
cc.coptions += -cheri-compartment=sched
fsdir{./}: fsdir{../}
}
privileged_compartment{allocator}: allocator/obje{main} fsdir{./}
allocator/
{
cc.poptions += -DDEBUG_ALLOCATOR=false -DNDEBUG
cc.coptions += -cheri-compartment=alloc -fvisibility=hidden
cxx.coptions += -fvisibility-inlines-hidden
obje{main}: $sdk/core/allocator/cxx{main} fsdir{./}
fsdir{./}: fsdir{../}
}
privileged_library{token_library}: token_library/obje{token_unseal} fsdir{./}
token_library/
{
cc.poptions += -DNDEBUG -DDEBUG_TOKEN_LIBRARY=false
cc.coptions += -fvisibility=hidden
obje{token_unseal}: $sdk/core/token_library/S{token_unseal} fsdir{./}
fsdir{./}: fsdir{../}
}
loader/
{
# @@ TODO: comes from somewhere.
#
cc.poptions += \
-DDEBUG_LOADER=false \
-DNDEBUG \
-DCHERIOT_LOADER_STACK_SIZE=1024 \
-DCHERIOT_LOADER_TRUSTED_STACK_SIZE=192
cc.coptions += -fvisibility=hidden
cxx.coptions += -fvisibility-inlines-hidden
obje{boot-s}: $sdk/core/loader/S{boot} fsdir{./}
obje{boot-c}: $sdk/core/loader/cxx{boot} fsdir{./}
{
cc.coptions += -O1
}
fsdir{./}: fsdir{../}
}
switcher/
{
cc.poptions += -DNDEBUG
cc.coptions += -fvisibility=hidden
obje{entry}: $sdk/core/switcher/S{entry} fsdir{./}
fsdir{./}: fsdir{../}
}
fsdir{./}: fsdir{../}
}
lib/
{
cc.poptions += -DNDEBUG
cc.coptions += -fvisibility=hidden
cxx.coptions += -fvisibility-inlines-hidden
library{atomic1}: atomic1/obje{atomic1} fsdir{./}
atomic1/
{
obje{atomic1}: $sdk/lib/atomic/cxx{atomic1} fsdir{./}
fsdir{./}: fsdir{../}
}
library{atomic4}: atomic4/obje{atomic4} fsdir{./}
atomic4/
{
obje{atomic4}: $sdk/lib/atomic/cxx{atomic4} fsdir{./}
fsdir{./}: fsdir{../}
}
library{locks}: locks/obje{locks semaphore} fsdir{./}
locks/
{
obje{locks}: $sdk/lib/locks/cxx{locks} fsdir{./}
obje{semaphore}: $sdk/lib/locks/cxx{semaphore} fsdir{./}
fsdir{./}: fsdir{../}
}
library{crt}: crt/obje{cz} fsdir{./}
crt/
{
obje{cz}: $sdk/lib/crt/c{cz} fsdir{./}
fsdir{./}: fsdir{../}
}
library{freestanding}: freestanding/obje{memcmp memcpy memset} fsdir{./}
freestanding/
{
# @@ These are built without NDEBUG/-fvisibility=hidden. Wonder if an
# omission or intentional?
#
cc.poptions = $regex.filter_out_match($cc.poptions, '^-DNDEBUG$')
cc.coptions = $regex.filter_out_match($cc.coptions, '^--fvisibility=hidden$')
obje{memcmp}: $sdk/lib/freestanding/c{memcmp} fsdir{./}
obje{memcpy}: $sdk/lib/freestanding/c{memcpy} fsdir{./}
obje{memset}: $sdk/lib/freestanding/c{memset} fsdir{./}
fsdir{./}: fsdir{../}
}
fsdir{./}: fsdir{../}
}
}
define firmware: file
firmware{*}: extension =
# The user is expected to set the `threads` variable on each firmware{}
# target. It should be a JSON array with one or more JSON object elements
# each containing the following members:
#
# [string] compartment
# [uint64] priority
# [string] entry_point
# [uint64] stack_size
# [uint64] trusted_stack_frames
#
firmware{*}:
{
[json_array, visibility=target] threads = [null]
}
define dump: file
dump{*}: extension = dump
define json: file
json{*}: extension = json
# Note: the order in which we specify things to link is no significant.
#
[rule_name=link_firmware] <firmware{~'/(.+)/'} dump{^'/\1/'} json{^'/\1/'}>: \
compartment{~'/(.+)/'} \
cheriot-rtos/core/loader/obje{boot-s boot-c} \
cheriot-rtos/core/switcher/obje{entry} \
cheriot-rtos/lib/library{atomic1 atomic4 locks crt} \
cheriot-rtos/core/privileged_library{token_library} \
cheriot-rtos/core/privileged_compartment{allocator} \
$ld $objdump
% update clean
recipe c++ link-firmware.cxx