Skip to content

target/lpc4088qsb: fix page_size mismatch causing silent flash corruption#2015

Open
alramlechner wants to merge 1 commit into
pyocd:developfrom
alramlechner:fix/lpc4088qsb-page-size
Open

target/lpc4088qsb: fix page_size mismatch causing silent flash corruption#2015
alramlechner wants to merge 1 commit into
pyocd:developfrom
alramlechner:fix/lpc4088qsb-page-size

Conversation

@alramlechner

@alramlechner alramlechner commented Jul 24, 2026

Copy link
Copy Markdown

Summary

target_lpc4088qsb.py's FlashRegion for the main flash bank (start=0x10000,
>64 KB) declares page_size=0x400, but the INTERNAL_FLASH_ALGO it uses
(shared with target_LPC4088FBD144, which correctly declares page_size=0x200
for the equivalent region) only implements 512-byte pages: its own
page_size/min_program_length are 0x200/512, and page_buffers holds a
single 512-byte buffer.

With page_size=0x400, the flash loader chunks writes into 1 KB pages, but
program_page() only programs the first 512 bytes of each chunk and silently
drops the rest — no error is raised. Any image whose .bin crosses the 64 KB
boundary and isn't an exact multiple of 1 KB in that region ends up with
512-byte holes left at the erased value.

How I found this

Debugging a board that ran fine until its firmware image grew past 64 KB,
after which it intermittently corrupted RAM depending on exact build layout.
Confirmed via readback (pyocd commander savemem + binary diff): a ~65.6 KB
image left a 512-byte hole unprogrammed (still 0xFF) right at the boundary,
while pyocd flash reported success with no warning.

Fix

Change page_size for that region from 0x400 to 0x200, matching the
flash algo and the sibling target target_LPC4088FBD144.py.

Testing

Re-flashed the same image after the fix; readback matched the source .bin
exactly, and the target (LPC4088-based board) now runs correctly.

…tion

The FlashRegion for the main flash bank (start=0x10000, >64 KB) declared
page_size=0x400, but the referenced INTERNAL_FLASH_ALGO (shared with
target_LPC4088FBD144, which correctly uses page_size=0x200 for the
equivalent region) only implements 512-byte pages: its own 'page_size'/
'min_program_length' are 0x200/512, and page_buffers holds a single
512-byte buffer.

With page_size=0x400, pyOCD's flash loader chunks writes into 1 KB pages,
but the flash algo's program_page() call only programs the first 512
bytes of each chunk and silently drops the rest -- no error is raised.
Any image whose .bin crosses the 64 KB boundary and is not an exact
multiple of 1 KB in that region ends up with 512-byte holes left at the
erased value, corrupting whatever data lands there (e.g. an .data
initializer image, if the linked image happens to end mid-page).

Confirmed via readback (savemem + binary diff) against a LPC4088-based
board: flashing a ~65.6 KB image left the trailing partial page
unprogrammed at the erased value, while pyocd reported success.
@alramlechner
alramlechner force-pushed the fix/lpc4088qsb-page-size branch from c58df60 to 63aeea7 Compare July 24, 2026 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant