Skip to content

Commit

Permalink
fixup! fix(core): fix bootloader update on STM32U5
Browse files Browse the repository at this point in the history
  • Loading branch information
TychoVrahe committed Nov 21, 2023
1 parent 009b9b7 commit 2983999
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions core/embed/bootloader/messages.c
Original file line number Diff line number Diff line change
Expand Up @@ -754,8 +754,8 @@ int process_msg_FirmwareUpload(uint8_t iface_num, uint32_t msg_size,
// write a burst (8 * quadword (16 bytes)) to the flash
ensure(flash_area_write_burst(&FIRMWARE_AREA, write_offset, quadword_ptr),
NULL);
write_offset += 8 * 4 * sizeof(uint32_t);
quadword_ptr += 8 * 4;
write_offset += FLASH_BURST_LENGTH * sizeof(uint32_t);
quadword_ptr += FLASH_BURST_LENGTH;
}
ensure(flash_lock_write(), NULL);

Expand Down
12 changes: 6 additions & 6 deletions core/embed/firmware/bl_check.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,24 +220,24 @@ void check_and_replace_bootloader(void) {
uint32_t last_whole_word_addr = (((uint32_t)decomp.dest) & ~0x7F);
while ((uint32_t)p < last_whole_word_addr) {
ensure(flash_area_write_burst(&BOOTLOADER_AREA, offset, p), NULL);
p += 8 * 4;
offset += 8 * 4 * sizeof(uint32_t);
p += FLASH_BURST_LENGTH;
offset += FLASH_BURST_LENGTH * sizeof(uint32_t);
}
if ((uint8_t *)p < decomp.dest) {
// last few bytes in case of unaligned data
uint32_t d[8 * 4] = {0};
uint32_t d[FLASH_BURST_LENGTH] = {0};
memcpy(&d, p, (uint32_t)decomp.dest - (uint32_t)p);
ensure(flash_area_write_burst(&BOOTLOADER_AREA, offset, d), NULL);
offset += 8 * 4 * sizeof(uint32_t);
offset += FLASH_BURST_LENGTH * sizeof(uint32_t);
}
decomp.dest = (uint8_t *)decomp_out;
} while (uzlib_uncompress(&decomp) >= 0);

uint32_t d[8 * 4] = {0};
uint32_t d[FLASH_BURST_LENGTH] = {0};
// fill the rest of the bootloader area with 0x00
while (offset < bl_len) {
ensure(flash_area_write_burst(&BOOTLOADER_AREA, offset, d), NULL);
offset += 8 * 4 * sizeof(uint32_t);
offset += FLASH_BURST_LENGTH * sizeof(uint32_t);
}

ensure(flash_lock_write(), NULL);
Expand Down
2 changes: 2 additions & 0 deletions core/embed/trezorhal/flash.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

#include "flash_ll.h"

#define FLASH_BURST_LENGTH (4 * 8)

void flash_init(void);

#endif // TREZORHAL_FLASH_H

0 comments on commit 2983999

Please sign in to comment.