Skip to content

Commit f9f6fd7

Browse files
committed
fix(uf2): reject an app-only image that starts above the app start, and reset the layout check on every block 0
1 parent 73d1322 commit f9f6fd7

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

‎src/usb/uf2/ghostfat.c‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -495,16 +495,17 @@ int write_block (uint32_t block_no, uint8_t *data, WriteState *state)
495495
* | MBR | | MBR |
496496
* ------------- -------------
497497
*/
498+
// An image carrying a SoftDevice starts at or below its first page; an app-only image must
499+
// start exactly at the app start. One built for another SoftDevice starts above or below it,
500+
// so every block of that file is rejected and nothing is written. Block 0 opens a new file
501+
// whatever its address (an MBR block at 0x0 included). Assumes the host writes front to back.
502+
if ( bl->blockNo == 0 )
503+
{
504+
state->sd_start_seen = false;
505+
state->wrong_layout = (bl->targetAddr > DFU_BANK_0_REGION_START);
506+
}
498507
if ( in_app_space(bl->targetAddr) )
499508
{
500-
// An image carrying a SoftDevice starts at its first page. An app-only image aimed below
501-
// the app start was built for another SoftDevice, so every block of that file is rejected
502-
// and nothing is written. Assumes the host writes the file front to back.
503-
if ( bl->blockNo == 0 )
504-
{
505-
state->sd_start_seen = false;
506-
state->wrong_layout = false;
507-
}
508509
if ( bl->targetAddr == USER_FLASH_START ) state->sd_start_seen = true;
509510
if ( !state->sd_start_seen && bl->targetAddr < DFU_BANK_0_REGION_START ) state->wrong_layout = true;
510511
if ( state->wrong_layout ) goto reject;

0 commit comments

Comments
 (0)