MBIC_Bootloader.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. void MBIC_Bootloader_FirmwareUpdate(uint8_t* data){
  116. uint8_t datatype = data[MBIC_PAYLOADSTART];
  117. #if 0 // PYJ.2020.06.04_BEGIN --
  118. uint8_t dataTest[1024] = {
  119. 0x4A,0x54,0x2D,0x4E,0x52,0x44,0x41,0x53,0x20,0x20,0x00,0x00,
  120. 0x00,0x01,0x6A,0x68,0x66,0x73,0x2D,0x6D,0x62,0x69,0x63,0x2D,
  121. 0x6E,0x72,0x64,0x61,0x73,0x2D,0x76,0x30,0x30,0x2E,0x30,0x30,0x2E,
  122. 0x30,0x31,0x2E,0x6D,0x62,0x63,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
  123. 0x20,0x20,0x20,0x20,0x20,0x14,0x06,0x03,0x10,0x1F,0xC4,0x3C,0x49,
  124. 0x42,0x98,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  125. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  126. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  127. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  128. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  129. };
  130. MBIC_FileDataCheck(dataTest);
  131. #endif // PYJ.2020.06.04_END --
  132. // printf("RX");
  133. // for(int i = 0; i < 128; i++)
  134. // printf("%c",*data++);
  135. switch(datatype){
  136. case MBIC_Notice_REQ:
  137. break;
  138. case MBIC_Download_DATA_REQ:
  139. break;
  140. case MBIC_Download_Confirm_REQ:
  141. break;
  142. case MBIC_Complete_Notice_REQ_REQ:
  143. break;
  144. case MBIC_Reboot_Notice_REQ:
  145. break;
  146. }
  147. }