update ota & otu

This commit is contained in:
pvvx 2017-02-05 00:26:09 +03:00
parent 1145aed8fb
commit 425b9306ec
8 changed files with 275 additions and 212 deletions

View file

@ -146,8 +146,12 @@ void fATSR(void *arg)
#if CONFIG_UART_XMODEM #if CONFIG_UART_XMODEM
void fATSY(void *arg) void fATSY(void *arg)
{ {
#ifdef RTL8710AF
OTU_FW_Update(0, 0, 115200);
#else
// use xmodem to update, RX: PA_6, TX: PA_7, baudrate: 1M // use xmodem to update, RX: PA_6, TX: PA_7, baudrate: 1M
OTU_FW_Update(0, 2, 115200); OTU_FW_Update(0, 2, 115200);
#endif
} }
#endif #endif
@ -1154,20 +1158,16 @@ void fATSL(void *arg) {
#if CONFIG_UART_XMODEM #if CONFIG_UART_XMODEM
void fATSX(void *arg) void fATSX(void *arg)
{ {
#ifdef RTL8711AM #ifdef RTL8710AF
#error "Set OTU_FW_Update UARTx pins!" // use xmodem to update, RX: PC_0, TX: PC_3, baudrate: 1M
OTU_FW_Update(0, 0, 115200);
// use xmodem to update, RX: PE_3, TX: PE_0, baudrate: 1M
// JTAG Off!
// OTU_FW_Update(0, 1, 115200);
#else
//#error "Set OTU_FW_Update UARTx pins!"
// use xmodem to update, RX: PA_6, TX: PA_7, baudrate: 1M // use xmodem to update, RX: PA_6, TX: PA_7, baudrate: 1M
OTU_FW_Update(0, 2, 115200); OTU_FW_Update(0, 2, 115200);
#else
#ifdef RTL8710AF
#error "OTU_FW_Update work only SDRAM buffer!"
#endif
// use xmodem to update, RX: PC_0, TX: PC_3, baudrate: 1M
OTU_FW_Update(0, 0, 115200);
// use xmodem to update, RX: PE_3, TX: PE_0, baudrate: 1M
// JTAG Off!
// OTU_FW_Update(0, 1, 115200);
#endif #endif
at_printf("\r\n[ATSX] OK"); at_printf("\r\n[ATSX] OK");
} }

View file

@ -20,6 +20,18 @@
#if CONFIG_UART_SOCKET #if CONFIG_UART_SOCKET
#if /*CONFIG_PERI_UPDATE_IMG*/1 #if /*CONFIG_PERI_UPDATE_IMG*/1
#define USE_FLASH_API 1
#if USE_FLASH_API
#include "device_lock.h"
#include "flash_api.h"
#endif
#ifndef FLASH_SECTOR_SIZE
#define FLASH_SECTOR_SIZE 4096
#endif
#define IMG1_SIGN_OFFSET 0x34 #define IMG1_SIGN_OFFSET 0x34
enum { enum {
@ -29,7 +41,7 @@ enum {
XMODEM_LOG_UART = 3 XMODEM_LOG_UART = 3
}; };
FWU_DATA_SECTION char xMFrameBuf[XM_BUFFER_SIZE]; FWU_DATA_SECTION char * xMFrameBuf; // [XM_BUFFER_SIZE];
FWU_DATA_SECTION XMODEM_CTRL xMCtrl; FWU_DATA_SECTION XMODEM_CTRL xMCtrl;
FWU_DATA_SECTION static u32 fw_img1_size; FWU_DATA_SECTION static u32 fw_img1_size;
@ -44,7 +56,7 @@ FWU_DATA_SECTION static u32 flash_wr_err_cnt;
FWU_DATA_SECTION HAL_RUART_ADAPTER xmodem_uart_adp; // we can dynamic allocate memory for this object to save memory FWU_DATA_SECTION HAL_RUART_ADAPTER xmodem_uart_adp; // we can dynamic allocate memory for this object to save memory
FWU_RODATA_SECTION const char Img2Signature[8]="81958711"; FWU_RODATA_SECTION const char Img2Signature[8] = IMG_SIGN_RUN;
extern u32 SpicCalibrationPattern[4]; extern u32 SpicCalibrationPattern[4];
extern const u8 ROM_IMG1_VALID_PATTEN[]; extern const u8 ROM_IMG1_VALID_PATTEN[];
extern HAL_RUART_ADAPTER *pxmodem_uart_adp; extern HAL_RUART_ADAPTER *pxmodem_uart_adp;
@ -61,6 +73,7 @@ extern VOID SpicWaitWipDoneRefinedRtl8195A(SPIC_INIT_PARA SpicInitPara);
VOID WriteImg1Sign(u32 Image2Addr); VOID WriteImg1Sign(u32 Image2Addr);
FWU_TEXT_SECTION void FWU_WriteWord(u32 Addr, u32 FData) FWU_TEXT_SECTION void FWU_WriteWord(u32 Addr, u32 FData)
{ {
SPIC_INIT_PARA SpicInitPara; SPIC_INIT_PARA SpicInitPara;
@ -81,7 +94,7 @@ FWU_TEXT_SECTION u32 xModem_MemCmp(const u32 *av, const u32 *bv, u32 len)
for (i=0; i<len4b; i++) { for (i=0; i<len4b; i++) {
if (a[i] != b[i]) { if (a[i] != b[i]) {
DBG_MISC_ERR("OTU: Flash write check error @ 0x%08x\r\n", (u32)(&b[i])); DBG_MISC_ERR("OTU: Flash write check error @ 0x%08x\n", (u32)(&b[i]));
return ((u32)(&b[i])); return ((u32)(&b[i]));
} }
} }
@ -93,13 +106,13 @@ u32 xModem_Frame_Dump(char *ptr, unsigned int frame_num)
{ {
u32 i; u32 i;
DiagPrintf("===== Frme %d ======\r\n", frame_num); DiagPrintf("===== Frme %d ======\n", frame_num);
for(i=0;i<128;i+=16) { for(i=0;i<128;i+=16) {
DiagPrintf("%02x: ", i); DiagPrintf("%02x: ", i);
DiagPrintf("%02x %02x %02x %02x %02x %02x %02x %02x ", DiagPrintf("%02x %02x %02x %02x %02x %02x %02x %02x ",
*(ptr+i),*(ptr+i+1),*(ptr+i+2),*(ptr+i+3),*(ptr+i+4),*(ptr+i+5),*(ptr+i+6),*(ptr+i+7)); *(ptr+i),*(ptr+i+1),*(ptr+i+2),*(ptr+i+3),*(ptr+i+4),*(ptr+i+5),*(ptr+i+6),*(ptr+i+7));
DiagPrintf("%02x %02x %02x %02x %02x %02x %02x %02x \r\n", DiagPrintf("%02x %02x %02x %02x %02x %02x %02x %02x\n",
*(ptr+i+8),*(ptr+i+9),*(ptr+i+10),*(ptr+i+11),*(ptr+i+12),*(ptr+i+13),*(ptr+i+14),*(ptr+i+15)); *(ptr+i+8),*(ptr+i+9),*(ptr+i+10),*(ptr+i+11),*(ptr+i+12),*(ptr+i+13),*(ptr+i+14),*(ptr+i+15));
} }
@ -205,26 +218,33 @@ u32 xModem_Frame_Img2(char *ptr, unsigned int frame_num, unsigned int frame_siz
// Parse Image2 header // Parse Image2 header
flash_wr_offset = fw_img2_addr; flash_wr_offset = fw_img2_addr;
fw_img2_size = rtk_le32_to_cpu(*((u32*)ptr)) + 0x10; fw_img2_size = rtk_le32_to_cpu(*((u32*)ptr)) + 0x10;
/*
if ((fw_img2_size & 0x03) != 0) { if ((fw_img2_size & 0x03) != 0) {
DBG_MISC_ERR("xModem_Frame_ImgAll Err#2: fw_img2_addr=0x%x fw_img2_size(%d) isn't 4-bytes aligned\r\n", fw_img2_addr, fw_img2_size); DBG_MISC_ERR("OTU: fw_img2_addr=0x%x fw_img2_size(%d) isn't 4-bytes aligned\n", fw_img2_addr, fw_img2_size);
fw_img1_size = 0; fw_img1_size = 0;
fw_img2_size = 0; fw_img2_size = 0;
return rx_len; return rx_len;
} }
*/
#ifdef RTL8710AF
if (fw_img2_size > (0x80000-0x0B000)) {
#else
if (fw_img2_size > (2*1024*1024)) { if (fw_img2_size > (2*1024*1024)) {
DBG_MISC_ERR("xModem_Frame_ImgAll Image2 to Big: fw_img2_addr=0x%x fw_img2_size(%d) \r\n", fw_img2_addr, fw_img2_size); #endif
DBG_MISC_ERR("OTU: fw_img2_addr=0x%x fw_img2_size(%d) to Big!\n", fw_img2_addr, fw_img2_size);
fw_img1_size = 0; fw_img1_size = 0;
fw_img2_size = 0; fw_img2_size = 0;
return rx_len; return rx_len;
} }
printf("fw_img2_addr=0x%x fw_img2_size(%d)\n", fw_img2_addr, fw_img2_size);
fw_img3_addr = fw_img2_addr + fw_img2_size; fw_img3_addr = fw_img2_addr + fw_img2_size;
// erase Flash first // erase Flash first
address = fw_img2_addr & (~0xfff); // 4k aligned, 4k is the page size of flash memory address = fw_img2_addr & (~(FLASH_SECTOR_SIZE-1)); // 4k aligned, 4k is the page size of flash memory
while ((address) < (fw_img2_addr+fw_img2_size)) { while ((address) < (fw_img2_addr+fw_img2_size)) {
DBG_MISC_INFO("Flash Erase: %p\n", address);
SpicSectorEraseFlashRtl8195A(SPI_FLASH_BASE + address); SpicSectorEraseFlashRtl8195A(SPI_FLASH_BASE + address);
address += 0x1000; address += FLASH_SECTOR_SIZE;
} }
flash_erased_addr = address; flash_erased_addr = address;
} }
@ -280,14 +300,19 @@ u32 xModem_Frame_Img2(char *ptr, unsigned int frame_num, unsigned int frame_siz
fw_img3_size = 0; fw_img3_size = 0;
return rx_len; return rx_len;
} }
/*
if ((fw_img3_size & 0x03) != 0) { if ((fw_img3_size & 0x03) != 0) {
DBG_MISC_ERR("xModem_Frame_ImgAll Err#5: fw_img3_addr=0x%x fw_img3_size(%d) isn't 4-bytes aligned\r\n", fw_img3_addr, fw_img3_size); DBG_MISC_ERR("OTU Err#5: fw_img3_addr=0x%x fw_img3_size(%d) isn't 4-bytes aligned\n", fw_img3_addr, fw_img3_size);
fw_img3_size = 0; fw_img3_size = 0;
return rx_len; return rx_len;
} }
*/
if (fw_img3_size > (2*1024*1024)) { #ifdef RTL8710AF
DBG_MISC_ERR("xModem_Frame_ImgAll Image3 to Big: fw_img3_addr=0x%x fw_img2_size(%d) \r\n", fw_img3_addr, fw_img3_size); if (fw_img2_size > (0x80000 - fw_img3_addr)) {
#else
if (fw_img2_size > (2*1024*1024)) {
#endif
DBG_MISC_ERR("OTU: fw_img3_addr=0x%x fw_img2_size(%d) to Big!\n", fw_img3_addr, fw_img3_size);
fw_img3_size = 0; fw_img3_size = 0;
return rx_len; return rx_len;
} }
@ -296,21 +321,22 @@ u32 xModem_Frame_Img2(char *ptr, unsigned int frame_num, unsigned int frame_siz
if (flash_erased_addr >= fw_img3_addr) { if (flash_erased_addr >= fw_img3_addr) {
address = flash_erased_addr; address = flash_erased_addr;
} else { } else {
address = fw_img3_addr & (~0xfff); // 4k aligned, 4k is the page size of flash memory address = fw_img3_addr & (~(FLASH_SECTOR_SIZE-1)); // 4k aligned, 4k is the page size of flash memory
} }
while ((address) < (fw_img3_addr+fw_img3_size)) { while ((address) < (fw_img3_addr+fw_img3_size)) {
DBG_MISC_INFO("Flash Erase: 0x%x\n", address); DBG_MISC_INFO("Flash Erase: %p\n", address);
#if 0 #if 0
if ((address & 0xFFFF) == 0) { if ((address & 0xFFFF) == 0) {
SpicBlockEraseFlashRtl8195A(SPI_FLASH_BASE + address); SpicBlockEraseFlashRtl8195A(SPI_FLASH_BASE + address);
address += 0x10000; // 1 block = 64k bytes address += FLASH_SECTOR_SIZE; // 1 block = 64k bytes
} }
else else
#endif #endif
{ {
SpicSectorEraseFlashRtl8195A(SPI_FLASH_BASE + address); SpicSectorEraseFlashRtl8195A(SPI_FLASH_BASE + address);
address += 0x1000; // 1 sector = 4k bytes address += FLASH_SECTOR_SIZE; // 1 sector = 4k bytes
} }
} }
flash_erased_addr = address; flash_erased_addr = address;
@ -375,7 +401,7 @@ u32 xModem_Frame_ImgAll(char *ptr, unsigned int frame_num, unsigned int frame_s
while (ROM_IMG1_VALID_PATTEN[i] != 0xff) { while (ROM_IMG1_VALID_PATTEN[i] != 0xff) {
if (ptr[i+IMG1_SIGN_OFFSET] != ROM_IMG1_VALID_PATTEN[i]) { if (ptr[i+IMG1_SIGN_OFFSET] != ROM_IMG1_VALID_PATTEN[i]) {
// image1 validation patten miss match // image1 validation patten miss match
DBG_MISC_ERR("xModem_Frame_ImgAll Err: Image1 Signature Incorrect\r\n"); DBG_MISC_ERR("OTU: Image1 Signature Incorrect\n");
fw_img1_size = 0; fw_img1_size = 0;
fw_img2_size = 0; fw_img2_size = 0;
fw_img2_addr = 0; fw_img2_addr = 0;
@ -391,15 +417,15 @@ u32 xModem_Frame_ImgAll(char *ptr, unsigned int frame_num, unsigned int frame_s
flash_wr_offset = 0; flash_wr_offset = 0;
fw_img1_size = rtk_le32_to_cpu(*((u32*)(ptr + 0x10))) + 0x20; fw_img1_size = rtk_le32_to_cpu(*((u32*)(ptr + 0x10))) + 0x20;
if ((fw_img1_size & 0x03) != 0) { /* if ((fw_img1_size & 0x03) != 0) {
DBG_MISC_WARN("xModem_Frame_ImgAll Err: fw_img1_size(0x%x) isn't 4-bytes aligned\r\n", fw_img1_size); DBG_MISC_WARN("OTU: fw_img1_size(0x%x) isn't 4-bytes aligned\n", fw_img1_size);
fw_img1_size = 0; fw_img1_size = 0;
fw_img2_size = 0; fw_img2_size = 0;
fw_img2_addr = 0; fw_img2_addr = 0;
fw_img3_size = 0; fw_img3_size = 0;
fw_img3_addr = 0; fw_img3_addr = 0;
return 0; return 0;
} } */
address = 0; address = 0;
img_size = fw_img1_size; img_size = fw_img1_size;
img_addr = 0; img_addr = 0;
@ -409,11 +435,11 @@ u32 xModem_Frame_ImgAll(char *ptr, unsigned int frame_num, unsigned int frame_s
fw_img2_addr = fw_img1_size; fw_img2_addr = fw_img1_size;
} }
fw_img2_size = 0; fw_img2_size = 0;
DBG_MISC_INFO("Update Image All: Image1 Size=%d, Image2 Addr=0x%x\r\n", fw_img1_size, fw_img2_addr); DBG_MISC_INFO("Update Image All: Image1 Size=%d, Image2 Addr=0x%x\n", fw_img1_size, fw_img2_addr);
} else { } else {
// It's image2(+image3) only // It's image2(+image3) only
if (fw_img2_addr == 0) { if (fw_img2_addr == 0) {
DBG_MISC_WARN("The single-image format in flash now, it cannot just update the image2\r\n"); DBG_MISC_WARN("The single-image format in flash now, it cannot just update the image2\n");
fw_img1_size = 0; fw_img1_size = 0;
fw_img2_size = 0; fw_img2_size = 0;
return rx_len; return rx_len;
@ -423,17 +449,17 @@ u32 xModem_Frame_ImgAll(char *ptr, unsigned int frame_num, unsigned int frame_s
fw_img1_size = 0; fw_img1_size = 0;
fw_img2_size = rtk_le32_to_cpu(*((u32*)ptr)) + 0x10; fw_img2_size = rtk_le32_to_cpu(*((u32*)ptr)) + 0x10;
fw_img3_addr = fw_img2_addr + fw_img2_size; fw_img3_addr = fw_img2_addr + fw_img2_size;
if ((fw_img2_size & 0x03) != 0) { /* if ((fw_img2_size & 0x03) != 0) {
DBG_MISC_ERR("xModem_Frame_ImgAll Err: fw_img2_size(0x%x) isn't 4-bytes aligned\r\n", fw_img2_size); DBG_MISC_ERR("OTU: fw_img2_size(0x%x) isn't 4-bytes aligned\n", fw_img2_size);
fw_img1_size = 0; fw_img1_size = 0;
fw_img2_size = 0; fw_img2_size = 0;
return rx_len; return rx_len;
} } */
address = fw_img2_addr & (~0xfff); // 4k aligned, 4k is the page size of flash memory address = fw_img2_addr & (~0xfff); // 4k aligned, 4k is the page size of flash memory
img_size = fw_img2_size; img_size = fw_img2_size;
img_addr = fw_img2_addr; img_addr = fw_img2_addr;
DBG_MISC_INFO("Update Image2: Addr=0x%x, Size=%d\r\n", fw_img2_addr, fw_img2_size); DBG_MISC_INFO("Update Image2: Addr=0x%x, Size=%d\n", fw_img2_addr, fw_img2_size);
} }
@ -532,15 +558,15 @@ u32 xModem_Frame_ImgAll(char *ptr, unsigned int frame_num, unsigned int frame_s
if (ImgIdx < frame_size) { if (ImgIdx < frame_size) {
fw_img2_size = rtk_le32_to_cpu(*((u32*)(ptr+ImgIdx))) + 0x10; fw_img2_size = rtk_le32_to_cpu(*((u32*)(ptr+ImgIdx))) + 0x10;
fw_img3_addr = fw_img2_addr + fw_img2_size; fw_img3_addr = fw_img2_addr + fw_img2_size;
if ((fw_img2_size & 0x03) != 0) { /* if ((fw_img2_size & 0x03) != 0) {
DBG_MISC_ERR("xModem_Frame_ImgAll Err#2: fw_img2_addr=0x%x fw_img2_size(%d) isn't 4-bytes aligned\r\n", fw_img2_addr, fw_img2_size); DBG_MISC_ERR("OTU: fw_img2_addr=0x%x fw_img2_size(%d) isn't 4-bytes aligned\n", fw_img2_addr, fw_img2_size);
fw_img1_size = 0; fw_img1_size = 0;
fw_img2_size = 0; fw_img2_size = 0;
return rx_len; return rx_len;
} }*/
if (fw_img2_size > (2*1024*1024)) { if (fw_img2_size > (2*1024*1024)) {
DBG_MISC_ERR("xModem_Frame_ImgAll Image2 to Big: fw_img2_addr=0x%x fw_img2_size(%d) \r\n", fw_img2_addr, fw_img2_size); DBG_MISC_ERR("OTU: fw_img2_addr=0x%x fw_img2_size(%d) to Big\n", fw_img2_addr, fw_img2_size);
fw_img1_size = 0; fw_img1_size = 0;
fw_img2_size = 0; fw_img2_size = 0;
return rx_len; return rx_len;
@ -601,17 +627,17 @@ u32 xModem_Frame_ImgAll(char *ptr, unsigned int frame_num, unsigned int frame_s
if (fw_img3_size == 0x1A1A1A1A) { if (fw_img3_size == 0x1A1A1A1A) {
// all padding bytes, no image3 // all padding bytes, no image3
fw_img3_size = 0; fw_img3_size = 0;
// DBG_8195A("No Img3\r\n"); // DBG_8195A("No Img3\n");
return rx_len; return rx_len;
} }
if ((fw_img3_size & 0x03) != 0) { /* if ((fw_img3_size & 0x03) != 0) {
DBG_MISC_ERR("xModem_Frame_ImgAll Err#5: fw_img3_addr=0x%x fw_img3_size(%d) isn't 4-bytes aligned\r\n", fw_img3_addr, fw_img3_size); DBG_MISC_ERR("OTU: fw_img3_addr=0x%x fw_img3_size(%d) isn't 4-bytes aligned\n", fw_img3_addr, fw_img3_size);
fw_img3_size = 0; fw_img3_size = 0;
return rx_len; return rx_len;
} } */
if (fw_img3_size > (2*1024*1024)) { if (fw_img3_size > (2*1024*1024)) {
DBG_MISC_ERR("xModem_Frame_ImgAll Image3 to Big: fw_img3_addr=0x%x fw_img2_size(%d) \r\n", fw_img3_addr, fw_img3_size); DBG_MISC_ERR("OTU: fw_img3_addr=0x%x fw_img2_size(%d) to Big!\n", fw_img3_addr, fw_img3_size);
fw_img3_size = 0; fw_img3_size = 0;
return rx_len; return rx_len;
} }
@ -678,14 +704,14 @@ xModem_Init_UART_Port(u8 uart_idx, u8 pin_mux, u32 baud_rate)
xmodem_uart_func_hook(&(xMCtrl.ComPort)); xmodem_uart_func_hook(&(xMCtrl.ComPort));
} else if(uart_idx == XMODEM_LOG_UART) { } else if(uart_idx == XMODEM_LOG_UART) {
// update firmware via Log UART // update firmware via Log UART
// DiagPrintf("Open xModem Transfer on Log UART...\r\n"); // DiagPrintf("Open xModem Transfer on Log UART...\n");
// xmodem_loguart_init(); // xmodem_loguart_init();
xmodem_loguart_init(baud_rate); xmodem_loguart_init(baud_rate);
xmodem_loguart_func_hook(&(xMCtrl.ComPort)); xmodem_loguart_func_hook(&(xMCtrl.ComPort));
// DiagPrintf("Please Start the xModem Sender...\r\n"); // DiagPrintf("Please Start the xModem Sender...\n");
} else { } else {
// invalid UART port // invalid UART port
DBG_MISC_ERR("xModem_Init_UART_Port: Invaild UART port(%d)\n", uart_idx); DBG_MISC_ERR("OTU: Invaild UART port(%d)\n", uart_idx);
return -1; return -1;
} }
@ -883,25 +909,32 @@ void OTU_FW_Update(u8 uart_idx, u8 pin_mux, u32 baud_rate)
flash_erased_addr = 0; flash_erased_addr = 0;
start_with_img1 = 0;; start_with_img1 = 0;;
flash_wr_err_cnt = 0; flash_wr_err_cnt = 0;
xMFrameBuf = malloc(XM_BUFFER_SIZE);
if(xMFrameBuf == NULL) {
DBG_MISC_ERR("OTU: SPI Init Fail!\n");
return;
}
// Get the address of the image2 to be updated #if USE_FLASH_API
device_mutex_lock(RT_DEV_LOCK_FLASH);
#endif
SPI_FLASH_PIN_FCTRL(ON); SPI_FLASH_PIN_FCTRL(ON);
if (!SpicFlashInitRtl8195A(SpicOneBitMode)){ if (!SpicFlashInitRtl8195A(SpicOneBitMode)){
SPI_FLASH_PIN_FCTRL(OFF); SPI_FLASH_PIN_FCTRL(OFF);
DBG_MISC_ERR("OTU_FW_Update: SPI Init Fail!!!!!!\n"); DBG_MISC_ERR("OTU: SPI Init Fail!\n");
return; goto end_error;
} }
SpicWaitWipDoneRefinedRtl8195A(SpicInitPara); SpicWaitWipDoneRefinedRtl8195A(SpicInitPara);
printf("FW Update Over UART%d, PinMux=%d, Baud=%d\n", uart_idx, pin_mux, baud_rate);
printf("FW Update Over UART%d, PinMux=%d, Baud=%d\r\n", uart_idx, pin_mux, baud_rate); // Get the address of the image2 to be updated
fw_img2_addr = SelectImg2ToUpdate(&OldImage2Addr); fw_img2_addr = SelectImg2ToUpdate(&OldImage2Addr);
// Start to update the Image2 through xModem on peripheral device // Start to update the Image2 through xModem on peripheral device
printf("FW Update Image2 @ 0x%x\r\n", fw_img2_addr); printf("FW Update Image2 @ 0x%x\n", fw_img2_addr);
// We update the image via xModem on UART now, if we want to uase other peripheral device // We update the image via xModem on UART now, if we want to uase other peripheral device
// to update the image then we need to redefine the API // to update the image then we need to redefine the API
if (xModem_Init_UART_Port(uart_idx, pin_mux, baud_rate) < 0) { if (xModem_Init_UART_Port(uart_idx, pin_mux, baud_rate) < 0) {
return; goto end_error;
} }
// xModemStart(&xMCtrl, xMFrameBuf, xModem_Frame_ImgAll); // Support Image format: Image1+Image2 or Image2 only // xModemStart(&xMCtrl, xMFrameBuf, xModem_Frame_ImgAll); // Support Image format: Image1+Image2 or Image2 only
@ -918,13 +951,21 @@ void OTU_FW_Update(u8 uart_idx, u8 pin_mux, u32 baud_rate)
#ifdef CONFIG_UPDATE_TOGGLE_IMG2 #ifdef CONFIG_UPDATE_TOGGLE_IMG2
// Mark the other image2 as old one by modify its signature // Mark the other image2 as old one by modify its signature
if (OldImage2Addr != 0) { if (OldImage2Addr != 0) {
printf("Mark Image2 @ 0x%x as Old\r\n", OldImage2Addr); printf("Mark Image2 @ 0x%x as Old\n", OldImage2Addr);
MarkImg2SignOld(OldImage2Addr); MarkImg2SignOld(OldImage2Addr);
} }
#endif #endif
} }
printf("OTU_FW_Update Done, Write Len=%d\n", wr_len); printf("OTU_FW_Update Done, Write Len=%d\n", wr_len);
end_error:
SPI_FLASH_PIN_FCTRL(OFF); SPI_FLASH_PIN_FCTRL(OFF);
#if USE_FLASH_API
device_mutex_unlock(RT_DEV_LOCK_FLASH);
#endif
if(xMFrameBuf) {
free(xMFrameBuf);
xMFrameBuf = NULL;
}
} }
FWU_TEXT_SECTION FWU_TEXT_SECTION
@ -934,7 +975,7 @@ u8 OTU_check_gpio(void)
HAL_GPIO_PIN GPIO_Pin; HAL_GPIO_PIN GPIO_Pin;
u8 enter_update; u8 enter_update;
GPIO_Pin.pin_name = HAL_GPIO_GetIPPinName_8195a(0x21);; //pin PC_1 GPIO_Pin.pin_name = HAL_GPIO_GetIPPinName_8195a(0x21); //pin PC_1
GPIO_Pin.pin_mode = DIN_PULL_HIGH; GPIO_Pin.pin_mode = DIN_PULL_HIGH;
_pHAL_Gpio_Adapter = &gBoot_Gpio_Adapter; _pHAL_Gpio_Adapter = &gBoot_Gpio_Adapter;
@ -1033,8 +1074,12 @@ void OTU_Img_Download(u8 uart_idx, u8 pin_mux, u32 baud_rate,
if (xModem_Init_UART_Port(uart_idx, pin_mux, baud_rate) < 0) { if (xModem_Init_UART_Port(uart_idx, pin_mux, baud_rate) < 0) {
return; return;
} }
if(xMFrameBuf == NULL) {
DBG_MISC_ERR("OTU: SPI Init Fail!\n");
return;
}
DBG_MISC_INFO("Image Download: StartOffset=%d StartAddr=0x%x MaxSize=%d\r\n", start_offset, start_addr, max_size); DBG_MISC_INFO("Image Download: StartOffset=%d StartAddr=0x%x MaxSize=%d\n", start_offset, start_addr, max_size);
fw_img2_addr = start_addr; fw_img2_addr = start_addr;
flash_wr_offset = start_offset; flash_wr_offset = start_offset;
@ -1043,17 +1088,20 @@ void OTU_Img_Download(u8 uart_idx, u8 pin_mux, u32 baud_rate,
if ((start_addr & 0xFF000000) == SPI_FLASH_BASE) { if ((start_addr & 0xFF000000) == SPI_FLASH_BASE) {
// it's going to write the Flash memory // it's going to write the Flash memory
if (((start_addr & 0x03) != 0) || ((start_offset&0x03) != 0)) { if (((start_addr & 0x03) != 0) || ((start_offset&0x03) != 0)) {
DiagPrintf("StartAddr(0x%x), StartOffset(0x%x) Must 4-bytes Aligned\r\n", start_addr, start_offset); DiagPrintf("StartAddr(0x%x), StartOffset(0x%x) Must 4-bytes Aligned\n", start_addr, start_offset);
return; return;
} }
#if USE_FLASH_API
device_mutex_lock(RT_DEV_LOCK_FLASH);
#endif
SPI_FLASH_PIN_FCTRL(ON); SPI_FLASH_PIN_FCTRL(ON);
if (!SpicFlashInitRtl8195A(SpicOneBitMode)){ if (!SpicFlashInitRtl8195A(SpicOneBitMode)){
DBG_MISC_ERR("OTU_FW_Update: SPI Init Fail!!!!!!\n"); DBG_MISC_ERR("OTU: SPI Init Fail!\n");
SPI_FLASH_PIN_FCTRL(OFF); SPI_FLASH_PIN_FCTRL(OFF);
return; goto end_error;
} }
is_flash = 1;
SpicWaitWipDoneRefinedRtl8195A(SpicInitPara); SpicWaitWipDoneRefinedRtl8195A(SpicInitPara);
is_flash = 1;
fw_img2_addr = start_addr & 0x00FFFFFF; fw_img2_addr = start_addr & 0x00FFFFFF;
xModemStart(&xMCtrl, xMFrameBuf, xModem_Frame_FlashWrite); xModemStart(&xMCtrl, xMFrameBuf, xModem_Frame_FlashWrite);
} else { } else {
@ -1065,9 +1113,16 @@ void OTU_Img_Download(u8 uart_idx, u8 pin_mux, u32 baud_rate,
xModem_DeInit_UART_Port(uart_idx); xModem_DeInit_UART_Port(uart_idx);
DBG_MISC_INFO("OTU_Img_Download Done, Write Len=%d\n", wr_len); DBG_MISC_INFO("OTU_Img_Download Done, Write Len=%d\n", wr_len);
end_error:
if (is_flash) { if (is_flash) {
SPI_FLASH_PIN_FCTRL(OFF); SPI_FLASH_PIN_FCTRL(OFF);
#if USE_FLASH_API
device_mutex_unlock(RT_DEV_LOCK_FLASH);
#endif
}
if(xMFrameBuf) {
free(xMFrameBuf);
xMFrameBuf = NULL;
} }
} }

View file

@ -103,16 +103,16 @@ static void update_ota_local_task(void *param)
#if CONFIG_WRITE_MAC_TO_FLASH #if CONFIG_WRITE_MAC_TO_FLASH
char mac[ETH_ALEN]; char mac[ETH_ALEN];
#endif #endif
printf("\n\r[%s] Update task start", __FUNCTION__); printf("[%s] Update task start\n", __FUNCTION__);
buf = update_malloc(BUF_SIZE); buf = update_malloc(BUF_SIZE);
if(!buf){ if(!buf){
printf("\n\r[%s] Alloc buffer failed", __FUNCTION__); printf("[%s] Alloc buffer failed\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
// Connect socket // Connect socket
server_socket = socket(AF_INET, SOCK_STREAM, 0); server_socket = socket(AF_INET, SOCK_STREAM, 0);
if(server_socket < 0){ if(server_socket < 0){
printf("\n\r[%s] Create socket failed", __FUNCTION__); printf("[%s] Create socket failed\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
server_addr.sin_family = AF_INET; server_addr.sin_family = AF_INET;
@ -120,52 +120,52 @@ static void update_ota_local_task(void *param)
server_addr.sin_port = cfg->port; server_addr.sin_port = cfg->port;
if(connect(server_socket, (struct sockaddr *)&server_addr, sizeof(server_addr)) == -1){ if(connect(server_socket, (struct sockaddr *)&server_addr, sizeof(server_addr)) == -1){
printf("\n\r[%s] socket connect failed", __FUNCTION__); printf("[%s] socket connect failed\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
// Erase config sectors // Erase config sectors
if(flash_EraseSector(CONFIG_SECTOR) < 0){ if(flash_EraseSector(CONFIG_SECTOR) < 0){
printf("\n\r[%s] Erase sector failed", __FUNCTION__); printf("[%s] Erase sector failed\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
#if CONFIG_WRITE_MAC_TO_FLASH #if CONFIG_WRITE_MAC_TO_FLASH
// Read MAC address // Read MAC address
if(flash_Read(FLASH_ADD_STORE_MAC, mac, ETH_ALEN) < 0){ if(flash_Read(FLASH_ADD_STORE_MAC, mac, ETH_ALEN) < 0){
printf("\n\r[%s] Read MAC error", __FUNCTION__); printf("[%s] Read MAC error\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
#endif #endif
// Erase update sectors // Erase update sectors
for(i = UPDATE_SECTOR; i <= FLASH_Sector_11; i += 8){ for(i = UPDATE_SECTOR; i <= FLASH_Sector_11; i += 8){
if(flash_EraseSector(i) < 0){ if(flash_EraseSector(i) < 0){
printf("\n\r[%s] Erase sector failed", __FUNCTION__); printf("[%s] Erase sector failed\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
} }
// Write update sectors // Write update sectors
address = flash_SectorAddress(UPDATE_SECTOR); address = flash_SectorAddress(UPDATE_SECTOR);
printf("\n\r"); printf("\n");
while(1){ while(1){
read_bytes = read(server_socket, buf, BUF_SIZE); read_bytes = read(server_socket, buf, BUF_SIZE);
if(read_bytes == 0) break; // Read end if(read_bytes == 0) break; // Read end
if(read_bytes < 0){ if(read_bytes < 0){
printf("\n\r[%s] Read socket failed", __FUNCTION__); printf("[%s] Read socket failed\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
if(flash_Wrtie(address + size, buf, read_bytes) < 0){ if(flash_Wrtie(address + size, buf, read_bytes) < 0){
printf("\n\r[%s] Write sector failed", __FUNCTION__); printf("[%s] Write sector failed\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
size += read_bytes; size += read_bytes;
for(i = 0; i < read_bytes; i ++) for(i = 0; i < read_bytes; i ++)
checksum += buf[i]; checksum += buf[i];
printf("\rUpdate file size = %d ", size); printf("Update file size = %d\n", size);
} }
#if CONFIG_WRITE_MAC_TO_FLASH #if CONFIG_WRITE_MAC_TO_FLASH
//Write MAC address //Write MAC address
if(!(mac[0]==0xff&&mac[1]==0xff&&mac[2]==0xff&&mac[3]==0xff&&mac[4]==0xff&&mac[5]==0xff)){ if(!(mac[0]==0xff&&mac[1]==0xff&&mac[2]==0xff&&mac[3]==0xff&&mac[4]==0xff&&mac[5]==0xff)){
if(flash_Wrtie(FLASH_ADD_STORE_MAC, mac, ETH_ALEN) < 0){ if(flash_Wrtie(FLASH_ADD_STORE_MAC, mac, ETH_ALEN) < 0){
printf("\n\r[%s] Write MAC failed", __FUNCTION__); printf("[%s] Write MAC failed\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
} }
@ -174,10 +174,10 @@ static void update_ota_local_task(void *param)
address = flash_SectorAddress(CONFIG_SECTOR); address = flash_SectorAddress(CONFIG_SECTOR);
if( (flash_Wrtie(address, (char*)&size, 4) < 0) || if( (flash_Wrtie(address, (char*)&size, 4) < 0) ||
(flash_Wrtie(address+4, (char*)&checksum, 4) < 0) ){ (flash_Wrtie(address+4, (char*)&checksum, 4) < 0) ){
printf("\n\r[%s] Write sector failed", __FUNCTION__); printf("[%s] Write sector failed\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
printf("\n\r[%s] Update OTA success!", __FUNCTION__); printf("[%s] Update OTA success!\n", __FUNCTION__);
update_ota_exit: update_ota_exit:
if(buf) if(buf)
update_free(buf); update_free(buf);
@ -186,7 +186,7 @@ update_ota_exit:
if(param) if(param)
update_free(param); update_free(param);
TaskOTA = NULL; TaskOTA = NULL;
printf("\n\r[%s] Update task exit", __FUNCTION__); printf("[%s] Update task exit\n", __FUNCTION__);
vTaskDelete(NULL); vTaskDelete(NULL);
return; return;
} }
@ -204,16 +204,16 @@ static void update_ota_local_task(void *param)
char mac[ETH_ALEN]; char mac[ETH_ALEN];
#endif #endif
printf("\n\r[%s] Update task start", __FUNCTION__); printf("[%s] Update task start\n", __FUNCTION__);
buf = update_malloc(BUF_SIZE); buf = update_malloc(BUF_SIZE);
if(!buf){ if(!buf){
printf("\n\r[%s] Alloc buffer failed", __FUNCTION__); printf("[%s] Alloc buffer failed\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
// Connect socket // Connect socket
server_socket = socket(AF_INET, SOCK_STREAM, 0); server_socket = socket(AF_INET, SOCK_STREAM, 0);
if(server_socket < 0){ if(server_socket < 0){
printf("\n\r[%s] Create socket failed", __FUNCTION__); printf("[%s] Create socket failed\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
server_addr.sin_family = AF_INET; server_addr.sin_family = AF_INET;
@ -221,20 +221,20 @@ static void update_ota_local_task(void *param)
server_addr.sin_port = cfg->port; server_addr.sin_port = cfg->port;
if(connect(server_socket, (struct sockaddr *)&server_addr, sizeof(server_addr)) == -1){ if(connect(server_socket, (struct sockaddr *)&server_addr, sizeof(server_addr)) == -1){
printf("\n\r[%s] socket connect failed", __FUNCTION__); printf("[%s] socket connect failed\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
// Erase config sectors // Erase config sectors
for(i = CONFIG_SECTOR; i < APPLICATION_SECTOR; i += FLASH_PAGE_SIZE){ for(i = CONFIG_SECTOR; i < APPLICATION_SECTOR; i += FLASH_PAGE_SIZE){
if(flash_EraseSector(i) < 0){ if(flash_EraseSector(i) < 0){
printf("\n\r[%s] Erase sector failed", __FUNCTION__); printf("[%s] Erase sector failed\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
} }
#if CONFIG_WRITE_MAC_TO_FLASH #if CONFIG_WRITE_MAC_TO_FLASH
// Read MAC address // Read MAC address
if(flash_Read(FLASH_ADD_STORE_MAC, mac, ETH_ALEN) < 0){ if(flash_Read(FLASH_ADD_STORE_MAC, mac, ETH_ALEN) < 0){
printf("\n\r[%s] Read MAC error", __FUNCTION__); printf("[%s] Read MAC error\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
#endif #endif
@ -242,18 +242,18 @@ static void update_ota_local_task(void *param)
// Erase update sectors // Erase update sectors
for(i = UPDATE_SECTOR; i < FLASH_Sector_0 + FLASH_SIZE; i += FLASH_PAGE_SIZE){ for(i = UPDATE_SECTOR; i < FLASH_Sector_0 + FLASH_SIZE; i += FLASH_PAGE_SIZE){
if(flash_EraseSector(i) < 0){ if(flash_EraseSector(i) < 0){
printf("\n\r[%s] Erase sector failed", __FUNCTION__); printf("[%s] Erase sector failed\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
} }
// Write update sectors // Write update sectors
address = UPDATE_SECTOR; address = UPDATE_SECTOR;
printf("\n\r"); printf("\n");
while(1){ while(1){
read_bytes = read(server_socket, buf, BUF_SIZE); read_bytes = read(server_socket, buf, BUF_SIZE);
if(read_bytes == 0) break; // Read end if(read_bytes == 0) break; // Read end
if(read_bytes < 0){ if(read_bytes < 0){
printf("\n\r[%s] Read socket failed", __FUNCTION__); printf("[%s] Read socket failed\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
if(flag_a == 0){ if(flag_a == 0){
@ -261,14 +261,14 @@ static void update_ota_local_task(void *param)
a = buf[read_bytes - 1]; a = buf[read_bytes - 1];
flag_a = 1; flag_a = 1;
if(flash_Wrtie(address + size, buf, read_bytes - 1) < 0){ if(flash_Wrtie(address + size, buf, read_bytes - 1) < 0){
printf("\n\r[%s] Write sector failed", __FUNCTION__); printf("[%s] Write sector failed\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
size += read_bytes - 1; size += read_bytes - 1;
} }
else{ else{
if(flash_Wrtie(address + size, buf, read_bytes) < 0){ if(flash_Wrtie(address + size, buf, read_bytes) < 0){
printf("\n\r[%s] Write sector failed", __FUNCTION__); printf("[%s] Write sector failed\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
size += read_bytes; size += read_bytes;
@ -277,7 +277,7 @@ static void update_ota_local_task(void *param)
else{ else{
a = buf[0] << 8 | a; a = buf[0] << 8 | a;
if(flash_Wrtie(address + size, (char*)(&a), 2) < 0){ if(flash_Wrtie(address + size, (char*)(&a), 2) < 0){
printf("\n\r[%s] Write sector failed", __FUNCTION__); printf("[%s] Write sector failed\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
size += 2; size += 2;
@ -287,14 +287,14 @@ static void update_ota_local_task(void *param)
a = buf[read_bytes - 1]; a = buf[read_bytes - 1];
flag_a = 1; flag_a = 1;
if(flash_Wrtie(address + size, buf + 1, read_bytes - 2) < 0){ if(flash_Wrtie(address + size, buf + 1, read_bytes - 2) < 0){
printf("\n\r[%s] Write sector failed", __FUNCTION__); printf("[%s] Write sector failed\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
size += read_bytes - 2; size += read_bytes - 2;
} }
else{ else{
if(flash_Wrtie(address + size, buf + 1, read_bytes - 1) < 0){ if(flash_Wrtie(address + size, buf + 1, read_bytes - 1) < 0){
printf("\n\r[%s] Write sector failed", __FUNCTION__); printf("[%s] Write sector failed\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
size += read_bytes - 1; size += read_bytes - 1;
@ -302,11 +302,11 @@ static void update_ota_local_task(void *param)
} }
for(i = 0; i < read_bytes; i ++) for(i = 0; i < read_bytes; i ++)
checksum += buf[i]; checksum += buf[i];
printf("\rUpdate file size = %d ", size); printf("Update file size = %d\n", size);
} }
if(flag_a){ if(flag_a){
if(flash_Wrtie(address + size, (char*)(&a), 2) < 0){ if(flash_Wrtie(address + size, (char*)(&a), 2) < 0){
printf("\n\r[%s] Write sector failed", __FUNCTION__); printf("[%s] Write sector failed", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
size += 1; size += 1;
@ -315,7 +315,7 @@ static void update_ota_local_task(void *param)
//Write MAC address //Write MAC address
if(!(mac[0]==0xff&&mac[1]==0xff&&mac[2]==0xff&&mac[3]==0xff&&mac[4]==0xff&&mac[5]==0xff)){ if(!(mac[0]==0xff&&mac[1]==0xff&&mac[2]==0xff&&mac[3]==0xff&&mac[4]==0xff&&mac[5]==0xff)){
if(flash_Wrtie(FLASH_ADD_STORE_MAC, mac, ETH_ALEN) < 0){ if(flash_Wrtie(FLASH_ADD_STORE_MAC, mac, ETH_ALEN) < 0){
printf("\n\r[%s] Write MAC failed", __FUNCTION__); printf("[%s] Write MAC failed\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
} }
@ -325,10 +325,10 @@ static void update_ota_local_task(void *param)
address = CONFIG_SECTOR; address = CONFIG_SECTOR;
if( (flash_Wrtie(address, (char*)&size, 4) < 0) || if( (flash_Wrtie(address, (char*)&size, 4) < 0) ||
(flash_Wrtie(address+4, (char*)&checksum, 4) < 0) ){ (flash_Wrtie(address+4, (char*)&checksum, 4) < 0) ){
printf("\n\r[%s] Write sector failed", __FUNCTION__); printf("[%s] Write sector failed\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
printf("\n\r[%s] Update OTA success!", __FUNCTION__); printf("[%s] Update OTA success!\n", __FUNCTION__);
update_ota_exit: update_ota_exit:
if(buf) if(buf)
update_free(buf); update_free(buf);
@ -337,7 +337,7 @@ update_ota_exit:
if(param) if(param)
update_free(param); update_free(param);
TaskOTA = NULL; TaskOTA = NULL;
printf("\n\r[%s] Update task exit", __FUNCTION__); printf("[%s] Update task exit\n", __FUNCTION__);
vTaskDelete(NULL); vTaskDelete(NULL);
return; return;
} }
@ -367,7 +367,7 @@ int write_ota_addr_to_system_data(flash_t *flash, uint32_t ota_addr)
//Get upgraded image 2 addr from offset //Get upgraded image 2 addr from offset
device_mutex_lock(RT_DEV_LOCK_FLASH); device_mutex_lock(RT_DEV_LOCK_FLASH);
flash_read_word(flash, OFFSET_DATA, &data); flash_read_word(flash, OFFSET_DATA, &data);
printf("\n\r[%s] data 0x%x ota_addr 0x%x", __FUNCTION__, data, ota_addr); printf("[%s] data 0x%x ota_addr 0x%x\n", __FUNCTION__, data, ota_addr);
if(data == ~0x0){ if(data == ~0x0){
flash_write_word(flash, OFFSET_DATA, ota_addr); flash_write_word(flash, OFFSET_DATA, ota_addr);
}else{ }else{
@ -413,19 +413,19 @@ static void update_ota_local_task(void *param)
uint32_t ota_addr = 0x80000; uint32_t ota_addr = 0x80000;
#endif #endif
#if CONFIG_CUSTOM_SIGNATURE #if CONFIG_CUSTOM_SIGNATURE
char custom_sig[32] = "Customer Signature-modelxxx"; char custom_sig[32] = "Customer Signature-modelxxx\n";
uint32_t read_custom_sig[8]; uint32_t read_custom_sig[8];
#endif #endif
printf("\n\r[%s] Update task start", __FUNCTION__); printf("[%s] Update task start\n", __FUNCTION__);
buf = update_malloc(BUF_SIZE); buf = update_malloc(BUF_SIZE);
if(!buf){ if(!buf){
printf("\n\r[%s] Alloc buffer failed", __FUNCTION__); printf("[%s] Alloc buffer failed\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
// Connect socket // Connect socket
server_socket = socket(AF_INET, SOCK_STREAM, 0); server_socket = socket(AF_INET, SOCK_STREAM, 0);
if(server_socket < 0){ if(server_socket < 0){
printf("\n\r[%s] Create socket failed", __FUNCTION__); printf("[%s] Create socket failed\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
server_addr.sin_family = AF_INET; server_addr.sin_family = AF_INET;
@ -433,7 +433,7 @@ static void update_ota_local_task(void *param)
server_addr.sin_port = cfg->port; server_addr.sin_port = cfg->port;
if(connect(server_socket, (struct sockaddr *)&server_addr, sizeof(server_addr)) == -1){ if(connect(server_socket, (struct sockaddr *)&server_addr, sizeof(server_addr)) == -1){
printf("\n\r[%s] socket connect failed", __FUNCTION__); printf("[%s] socket connect failed\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
DBG_INFO_MSG_OFF(_DBG_SPI_FLASH_); DBG_INFO_MSG_OFF(_DBG_SPI_FLASH_);
@ -447,9 +447,9 @@ static void update_ota_local_task(void *param)
flash_read_word(&flash, IMAGE_x+4, &ImgxAddr); flash_read_word(&flash, IMAGE_x+4, &ImgxAddr);
device_mutex_unlock(RT_DEV_LOCK_FLASH); device_mutex_unlock(RT_DEV_LOCK_FLASH);
if(ImgxAddr==0x30000000){ if(ImgxAddr==0x30000000){
printf("\n\r[%s] IMAGE_3 0x%x Img3Len 0x%x", __FUNCTION__, IMAGE_x, ImgxLen); printf("[%s] IMAGE_3 0x%x Img3Len 0x%x\n", __FUNCTION__, IMAGE_x, ImgxLen);
}else{ }else{
printf("\n\r[%s] no IMAGE_3", __FUNCTION__); printf("[%s] no IMAGE_3\n", __FUNCTION__);
// no image3 // no image3
IMAGE_x = IMAGE_2; IMAGE_x = IMAGE_2;
ImgxLen = Img2Len; ImgxLen = Img2Len;
@ -459,7 +459,7 @@ static void update_ota_local_task(void *param)
(ota_addr < IMAGE_x) || (ota_addr < IMAGE_x) ||
((ota_addr & 0xfff) != 0)|| ((ota_addr & 0xfff) != 0)||
(ota_addr == ~0x0)){ (ota_addr == ~0x0)){
printf("\n\r[%s] illegal ota addr 0x%x", __FUNCTION__, ota_addr); printf("[%s] illegal ota addr 0x%x\n", __FUNCTION__, ota_addr);
goto update_ota_exit; goto update_ota_exit;
}else }else
write_ota_addr_to_system_data( &flash, ota_addr); write_ota_addr_to_system_data( &flash, ota_addr);
@ -472,7 +472,7 @@ static void update_ota_local_task(void *param)
(NewImg2Addr < IMAGE_x) || (NewImg2Addr < IMAGE_x) ||
((NewImg2Addr & 0xfff) != 0)|| ((NewImg2Addr & 0xfff) != 0)||
(NewImg2Addr == ~0x0)){ (NewImg2Addr == ~0x0)){
printf("\n\r[%s] Invalid OTA Address 0x%x", __FUNCTION__, NewImg2Addr); printf("[%s] Invalid OTA Address 0x%x\n", __FUNCTION__, NewImg2Addr);
goto update_ota_exit; goto update_ota_exit;
} }
#else #else
@ -484,15 +484,15 @@ static void update_ota_local_task(void *param)
memset(file_info, 0, sizeof(file_info)); memset(file_info, 0, sizeof(file_info));
if(file_info[0] == 0){ if(file_info[0] == 0){
printf("\n\r[%s] Read info first", __FUNCTION__); printf("[%s] Read info first\n", __FUNCTION__);
read_bytes = read(server_socket, file_info, sizeof(file_info)); read_bytes = read(server_socket, file_info, sizeof(file_info));
// !X!X!X!X!X!X!X!X!X!X!X!X!X!X!X!X!X!X!X!X // !X!X!X!X!X!X!X!X!X!X!X!X!X!X!X!X!X!X!X!X
// !W checksum !W padding 0 !W file size !W // !W checksum !W padding 0 !W file size !W
// !X!X!X!X!X!X!X!X!X!X!X!X!X!X!X!X!X!X!X!X // !X!X!X!X!X!X!X!X!X!X!X!X!X!X!X!X!X!X!X!X
printf("\n\r[%s] info %d bytes", __FUNCTION__, read_bytes); printf("[%s] info %d bytes", __FUNCTION__, read_bytes);
printf("\n\r[%s] tx chechsum 0x%x, file size 0x%x", __FUNCTION__, file_info[0],file_info[2]); printf("[%s] tx chechsum 0x%x, file size 0x%x\n", __FUNCTION__, file_info[0],file_info[2]);
if(file_info[2] == 0){ if(file_info[2] == 0){
printf("\n\r[%s] No checksum and file size", __FUNCTION__); printf("[%s] No checksum and file size\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
} }
@ -509,7 +509,7 @@ static void update_ota_local_task(void *param)
// read Part1/Part2 signature // read Part1/Part2 signature
flash_read_word(&flash, Part1Addr+8, &SigImage0); flash_read_word(&flash, Part1Addr+8, &SigImage0);
flash_read_word(&flash, Part1Addr+12, &SigImage1); flash_read_word(&flash, Part1Addr+12, &SigImage1);
printf("\n\r[%s] Part1 Sig %x", __FUNCTION__, SigImage0); printf("[%s] Part1 Sig %x\n", __FUNCTION__, SigImage0);
if(SigImage0==0x30303030 && SigImage1==0x30303030) if(SigImage0==0x30303030 && SigImage1==0x30303030)
ATSCAddr = Part1Addr; // ATSC signature ATSCAddr = Part1Addr; // ATSC signature
else if(SigImage0==0x35393138 && SigImage1==0x31313738) else if(SigImage0==0x35393138 && SigImage1==0x31313738)
@ -520,7 +520,7 @@ static void update_ota_local_task(void *param)
flash_read_word(&flash, Part2Addr+8, &SigImage0); flash_read_word(&flash, Part2Addr+8, &SigImage0);
flash_read_word(&flash, Part2Addr+12, &SigImage1); flash_read_word(&flash, Part2Addr+12, &SigImage1);
device_mutex_unlock(RT_DEV_LOCK_FLASH); device_mutex_unlock(RT_DEV_LOCK_FLASH);
printf("\n\r[%s] Part2 Sig %x", __FUNCTION__, SigImage0); printf("[%s] Part2 Sig %x\n", __FUNCTION__, SigImage0);
if(SigImage0==0x30303030 && SigImage1==0x30303030) if(SigImage0==0x30303030 && SigImage1==0x30303030)
ATSCAddr = Part2Addr; // ATSC signature ATSCAddr = Part2Addr; // ATSC signature
else if(SigImage0==0x35393138 && SigImage1==0x31313738) else if(SigImage0==0x35393138 && SigImage1==0x31313738)
@ -534,11 +534,11 @@ static void update_ota_local_task(void *param)
NewImg2Addr = ATSCAddr; NewImg2Addr = ATSCAddr;
} }
printf("\n\r[%s] New %x, Old %x", __FUNCTION__, NewImg2Addr, OldImg2Addr); printf("[%s] New %x, Old %x\n", __FUNCTION__, NewImg2Addr, OldImg2Addr);
if( NewImg2Addr==Part1Addr ){ if( NewImg2Addr==Part1Addr ){
if( file_info[2] > (Part2Addr-Part1Addr) ){ // firmware size too large if( file_info[2] > (Part2Addr-Part1Addr) ){ // firmware size too large
printf("\n\r[%s] Part1 size < OTA size", __FUNCTION__); printf("[%s] Part1 size < OTA size\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
// or update to partition2 // or update to partition2
// NewImg2Addr = Part2Addr; // NewImg2Addr = Part2Addr;
@ -550,46 +550,46 @@ static void update_ota_local_task(void *param)
//Erase upgraded image 2 region //Erase upgraded image 2 region
if(NewImg2Len == 0){ if(NewImg2Len == 0){
NewImg2Len = file_info[2]; NewImg2Len = file_info[2];
printf("\n\r[%s] NewImg2Len %d ", __FUNCTION__, NewImg2Len); printf("[%s] NewImg2Len %d\n", __FUNCTION__, NewImg2Len);
if((int)NewImg2Len > 0){ if((int)NewImg2Len > 0){
NewImg2BlkSize = ((NewImg2Len - 1)/4096) + 1; NewImg2BlkSize = ((NewImg2Len - 1)/4096) + 1;
printf("\n\r[%s] NewImg2BlkSize %d 0x%8x", __FUNCTION__, NewImg2BlkSize, NewImg2BlkSize); printf("[%s] NewImg2BlkSize %d 0x%8x\n", __FUNCTION__, NewImg2BlkSize, NewImg2BlkSize);
device_mutex_lock(RT_DEV_LOCK_FLASH); device_mutex_lock(RT_DEV_LOCK_FLASH);
for( i = 0; i < NewImg2BlkSize; i++) for( i = 0; i < NewImg2BlkSize; i++)
flash_erase_sector(&flash, NewImg2Addr + i * 4096); flash_erase_sector(&flash, NewImg2Addr + i * 4096);
device_mutex_unlock(RT_DEV_LOCK_FLASH); device_mutex_unlock(RT_DEV_LOCK_FLASH);
}else{ }else{
printf("\n\r[%s] Size INVALID", __FUNCTION__); printf("[%s] Size INVALID\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
} }
printf("\n\r[%s] NewImg2Addr 0x%x", __FUNCTION__, NewImg2Addr); printf("[%s] NewImg2Addr 0x%x\n", __FUNCTION__, NewImg2Addr);
// reset // reset
file_checksum.u = 0; file_checksum.u = 0;
// Write New Image 2 sector // Write New Image 2 sector
if(NewImg2Addr != ~0x0){ if(NewImg2Addr != ~0x0){
address = NewImg2Addr; address = NewImg2Addr;
printf("\n\r"); printf("");
while(1){ while(1){
memset(buf, 0, BUF_SIZE); memset(buf, 0, BUF_SIZE);
read_bytes = read(server_socket, buf, BUF_SIZE); read_bytes = read(server_socket, buf, BUF_SIZE);
if(read_bytes == 0) break; // Read end if(read_bytes == 0) break; // Read end
if(read_bytes < 0){ if(read_bytes < 0){
printf("\n\r[%s] Read socket failed", __FUNCTION__); printf("[%s] Read socket failed\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
checksum += file_checksum.c[0]; // not read end, this is not attached checksum checksum += file_checksum.c[0]; // not read end, this is not attached checksum
checksum += file_checksum.c[1]; checksum += file_checksum.c[1];
checksum += file_checksum.c[2]; checksum += file_checksum.c[2];
checksum += file_checksum.c[3]; checksum += file_checksum.c[3];
//printf("\n\r[%s] read_bytes %d", __FUNCTION__, read_bytes); //printf("[%s] read_bytes %d", __FUNCTION__, read_bytes);
#if 1 #if 1
device_mutex_lock(RT_DEV_LOCK_FLASH); device_mutex_lock(RT_DEV_LOCK_FLASH);
if(flash_stream_write(&flash, address + size, read_bytes, buf) < 0){ if(flash_stream_write(&flash, address + size, read_bytes, buf) < 0){
printf("\n\r[%s] Write sector failed", __FUNCTION__); printf("[%s] Write sector failed\n", __FUNCTION__);
device_mutex_unlock(RT_DEV_LOCK_FLASH); device_mutex_unlock(RT_DEV_LOCK_FLASH);
goto update_ota_exit; goto update_ota_exit;
} }
@ -615,7 +615,7 @@ static void update_ota_local_task(void *param)
if(size == NewImg2Len) if(size == NewImg2Len)
break; break;
} }
printf("\n\r"); printf("\n");
// read flash data back and calculate checksum // read flash data back and calculate checksum
for(i=0;i<size-4;i+=BUF_SIZE){ for(i=0;i<size-4;i+=BUF_SIZE){
@ -626,27 +626,27 @@ static void update_ota_local_task(void *param)
flash_checksum+=buf[k]; flash_checksum+=buf[k];
} }
printf("\n\rUpdate file size = %d checksum 0x%8x flash checksum 0x%8x attached checksum 0x%8x", size, checksum, flash_checksum, file_checksum.u); printf("Update file size = %d checksum 0x%8x flash checksum 0x%8x attached checksum 0x%8x\n", size, checksum, flash_checksum, file_checksum.u);
#if CONFIG_WRITE_MAC_TO_FLASH #if CONFIG_WRITE_MAC_TO_FLASH
//Write MAC address //Write MAC address
if(!(mac[0]==0xff&&mac[1]==0xff&&mac[2]==0xff&&mac[3]==0xff&&mac[4]==0xff&&mac[5]==0xff)){ if(!(mac[0]==0xff&&mac[1]==0xff&&mac[2]==0xff&&mac[3]==0xff&&mac[4]==0xff&&mac[5]==0xff)){
device_mutex_lock(RT_DEV_LOCK_FLASH); device_mutex_lock(RT_DEV_LOCK_FLASH);
if(flash_write_word(&flash, FLASH_ADD_STORE_MAC, mac, ETH_ALEN) < 0){ if(flash_write_word(&flash, FLASH_ADD_STORE_MAC, mac, ETH_ALEN) < 0){
printf("\n\r[%s] Write MAC failed", __FUNCTION__); printf("[%s] Write MAC failed\n", __FUNCTION__);
device_mutex_unlock(RT_DEV_LOCK_FLASH); device_mutex_unlock(RT_DEV_LOCK_FLASH);
goto update_ota_exit; goto update_ota_exit;
} }
device_mutex_unlock(RT_DEV_LOCK_FLASH); device_mutex_unlock(RT_DEV_LOCK_FLASH);
} }
#endif #endif
//printf("\n\r checksum 0x%x file_info 0x%x ", checksum, *(file_info)); //printf(" checksum 0x%x file_info 0x%x ", checksum, *(file_info));
#if CONFIG_CUSTOM_SIGNATURE #if CONFIG_CUSTOM_SIGNATURE
device_mutex_lock(RT_DEV_LOCK_FLASH); device_mutex_lock(RT_DEV_LOCK_FLASH);
for(i = 0; i < 8; i ++){ for(i = 0; i < 8; i ++){
flash_read_word(&flash, NewImg2Addr + 0x28 + i *4, read_custom_sig + i); flash_read_word(&flash, NewImg2Addr + 0x28 + i *4, read_custom_sig + i);
} }
device_mutex_unlock(RT_DEV_LOCK_FLASH); device_mutex_unlock(RT_DEV_LOCK_FLASH);
printf("\n\r[%s] read_custom_sig %s", __FUNCTION__ , (char*)read_custom_sig); printf("[%s] read_custom_sig %s\n", __FUNCTION__ , (char*)read_custom_sig);
#endif #endif
// compare checksum with received checksum // compare checksum with received checksum
//if(!memcmp(&checksum,file_info,sizeof(checksum)) //if(!memcmp(&checksum,file_info,sizeof(checksum))
@ -659,24 +659,24 @@ static void update_ota_local_task(void *param)
//Set signature in New Image 2 addr + 8 and + 12 //Set signature in New Image 2 addr + 8 and + 12
uint32_t sig_readback0,sig_readback1; uint32_t sig_readback0,sig_readback1;
device_mutex_lock(RT_DEV_LOCK_FLASH); device_mutex_lock(RT_DEV_LOCK_FLASH);
flash_write_word(&flash,NewImg2Addr + 8, 0x35393138); flash_write_word(&flash,NewImg2Addr + 8, IMG_SIGN1_RUN);
flash_write_word(&flash,NewImg2Addr + 12, 0x31313738); flash_write_word(&flash,NewImg2Addr + 12, IMG_SIGN2_RUN);
flash_read_word(&flash, NewImg2Addr + 8, &sig_readback0); flash_read_word(&flash, NewImg2Addr + 8, &sig_readback0);
flash_read_word(&flash, NewImg2Addr + 12, &sig_readback1); flash_read_word(&flash, NewImg2Addr + 12, &sig_readback1);
device_mutex_unlock(RT_DEV_LOCK_FLASH); device_mutex_unlock(RT_DEV_LOCK_FLASH);
printf("\n\r[%s] signature %x,%x, checksum 0x%x", __FUNCTION__ , sig_readback0, sig_readback1, checksum); printf("[%s] signature %x,%x, checksum 0x%x\n", __FUNCTION__ , sig_readback0, sig_readback1, checksum);
#if SWAP_UPDATE #if SWAP_UPDATE
if(OldImg2Addr != ~0x0){ if(OldImg2Addr != ~0x0){
device_mutex_lock(RT_DEV_LOCK_FLASH); device_mutex_lock(RT_DEV_LOCK_FLASH);
flash_write_word(&flash,OldImg2Addr + 8, 0x35393130); flash_write_word(&flash,OldImg2Addr + 8, IMG_SIGN1_SWP);
flash_write_word(&flash,OldImg2Addr + 12, 0x31313738); flash_write_word(&flash,OldImg2Addr + 12, IMG_SIGN2_SWP);
flash_read_word(&flash, OldImg2Addr + 8, &sig_readback0); flash_read_word(&flash, OldImg2Addr + 8, &sig_readback0);
flash_read_word(&flash, OldImg2Addr + 12, &sig_readback1); flash_read_word(&flash, OldImg2Addr + 12, &sig_readback1);
device_mutex_unlock(RT_DEV_LOCK_FLASH); device_mutex_unlock(RT_DEV_LOCK_FLASH);
printf("\n\r[%s] old signature %x,%x", __FUNCTION__ , sig_readback0, sig_readback1); printf("[%s] old signature %x,%x\n", __FUNCTION__ , sig_readback0, sig_readback1);
} }
#endif #endif
printf("\n\r[%s] Update OTA success!", __FUNCTION__); printf("[%s] Update OTA success!\n", __FUNCTION__);
ret = 0; ret = 0;
} }
@ -689,9 +689,9 @@ update_ota_exit:
if(param) if(param)
update_free(param); update_free(param);
TaskOTA = NULL; TaskOTA = NULL;
printf("\n\r[%s] Update task exit", __FUNCTION__); printf("[%s] Update task exit\n", __FUNCTION__);
if(!ret){ if(!ret){
printf("\n\r[%s] Ready to reboot", __FUNCTION__); printf("[%s] Ready to reboot\n", __FUNCTION__);
ota_platform_reset(); ota_platform_reset();
} }
vTaskDelete(NULL); vTaskDelete(NULL);
@ -706,20 +706,20 @@ int update_ota_local(char *ip, int port)
update_cfg_local_t *pUpdateCfg; update_cfg_local_t *pUpdateCfg;
if(TaskOTA){ if(TaskOTA){
printf("\n\r[%s] Update task has created.", __FUNCTION__); printf("[%s] Update task has created.\n", __FUNCTION__);
return 0; return 0;
} }
pUpdateCfg = update_malloc(sizeof(update_cfg_local_t)); pUpdateCfg = update_malloc(sizeof(update_cfg_local_t));
if(pUpdateCfg == NULL){ if(pUpdateCfg == NULL){
printf("\n\r[%s] Alloc update cfg failed", __FUNCTION__); printf("[%s] Alloc update cfg failed\n", __FUNCTION__);
return -1; return -1;
} }
pUpdateCfg->ip_addr = inet_addr(ip); pUpdateCfg->ip_addr = inet_addr(ip);
pUpdateCfg->port = ntohs(port); pUpdateCfg->port = ntohs(port);
if(xTaskCreate(update_ota_local_task, "OTA_server", STACK_SIZE, pUpdateCfg, TASK_PRIORITY, &TaskOTA) != pdPASS){ if(xTaskCreate(update_ota_local_task, "OTA_server\n", STACK_SIZE, pUpdateCfg, TASK_PRIORITY, &TaskOTA) != pdPASS){
update_free(pUpdateCfg); update_free(pUpdateCfg);
printf("\n\r[%s] Create update task failed", __FUNCTION__); printf("[%s] Create update task failed\n", __FUNCTION__);
} }
return 0; return 0;
} }
@ -738,68 +738,68 @@ static void update_ota_cloud_task(void *param)
#if CONFIG_WRITE_MAC_TO_FLASH #if CONFIG_WRITE_MAC_TO_FLASH
char mac[ETH_ALEN]; char mac[ETH_ALEN];
#endif #endif
printf("\n\r[%s] Update task start", __FUNCTION__); printf("[%s] Update task start\n", __FUNCTION__);
buf = update_malloc(BUF_SIZE); buf = update_malloc(BUF_SIZE);
if(!buf){ if(!buf){
printf("\n\r[%s] Alloc buffer failed", __FUNCTION__); printf("[%s] Alloc buffer failed\n", __FUNCTION__);
goto update_ota_exit_1; goto update_ota_exit_1;
} }
// Init ctx // Init ctx
if(updater_init_ctx(&ctx, (char*)cfg->repository, (char*)cfg->file_path) != 0) { if(updater_init_ctx(&ctx, (char*)cfg->repository, (char*)cfg->file_path) != 0) {
printf("\n\r[%s] Cloud ctx init failed", __FUNCTION__); printf("[%s] Cloud ctx init failed\n", __FUNCTION__);
goto update_ota_exit_1; goto update_ota_exit_1;
} }
printf("\n\r[%s] Firmware link: %s, size = %d bytes, checksum = 0x%08x, version = %s\n", __FUNCTION__, printf("[%s] Firmware link: %s, size = %d bytes, checksum = 0x%08x, version = %s\n", __FUNCTION__,
ctx.link, ctx.size, ctx.checksum, ctx.version); ctx.link, ctx.size, ctx.checksum, ctx.version);
// Erase config sectors // Erase config sectors
if(flash_EraseSector(CONFIG_SECTOR) < 0){ if(flash_EraseSector(CONFIG_SECTOR) < 0){
printf("\n\r[%s] Erase sector failed", __FUNCTION__); printf("[%s] Erase sector failed\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
#if CONFIG_WRITE_MAC_TO_FLASH #if CONFIG_WRITE_MAC_TO_FLASH
// Read MAC address // Read MAC address
if(flash_Read(FLASH_ADD_STORE_MAC, mac, ETH_ALEN) < 0){ if(flash_Read(FLASH_ADD_STORE_MAC, mac, ETH_ALEN) < 0){
printf("\n\r[%s] Read MAC error", __FUNCTION__); printf("[%s] Read MAC error\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
#endif #endif
// Erase update sectors // Erase update sectors
for(i = UPDATE_SECTOR; i <= FLASH_Sector_11; i += 8){ for(i = UPDATE_SECTOR; i <= FLASH_Sector_11; i += 8){
if(flash_EraseSector(i) < 0){ if(flash_EraseSector(i) < 0){
printf("\n\r[%s] Erase sector failed", __FUNCTION__); printf("[%s] Erase sector failed\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
} }
// Write update sectors // Write update sectors
address = flash_SectorAddress(UPDATE_SECTOR); address = flash_SectorAddress(UPDATE_SECTOR);
printf("\n\r"); printf("\n");
while(ctx.bytes < ctx.size){ while(ctx.bytes < ctx.size){
read_bytes = updater_read_bytes(&ctx, (unsigned char*)buf, BUF_SIZE); read_bytes = updater_read_bytes(&ctx, (unsigned char*)buf, BUF_SIZE);
if(read_bytes == 0) break; // Read end if(read_bytes == 0) break; // Read end
if(read_bytes < 0){ if(read_bytes < 0){
printf("\n\r[%s] Read socket failed", __FUNCTION__); printf("[%s] Read socket failed\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
if(flash_Wrtie(address + size, buf, read_bytes) < 0){ if(flash_Wrtie(address + size, buf, read_bytes) < 0){
printf("\n\r[%s] Write sector failed", __FUNCTION__); printf("[%s] Write sector failed\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
size += read_bytes; size += read_bytes;
for(i = 0; i < read_bytes; i ++) for(i = 0; i < read_bytes; i ++)
checksum += buf[i]; checksum += buf[i];
printf("\rUpdate file size = %d/%d bytes ", ctx.bytes, ctx.size); printf("\rUpdate file size = %d/%d bytes\n", ctx.bytes, ctx.size);
} }
printf("\n\r[%s] ctx checksum = %08x, computed checksum = %08x\n", __FUNCTION__, ctx.checksum, checksum); printf("[%s] ctx checksum = %08x, computed checksum = %08x\n", __FUNCTION__, ctx.checksum, checksum);
if(checksum != ctx.checksum){ if(checksum != ctx.checksum){
printf("\n\r[%s] Checksum error", __FUNCTION__); printf("[%s] Checksum error\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
#if CONFIG_WRITE_MAC_TO_FLASH #if CONFIG_WRITE_MAC_TO_FLASH
//Write MAC address //Write MAC address
if(!(mac[0]==0xff&&mac[1]==0xff&&mac[2]==0xff&&mac[3]==0xff&&mac[4]==0xff&&mac[5]==0xff)){ if(!(mac[0]==0xff&&mac[1]==0xff&&mac[2]==0xff&&mac[3]==0xff&&mac[4]==0xff&&mac[5]==0xff)){
if(flash_Wrtie(FLASH_ADD_STORE_MAC, mac, ETH_ALEN) < 0){ if(flash_Wrtie(FLASH_ADD_STORE_MAC, mac, ETH_ALEN) < 0){
printf("\n\r[%s] Write MAC failed", __FUNCTION__); printf("[%s] Write MAC failed\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
} }
@ -808,10 +808,10 @@ static void update_ota_cloud_task(void *param)
address = flash_SectorAddress(CONFIG_SECTOR); address = flash_SectorAddress(CONFIG_SECTOR);
if( (flash_Wrtie(address, (char*)&size, 4) < 0) || if( (flash_Wrtie(address, (char*)&size, 4) < 0) ||
(flash_Wrtie(address+4, (char*)&checksum, 4) < 0) ){ (flash_Wrtie(address+4, (char*)&checksum, 4) < 0) ){
printf("\n\r[%s] Write sector failed", __FUNCTION__); printf("[%s] Write sector failed\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
printf("\n\r[%s] Update OTA success!", __FUNCTION__); printf("[%s] Update OTA success!\n", __FUNCTION__);
update_ota_exit: update_ota_exit:
updater_free_ctx(&ctx); updater_free_ctx(&ctx);
@ -821,7 +821,7 @@ update_ota_exit_1:
if(param) if(param)
update_free(param); update_free(param);
TaskOTA = NULL; TaskOTA = NULL;
printf("\n\r[%s] Update task exit", __FUNCTION__); printf("[%s] Update task exit\n", __FUNCTION__);
vTaskDelete(NULL); vTaskDelete(NULL);
return; return;
} }
@ -837,31 +837,31 @@ static void update_ota_cloud_task(void *param)
#if CONFIG_WRITE_MAC_TO_FLASH #if CONFIG_WRITE_MAC_TO_FLASH
char mac[ETH_ALEN]; char mac[ETH_ALEN];
#endif #endif
printf("\n\r[%s] Update task start", __FUNCTION__); printf("[%s] Update task start\n", __FUNCTION__);
buf = update_malloc(BUF_SIZE); buf = update_malloc(BUF_SIZE);
if(!buf){ if(!buf){
printf("\n\r[%s] Alloc buffer failed", __FUNCTION__); printf("[%s] Alloc buffer failed\n", __FUNCTION__);
goto update_ota_exit_1; goto update_ota_exit_1;
} }
// Init ctx // Init ctx
if(updater_init_ctx(&ctx, (char*)cfg->repository, (char*)cfg->file_path) != 0) { if(updater_init_ctx(&ctx, (char*)cfg->repository, (char*)cfg->file_path) != 0) {
printf("\n\r[%s] Cloud ctx init failed", __FUNCTION__); printf("[%s] Cloud ctx init failed\n", __FUNCTION__);
goto update_ota_exit_1; goto update_ota_exit_1;
} }
printf("\n\r[%s] Firmware link: %s, size = %d bytes, checksum = 0x%08x, version = %s\n", __FUNCTION__, printf("[%s] Firmware link: %s, size = %d bytes, checksum = 0x%08x, version = %s\n", __FUNCTION__,
ctx.link, ctx.size, ctx.checksum, ctx.version); ctx.link, ctx.size, ctx.checksum, ctx.version);
// Erase config sectors // Erase config sectors
for(i = CONFIG_SECTOR; i < APPLICATION_SECTOR; i += FLASH_PAGE_SIZE){ for(i = CONFIG_SECTOR; i < APPLICATION_SECTOR; i += FLASH_PAGE_SIZE){
if(flash_EraseSector(i) < 0){ if(flash_EraseSector(i) < 0){
printf("\n\r[%s] Erase sector failed", __FUNCTION__); printf("[%s] Erase sector failed\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
} }
#if CONFIG_WRITE_MAC_TO_FLASH #if CONFIG_WRITE_MAC_TO_FLASH
// Read MAC address // Read MAC address
if(flash_Read(FLASH_ADD_STORE_MAC, mac, ETH_ALEN) < 0){ if(flash_Read(FLASH_ADD_STORE_MAC, mac, ETH_ALEN) < 0){
printf("\n\r[%s] Read MAC error", __FUNCTION__); printf("[%s] Read MAC error\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
#endif #endif
@ -869,18 +869,18 @@ static void update_ota_cloud_task(void *param)
// Erase update sectors // Erase update sectors
for(i = UPDATE_SECTOR; i < FLASH_Sector_0 + FLASH_SIZE; i += FLASH_PAGE_SIZE){ for(i = UPDATE_SECTOR; i < FLASH_Sector_0 + FLASH_SIZE; i += FLASH_PAGE_SIZE){
if(flash_EraseSector(i) < 0){ if(flash_EraseSector(i) < 0){
printf("\n\r[%s] Erase sector failed", __FUNCTION__); printf("[%s] Erase sector failed\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
} }
// Write update sectors // Write update sectors
address = UPDATE_SECTOR; address = UPDATE_SECTOR;
printf("\n\r"); printf("\n");
while(ctx.bytes < ctx.size){ while(ctx.bytes < ctx.size){
read_bytes = updater_read_bytes(&ctx, (unsigned char*)buf, BUF_SIZE); read_bytes = updater_read_bytes(&ctx, (unsigned char*)buf, BUF_SIZE);
if(read_bytes == 0) break; // Read end if(read_bytes == 0) break; // Read end
if(read_bytes < 0){ if(read_bytes < 0){
printf("\n\r[%s] Read socket failed", __FUNCTION__); printf("[%s] Read socket failed\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
if(flag_a == 0){ if(flag_a == 0){
@ -888,14 +888,14 @@ static void update_ota_cloud_task(void *param)
a = buf[read_bytes - 1]; a = buf[read_bytes - 1];
flag_a = 1; flag_a = 1;
if(flash_Wrtie(address + size, buf, read_bytes - 1) < 0){ if(flash_Wrtie(address + size, buf, read_bytes - 1) < 0){
printf("\n\r[%s] Write sector failed", __FUNCTION__); printf("[%s] Write sector failed\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
size += read_bytes - 1; size += read_bytes - 1;
} }
else{ else{
if(flash_Wrtie(address + size, buf, read_bytes) < 0){ if(flash_Wrtie(address + size, buf, read_bytes) < 0){
printf("\n\r[%s] Write sector failed", __FUNCTION__); printf("[%s] Write sector failed\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
size += read_bytes; size += read_bytes;
@ -904,7 +904,7 @@ static void update_ota_cloud_task(void *param)
else{ else{
a = buf[0]<< 8 |a; a = buf[0]<< 8 |a;
if(flash_Wrtie(address + size, (char*)(&a), 2) < 0){ if(flash_Wrtie(address + size, (char*)(&a), 2) < 0){
printf("\n\r[%s] Write sector failed", __FUNCTION__); printf("[%s] Write sector failed\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
size += 2; size += 2;
@ -914,14 +914,14 @@ static void update_ota_cloud_task(void *param)
a = buf[read_bytes - 1]; a = buf[read_bytes - 1];
flag_a = 1; flag_a = 1;
if(flash_Wrtie(address + size, buf + 1, read_bytes - 2) < 0){ if(flash_Wrtie(address + size, buf + 1, read_bytes - 2) < 0){
printf("\n\r[%s] Write sector failed", __FUNCTION__); printf("[%s] Write sector failed\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
size += read_bytes - 2; size += read_bytes - 2;
} }
else{ else{
if(flash_Wrtie(address + size, buf + 1, read_bytes - 1) < 0){ if(flash_Wrtie(address + size, buf + 1, read_bytes - 1) < 0){
printf("\n\r[%s] Write sector failed", __FUNCTION__); printf("[%s] Write sector failed\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
size += read_bytes - 1; size += read_bytes - 1;
@ -929,25 +929,25 @@ static void update_ota_cloud_task(void *param)
} }
for(i = 0; i < read_bytes; i ++) for(i = 0; i < read_bytes; i ++)
checksum += buf[i]; checksum += buf[i];
printf("\rUpdate file size = %d/%d bytes ", ctx.bytes, ctx.size); printf("\rUpdate file size = %d/%d bytes\n", ctx.bytes, ctx.size);
} }
if(flag_a){ if(flag_a){
if(flash_Wrtie(address + size, (char*)(&a), 2) < 0){ if(flash_Wrtie(address + size, (char*)(&a), 2) < 0){
printf("\n\r[%s] Write sector failed", __FUNCTION__); printf("[%s] Write sector failed\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
size += 1; size += 1;
} }
printf("\n\r[%s] ctx checksum = %08x, computed checksum = %08x\n", __FUNCTION__, ctx.checksum, checksum); printf("[%s] ctx checksum = %08x, computed checksum = %08x\n", __FUNCTION__, ctx.checksum, checksum);
if(checksum != ctx.checksum){ if(checksum != ctx.checksum){
printf("\n\r[%s] Checksum error", __FUNCTION__); printf("[%s] Checksum error\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
#if CONFIG_WRITE_MAC_TO_FLASH #if CONFIG_WRITE_MAC_TO_FLASH
//Write MAC address //Write MAC address
if(!(mac[0]==0xff&&mac[1]==0xff&&mac[2]==0xff&&mac[3]==0xff&&mac[4]==0xff&&mac[5]==0xff)){ if(!(mac[0]==0xff&&mac[1]==0xff&&mac[2]==0xff&&mac[3]==0xff&&mac[4]==0xff&&mac[5]==0xff)){
if(flash_Wrtie(FLASH_ADD_STORE_MAC, mac, ETH_ALEN) < 0){ if(flash_Wrtie(FLASH_ADD_STORE_MAC, mac, ETH_ALEN) < 0){
printf("\n\r[%s] Write MAC failed", __FUNCTION__); printf("[%s] Write MAC failed\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
} }
@ -957,10 +957,10 @@ static void update_ota_cloud_task(void *param)
address = CONFIG_SECTOR; address = CONFIG_SECTOR;
if( (flash_Wrtie(address, (char*)&size, 4) < 0) || if( (flash_Wrtie(address, (char*)&size, 4) < 0) ||
(flash_Wrtie(address+4, (char*)&checksum, 4) < 0) ){ (flash_Wrtie(address+4, (char*)&checksum, 4) < 0) ){
printf("\n\r[%s] Write sector failed", __FUNCTION__); printf("[%s] Write sector failed\n", __FUNCTION__);
goto update_ota_exit; goto update_ota_exit;
} }
printf("\n\r[%s] Update OTA success!", __FUNCTION__); printf("[%s] Update OTA success!\n", __FUNCTION__);
update_ota_exit: update_ota_exit:
updater_free_ctx(&ctx); updater_free_ctx(&ctx);
@ -970,7 +970,7 @@ update_ota_exit_1:
if(param) if(param)
update_free(param); update_free(param);
TaskOTA = NULL; TaskOTA = NULL;
printf("\n\r[%s] Update task exit", __FUNCTION__); printf("[%s] Update task exit\n", __FUNCTION__);
vTaskDelete(NULL); vTaskDelete(NULL);
return; return;
} }
@ -983,27 +983,27 @@ int update_ota_cloud(char *repository, char *file_path)
update_cfg_cloud_t *pUpdateCfg; update_cfg_cloud_t *pUpdateCfg;
if(TaskOTA){ if(TaskOTA){
printf("\n\r[%s] Update task has created.", __FUNCTION__); printf("[%s] Update task has created.\n", __FUNCTION__);
return 0; return 0;
} }
pUpdateCfg = update_malloc(sizeof(update_cfg_cloud_t)); pUpdateCfg = update_malloc(sizeof(update_cfg_cloud_t));
if(pUpdateCfg == NULL){ if(pUpdateCfg == NULL){
printf("\n\r[%s] Alloc update cfg failed.", __FUNCTION__); printf("[%s] Alloc update cfg failed.\n", __FUNCTION__);
goto exit; goto exit;
} }
if(strlen(repository) > (REPOSITORY_LEN-1)){ if(strlen(repository) > (REPOSITORY_LEN-1)){
printf("\n\r[%s] Repository length is too long.", __FUNCTION__); printf("[%s] Repository length is too long.\n", __FUNCTION__);
goto exit; goto exit;
} }
if(strlen(file_path) > (FILE_PATH_LEN-1)){ if(strlen(file_path) > (FILE_PATH_LEN-1)){
printf("\n\r[%s] File path length is too long.", __FUNCTION__); printf("[%s] File path length is too long.\n", __FUNCTION__);
goto exit; goto exit;
} }
strcpy((char*)pUpdateCfg->repository, repository); strcpy((char*)pUpdateCfg->repository, repository);
strcpy((char*)pUpdateCfg->file_path, file_path); strcpy((char*)pUpdateCfg->file_path, file_path);
if(xTaskCreate(update_ota_cloud_task, "OTA_server", STACK_SIZE, pUpdateCfg, TASK_PRIORITY, &TaskOTA) != pdPASS){ if(xTaskCreate(update_ota_cloud_task, "OTA_server", STACK_SIZE, pUpdateCfg, TASK_PRIORITY, &TaskOTA) != pdPASS){
printf("\n\r[%s] Create update task failed", __FUNCTION__); printf("[%s] Create update task failed\n", __FUNCTION__);
goto exit; goto exit;
} }
@ -1016,11 +1016,11 @@ exit:
//--------------------------------------------------------------------- //---------------------------------------------------------------------
void cmd_update(int argc, char **argv) void cmd_update(int argc, char **argv)
{ {
// printf("\n\r[%s] Firmware A", __FUNCTION__); // printf("[%s] Firmware A", __FUNCTION__);
#if (SERVER_TYPE == SERVER_LOCAL) #if (SERVER_TYPE == SERVER_LOCAL)
int port; int port;
if(argc != 3){ if(argc != 3){
printf("\n\r[%s] Usage: update IP PORT", __FUNCTION__); printf("[%s] Usage: update IP PORT\n", __FUNCTION__);
return; return;
} }
port = atoi(argv[2]); port = atoi(argv[2]);
@ -1028,7 +1028,7 @@ void cmd_update(int argc, char **argv)
#endif #endif
#if (SERVER_TYPE == SERVER_CLOUD) #if (SERVER_TYPE == SERVER_CLOUD)
if(argc != 3){ if(argc != 3){
printf("\n\r[%s] Usage: update REPOSITORY FILE_PATH", __FUNCTION__); printf("[%s] Usage: update REPOSITORY FILE_PATH\n", __FUNCTION__);
return; return;
} }
update_ota_cloud(argv[1], argv[2]); update_ota_cloud(argv[1], argv[2]);
@ -1056,9 +1056,9 @@ void cmd_ota_image(bool cmd){
device_mutex_lock(RT_DEV_LOCK_FLASH); device_mutex_lock(RT_DEV_LOCK_FLASH);
flash_stream_read(&flash, Part2Addr, FLASH_SECTOR_SIZE, pbuf); flash_stream_read(&flash, Part2Addr, FLASH_SECTOR_SIZE, pbuf);
if (cmd == 1) if (cmd == 1)
memcpy((char*)pbuf+8, "81958711", 8); memcpy((char*)pbuf+8, IMG_SIGN_RUN, 8);
else else
memcpy((char*)pbuf+8, "01958711", 8); memcpy((char*)pbuf+8, IMG_SIGN_SWP, 8);
flash_erase_sector(&flash, Part2Addr); flash_erase_sector(&flash, Part2Addr);
flash_stream_write(&flash, Part2Addr, FLASH_SECTOR_SIZE, pbuf); flash_stream_write(&flash, Part2Addr, FLASH_SECTOR_SIZE, pbuf);
@ -1068,9 +1068,9 @@ void cmd_ota_image(bool cmd){
device_mutex_lock(RT_DEV_LOCK_FLASH); device_mutex_lock(RT_DEV_LOCK_FLASH);
flash_stream_read(&flash, Part1Addr, FLASH_SECTOR_SIZE, pbuf); flash_stream_read(&flash, Part1Addr, FLASH_SECTOR_SIZE, pbuf);
if (cmd == 1) if (cmd == 1)
memcpy((char*)pbuf+8, "01958711", 8); memcpy((char*)pbuf+8, IMG_SIGN_SWP, 8);
else else
memcpy((char*)pbuf+8, "81958711", 8); memcpy((char*)pbuf+8, IMG_SIGN_RUN, 8);
flash_erase_sector(&flash, Part1Addr); flash_erase_sector(&flash, Part1Addr);
flash_stream_write(&flash, Part1Addr, FLASH_SECTOR_SIZE, pbuf); flash_stream_write(&flash, Part1Addr, FLASH_SECTOR_SIZE, pbuf);

View file

@ -50,7 +50,7 @@ RAM_START_FUNCTION __attribute__((section(".start.ram.data.e"))) gRamPatchFun2 =
RAM_START_FUNCTION __attribute__((section(".image2.ram.data"))) gImage2EntryFun0 = RAM_START_FUNCTION __attribute__((section(".image2.ram.data"))) gImage2EntryFun0 =
{ InfraStart + 1 }; { InfraStart + 1 };
_RAM_IMG2_VALID_PATTEN __attribute__((section(".image2.validate.rodata"))) RAM_IMG2_VALID_PATTEN = _RAM_IMG2_VALID_PATTEN __attribute__((section(".image2.validate.rodata"))) RAM_IMG2_VALID_PATTEN =
{ { "RTKWin" }, { 0xff, 0, 1, 1, 0, 0x95, 0x81, 1, 1, 0, 0, 0, 0 } }; { { IMG2_SIGN_TXT }, { 0xff, 0, 1, 1, 0, 0x95, 0x81, 1, 1, 0, 0, 0, 0 } }; // "RTKWin"
HAL_GPIO_ADAPTER __attribute__((section(".hal.ram.data"))) gBoot_Gpio_Adapter; HAL_GPIO_ADAPTER __attribute__((section(".hal.ram.data"))) gBoot_Gpio_Adapter;

View file

@ -88,7 +88,7 @@ RAM_START_FUNCTION __attribute__((section(".start.ram.data.e"))) gRamPatchFun2 =
RAM_START_FUNCTION __attribute__((section(".image2.ram.data"))) gImage2EntryFun0 = RAM_START_FUNCTION __attribute__((section(".image2.ram.data"))) gImage2EntryFun0 =
{ InfraStart + 1 }; { InfraStart + 1 };
_RAM_IMG2_VALID_PATTEN __attribute__((section(".image2.validate.rodata"))) RAM_IMG2_VALID_PATTEN = _RAM_IMG2_VALID_PATTEN __attribute__((section(".image2.validate.rodata"))) RAM_IMG2_VALID_PATTEN =
{ { "RTKWin" }, { 0xff, 0, 1, 1, 0, 0x95, 0x81, 1, 1, 0, 0, 0, 0 } }; { { IMG2_SIGN_TXT }, { 0xff, 0, 1, 1, 0, 0x95, 0x81, 1, 1, 0, 0, 0, 0 } }; // "RTKWin"
HAL_GPIO_ADAPTER __attribute__((section(".hal.ram.data"))) gBoot_Gpio_Adapter; HAL_GPIO_ADAPTER __attribute__((section(".hal.ram.data"))) gBoot_Gpio_Adapter;
@ -204,7 +204,7 @@ void __attribute__((section(".hal.ram.text"))) RtlBootToSram(void) {
SpicFlashInitRtl8195A(1); // SpicBitMode 1 SpicFlashInitRtl8195A(1); // SpicBitMode 1
DBG_8195A("===== Enter Image 1.5 ====\nImg2 Sign: %s, InfaStart @ 0x%08x\n", DBG_8195A("===== Enter Image 1.5 ====\nImg2 Sign: %s, InfaStart @ 0x%08x\n",
&__image2_validate_code__, __image2_entry_func__); &__image2_validate_code__, __image2_entry_func__);
if (strcmp((const char * )&__image2_validate_code__, "RTKWin")) { if (strcmp((const char * )&__image2_validate_code__, IMG2_SIGN_TXT)) {
DBG_MISC_ERR("Invalid Image2 Signature!\n"); DBG_MISC_ERR("Invalid Image2 Signature!\n");
RtlConsolRom(10000); // ROM: RtlConsolRom = 0xedcd; RtlConsolRom(10000); // ROM: RtlConsolRom = 0xedcd;
} }
@ -231,7 +231,7 @@ int __attribute__((section(".hal.ram.text"))) IsForceLoadDefaultImg2(void) {
u8 gpio_pin[4]; u8 gpio_pin[4];
HAL_GPIO_PIN GPIO_Pin; HAL_GPIO_PIN GPIO_Pin;
*((u32 *) &gpio_pin) = *(u32 *) (SPI_FLASH_BASE + 0x9008); // config data + 8 *((u32 *) &gpio_pin) = *(u32 *) (SPI_FLASH_BASE + FLASH_SYSTEM_DATA_ADDR + 0x08); // config data + 8
int i = 0; int i = 0;
_pHAL_Gpio_Adapter = (int) &gBoot_Gpio_Adapter; _pHAL_Gpio_Adapter = (int) &gBoot_Gpio_Adapter;
int result = 0; int result = 0;
@ -347,16 +347,16 @@ void __attribute__((section(".hal.ram.text"))) PreProcessForVendor(void) {
{ {
v16 = -1; v16 = -1;
v17 = -1; v17 = -1;
if (sign2 == 0x31313738) { if (sign2 == IMG_SIGN2_RUN) {
if (sign1 == 0x35393138) { if (sign1 == IMG_SIGN1_RUN) {
v16 = img1size; v16 = img1size;
v17 = -1; v17 = -1;
} else if (sign1 == 0x35393130) { } else if (sign1 == IMG_SIGN1_SWP) {
v17 = img1size; v17 = img1size;
v16 = -1; v16 = -1;
} }
} }
u32 OTA_addr = *(u32 *) (SPI_FLASH_BASE + 0x9000); // config sector data u32 OTA_addr = *(u32 *) (SPI_FLASH_BASE + FLASH_SYSTEM_DATA_ADDR); // config sector data
if (OTA_addr != -1) { if (OTA_addr != -1) {
u32 image2size = *(u32 *) (img1size + SPI_FLASH_BASE); u32 image2size = *(u32 *) (img1size + SPI_FLASH_BASE);
if (OTA_addr >= (img1size + image2size) if (OTA_addr >= (img1size + image2size)
@ -364,9 +364,9 @@ void __attribute__((section(".hal.ram.text"))) PreProcessForVendor(void) {
prdflash = (u32 *) (OTA_addr + SPI_FLASH_BASE + 8); prdflash = (u32 *) (OTA_addr + SPI_FLASH_BASE + 8);
sign1 = *prdflash++; sign1 = *prdflash++;
sign2 = *prdflash; sign2 = *prdflash;
if (sign2 == 0x31313738) { if (sign2 == IMG_SIGN2_RUN) {
if (sign1 == 0x35393138) v16 = OTA_addr; if (sign1 == IMG_SIGN1_RUN) v16 = OTA_addr;
else if (sign1 == 0x35393130) v17 = OTA_addr; else if (sign1 == IMG_SIGN1_SWP) v17 = OTA_addr;
} }
LABEL_41: if (IsForceLoadDefaultImg2()) { LABEL_41: if (IsForceLoadDefaultImg2()) {
if (v17 != -1) run_image = v17; if (v17 != -1) run_image = v17;
@ -421,7 +421,7 @@ LABEL_55: prdflash = run_image + SPI_FLASH_BASE;
(const char * )(Image2Addr + 4), (const char * )(Image2Addr + 4),
*(u32 *)Image2Addr); *(u32 *)Image2Addr);
if (strcmp((const char * )(Image2Addr + 4), if (strcmp((const char * )(Image2Addr + 4),
"RTKWin")) { IMG2_SIGN_TXT)) {
DBG_MISC_ERR("Invalid Image2 Signature\n"); DBG_MISC_ERR("Invalid Image2 Signature\n");
while (1) RtlConsolRom(1000); while (1) RtlConsolRom(1000);
} }
@ -439,7 +439,7 @@ LABEL_55: prdflash = run_image + SPI_FLASH_BASE;
goto LABEL_41; goto LABEL_41;
} }
} // if (flash_enable) } // if (flash_enable)
if (strcmp((const char * )(Image2Addr + 4), "RTKWin")) { if (strcmp((const char * )(Image2Addr + 4), IMG2_SIGN_TXT)) {
DBG_MISC_ERR("Invalid Image2 Signature\n", 2 * ConfigDebugErr); DBG_MISC_ERR("Invalid Image2 Signature\n", 2 * ConfigDebugErr);
while (1) RtlConsolRom(1000); while (1) RtlConsolRom(1000);
} }

View file

@ -161,4 +161,12 @@
#define FLASH_ADC_PARA_OFFSET 0x200 #define FLASH_ADC_PARA_OFFSET 0x200
#define FLASH_ADC_PARA_BASE (FLASH_SYSTEM_DATA_ADDR+FLASH_ADC_PARA_OFFSET) #define FLASH_ADC_PARA_BASE (FLASH_SYSTEM_DATA_ADDR+FLASH_ADC_PARA_OFFSET)
#define IMG_SIGN_RUN "81958711"
#define IMG_SIGN_SWP "01958711"
#define IMG_SIGN1_RUN 0x35393138 // "8195"
#define IMG_SIGN1_SWP 0x35393130 // "0195"
#define IMG_SIGN2_RUN 0x31313738 // "8711"
#define IMG_SIGN2_SWP IMG_SIGN2_RUN // "8711"
#define IMG2_SIGN_TXT "RTKWin"
#endif //_HAL_8195A_H_ #endif //_HAL_8195A_H_