From 1cbd9663e07f29c92056dbc7d748a19670f0fd8e Mon Sep 17 00:00:00 2001 From: Michael Oborne Date: Mon, 23 Jan 2023 14:37:29 +1100 Subject: [PATCH] Uploader: fix order of commands, to prevent bricking. --- ExtLibs/px4uploader/Uploader.cs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/ExtLibs/px4uploader/Uploader.cs b/ExtLibs/px4uploader/Uploader.cs index 59192dc1d2..ace1355660 100644 --- a/ExtLibs/px4uploader/Uploader.cs +++ b/ExtLibs/px4uploader/Uploader.cs @@ -927,11 +927,26 @@ public void upload(Firmware fw) if (self.extf_maxsize < fw.extf_image_size && self.extf_maxsize != 0) throw new Exception("extf image is too large for this board"); + // erasing the internal flash will prevent a case where a unplug during external flashing will cause bootloader mode on reboot as there i no valid internal flash. even if the external was valid. if (fw.image_size > 0) { print("erase..."); self.__erase(); + } + + // external first - second internal + if (fw.extf_image_size > 0) + { + print("erase extf..."); + self.__erase_extf(fw); + print("program extf..."); + self.__program_extf(fw); + print("verify extf..."); + self.__verify_extf(fw); + } + if (fw.image_size > 0) + { print("program..."); self.__program(fw); @@ -941,15 +956,6 @@ public void upload(Firmware fw) else self.__verify_v3(fw); } - if(fw.extf_image_size > 0) - { - print("erase extf..."); - self.__erase_extf(fw); - print("program extf..."); - self.__program_extf(fw); - print("verify extf..."); - self.__verify_extf(fw); - } print("done, rebooting."); self.__reboot();