Files
krane-fb-stub/build.sh
T
vhaudiquet 64e19c213a krane-fb-stub: arm64 framebuffer test payload for depthcharge
Minimal freestanding arm64 binary that depthcharge boots as a kernel:
parses depthcharge's /firmware/coreboot DTB node, walks the coreboot
table, finds LB_TAG_FRAMEBUFFER, and paints red/yellow/green/blue
checkpoints (~2s each) into the live boot-splash framebuffer.

Verified against coreboot tables header, Linux arm64 booting.rst, and
depthcharge's fit.c/boot64.c. Host parser tests pass against the live
/sys/firmware/fdt; full red->yellow->green->blue sequence verified
end-to-end under qemu-system-aarch64; packed image verifies with the
ChromeOS devkeys.
2026-08-29 19:21:28 +02:00

51 lines
1.7 KiB
Bash
Executable File

#!/bin/sh
# build.sh — build krane-fb-stub raw arm64 binary.
# Output: krane-fb-stub.bin (arm64 Linux Image with 64-byte header).
set -e
cd "$(dirname "$0")"
CC=aarch64-linux-gnu-gcc
OBJCOPY=aarch64-linux-gnu-objcopy
READELF=aarch64-linux-gnu-readelf
OBJDUMP=aarch64-linux-gnu-objdump
CFLAGS="-O2 -ffreestanding -fPIC -fno-builtin -fno-stack-protector \
-fno-unwind-tables -fno-asynchronous-unwind-tables -mstrict-align \
-mgeneral-regs-only -Wall -Wextra -Werror"
${CC} -c stub.S -o stub_head.o
${CC} -c main.c -o main.o ${CFLAGS}
${CC} -nostdlib -nostartfiles -static -no-pie -Wl,-T,linker.ld,-n,-z,max-page-size=4096 \
-o krane-fb-stub.elf stub_head.o main.o
# The payload is copied to an arbitrary 2MiB-aligned slot with no relocation
# processing: any dynamic relocation in the linked image is a build failure.
if ${READELF} -r krane-fb-stub.elf | grep -q R_AARCH64; then
echo "FATAL: dynamic relocations present:" >&2
${READELF} -r krane-fb-stub.elf
exit 1
fi
# .bss is not copied by depthcharge; everything we use must be in the file.
BSS=$(${OBJDUMP} -h krane-fb-stub.elf | awk '$3==".bss" {print $3}')
if [ -n "$BSS" ]; then
echo "FATAL: .bss is non-empty; image_size must cover all state" >&2
exit 1
fi
${OBJCOPY} -O binary krane-fb-stub.elf krane-fb-stub.bin
# Patch image_size (offset 0x10, LE u64) to the final file size.
python3 - "$PWD/krane-fb-stub.bin" <<'EOF'
import os, struct, sys
path = sys.argv[1]
size = os.path.getsize(path)
with open(path, "r+b") as f:
f.seek(0x10)
f.write(struct.pack("<Q", size))
print(f"image_size patched: {size} (0x{size:x}) bytes")
EOF
echo "OK: krane-fb-stub.bin built."
${OBJDUMP} -h krane-fb-stub.elf | sed -n '4,12p'