diff --git a/build-firmware.sh b/build-firmware.sh index 4bac525..bddf417 100755 --- a/build-firmware.sh +++ b/build-firmware.sh @@ -22,14 +22,38 @@ echo "==> Building toolchain image ($IMAGE)" docker build --platform linux/amd64 -t "$IMAGE" "$REPO_DIR/docker" echo "==> Running build in container ($PLATFORM)" +BUILD_LOG="$(mktemp)" +trap 'rm -f "$BUILD_LOG"' EXIT +# Stream to the terminal and capture a copy so we can re-show the linker's +# memory-usage table at the end (pipefail makes a build failure still abort). docker run --rm --platform linux/amd64 \ -v "$REPO_DIR":/work \ "$IMAGE" \ - bash /work/docker/build.sh "$PLATFORM" + bash /work/docker/build.sh "$PLATFORM" 2>&1 | tee "$BUILD_LOG" echo echo "==> Firmware ready:" echo " $REPO_DIR/MDUV380_firmware/build/${OUT}.bin" + +# Re-print the linker's per-region memory usage (emitted by --print-memory-usage +# during the link) with the free bytes worked out for each region. +if grep -q "Memory region" "$BUILD_LOG"; then + echo + echo "==> Memory usage (FLASH = code budget, RAM/CCMRAM = data budget):" + grep -A3 "Memory region" "$BUILD_LOG" | awk ' + function toBytes(n, unit) { + if (unit == "KB") return n * 1024 + if (unit == "MB") return n * 1024 * 1024 + if (unit == "GB") return n * 1024 * 1024 * 1024 + return n # already bytes + } + NR == 1 { printf " %-9s %11s %12s %8s %11s\n", "Region", "Used", "Size", "Used%", "Free"; next } + /:/ { + gsub(":", "", $1) + used = toBytes($2, $3); size = toBytes($4, $5); free = size - used + printf " %-9s %9d B %10d B %7s %9d B\n", $1, used, size, $6, free + }' +fi echo echo "Flash it (with the radio in firmware-update mode) using:" echo " ./MDUV380_firmware/tools/opengd77_stm32_firmware_loader.py \\" diff --git a/docker/firmware.mk b/docker/firmware.mk index 9f90930..69eb2be 100644 --- a/docker/firmware.mk +++ b/docker/firmware.mk @@ -63,6 +63,7 @@ ASFLAGS := $(CPU) -x assembler-with-cpp -DDEBUG -g3 -MMD -MP LDSCRIPT := ../STM32F405VGTX_FLASH.ld LDFLAGS := $(CPU) -T$(LDSCRIPT) --specs=nano.specs \ -Wl,-Map=$(TARGET).map,--cref -Wl,--gc-sections -static \ + -Wl,--print-memory-usage \ -Wl,--start-group -lc -lm -Wl,--end-group # ---- Sources --------------------------------------------------------------