1#!/bin/bash
2
3usage ()
4{
5	echo "Usage:"
6	echo "./run.sh [<path_to_image>]"
7	echo "Note: if <path_to_image> is not provided, will create a 'sd.bin'"
8	echo "in the current directory and load it by default."
9}
10
11path_image=${1}
12
13if [ -z $path_image ]; then
14	path_image="./sd.bin"
15	if [ ! -f $path_image ]; then
16		dd if=/dev/zero of=$path_image bs=1024 count=65536
17		mkfs.fat $path_image
18	fi
19fi
20
21if [ ! -f $path_image ]; then
22	echo "ERROR: $path_image does not exist!"
23	usage
24	exit
25fi
26
27qemu-system-riscv64 -nographic -machine virt -m 256M -kernel rtthread.bin \
28-drive if=none,file=$path_image,format=raw,id=blk0 -device virtio-blk-device,drive=blk0,bus=virtio-mmio-bus.0 \
29-netdev user,id=tap0 -device virtio-net-device,netdev=tap0,bus=virtio-mmio-bus.1 \
30-device virtio-serial-device -chardev socket,host=127.0.0.1,port=4321,server=on,wait=off,telnet=on,id=console0 -device virtserialport,chardev=console0
31