Files
RCM-Emulator/tests/kernelcpu/build.sh
T
2026-11-05 23:45:44 +01:00

26 lines
1.1 KiB
Bash
Executable File

#!/bin/sh
# Builds tests/kernelcpu/payload.bin: cpu0.S with devkitA64's assembler,
# embedded as a word array into the BPMP payload built with arm-none-eabi.
set -e
D=$(dirname "$0")
A64=${A64:-/opt/devkitpro/devkitA64/bin/aarch64-none-elf-}
ARM=${ARM:-/opt/devkitpro/devkitARM/bin/arm-none-eabi-}
${A64}gcc -c -o "$D/cpu0.o" "$D/cpu0.S"
${A64}ld -Ttext=0xA0000000 -o "$D/cpu0.elf" "$D/cpu0.o"
${A64}objcopy -O binary "$D/cpu0.elf" "$D/cpu0.bin"
python3 - "$D/cpu0.bin" "$D/cpu0_blob.h" <<'PY'
import sys, struct
b = open(sys.argv[1], "rb").read()
b += b"\0" * (-len(b) % 4)
w = struct.unpack("<%dI" % (len(b) // 4), b)
with open(sys.argv[2], "w") as f:
f.write("/* Generated by build.sh from cpu0.S. */\nstatic const u32 cpu0_blob[] = {\n")
for i in range(0, len(w), 6):
f.write(" " + ", ".join("0x%08x" % x for x in w[i:i + 6]) + ",\n")
f.write("};\n")
PY
${ARM}gcc -march=armv4t -marm -Os -ffreestanding -nostdlib -fno-builtin -I"$D" \
-T "$D/link.ld" -o "$D/payload.elf" "$D/payload.c"
${ARM}objcopy -O binary "$D/payload.elf" "$D/payload.bin"
echo "built $D/payload.bin"