diff --git a/scripts/create-dfu-image.sh b/scripts/create-dfu-image.sh new file mode 100755 index 0000000..925708c --- /dev/null +++ b/scripts/create-dfu-image.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +set -euo pipefail + +if [[ $# -ne 2 ]]; then + printf 'Usage: %s \n' "$0" >&2 + exit 2 +fi + +readonly input_elf="$1" +readonly output_image="$2" +readonly host="$(rustc -vV | sed -n 's/^host: //p')" +readonly llvm_objcopy="$(rustc --print sysroot)/lib/rustlib/$host/bin/llvm-objcopy" + +if [[ ! -x "$llvm_objcopy" ]]; then + printf 'llvm-objcopy is unavailable; install it with: rustup component add llvm-tools-preview\n' >&2 + exit 1 +fi + +"$llvm_objcopy" -O binary "$input_elf" "$output_image" +printf 'DFU image: %s\n' "$output_image"