OXYGENHUB
◆ main x16-emulator / .flow / image / build-riscv64.sh
2.8 KiB · Bourne Again Shell (bash) · executable · last changed ci: boot the R49 ROM on narvi-1 instead of the conformance suite 15 days ago source blame history raw
1
#!/bin/sh
2
# Build the riscv64 image the pipeline's jobs run in on narvi-1, and write it
3
# as a root file system tarball for `flow rootfs import`. There is no Docker
4
# on a RISC-V board, so this is Ubuntu Base 24.04.5 riscv64, checked against
5
# its published SHA-256, with the build's packages installed by apt in a
6
# chroot. Run it on a riscv64 Linux machine (narvi) as root or a user with
7
# sudo, then
8
#
9
#     FLOW_HOME=~/flow ~/flow/bin/flow rootfs import x16emu-riscv64.tar
10
#
11
# and pin the printed hash in .flow/pipeline.kdl. Rebuild, re-import and
12
# re-pin when the packages below change.
13
set -eu
14
here=$(cd "$(dirname "$0")" && pwd)
15
out=${1:-$here/x16emu-riscv64.tar}
16
release=24.04.5
17
base=ubuntu-base-$release-base-riscv64.tar.gz
18
sha256=651c516f291259ec913caa1efd0cfff738cd223adfc6617c884f07af487f08cf
19
# What the Makefile needs, as README.md lists for riscv64 Linux: C11 and
20
# C++17 compilers, make, SDL2 and zlib; and Python with pytest for the
21
# conformance suite, once the syscall tier lets a job use loopback TCP.
22
packages="build-essential make libsdl2-dev zlib1g-dev python3 python3-pytest"
23
24
test "$(uname -m)" = riscv64 || { echo "build-riscv64.sh: run this on a riscv64 machine" >&2; exit 1; }
25
work=$(mktemp -d)
26
root=$work/root
27
cleanup() {
28
	sudo umount "$root/proc" "$root/dev" 2>/dev/null || true
29
	sudo rm -rf "$work"
30
}
31
trap cleanup EXIT
32
33
curl -fsSL -o "$work/$base" "https://cdimage.ubuntu.com/ubuntu-base/releases/$release/release/$base"
34
echo "$sha256  $work/$base" | sha256sum -c - >/dev/null
35
mkdir "$root"
36
sudo tar -C "$root" -xzf "$work/$base"
37
sudo mv "$root/etc/resolv.conf" "$work/resolv.conf.image" 2>/dev/null || true
38
sudo cp /etc/resolv.conf "$root/etc/resolv.conf"
39
sudo mount --bind /dev "$root/dev"
40
sudo mount -t proc proc "$root/proc"
41
sudo chroot "$root" sh -c "
42
	export DEBIAN_FRONTEND=noninteractive
43
	apt-get update -q >/dev/null
44
	apt-get install -y -q --no-install-recommends $packages >/dev/null
45
	apt-get clean
46
	rm -rf /var/lib/apt/lists/*"
47
sudo umount "$root/proc" "$root/dev"
48
# The R49 ROM, from the emulator's own R49 release, for the boot job: the
49
# zip and the ROM in it both checked against their SHA-256.
50
r49=https://github.com/X16Community/x16-emulator/releases/download/r49/x16emu_linux-x86_64-r49.zip
51
curl -fsSL -o "$work/r49.zip" "$r49"
52
echo "efb2d4ad36ae4244370004891aa67bdf85d2ec01b42b7f12f97b48b62aff009d  $work/r49.zip" | sha256sum -c - >/dev/null
53
python3 -c 'import sys, zipfile; open(sys.argv[2], "wb").write(zipfile.ZipFile(sys.argv[1]).read("rom.bin"))' "$work/r49.zip" "$work/rom.bin"
54
echo "b81654cc8c87ed96e3ffc7c8e7c312c9f3b7b870c7bb34de61e61eac931b819a  $work/rom.bin" | sha256sum -c - >/dev/null
55
sudo install -D -m 0644 "$work/rom.bin" "$root/opt/x16rom/rom.bin"
56
sudo rm "$root/etc/resolv.conf"
57
sudo mv "$work/resolv.conf.image" "$root/etc/resolv.conf" 2>/dev/null || true
58
sudo tar -C "$root" -cf "$out" .
59
sudo chown "$(id -u):$(id -g)" "$out"
60
echo "$out"