-
Notifications
You must be signed in to change notification settings - Fork 1
/
rock-emulator.sh
71 lines (65 loc) · 1.83 KB
/
rock-emulator.sh
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/bash
MODE=$1
if [ "$UID" -ne 0 ]; then
echo "This program needs sudo rights."
echo "Run it with 'sudo $0'"
exit 1
fi
if [ $# -ne 1 ]; then
echo "Usage: $0 <image_file> [rw]"
echo " ro=readonly (Standard)"
echo " rw=read/write mode"
echo ""
echo "WARNING: After rw mode the image will not longer boot custom"
echo " Kernels on your Rock4SE board! This is just for"
echo " emulation or developing on a x86 host."
echo ""
exit 1
fi
if [ "$MODE" == "rw" ]; then
echo "WARNING RUNNING IN READ/WRITE MODE!"
else
MODE=ro
fi
SDCARD=$1
loop_device=$(sudo losetup -f)
available_cpus=$(nproc)
max_cpus=8
if ((available_cpus > max_cpus)); then
CPUS=$max_cpus
else
CPUS=$available_cpus
fi
losetup -P "$loop_device" "$SDCARD"
sleep 1
mkdir -p loop .qemu
sleep 1
sudo mount "${loop_device}p2" loop
sleep 1
cp loop/boot/vmlinuz* .qemu/vmlinuz
cp loop/boot/initrd* .qemu/initrd.img
umount loop/
rmdir loop/
losetup -d $loop_device
chown -R ${SUDO_USER}:${SUDO_USER} .qemu
mkdir -p /tmp/mytpm1
swtpm socket --tpmstate dir=/tmp/mytpm1 --ctrl type=unixio,path=/tmp/mytpm1/swtpm-sock --tpm2 --log level=0 &
qemu-system-aarch64 \
-M virt \
-cpu cortex-a72 -smp $CPUS \
-m 2048 \
-kernel "${PWD}/.qemu/"vmlinuz \
-initrd "${PWD}/.qemu/"initrd.img \
-drive if=none,file=${SDCARD},format=raw,id=disk \
-bios /usr/lib/u-boot/qemu_arm64/u-boot.bin \
-chardev socket,id=chrtpm,path=/tmp/mytpm1/swtpm-sock \
-tpmdev emulator,id=tpm0,chardev=chrtpm \
-append "root=LABEL=rootfs ${MODE}" \
-device virtio-blk-device,drive=disk \
-device virtio-keyboard-pci \
-netdev user,id=net0 \
-device virtio-net-pci,netdev=net0 \
-device virtio-gpu-pci -device qemu-xhci -device virtio-mouse-pci \
-display gtk,gl=on,show-cursor=on,show-tabs=on
rm -rf .qemu
pkill swtpm