forked from xuos/xiuos
1、Optimize the tcp server file reading operation during the OTA process
2、Optimize the ota.c file 3、revert dev_serial.c
This commit is contained in:
parent
e48bd6fd67
commit
5a1fe0be3b
|
@ -154,9 +154,7 @@ static inline int SerialDevIntRead(struct SerialHardwareDevice *serial_dev, stru
|
||||||
|
|
||||||
CriticalAreaUnLock(lock);
|
CriticalAreaUnLock(lock);
|
||||||
|
|
||||||
#ifndef TOOL_USING_OTA
|
|
||||||
MdelayKTask(20);
|
MdelayKTask(20);
|
||||||
#endif
|
|
||||||
|
|
||||||
*read_data = get_char;
|
*read_data = get_char;
|
||||||
read_data++;
|
read_data++;
|
||||||
|
|
|
@ -33,13 +33,21 @@
|
||||||
* Private Function Prototypes
|
* Private Function Prototypes
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
static uint32_t calculate_crc32(uint32_t addr, uint32_t len);
|
static uint32_t calculate_crc32(uint32_t addr, uint32_t len);
|
||||||
|
static uint16_t calculate_crc16(uint8_t * data, uint32_t len);
|
||||||
static void UpdateNewApplication(void);
|
static void UpdateNewApplication(void);
|
||||||
static void InitialVersion(void);
|
static void InitialVersion(void);
|
||||||
static void BackupVersion(void);
|
static void BackupVersion(void);
|
||||||
static void BootLoaderJumpApp(void);
|
static void BootLoaderJumpApp(void);
|
||||||
static status_t UpdateOTAFlag(ota_info_t *ptr);
|
static status_t UpdateOTAFlag(ota_info_t *ptr);
|
||||||
|
static void app_ota_by_iap(void);
|
||||||
static void Update(void);
|
static void Update(void);
|
||||||
|
|
||||||
|
#ifdef CONNECTION_ADAPTER_4G
|
||||||
|
static void get_start_signal(struct Adapter* adapter);
|
||||||
|
static int ota_data_recv(struct Adapter* adapter);
|
||||||
|
static void app_ota_by_4g(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Data
|
* Private Data
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
@ -60,6 +68,7 @@ static const mcuboot_t mcuboot =
|
||||||
mcuboot_delay
|
mcuboot_delay
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static const uint32_t crc32tab[] = {
|
static const uint32_t crc32tab[] = {
|
||||||
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
|
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
|
||||||
0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
|
0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
|
||||||
|
@ -142,6 +151,7 @@ static uint16_t calculate_crc16(uint8_t * data, uint32_t len)
|
||||||
return reg_crc;
|
return reg_crc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* 函 数 名: UpdateNewApplication
|
* 函 数 名: UpdateNewApplication
|
||||||
* 功能描述: 在bootloader里进行调用,根据Flash中Flag分区中的信息决定是否进行版本更新
|
* 功能描述: 在bootloader里进行调用,根据Flash中Flag分区中的信息决定是否进行版本更新
|
||||||
|
@ -255,6 +265,7 @@ static void InitialVersion(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* 函 数 名: BackupVersion
|
* 函 数 名: BackupVersion
|
||||||
* 功能描述: 版本回退函数,如果升级的APP存在bug导致无法跳转需调用此函数进行版本回退
|
* 功能描述: 版本回退函数,如果升级的APP存在bug导致无法跳转需调用此函数进行版本回退
|
||||||
|
@ -396,13 +407,14 @@ void app_clear_jumpflag(void)
|
||||||
mcuboot.flash_deinit();
|
mcuboot.flash_deinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* 函 数 名: Update
|
* 函 数 名: Update
|
||||||
* 功能描述: 根据实际情况进行初始化版本的烧录或者新版本的升级
|
* 功能描述: 根据实际情况进行初始化版本的烧录或者新版本的升级
|
||||||
* 形 参: 无
|
* 形 参: 无
|
||||||
* 返 回 值: 无
|
* 返 回 值: 无
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
void Update(void)
|
static void Update(void)
|
||||||
{
|
{
|
||||||
ota_info_t ota_info;
|
ota_info_t ota_info;
|
||||||
mcuboot.flash_init();
|
mcuboot.flash_init();
|
||||||
|
@ -420,6 +432,7 @@ void Update(void)
|
||||||
mcuboot.flash_deinit();
|
mcuboot.flash_deinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* 函 数 名: ota_entry
|
* 函 数 名: ota_entry
|
||||||
* 功能描述: bootloader的入口函数
|
* 功能描述: bootloader的入口函数
|
||||||
|
@ -667,7 +680,7 @@ try_again:
|
||||||
* 形 参: adapter:Adapter指针,指向注册的4G设备
|
* 形 参: adapter:Adapter指针,指向注册的4G设备
|
||||||
* 返 回 值: 0:传输成功,-1:传输失败
|
* 返 回 值: 0:传输成功,-1:传输失败
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
void app_ota_by_4g(void)
|
static void app_ota_by_4g(void)
|
||||||
{
|
{
|
||||||
struct ota_data recv_msg;
|
struct ota_data recv_msg;
|
||||||
char reply[16] = {0};
|
char reply[16] = {0};
|
||||||
|
|
|
@ -254,6 +254,7 @@ int ota_file_send(int fd)
|
||||||
if(NULL == file_fd)
|
if(NULL == file_fd)
|
||||||
{
|
{
|
||||||
printf("open file failed.\n");
|
printf("open file failed.\n");
|
||||||
|
fclose(file_fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
fseek(file_fd, 0, SEEK_SET);
|
fseek(file_fd, 0, SEEK_SET);
|
||||||
|
@ -266,7 +267,7 @@ int ota_file_send(int fd)
|
||||||
|
|
||||||
data.header.frame_flag = 0x5A5A;
|
data.header.frame_flag = 0x5A5A;
|
||||||
length = fread(data.frame.frame_data, 1, LENGTH, file_fd);
|
length = fread(data.frame.frame_data, 1, LENGTH, file_fd);
|
||||||
if(length > 0)
|
if(length == LENGTH)
|
||||||
{
|
{
|
||||||
printf("read %d bytes\n",length);
|
printf("read %d bytes\n",length);
|
||||||
data.frame.frame_id = frame_cnt;
|
data.frame.frame_id = frame_cnt;
|
||||||
|
@ -274,6 +275,29 @@ int ota_file_send(int fd)
|
||||||
data.frame.crc = calculate_crc16(data.frame.frame_data, length);
|
data.frame.crc = calculate_crc16(data.frame.frame_data, length);
|
||||||
file_length += length;
|
file_length += length;
|
||||||
}
|
}
|
||||||
|
else if(length > 0 && length < LENGTH)
|
||||||
|
{
|
||||||
|
if(ferror(file_fd))
|
||||||
|
{
|
||||||
|
printf("read %s file error!\n", basename(BIN_PATH));
|
||||||
|
ret = -1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("read %d bytes\n",length);
|
||||||
|
data.frame.frame_id = frame_cnt;
|
||||||
|
data.frame.frame_len = length;
|
||||||
|
data.frame.crc = calculate_crc16(data.frame.frame_data, length);
|
||||||
|
file_length += length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//fread返回值为0,此时是个空包,不需要再发送了否则是冗余数据
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("read %s file done!\n", basename(BIN_PATH));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
send_again:
|
send_again:
|
||||||
printf("send frame[%d] to client %d.\n", frame_cnt, fd);
|
printf("send frame[%d] to client %d.\n", frame_cnt, fd);
|
||||||
|
@ -303,7 +327,7 @@ recv_again:
|
||||||
else if(0 == strncmp(buf, "ok", length))
|
else if(0 == strncmp(buf, "ok", length))
|
||||||
{
|
{
|
||||||
printf("receive buf[%s] length %d from client %d.\n", buf, length, fd);
|
printf("receive buf[%s] length %d from client %d.\n", buf, length, fd);
|
||||||
try_times = 10;
|
try_times = 5;
|
||||||
printf("send to client %d frame[%d] data send done.\n",fd, frame_cnt);
|
printf("send to client %d frame[%d] data send done.\n",fd, frame_cnt);
|
||||||
frame_cnt++;
|
frame_cnt++;
|
||||||
continue;
|
continue;
|
||||||
|
@ -319,7 +343,7 @@ recv_again:
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("send to client %d frame[%d] 10 times failed.\n",fd, frame_cnt);
|
printf("send to client %d frame[%d] 5 times failed.\n",fd, frame_cnt);
|
||||||
ret = -1;
|
ret = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue