From 623a30be55b809fcde1617ceea074d653485ea9f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 24 Jun 2018 16:01:33 +1000 Subject: [PATCH] waf: build hex file with and without bootloader this allows for DFU tools without losing parameters --- Tools/ardupilotwaf/chibios.py | 2 +- Tools/scripts/make_intel_hex.py | 48 +++++++++++++++++++++++++++++++++ Tools/scripts/make_intel_hex.sh | 30 --------------------- 3 files changed, 49 insertions(+), 31 deletions(-) create mode 100755 Tools/scripts/make_intel_hex.py delete mode 100755 Tools/scripts/make_intel_hex.sh diff --git a/Tools/ardupilotwaf/chibios.py b/Tools/ardupilotwaf/chibios.py index 21e17bdcee..c19bff2cd0 100644 --- a/Tools/ardupilotwaf/chibios.py +++ b/Tools/ardupilotwaf/chibios.py @@ -113,7 +113,7 @@ class build_abin(Task.Task): class build_intel_hex(Task.Task): '''build an intel hex file for upload with DFU''' color='CYAN' - run_str='${TOOLS_SCRIPTS}/make_intel_hex.sh ${SRC} ${FLASH_RESERVE_START_KB} ${TGT}' + run_str='${TOOLS_SCRIPTS}/make_intel_hex.py ${SRC} ${FLASH_RESERVE_START_KB}' always_run = True def keyword(self): return "Generating" diff --git a/Tools/scripts/make_intel_hex.py b/Tools/scripts/make_intel_hex.py new file mode 100755 index 0000000000..834f6e28a3 --- /dev/null +++ b/Tools/scripts/make_intel_hex.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python + +import sys, os, shutil +import intelhex + +# make two intel hex files, one including bootloader and one without +# for loading with DFU based tools + +if len(sys.argv) != 4: + print("Usage: make_intel_hex.py BINFILE BOOTLOADER RESERVE_KB") + sys.exit(1) + +scripts = os.path.dirname(__file__) +binfile = sys.argv[1] +bootloaderfile = sys.argv[2] +reserve_kb = int(sys.argv[3]) +(root,ext) = os.path.splitext(binfile) +hexfile = root + ".hex" +hex_with_bl = root + "_with_bl.hex" + +if not os.path.exists(binfile): + print("Can't find bin file %s" % binfile) + sys.exit(1) + +if not os.path.exists(bootloaderfile): + print("Can't find bootloader file %s" % bootloaderfile) + sys.exit(1) + +blimage = bytes(open(bootloaderfile, "rb").read()) +blimage += bytes(chr(255) * (reserve_kb * 1024 - len(blimage))) + +appimage = bytes(open(binfile,"rb").read()) + +with_bl = blimage + appimage + +tmpfile = hexfile + ".tmp" + +open(tmpfile, "wb").write(appimage) + +intelhex.bin2hex(tmpfile, hexfile, offset=(0x08000000 + reserve_kb*1024)) + +open(tmpfile, "wb").write(with_bl) + +intelhex.bin2hex(tmpfile, hex_with_bl, offset=0x08000000) + +os.unlink(tmpfile) +print("Created %s" % hexfile) +print("Created %s" % hex_with_bl) diff --git a/Tools/scripts/make_intel_hex.sh b/Tools/scripts/make_intel_hex.sh deleted file mode 100755 index 32c3285f64..0000000000 --- a/Tools/scripts/make_intel_hex.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/sh -# make an intel hex file including bootloader, for loading with DFU - -if [ $# -lt 4 ]; then - echo "Usage: make_intel_hex.sh BINFILE BOOTLOADER RESERVE_KB HEXFILEOUT" - exit 1 -fi - -SCRIPTS=$(dirname $0) - -BINFILE="$1" -BOOTLOADERFILE="$2" -RESERVE_KB="$3" -HEXFILE="$4" - -[ -f "$BINFILE" ] || { - echo "Can't find bin file $BINFILE" - exit 1 -} - -[ -f "$BOOTLOADERFILE" ] || { - echo "Can't find bootloader file $BOOTLOADERFILE" - exit 1 -} - -cat "$BOOTLOADERFILE" > "$HEXFILE".tmp -dd bs=1024 seek=$RESERVE_KB if="$BINFILE" of="$HEXFILE".tmp 2>&1 -"$SCRIPTS"/bin2hex.py --offset 0x08000000 "$HEXFILE".tmp "$HEXFILE" -rm -f "$HEXFILE".tmp -echo "Created $HEXFILE"