Repository navigation
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·193 lines (180 loc) · 8.4 KB
/
Copy pathrun.sh
File metadata and controls
executable file
·193 lines (180 loc) · 8.4 KB
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
#!/usr/bin/env bash
#
# Boot under QEMU. Does not build unless asked.
#
# ./run.sh boot whatever is built — AROS if its ELF exists,
# otherwise Emu68 on its own
# ./run.sh --no-aros Emu68 alone, even if the AROS ELF is there
# ./run.sh --no-sd AROS without an SD card
# ./run.sh --sd PATH a different card
# ./run.sh --headless serial only, no window
# ./run.sh --gui force a window even with no display detected
# GUI boots include a USB tablet
# ./run.sh --serial FILE send the serial console to a file instead of stdio
# ./run.sh --debug FLAGS adds sysdebug=FLAGS to the kernel arguments
# ./run.sh --build build Emu68 first (not done by default)
# ./run.sh --clean rebuild Emu68 from scratch first (implies --build)
# ./run.sh --no-build accepted and ignored; building is already off
# ./run.sh -- <args...> everything after -- goes to qemu
#
# BELLATRIX_RIGEL=0/1 forces the classic chipset off or on for this boot; the
# default is whatever the last build put in the image. BOOTARGS replaces the
# kernel command line outright.
#
# BELLATRIX_CHIPDIV=N runs the chipset's clock at 1/N of real time. With the
# chipset on, this script defaults it to 8 because QEMU cannot deliver a fifth
# of the colour clocks real time asks for and the boot stalls without it; =1
# restores hardware's behaviour. A card is unaffected -- see make-sdcard.sh.
# BELLATRIX_CHIPFLOOR=1 keeps the chipset core from taking steps too short to
# reach a deadline. Off by default; see below.
#
# QEMU emulates the Raspberry Pi. Emu68 is the bare-metal owner; when AROS is
# in play, Emu68 loads its m68k ELF from -initrd. Ctrl-A X quits.
#
# Pieces, and what builds them:
# out/images/{Bellatrix,Emu68}.img scripts/build.sh (--build, or run it)
# out/firmware/bcm2710-*.dtb scripts/build.sh
# out/aros/aros-emu68-m68k.elf scripts/build-aros.sh (never built here — it
# also builds a cross toolchain)
# out/aros/sd.img scripts/make-sdcard.sh
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
KERNEL_NAME="$(cat "$ROOT/out/images/Emu68.kernel-name" 2>/dev/null || echo Emu68.img)"
KERNEL="$ROOT/out/images/$KERNEL_NAME"
DTB="$ROOT/out/firmware/bcm2710-rpi-3-b.dtb"
INITRD="$ROOT/out/aros/aros-emu68-m68k.elf"
SD="$ROOT/out/aros/sd.img"
RIGEL_STAMP="$ROOT/out/images/Emu68.config-rigel"
MONITOR="${BELLATRIX_QEMU_MONITOR:-/tmp/emu68-monitor.sock}"
# Off by default. Booting and building are different intentions, and a run
# that silently rebuilds takes an unpredictable amount of time -- which matters
# when the thing being measured is how long a boot takes.
BUILD=0
CLEAN=""
# A window by default when there is a display to put it on — AROS is a
# graphical system and the framebuffer is usually the point. Falls back to
# serial-only automatically, so this still works over SSH or in CI.
if [ -n "${DISPLAY:-}${WAYLAND_DISPLAY:-}" ]; then
DISPLAY_ARG="gtk"
else
DISPLAY_ARG="none"
fi
WANT_AROS="auto"
USE_SD=1
DEBUG=""
# Where the AUX mini-UART console goes. stdio for a human; a file for anything
# unattended, which is what scripts/boot-timing.py uses so it can read the log
# while the run is still going. PL011 remains disconnected here for Bluetooth.
SERIAL="stdio"
EXTRA=()
while [ $# -gt 0 ]; do
case "$1" in
--build) BUILD=1 ;;
--no-build) BUILD=0 ;;
--clean) CLEAN="clean"; BUILD=1 ;;
--gui) DISPLAY_ARG="gtk" ;;
--headless) DISPLAY_ARG="none" ;;
--serial) SERIAL="file:$2"; shift ;;
--no-aros) WANT_AROS="no" ;;
--no-sd) USE_SD=0 ;;
--sd) SD="$2"; shift ;;
--debug) DEBUG="$2"; shift ;;
--) shift; EXTRA=("$@"); break ;;
-h|--help) sed -n '2,33p' "$0" | sed 's/^# \?//'; exit 0 ;;
*) echo "unknown option: $1 (try --help)" >&2; exit 2 ;;
esac
shift
done
[ "$BUILD" = 1 ] && "$ROOT/scripts/build.sh" ${CLEAN:+$CLEAN}
for f in "$KERNEL" "$DTB"; do
[ -f "$f" ] || { echo "ERROR: missing $f — run scripts/build.sh" >&2; exit 1; }
done
command -v qemu-system-aarch64 >/dev/null \
|| { echo "ERROR: qemu-system-aarch64 not found" >&2; exit 1; }
case "$WANT_AROS" in
no) AROS=0 ;;
auto) [ -f "$INITRD" ] && AROS=1 || AROS=0 ;;
esac
QEMU=(
qemu-system-aarch64
-M raspi3b
-accel tcg,tb-size=64
-kernel "$KERNEL"
-dtb "$DTB"
# QEMU raspi3b exposes PL011 first and AUX mini-UART second. Bellatrix logs
# only through the latter; PL011 is deliberately reserved for Bluetooth.
-serial null
-serial "$SERIAL"
-display "$DISPLAY_ARG"
-no-reboot
-monitor "unix:$MONITOR,server,nowait"
)
# The raspi3b machine provides the DWC2 USB host controller, but QEMU does not
# populate it with a pointing device automatically. Use an absolute USB HID
# tablet for graphical runs: it does not depend on frontend pointer capture,
# and QEMU's SDL relative usb-mouse path reverses both motion axes here.
if [ "$DISPLAY_ARG" != "none" ]; then
QEMU+=(-device usb-tablet)
fi
if [ "$AROS" = 1 ]; then
# No display argument any more. `nocomposition` used to be required: it kept
# AROSMonDrvs from starting DEVS:Monitors/Compositor, which installed and
# then left the screen on the Emu68 logo. Upstream b72155e2bb (pin
# e9e1f786da) deleted that program -- every display now owns a compositor
# inside gfx.hidd -- and AROSMonDrvs ignores the argument. A boot without it
# reaches the desktop (ISSUE-0088, M10a).
BOOTARGS="${BOOTARGS-}"
# The chipset is a boot argument now, on both sides of the boundary: `rigel`
# tells Emu68 to build the classic machine and tells AROS to expect it. The
# default follows the last build -- an image with no chipset in it has
# nothing to enable -- and BELLATRIX_RIGEL=0/1 overrides that, which is how
# one image gets booted both ways without rebuilding.
if [ "${BELLATRIX_RIGEL:-$(cat "$RIGEL_STAMP" 2>/dev/null || echo 0)}" = 1 ]; then
BOOTARGS="$BOOTARGS rigel"
# How fast chipset time runs, and why this script picks a default where
# the card does not.
#
# Chipset time comes from the wall clock. A host that cannot deliver
# 3546895 colour clocks a second does not get a slower chipset: it gets
# a core pinned at 100% believing it is behind, four fifths of the
# requested colour clocks discarded at the catch-up cap, and a 5.9 ms
# lock hold in front of every CPU access to the classic domain.
# Measured here at 690000 CCK/s -- and the boot then stalls in the
# graphics drivers rather than reaching a desktop.
#
# This script is the QEMU path and only that; a card is written by
# make-sdcard.sh and is not affected by anything here. So it defaults
# the divisor rather than leaving a chipset boot that does not work and
# a knob nobody knew to reach for. 8 is what was measured: it meets
# 99.6% of the scaled demand with nothing discarded, and the boot
# reaches display takeover.
#
# BELLATRIX_CHIPDIV=1 restores hardware's own behaviour for anyone who
# wants to reproduce it here.
BOOTARGS="$BOOTARGS bellatrix.chipdiv=${BELLATRIX_CHIPDIV:-8}"
fi
# BELLATRIX_CHIPFLOOR=1 stops the chipset core taking a step too short to
# reach an observable deadline. Off by default: it is a performance change
# to the chipset, and it makes a CPU polling the beam with nothing else
# programmed read a position up to two scanlines stale.
if [ "${BELLATRIX_CHIPFLOOR:-0}" = 1 ]; then
BOOTARGS="$BOOTARGS bellatrix.chipfloor"
fi
QEMU+=(-initrd "$INITRD")
if [ "$USE_SD" = 1 ]; then
[ -f "$SD" ] || { echo "ERROR: missing $SD — run scripts/make-sdcard.sh" >&2; exit 1; }
QEMU+=(-drive "file=$SD,if=sd,format=raw")
fi
WHAT="Emu68 + AROS"
[ "$USE_SD" = 1 ] && WHAT="$WHAT + $(basename "$SD")"
else
BOOTARGS="${BOOTARGS:-enable_cache}"
WHAT="Emu68 alone"
[ -f "$INITRD" ] || echo "[run] no AROS ELF — run scripts/build-aros.sh to boot it too"
fi
[ -n "$DEBUG" ] && BOOTARGS="$BOOTARGS sysdebug=$DEBUG"
BOOTARGS="${BOOTARGS# }"
QEMU+=(-append "$BOOTARGS")
echo "[run] $WHAT | display: $DISPLAY_ARG | append: $BOOTARGS"
echo "[run] Ctrl-A X to quit; 'nc -U $MONITOR' for the QEMU monitor"
exec "${QEMU[@]}" "${EXTRA[@]}"