xref: /aosp_15_r20/external/coreboot/util/riscv/make-spike-elf.sh (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1#!/usr/bin/env sh
2#
3# This script is based on:
4# https://docs.google.com/document/d/1Pvf9Yxorcd3sbgs8WcomcTl3J4bmX6e1UE0ROCefR88
5
6set -e
7
8usage() {
9	echo "This script converts a flat file into an ELF, that can be passed"
10	echo "to SPIKE, the RISC-V reference emulator."
11	echo ""
12	echo "Usage: $0 coreboot.rom coreboot.elf"
13}
14
15if [ $# -ne 2 ]; then
16	usage
17	exit 1
18fi
19
20FLAT_FILE="$1"
21OBJECT_FILE=$(mktemp /tmp/coreboot-spike.XXXXXX)
22ELF_FILE="$2"
23TOOL_PATH="$(dirname "$0")"
24XGCC_BIN="$TOOL_PATH/../crossgcc/xgcc/bin"
25
26"$XGCC_BIN/riscv64-elf-objcopy" -I binary -O elf64-littleriscv \
27	-B riscv "$FLAT_FILE" "$OBJECT_FILE"
28"$XGCC_BIN/riscv64-elf-ld" "$OBJECT_FILE" -T "$TOOL_PATH/spike-elf.ld" \
29	 -o "$ELF_FILE"
30rm "$OBJECT_FILE"
31