summaryrefslogtreecommitdiff
path: root/qemu-boot
blob: 54103e1b366012b70dfbccf5093c5e81a0c669fe (plain)
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
#!/bin/sh -e

# if you use QEMU user mode networking, endpoint 127.0.0.1:2222 on the host will be forwarded to port 22 in the guest
SSH_PORTFORWARD=${SSH_PORTFORWARD:-2222}

virtioblk=virtio-blk-device
virtionet=virtio-net-device

case "$QEMU_ARCH" in
  i386)
    qemu_sysoptions="-smp 2 -m 500M"
    qemu_console=ttyS0
    nic=e1000
    diskoption="-drive file=$OUTPUT/disk-image.raw,media=disk,format=raw,if=none,id=sata0 -device ich9-ahci,id=ahci -device ide-drive,drive=sata0,bus=ahci.0" ;;
  x86_64)
    qemu_sysoptions="-enable-kvm -cpu host -smp 4 -m 500M"
    qemu_console=ttyS0
    nic=e1000
    virtioblk=virtio-blk-pci
    virtionet=virtio-net-pci
    diskoption="-drive file=$OUTPUT/disk-image.raw,media=disk,format=raw,if=none,id=sata0 -device ich9-ahci,id=ahci -device ide-drive,drive=sata0,bus=ahci.0" ;;
  arm)
    qemu_sysoptions="-m 500M -M vexpress-a9 -cpu cortex-a9 -dtb sub/disk-image/vexpress-v2p-ca9.dtb"
    qemu_console=ttyAMA0
    USE_VIRTIO_NETWORK=true  # we only support virtio on armv7
    diskoption="-sd $OUTPUT/disk-image.raw" ;;
  aarch64)
    qemu_sysoptions="-M virt -cpu cortex-a57 -m 500M"
    qemu_console=ttyAMA0
    USE_VIRTIO_NETWORK=true  # we only support virtio on armv8
    diskoption="-device sdhci-pci -device sd-card,drive=sdcard -drive file=$OUTPUT/disk-image.raw,id=sdcard,cache=unsafe,if=none,format=raw" ;;
esac

nographic=-nographic

# On graphical mode, enforce tty1 as the console
if $USE_GRAPHIC ; then
  qemu_console=tty1
  nographic=
fi

# If the image has been compiled for a virtual disk (/dev/vda)
if $USE_VIRTIO_DISK ; then
  diskoption="-drive file=$OUTPUT/disk-image.raw,format=raw,if=none,id=disk -device $virtioblk,drive=disk"
fi

if $USE_VIRTIO_NETWORK ; then
  nic=$virtionet
fi

qemu_guestnetoptions="-device $nic,netdev=network"

# running in QEMU with TAP networking (need to be root to configure the host)
# or running QEMU in user-mode networking (which is the default in QEMU), with redirection of port 2222 to 22
if $USE_TAP ; then
  qemu_hostnetoptions="-netdev tap,id=network,ifname=tap0,script=no,downscript=no"
else
  qemu_hostnetoptions="-netdev user,id=network,hostfwd=tcp:127.0.0.1:${SSH_PORTFORWARD}-:22"
fi

# echo qemu-system-$QEMU_ARCH $nographic $qemu_sysoptions $qemu_guestnetoptions $qemu_hostnetoptions \
#   -append "console=$qemu_console" \
#   -kernel "$OUTPUT/kernel" \
#   -initrd "$OUTPUT/initramfs.img.gz" \
#   $diskoption

exec qemu-system-$QEMU_ARCH $nographic $qemu_sysoptions $qemu_guestnetoptions $qemu_hostnetoptions \
  -append "console=$qemu_console" \
  -kernel "$OUTPUT/kernel" \
  -initrd "$OUTPUT/initramfs.img.gz" \
  $diskoption