From 88135b8ba5895763ae927c89981ccca0be5c14c3 Mon Sep 17 00:00:00 2001 From: jindaxia Date: Sun, 7 Mar 2021 21:49:50 +0800 Subject: [PATCH] support select file to flash a jumploader --- src/main/python/main.py | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/main/python/main.py b/src/main/python/main.py index 7185463..c4372ce 100644 --- a/src/main/python/main.py +++ b/src/main/python/main.py @@ -348,6 +348,15 @@ def sanity_check_qmk_firmware(self, firmware, offset=0): return False return True + def check_jumperloader_firmware(self, jumper_loader): + # check the size so we don't trash bootloader + # (ok, we wouldn't overwrite it anyway as it's checked again in cmd_flash) + if len(jumper_loader) > QMK_OFFSET_DEFAULT: + self._on_error("Jumper loader is too large: 0x{:X} max allowed is 0x{:X}".format( + len(jumper_loader), MAX_FIRMWARE-QMK_OFFSET_DEFAULT)) + return False + return True + def on_click_flash_qmk(self): self.dev = self.get_active_device() if not self.dev: @@ -402,7 +411,36 @@ def on_click_revert(self): self.dangerous_flash(appctxt.get_resource("stock-firmware.bin")) def on_click_flash_jumploader(self): - self.dangerous_flash(appctxt.get_resource("jumploader.bin")) + reply = QMessageBox.question(self, "Warning", "This is a potentially dangerous operation, are you sure you want to continue?", + QMessageBox.Yes | QMessageBox.No, QMessageBox.No) + if reply != QMessageBox.Yes: + return + + self.dev = self.get_active_device() + if not self.dev: + return + + options = QFileDialog.Options() + options |= QFileDialog.DontUseNativeDialog + filename = QFileDialog.getOpenFileName( + None, "Select jumploader to flash", "", "Jumploader Files (*.bin)", options=options)[0] + if not filename: + self.close_dev() + return + + with open(filename, "rb") as inf: + firmware = inf.read() + + if not self.check_jumperloader_firmware(firmware): + self.close_dev() + return + + if len(firmware) < QMK_OFFSET_DEFAULT: + firmware += b"\x00" * (QMK_OFFSET_DEFAULT - len(firmware)) + + self.lock_user() + threading.Thread(target=lambda: cmd_flash( + self.dev, 0, firmware, self.on_progress, self.on_complete, self.on_error)).start() def excepthook(exc_type, exc_value, exc_tb):