-
Notifications
You must be signed in to change notification settings - Fork 4
/
ppc-boot.sh
executable file
·359 lines (298 loc) · 11 KB
/
ppc-boot.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
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
#!/bin/bash
#
# Run a test doing a basic boot with network and poweroff for each PPC
# machines supported in QEMU using a builroot image
#
# Copyright (c) 2021, IBM Corporation.
#
# This work is licensed under the terms of the GNU GPL version 2. See
# the COPYING file in the top-level directory.
me=${0##*/}
qemu_prefix=/usr
buildroot_dir=./buildroot
quiet=
# mac99+7450 is broken
machines32="ref405ep bamboo sam460ex g3beige-604 g3beige-g3 mac99-g4 mac99-7447 mac99-7448 mac99-7450 mpc8544ds e500mc 40p"
# lack support for powernv10
machines64="e5500 e6500 g5-32 g5-64 pseries-970 pseries-970mp pseries-POWER5+ pseries pseriesle8 pseriesle9 pseriesle-vof pseriesle10 powernv8 powernv9 powernv10"
machines="$machines32 $machines64"
PASSED="[32mPASSED[0m"
FAILED="[31mFAILED[0m"
usage()
{
cat <<EOF
$me 1.0
Usage: $me [OPTION] <board ...>
Known values for OPTION are:
-h|--help display this help and exit
-q|--quiet all outputs are redirected to a logfile per machine
-p|--prefix <DIR> install prefix of QEMU binaries
Defaults to "$qemu_prefix".
-b|--buildroot <DIR> directory where to find builroot images.
Defaults to "$buildroot_dir".
-o|--openbios <FILE> use <FILE> as a custom OpenBIOS firmware
--64 use the 64-bit build for all the tests
Possible machines are:
$machines
EOF
exit 1;
}
options=`getopt -o hqp:b:o: -l help,quiet,prefix:,buildroot:openbios:,64 -- "$@"`
if [ $? -ne 0 ]
then
usage
fi
eval set -- "$options"
while true
do
case "$1" in
-h|--help) usage ;;
-q|--quiet) quiet=1; shift 1;;
-p|--prefix) qemu_prefix="$2"; shift 2;;
-b|--buildroot) buildroot_dir="$2"; shift 2;;
-o|--openbios) openbios="$2"; shift 2;;
--64) sixtyfour=1; shift 1;;
--) shift 1; break ;;
*) break ;;
esac
done
qemu="$qemu_prefix/bin/qemu-system-ppc"
qemu64="${qemu}64"
if [[ -n "$sixtyfour" ]]; then
if [[ ! -f "$qemu64" ]]; then
echo "$me: no 64-bit QEMU binary in \"$qemu_prefix\" directory"
exit 1
fi
qemu="$qemu64"
else
if [[ ! -f "$qemu" || ! -f "$qemu64" ]]; then
echo "$me: no QEMU binaries in \"$qemu_prefix\" directory"
exit 1
fi
fi
if [ ! -d "$buildroot_dir" ]; then
echo "$me: unknown \"$buildroot_dir\" directory for buildroot images"
exit 1
fi
if [ -n "$openbios" ]; then
if [ -f "$openbios" ]; then
openbios_args="-bios $openbios"
else
echo "$me: invalid \"$openbios\" OpenBIOS file image"
exit 1
fi
fi
spawn_qemu()
{
local machine_args
local kernel_args
local initrd_args
local net_args
local hd_args
machine=$1
logfile=${machine}.log
timeout=20
case "$machine" in
ref405ep*)
buildroot_images=$buildroot_dir/qemu_ppc_ref405ep-latest
machine_args="-M $machine -serial null"
kernel_args="-kernel $buildroot_images/cuImage.hotfoot.elf"
initrd_args="-initrd $buildroot_images/rootfs.cpio"
net_args="-net nic,model=rtl8139,addr=3 -net user"
;;
bamboo)
buildroot_images=$buildroot_dir/qemu_ppc_${machine}-latest
machine_args="-M $machine"
kernel_args="-kernel $buildroot_images/vmlinux"
net_args="-net nic,model=virtio-net-pci -net user"
;;
sam460ex)
buildroot_images=$buildroot_dir/qemu_ppc_${machine}-latest
machine_args="-M $machine"
kernel_args="-kernel $buildroot_images/vmlinux"
net_args="-device virtio-net-pci,netdev=net0 -netdev user,id=net0"
;;
g3beige-*)
cpu="${machine#g3beige-*}"
machine=g3beige
buildroot_images=$buildroot_dir/qemu_ppc_${machine}-latest
machine_args="-m 1G -M $machine $openbios_args -cpu $cpu"
kernel_args="-kernel $buildroot_images/vmlinux -append \"root=/dev/sda\""
net_args="-net nic,model=rtl8139 -net user"
hd_args="-drive file=$buildroot_images/rootfs.ext2,format=raw"
;;
e500mc)
buildroot_images=$buildroot_dir/qemu_ppc_${machine}-latest
machine_args="-m 1G -M ppce500 -cpu e500mc"
kernel_args="-kernel $buildroot_images/uImage -append \"root=/dev/vda\""
net_args="-net nic,model=virtio-net-pci -net user"
hd_args="-drive file=$buildroot_images/rootfs.ext2,if=virtio,format=raw"
;;
mpc8544ds)
buildroot_images=$buildroot_dir/qemu_ppc_${machine}-latest
machine_args="-m 1G -M mpc8544ds"
kernel_args="-kernel $buildroot_images/vmlinux"
net_args="-net nic,model=e1000 -net user"
;;
e5500|e6500)
qemu=$qemu64
buildroot_images=$buildroot_dir/qemu_ppc64_e5500-latest
machine_args="-m 1G -M ppce500 -cpu ${machine}"
kernel_args="-kernel $buildroot_images/uImage -append \"root=/dev/vda\""
net_args="-net nic,model=virtio-net-pci -net user"
hd_args="-drive file=$buildroot_images/rootfs.ext2,if=virtio,format=raw"
;;
40p)
cpu=604
buildroot_images=$buildroot_dir/qemu_ppc_${machine}-latest
machine_args="-M ${machine} $openbios_args -cpu $cpu"
hd_args="-cdrom images/zImage.initrd.sandalfoot -boot d"
;;
mac99-*)
cpu="${machine#mac99-*}"
machine=mac99
buildroot_images=$buildroot_dir/qemu_ppc_${machine}-latest
machine_args="-m 1G -M ${machine},via=pmu $openbios_args -cpu $cpu"
kernel_args="-kernel $buildroot_images/vmlinux -append \"root=/dev/sda\""
net_args="-net nic,model=sungem -net user"
hd_args="-drive file=$buildroot_images/rootfs.ext2,format=raw"
;;
g5-32)
qemu=$qemu64
machine=mac99
buildroot_images64=$buildroot_dir/qemu_ppc64_${machine}-latest
buildroot_images32=$buildroot_dir/qemu_ppc_${machine}-latest
machine_args="-m 1G -M ${machine},via=pmu $openbios_args -cpu 970"
kernel_args="-kernel $buildroot_images64/vmlinux -append \"root=/dev/sda\""
net_args="-net nic,model=sungem -net user"
hd_args="-drive file=$buildroot_images32/rootfs.ext2,format=raw"
;;
g5-64)
qemu=$qemu64
machine=mac99
buildroot_images=$buildroot_dir/qemu_ppc64_${machine}-latest
machine_args="-m 1G -M ${machine},via=pmu $openbios_args -cpu 970"
kernel_args="-kernel $buildroot_images/vmlinux -append \"root=/dev/sda\""
net_args="-net nic,model=sungem -net user"
hd_args="-drive file=$buildroot_images/rootfs.ext2,format=raw"
;;
pseries-*)
timeout=30
qemu=$qemu64
cpu="${machine#pseries-*}"
machine=pseries
buildroot_images=$buildroot_dir/qemu_ppc64_${machine}_p5p-latest
poweroff_expect="Power down"
machine_args="-m 1G -M $machine -cpu $cpu -nodefaults"
kernel_args="-kernel $buildroot_images/vmlinux -append \"root=/dev/sda\""
net_args="-net nic -net user"
hd_args="-drive file=$buildroot_images/rootfs.ext2,if=scsi,format=raw"
;;
pseries)
timeout=30
qemu=$qemu64
buildroot_images=$buildroot_dir/qemu_ppc64_${machine}-latest
poweroff_expect="Power down"
machine_args="-m 1G -M $machine -cpu POWER7 -nodefaults"
kernel_args="-kernel $buildroot_images/vmlinux -append \"root=/dev/sda\""
net_args="-net nic -net user"
hd_args="-drive file=$buildroot_images/rootfs.ext2,if=scsi,format=raw"
;;
pseriesle-vof)
timeout=30
qemu=$qemu64
cpu="POWER9"
machine=pseries,x-vof=on
buildroot_images=$buildroot_dir/qemu_ppc64le_pseries-latest
poweroff_expect="Power down"
machine_args="-m 1G -M $machine -cpu $cpu -nodefaults"
kernel_args="-kernel $buildroot_images/vmlinux -append \"root=/dev/sda\""
net_args="-net nic -net user"
hd_args="-drive file=$buildroot_images/rootfs.ext2,if=scsi,format=raw"
;;
pseriesle*)
timeout=30
qemu=$qemu64
cpu="POWER${machine#pseriesle*}"
machine=pseries
buildroot_images=$buildroot_dir/qemu_ppc64le_${machine}-latest
machine_args="-m 1G -M $machine -cpu $cpu -nodefaults"
kernel_args="-kernel $buildroot_images/vmlinux -append \"root=/dev/sda\""
net_args="-net nic -net user"
hd_args="-drive file=$buildroot_images/rootfs.ext2,if=scsi,format=raw"
;;
powernv*)
timeout=30
qemu=$qemu64
buildroot_images=$buildroot_dir/qemu_ppc64le_powernv8-latest
machine_args="-m 1G -M $machine"
kernel_args="-kernel $buildroot_images/vmlinux -append \"root=/dev/nvme0n1\""
net_args="-device e1000e,bus=pcie.1,addr=0x0,netdev=net0 -netdev user,id=net0"
hd_args="-device nvme,bus=pcie.2,addr=0x0,drive=drive0,serial=1234 \
-drive file=$buildroot_images/rootfs.ext2,if=none,id=drive0,format=raw,cache=none"
;;
*)
echo "invalid machine \"$machine\"";
exit 1;
esac
qemu_cmd="$qemu $machine_args $kernel_args $initrd_args $hd_args $net_args"
qemu_cmd="$qemu_cmd -serial mon:stdio -nographic -snapshot"
if [ -n "$quiet" ]; then
exec 1>$logfile 2>&1
fi
#
# TODO :
# - Exit faster
# - Catch more error
#
expect \
-c "spawn $qemu_cmd" \
-c "set timeout $timeout" \
-c 'expect -re "^qemu-system-ppc64: (?!warning:)(.*)" \
{ puts -nonewline stderr "ERROR: $expect_out(1,string)"; \
exit 6 } \
-re "^qemu-system-ppc: (?!warning:)(.*)" \
{ puts -nonewline stderr "ERROR: $expect_out(1,string)"; \
exit 6 }' \
-c 'expect "SLOF" { puts -nonewline stderr "FW "; \
exp_continue } \
"OPAL v" { puts -nonewline stderr "FW "; \
exp_continue } \
">> OpenBIOS" { puts -nonewline stderr "FW "; \
exp_continue } \
"U-Boot" { puts -nonewline stderr "FW "; \
exp_continue } \
"=>" { send "bootm 0x1000000 0x1800000\r"; \
exp_continue } \
"Linux version " { puts -nonewline stderr "Linux "; \
exp_continue } \
"/init as init" { puts -nonewline stderr "/init "; \
exp_continue } \
"lease of 10.0.2.15" { puts -nonewline stderr "net "; \
exp_continue } \
timeout { puts -nonewline stderr "TIMEOUT"; exit 1 } \
"Kernel panic" { puts -nonewline stderr "PANIC"; exit 2 } \
"illegal instruction" { puts -nonewline stderr "SIGILL"; exit 3 } \
"Segmentation fault" { puts -nonewline stderr "SEGV"; exit 4 } \
": Assertion" { puts -nonewline stderr "ASSERT"; exit 5 } \
"activate this console." { puts -nonewline stderr "login "} \
"powernv login:" { puts -nonewline stderr "login "} \
"buildroot login:" { puts -nonewline stderr "login " }' \
-c 'send "root\r"' \
-c 'expect timeout { puts -nonewline stderr "TIMEOUT"; exit 1 } \
"Password:" { send "passw0rd\r"; exp_continue } \
"#"' \
-c 'send "poweroff\r"' \
-c 'expect timeout { puts -nonewline stderr "TIMEOUT"; exit 1 } \
"halted" { puts -nonewline stderr "DONE"; exit 0 } \
"Terminated" { puts -nonewline stderr "DONE"; exit 0 } \
"Power down" { puts -nonewline stderr "DONE"; exit 0 }' \
-c "expect -i $spawn_id eof" 2>&3
}
tests_machines=${*:-"$machines"}
exec 3>&1
for m in $tests_machines; do
echo -n "$m : " >&3
spawn_qemu $m && pass=$PASSED || pass=$FAILED
echo " ($pass)" >&3
done