Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ it and is upstream Adafruit history, kept for provenance.
- A DFU session started after a SoftDevice update no longer ends before it begins.
- Build change, no behavior change: the bootloader is now compiled with `-flto`, which shrinks every image by about 3.3 KB of flash. Section addresses and SoftDevice call sites are unchanged.
- The lazy-erase packet buffer holds 16 packets instead of 8. Costs about 2 KB of `.bss`.
- Hardening, no behavior change: `flash_nrf5x_write` splits a write that crosses a 4 KB page instead of running past its page buffer. The UF2 path accepts only 256 B blocks at 256 B-aligned addresses, so no current caller crosses a page.
- A UF2 whose application blocks start below the installed SoftDevice's end and carry no SoftDevice (no block at 0x1000) is now rejected as WRONG FILE: every block of the file is rejected and nothing is written. An app-only image built for a different SoftDevice would have overwritten the last page of the installed one. SoftDevice+app images, app-only images at the application start, and `CURRENT.UF2` restores are unaffected; the check assumes the host writes the file front to back.

## OTAFIX 2.5
Expand Down
27 changes: 19 additions & 8 deletions src/flash_nrf5x.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,25 @@ void flash_nrf5x_flush (bool need_erase)

void flash_nrf5x_write (uint32_t dst, void const *src, int len, bool need_erase)
{
uint32_t newAddr = dst & ~(FLASH_PAGE_SIZE - 1);

if ( newAddr != _fl_addr )
while ( len > 0 )
{
flash_nrf5x_flush(need_erase);
_fl_addr = newAddr;
memcpy(_fl_buf, (void *) newAddr, FLASH_PAGE_SIZE);
uint32_t newAddr = dst & ~(FLASH_PAGE_SIZE - 1);

if ( newAddr != _fl_addr )
{
flash_nrf5x_flush(need_erase);
_fl_addr = newAddr;
memcpy(_fl_buf, (void *) newAddr, FLASH_PAGE_SIZE);
}

uint32_t offset = dst & (FLASH_PAGE_SIZE - 1);
uint32_t n = FLASH_PAGE_SIZE - offset;
if ( n > (uint32_t) len ) n = (uint32_t) len;

memcpy(_fl_buf + offset, src, n);

dst += n;
src = (uint8_t const *) src + n;
len -= (int) n;
}
memcpy(_fl_buf + (dst & (FLASH_PAGE_SIZE - 1)), src, len);
}

Loading