123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- /*
- * MBIC_Bootloader.c
- *
- * Created on: 2020. 5. 18.
- * Author: parkyj
- */
- #include "main.h"
- #include <stdbool.h>
- #include "MBIC_Bootloader.h"
- #define MARK_START_POSITION 0
- #define TYPE_START_POSITION 9
- #define FILE_TYPE_START_POSITION 10
- #define VERSION_START_POSITION 11
- #define FILENAME_START_POSITION 14
- #define CREATION_TIME_START_POSITION 55
- #define LENGTH_START_POSITION 61
- #define CRC_START_POSITION 65
- #define RESERVED_START_POSITION 69
- typedef struct{
- uint16_t Length;
- uint16_t Crcchk;
- bool FileChk;
- }BootLoaderDataCheck_st;
- BootLoaderDataCheck_st MBIC_FileDataCheck(uint8_t* data){
- BootLoaderDataCheck_st ret = {0,0,false};
- int8_t MBIC_Mark[9] = "JT-NRDAS ";
- int8_t MBIC_FileName1[] = "jhfs-mbic-nrdas-v";
- int8_t MBIC_FileName2[] = "v00.00.01.mbc";
- uint8_t MBIC_type = 0x20;
- uint8_t MBIC_FileType = 0x00;
- int i = 0;
- /***
- MARK Check
- ***/
- for(i = MARK_START_POSITION; i < TYPE_START_POSITION; i++){
- if(MBIC_Mark[i] != data[i]){
- printf("Data Diff \r\n");
- return ret;
- }else{
- printf("MARK Data Success \r\n");
- }
- }
- /***
- TYPE Check
- ***/
- for(i = TYPE_START_POSITION; i < FILE_TYPE_START_POSITION; i++){
- if(MBIC_type != data[i]){
- printf("Data Diff \r\n");
- return ret;
- }
- else
- printf("Type Data Success \r\n");
- }
- /***
- File Type Check
- ***/
- for(i = FILE_TYPE_START_POSITION; i < VERSION_START_POSITION; i++){
- if(MBIC_FileType != data[i]){
- printf("Data Diff \r\n");
- return ret;
- }
- else
- printf("File Type Data Success \r\n");
- }
- /***
- Version Check
- ***/
- for(i = VERSION_START_POSITION; i < FILENAME_START_POSITION; i++){
- printf("Version Data Success Version %x\r\n",data[i]);
- }
- /***
- File Name Check
- ***/
- for(i = FILENAME_START_POSITION; i < 30; i++){
- if(MBIC_FileName1[i-14] != data[i]){
- printf("Data Diff \r\n");
- printf("MBIC_FileName1[%d] : %x, data[%d] : %x\r\n",i - 14,MBIC_FileName1[i - 14],i,data[i]);
- return ret;
- }
- else
- printf("File Name Data Success %c\r\n",data[i]);
- }
- for(i = i; i < 43; i++){
- if(MBIC_FileName2[i-30] != data[i]){
- printf("Data Diff %c\r\n",data[i]);
- printf("MBIC_FileName2[%d] : %x, data[%d] : %x\r\n",i - 30,MBIC_FileName2[i - 30],i,data[i]);
- return ret;
- }
- else
- printf("File Name Data Success %c\r\n",data[i]);
- }
- for(i = i; i < 49; i++){
- printf("Creation Success %x\r\n",data[i]);
- }
- for(i = i; i < 55; i++){
- printf("Creation Success data[%d] : %x\r\n",i,data[i]);
- }
- printf(" %d",data[i++]);
- printf(" -%02d",data[i++]);
- printf(" -%02d",data[i++]);
- printf(" -%02d",data[i++]);
- printf(" -%02d",data[i++]);
- printf(" -%02d\r\n",data[i++]);
-
-
-
- ret.Length = ((data[i++] << 8) & 0xFF00);
- ret.Length += (data[i++]);
- printf("data[%d] : %d\r\n",i - 1,ret.Length);
- printf("data[%d] : %d\r\n",i - 1,ret.Length);
- ret.Crcchk = ((data[i++] << 8) & 0xFF00);
- ret.Crcchk += (data[i++]);
-
- printf("CRC_H[%d] : %x\r\n",i,ret.Crcchk);
- printf("CRC_L[%d] : %x\r\n",i,ret.Crcchk);
- ret.FileChk = true;
- return ret;
- }
- uint8_t* MBIC_HeaderMergeFunction(uint8_t* data, uint32_t CrcIndex)
- {
- byte[] ret = new byte[data.Length + 22 + 3];
- UInt16 CRCData = CRC16_Generate(data,data.Length);
- ret[(int)MBICProt_st.MBIC_PAYLOADSTART + CrcIndex + 0] = Convert.ToByte((CRCData & 0xFF00) >> 8);
- ret[(int)MBICProt_st.MBIC_PAYLOADSTART + CrcIndex + 1] = Convert.ToByte((CRCData & 0x00FF));
- ret[(int)MBICProt_st.MBIC_PAYLOADSTART + CrcIndex + 2] = 0x03;
- ret[(int)MBICProt_st.MBIC_PREAMBLE_0] = MBIC_PREAMBLE0;
- ret[(int)MBICProt_st.MBIC_PREAMBLE_1] = MBIC_PREAMBLE1;
- ret[(int)MBICProt_st.MBIC_PREAMBLE_2] = MBIC_PREAMBLE2;
- ret[(int)MBICProt_st.MBIC_PREAMBLE_3] = MBIC_PREAMBLE3;
- ret[(int)MBICProt_st.MBIC_SUBUID_0] = MBIC_SUBUID0;
- ret[(int)MBICProt_st.MBIC_SUBUID_1] = MBIC_SUBUID1;
- ret[(int)MBICProt_st.MBIC_RCODE_0] = 0;
- ret[(int)MBICProt_st.MBIC_TRID_0] = 0;
- ret[(int)MBICProt_st.MBIC_TRID_1] = 0;
- ret[(int)MBICProt_st.MBIC_SEQSUM_0] = 0;
- ret[(int)MBICProt_st.MBIC_TTL_0] = 0;
- ret[(int)MBICProt_st.MBIC_TIME_0] = 0;
- ret[(int)MBICProt_st.MBIC_TIME_1] = 0;
- ret[(int)MBICProt_st.MBIC_TIME_2] = 0;
- ret[(int)MBICProt_st.MBIC_TIME_3] = 0;
- ret[(int)MBICProt_st.MBIC_TIME_4] = 0;
- ret[(int)MBICProt_st.MBIC_TIME_5] = 0;
- ret[(int)MBICProt_st.MBIC_ERRRESPONSE_0] = MBIC_ERRRESPONSE;
- ret[(int)MBICProt_st.MBIC_CMD_0] = MBIC_ERRRESPONSE;
- ret[(int)MBICProt_st.MBIC_LENGTH_0] = MBIC_ERRRESPONSE;
- ret[(int)MBICProt_st.MBIC_LENGTH_1] = MBIC_ERRRESPONSE;
- ret[(int)MBICProt_st.MBIC_HEADERCHECKSUM_0] = Chksum_Create(ret);
- for(int i = 0; i < data.Length; i ++)
- ret[(int)MBICProt_st.MBIC_PAYLOADSTART + i] = data[i];
- return ret;
- }
- void MBIC_Bootloader_FirmwareUpdate(uint8_t* data){
- uint8_t datatype = data[MBIC_PAYLOADSTART];
- #if 0 // PYJ.2020.06.04_BEGIN --
- uint8_t dataTest[1024] = {
- 0x4A,0x54,0x2D,0x4E,0x52,0x44,0x41,0x53,0x20,0x20,0x00,0x00,
- 0x00,0x01,0x6A,0x68,0x66,0x73,0x2D,0x6D,0x62,0x69,0x63,0x2D,
- 0x6E,0x72,0x64,0x61,0x73,0x2D,0x76,0x30,0x30,0x2E,0x30,0x30,0x2E,
- 0x30,0x31,0x2E,0x6D,0x62,0x63,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
- 0x20,0x20,0x20,0x20,0x20,0x14,0x06,0x03,0x10,0x1F,0xC4,0x3C,0x49,
- 0x42,0x98,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
- };
-
- #endif // PYJ.2020.06.04_END --
- MBIC_FileDataCheck(&data[MBIC_PAYLOADSTART]);
-
- // printf("RX");
- // for(int i = 0; i < 128; i++)
- // printf("%c",*data++);
- switch(datatype){
- case MBIC_Notice_REQ:
-
- break;
- case MBIC_Download_DATA_REQ:
- break;
- case MBIC_Download_Confirm_REQ:
- break;
- case MBIC_Complete_Notice_REQ_REQ:
- break;
- case MBIC_Reboot_Notice_REQ:
- break;
- }
- }
|