-
Notifications
You must be signed in to change notification settings - Fork 1
/
runon
executable file
·213 lines (186 loc) · 8.54 KB
/
runon
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/bin/bash
TARGET=$1
shift
DEBUG=$1
expr "$DEBUG" : "[-]*debug" >/dev/null 2>&1
if [ $? -eq 0 ]; then
ENTER_DEBUG=1
shift
fi
PARAMS=$*
LKVM=$HOME/kvmtool
#QEMU=$HOME/qemu/build/
set $(egrep ^NATURE Makefile)
NATURE=$3
APP=target/aarch64-unknown-uefi/$NATURE/barekit.afx
EL3_STUB=target/aarch64-unknown-uefi/copy_to_secmem.bin
#-kernel qemu option requires some properties from the binary file
# in some cases, the binary has no recognizable form
# the following command allows to load an arbitray binary and set start address
#qemu-system-aarch64 -nographic -machine virt,accel=kvm -cpu host -serial mon:stdio -m 16M -device loader,file=<purebinary>,addr=0x40200000 -device loader,addr=0x40200000,cpu-num=0
# the flash is made of a stub at offset and a payload at offset 4096
# the stub copies the payload at $SECMEM_BASE (writeen in the flash)
# then transfers control to it
# this is necessary because it may not be easy with Qemu to position
# the payload directly in secmem (required for EL3 run)
stage_el3_flash() {
FLASH=$1
SECMEM_BASE=$2
truncate -s 64M $FLASH
# update size of payload in the stub
set $(wc -c $APP)
v=$(printf "%08x" $1)
echo -n -e "\\x${v:6:2}\\x${v:4:2}\\x${v:2:2}\\x${v:0:2}" | dd of=$EL3_STUB bs=4 seek=1 conv=notrunc > /dev/null 2>&1
#update the secure memory base address in the stub
v=$(printf "%016x" $SECMEM_BASE)
echo -n -e "\\x${v:14:2}\\x${v:12:2}\\x${v:10:2}\\x${v:8:2}\\x${v:6:2}\\x${v:4:2}\\x${v:2:2}\\x${v:0:2}" | dd of=$EL3_STUB bs=8 seek=1 conv=notrunc > /dev/null 2>&1
#place the stub at the begining of the flash
dd if=$EL3_STUB of=$FLASH bs=4096 conv=notrunc > /dev/null 2>&1
#place the payload at offset 4096
echo dd if=$APP of=$FLASH seek=1 bs=4096 conv=notrunc
dd if=$APP of=$FLASH seek=1 bs=4096 conv=notrunc > /dev/null 2>&1
}
case $TARGET in
kvmtool)
if [ "$ENTER_DEBUG" == "1" ]; then
DEBUG_TAG="--debug-single-step"
fi
$LKVM/lkvm run --mem 64 -c 1 --pmu --console serial --kernel $APP --params "$PARAMS" $DEBUG_TAG
;;
kvmtool-raw)
if [ "$ENTER_DEBUG" == "1" ]; then
DEBUG_TAG="--debug-single-step"
fi
sudo sysctl kernel.perf_event_paranoid=-1
$LKVM/lkvm run --mem 64 -c 1 --pmu --console serial --kernel $APP $DEBUG_TAG --enable-raw $PARAMS
;;
qemu-kvm)
${QEMU}qemu-system-aarch64 -nographic -machine virt,accel=kvm -cpu host -serial mon:stdio -m 64M -kernel $APP -append "$PARAMS"
;;
qemu-hvf)
${QEMU}qemu-system-aarch64 -nographic -machine virt,accel=hvf -cpu host -serial mon:stdio -m 16M -kernel $APP -append "$PARAMS"
;;
qemu)
${QEMU}qemu-system-aarch64 -nographic -machine virt -cpu cortex-a72 -serial mon:stdio -m 64M -kernel $APP -append "$PARAMS"
;;
qemu-edk2)
if [ "$(uname -s)" != "Darwin" ]; then
truncate --size 64M run_efi/QEMU_UBOOT_ENV.fd
../u-boot/tools/env/fw_setenv -c run_efi/uboot_env.config bootargs "$PARAMS"
ACCEL=kvm
else
ACCEL=hvf
fi
#minimum of 64M to initialize the EFI subsystem
${QEMU}qemu-system-aarch64 -nographic -nodefaults -machine virt -cpu cortex-a72 -serial mon:stdio -m 1G \
-drive if=pflash,format=raw,readonly=on,file=/usr/share/AAVMF/AAVMF_CODE.fd \
-drive if=pflash,format=raw,file=run_efi/AAVMF_VARS.fd \
-drive file=run_efi/disk.img,format=raw,if=virtio
;;
qemu-uboot)
if [ "$(uname -s)" != "Darwin" ]; then
truncate --size 64M run_efi/QEMU_UBOOT_ENV.fd
../u-boot/tools/env/fw_setenv -c run_efi/uboot_env.config bootargs "$PARAMS"
ACCEL=kvm
else
ACCEL=hvf
fi
#minimum of 64M to initialize the EFI subsystem
${QEMU}qemu-system-aarch64 -nographic -nodefaults -machine virt -cpu cortex-a72 -serial mon:stdio -m 1G \
-drive if=pflash,format=raw,readonly=on,file=run_efi/QEMU_UBOOT.fd \
-drive if=pflash,format=raw,file=run_efi/QEMU_UBOOT_ENV.fd \
-drive file=run_efi/disk.img,format=raw,if=virtio
;;
qemu-tfa2)
if [ "$(uname -s)" != "Darwin" ]; then
truncate --size 64M run_efi/QEMU_UBOOT_ENV.fd
../u-boot/tools/env/fw_setenv -c run_efi/uboot_env.config bootargs "$PARAMS"
fi
truncate --size 64M run_efi/flash.bin
dd if=../arm-trusted-firmware/build/qemu/release/bl1.bin of=run_efi/flash.bin bs=4096 conv=notrunc > /dev/null 2>&1
dd if=../arm-trusted-firmware/build/qemu/release/fip.bin of=run_efi/flash.bin seek=64 bs=4096 conv=notrunc > /dev/null 2>&1
#need to have 1GB of RAM in the VM for TFA to work !!!
#https://elixir.bootlin.com/arm-trusted-firmware/v2.8/source/plat/qemu/qemu/include/platform_def.h#L181
${QEMU}qemu-system-aarch64 -nographic -nodefaults -machine virt,secure=on -cpu cortex-a72 -m 1G \
-chardev stdio,mux=on,id=char0 \
-mon chardev=char0,mode=readline \
-serial chardev:char0 \
-chardev file,id=char1,path=/tmp/secuart.log \
-serial chardev:char1 \
-drive if=pflash,format=raw,readonly=on,file=run_efi/flash.bin \
-drive if=pflash,format=raw,file=run_efi/QEMU_UBOOT_ENV.fd \
-drive file=run_efi/disk.img,format=raw,if=virtio
;;
qemu-tfa-honeycomb)
if [ "$(uname -s)" != "Darwin" ]; then
truncate --size 64M run_efi/QEMU_UBOOT_ENV.fd
../u-boot/tools/env/fw_setenv -c run_efi/uboot_env.config bootargs "$PARAMS"
fi
#truncate --size 64M run_efi/flash.bin
dd if=/Volumes/ff/arm-trusted-firmware/build/qemu/release/bl1.bin of=run_efi/flash.bin bs=4096 conv=notrunc > /dev/null 2>&1
dd if=/Volumes/ff/arm-trusted-firmware/build/qemu/release/fip.bin of=run_efi/flash.bin seek=64 bs=4096 conv=notrunc > /dev/null 2>&1
#need to have 1GB of RAM in the VM for TFA to work !!!
#https://elixir.bootlin.com/arm-trusted-firmware/v2.8/source/plat/qemu/qemu/include/platform_def.h#L181
${QEMU}qemu-system-aarch64 -nographic -nodefaults -machine virt,secure=on -cpu cortex-a72 -m 1G \
-chardev stdio,mux=on,id=char0 \
-mon chardev=char0,mode=readline \
-serial chardev:char0 \
-serial chardev:char0 \
-drive if=pflash,format=raw,readonly=on,file=run_efi/flash.bin \
-drive if=pflash,format=raw,file=run_efi/QEMU_UBOOT_ENV.fd \
-drive file=run_efi/disk.img,format=raw,if=virtio
;;
qemu-tfa1)
if [ "$(uname -s)" != "Darwin" ]; then
truncate --size 64M run_efi/QEMU_UBOOT_ENV.fd
../u-boot/tools/env/fw_setenv -c run_efi/uboot_env.config bootargs "$PARAMS"
fi
truncate --size 64M run_efi/flash.bin
dd if=../arm-trusted-firmware/build/qemu/release/bl1.bin of=run_efi/flash.bin bs=4096 conv=notrunc > /dev/null 2>&1
dd if=../arm-trusted-firmware/build/qemu/release/fip.bin of=run_efi/flash.bin seek=64 bs=4096 conv=notrunc > /dev/null 2>&1
#need to have 1GB of RAM in the VM for TFA to work !!!
#https://elixir.bootlin.com/arm-trusted-firmware/v2.8/source/plat/qemu/qemu/include/platform_def.h#L181
${QEMU}qemu-system-aarch64 -nographic -nodefaults -machine virt,secure=on -cpu cortex-a72 -m 1G \
-chardev stdio,mux=on,id=char0 \
-mon chardev=char0,mode=readline \
-serial chardev:char0 \
-serial chardev:char0 \
-drive if=pflash,format=raw,readonly=on,file=run_efi/flash.bin \
-drive if=pflash,format=raw,file=run_efi/QEMU_UBOOT_ENV.fd \
-drive file=run_efi/disk.img,format=raw,if=virtio
;;
qemu-el3)
stage_el3_flash run_efi/flash.bin 0xe000000
${QEMU}qemu-system-aarch64 -nographic -nodefaults -machine virt,secure=on -cpu cortex-a72 -m 64M \
-chardev stdio,mux=on,id=char0 \
-mon chardev=char0,mode=readline \
-serial chardev:char0 \
-serial chardev:char0 \
-drive if=pflash,format=raw,readonly=on,file=run_efi/flash.bin
;;
remote-emula4)
stage_el3_flash run_efi/flash.bin 0xe000000
;;
#-extra-symbols 'origin=barekit;path=target/aarch64-unknown-uefi/release/barekit.afx;map=barekit.mapsym;load-base=0x1000;relocated=0x0e000000' \
emula4-qemu)
stage_el3_flash run_efi/flash.bin 0xe000000
/home/ff/Emula4/build/Emula4 \
-control-dir /home/ff/barekit \
-platform-dir /home/ff/barekit \
-extra-symbols 'origin=copy-to-secmem-stub;path=target/aarch64-unknown-uefi/copy_to_secmem.elf;load-base=0' \
-extra-symbols 'origin=barekit;map=barekit.mapsym;load-base=0x1000;relocated=0x0e000000' \
-patching-triggers 'copy-to-secmem-stub:#entry,barekit:#entry' \
-memory-layout qemu \
-inject-fdt \
-reset-address 0 \
-vobj "CPU#name='A72@QEMU/0';MIDR_EL1=0x410fd083||hostcpu#cluster=P" \
-vobj "RAM#address=0x40000000;trampoline=true||hostmem#size=1024" \
-vobj "SECRAM#address=0x0e000000||hostmem#size=16" \
-vobj "fixed-clock#name=main_clock" \
-vobj "GICv3@QEMU#name=main_gic;root=true" \
-vobj "PL011#name=stdout-path;address=0x9000000;uartclk=main_clock;apb_pclk=main_clock;irq=spi:1@main_gic||pipe#path=/tmp/emula4-uart" \
-vobj "PL011#name=secure-stdout-path;address=0x9040000;uartclk=main_clock;apb_pclk=main_clock;irq=spi:2@main_gic||pipe#path=/tmp/emula4-secure-uart" \
-vobj "CFI#address=0x0||mapped-file#path=run_efi/flash.bin" \
-vobj "CFI#address=0x4000000||mapped-file#path=run_efi/AAVMF_VARS.fd"
;;
esac