forked from AdaCore/bb-runtimes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_rts.py
executable file
·376 lines (341 loc) · 11.1 KB
/
build_rts.py
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
370
371
372
373
374
375
376
#! /usr/bin/env python3
#
# Copyright (C) 2016-2020, AdaCore
#
# Python script to gather files for the bareboard runtime.
# Don't use any fancy features. Ideally, this script should work with any
# Python version starting from 2.6 (yes, it's very old but that's the system
# python on oldest host).
from support import Compiler, set_target_compiler
from support.files_holder import FilesHolder
from support.bsp_sources.installer import Installer
from support.docgen import docgen
# PikeOS
from pikeos import AArch64PikeOS5, ArmPikeOS, ArmPikeOS42, ArmPikeOS5, \
PPCPikeOS5
# Cortex-M runtimes
from arm.cortexm import Stm32, Stm32l, Sam, SmartFusion2, LM3S, Microbit, \
NRF52840, NRF52832, MicrosemiM1, Stm32F0, RP2040Target, \
CortexM0, CortexM0P, CortexM1, CortexM3, CortexM4, CortexM4F, \
CortexM7F, CortexM7DF, CortexM23, CortexM33F, CortexM33DF
# Cortex-A/R runtimes
from arm.cortexar import TMS570, Rpi2, Rpi2Mc, Zynq7000, ZynqmpR5
# Aarch64
from aarch64 import Rpi3, Rpi3Mc, ZynqMP
# Deos
from deos import ArmDeos
# leon
from sparc import Leon2, Leon3, Leon4
# powerpc
from powerpc import MPC5200, MPC8641, MPC8349e, Virtex5, P2020, P5566, P5634
# riscv
from riscv import Spike, PolarFireSOC, HiFive1, \
RV32I, RV32IM, RV32IAC, RV32IMAC, RV32IMAFC, RV32IMAFDC, \
RV64IM, RV64IMC, RV64IMAC, RV64IMAFC, RV64IMFC, RV64IMAFDC
# visium
from visium import Visium
# x86_64
from x86_64 import X8664Generic, X8664Muen
# native
from native import X86Native, X8664Native
# vx7r2cert
from vx7r2cert import AArch64Vx7r2Cert, ArmVx7r2Cert, \
PPCVx7r2Cert, PPC64Vx7r2Cert, \
X86Vx7r2Cert, X86_64Vx7r2Cert, \
AArch64Vx7r2Cert_RTP, ArmVx7r2Cert_RTP, \
PPCVx7r2Cert_RTP, PPC64Vx7r2Cert_RTP, \
X86Vx7r2Cert_RTP, X86_64Vx7r2Cert_RTP
from qnx import Aarch64QNX, ARMQNX
import argparse
import os
import subprocess
import sys
def build_configs(target):
# PikeOS
if target == 'aarch64-pikeos5':
t = AArch64PikeOS5()
elif target == 'arm-pikeos':
t = ArmPikeOS()
elif target == 'arm-pikeos4.2':
t = ArmPikeOS42()
elif target == 'arm-pikeos5':
t = ArmPikeOS5()
elif target == 'ppc-pikeos5':
t = PPCPikeOS5()
# AArch64 elf
elif target == 'rpi3':
t = Rpi3()
elif target == 'rpi3mc':
t = Rpi3Mc()
elif target == 'zynqmp':
t = ZynqMP()
# ARM elf
elif target == 'zynq7000':
t = Zynq7000()
elif target == 'zynqmpr5':
t = ZynqmpR5()
elif target == 'rpi2':
t = Rpi2()
elif target == 'rpi2mc':
t = Rpi2Mc()
elif target in RP2040Target.supported_targets:
t = RP2040Target(target)
elif target.startswith('sam'):
t = Sam(target)
elif target.startswith('smartfusion2'):
t = SmartFusion2()
elif target.startswith('stm32f0'):
t = Stm32F0(target)
elif target.startswith('stm32l'):
t = Stm32l(target)
elif target.startswith('stm32'):
t = Stm32(target)
elif target == 'feather_stm32f405':
t = Stm32(target)
elif target == 'nucleo_f401re':
t = Stm32(target)
elif target == 'openmv2':
t = Stm32(target)
elif target == 'tms570':
# by default, the TMS570LS3137 HDK board
t = TMS570('tms570ls31')
elif target == 'tms570_sci':
# by default, the TMS570LS3137 HDK board
t = TMS570('tms570ls31', uart_io=True)
elif target == 'tms570lc':
# alias for the TMS570LC43x HDK board
t = TMS570('tms570lc43', uart_io=True)
elif target == 'tms570lc_dcc':
t = TMS570('tms570lc43', uart_io=False)
elif target == 'lm3s':
t = LM3S()
elif target == 'microbit':
t = Microbit()
elif target == 'nrf52840':
t = NRF52840()
elif target == 'nrf52832':
t = NRF52832()
elif target == "microsemi-m1":
t = MicrosemiM1()
elif target == 'cortex-m0':
t = CortexM0()
elif target == 'cortex-m0p':
t = CortexM0P()
elif target == 'cortex-m1':
t = CortexM1()
elif target == 'cortex-m3':
t = CortexM3()
elif target == 'cortex-m4':
t = CortexM4()
elif target == 'cortex-m4f':
t = CortexM4F()
elif target == 'cortex-m7f':
t = CortexM7F()
elif target == 'cortex-m7df':
t = CortexM7DF()
elif target == 'cortex-m23':
t = CortexM23()
elif target == 'cortex-m33f':
t = CortexM33F()
elif target == 'cortex-m33df':
t = CortexM33DF()
elif target == 'arm-deos':
t = ArmDeos()
# SPARC/Leon elf
elif target == 'leon2' or target == 'leon':
t = Leon2()
elif target == 'leon3':
t = Leon3(smp=False)
elif target == 'leon3-smp':
t = Leon3(smp=True)
elif target == 'leon4':
t = Leon4(smp=False)
elif target == 'leon4-smp':
t = Leon4(smp=True)
# PPC elf
elif target == 'mpc5200':
t = MPC5200()
elif target == 'mpc8641':
t = MPC8641()
elif target == '8349e':
t = MPC8349e()
elif target == 'p2020':
t = P2020()
elif target == 'p5566':
t = P5566()
elif target == 'mpc5634':
t = P5634()
elif target == 'virtex5':
t = Virtex5()
# Visium elf
elif target == 'mcm':
t = Visium()
# Risc-V
elif target == 'spike':
t = Spike()
elif target == 'hifive1':
t = HiFive1()
elif target == 'polarfiresoc':
t = PolarFireSOC()
elif target == "rv32i":
t = RV32I()
elif target == "rv32im":
t = RV32IM()
elif target == "rv32iac":
t = RV32IAC()
elif target == "rv32imac":
t = RV32IMAC()
elif target == "rv32imafc":
t = RV32IMAFC()
elif target == "rv32imafdc":
t = RV32IMAFDC()
elif target == "rv64im":
t = RV64IM()
elif target == "rv64imc":
t = RV64IMC()
elif target == "rv64imac":
t = RV64IMAC()
elif target == "rv64imafc":
t = RV64IMAFC()
elif target == "rv64imfc":
t = RV64IMFC()
elif target == "rv64imafdc":
t = RV64IMAFDC()
# x86_64
elif target == 'x86_64':
t = X8664Generic()
elif target == 'x86_64-muen':
t = X8664Muen()
elif target in ('x86-linux', 'x86-windows'):
t = X86Native()
elif target in ('x86_64-linux', 'x86_64-windows', 'x86_64-windows64'):
t = X8664Native()
# vx7r2cert
elif target == "aarch64-vx7r2cert":
t = AArch64Vx7r2Cert()
elif target == "arm-vx7r2cert":
t = ArmVx7r2Cert()
elif target == "ppc-vx7r2cert":
t = PPCVx7r2Cert()
elif target == "ppc64-vx7r2cert":
t = PPC64Vx7r2Cert()
elif target == "x86-vx7r2cert":
t = X86Vx7r2Cert()
elif target == "x86_64-vx7r2cert":
t = X86_64Vx7r2Cert()
elif target == "aarch64-vx7r2cert-rtp":
t = AArch64Vx7r2Cert_RTP()
elif target == "arm-vx7r2cert-rtp":
t = ArmVx7r2Cert_RTP()
elif target == "ppc-vx7r2cert-rtp":
t = PPCVx7r2Cert_RTP()
elif target == "ppc64-vx7r2cert-rtp":
t = PPC64Vx7r2Cert_RTP()
elif target == "x86-vx7r2cert-rtp":
t = X86Vx7r2Cert_RTP()
elif target == "x86_64-vx7r2cert-rtp":
t = X86_64Vx7r2Cert_RTP()
elif target == "aarch64-qnx":
t = Aarch64QNX()
elif target == "arm-qnx":
t = ARMQNX()
else:
print('Error: undefined target %s' % target)
sys.exit(2)
return t
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
'-v', '--verbose', action="store_true",
help='Verbose output')
parser.add_argument(
'-f', '--force', action="store_true",
help=('Forces the installation by overwriting '
'any pre-existing runtime.'))
parser.add_argument(
'--rts-src-descriptor',
help='The runtime source descriptor file (rts-sources.json)')
parser.add_argument(
'--gen-doc', action="store_true",
help='Generate the documentation')
parser.add_argument(
'--compiler', default='gnat',
help='The compiler to generate flags for (gnat or gnat_llvm, defaults to gnat)')
parser.add_argument(
'-o', '--output', default='install',
help='Where built runtimes will be installed')
parser.add_argument(
'-l', '--link', action="store_true",
help="Use symlinks instead of copies when installing")
parser.add_argument(
'-b', '--build', action="store_true",
help="Build the runtimes")
parser.add_argument(
'--build-flags', help="Flags passed to gprbuild")
parser.add_argument(
'--shared', action="store_true",
help='Additionally build shared runtime '
'(only available on platforms that support shared libraries)')
parser.add_argument(
'target', nargs='+',
help='List of target boards to generate runtimes for')
args = parser.parse_args()
if args.verbose:
FilesHolder.verbose = True
if args.link:
FilesHolder.link = True
if args.force:
Installer.overwrite = True
set_target_compiler(Compiler[args.compiler])
boards = []
if len(args.target) == 1 and args.target[0].endswith("vx7r2cert"):
args.target.append(args.target[0] + "-rtp")
for arg in args.target:
board = build_configs(arg)
boards.append(board)
dest = os.path.abspath(args.output)
if not os.path.exists(dest):
os.makedirs(dest)
# README file generation
if args.gen_doc:
# figure out the target
target = boards[0].target
for board in boards:
assert target == board.target, \
"cannot generate rts doc for different compiler targets"
doc_dir = os.path.join(dest, 'doc')
docgen(boards, target, doc_dir)
# and do nothing else
return
if not os.path.exists(dest):
os.makedirs(dest)
# Install the runtimes sources
projects = []
for board in boards:
print("install runtime sources for %s" % board.name)
sys.stdout.flush()
installer = Installer(board)
projects += installer.install(
dest, rts_descriptor=args.rts_src_descriptor)
# and build them
if args.build:
for prj in projects:
print("building project %s" % prj)
sys.stdout.flush()
cmd = ['gprbuild', '-j0', '-p', '-v', '-P', prj]
if args.build_flags is not None:
cmd += args.build_flags.split()
subprocess.check_call(cmd)
if args.shared:
cmd.extend(["-f", "-XLIBRARY_TYPE=dynamic"])
subprocess.check_call(cmd)
# Post-process: remove build artifacts from obj directory
cleanup_ext = ('.o', '.ali', '.stdout', '.stderr', '.d', '.lexch')
obj_dir = os.path.join(os.path.dirname(prj), 'obj')
for fname in os.listdir(obj_dir):
_, ext = os.path.splitext(fname)
if ext in cleanup_ext:
os.unlink(os.path.join(obj_dir, fname))
print("runtimes successfully installed in %s" % dest)
if __name__ == '__main__':
main()