123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- /*
- * MBIC_BootLoader.c
- *
- * Created on: 2020. 5. 4.
- * Author: parkyj
- */
- #include <stdbool.h>
- #include "main.h"
- #include "MBIC_BootLoader.h"
- #include "CRC.h"
- extern uint32_t crc32(uint32_t crc, const void *buf, size_t size);
- extern bool chksum(uint8_t *data, uint32_t leng,uint8_t chkdata);
- void MBIC_FirmwareUpdateStart(uint8_t* data);
- void MBIC_HeaderCheck(uint8_t* data);
- #define MBOC 0x00F0
- #define MBIC 0x00F1
- void MBIC_HeaderCheck(uint8_t* data){
- uint8_t Chksum_ret = false;
- /* MDOC 00 F0
- MBIC 00 F1*/
- uint16_t SubUid = ((data[MBIC_SUBUID_0] << 8) & 0xFF00)
- |((data[MBIC_SUBUID_1]) & 0x00FF);
-
- /* MBIC_PREAMBLE : 0x16161616 */
- if(data[MBIC_PREAMBLE_0] == MBIC_PREAMBLE0
- &&data[MBIC_PREAMBLE_1] == MBIC_PREAMBLE1
- &&data[MBIC_PREAMBLE_2] == MBIC_PREAMBLE2
- &&data[MBIC_PREAMBLE_3] == MBIC_PREAMBLE3){
- Chksum_ret = chksum(data,
- MBIC_LENGTH_1 - MBIC_SUBUID_0 - 1,
- data[MBIC_HEADERCHECKSUM_0]);
- if(Chksum_ret == false)
- printf("CheckSum Ret False \r\n");
- if(data[4] == MBIC){
- MBIC_FirmwareUpdateStart(data);
- }
- }
- }
- typedef struct{
- uint8_t mark[9];
- uint8_t type;
- uint8_t file_type;
- uint8_t version[3];
- uint8_t filename[41];
- uint8_t creation_time[6];
- uint8_t length[4];
- uint8_t crc[4];
- uint8_t reserved[59];
- };
- #define MBIC_DOWNLOAD_MARK "JT-NRDAS "
- #define MBIC_DOWNLOAD_TYPE 0x20
- #define MBIC_DOWNLOAD_FILETYPE 0
- #define MBIC_DOWNLOAD_FILENAME "MU jhfs-mbic-nrdas-v00.00.01.mbc MBIC CPU"
-
- void MBIC_DownLoadHeaderCheck(uint8_t* data){
- if( strncmp(&data[MBIC_DOWNLOAD_MARK0],MBIC_DOWNLOAD_MARK,sizeof(MBIC_DOWNLOAD_MARK)) != 0){
- printf("FUNCTION : %s LINE : %d = %s Mark ERR \r\n",__func__,__LINE__);
- }
- if( strncmp(&data[MBIC_DOWNLOAD_FILENAME0],MBIC_DOWNLOAD_FILENAME,sizeof(MBIC_DOWNLOAD_FILENAME)) != 0){
- printf("FUNCTION : %s LINE : %d = FILENAME ERR ERR \r\n",__func__,__LINE__);
- }
-
-
- MBIC_FirmwareUpdateStart(data);
- }
- void MBIC_FirmwareUpdateStart(uint8_t* data){
- uint8_t ret = 0;
- uint32_t crccheck = 0;
- uint8_t datatype = data[MBIC_DOWNLOAD_DATASTART];
- // crc32();
- switch(datatype){
- case DOWNLOAD_NOTI_REQ:
- break;
- case DOWNLOAD_DATA:
- break;
- case DOWNLOAD_CONFIRM:
- break;
- case DOWNLOAD_COMPLETE_CMD:
- break;
- case SYSTEMP_REBOOT:
- break;
- }
- // crccheck = crc32(&data[bluecell_type],data[bluecell_length],data[data[bluecell_length] + 1]);
- /* if(crccheck == NO_ERROR){
- AckData_Buf[bluecell_type] = FirmwareUpdataAck;
- if(data[bluecell_type] == 0xDD || data[bluecell_type] == 0xEE)//Start Firmware byte
- ret = Flash_write(&data[0]);
- if(ret == 1)
- AckData_Buf[bluecell_type] = FirmwareUpdataNak;
- }else{
- for(uint8_t i = 0; i < data[bluecell_length] + 3; i++)
- printf("%02x ",data[i]);
- printf("Check Sum error \n");
- AckData_Buf[bluecell_type] = FirmwareUpdataNak;
- }
- AckData_Buf[bluecell_crc] = STH30_CreateCrc(&AckData_Buf[bluecell_type],AckData_Buf[bluecell_length]);
- if(data[bluecell_type] != 0xEE && data[bluecell_type] != Bluecell_Reset){
- Uart1_Data_Send(&AckData_Buf[bluecell_stx],AckData_Buf[bluecell_length] + 3);
- }
- if(data[bluecell_type] == 0xEE)
- printf("update Complete \n");*/
- }
|