MBIC_BootLoader.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * MBIC_BootLoader.c
  3. *
  4. * Created on: 2020. 5. 4.
  5. * Author: parkyj
  6. */
  7. #include <stdbool.h>
  8. #include "main.h"
  9. #include "MBIC_BootLoader.h"
  10. #include "CRC.h"
  11. extern uint32_t crc32(uint32_t crc, const void *buf, size_t size);
  12. extern bool chksum(uint8_t *data, uint32_t leng,uint8_t chkdata);
  13. void MBIC_FirmwareUpdateStart(uint8_t* data);
  14. void MBIC_HeaderCheck(uint8_t* data);
  15. #define MBOC 0x00F0
  16. #define MBIC 0x00F1
  17. void MBIC_HeaderCheck(uint8_t* data){
  18. uint8_t Chksum_ret = false;
  19. /* MDOC 00 F0
  20. MBIC 00 F1*/
  21. uint16_t SubUid = ((data[MBIC_SUBUID_0] << 8) & 0xFF00)
  22. |((data[MBIC_SUBUID_1]) & 0x00FF);
  23. /* MBIC_PREAMBLE : 0x16161616 */
  24. if(data[MBIC_PREAMBLE_0] == MBIC_PREAMBLE0
  25. &&data[MBIC_PREAMBLE_1] == MBIC_PREAMBLE1
  26. &&data[MBIC_PREAMBLE_2] == MBIC_PREAMBLE2
  27. &&data[MBIC_PREAMBLE_3] == MBIC_PREAMBLE3){
  28. Chksum_ret = chksum(data,
  29. MBIC_LENGTH_1 - MBIC_SUBUID_0 - 1,
  30. data[MBIC_HEADERCHECKSUM_0]);
  31. if(Chksum_ret == false){
  32. printf("CheckSum Ret False \r\n");
  33. return;
  34. }
  35. if(data[4] == MBIC){
  36. MBIC_FirmwareUpdateStart(data);
  37. }else{
  38. return;
  39. }
  40. }
  41. }
  42. typedef struct{
  43. uint8_t mark[9];
  44. uint8_t type;
  45. uint8_t file_type;
  46. uint8_t version[3];
  47. uint8_t filename[41];
  48. uint8_t creation_time[6];
  49. uint8_t length[4];
  50. uint8_t crc[4];
  51. uint8_t reserved[59];
  52. };
  53. #define MBIC_DOWNLOAD_MARK "JT-NRDAS "
  54. #define MBIC_DOWNLOAD_TYPE 0x20
  55. #define MBIC_DOWNLOAD_FILETYPE 0
  56. #define MBIC_DOWNLOAD_FILENAME "MU jhfs-mbic-nrdas-v00.00.01.mbc MBIC CPU"
  57. void MBIC_DownLoadHeaderCheck(uint8_t* data){
  58. if( strncmp(&data[MBIC_DOWNLOAD_MARK0],MBIC_DOWNLOAD_MARK,sizeof(MBIC_DOWNLOAD_MARK)) != 0){
  59. printf("FUNCTION : %s LINE : %d = %s Mark ERR \r\n",__func__,__LINE__);
  60. return;
  61. }
  62. if( strncmp(&data[MBIC_DOWNLOAD_FILENAME0],MBIC_DOWNLOAD_FILENAME,sizeof(MBIC_DOWNLOAD_FILENAME)) != 0){
  63. printf("FUNCTION : %s LINE : %d = FILENAME ERR ERR \r\n",__func__,__LINE__);
  64. return;
  65. }
  66. MBIC_FirmwareUpdateStart(data);
  67. }
  68. void MBIC_FirmwareUpdateStart(uint8_t* data){
  69. uint8_t ret = 0;
  70. uint32_t crccheck = 0;
  71. uint8_t datatype = data[MBIC_DOWNLOAD_DATASTART];
  72. // crc32();
  73. switch(datatype){
  74. case DOWNLOAD_NOTI_REQ:
  75. break;
  76. case DOWNLOAD_DATA:
  77. break;
  78. case DOWNLOAD_CONFIRM:
  79. break;
  80. case DOWNLOAD_COMPLETE_CMD:
  81. break;
  82. case SYSTEMP_REBOOT:
  83. break;
  84. }
  85. // crccheck = crc32(&data[bluecell_type],data[bluecell_length],data[data[bluecell_length] + 1]);
  86. /* if(crccheck == NO_ERROR){
  87. AckData_Buf[bluecell_type] = FirmwareUpdataAck;
  88. if(data[bluecell_type] == 0xDD || data[bluecell_type] == 0xEE)//Start Firmware byte
  89. ret = Flash_write(&data[0]);
  90. if(ret == 1)
  91. AckData_Buf[bluecell_type] = FirmwareUpdataNak;
  92. }else{
  93. for(uint8_t i = 0; i < data[bluecell_length] + 3; i++)
  94. printf("%02x ",data[i]);
  95. printf("Check Sum error \n");
  96. AckData_Buf[bluecell_type] = FirmwareUpdataNak;
  97. }
  98. AckData_Buf[bluecell_crc] = STH30_CreateCrc(&AckData_Buf[bluecell_type],AckData_Buf[bluecell_length]);
  99. if(data[bluecell_type] != 0xEE && data[bluecell_type] != Bluecell_Reset){
  100. Uart1_Data_Send(&AckData_Buf[bluecell_stx],AckData_Buf[bluecell_length] + 3);
  101. }
  102. if(data[bluecell_type] == 0xEE)
  103. printf("update Complete \n");*/
  104. }