OTA info addresses need to be aligned

This commit is contained in:
songyanguang 2025-05-09 18:21:36 +08:00
parent a3771bed07
commit cd121f49f9
6 changed files with 65 additions and 51 deletions

View File

@ -200,6 +200,8 @@ static int Ec801eConnect(struct Adapter *adapter, enum NetRoleType net_role, con
int try = 0; int try = 0;
uint8_t ec801e_cmd[64]; uint8_t ec801e_cmd[64];
ADAPTER_DEBUG("%s enter\n", __func__);
AtSetReplyEndChar(adapter->agent, 0x4F, 0x4B); AtSetReplyEndChar(adapter->agent, 0x4F, 0x4B);
/*step1: serial write "+++", quit transparent mode*/ /*step1: serial write "+++", quit transparent mode*/

View File

@ -46,6 +46,8 @@ int AdapterNetActive(void)
{ {
int ret = 0; int ret = 0;
uint32_t baud_rate = BAUD_RATE_115200; uint32_t baud_rate = BAUD_RATE_115200;
KPrintf("%s enter\n", __func__);
adapter = AdapterDeviceFindByName(ADAPTER_4G_NAME); adapter = AdapterDeviceFindByName(ADAPTER_4G_NAME);
adapter->socket.socket_id = 0; adapter->socket.socket_id = 0;
@ -66,12 +68,14 @@ int AdapterNetActive(void)
{ {
goto out; goto out;
} }
KPrintf("%s success\n", __func__);
out: out:
if (ret < 0) if (ret < 0)
{ {
AdapterDeviceClose(adapter); AdapterDeviceClose(adapter);
} }
KPrintf("%s fail\n", __func__);
return ret; return ret;
} }
@ -112,6 +116,7 @@ bool MQTT_Connect(void)
{ {
uint8_t TryConnect_time = 10; //尝试登录次数 uint8_t TryConnect_time = 10; //尝试登录次数
KPrintf("%s enter\n", __func__);
memset(&Platform_mqtt,0,sizeof(Platform_mqtt)); memset(&Platform_mqtt,0,sizeof(Platform_mqtt));
#ifdef XIUOS_PLATFORM #ifdef XIUOS_PLATFORM
sprintf(Platform_mqtt.ClientID,"%s",CLIENTID); //客户端ID存入缓冲区 sprintf(Platform_mqtt.ClientID,"%s",CLIENTID); //客户端ID存入缓冲区

View File

@ -79,7 +79,7 @@ void readRomConfiguration(void) {
if ((CFG->cfgFlag[0] != checkcode1) || (CFG->cfgFlag[1] != checkcode2)) { if ((CFG->cfgFlag[0] != checkcode1) || (CFG->cfgFlag[1] != checkcode2)) {
CFG_ERASE(PAGE_WRITE_START_ADDR, FLASH_PAGE_SIZE); CFG_ERASE(PAGE_WRITE_START_ADDR, FLASH_PAGE_SIZE);
CFG_WRITE(PAGE_WRITE_START_ADDR, (u8 *)&defaultConfiguration, MODULE_CFG_LEN); 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 NVIC_SystemReset(); // 复位ch32v208
} }

View File

@ -109,7 +109,7 @@ void mcuboot_reset(void)
void mcuboot_jump(void) void mcuboot_jump(void)
{ {
KPrintf("boot jumpApp\n"); KPrintf("boot jumpApp\n\n");
jumpApp(); jumpApp();
/* /*
uint32_t addr = XIUOS_FLAH_ADDRESS; uint32_t addr = XIUOS_FLAH_ADDRESS;

View File

@ -80,14 +80,14 @@ status_t Flash_Erase(uint32_t start_addr, uint32_t imageSize)
uint32_t page_count; uint32_t page_count;
uint32_t pageNum = (imageSize%FLASH_PAGE_FAST_SIZE != 0)? (imageSize/FLASH_PAGE_FAST_SIZE + 1):(imageSize/FLASH_PAGE_FAST_SIZE); 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(); FLASH_Unlock_Fast();
for(page_count = 0; page_count < pageNum; page_count++) for(page_count = 0; page_count < pageNum; page_count++)
{ {
FLASH_ErasePage_Fast(start_addr + (page_count * FLASH_PAGE_FAST_SIZE)); FLASH_ErasePage_Fast(start_addr + (page_count * FLASH_PAGE_FAST_SIZE));
} }
FLASH_Lock_Fast(); 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; 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 page_count;
uint32_t pageNum = (NumByteToWrite%FLASH_PAGE_FAST_SIZE != 0)? (NumByteToWrite/FLASH_PAGE_FAST_SIZE + 1):(NumByteToWrite/FLASH_PAGE_FAST_SIZE); 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(); FLASH_Unlock_Fast();
for(page_count = 0; page_count < pageNum; page_count++) 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_ProgramPage_Fast(WriteAddr + (page_count * FLASH_PAGE_FAST_SIZE), (uint32_t *)&pBuffer[page_count * FLASH_PAGE_FAST_SIZE]);
} }
FLASH_Lock_Fast(); 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; return (status_t)kStatus_Success;

View File

@ -104,6 +104,7 @@ static const uint32_t crc32tab[] = {
0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
}; };
__attribute__((aligned(8))) ota_info_t g_ota_info;
/******************************************************************************* /*******************************************************************************
* : calculate_crc32 * : calculate_crc32
@ -197,19 +198,19 @@ static status_t UpdateOTAFlag(ota_info_t *ptr)
static void InitialVersion(void) static void InitialVersion(void)
{ {
int32_t size; 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); size = mcuboot.download_by_serial(XIUOS_FLAH_ADDRESS);
if(size > 0) if(size > 0)
{ {
ota_info.os.size = size; p_ota_info->os.size = size;
ota_info.os.crc32 = calculate_crc32(XIUOS_FLAH_ADDRESS, 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(p_ota_info->os.version,"001.000.000",sizeof(p_ota_info->os.version));
strncpy(ota_info.os.description, "The initial firmware.", sizeof(ota_info.os.description)); 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) static void BootLoaderJumpApp(void)
{ {
ota_info_t ota_info; ota_info_t *p_ota_info = &g_ota_info;
mcuboot.flash_init(); mcuboot.flash_init();
memset(&ota_info, 0, sizeof(ota_info_t)); memset(p_ota_info, 0, sizeof(ota_info_t));
mcuboot.op_flash_read(FLAG_FLAH_ADDRESS, (void*)&ota_info, 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"); 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 else
{ {
ota_info.lastjumpflag = JUMP_FAILED_FLAG; p_ota_info->lastjumpflag = JUMP_FAILED_FLAG;
UpdateOTAFlag(&ota_info); UpdateOTAFlag(p_ota_info);
} }
mcuboot.flash_deinit(); mcuboot.flash_deinit();
mcuboot.op_jump(); mcuboot.op_jump();
@ -882,18 +888,19 @@ static void mqttCloudInteraction(void* parameter)
int datalen; int datalen;
int ret = 0; int ret = 0;
int freecnt = 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 heart_time = 0;
uint32_t flashdestination = DOWN_FLAH_ADDRESS; uint32_t flashdestination = DOWN_FLAH_ADDRESS;
uint8_t topicdatabuff[2][64]; uint8_t topicdatabuff[2][64];
char *ptr1, *ptr2; char *ptr1, *ptr2;
uint16_t payloadLen; uint16_t payloadLen;
KPrintf("%s enter\n", __func__);
mcuboot.flash_init(); mcuboot.flash_init();
memset(&ota_info, 0, sizeof(ota_info_t)); memset(p_ota_info, 0, sizeof(ota_info_t));
mcuboot.op_flash_read(FLAG_FLAH_ADDRESS, (void*)&ota_info, sizeof(ota_info_t)); mcuboot.op_flash_read(FLAG_FLAH_ADDRESS, (void*)p_ota_info, sizeof(ota_info_t));
ota_info.status = OTA_STATUS_DOWNLOADING; p_ota_info->status = OTA_STATUS_DOWNLOADING;
UpdateOTAFlag(&ota_info); UpdateOTAFlag(p_ota_info);
memset(topicdatabuff,0,sizeof(topicdatabuff)); memset(topicdatabuff,0,sizeof(topicdatabuff));
sprintf(topicdatabuff[0],"ota/%s/update",CLIENTID); sprintf(topicdatabuff[0],"ota/%s/update",CLIENTID);
sprintf(topicdatabuff[1],"ota/%s/files",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); KPrintf("File size is larger than partition size,the partition size is %dk.\n",APP_FLASH_SIZE/1024);
ret = -1; ret = -1;
ota_info.status = OTA_STATUS_ERROR; p_ota_info->status = OTA_STATUS_ERROR;
memset(ota_info.error_message,0,sizeof(ota_info.error_message)); memset(p_ota_info->error_message,0,sizeof(p_ota_info->error_message));
strncpy(ota_info.error_message, "File size is larger than partition size!",sizeof(ota_info.error_message)); strncpy(p_ota_info->error_message, "File size is larger than partition size!",sizeof(p_ota_info->error_message));
UpdateOTAFlag(&ota_info); UpdateOTAFlag(p_ota_info);
break; break;
} }
if(mcuboot.op_flash_erase(DOWN_FLAH_ADDRESS,platform_ota.size) != kStatus_Success) if(mcuboot.op_flash_erase(DOWN_FLAH_ADDRESS,platform_ota.size) != kStatus_Success)
{ {
KPrintf("Failed to erase download partition!\n"); KPrintf("Failed to erase download partition!\n");
ret = -1; ret = -1;
ota_info.status = OTA_STATUS_ERROR; p_ota_info->status = OTA_STATUS_ERROR;
memset(ota_info.error_message,0,sizeof(ota_info.error_message)); memset(p_ota_info->error_message,0,sizeof(p_ota_info->error_message));
strncpy(ota_info.error_message, "Failed to erase download partition!",sizeof(ota_info.error_message)); strncpy(p_ota_info->error_message, "Failed to erase download partition!",sizeof(p_ota_info->error_message));
UpdateOTAFlag(&ota_info); UpdateOTAFlag(p_ota_info);
break; break;
} }
platform_ota.counter = (platform_ota.size%FRAME_LEN != 0)? (platform_ota.size/FRAME_LEN + 1):(platform_ota.size/FRAME_LEN); 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"); KPrintf("Failed to get ota information!\n");
ret = -1; ret = -1;
ota_info.status = OTA_STATUS_ERROR; p_ota_info->status = OTA_STATUS_ERROR;
memset(ota_info.error_message,0,sizeof(ota_info.error_message)); memset(p_ota_info->error_message,0,sizeof(p_ota_info->error_message));
strncpy(ota_info.error_message, "Failed to get ota information!",sizeof(ota_info.error_message)); strncpy(p_ota_info->error_message, "Failed to get ota information!",sizeof(p_ota_info->error_message));
UpdateOTAFlag(&ota_info); UpdateOTAFlag(p_ota_info);
break; break;
} }
} }
@ -1001,10 +1008,10 @@ reconnect:
{ {
KPrintf("current frame[%d] flash failed.\n",platform_ota.num-1); KPrintf("current frame[%d] flash failed.\n",platform_ota.num-1);
ret = -1; ret = -1;
ota_info.status = OTA_STATUS_ERROR; p_ota_info->status = OTA_STATUS_ERROR;
memset(ota_info.error_message,0,sizeof(ota_info.error_message)); memset(p_ota_info->error_message,0,sizeof(p_ota_info->error_message));
sprintf(ota_info.error_message,"current frame[%d] flash failed.",platform_ota.num-1); sprintf(p_ota_info->error_message,"current frame[%d] flash failed.",platform_ota.num-1);
UpdateOTAFlag(&ota_info); UpdateOTAFlag(p_ota_info);
break; break;
} }
else else
@ -1084,21 +1091,21 @@ reconnect:
// 新版本固件接收完毕,写入描述信息 // 新版本固件接收完毕,写入描述信息
if(0 == ret) if(0 == ret)
{ {
ota_info.down.size = platform_ota.size; p_ota_info->down.size = platform_ota.size;
ota_info.down.crc32 = calculate_crc32(DOWN_FLAH_ADDRESS, 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)); memset(p_ota_info->down.version,0,sizeof(p_ota_info->down.version));
strncpy(ota_info.down.version, platform_ota.version, sizeof(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)); memset(p_ota_info->down.description,0,sizeof(p_ota_info->down.description));
strncpy(ota_info.down.description, "MQTT OTA bin.",sizeof(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)); memset(p_ota_info->error_message,0,sizeof(p_ota_info->error_message));
strncpy(ota_info.error_message, "No error message!",sizeof(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"); KPrintf("firmware file transfer successful,start reboot!\n");
} }
else else