| | |
| | | #include "AppConfig.h" |
| | | #include "menu.h" |
| | | #include "aes.h" |
| | | #include "AppConfig.h" |
| | | static const uint32_t fw_addr = 0x04004000; |
| | | static const uint32_t fw_bytes = 14712; |
| | | |
| | |
| | | } |
| | | |
| | | } |
| | | unsigned short int APP_byte = 0; |
| | | unsigned short int updata_byte = 0; |
| | | uint8_t trx_buf[10] = {0}; |
| | | int test1; |
| | | int aaa; |
| | | uint16_t finalbag; |
| | | static unsigned char zhongjian_shuju[128]; |
| | | uint8_t jiexi_shuju[128]; |
| | | static void app_wdt_callback(void *dev, uint32_t status) |
| | | { |
| | | ASSERT(status, "WDT TIMEOUT,程序复位"); |
| | |
| | | .int_en = true, |
| | | .callback = app_wdt_callback, |
| | | }; |
| | | |
| | | int main(void) |
| | | { uint8_t c; |
| | | |
| | |
| | | { |
| | | } |
| | | updata_byte = tmp;//读取指定地址的值 |
| | | if(updata_byte == 0xAAAA)//判断此地址的值是否为0xAAAA,如果是则升级 |
| | | if(updata_byte == 0xAAAA)//判断此地址的值是否为0xAAAA,如果是则 升级 |
| | | { |
| | | SerialPutString("串口升级启动\r\n"); |
| | | |
| | |
| | | } |
| | | else if(updata_byte == 0xBBBB)//判断此地址的值是否为0xBBBB,如果是则网络升级 |
| | | { |
| | | unsigned int i = 0; |
| | | unsigned int spiflash_addr = APP_CONFIG_APP_DOWN_LOAD_SPIFLASH_ADDRESS; |
| | | unsigned int flashdestination = APP_CONFIG_APPLICATION_ADDRESS; |
| | | uint32_t JumpAddress; |
| | | pFunction Jump_To_Application; |
| | | unsigned int ii = 0; |
| | | // unsigned int spiflash_addr = APP_CONFIG_APP_DOWN_LOAD_SPIFLASH_ADDRESS; |
| | | // unsigned int flashdestination = APP_CONFIG_APPLICATION_ADDRESS; |
| | | // uint32_t JumpAddress; |
| | | // pFunction Jump_To_Application; |
| | | |
| | | SerialPutString("网络升级启动启动\r\n"); |
| | | // Flash_Init(); |
| | | // Flash_Erase(APP_CONFIG_APPLICATION_ADDRESS, APP_CONFIG_APPLICATION_SIZE);//MK8000修改 |
| | | flash_erase(FLASH_ID0, APP_CONFIG_APPLICATION_ADDRESS, APP_CONFIG_APPLICATION_SIZE);//擦除APP |
| | | SerialPutString("OTA完成,解密文件启动\r\n"); |
| | | SerialPutString("OTA固件解压\r\n"); |
| | | |
| | | aesDecInit(); |
| | | /* 200KB */ |
| | | while(spiflash_addr < (APP_CONFIG_APP_DOWN_LOAD_SPIFLASH_ADDRESS + APP_CONFIG_APP_DOWN_LOAD_SPIFLASH_SIZE)) |
| | | { |
| | | /* 读取一包数据 */ |
| | | //SPIFlash_Read(SPI_FLASH_ID_0, buff, spiflash_addr, sizeof(buff));MK8000修改 |
| | | flash_read(FLASH_ID0, spiflash_addr, buff, sizeof(buff)); |
| | | while (flash_check_busy(FLASH_ID0)) |
| | | { |
| | | } |
| | | spiflash_addr += sizeof(buff); |
| | | |
| | | for(i = 0; i < sizeof(buff); i += 16) |
| | | { |
| | | aesDecrypt(&buff[i],key); |
| | | } |
| | | |
| | | flash_write(FLASH_ID0, flashdestination, buff, sizeof(buff)); |
| | | while (flash_check_busy(FLASH_ID0)) |
| | | { |
| | | } |
| | | flashdestination += sizeof(buff); |
| | | // Flash_Write(flashdestination, buff, sizeof(buff)); |
| | | // flashdestination += sizeof(buff); //MK8000修改 |
| | | } |
| | | |
| | | /* 清标志 */ |
| | | tmp = 0xFFFF; |
| | | flash_erase(FLASH_ID0, APP_CONFIG_IAPFLAG_MAP, 2);//擦除APPFLAG |
| | | flash_write(FLASH_ID0, APP_CONFIG_IAPFLAG_MAP, (uint8_t*)&tmp, sizeof(tmp)); |
| | | delay_ms(500); |
| | | NVIC_SystemReset(); |
| | | // SPIFlash_Erase(SPI_FLASH_ID_0, APP_CONFIG_IAPFLAG_MAP,2, SPI_FLASH_SECTOR_ERASE_MODE_4K); |
| | | // SPIFlash_Write(SPI_FLASH_ID_0, APP_CONFIG_IAPFLAG_MAP, (HIDO_UINT8*)&tmp, sizeof(tmp)); //MK8000修改 |
| | | |
| | | //HAL_Delay(500); |
| | | //SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; MK8000 修改 |
| | | flash_erase(FLASH_ID0, APP_CONFIG_IAPFLAG_SECTOR_ADDR, FLASH_SECTOR_SIZE);//擦除APP |
| | | flash_read(FLASH_ID0, APP_CONFIG_IAPFLAG_MAP, (uint8_t*)&tmp, 2); |
| | | APP_byte = tmp; |
| | | if(APP_byte==0XBBBB) |
| | | { |
| | | memcpy((void *)SRAM_BASE, (void *)APP_CONFIG_APPLICATION_ADDRESS, APP_CONFIG_APPLICATION_SIZE);//size太大导致覆盖没法跳转 |
| | | __set_MSP(*(uint32_t *)SRAM_BASE); |
| | | typedef void (*p_entry_t)(void); |
| | | ((p_entry_t) (*(uint32_t *)(SRAM_BASE + 4) + SRAM_BASE))(); |
| | | } |
| | | SerialPutString("擦除标注位成功\r\n"); |
| | | test1=flash_erase(FLASH_ID0,APP1_ADRESS,APP_CONFIG_APPLICATION_SIZE); |
| | | if(test1==0) |
| | | { |
| | | finalbag=(APP_CONFIG_APPLICATION_SIZE/128)+1; |
| | | for(aaa=0;aaa<finalbag;aaa++) |
| | | { |
| | | // time32_reset=0; |
| | | memcpy(&zhongjian_shuju,(void *)(APP2_ADRESS+(aaa*128)),128); |
| | | |
| | | for(ii = 0; ii < sizeof(zhongjian_shuju); ii += 16) |
| | | {aesDecrypt(&zhongjian_shuju[ii],key);} |
| | | |
| | | test1=flash_write_nbytes(FLASH_ID0, (APP1_ADRESS+(aaa*128)), zhongjian_shuju, sizeof(zhongjian_shuju)); |
| | | // if(test1==0) |
| | | // {SerialPutString("解密成功\r\n");} |
| | | // else |
| | | // {SerialPutString("解密失败\r\n");} |
| | | wdt_ping(WDT_ID0);//喂狗 |
| | | } |
| | | delay_ms(10); |
| | | SerialPutString("OTA解密成功,准备重启\r\n"); |
| | | delay_ms(500); |
| | | NVIC_SystemReset(); |
| | | } |
| | | |
| | | } |
| | | } |
| | | else if(updata_byte == 0xCCCC)//OTA |
| | | { |
| | | SerialPutString("OTA升级启动\r\n"); |
| | | IAP_JumpTo(SRAM_BASE); |
| | | |
| | | SerialPutString("进入OTA,升级启动\r\n"); |
| | | memcpy((void *)SRAM_BASE, (void *)OTA_ADRESS, APP_CONFIG_APPLICATION_SIZE);//size太大导致覆盖没法跳转 |
| | | __set_MSP(*(uint32_t *)SRAM_BASE); |
| | | typedef void (*p_entry_t)(void); |
| | | ((p_entry_t) (*(uint32_t *)(SRAM_BASE + 4) + SRAM_BASE))(); |
| | | // Serial0PutString("进入OTA\r\n"); |
| | | } |
| | | else //不是则跳转到APP,注意F0和其他系列的跳转有些不一样,跳转部分可参考原子哥代码 |
| | | { |
| | | //Delay_ms(1000); |
| | | //Delay_ms(1000); |
| | | /* Test if user code is programmed starting from address "APP_CONFIG_APPLICATION_ADDRESS" */ |
| | | //Serial0PutString("跳转APPhehe\r\n"); |
| | | memcpy((void *)SRAM_BASE, (void *)APP_CONFIG_APPLICATION_ADDRESS, APP_CONFIG_APPLICATION_SIZE);//size太大导致覆盖没法跳转 |