From ee6410acddcee6ac3f3bd2148943db36837877a1 Mon Sep 17 00:00:00 2001 From: tychovrahe Date: Thu, 29 Aug 2024 13:23:26 +0200 Subject: [PATCH] fix(core/bootloader): fix repeated firmware upload [no changelog] --- core/embed/bootloader/messages.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/embed/bootloader/messages.c b/core/embed/bootloader/messages.c index 58fdce13b5..7cee213aba 100644 --- a/core/embed/bootloader/messages.c +++ b/core/embed/bootloader/messages.c @@ -577,10 +577,11 @@ int process_msg_FirmwareUpload(uint8_t iface_num, uint32_t msg_size, memcpy(&hdr, received_hdr, sizeof(hdr)); size_t headers_end = IMAGE_HEADER_SIZE + vhdr.hdrlen; - headers_offset = IMAGE_CODE_ALIGN(IMAGE_HEADER_SIZE + vhdr.hdrlen); + size_t tmp_headers_offset = + IMAGE_CODE_ALIGN(IMAGE_HEADER_SIZE + vhdr.hdrlen); // check padding between headers and the code - for (size_t i = headers_end; i < headers_offset; i++) { + for (size_t i = headers_end; i < tmp_headers_offset; i++) { if (CHUNK_BUFFER_PTR[i] != 0) { MSG_SEND_INIT(Failure); MSG_SEND_ASSIGN_VALUE(code, FailureType_Failure_ProcessError); @@ -705,6 +706,7 @@ int process_msg_FirmwareUpload(uint8_t iface_num, uint32_t msg_size, NULL); } + headers_offset = IMAGE_CODE_ALIGN(IMAGE_HEADER_SIZE + vhdr.hdrlen); read_offset = IMAGE_INIT_CHUNK_SIZE; // request the rest of the first chunk