-
Notifications
You must be signed in to change notification settings - Fork 0
/
do.sh
executable file
·301 lines (258 loc) · 7.65 KB
/
do.sh
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
#!/bin/bash
set -e
#target=konservendose
target=testrack
#hw_target=testrack-noel
hw_target=jv
cmd=$1
buildroot=$(realpath srcs/buildroot/)
dts=$(realpath srcs/dts/)
busybox=$(realpath srcs/busybox/)
jailhouse=$(realpath srcs/jailhouse/)
linux=$(realpath srcs/linux/)
qemu=$(realpath srcs/qemu/)
opensbi=$(realpath srcs/opensbi/)
res=$(realpath res/)
# requires absolute path
dst_busybox="$PWD/build/busybox/"
dst_buildroot_root="$PWD/build/buildroot_root/"
dst_buildroot_non_root="$PWD/build/buildroot_non_root/"
dst_initrd="$PWD/build/initrd/"
dst_rootfs="$dst_initrd/rootfs/"
dst_f_initrd="$dst_initrd/initramfs.cpio"
dst_linux="$PWD/build/linux/"
dst_opensbi="$PWD/build/opensbi/"
dst_qemu="$PWD/build/qemu/"
dtb="$PWD/build/dtb/"
buildroot_root_overlay="$PWD/build/buildroot_root_overlay"
buildroot_non_root_overlay="$PWD/build/buildroot_non_root_overlay"
busybox_res="$res/busybox/"
nproc=$(nproc)
MAKE="make -j $(nproc)"
. setenv
INITRD="$dst_buildroot_root/images/rootfs.cpio.gz"
#INITRD="$dst_buildroot_non_root/images/rootfs.cpio.gz"
#INITRD="$dst_initrd/initramfs.cpio.gz"
DTB_QEMU="$dtb/qemu"
function debug() {
${CROSS_COMPILE}gdb -q
}
function prepare_buildroot() {
cd $buildroot
make O=$dst_buildroot_root defconfig
make O=$dst_buildroot_non_root defconfig
cd ../..
cp res/buildroot_root-config $dst_buildroot_root/.config
cp res/buildroot_non_root-config $dst_buildroot_non_root/.config
cd $dst_buildroot_root
make oldconfig
cd $dst_buildroot_non_root
make oldconfig
}
function prepare_non_root_overlay() {
# Prepare non-root overlay
mkdir -p $buildroot_non_root_overlay/etc/systemd/network \
$buildroot_non_root_overlay/root/.ssh
cp -av res/1-jailhouse-non-root.network $buildroot_non_root_overlay/etc/systemd/network/
tar -xvf res/ssh.tar -C $buildroot_non_root_overlay/
cp -v res/authorized_keys $buildroot_non_root_overlay/root/.ssh/
echo bash > $buildroot_non_root_overlay/root/.bash_login
}
function prepare_root_overlay() {
# Prepare root overlay
mkdir -p $buildroot_root_overlay/usr/bin/ \
$buildroot_root_overlay/root/.ssh \
$buildroot_root_overlay/etc/jailhouse \
$buildroot_root_overlay/usr/lib/firmware/ \
$buildroot_root_overlay/etc/systemd/network/
tar -xvf res/ssh.tar -C $buildroot_root_overlay/
# comment out for more space
cp -v build/buildroot_non_root/images/rootfs.cpio.gz $buildroot_root_overlay/root/
cp -v $KERNEL $buildroot_root_overlay/root/
cp -v res/authorized_keys $buildroot_root_overlay/root/.ssh/
cp -v res/bash_history $buildroot_root_overlay/root/.bash_history
cp -v res/bashrc $buildroot_root_overlay/root/.bashrc
echo bash > $buildroot_root_overlay/root/.bash_login
cp -av $jailhouse/driver/jailhouse.ko $buildroot_root_overlay/root/
cp -av $jailhouse/hypervisor/jailhouse.bin $buildroot_root_overlay/usr/lib/firmware
cp -av $jailhouse/tools/jailhouse $buildroot_root_overlay/usr/bin/
cp -av $jailhouse/tools/jailhouse-cell-stats $buildroot_root_overlay/usr/bin/
cp -av $jailhouse/configs/riscv/*.cell $buildroot_root_overlay/etc/jailhouse/
cp -av $jailhouse/configs/riscv/dts/*.dtb $buildroot_root_overlay/etc/jailhouse
cp -av $jailhouse/inmates/demos/riscv/*.bin $buildroot_root_overlay/etc/jailhouse
cp -av $jailhouse/inmates/tools/riscv/*.bin $buildroot_root_overlay/etc/jailhouse
cp -av res/scripts/* $buildroot_root_overlay/usr/bin/
cp -av res/1-jailhouse-root.network $buildroot_root_overlay/etc/systemd/network/
}
function buildroot() {
prepare_non_root_overlay
# Build buildroot for non-root cell
cd $dst_buildroot_non_root
make
cd ../..
prepare_root_overlay
cd $dst_buildroot_root
make
}
function start_qemu() {
mkdir -p $dtb
if [[ $1 == "uc" ]]; then
CPUS=1
elif [[ $1 == "mc" ]]; then
CPUS=6
else
echo "Unknown config $1"
exit -1
fi
$QEMU \
-monitor null \
-cpu rv64,h=true -smp cpus=$CPUS \
-m 1G \
-display none \
-serial mon:stdio \
-monitor telnet:127.0.0.1:55555,server,nowait \
-kernel $KERNEL \
-initrd $INITRD \
-machine $QEMU_MACHINE \
-netdev user,id=net,hostfwd=::33333-:22,hostfwd=::33344-:23 \
-device e1000e,addr=2.0,netdev=net \
-append "mem=768M ip=dhcp" \
-s
}
function build_initrd() {
cd $dst_rootfs
mkdir -p root
# comment out to save space (rocket)
cp -av $KERNEL ./root/
cp -av ../../buildroot_non_root/images/rootfs.cpio.gz ./root/
mkdir -p ./etc/jailhouse
cp -av $jailhouse/configs/riscv/dts/*.dtb \
$jailhouse/configs/riscv/*.cell \
$jailhouse/inmates/demos/riscv/*.bin \
$jailhouse/inmates/tools/riscv/*.bin \
./etc/jailhouse/
cp -av $jailhouse/driver/jailhouse.ko .
cp -av $jailhouse/hypervisor/jailhouse.bin ./lib/firmware
cp -av $jailhouse/tools/jailhouse ./sbin/jailhouse
cp -av $jailhouse/tools/jailhouse-cell-stats ./sbin/jailhouse-cell-stats
cp -av $busybox_res/rcS ./etc/init.d/rcS
cp -av $busybox_res/fstab ./etc/fstab
cp -av $res/scripts/* ./usr/bin/
find . | cpio -o -H newc > $dst_f_initrd
pigz -f $dst_f_initrd
}
function build_linux() {
cd $dst_linux
$MAKE
}
function build_opensbi() {
cd $opensbi
# Remove OpenSBI firmware to enforce rebuild
rm -rf $dst_opensbi/platform/generic/firmware
$MAKE FW_TEXT_START=0 PLATFORM=generic FW_PIC= O=$dst_opensbi FW_PAYLOAD_PATH=$KERNEL
cd ../..
mkdir -p $dtb
}
function prepare_linux() {
mkdir -p $dst_linux
cd $dst_linux
$MAKE -C $linux O=$dst_linux lfd_riscv64_defconfig oldconfig
}
function build_qemu() {
mkdir -p $dst_qemu
cd $dst_qemu
$qemu/configure --disable-werror --target-list=riscv64-softmmu
$MAKE
}
# We build Jailhouse inside the source directory. Eases Debugging.
function build_jailhouse() {
cd $jailhouse
$MAKE
}
function deploy() {
rsync -avz -e ssh \
$KERNEL \
${KERNEL}.gz \
$VMLINUX \
build/initrd/initramfs.cpio.gz \
$dst_buildroot_root/images/rootfs.cpio.gz \
$jailhouse/driver/jailhouse.ko \
$jailhouse/hypervisor/hypervisor.o \
$target:jailv/
}
function deploy_target() {
prepare_root_overlay
cd $buildroot_root_overlay
rsync --chown root:root -avz -e ssh --owner root \
. $hw_target:/
}
function build_busybox() {
mkdir -p $dst_busybox
cp res/busybox/defconfig $dst_busybox/.config
cd $busybox
$MAKE O=$dst_busybox oldconfig
cd $dst_busybox
$MAKE CONFIG_PREFIX=$dst_rootfs install
cd $dst_rootfs
mkdir -p etc/init.d/ lib/firmware/ proc sys dev etc/dropbear dev/pts
ln -svf /sbin/init ./init
}
if [[ $cmd == "debug" ]]; then
debug
elif [[ $cmd == "initrd" ]]; then
build_initrd
elif [[ $cmd == "jailhouse" ]]; then
build_jailhouse
elif [[ $cmd == "linux" ]]; then
build_linux
elif [[ $cmd == "opensbi" ]]; then
build_opensbi
elif [[ $cmd == "prepare_linux" ]]; then
prepare_linux
elif [[ $cmd == "qemu" ]]; then
build_qemu
elif [[ $cmd == "busybox" ]]; then
build_busybox
elif [[ $cmd == "start" ]]; then
start_qemu $2
elif [[ $cmd == "deploy" ]]; then
deploy
elif [[ $cmd == "deploy_target" ]]; then
deploy_target
elif [[ $cmd == "buildroot" ]]; then
buildroot
elif [[ $cmd == "prepare_buildroot" ]]; then
prepare_buildroot
elif [[ $cmd == "qemu_aplic_uc" ]]; then
QEMU_MACHINE="virt,aia=aplic"
build_jailhouse
#build_initrd
start_qemu uc virt
elif [[ $cmd == "qemu_aplic_mc" ]]; then
QEMU_MACHINE="virt,aia=aplic"
build_jailhouse
#build_initrd
start_qemu mc virt
elif [[ $cmd == "qemu_aplic_imsic_uc" ]]; then
QEMU_MACHINE="virt,aia=aplic-imsic,aia-guests=3"
build_jailhouse
#build_initrd
start_qemu uc virt
elif [[ $cmd == "qemu_aplic_imsic_mc" ]]; then
QEMU_MACHINE="virt,aia=aplic-imsic,aia-guests=3"
build_jailhouse
#build_initrd
start_qemu mc virt
elif [[ $cmd == "qemu_plic_uc" ]]; then
QEMU_MACHINE="virt"
build_jailhouse
#build_initrd
start_qemu uc virt
elif [[ $cmd == "qemu_plic_mc" ]]; then
QEMU_MACHINE="virt"
build_jailhouse
#build_initrd
start_qemu mc virt
else
echo "Unknown target: $cmd"
fi