MBIC_Bootloader.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /*
  2. * MBIC_Bootloader.c
  3. *
  4. * Created on: 2020. 5. 18.
  5. * Author: parkyj
  6. */
  7. #include "main.h"
  8. #include <stdbool.h>
  9. #include "MBIC_Bootloader.h"
  10. #define MARK_START_POSITION 0
  11. #define TYPE_START_POSITION 9
  12. #define FILE_TYPE_START_POSITION 10
  13. #define VERSION_START_POSITION 11
  14. #define FILENAME_START_POSITION 14
  15. #define CREATION_TIME_START_POSITION 55
  16. #define LENGTH_START_POSITION 61
  17. #define CRC_START_POSITION 65
  18. #define RESERVED_START_POSITION 69
  19. typedef struct{
  20. uint16_t Length;
  21. uint16_t Crcchk;
  22. bool FileChk;
  23. }BootLoaderDataCheck_st;
  24. BootLoaderDataCheck_st MBIC_FileDataCheck(uint8_t* data){
  25. BootLoaderDataCheck_st ret = {0,0,false};
  26. int8_t MBIC_Mark[9] = "JT-NRDAS ";
  27. int8_t MBIC_FileName1[] = "jhfs-mbic-nrdas-v";
  28. int8_t MBIC_FileName2[] = "v00.00.01.mbc";
  29. uint8_t MBIC_type = 0x20;
  30. uint8_t MBIC_FileType = 0x00;
  31. int i = 0;
  32. /***
  33. MARK Check
  34. ***/
  35. for(i = MARK_START_POSITION; i < TYPE_START_POSITION; i++){
  36. if(MBIC_Mark[i] != data[i]){
  37. printf("Data Diff \r\n");
  38. return ret;
  39. }else{
  40. printf("MARK Data Success \r\n");
  41. }
  42. }
  43. /***
  44. TYPE Check
  45. ***/
  46. for(i = TYPE_START_POSITION; i < FILE_TYPE_START_POSITION; i++){
  47. if(MBIC_type != data[i]){
  48. printf("Data Diff \r\n");
  49. return ret;
  50. }
  51. else
  52. printf("Type Data Success \r\n");
  53. }
  54. /***
  55. File Type Check
  56. ***/
  57. for(i = FILE_TYPE_START_POSITION; i < VERSION_START_POSITION; i++){
  58. if(MBIC_FileType != data[i]){
  59. printf("Data Diff \r\n");
  60. return ret;
  61. }
  62. else
  63. printf("File Type Data Success \r\n");
  64. }
  65. /***
  66. Version Check
  67. ***/
  68. for(i = VERSION_START_POSITION; i < FILENAME_START_POSITION; i++){
  69. printf("Version Data Success Version %x\r\n",data[i]);
  70. }
  71. /***
  72. File Name Check
  73. ***/
  74. for(i = FILENAME_START_POSITION; i < 30; i++){
  75. if(MBIC_FileName1[i-14] != data[i]){
  76. printf("Data Diff \r\n");
  77. printf("MBIC_FileName1[%d] : %x, data[%d] : %x\r\n",i - 14,MBIC_FileName1[i - 14],i,data[i]);
  78. return ret;
  79. }
  80. else
  81. printf("File Name Data Success %c\r\n",data[i]);
  82. }
  83. for(i = i; i < 43; i++){
  84. if(MBIC_FileName2[i-30] != data[i]){
  85. printf("Data Diff %c\r\n",data[i]);
  86. printf("MBIC_FileName2[%d] : %x, data[%d] : %x\r\n",i - 30,MBIC_FileName2[i - 30],i,data[i]);
  87. return ret;
  88. }
  89. else
  90. printf("File Name Data Success %c\r\n",data[i]);
  91. }
  92. for(i = i; i < 49; i++){
  93. printf("Creation Success %x\r\n",data[i]);
  94. }
  95. for(i = i; i < 55; i++){
  96. printf("Creation Success data[%d] : %x\r\n",i,data[i]);
  97. }
  98. printf(" %d",data[i++]);
  99. printf(" -%02d",data[i++]);
  100. printf(" -%02d",data[i++]);
  101. printf(" -%02d",data[i++]);
  102. printf(" -%02d",data[i++]);
  103. printf(" -%02d\r\n",data[i++]);
  104. ret.Length = ((data[i++] << 8) & 0xFF00);
  105. ret.Length += (data[i++]);
  106. printf("data[%d] : %d\r\n",i - 1,ret.Length);
  107. printf("data[%d] : %d\r\n",i - 1,ret.Length);
  108. ret.Crcchk = ((data[i++] << 8) & 0xFF00);
  109. ret.Crcchk += (data[i++]);
  110. printf("CRC_H[%d] : %x\r\n",i,ret.Crcchk);
  111. printf("CRC_L[%d] : %x\r\n",i,ret.Crcchk);
  112. ret.FileChk = true;
  113. return ret;
  114. }
  115. uint8_t* MBIC_HeaderMergeFunction(uint8_t* data, uint32_t CrcIndex)
  116. {
  117. byte[] ret = new byte[data.Length + 22 + 3];
  118. UInt16 CRCData = CRC16_Generate(data,data.Length);
  119. ret[(int)MBICProt_st.MBIC_PAYLOADSTART + CrcIndex + 0] = Convert.ToByte((CRCData & 0xFF00) >> 8);
  120. ret[(int)MBICProt_st.MBIC_PAYLOADSTART + CrcIndex + 1] = Convert.ToByte((CRCData & 0x00FF));
  121. ret[(int)MBICProt_st.MBIC_PAYLOADSTART + CrcIndex + 2] = 0x03;
  122. ret[(int)MBICProt_st.MBIC_PREAMBLE_0] = MBIC_PREAMBLE0;
  123. ret[(int)MBICProt_st.MBIC_PREAMBLE_1] = MBIC_PREAMBLE1;
  124. ret[(int)MBICProt_st.MBIC_PREAMBLE_2] = MBIC_PREAMBLE2;
  125. ret[(int)MBICProt_st.MBIC_PREAMBLE_3] = MBIC_PREAMBLE3;
  126. ret[(int)MBICProt_st.MBIC_SUBUID_0] = MBIC_SUBUID0;
  127. ret[(int)MBICProt_st.MBIC_SUBUID_1] = MBIC_SUBUID1;
  128. ret[(int)MBICProt_st.MBIC_RCODE_0] = 0;
  129. ret[(int)MBICProt_st.MBIC_TRID_0] = 0;
  130. ret[(int)MBICProt_st.MBIC_TRID_1] = 0;
  131. ret[(int)MBICProt_st.MBIC_SEQSUM_0] = 0;
  132. ret[(int)MBICProt_st.MBIC_TTL_0] = 0;
  133. ret[(int)MBICProt_st.MBIC_TIME_0] = 0;
  134. ret[(int)MBICProt_st.MBIC_TIME_1] = 0;
  135. ret[(int)MBICProt_st.MBIC_TIME_2] = 0;
  136. ret[(int)MBICProt_st.MBIC_TIME_3] = 0;
  137. ret[(int)MBICProt_st.MBIC_TIME_4] = 0;
  138. ret[(int)MBICProt_st.MBIC_TIME_5] = 0;
  139. ret[(int)MBICProt_st.MBIC_ERRRESPONSE_0] = MBIC_ERRRESPONSE;
  140. ret[(int)MBICProt_st.MBIC_CMD_0] = MBIC_ERRRESPONSE;
  141. ret[(int)MBICProt_st.MBIC_LENGTH_0] = MBIC_ERRRESPONSE;
  142. ret[(int)MBICProt_st.MBIC_LENGTH_1] = MBIC_ERRRESPONSE;
  143. ret[(int)MBICProt_st.MBIC_HEADERCHECKSUM_0] = Chksum_Create(ret);
  144. for(int i = 0; i < data.Length; i ++)
  145. ret[(int)MBICProt_st.MBIC_PAYLOADSTART + i] = data[i];
  146. return ret;
  147. }
  148. void MBIC_Bootloader_FirmwareUpdate(uint8_t* data){
  149. uint8_t datatype = data[MBIC_PAYLOADSTART];
  150. #if 0 // PYJ.2020.06.04_BEGIN --
  151. uint8_t dataTest[1024] = {
  152. 0x4A,0x54,0x2D,0x4E,0x52,0x44,0x41,0x53,0x20,0x20,0x00,0x00,
  153. 0x00,0x01,0x6A,0x68,0x66,0x73,0x2D,0x6D,0x62,0x69,0x63,0x2D,
  154. 0x6E,0x72,0x64,0x61,0x73,0x2D,0x76,0x30,0x30,0x2E,0x30,0x30,0x2E,
  155. 0x30,0x31,0x2E,0x6D,0x62,0x63,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
  156. 0x20,0x20,0x20,0x20,0x20,0x14,0x06,0x03,0x10,0x1F,0xC4,0x3C,0x49,
  157. 0x42,0x98,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  158. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  159. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  160. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  161. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  162. };
  163. #endif // PYJ.2020.06.04_END --
  164. MBIC_FileDataCheck(&data[MBIC_PAYLOADSTART]);
  165. // printf("RX");
  166. // for(int i = 0; i < 128; i++)
  167. // printf("%c",*data++);
  168. switch(datatype){
  169. case MBIC_Notice_REQ:
  170. break;
  171. case MBIC_Download_DATA_REQ:
  172. break;
  173. case MBIC_Download_Confirm_REQ:
  174. break;
  175. case MBIC_Complete_Notice_REQ_REQ:
  176. break;
  177. case MBIC_Reboot_Notice_REQ:
  178. break;
  179. }
  180. }