Skip to content

fix(linker): IAP_Binary_Template length not shrunk after bootloader offset (STM32H743I-EVAL)#346

Open
94xhn wants to merge 2 commits into
STMicroelectronics:masterfrom
94xhn:fix/linker-cross-toolchain-audit
Open

fix(linker): IAP_Binary_Template length not shrunk after bootloader offset (STM32H743I-EVAL)#346
94xhn wants to merge 2 commits into
STMicroelectronics:masterfrom
94xhn:fix/linker-cross-toolchain-audit

Conversation

@94xhn

@94xhn 94xhn commented Jul 11, 2026

Copy link
Copy Markdown

Update: this PR originally contained a second finding (CM7 given "access" to CM4's flash bank on 18 dual-core examples) that was based on a mistaken premise - see the discussion below. That part has been reverted; only the finding below remains.


Not tied to a specific existing issue - found by cross-checking each example's GCC (STM32CubeIDE)/IAR (EWARM)/Keil (MDK-ARM) linker scripts against each other and against known-good Templates sibling projects for the same chip.

IAP_Binary_Template (STM32H743I-EVAL)

Keil's .uvprojx correctly offsets the app's flash start address to leave room for the bootloader, but never shrinks the length to compensate - OCR_RVCT4 still declares 2048K as if starting from 0x08000000, running past the chip's actual end of flash by exactly the size of the reserved bootloader region. IAR/GCC in the same project both correctly use 1920K. Fixed Keil's OCR_RVCT4 Size to 0x1E0000 (1920K).

Test plan

No local ARM toolchain (arm-none-eabi-gcc/IAR/Keil) available to compile/link-test this change, so verification relied on address-arithmetic cross-referencing against IAR's and GCC's already-correct values in the same project.

Disclosure

Generative AI (Claude) was used to help investigate this (systematic cross-toolchain linker script comparison) and implement/verify the fix. All changes were reviewed by me before submission.

Found by cross-checking each example's GCC (STM32CubeIDE)/IAR (EWARM)/
Keil (MDK-ARM) linker scripts against each other and against known-good
Templates sibling projects, following the same audit already done for
STM32CubeG4/WB/WL/U5/F7/F4/L4 in this repo family.

1. CM7 core of 18 dual-core (CM7+CM4) examples across
   STM32H745I-DISCO, STM32H747I-DISCO, and STM32H747I-EVAL
   (STM32H745/H747xI, 2MB flash physically split into two 1MB banks -
   bank1 0x08000000-0x080FFFFF for CM7, bank2 0x08100000-0x081FFFFF
   for CM4): both IAR's `.icf` and Keil's `.uvprojx` (CM7 target)
   declared the CM7 core's flash region as the full 2MB
   (0x08000000-0x081FFFFF), giving CM7 access to bank2 - the flash
   bank that's supposed to belong exclusively to CM4. GCC's `.ld` for
   the same 18 examples, and the board's own Templates project (e.g.
   `Templates/BootCM4_CM7/EWARM/stm32h7xx_CM7_FLASH.icf`), all
   correctly restrict CM7 to 1MB (bank1 only). This is a
   "2-of-3-toolchains-wrong" case - a naive majority vote here would
   have picked the wrong answer. NUCLEO-H745ZI-Q's equivalent examples
   were checked and are all correct, so this isn't a family-wide
   defect, just these two DISCO/EVAL boards.

   Fixed all 18 IAR `.icf` files' ROM_end from 0x081FFFFF to
   0x080FFFFF, and all 18 Keil `.uvprojx` files' CM7-target
   OCR_RVCT4 Size from 0x200000 (2MB) to 0x100000 (1MB) - using a
   precise multi-line match on the CM7 target's specific
   StartAddress/Size pair so the sibling CM4 target block (already
   correct, different StartAddress) is left untouched.

2. IAP_Binary_Template (STM32H743I-EVAL): Keil's `.uvprojx` correctly
   offsets the app's flash start address to leave room for the
   bootloader, but never shrinks the length to compensate - OCR_RVCT4
   still declares 2048K as if starting from 0x08000000, running past
   the chip's actual end of flash by exactly the size of the reserved
   bootloader region. IAR/GCC in the same project both correctly use
   1920K. Fixed Keil's OCR_RVCT4 Size to 0x1E0000 (1920K).

No local ARM toolchain (arm-none-eabi-gcc/IAR/Keil) available to
compile/link-test these changes; verification relied on
address-arithmetic cross-referencing against multiple independent
references per finding (sibling toolchain files of the same project,
Templates gold standards, and NUCLEO-H745ZI-Q's unaffected equivalent
examples as a cross-board sanity check).

Signed-off-by: 94xhn <87560781+94xhn@users.noreply.github.com>
@MrBlueXav

Copy link
Copy Markdown

I'm afraid this is wrong.
Both Flash memory banks are fully accessible by CM7 and CM4.
See RM0399 p. 108
Sincerely,
Xavier

The previous commit's finding STMicroelectronics#1 ("CM7 core given access to CM4's flash
bank") was based on a mistaken premise. Per maintainer feedback (see
RM0399 Table 2, "Bus-master-to-bus-slave interconnect"), both Flash
bank 1 and Flash bank 2 are marked as accessible ("X") from the
Cortex-M7 master (AXIM) as well as from the Cortex-M4 master (S-bus).
There is no hardware access restriction preventing CM7 from using
bank2 - the PR's description of bank2 as "exclusively meant for CM4"
was incorrect, and the 36-file change (18 boards x IAR .icf + Keil
.uvprojx) built on that incorrect premise should not have been made.

This commit reverts all 36 files touched by that specific finding back
to their pre-PR state, leaving only finding STMicroelectronics#2 (IAP_Binary_Template on
STM32H743I-EVAL, a single-core H743 device unrelated to this dispute -
Keil's OCR_RVCT4 length not shrunk after the bootloader offset) as the
remaining, unaffected content of this PR.

Signed-off-by: 94xhn <87560781+94xhn@users.noreply.github.com>
@94xhn

94xhn commented Jul 12, 2026

Copy link
Copy Markdown
Author

Thank you for the correction and the reference, Xavier - you're right, and I apologize for the mistake.

RM0399 Table 2 ("Bus-master-to-bus-slave interconnect", p.108) explicitly marks both Flash bank 1 and Flash bank 2 as accessible ("X") from the Cortex-M7 master (AXIM) as well as from the Cortex-M4 master (S-bus). There's no hardware access restriction preventing CM7 from using bank2, so describing it as "the bank exclusively meant for CM4" and treating IAR/Keil's 2MB declaration for the CM7 target as a bug was incorrect on my part.

I've pushed a commit that reverts all 36 files from that finding back to their original state. The PR now only contains the other, unrelated finding (IAP_Binary_Template on STM32H743I-EVAL - a single-core H743 device, Keil's declared length not shrunk after the bootloader offset), which doesn't depend on the bank-access premise at all.

Sorry for the noise, and thanks again for catching this.

@94xhn 94xhn changed the title fix(linker): correct several cross-toolchain memory map inconsistencies fix(linker): IAP_Binary_Template length not shrunk after bootloader offset (STM32H743I-EVAL) Jul 12, 2026
@ALABSTM ALABSTM added bug Something isn't working projects Projects-related (demos, applications, examples) issue or pull-request. labels Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working projects Projects-related (demos, applications, examples) issue or pull-request.

Projects

Development

Successfully merging this pull request may close these issues.

4 participants