Hi,
Am working on ATMEL Sam4cms based board and trying to write a basic application (lets say bootloader) which will jump to an image placed in a different location.
Here is my scatter file for bootloader which starts at 0x1000000
; ************************************************************* ; *** Scatter-Loading Description File generated by uVision *** ; *************************************************************
; load region BOOTLOADER_IROM1 0x1000000 0x100000 { ; Execution Region ER_IROM1 0x1000000 0xFFF0 { *.o(RESET, +First) *(InRoot$$Sections) * (.init_array) .ANY (+RO) }
; RW data RW_IRAM0 0x20000000 0x00002000 { .ANY (+RW +ZI) *(HEAP) }
RW_IRAM1 0x2003F000 UNINIT 0x00001000{ ; ZI data will not be initialized to zero *(NoInit) }
}
And for App which starts at 0x01010000
APP_IROM1 0x1010000 NOCOMPRESS 0xF0000 { ; load region size_region ER_IROM1 0x1010000 0xF0000 { ; load address = execution address *.o(RESET, +First) *(InRoot$$Sections) * (.init_array) .ANY (+RO) }
RW_IRAM0 0x20002000 0x0003D000 { .ANY (+RW +ZI) *(HEAP) }
and the code to jump
int main() { __disable_irq();
std::uint32_t i = 0;
// Disable IRQs for (i = 0; i < 8; i ++) NVIC->ICER[i] = 0xFFFFFFFF; // Clear pending IRQs for (i = 0; i < 8; i ++) NVIC->ICPR[i] = 0xFFFFFFFF; // -- Modify vector table location // Barriars __DSB(); __ISB();
_binExec(reinterpret_cast<void *>(0x1010000 )); }
__asm__ void _binExec (void * l_code_addr) { mov r1, r0 ldr r0, [r1, #4] ldr sp, [r1] /*msr msp, [r1]*/ blx r0 }
Though the value shown at r0 is inline with map file's Reset_Handler, program counter doesnot jump to that address, it simply hangs. Getting "No Synchronisation" as keil trace error.
Can anyone please help.
Regards Prasad
Here is a snapshot of map file of second image:
Memory Map of the image
Image Entry point : 0x010103cd
Load Region APP_IROM1 (Base: 0x01010000, Size: 0x0009be20, Max: 0x000f0000, ABSOLUTE, COMPRESSED[0x0009b17c])
And the value present in r0 register is also 0x010103cd.
So it looks fine to me.
Can there be any issues with scatter file that I have written or am I missing any linker settings?
You need to actually look at what is loaded in the flash. Make sure that the the Bootloader and "New image" have valid Vector Tables, with both stack pointer and starting PC correct. The symptoms you are describing sound like loading the "2nd image" causes things to behave strangely (order of loading also seems to change the behavior). The logic for the jump from the bootloader to the "Application" is fine. disable interrupts. Disable all interrupts and Clear all pending interrupts, Set Stack pointer (Make sure you are running on MSP, it seems that you are quite aware of this though). Jump to the Address in the starting PC address in the Application Vector Table. It really seems that loading the "2nd image" is causing an issue. I have had "cheap" JTAG's that would always erase the whole chip even if the flash was segmented in a way that was not necessary. Look at what is actually in the flash after loading both images.