forked from ljskernel/kernel-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkerndev-run
More file actions
executable file
·130 lines (106 loc) · 3.58 KB
/
kerndev-run
File metadata and controls
executable file
·130 lines (106 loc) · 3.58 KB
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
#!/bin/bash
set -e; set -o pipefail; source kerndev-shared.sh
# Networking scripts adapted from
# https://github.com/lahwaacz/archlinux-dotfiles/blob/master/Scripts/qemu-launcher.sh
# If argument provided it specifies a cross-compile target architecture.
target_arch=${1:-$(uname -m)}
tap_limit=10
br_nic="qemu-br0"
mac="de:ad:be:ef:f0:0f"
# Functions.
function get_tap_name() {
for (( i=0; i < $tap_limit; i++ )); do
local name="tap$i"
if [[ ! -d "/sys/class/net/$name" ]]; then
echo "$name"
break
fi
done
}
function determine_wan_nic()
{
# Adapted from http://unix.stackexchange.com/a/302613 with love.
ip route ls | grep default | grep -Po '(?<=(dev ))[^ ]+' || true
}
check_exists brctl dnsmasq idemptables
tap_nic=$(get_tap_name)
elevate $@
# We want access to the underlying user.
[[ -z "$SUDO_USER" ]] && fatal Please run this using sudo!
# Default to assuming the target_arch is an actual qemu arch.
qemu=qemu-system-${target_arch}
case $target_arch in
arm)
# Use aarch64 + backwards compatibility.
qemu=qemu-system-aarch64
rootfs_image_path=$KERNDEV_PATH/rootfs_arm.img
;&
aarch64)
kernel_image_path=$LINUX_DEV_PATH/arch/arm64/boot/Image
rootfs_image_path=${rootfs_image_path:-$KERNDEV_PATH/rootfs_aarch64.img}
if [[ "${target_arch}" == "$(uname -m)" ]]; then
rootfs_image_path=$KERNDEV_PATH/rootfs.img
arch_opts="
-machine virt
-enable-kvm
-cpu host
-drive if=none,file=$rootfs_image_path,id=vda,format=raw
-device virtio-blk-device,drive=vda"
else
echo $target_arch
arch_opts="-machine virt
-cpu cortex-a57
-machine type=virt,kernel_irqchip=on
-drive if=none,file=$rootfs_image_path,id=vda,format=raw
-device virtio-blk-device,drive=vda"
fi
arch_append="console=ttyAMA0"
arch_net_opts="-net nic,model=virtio,macaddr=$mac
-netdev tap,ifname=$tap_nic,script=no,downscript=no,id=tap
-device virtio-net-device,netdev=tap"
;;
x86_64|icelake)
kernel_image_path=$LINUX_DEV_PATH/arch/x86/boot/bzImage
rootfs_image_path=$KERNDEV_PATH/rootfs.img
if [[ "$target_arch" == "icelake" ]] || ! lsmod | grep kvm > /dev/null; then
qemu=qemu-system-x86_64
arch_opts="-cpu Icelake-Server
-drive file=$rootfs_image_path,if=virtio,cache=none,format=raw
-boot once=c"
else
arch_opts="-enable-kvm
-cpu host
-drive file=$rootfs_image_path,if=virtio,cache=none,format=raw
-boot once=c"
fi
arch_append="console=ttyS0"
arch_net_opts="-net nic,model=virtio,macaddr=$mac
-net tap,ifname=$tap_nic,script=no,downscript=no"
;;
*)
fatal "unknown architecture: $target_arch"
;;
esac
# '-echr 0x02' moves escape key to C-b to avoid C-a getting nerfed.
shared_opts="-nographic -s -echr 0x02"
shared_append="root=/dev/vda rw earlyprintk=ttyS0 loglevel=2 nokaslr no_hash_pointers"
numa_opts="-smp ${QEMU_CORES} -m ${QEMU_RAM} "
if [[ -n "$USE_NUMA" ]]; then
# Really an experimental and crazy NUMA architecture.
numa_opts+="-object memory-backend-ram,size=15M,id=m0 "
numa_opts+="-numa node,memdev=m0,cpus=1 "
numa_opts+="-object memory-backend-ram,size=3G,id=m1 "
numa_opts+="-numa node,memdev=m1,cpus=2-3 "
numa_opts+="-object memory-backend-ram,size=5105M,id=m2 "
numa_opts+="-numa node,memdev=m2,cpus=4-7"
fi
wan_nic=$(determine_wan_nic)
if [[ -n "$wan_nic" ]]; then
kerndev-qemu-tap-helper.sh $SUDO_USER $tap_nic $br_nic $wan_nic up
trap "kerndev-qemu-tap-helper.sh $SUDO_USER $tap_nic $br_nic $wan_nic down" EXIT
else
echo "WARN: Couldn't determine NIC, networking will not work." >&2
unset arch_net_opts
fi
$qemu $shared_opts $numa_opts $arch_opts $arch_net_opts $QEMU_CUSTOM_SETTINGS \
-kernel $kernel_image_path -append "$shared_append $arch_append"