-
Notifications
You must be signed in to change notification settings - Fork 3
/
autofile.py
221 lines (178 loc) · 7.39 KB
/
autofile.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
import logging
import os.path
from pathlib import Path
from automate.utils import fix_symlinks
from automate.utils.network import rsync
from invoke import task
ROOT_PATH = Path(os.path.dirname(os.path.abspath(__file__)))
JAILHOUSE_REPO = "https://github.com/siemens/jailhouse.git"
JAILHOUSE_COMMIT = "master" # GIT branch or sha or tag to use
JAILHOUSE_PATH = ROOT_PATH / "jailhouse"
JAILHOUSE_BOARDS = ["jetsontx2", "raspberrypi4b-jh1"]
@task
def update(c, reset=False):
"""Update the jailhouse from github"""
if not JAILHOUSE_PATH.exists():
c.run(f"git clone {JAILHOUSE_REPO} {JAILHOUSE_PATH}")
with c.cd(str(JAILHOUSE_PATH)):
if reset:
c.run("git reset --hard")
try:
c.run("git pull")
except Exception as e:
logging.fatal("Git pull failed")
logging.fatal(
"You might wan't to try 'automate-run update --reset' to reset the jailhouse checkout before pulling"
)
logging.info("Error: %s", str(e))
return -1
c.run(f"git checkout '{JAILHOUSE_COMMIT}'")
@task
def build(c, board_ids="all", sync_kernel=False, ignore_dtb=False):
"Build jailhouse hypervisor and kernel module for target system"
if board_ids == "all":
board_ids = JAILHOUSE_BOARDS
else:
board_ids = board_ids.split(",")
with c.cd(str(ROOT_PATH)):
c.run("mkdir -p builds")
c.run("mkdir -p kernels")
for board_id in board_ids:
board = c.board(board_id)
cross_compiler = board.compiler()
kernel_name = "default"
for kernel_desc in board.os.kernels:
if kernel_desc.name == "jailhouse":
kernel_name = "jailhouse"
kernel_data = board.kernel_data(kernel_name)
build_cache_path = kernel_data.build_cache_path
if not build_cache_path.exists():
logging.warning(
f"Could not find cached kernel build directory for board {board.id} in {str(build_cache_path)} "
)
logging.warning("Skipping jailhouse build")
continue
kernel_path = ROOT_PATH / "kernels" / board_id / kernel_name
if not kernel_path.exists() or sync_kernel:
print("Getting cached kernel build")
c.run(f"mkdir -p {kernel_path}")
c.run(
f"cp {build_cache_path} kernels/{board.name}/{kernel_name}"
)
with c.cd(f"kernels/{board.id}/{kernel_name}"):
c.run(f"tar xJf {kernel_data.build_cache_name}")
kernel_arch = kernel_data.arch
kdir = (
ROOT_PATH
/ "kernels"
/ board.name
/ kernel_name
/ kernel_data.srcdir
)
kdir = os.path.realpath(kdir.absolute())
dest_dir = ROOT_PATH / "builds" / board.name / "jailhouse"
cross_compile = cross_compiler.bin_path / cross_compiler.prefix
c.run(f"mkdir -p {dest_dir}")
c.run(f"rsync -r --delete jailhouse/ {dest_dir}")
with c.cd(str(dest_dir)):
result = c.run(
f"make CROSS_COMPILE={cross_compile} KDIR={kdir} ARCH={kernel_arch} V=1",
warn=True,
)
if result.return_code != 0:
logging.error("Could not build with device trees")
if not ignore_dtb:
logging.error("to retry without dtbs try --ignore-dtb")
return result.return_code
logging.error("retrying build without device trees")
c.run(
"rm -rf configs/*/dts"
) # Currently does not build for many targets
result = c.run(
f"make CROSS_COMPILE={cross_compile} KDIR={kdir} ARCH={kernel_arch} V=1",
warn=True,
)
@task
def deploy(c, board_ids="all"):
"Install the built jailhouse hypervisor and kernel module on the board"
if board_ids == "all":
board_ids = JAILHOUSE_BOARDS
else:
board_ids = board_ids.split(",")
with c.cd(str(ROOT_PATH)):
for board_id in board_ids:
board = c.board(board_id)
build_dir = ROOT_PATH / "builds" / board_id / "jailhouse"
with board.connect() as con:
rsync(con, str(build_dir), str(board.rundir))
with con.cd(str(board.rundir / "jailhouse")):
con.run("sudo cp hypervisor/jailhouse.bin /lib/firmware")
@task
def extract(c, board_ids="all"):
"Extract board information"
if board_ids == "all":
board_ids = JAILHOUSE_BOARDS
else:
board_ids = board_ids.split(",")
with c.cd(str(ROOT_PATH)):
for board_id in board_ids:
board = c.board(board_id)
files = [
"/sys/bus/pci/devices/*/config",
"/sys/bus/pci/devices/*/resource",
"/sys/devices/system/cpu/cpu*/uevent",
"/sys/firmware/acpi/tables/APIC",
"/sys/firmware/acpi/tables/MCFG",
"/sys/firmware/devicetree",
"/proc/iomem",
"/proc/cpuinfo",
"/proc/cmdline",
"/proc/ioports",
]
with board.lock_ctx():
with board.connect() as con:
con.run(f"sudo rm -rf /tmp/{board_id}")
con.run(f"mkdir -p /tmp/{board_id}")
for file in files:
con.run(
f"sudo cp -r --parents {file} /tmp/{board_id}",
warn=True,
)
with con.cd("/tmp"):
print(f"creating {board_id}.tar.gz")
con.run(f"sudo rm -f {board_id}.tar.gz")
con.run(f"sudo tar cvzf {board_id}.tar.gz {board_id}")
c.run("mkdir -p board_data")
print("Getting data")
con.get(
f"/tmp/{board_id}.tar.gz",
f"board_data/{board_id}.tar.gz",
)
con.run(
f"sudo rm -rf /tmp/{board_id}.tar.gz /tmp/{board_id}/"
)
with c.cd("board_data"):
c.run(f"tar xvzf {board_id}.tar.gz")
c.run("chown -R ${USER} board_data/")
c.run("chmod -R ug+wr board_data")
fix_symlinks(f"board_data/{board_id}")
@task
def pre_commit(c):
"Installs pre commit hooks"
root_path = Path(os.path.dirname(os.path.abspath(__file__)))
with c.cd(str(root_path)):
c.run("pre-commit install")
@task
def build_kernels(c, config_name="jailhouse"):
"Build kernel configs for jailhouse"
for board_name in JAILHOUSE_BOARDS:
board = c.board(board_name)
for kernel in board.os.kernels:
if kernel.name == config_name:
kernel_builder = board.builder(
"kernel", f"kernels/{board_name}/{config_name}"
)
kernel_builder.configure(config_name)
kernel_builder.build()
kernel_builder.install()
kernel_builder.deploy()