-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_kernel.sh
executable file
·70 lines (57 loc) · 2.18 KB
/
run_kernel.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
#!/bin/bash
# Argument expect
# 1: Kernel binary
# 2: Destination for grub directory
# 3: Mode test/boot
# 4: QEMU additional arguments like -s -S in case of debug
#Copy test binary to grub dir
cp -f $1 iso/boot/$2
# Set timeout value to 0 for test or 5 for normal boot
[ "$3" == "test" ] && timeout=0 || timeout=5
[ "$3" == "test" ] && qemu-img create hard-drive 2M || ./create-img.bsh hard-drive
# Changing grub timeout (sed command is different between Mac and Linux)
[ "$(uname)" == "Darwin" ] && sed -i '' 's/timeout=.*/timeout='$timeout'/' iso/boot/grub/grub.cfg \
|| sed -i 's/timeout=.*/timeout='$timeout'/' iso/boot/grub/grub.cfg
# Build iso file using test binary and grub
# Compress the binary if it is located in rust release target directory
[ "$(basename $(dirname $1))" == "release" ] && grub-mkrescue --compress=xz -o $2 iso \
|| grub-mkrescue -o $2 iso
# Create log directory
DIR_LOGS=logs
mkdir -p $DIR_LOGS
# Sound hardware depends on Host OS
[ $(uname) == "Darwin" ] && AUDIODEV="coreaudio" || AUDIODEV="pa"
# Expect qemu args to be in arg 4
# In case of test, redirect logfile output to stdio as well
[ "$3" == "test" ] && QEMU_ARGS="-chardev stdio,id=char0,logfile=$DIR_LOGS/kernel.log -display none" \
|| QEMU_ARGS="-chardev file,id=char0,path=$DIR_LOGS/kernel.log -display curses"
QEMU_ARGS="
$QEMU_ARGS
$4
-audiodev $AUDIODEV,id=audio0 -machine pcspk-audiodev=audio0
-d int
-drive id=cdrom,file=$2,format=raw,if=none
-device ide-cd,drive=cdrom,bus=ide.0
-drive id=disk,file=hard-drive,format=raw,if=none
-device ide-hd,drive=disk,bus=ide.1
-serial chardev:char0
-serial file:$DIR_LOGS/debug_kernel.log
-no-reboot
-rtc base=localtime
-device isa-debug-exit,iobase=0xf4,iosize=0x04
"
# Run qemu for kernel unit tests
if [ "$3" == "test" ]; then
qemu-system-i386 $QEMU_ARGS 2> logs/qemu.log | awk "
/[ok]/ {sub(/\[ok\]/,\"[\033[32mok\033[39m]\");}
/[failed]/ {sub(/\[failed\]/,\"[\033[31mfailed\033[39m]\");}
// {print; system(\"\")}"
ret=${PIPESTATUS[0]}
if [ $ret -eq 33 ]; then
exit 0;
fi
exit 1;
# Run qemu for kernel run
else
qemu-system-i386 $QEMU_ARGS 2> $DIR_LOGS/qemu.log
fi