rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | |
| 3 | function 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 | |
| 18 | DO_NET=0 |
| 19 | DO_NET_TAP=0 |
| 20 | DO_BLOCK=0 |
| 21 | DO_64BIT=0 |
| 22 | DO_DISPLAY=0 |
| 23 | DO_CMPCTMALLOC=0 |
| 24 | DO_MINIHEAP=0 |
| 25 | MEMSIZE=512 |
| 26 | SUDO="" |
| 27 | |
| 28 | while 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 |
| 43 | done |
| 44 | |
| 45 | shift $((OPTIND-1)) |
| 46 | |
| 47 | if [ $DO_64BIT == 1 ]; then |
| 48 | QEMU="qemu-system-aarch64 -machine virt -cpu cortex-a53" |
| 49 | PROJECT="qemu-virt-a53-test" |
| 50 | else |
| 51 | QEMU="qemu-system-arm -machine virt -cpu cortex-a15" |
| 52 | PROJECT="qemu-virt-a15-test" |
| 53 | fi |
| 54 | |
| 55 | ARGS=" -m $MEMSIZE -kernel build-${PROJECT}/lk.elf" |
| 56 | BLOCK_ARGS=" -drive if=none,file=blk.bin,id=blk,format=raw -device virtio-blk-device,drive=blk" |
| 57 | NET_ARGS=" -netdev user,id=vmnic,hostname=qemu -device virtio-net-device,netdev=vmnic" |
| 58 | NET_TAP_ARGS=" -netdev tap,id=vmnic -device virtio-net-device,netdev=vmnic" |
| 59 | NO_DISPLAY_ARGS=" -nographic" |
| 60 | DISPLAY_ARGS=" -device virtio-gpu-device -serial stdio" |
| 61 | |
| 62 | echo DO_BLOCK = $DO_BLOCK |
| 63 | echo DO_NET = $DO_NET |
| 64 | |
| 65 | if [ $DO_BLOCK == 1 ]; then |
| 66 | ARGS+=$BLOCK_ARGS |
| 67 | fi |
| 68 | if [ $DO_NET == 1 ]; then |
| 69 | ARGS+=$NET_ARGS |
| 70 | fi |
| 71 | if [ $DO_NET_TAP == 1 ]; then |
| 72 | ARGS+=$NET_TAP_ARGS |
| 73 | SUDO="sudo " |
| 74 | fi |
| 75 | if [ $DO_DISPLAY == 1 ]; then |
| 76 | ARGS+=$DISPLAY_ARGS |
| 77 | else |
| 78 | ARGS+=$NO_DISPLAY_ARGS |
| 79 | fi |
| 80 | |
| 81 | MAKE_VARS="" |
| 82 | |
| 83 | if [ $DO_CMPCTMALLOC == 1 ]; then |
| 84 | MAKE_VARS=LK_HEAP_IMPLEMENTATION=cmpctmalloc |
| 85 | elif [ $DO_MINIHEAP == 1 ]; then |
| 86 | MAKE_VARS=LK_HEAP_IMPLEMENTATION=miniheap |
| 87 | fi |
| 88 | |
| 89 | make $MAKE_VARS $PROJECT -j4 && |
| 90 | echo $SUDO $QEMU $ARGS $@ && |
| 91 | $SUDO $QEMU $ARGS $@ |