Files

34 lines
1.4 KiB
Bash
Executable File

#!/bin/sh
# Builds linux/boot.bin: shim.S (an AArch64 assembler) embedded in the BPMP payload.
set -e
D=$(dirname "$0")
# devkitPro when it is installed, else the distribution's cross compilers
# (gcc-aarch64-linux-gnu, gcc-arm-none-eabi), as on CI.
DKP=${DEVKITPRO:-/opt/devkitpro}
if [ -z "$A64" ]; then
A64=aarch64-linux-gnu-
if [ -x "$DKP/devkitA64/bin/aarch64-none-elf-gcc" ]; then A64=$DKP/devkitA64/bin/aarch64-none-elf-; fi
fi
if [ -z "$ARM" ]; then
ARM=arm-none-eabi-
if [ -x "$DKP/devkitARM/bin/arm-none-eabi-gcc" ]; then ARM=$DKP/devkitARM/bin/arm-none-eabi-; fi
fi
${A64}gcc -c -o "$D/shim.o" "$D/shim.S"
${A64}ld -Ttext=0xA0000000 -o "$D/shim.elf" "$D/shim.o"
${A64}objcopy -O binary "$D/shim.elf" "$D/shim.bin"
python3 - "$D/shim.bin" "$D/shim_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 shim.S. */\nstatic const u32 shim_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/boot.elf" "$D/boot.c"
${ARM}objcopy -O binary "$D/boot.elf" "$D/boot.bin"
echo "built $D/boot.bin"