From 960c0d0f8b9ff752aae2ba5fa5425a907324ab74 Mon Sep 17 00:00:00 2001 From: Andy Piper Date: Fri, 4 Feb 2022 17:56:35 +0000 Subject: [PATCH] scripts: allow more time for external flash verification create ssbl uploader script for SPRacingH7 --- Tools/scripts/ssbl_uploader.sh | 18 ++++++++++++++++++ Tools/scripts/uploader.py | 25 ++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 Tools/scripts/ssbl_uploader.sh diff --git a/Tools/scripts/ssbl_uploader.sh b/Tools/scripts/ssbl_uploader.sh new file mode 100644 index 0000000000..573cefbc17 --- /dev/null +++ b/Tools/scripts/ssbl_uploader.sh @@ -0,0 +1,18 @@ +#!/bin/sh +# Upload a firmware image to a flight controller using the second-stage bootloader + +if [ $# -lt 2 ]; then + echo "Usage: ssbl_uploader.sh BOARD TARGET" + exit 1 +fi + +BOARD="$1" +TARGET="$2" +TARGET2MB=build/${BOARD}/bin/${TARGET}_2MB.bin + +rm -f "${TARGET2MB}-VERIFY.bin" +dd if=/dev/zero ibs=1k count=2048 of=${TARGET2MB} +dd conv=notrunc if=build/${BOARD}/bin/${TARGET}_extf.bin of=${TARGET2MB} +dfu-util -D "${TARGET2MB}" -s 0x90100000:0x200000 +dfu-util -U "${TARGET2MB}-VERIFY.bin" -s 0x90100000:0x200000 +diff -sb ${TARGET2MB} "${TARGET2MB}-VERIFY.bin" diff --git a/Tools/scripts/uploader.py b/Tools/scripts/uploader.py index 7df0b5e398..c7abdd4d27 100755 --- a/Tools/scripts/uploader.py +++ b/Tools/scripts/uploader.py @@ -661,10 +661,33 @@ class uploader(object): size_bytes = chr(size) print("\n", end='') self.__drawProgressBar(label, 1, 100) + expect_crc = fw.extf_crc(size) self.__send(uploader.EXTF_GET_CRC + size_bytes + uploader.EOC) - report_crc = self.__recv_int() + + # crc can be slow, give it 10s + deadline = time.time() + 10.0 + while time.time() < deadline: + + # Draw progress bar + estimatedTimeRemaining = deadline-time.time() + if estimatedTimeRemaining >= 4.0: + self.__drawProgressBar(label, 10.0-estimatedTimeRemaining, 4.0) + else: + self.__drawProgressBar(label, 5.0, 5.0) + sys.stdout.write(" (timeout: %d seconds) " % int(deadline-time.time())) + sys.stdout.flush() + + try: + report_crc = self.__recv_int() + break + except Exception: + continue + + if time.time() >= deadline: + raise RuntimeError("Program CRC timed out") + self.__getSync() if report_crc != expect_crc: print("\nExpected 0x%x" % expect_crc)