From cd121f49f9f63bcde03abe27b7dd428fc7c8d606 Mon Sep 17 00:00:00 2001 From: songyanguang <345810377@qq.com> Date: Fri, 9 May 2025 18:21:36 +0800 Subject: [PATCH] OTA info addresses need to be aligned --- .../Framework/connection/4g/ec801e/ec801e.c | 2 + APP_Framework/lib/mqtt/platform_mqtt.c | 5 + .../XiZi_IIoT/board/ch32v208rbt6/board.c | 2 +- .../third_party_driver/ota/boot_for_ota.c | 2 +- .../third_party_driver/ota/flash_for_ota.c | 8 +- .../XiZi_IIoT/tool/bootloader/ota/ota.c | 97 ++++++++++--------- 6 files changed, 65 insertions(+), 51 deletions(-) diff --git a/APP_Framework/Framework/connection/4g/ec801e/ec801e.c b/APP_Framework/Framework/connection/4g/ec801e/ec801e.c index b1794f40b..afbd895a0 100644 --- a/APP_Framework/Framework/connection/4g/ec801e/ec801e.c +++ b/APP_Framework/Framework/connection/4g/ec801e/ec801e.c @@ -200,6 +200,8 @@ static int Ec801eConnect(struct Adapter *adapter, enum NetRoleType net_role, con int try = 0; uint8_t ec801e_cmd[64]; + ADAPTER_DEBUG("%s enter\n", __func__); + AtSetReplyEndChar(adapter->agent, 0x4F, 0x4B); /*step1: serial write "+++", quit transparent mode*/ diff --git a/APP_Framework/lib/mqtt/platform_mqtt.c b/APP_Framework/lib/mqtt/platform_mqtt.c index ccaf15e1d..41fc624c0 100644 --- a/APP_Framework/lib/mqtt/platform_mqtt.c +++ b/APP_Framework/lib/mqtt/platform_mqtt.c @@ -46,6 +46,8 @@ int AdapterNetActive(void) { int ret = 0; uint32_t baud_rate = BAUD_RATE_115200; + + KPrintf("%s enter\n", __func__); adapter = AdapterDeviceFindByName(ADAPTER_4G_NAME); adapter->socket.socket_id = 0; @@ -66,12 +68,14 @@ int AdapterNetActive(void) { goto out; } + KPrintf("%s success\n", __func__); out: if (ret < 0) { AdapterDeviceClose(adapter); } + KPrintf("%s fail\n", __func__); return ret; } @@ -112,6 +116,7 @@ bool MQTT_Connect(void) { uint8_t TryConnect_time = 10; //尝试登录次数 + KPrintf("%s enter\n", __func__); memset(&Platform_mqtt,0,sizeof(Platform_mqtt)); #ifdef XIUOS_PLATFORM sprintf(Platform_mqtt.ClientID,"%s",CLIENTID); //客户端ID存入缓冲区 diff --git a/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/board.c b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/board.c index 04d16c862..4607c0f9d 100644 --- a/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/board.c +++ b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/board.c @@ -79,7 +79,7 @@ void readRomConfiguration(void) { if ((CFG->cfgFlag[0] != checkcode1) || (CFG->cfgFlag[1] != checkcode2)) { CFG_ERASE(PAGE_WRITE_START_ADDR, FLASH_PAGE_SIZE); CFG_WRITE(PAGE_WRITE_START_ADDR, (u8 *)&defaultConfiguration, MODULE_CFG_LEN); - KPrintf("%s NVIC_SystemReset\n", __func__); + KPrintf("%s NVIC_SystemReset\n\n", __func__); NVIC_SystemReset(); // 复位ch32v208 } diff --git a/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ota/boot_for_ota.c b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ota/boot_for_ota.c index 1270cb2ca..68d229a6e 100644 --- a/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ota/boot_for_ota.c +++ b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ota/boot_for_ota.c @@ -109,7 +109,7 @@ void mcuboot_reset(void) void mcuboot_jump(void) { - KPrintf("boot jumpApp\n"); + KPrintf("boot jumpApp\n\n"); jumpApp(); /* uint32_t addr = XIUOS_FLAH_ADDRESS; diff --git a/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ota/flash_for_ota.c b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ota/flash_for_ota.c index 81ee0ef65..25d69c17a 100644 --- a/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ota/flash_for_ota.c +++ b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ota/flash_for_ota.c @@ -80,14 +80,14 @@ status_t Flash_Erase(uint32_t start_addr, uint32_t imageSize) uint32_t page_count; uint32_t pageNum = (imageSize%FLASH_PAGE_FAST_SIZE != 0)? (imageSize/FLASH_PAGE_FAST_SIZE + 1):(imageSize/FLASH_PAGE_FAST_SIZE); - KPrintf("Flash_Erase start_addr=0x%x imageSize=0x%x\n", start_addr, imageSize); + KPrintf("Flash_Erase start_addr=%08x imageSize=0x%x\n", start_addr, imageSize); FLASH_Unlock_Fast(); for(page_count = 0; page_count < pageNum; page_count++) { FLASH_ErasePage_Fast(start_addr + (page_count * FLASH_PAGE_FAST_SIZE)); } FLASH_Lock_Fast(); - KPrintf("Flash_Erase start_addr=0x%x success\n", start_addr); + KPrintf("Flash_Erase start_addr=%08x success\n", start_addr); return (status_t)kStatus_Success; } @@ -106,14 +106,14 @@ status_t Flash_Write(uint32_t WriteAddr, uint8_t *pBuffer, uint32_t NumByteToWri uint32_t page_count; uint32_t pageNum = (NumByteToWrite%FLASH_PAGE_FAST_SIZE != 0)? (NumByteToWrite/FLASH_PAGE_FAST_SIZE + 1):(NumByteToWrite/FLASH_PAGE_FAST_SIZE); - KPrintf("Flash_Write start_addr=0x%x imageSize=0x%x\n", WriteAddr, NumByteToWrite); + KPrintf("Flash_Write start_addr=%08x pBuffer=%p imageSize=0x%x\n", WriteAddr, pBuffer, NumByteToWrite); FLASH_Unlock_Fast(); for(page_count = 0; page_count < pageNum; page_count++) { FLASH_ProgramPage_Fast(WriteAddr + (page_count * FLASH_PAGE_FAST_SIZE), (uint32_t *)&pBuffer[page_count * FLASH_PAGE_FAST_SIZE]); } FLASH_Lock_Fast(); - KPrintf("Flash_Write start_addr=0x%x success\n", WriteAddr); + KPrintf("Flash_Write start_addr=%08x success\n", WriteAddr); return (status_t)kStatus_Success; diff --git a/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/ota.c b/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/ota.c index 515c6e629..2acb19ed3 100644 --- a/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/ota.c +++ b/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/ota.c @@ -104,6 +104,7 @@ static const uint32_t crc32tab[] = { 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d }; +__attribute__((aligned(8))) ota_info_t g_ota_info; /******************************************************************************* * 函 数 名: calculate_crc32 @@ -197,19 +198,19 @@ static status_t UpdateOTAFlag(ota_info_t *ptr) static void InitialVersion(void) { int32_t size; - ota_info_t ota_info; + ota_info_t *p_ota_info = &g_ota_info; - memset(&ota_info, 0, sizeof(ota_info_t)); + memset(p_ota_info, 0, sizeof(ota_info_t)); size = mcuboot.download_by_serial(XIUOS_FLAH_ADDRESS); if(size > 0) { - ota_info.os.size = size; - ota_info.os.crc32 = calculate_crc32(XIUOS_FLAH_ADDRESS, size); + p_ota_info->os.size = size; + p_ota_info->os.crc32 = calculate_crc32(XIUOS_FLAH_ADDRESS, size); - strncpy(ota_info.os.version,"001.000.000",sizeof(ota_info.os.version)); - strncpy(ota_info.os.description, "The initial firmware.", sizeof(ota_info.os.description)); + strncpy(p_ota_info->os.version,"001.000.000",sizeof(p_ota_info->os.version)); + strncpy(p_ota_info->os.description, "The initial firmware.", sizeof(p_ota_info->os.description)); - UpdateOTAFlag(&ota_info); + UpdateOTAFlag(p_ota_info); } } @@ -458,21 +459,26 @@ static void Update(void) *******************************************************************************/ static void BootLoaderJumpApp(void) { - ota_info_t ota_info; + ota_info_t *p_ota_info = &g_ota_info; mcuboot.flash_init(); - memset(&ota_info, 0, sizeof(ota_info_t)); - mcuboot.op_flash_read(FLAG_FLAH_ADDRESS, (void*)&ota_info, sizeof(ota_info_t)); + memset(p_ota_info, 0, sizeof(ota_info_t)); + mcuboot.op_flash_read(FLAG_FLAH_ADDRESS, (void*)p_ota_info, sizeof(ota_info_t)); - if(ota_info.lastjumpflag == JUMP_FAILED_FLAG) + if(p_ota_info->lastjumpflag == JUMP_FAILED_FLAG) { mcuboot.print_string("\r\n------Jump to app partition failed,start version rollback!------\r\n"); - BackupVersion(); +#ifdef BOARD_CH32V208RBT6 + p_ota_info->lastjumpflag = JUMP_SUCCESS_FLAG; + UpdateOTAFlag(p_ota_info); +#else + BackupVersion(); +#endif } else { - ota_info.lastjumpflag = JUMP_FAILED_FLAG; - UpdateOTAFlag(&ota_info); + p_ota_info->lastjumpflag = JUMP_FAILED_FLAG; + UpdateOTAFlag(p_ota_info); } mcuboot.flash_deinit(); mcuboot.op_jump(); @@ -882,18 +888,19 @@ static void mqttCloudInteraction(void* parameter) int datalen; int ret = 0; int freecnt = 0; - ota_info_t ota_info; + ota_info_t *p_ota_info = &g_ota_info; uint32_t heart_time = 0; uint32_t flashdestination = DOWN_FLAH_ADDRESS; uint8_t topicdatabuff[2][64]; char *ptr1, *ptr2; uint16_t payloadLen; + KPrintf("%s enter\n", __func__); mcuboot.flash_init(); - memset(&ota_info, 0, sizeof(ota_info_t)); - mcuboot.op_flash_read(FLAG_FLAH_ADDRESS, (void*)&ota_info, sizeof(ota_info_t)); - ota_info.status = OTA_STATUS_DOWNLOADING; - UpdateOTAFlag(&ota_info); + memset(p_ota_info, 0, sizeof(ota_info_t)); + mcuboot.op_flash_read(FLAG_FLAH_ADDRESS, (void*)p_ota_info, sizeof(ota_info_t)); + p_ota_info->status = OTA_STATUS_DOWNLOADING; + UpdateOTAFlag(p_ota_info); memset(topicdatabuff,0,sizeof(topicdatabuff)); sprintf(topicdatabuff[0],"ota/%s/update",CLIENTID); sprintf(topicdatabuff[1],"ota/%s/files",CLIENTID); @@ -959,20 +966,20 @@ reconnect: { KPrintf("File size is larger than partition size,the partition size is %dk.\n",APP_FLASH_SIZE/1024); ret = -1; - ota_info.status = OTA_STATUS_ERROR; - memset(ota_info.error_message,0,sizeof(ota_info.error_message)); - strncpy(ota_info.error_message, "File size is larger than partition size!",sizeof(ota_info.error_message)); - UpdateOTAFlag(&ota_info); + p_ota_info->status = OTA_STATUS_ERROR; + memset(p_ota_info->error_message,0,sizeof(p_ota_info->error_message)); + strncpy(p_ota_info->error_message, "File size is larger than partition size!",sizeof(p_ota_info->error_message)); + UpdateOTAFlag(p_ota_info); break; } if(mcuboot.op_flash_erase(DOWN_FLAH_ADDRESS,platform_ota.size) != kStatus_Success) { KPrintf("Failed to erase download partition!\n"); ret = -1; - ota_info.status = OTA_STATUS_ERROR; - memset(ota_info.error_message,0,sizeof(ota_info.error_message)); - strncpy(ota_info.error_message, "Failed to erase download partition!",sizeof(ota_info.error_message)); - UpdateOTAFlag(&ota_info); + p_ota_info->status = OTA_STATUS_ERROR; + memset(p_ota_info->error_message,0,sizeof(p_ota_info->error_message)); + strncpy(p_ota_info->error_message, "Failed to erase download partition!",sizeof(p_ota_info->error_message)); + UpdateOTAFlag(p_ota_info); break; } platform_ota.counter = (platform_ota.size%FRAME_LEN != 0)? (platform_ota.size/FRAME_LEN + 1):(platform_ota.size/FRAME_LEN); @@ -984,10 +991,10 @@ reconnect: { KPrintf("Failed to get ota information!\n"); ret = -1; - ota_info.status = OTA_STATUS_ERROR; - memset(ota_info.error_message,0,sizeof(ota_info.error_message)); - strncpy(ota_info.error_message, "Failed to get ota information!",sizeof(ota_info.error_message)); - UpdateOTAFlag(&ota_info); + p_ota_info->status = OTA_STATUS_ERROR; + memset(p_ota_info->error_message,0,sizeof(p_ota_info->error_message)); + strncpy(p_ota_info->error_message, "Failed to get ota information!",sizeof(p_ota_info->error_message)); + UpdateOTAFlag(p_ota_info); break; } } @@ -1001,10 +1008,10 @@ reconnect: { KPrintf("current frame[%d] flash failed.\n",platform_ota.num-1); ret = -1; - ota_info.status = OTA_STATUS_ERROR; - memset(ota_info.error_message,0,sizeof(ota_info.error_message)); - sprintf(ota_info.error_message,"current frame[%d] flash failed.",platform_ota.num-1); - UpdateOTAFlag(&ota_info); + p_ota_info->status = OTA_STATUS_ERROR; + memset(p_ota_info->error_message,0,sizeof(p_ota_info->error_message)); + sprintf(p_ota_info->error_message,"current frame[%d] flash failed.",platform_ota.num-1); + UpdateOTAFlag(p_ota_info); break; } else @@ -1084,21 +1091,21 @@ reconnect: // 新版本固件接收完毕,写入描述信息 if(0 == ret) { - ota_info.down.size = platform_ota.size; - ota_info.down.crc32 = calculate_crc32(DOWN_FLAH_ADDRESS, platform_ota.size); + p_ota_info->down.size = platform_ota.size; + p_ota_info->down.crc32 = calculate_crc32(DOWN_FLAH_ADDRESS, platform_ota.size); - memset(ota_info.down.version,0,sizeof(ota_info.down.version)); - strncpy(ota_info.down.version, platform_ota.version, sizeof(ota_info.down.version)); + memset(p_ota_info->down.version,0,sizeof(p_ota_info->down.version)); + strncpy(p_ota_info->down.version, platform_ota.version, sizeof(p_ota_info->down.version)); - memset(ota_info.down.description,0,sizeof(ota_info.down.description)); - strncpy(ota_info.down.description, "MQTT OTA bin.",sizeof(ota_info.down.description)); + memset(p_ota_info->down.description,0,sizeof(p_ota_info->down.description)); + strncpy(p_ota_info->down.description, "MQTT OTA bin.",sizeof(p_ota_info->down.description)); - ota_info.status = OTA_STATUS_READY; + p_ota_info->status = OTA_STATUS_READY; - memset(ota_info.error_message,0,sizeof(ota_info.error_message)); - strncpy(ota_info.error_message, "No error message!",sizeof(ota_info.error_message)); + memset(p_ota_info->error_message,0,sizeof(p_ota_info->error_message)); + strncpy(p_ota_info->error_message, "No error message!",sizeof(p_ota_info->error_message)); - UpdateOTAFlag(&ota_info); + UpdateOTAFlag(p_ota_info); KPrintf("firmware file transfer successful,start reboot!\n"); } else