Skip to content

Commit

Permalink
Uploader: fix order of commands, to prevent bricking.
Browse files Browse the repository at this point in the history
  • Loading branch information
meee1 committed Jan 28, 2023
1 parent 7c2b85d commit 1cbd966
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions ExtLibs/px4uploader/Uploader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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();
Expand Down

0 comments on commit 1cbd966

Please sign in to comment.