From 482f4c0283466a11b67dd2215ba817a78aca02bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Onur=20=C3=96zkan?= Date: Sat, 1 Aug 2026 21:01:50 +0300 Subject: [PATCH] scripts: improve create-dfu-image.sh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Onur Özkan --- boards/kakute-f7-mini-v3/README.md | 6 ++---- scripts/analyze-fw.py | 2 +- scripts/create-dfu-image.sh | 22 +++++++++++++++++++--- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/boards/kakute-f7-mini-v3/README.md b/boards/kakute-f7-mini-v3/README.md index 77a3f34..b3cf12e 100644 --- a/boards/kakute-f7-mini-v3/README.md +++ b/boards/kakute-f7-mini-v3/README.md @@ -15,12 +15,10 @@ cargo build --release -p kaptan-kakute-f7-mini-v3 --features firmware --target t Create its DFU (device firmware update) image: ```sh -./scripts/create-dfu-image.sh \ - target/thumbv7em-none-eabihf/release/kaptan-kakute-f7-mini-v3 \ - target/thumbv7em-none-eabihf/release/kaptan-kakute-f7-mini-v3.bin +./scripts/create-dfu-image.sh target/thumbv7em-none-eabihf/release/kaptan-kakute-f7-mini-v3 ``` -The converter works with any firmware ELF. It uses rustup's `llvm-tools-preview` component which the workspace toolchain installs automatically. +The converter derives the `.bin` path and matching board `memory.x`, then prints the firmware size report. It uses rustup's `llvm-tools-preview` component which the workspace toolchain installs automatically. ## Flash over USB DFU diff --git a/scripts/analyze-fw.py b/scripts/analyze-fw.py index c93787e..b7ea454 100755 --- a/scripts/analyze-fw.py +++ b/scripts/analyze-fw.py @@ -2,7 +2,7 @@ """Show flash, static RAM and ELF-section use for embedded firmware. Usage: - python3 scripts/analyze_kaptan_firmware.py + scripts/analyze-fw.py """ import re diff --git a/scripts/create-dfu-image.sh b/scripts/create-dfu-image.sh index 925708c..f8372d7 100755 --- a/scripts/create-dfu-image.sh +++ b/scripts/create-dfu-image.sh @@ -1,16 +1,31 @@ #!/usr/bin/env bash set -euo pipefail -if [[ $# -ne 2 ]]; then - printf 'Usage: %s \n' "$0" >&2 +if [[ $# -ne 1 ]]; then + printf 'Usage: %s \n' "$0" >&2 exit 2 fi readonly input_elf="$1" -readonly output_image="$2" +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 host="$(rustc -vV | sed -n 's/^host: //p')" readonly llvm_objcopy="$(rustc --print sysroot)/lib/rustlib/$host/bin/llvm-objcopy" +if [[ ! -f "$input_elf" ]]; then + printf 'firmware ELF does not exist: %s\n' "$input_elf" >&2 + exit 1 +fi + +if [[ ! -f "$memory_x" ]]; then + printf 'cannot find the linker layout for board %q: %s\n' "$board_name" "$memory_x" >&2 + exit 1 +fi + if [[ ! -x "$llvm_objcopy" ]]; then printf 'llvm-objcopy is unavailable; install it with: rustup component add llvm-tools-preview\n' >&2 exit 1 @@ -18,3 +33,4 @@ 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"