Skip to content

Commit

Permalink
Update boot_info mechanism
Browse files Browse the repository at this point in the history
Data from boot_info gets changed after reboot when Read protection was enabled for H7, this is a hacky fix until it is clear what is going on.
  • Loading branch information
Igor-Misic committed Sep 21, 2022
1 parent cedde21 commit f48c79f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Bootloader/Inc/binary_update.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
typedef struct bootInfo {
uint32_t jump_address; //!< Address for BL to jump
bool skip_bl_loop; //!< Flag to skip BL loop
signatureType_E previus_binary; //!< Previous detected binary
uint8_t end; // FIXME: added here because after restart something is messing up with data in the structure and if there is an extra byte at the end it messes only with it
} bootInfo_S;
#pragma pack(pop)

Expand Down
2 changes: 1 addition & 1 deletion Bootloader/Inc/signature.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ typedef enum signatureType_ENUM {
signatureType_BOOTLOADER_FLASH = 0x02, //!< New bootloader for FLASH
signatureType_BOOTLOADER_RAM = 0x03, //!< Bootloader for RAM
signatureType_UNKNOWN = 0xFF, //!< Not existing or unknown signature
} signatureType_E __attribute__ ((__packed__));
} signatureType_E;

signatureType_E Signature_verification(const signature_S* signature);

Expand Down
10 changes: 5 additions & 5 deletions Bootloader/Src/binary_update.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
#include "signature.h"

__attribute__ ((section(".restart_info")))
bootInfo_S boot_info; //!< Instruction on where to jump after the restart
volatile bootInfo_S boot_info; //!< Instruction on where to jump after the restart
static uint64_t s_address; //!< Address from where to erase flash and write binary
static signatureType_E s_detected_binary; //!< Detected binary
static signatureType_E s_detected_binary; //!< Detected binary

static bool BinaryUpdate_writeToFlash(uint8_t* write_buffer, const uint32_t data_length);

Expand Down Expand Up @@ -93,7 +93,6 @@ BinaryUpdate_handleBootInfo(void) {
default:
boot_info.jump_address = FLASH_FIRMWARE_ADDRESS;
boot_info.skip_bl_loop = false;
boot_info.previus_binary = signatureType_FIRMWARE_FLASH;
break;
}
}
Expand Down Expand Up @@ -128,7 +127,7 @@ BinaryUpdate_erase(uint32_t firmware_size) {
success = FlashAdapter_erase(firmware_size, s_address);
break;
case signatureType_BOOTLOADER_FLASH:
if (signatureType_BOOTLOADER_RAM == boot_info.previus_binary) {
if (boot_info.jump_address == RAM_FIRMWARE_ADDRESS) {
//Only allowed to erase if RAM version is running
success = FlashAdapter_erase(firmware_size, s_address);
}
Expand Down Expand Up @@ -233,7 +232,8 @@ BinaryUpdate_finish(void) {
break;
}

boot_info.previus_binary = s_detected_binary;
boot_info.end = 0xFF;

return success;
}

Expand Down

0 comments on commit f48c79f

Please sign in to comment.