I have created an L2 bootloader (modified from an NXP provided "OTA Bootloader") that will look for various images in QSPI flash, validate them, and decide which one to boot based on an A/B/Factory partitioning scheme.
The bootloader is what is loaded by the BootROM and is XIP from flash. The images I want to boot are also in QSPI and I want them to be XIP as well.
I have the following setup:
RT-1052
L2 bootloader runs, can find the images in flash, validate them, and "jump" to their respective start addresses.
Vector table "seems" correct for image I'm attempting to jump to, the stack pointer is set to 0x20000000 (SRAM DTC), ResetISR "appears" to be at the correct memory location.
Functions are below for jumping to application.
void jump_to_user_application(uint32_t app_start)
{
/* Invalidate caches */
SCB_DisableDCache();
SCB_DisableICache();
/* The main application will enable caches */
__DMB();
/* Relocate vector table */
SCB->VTOR = app_start;
jump(*(uint32_t *)(app_start), *((uint32_t *)(app_start+4)));
}
/* Jump to application */
static void jump(uint32_t user_sp, uint32_t user_startup)
{
static void (*farewell_bootloader)(void) = 0;
farewell_bootloader = (void (*)(void))user_startup;
// Set stack pointers to the application stack pointer.
__set_MSP(user_sp);
__set_PSP(user_sp);
// Jump to the application.
farewell_bootloader();
}
Issues:
I get an Imprecise Bus Error hard fault after the jump.
Things I've tried:
* I've tried building the app without the XIP headers and DCD headers, loading the raw binary into flash as the expected location and jumping to it. Same error.
* Disabling the cache was another suggestion ( as you can see in the functions above I'm doing that, still didn't help)
* Aligned the memory map for the bootloader and the memory map of the application to make sure we were all on the same page.
Questions:
1. Since my bootloader is what is being processed by the BootROM, do I need to build the bootloader differently to ensure memory is properly setup for the application I'm trying to jump to?
2. Is there a "de-initialization" sequence I need to do before jumping to the application beyond what I'm doing above? I'm wondering if the bus fault has something to do with the fact that the application assumes it is coming out of reset and is trying to run through its initialization sequence but the bootloader has already done that.
3. How do I build my application such that it can get loaded at a different location? I've modified the linker script and all the memory addresses appear to be correct, but I'm just loading the raw binary (not running it through any of the factory tools to create a "bootable" image, since I don't need it to be run from the BootRom)
My primary confusion here is that most forum answers for booting to SRAM have you run the binary output by MCUXpresso through the BootUtility tools, but since my image is linked at 0x60100000 the MCUBootUtility adds 1M of 0's to the image since it is trying to put the HDR and IVT at the base of flash to make it a bootable image. I don't want that since my bootloader is going to live in the first 1M of flash.
Thanks,
Greg