forked from AdaCore/bb-runtimes
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild_rts.py
executable file
·274 lines (244 loc) · 7.62 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
#! /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.files_holder import FilesHolder
from support.bsp_sources.installer import Installer
from support.docgen import docgen
# PikeOS
from pikeos import ArmPikeOS, ArmPikeOS42, ArmPikeOS5
# Cortex-M runtimes
from arm.cortexm import Stm32, Sam, SmartFusion2, LM3S, Microbit, \
NRF52840, NRF52832, MicrosemiM1, \
CortexM0, CortexM0P, CortexM1, CortexM3, CortexM4, CortexM4F, \
CortexM7F, CortexM7DF
# Cortex-A/R runtimes
from arm.cortexar import TMS570, Rpi2, Rpi2Mc, Zynq7000
# Aarch64
from aarch64 import Rpi3, Rpi3Mc, ZynqMP
# leon
from sparc import Leon2, Leon3, Leon4
# m68k
from m68k import M68020, M68020_SoftFloat
# powerpc
from powerpc import MPC8641, MPC8349e, P2020, P5566, P5634
# riscv
from riscv import Spike, Unleashed, HiFive1, PicoRV32, RV32IMC
# visium
from visium import Visium
# native
from native import X86Native, X8664Native
import argparse
import os
import subprocess
import sys
def build_configs(target):
# PikeOS
if target == 'arm-pikeos':
t = ArmPikeOS()
elif target == 'arm-pikeos4.2':
t = ArmPikeOS42()
elif target == 'arm-pikeos5':
t = ArmPikeOS5()
# 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 == 'rpi2':
t = Rpi2()
elif target == 'rpi2mc':
t = Rpi2Mc()
elif target.startswith('sam'):
t = Sam(target)
elif target.startswith('smartfusion2'):
t = SmartFusion2()
elif target.startswith('stm32'):
t = Stm32(target)
elif target == 'feather_stm32f405':
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()
# 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)
# m68k elf
elif target == 'm68020':
t = M68020()
elif target == 'm68020-softfloat':
t = M68020_SoftFloat()
# PPC elf
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()
# Visium elf
elif target == 'mcm':
t = Visium()
# Risc-V
elif target == 'spike':
t = Spike()
elif target == 'hifive1':
t = HiFive1()
elif target == 'unleashed':
t = Unleashed()
elif target == 'picorv32':
t = PicoRV32()
elif target == 'rv32imc':
t = RV32IMC()
# native platforms
elif target == 'x86-linux':
t = X86Native()
elif target == 'x86-windows':
t = X86Native()
elif target == 'x86_64-linux':
t = X8664Native()
elif target == 'x86_64-windows':
t = X8664Native()
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(
'-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(
'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
boards = []
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', '-P', prj]
if args.build_flags is not None:
cmd += args.build_flags.split()
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()