forked from cadriel/FluiddPIOLD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·108 lines (92 loc) · 3.19 KB
/
run.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/bash
##### run.sh - test new image
<<COMMENT
Original by "prg3" ( https://github.com/prg3 ) and "Noms" ( https://github.com/Nomsplease )
Modified by "KwadFan" ( https://github.com/KwadFan )
COMMENT
### Configuration
WORKSPACE=src/workspace
IMG_FILE= #if blank, will be detected
## QEMU Parameters
QEMU_BIN='qemu-system-arm'
QEMU_CPU='arm1176' #CPU Type
QEMU_RAM='256' # in Megabyte
QEMU_KERNEL='emulation/kernel-qemu-4.19.50-buster' #kernel image, do not modify except you what you doing.
QEMU_MACHINE='versatilepb'
QEMU_DTB='emulation/versatile-pb.dtb'
QEMU_OPTIONS='-no-reboot -nographic'
QEMU_NET='-net user,ipv4=on,ipv6=on,hostfwd=tcp::22222-:22,hostfwd=tcp::8888-:80 -net nic'
### Functions
## Hint
start_hint() {
echo -e "\e[1;30m\n------------------------------------\e[0m"
echo -e "\e[1;31m Hit Control-a x to exit Emulation!\e[0m "
echo -e "\e[1;30m------------------------------------\e[0m\n"
}
## looking for qemu-system-arm , package manager independent
search_for_qemu() {
for BIN_PATH in $(awk -F':' '{ for(i=1;i<=NF;i++) print $i}' <<< ${PATH})
do
[[ -x $BIN_PATH/$QEMU_BIN ]] && { QEMU_CMD=$BIN_PATH/$QEMU_BIN ; break; }
done
}
## check if needed files missing.
check_env() {
echo -e "\e[0;37mChecking Environment...\e[0m"
if [ ! -z $QEMU_CMD ];
then
echo -e "\n\e[1;32mqemu-system-arm\e[0m installed..."
else
echo -e '\n\e[1;31mCommand qemu-system-arm not found:\n\e[0m
\e[1;33mPlease install qemu-user-static and qemu-system-arm first!\e[0m'
exit 2;
fi
if [ ! -e $QEMU_KERNEL ];
then
echo -e "\n\e[1;32m${QEMU_KERNEL}\e[0m missing, exiting..."
exit 2
else
echo -e "\n\e[1;32m${QEMU_KERNEL}\e[0m found..."
fi
if [ ! -e $QEMU_DTB ];
then
echo -e "\n\e[1;32m${QEMU_DTB}\e[0m missing, exiting..."
exit 2
else
echo -e "\n\e[1;32m${QEMU_DTB}\e[0m found..."
fi
}
img_file_handling() {
if [ $(ls $WORKSPACE/*.img | wc -l) -gt 1 ];
then
echo -e "\n\e[1;33mOoops\e[0m, more than \e[1;32m1\e[0m Image found...\n"
PS3='Choose Image File: '
select IMAGE in $(cd $WORKSPACE && ls *.img)
do
echo -e "\nUsing \e[1;32m$IMAGE\e[0m\n"
IMG_FILE=$IMAGE
break
done
elif [ $(ls $WORKSPACE/*.img | wc -l) = 1 ];
then
IMG_FILE=$(cd $WORKSPACE && ls *.img)
echo -e "\nFound \e[1;32m${IMG_FILE}\e[0m in \e[1;34m${WORKSPACE}\e[0m\n"
else
echo -e "\n 'Image File' not specified or found, exiting script."
exit 2
fi
}
## run image
run_img() {
qemu-system-arm -cpu $QEMU_CPU -m $QEMU_RAM \
-kernel $QEMU_KERNEL -M $QEMU_MACHINE -dtb \
$QEMU_DTB $QEMU_OPTIONS \
-append 'dwc_otg.lpm_enable=0 root=/dev/sda2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait' \
-drive file=$WORKSPACE/$IMG_FILE,index=0,media=disk,format=raw $QEMU_NET
}
### Main
start_hint
search_for_qemu
check_env
img_file_handling
run_img