全流程升级验证成功
This commit is contained in:
@@ -15,17 +15,21 @@
|
||||
#define UPDATA_PACK_LEN 128
|
||||
#define UPDATA_BASE_ADDR 0x1000
|
||||
#define UPDATA_DATA_LEN (12*1024)
|
||||
#define UPDATA_FLAG_ADDR (0x3c7c)
|
||||
#define UPDATA_FLAG_ADDR (0x7c)
|
||||
//#define UPDATA_FLAG ((uint8_t []){0x99,0x66,0xaa,0x55})
|
||||
#define UPDATA_FLAG ((uint8_t []){0xaa,0xbb,0xcc,0xdd})
|
||||
|
||||
#define UPDATA_CRC_ALL ((uint32_t *)(MC_CODE_ADDR+16*1024))[0]
|
||||
#define UPDATA_CRC_APP ((uint32_t *)(MC_CODE_ADDR+16*1024))[1]
|
||||
|
||||
// 擦除
|
||||
static uint8_t EW_Erease(void)
|
||||
static uint8_t EW_bootErease(void)
|
||||
{
|
||||
uint8_t data[3]={0xfe,0x00,0x00};
|
||||
uint8_t read[4]={0};
|
||||
uint8_t ret=0;
|
||||
DMod_SendBytesXor(data,2,1);
|
||||
delay_ms(10);
|
||||
ret=DMod_ReadBytesXor(read,4,100);
|
||||
DBG_LOG("ret=%d,dat=%02x,%02x,%02x,%02x,",ret,read[0],read[1],read[2],read[3]);
|
||||
return ret;
|
||||
@@ -33,14 +37,14 @@ static uint8_t EW_Erease(void)
|
||||
static int cmd_jwt_boot_erase(list_def *argv)
|
||||
{
|
||||
int ret=0;
|
||||
ret=EW_Erease();
|
||||
ret=EW_bootErease();
|
||||
return ret;
|
||||
}
|
||||
commend_export(jwt_boot_erase,cmd_jwt_boot_erase,"jwt srase in boot")
|
||||
|
||||
|
||||
// 跳转
|
||||
static uint8_t EW_Jump(void)
|
||||
static uint8_t EW_bootJump(void)
|
||||
{
|
||||
uint8_t data[3]={0xf9,0x00,0x00};
|
||||
uint8_t read[4]={0};
|
||||
@@ -53,19 +57,20 @@ static uint8_t EW_Jump(void)
|
||||
static int cmd_jwt_boot_jump(list_def *argv)
|
||||
{
|
||||
int ret=0;
|
||||
ret=EW_Jump();
|
||||
ret=EW_bootJump();
|
||||
return ret;
|
||||
}
|
||||
commend_export(jwt_boot_jump,cmd_jwt_boot_jump,"jwt jump in boot")
|
||||
|
||||
|
||||
// 充电
|
||||
static uint8_t EW_Charg(void)
|
||||
static uint8_t EW_bootCharg(void)
|
||||
{
|
||||
uint8_t data[4]={0xf8,0x01,0x01,0x00};
|
||||
uint8_t read[4]={0};
|
||||
uint8_t ret=0;
|
||||
DMod_SendBytesXor(data,3,1);
|
||||
delay_ms(2);
|
||||
ret=DMod_ReadBytesXor(read,4,100);
|
||||
DBG_LOG("ret=%d,dat=%02x,%02x,%02x,%02x,",ret,read[0],read[1],read[2],read[3]);
|
||||
return ret;
|
||||
@@ -73,7 +78,7 @@ static uint8_t EW_Charg(void)
|
||||
static int cmd_jwt_boot_charg(list_def *argv)
|
||||
{
|
||||
int ret=0;
|
||||
ret=EW_Charg();
|
||||
ret=EW_bootCharg();
|
||||
return ret;
|
||||
}
|
||||
commend_export(jwt_boot_charg,cmd_jwt_boot_charg,"jwt charg in boot")
|
||||
@@ -81,7 +86,7 @@ commend_export(jwt_boot_charg,cmd_jwt_boot_charg,"jwt charg in boot")
|
||||
|
||||
|
||||
// 放电
|
||||
static uint8_t EW_DisCharg(void)
|
||||
static uint8_t EW_bootDisCharg(void)
|
||||
{
|
||||
uint8_t data[4]={0xf8,0x01,0x00,0x00};
|
||||
uint8_t read[4]={0};
|
||||
@@ -94,7 +99,7 @@ static uint8_t EW_DisCharg(void)
|
||||
static int cmd_jwt_boot_discharg(list_def *argv)
|
||||
{
|
||||
int ret=0;
|
||||
ret=EW_Charg();
|
||||
ret=EW_bootDisCharg();
|
||||
return ret;
|
||||
}
|
||||
commend_export(jwt_boot_discharg,cmd_jwt_boot_discharg,"jwt discharg in boot")
|
||||
@@ -103,7 +108,7 @@ commend_export(jwt_boot_discharg,cmd_jwt_boot_discharg,"jwt discharg in boot")
|
||||
|
||||
// 发送数据
|
||||
// len 最长为128字节
|
||||
static uint8_t EW_Write(uint16_t addr,uint8_t *d,uint16_t len)
|
||||
static uint8_t EW_bootWrite(uint16_t addr,uint8_t *d,uint16_t len)
|
||||
{
|
||||
uint8_t ret=0;
|
||||
uint8_t read[4]={0};
|
||||
@@ -114,26 +119,31 @@ static uint8_t EW_Write(uint16_t addr,uint8_t *d,uint16_t len)
|
||||
buf[2]=addr&0xff;
|
||||
buf[3]=addr>>8;
|
||||
rt_memcpy(&buf[4],d,len);
|
||||
LED2_Out=0;
|
||||
DMod_SendBytesXor(buf,len+2+2,1);
|
||||
LED2_Out=1;
|
||||
ret=DMod_ReadBytesXor(read,4,100);
|
||||
rt_free(buf);
|
||||
DBG_LOG("ret=%d,dat=%02x,%02x,%02x,%02x,",ret,read[0],read[1],read[2],read[3]);
|
||||
if(ret){
|
||||
DBG_LOG("ret=%d,dat=%02x,%02x,%02x,%02x,",ret,read[0],read[1],read[2],read[3]);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 校验
|
||||
static uint8_t EW_CheckCrc(uint16_t adr_start,uint16_t adr_end,uint32_t *crc)
|
||||
static uint8_t EW_bootCheckCrc(uint16_t adr_start,uint16_t adr_end,uint32_t *crc)
|
||||
{
|
||||
uint8_t ret=0;
|
||||
uint8_t cmd[7]={0xfb,0x04,adr_start&0xff,adr_start>>8,adr_end&0xff,adr_end>>8};
|
||||
uint8_t read[4+4]={0};
|
||||
DMod_SendBytesXor(cmd,6,1);
|
||||
delay_ms(10);
|
||||
ret=DMod_ReadBytesXor(read,8,100);
|
||||
if(ret==0){
|
||||
if(crc){
|
||||
*crc=(read[3])|(read[4]<<8)|(read[5]<<16)|(read[6]<<24);
|
||||
*crc=(read[3]<<24)|(read[4]<<16)|(read[5]<<8)|(read[6]<<0);
|
||||
}
|
||||
}
|
||||
DBG_LOG("addr_start=0x%04x,addr_end=0x%04x.",adr_start,adr_end);
|
||||
@@ -145,9 +155,10 @@ static int cmd_jwt_boot_checkcrc(list_def *argv)
|
||||
{
|
||||
int ret=0;
|
||||
uint32_t crc=0;
|
||||
ret=EW_CheckCrc(UPDATA_BASE_ADDR,UPDATA_BASE_ADDR+UPDATA_DATA_LEN,&crc);
|
||||
ret=EW_bootCheckCrc(UPDATA_BASE_ADDR,UPDATA_BASE_ADDR+UPDATA_DATA_LEN,&crc);
|
||||
cmd_print("jwt crc32=0x%04x.",crc);
|
||||
crc=Crc32Calu((uint32_t *)(MC_CODE_ADDR+UPDATA_BASE_ADDR),UPDATA_DATA_LEN);
|
||||
//crc=Crc32Calu((uint32_t *)(MC_CODE_ADDR+UPDATA_BASE_ADDR),UPDATA_DATA_LEN);
|
||||
crc=UPDATA_CRC_APP;
|
||||
cmd_print("local crc32=0x%04x.",crc);
|
||||
return ret;
|
||||
}
|
||||
@@ -156,7 +167,7 @@ commend_export(jwt_boot_checkcrc,cmd_jwt_boot_checkcrc,"jwt checkcrc in boot")
|
||||
|
||||
|
||||
// 读取
|
||||
static uint8_t EW_Read(uint16_t adr,uint8_t *buf,uint16_t len)
|
||||
static uint8_t EW_bootRead(uint16_t adr,uint8_t *buf,uint16_t len)
|
||||
{
|
||||
uint8_t ret=0;
|
||||
uint8_t cmd[7]={0xfa,0x03,adr&0xff,adr>>8,len};
|
||||
@@ -198,11 +209,35 @@ static int cmd_jwt_app_commtest(list_def *argv)
|
||||
commend_export(jwt_app_commtest,cmd_jwt_app_commtest,"jwt commtest in app")
|
||||
|
||||
|
||||
|
||||
// app:读取数据
|
||||
static int EW_appRead(void)
|
||||
{
|
||||
uint8_t read_buf[4]={0};
|
||||
int ret=0;
|
||||
uint8_t addr=(uint8_t)(UPDATA_FLAG_ADDR/4);
|
||||
DBG_LOG("addr=0x%02x.",addr);
|
||||
ret=EW_ReadMTP(1,addr,read_buf,4);
|
||||
DBG_LOG("ret=%d,dat=%02x,%02x,%02x,%02x,",ret,read_buf[0],read_buf[1],read_buf[2],read_buf[3]);
|
||||
}
|
||||
static int cmd_jwt_app_read(list_def *argv)
|
||||
{
|
||||
int ret=0;
|
||||
ret=EW_appRead();
|
||||
return ret;
|
||||
}
|
||||
commend_export(jwt_app_read,cmd_jwt_app_read,"jwt read in app")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 升级
|
||||
void EW_Updata(void)
|
||||
{
|
||||
Checker_RunCfg_st *cfg=&checker_runcfg;
|
||||
uint8_t ret=0;
|
||||
uint8_t read_buf[4]={0};
|
||||
uint8_t *data=(uint8_t *)MC_CODE_ADDR+UPDATA_BASE_ADDR;
|
||||
uint16_t len=UPDATA_DATA_LEN;
|
||||
uint16_t addr=UPDATA_BASE_ADDR;
|
||||
@@ -210,38 +245,57 @@ void EW_Updata(void)
|
||||
uint32_t crc=0;
|
||||
uint32_t crc_module=0;
|
||||
delay_ms(100);
|
||||
ret=EW_Charg();
|
||||
ret=EW_bootCharg();
|
||||
if(ret) {ret=1;goto err;}
|
||||
delay_ms(6000);
|
||||
ret=EW_Erease();
|
||||
ret=EW_bootErease();
|
||||
if(ret) {ret=2;goto err;}
|
||||
delay_ms(600);
|
||||
while(len>0){
|
||||
pack_len=len>UPDATA_PACK_LEN?UPDATA_PACK_LEN:len;
|
||||
ret=EW_Write(addr,data,pack_len);
|
||||
LED1_Out=!LED1_Out;
|
||||
ret=EW_bootWrite(addr,data,pack_len);
|
||||
addr+=pack_len;
|
||||
data+=pack_len;
|
||||
len-=pack_len;
|
||||
if(ret) {ret=3;goto err;}
|
||||
delay_ms(50);
|
||||
delay_ms(1);
|
||||
}
|
||||
crc=Crc32Calu((uint32_t *)(MC_CODE_ADDR+UPDATA_BASE_ADDR),UPDATA_DATA_LEN);
|
||||
//crc=Crc32Calu((uint32_t *)(MC_CODE_ADDR+UPDATA_BASE_ADDR),UPDATA_DATA_LEN);
|
||||
crc=UPDATA_CRC_APP;
|
||||
DBG_LOG("local crc:0x%04x.",crc);
|
||||
ret=EW_CheckCrc(UPDATA_BASE_ADDR,UPDATA_BASE_ADDR+UPDATA_DATA_LEN,&crc_module);
|
||||
ret=EW_bootCheckCrc(UPDATA_BASE_ADDR,UPDATA_BASE_ADDR+UPDATA_DATA_LEN,&crc_module);
|
||||
DBG_LOG("module crc:0x%04x.",crc_module);
|
||||
if(ret) {ret=4;goto err;}
|
||||
if(crc!=crc_module){ret=5;goto err;}
|
||||
delay_ms(50);
|
||||
ret=EW_Jump();
|
||||
ret=EW_bootJump();
|
||||
if(ret) {ret=6;goto err;}
|
||||
delay_ms(100);
|
||||
delay_ms(6000);
|
||||
ret=EW_EnWriteMTP(0,1);
|
||||
if(ret) {ret=7;goto err;}
|
||||
delay_ms(100);
|
||||
// 数据溢出
|
||||
// ret=EW_WriteMTP(0,(uint8_t)(UPDATA_FLAG_ADDR/4),UPDATA_FLAG,4);
|
||||
DBG_LOG("EW_EnWriteMTP success.");
|
||||
delay_ms(1);
|
||||
|
||||
ret=EW_WriteMTP(1,(uint8_t)(UPDATA_FLAG_ADDR/4),UPDATA_FLAG,4);
|
||||
if(ret) {ret=8;goto err;}
|
||||
delay_ms(100);
|
||||
DBG_LOG("EW_WriteMTP success.");
|
||||
delay_ms(1);
|
||||
ret=EW_ReadMTP(1,(uint8_t)(UPDATA_FLAG_ADDR/4),read_buf,4);
|
||||
if(ret) {ret=9;goto err;}
|
||||
if(memcmp(read_buf,UPDATA_FLAG,4)!=0){
|
||||
DBG_LOG("read_buf=0x%02d,0x%02d,0x%02d,0x%02d.",read_buf[0],read_buf[1],read_buf[2],read_buf[3]);
|
||||
ret=10;goto err;
|
||||
}
|
||||
DBG_LOG("EW_ReadMTP check success.");
|
||||
delay_ms(1);
|
||||
XTBUS_OFF;
|
||||
delay_ms(1000);
|
||||
XTBUS_ON;
|
||||
delay_ms(6000);
|
||||
ret=EW_appCommTest();
|
||||
if(ret) {ret=11;goto err;}
|
||||
DBG_LOG("EW_appCommTest success.");
|
||||
|
||||
err:
|
||||
DBG_LOG("ret=%d",ret);
|
||||
|
Reference in New Issue
Block a user