My system has a STM32F2xx bootloader(0x0800 0000) and an app (0x0800 4000).
1. No bootloader(only app, placed at address 0x0800 0000), the app works as expected.
2. No LTO enabled, bootloader jumps to __main successfully and app is loaded at power up.
When Link time optimisation (LTO) option in KEIL is enabled for app (0x0800 4000), a hard fault is encountered in __scatterload. Here is a snapshot of fault and saved register in my fault hander (fault handler has a breakpoint instruction).
Hi Friends,
Just found that ARM suggests not using LTO with Scatter file (which I am reluctantly doing).
https://developer.arm.com/documentation/100748/0620/Writing-Optimized-Code/Optimizing-across-modules-with-Link-Time-Optimization/Restrictions-with-Link-Time-Optimization
Has anyone found a solution/workaround to overcome this issue?
Thank you.
> Just found that ARM suggests not using LTO with Scatter file (which I am reluctantly doing).
This is not what this article says. There are some restrictions, but the linker will always receive a scatter file, either the one you created or one that was created by µVision.
I think that there is something wrong the way you call the application from the bootloader. The bootloader needs to disable all interrupts and set some registers to a reset-value before starting the application. Other registers like VTOR need to be initialized according to the start address of the application. I recommend reading this knowledgebase article and to check if your bootloader does all the things that are recommended in the knowledgebase article. Here is the link to it:
https://developer.arm.com/documentation/ka002218/latest/
As Hans said, LTO is OK to use with scatter-loading, but you must be aware of its effects.
Does your LTO link emit any warnings? Likely "No section matches pattern xxx"?
There is a thorough discussion on the effect of LTO here:https://developer.arm.com/documentation/100748/latest/Writing-Optimized-Code/Scatter-file-section-or-object-placement-with-Link-Time-Optimization
You could also build your boot-loader without LTO, but keep this enabled for the rest of your application.To do this in MDK, create a new Group (right-click > Add Group), and place the bootloader sources therein.
Then you can right-click > Options for that group and set group-specific compiler options, such as disabling LTO for that group.