Improve valid image check to account for ITCM access devices
@@ -35,6 +35,8 @@ void LaunchCLR(uint32_t address)
bool CheckValidCLRImage(uint32_t address)
{
+ uint32_t resetVectorAddress;
+
// load nanoCLR vector table
const vectors_t* nanoCLRVectorTable = (vectors_t*) address;
@@ -51,9 +53,27 @@ bool CheckValidCLRImage(uint32_t address)
// that's an assembly "b.n" (branch instruction) the very first one in the Reset_Handler function
// see os\common\startup\ARMCMx\compilers\GCC\vectors.S
+
+ // for series that have ART Accelerator the handlers addresses stored in the vector table are for ITCM access
+ // need to parsed them to reach the equivalent address in AXI access
+ #ifdef FLASHITCM_BASE
+
+ // read address (ITCM)
+ resetVectorAddress = (uint32_t)((uint32_t*)nanoCLRVectorTable->reset_handler);
+ // parse it to get the address in the AXI range
+ resetVectorAddress -= FLASHITCM_BASE;
+ resetVectorAddress += FLASHAXI_BASE;
+
+ #else
+
+ // "regular" address mapping
+ resetVectorAddress = (uint32_t)((uint32_t*)nanoCLRVectorTable->reset_handler);
+
+ #endif
+
// sanity check for invalid address (out of flash range which causes a hard fault)
- if( (uint32_t)((uint32_t*)nanoCLRVectorTable->reset_handler) <= FLASH1_MEMORY_StartAddress ||
- (uint32_t)((uint32_t*)nanoCLRVectorTable->reset_handler) >= (FLASH1_MEMORY_StartAddress + FLASH1_MEMORY_Size) )
+ if( resetVectorAddress <= FLASH1_MEMORY_StartAddress ||
+ resetVectorAddress >= (FLASH1_MEMORY_StartAddress + FLASH1_MEMORY_Size) )
{
// check failed, doesn't seem to be a valid CLR image
return false;
