本帖最后由 一只耳朵怪 于 2018-6-11 12:00 编辑
大家好:
最近我发现我在BootLoader里面写入数据到程序的运行期间。发现写入全部失败。代码:
while(ui32FlashAddr > len + TFTP_BLOCK_SIZE) [ ui32FlashAddr = ((g_ui32TFTPBlock - 1) * TFTP_BLOCK_SIZE) + APP_START_ADDRESS; W25QXX_Read(pui8Packet,UPGRADE_FLASH_ADDR + TFTP_BLOCK_SIZE,TFTP_BLOCK_SIZE); if(ui32FlashAddr < g_ui32FlashEnd) [ // // If this is the first block and we have been provided with a start // hook func
tion, call it here to indicate that we are about to begin // flashing a new image. // #ifdef BL_START_FN_HOOK if(g_ui32TFTPBlock == 1) [ BL_START_FN_HOOK(); ] #endif // // Clear any flash error indicator. // BL_FLASH_CL_ERR_FN_HOOK(); // // If this is the first data packet and code protection is enabled, // then erase the entire flash. // #ifdef FLASH_CODE_PROTECTION if(g_ui32TFTPBlock == 1) [ // // Loop through the pages in the flash, excluding the pages that // contain the boot loader and the optional reserved space. // for(ui32Idx = APP_START_ADDRESS; ui32Idx < g_ui32FlashEnd; ui32Idx += FLASH_PAGE_SIZE) [ // // Erase this block of the flash. // BL_FLASH_ERASE_FN_HOOK((ui32Idx); ] ] #else // // Flash code protection is not enabled, so see if the data in this // packet will be programmed to the beginning of a flash block. We // assume that the flash block size is always a multiple of 1KB so, // since each TFTP packet is 512 bytes and that the start must always // be on a flash page boundary, we can be sure that we will hit the // start of each page as we receive packets. // if(!(ui32FlashAddr & (FLASH_PAGE_SIZE - 1))) [ // // Erase this block of the flash. // BL_FLASH_ERASE_FN_HOOK(ui32FlashAddr); ] #endif // // Decrypt the data if required. // #ifdef BL_DECRYPT_FN_HOOK BL_DECRYPT_FN_HOOK(pui8Packet + 4, uip_len - 4); #endif // // Program this block of data into flash. // BL_FLASH_PROGRAM_FN_HOOK(ui32FlashAddr, (pui8Packet), TFTP_BLOCK_SIZE); ] g_ui32TFTPBlock ++; ] ((void (*)(void))APP_START_ADDRESS)();