From f0eedf301d22127e3beb28cbe291795099392d42 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Wed, 3 Mar 2021 16:31:55 +0200 Subject: [PATCH] optiboot: check boot_app_magic as well before early exit --- Firmware/optiboot_w25x20cl.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Firmware/optiboot_w25x20cl.cpp b/Firmware/optiboot_w25x20cl.cpp index ea6d1b99e..ed38b2999 100644 --- a/Firmware/optiboot_w25x20cl.cpp +++ b/Firmware/optiboot_w25x20cl.cpp @@ -80,7 +80,10 @@ extern struct block_t *block_buffer; //! @return 0 if "start\n" was sent. Optiboot ran normally. No need to send "start\n" in setup() uint8_t optiboot_w25x20cl_enter() { - if (boot_app_flags & BOOT_APP_FLG_USER0) return 1; +// Make sure to check boot_app_magic as well. Since these bootapp flags are located right in the middle of the stack, +// they can be unintentionally changed. As a workaround to the language upload problem, do not only check for one bit if it's set, +// but rather test 33 bits for the correct value before exiting optiboot early. + if ((boot_app_magic == BOOT_APP_MAGIC) && (boot_app_flags & BOOT_APP_FLG_USER0)) return 1; uint8_t ch; uint8_t rampz = 0; register uint16_t address = 0;