Changing code location in XIP Flash causes program failure.
I have done further experiments to try to determine why the application loaded at 0x70040400 (for starting via bootloader) is behaving differently from the "standalone" version loaded at address 0x70000000 .
The difference is that the "bad" version fails: it stalls during sys_check_timeouts() in the LWIP code and the debugger loses control. The standalone version is "good" in that its execution continues without stalling.
To test if is is a code location issue, or an issue with the runtime environment set up for app execution, I took the "good" standalone version, temporarily disabled managed linker scripts, and added a padding directive as follows to the .ld file:
/* Image Vector Table and Boot Data for booting from external flash */
.boot_hdr : ALIGN(4)
{
FILL(0xff)
__boot_hdr_start__ = ABSOLUTE(.) ;
KEEP(*(.boot_hdr.conf))
. = 0x1000 ;
KEEP(*(.boot_hdr.ivt))
. = 0x1020 ;
KEEP(*(.boot_hdr.boot_data))
. = 0x1030 ;
KEEP(*(.boot_hdr.dcd_data))
__boot_hdr_end__ = ABSOLUTE(.) ;
. = 0x2000 ;
. = 0x40400 ; /* Add padding to load next section at 0x70040400 */
} >PROGRAM_FLASH
/* MAIN TEXT SECTION */
.text : ALIGN(4)
{
FILL(0xff)
__vectors_start__ = ABSOLUTE(.) ;
This aligned the main text section in the modified "good" version to load at 0x70040400, ie same as "bad" version. Extract from .map file to show this:
0x00002000 . = 0x2000
*fill* 0x70001460 0xba0 ff
0x00040400 . = 0x40400
*fill* 0x70002000 0x3e400 ff
.text 0x70040400 0xc7734
FILL mask 0xff
0x70040400 __vectors_start__ = ABSOLUTE (.)
*(SORT_BY_ALIGNMENT(.isr_vector))
.isr_vector 0x70040400 0x2b8 ./startup/startup_mimxrt1064.o
0x70040400 g_pfnVectors
0x70040400 __Vectors
0x700406b8 . = ALIGN (0x4)
The remaining functions in the modified "good" version are loaded at addresses corresponding to those in the "bad" version
The modified "good" version with padding now fails in the same way as the "bad" version . Aside from the addition of padding, no other changes were made. So it appears to be a code location issue.
Can anyone suggest how changing the location of code in XIP flash could make a difference to program execution?