Skip to content

Commit

Permalink
Fix bootloader size comparison (fix BlueSCSI#227)
Browse files Browse the repository at this point in the history
Previously firmware update files that were slightly too large would
be erroneously accepted. In practice these would give an error already
during build process.
  • Loading branch information
PetteriAimonen authored and erichelgeson committed Jun 20, 2023
1 parent de9b1cc commit 57e68a9
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/BlueSCSI_bootloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,17 @@ bool find_firmware_image(FsFile &file, char name[MAX_FILE_PATH + 1])

bool program_firmware(FsFile &file)
{
uint32_t fwsize = file.size() - PLATFORM_BOOTLOADER_SIZE;
uint32_t filesize = file.size();
uint32_t fwsize = filesize - PLATFORM_BOOTLOADER_SIZE;
uint32_t num_pages = (fwsize + PLATFORM_FLASH_PAGE_SIZE - 1) / PLATFORM_FLASH_PAGE_SIZE;

// Make sure the buffer is aligned to word boundary
static uint32_t buffer32[PLATFORM_FLASH_PAGE_SIZE / 4];
uint8_t *buffer = (uint8_t*)buffer32;

if (fwsize > PLATFORM_FLASH_TOTAL_SIZE)
if (filesize > PLATFORM_FLASH_TOTAL_SIZE)
{
log("Firmware too large: ", (int)fwsize, " flash size ", (int)PLATFORM_FLASH_TOTAL_SIZE);
log("Firmware too large: ", (int)filesize, " flash size ", (int)PLATFORM_FLASH_TOTAL_SIZE);
return false;
}

Expand Down

0 comments on commit 57e68a9

Please sign in to comment.