build(f722): centralize linker layout

This commit is contained in:
Onur Özkan committed 2026-08-22 18:38:06 +03:00
1 parent 387fdaad23
commit ceb2134392
8 files changed
+358 -77

No files matched your search

+11 -8
View File
@@ -1,18 +1,16 @@
#!/usr/bin/env bash
set -euo pipefail
if [[ $# -ne 1 ]]; then
printf 'Usage: %s <firmware.elf>\n' "$0" >&2
if [[ $# -lt 1 || $# -gt 2 ]]; then
printf 'Usage: %s <firmware.elf> [memory.x]\n' "$0" >&2
exit 2
fi
readonly input_elf="$1"
readonly firmware_name="$(basename "${input_elf%.elf}")"
readonly board_name="${firmware_name#kaptan-}"
readonly output_image="${input_elf%.elf}.bin"
readonly script_directory="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
readonly workspace_root="$(cd -- "$script_directory/.." && pwd)"
readonly memory_x="$workspace_root/boards/$board_name/memory.x"
readonly memory_x="${2:-$workspace_root/platforms/stm32f7/link/f722/memory.x}"
readonly host="$(rustc -vV | sed -n 's/^host: //p')"
readonly llvm_objcopy="$(rustc --print sysroot)/lib/rustlib/$host/bin/llvm-objcopy"
@@ -22,7 +20,7 @@ if [[ ! -f "$input_elf" ]]; then
fi
if [[ ! -f "$memory_x" ]]; then
printf 'cannot find the linker layout for board %q: %s\n' "$board_name" "$memory_x" >&2
printf 'cannot find linker layout: %s\n' "$memory_x" >&2
exit 1
fi
@@ -31,6 +29,11 @@ if [[ ! -x "$llvm_objcopy" ]]; then
exit 1
fi
"$llvm_objcopy" -O binary "$input_elf" "$output_image"
printf 'DFU image: %s\n' "$output_image"
"$script_directory/analyze-fw.py" "$input_elf" "$memory_x"
temporary_image="$(mktemp "${output_image}.tmp.XXXXXX")"
trap 'rm -f -- "$temporary_image"' EXIT
"$llvm_objcopy" -O binary "$input_elf" "$temporary_image"
mv -f -- "$temporary_image" "$output_image"
trap - EXIT
printf 'DFU image: %s\n' "$output_image"