blob: 3d3cfb07dfe3a515bb02573cc4ae67eb7b90795c [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001#!/bin/bash
2
3function HELP {
4 echo "help:"
5 echo "-b a virtio block device"
6 echo "-c cmpctmalloc instead of dlmalloc"
7 echo "-M miniheap instead of dlmalloc"
8 echo "-n a virtio network device"
9 echo "-t a virtio tap network device"
10 echo "-d a virtio display"
11 echo "-6 64bit arm"
12 echo "-m <memory in MB>"
13 echo "-h for help"
14 echo "all arguments after -- are passed to qemu directly"
15 exit 1
16}
17
18DO_NET=0
19DO_NET_TAP=0
20DO_BLOCK=0
21DO_64BIT=0
22DO_DISPLAY=0
23DO_CMPCTMALLOC=0
24DO_MINIHEAP=0
25MEMSIZE=512
26SUDO=""
27
28while getopts bdhm:cMnt6 FLAG; do
29 case $FLAG in
30 b) DO_BLOCK=1;;
31 c) DO_CMPCTMALLOC=1;;
32 d) DO_DISPLAY=1;;
33 M) DO_MINIHEAP=1;;
34 n) DO_NET=1;;
35 t) DO_NET_TAP=1;;
36 6) DO_64BIT=1;;
37 m) MEMSIZE=$OPTARG;;
38 h) HELP;;
39 \?)
40 echo unrecognized option
41 HELP
42 esac
43done
44
45shift $((OPTIND-1))
46
47if [ $DO_64BIT == 1 ]; then
48 QEMU="qemu-system-aarch64 -machine virt -cpu cortex-a53"
49 PROJECT="qemu-virt-a53-test"
50else
51 QEMU="qemu-system-arm -machine virt -cpu cortex-a15"
52 PROJECT="qemu-virt-a15-test"
53fi
54
55ARGS=" -m $MEMSIZE -kernel build-${PROJECT}/lk.elf"
56BLOCK_ARGS=" -drive if=none,file=blk.bin,id=blk,format=raw -device virtio-blk-device,drive=blk"
57NET_ARGS=" -netdev user,id=vmnic,hostname=qemu -device virtio-net-device,netdev=vmnic"
58NET_TAP_ARGS=" -netdev tap,id=vmnic -device virtio-net-device,netdev=vmnic"
59NO_DISPLAY_ARGS=" -nographic"
60DISPLAY_ARGS=" -device virtio-gpu-device -serial stdio"
61
62echo DO_BLOCK = $DO_BLOCK
63echo DO_NET = $DO_NET
64
65if [ $DO_BLOCK == 1 ]; then
66 ARGS+=$BLOCK_ARGS
67fi
68if [ $DO_NET == 1 ]; then
69 ARGS+=$NET_ARGS
70fi
71if [ $DO_NET_TAP == 1 ]; then
72 ARGS+=$NET_TAP_ARGS
73 SUDO="sudo "
74fi
75if [ $DO_DISPLAY == 1 ]; then
76 ARGS+=$DISPLAY_ARGS
77else
78 ARGS+=$NO_DISPLAY_ARGS
79fi
80
81MAKE_VARS=""
82
83if [ $DO_CMPCTMALLOC == 1 ]; then
84 MAKE_VARS=LK_HEAP_IMPLEMENTATION=cmpctmalloc
85elif [ $DO_MINIHEAP == 1 ]; then
86 MAKE_VARS=LK_HEAP_IMPLEMENTATION=miniheap
87fi
88
89make $MAKE_VARS $PROJECT -j4 &&
90echo $SUDO $QEMU $ARGS $@ &&
91$SUDO $QEMU $ARGS $@