MBIC_BootLoader.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. if(data[4] == MBIC){
  34. MBIC_FirmwareUpdateStart(data);
  35. }
  36. }
  37. }
  38. typedef struct{
  39. uint8_t mark[9];
  40. uint8_t type;
  41. uint8_t file_type;
  42. uint8_t version[3];
  43. uint8_t filename[41];
  44. uint8_t creation_time[6];
  45. uint8_t length[4];
  46. uint8_t crc[4];
  47. uint8_t reserved[59];
  48. };
  49. #define MBIC_DOWNLOAD_MARK "JT-NRDAS "
  50. #define MBIC_DOWNLOAD_TYPE 0x20
  51. #define MBIC_DOWNLOAD_FILETYPE 0
  52. #define MBIC_DOWNLOAD_FILENAME "MU jhfs-mbic-nrdas-v00.00.01.mbc MBIC CPU"
  53. void MBIC_DownLoadHeaderCheck(uint8_t* data){
  54. if( strncmp(&data[MBIC_DOWNLOAD_MARK0],MBIC_DOWNLOAD_MARK,sizeof(MBIC_DOWNLOAD_MARK)) != 0){
  55. printf("FUNCTION : %s LINE : %d = %s Mark ERR \r\n",__func__,__LINE__);
  56. }
  57. if( strncmp(&data[MBIC_DOWNLOAD_FILENAME0],MBIC_DOWNLOAD_FILENAME,sizeof(MBIC_DOWNLOAD_FILENAME)) != 0){
  58. printf("FUNCTION : %s LINE : %d = FILENAME ERR ERR \r\n",__func__,__LINE__);
  59. }
  60. MBIC_FirmwareUpdateStart(data);
  61. }
  62. void MBIC_FirmwareUpdateStart(uint8_t* data){
  63. uint8_t ret = 0;
  64. uint32_t crccheck = 0;
  65. uint8_t datatype = data[MBIC_DOWNLOAD_DATASTART];
  66. // crc32();
  67. switch(datatype){
  68. case DOWNLOAD_NOTI_REQ:
  69. break;
  70. case DOWNLOAD_DATA:
  71. break;
  72. case DOWNLOAD_CONFIRM:
  73. break;
  74. case DOWNLOAD_COMPLETE_CMD:
  75. break;
  76. case SYSTEMP_REBOOT:
  77. break;
  78. }
  79. // crccheck = crc32(&data[bluecell_type],data[bluecell_length],data[data[bluecell_length] + 1]);
  80. /* if(crccheck == NO_ERROR){
  81. AckData_Buf[bluecell_type] = FirmwareUpdataAck;
  82. if(data[bluecell_type] == 0xDD || data[bluecell_type] == 0xEE)//Start Firmware byte
  83. ret = Flash_write(&data[0]);
  84. if(ret == 1)
  85. AckData_Buf[bluecell_type] = FirmwareUpdataNak;
  86. }else{
  87. for(uint8_t i = 0; i < data[bluecell_length] + 3; i++)
  88. printf("%02x ",data[i]);
  89. printf("Check Sum error \n");
  90. AckData_Buf[bluecell_type] = FirmwareUpdataNak;
  91. }
  92. AckData_Buf[bluecell_crc] = STH30_CreateCrc(&AckData_Buf[bluecell_type],AckData_Buf[bluecell_length]);
  93. if(data[bluecell_type] != 0xEE && data[bluecell_type] != Bluecell_Reset){
  94. Uart1_Data_Send(&AckData_Buf[bluecell_stx],AckData_Buf[bluecell_length] + 3);
  95. }
  96. if(data[bluecell_type] == 0xEE)
  97. printf("update Complete \n");*/
  98. }