bool FLASH_CheckCopyMemory(flash_device_t sourceDeviceID, uint32_t sourceAddress, flash_device_t destinationDeviceID, uint32_t destinationAddress, uint32_t length, uint8_t module_function, uint8_t flags) { if (FLASH_CheckValidAddressRange(sourceDeviceID, sourceAddress, length) != true) { return false; } if (FLASH_CheckValidAddressRange(destinationDeviceID, destinationAddress, length) != true) { return false; } #ifndef USE_SERIAL_FLASH // this predates the module system (early P1's using external flash for storage) if ((sourceDeviceID == FLASH_INTERNAL) && (flags & MODULE_VERIFY_MASK)) { uint32_t moduleLength = FLASH_ModuleLength(sourceDeviceID, sourceAddress); if((flags & (MODULE_VERIFY_LENGTH|MODULE_VERIFY_CRC)) && (length < moduleLength+4)) { return false; } const module_info_t* info = FLASH_ModuleInfo(sourceDeviceID, sourceAddress); if ((info->module_function != MODULE_FUNCTION_RESOURCE) && (info->platform_id != PLATFORM_ID)) { return false; } // verify destination address if ((flags & MODULE_VERIFY_DESTINATION_IS_START_ADDRESS) && (((uint32_t)info->module_start_address) != destinationAddress)) { return false; } if ((flags & MODULE_VERIFY_FUNCTION) && (info->module_function != module_function)) { return false; } if ((flags & MODULE_VERIFY_CRC) && !FLASH_VerifyCRC32(sourceDeviceID, sourceAddress, moduleLength)) { return false; } } #endif return true; }
void HAL_Core_Setup_finalize(void) { // Now that main() has been executed, we can plug in the original WICED ISR in the // ISR chain.) uint32_t* isrs = (uint32_t*)&link_ram_interrupt_vectors_location; isrs[SysTickIndex] = (uint32_t)SysTickChain; #ifdef MODULAR_FIRMWARE const uint32_t app_backup = 0x800C000; // when unpacking from the combined image, we have the default application image stored // in the eeprom region. const module_info_t* app_info = FLASH_ModuleInfo(FLASH_INTERNAL, app_backup); if (app_info->module_start_address==(void*)0x80A0000) { LED_SetRGBColor(RGB_COLOR_GREEN); uint32_t length = app_info->module_end_address-app_info->module_start_address+4; if (length < 80*1024 && FLASH_CopyMemory(FLASH_INTERNAL, app_backup, FLASH_INTERNAL, 0x80E0000, length, MODULE_FUNCTION_USER_PART, MODULE_VERIFY_CRC|MODULE_VERIFY_FUNCTION)) { FLASH_CopyMemory(FLASH_INTERNAL, app_backup, FLASH_INTERNAL, 0x80A0000, length, MODULE_FUNCTION_USER_PART, MODULE_VERIFY_CRC|MODULE_VERIFY_DESTINATION_IS_START_ADDRESS|MODULE_VERIFY_FUNCTION); FLASH_EraseMemory(FLASH_INTERNAL, app_backup, length); } LED_SetRGBColor(RGB_COLOR_WHITE); } #endif }