Subversion Repositories pentevo

Rev

Rev 908 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed | ?url?

  1. #include <stdint.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5.  
  6. // for non-boot area of 0x00000..0x1DFFF
  7. #define ADDR_RANGE (0x1E000)
  8.  
  9. // fill value
  10. #define FILL_VALUE (0xFF)
  11.  
  12. #include "ihex.h"
  13. #include "crc.h"
  14.  
  15.  
  16. uint8_t buffer[ADDR_RANGE];
  17.  
  18. int main(int argc, char ** argv)
  19. {
  20.         int was_error = 0;
  21.  
  22.         uint16_t crc;
  23.  
  24.  
  25.         if( argc!=3 )
  26.         {
  27.                 printf("Fix CRC for the ZXEvo AVR firmware in order to pass bootloader CRC check.\n");
  28.                 printf("===\n");
  29.                 printf("Usage: crcfix <infile> <outfile>\n");
  30.  
  31.                 if( argc==2 )
  32.                 {
  33.                         if( !strcmp(argv[1],"-h") || !strcmp(argv[1],"--help") )
  34.                                 exit(0);
  35.                 }
  36.  
  37.                 exit(1);
  38.         }
  39.  
  40.  
  41.         // parse input file
  42.         was_error = was_error || !parse_ihex(buffer, 0, 0, ADDR_RANGE-2, FILL_VALUE, argv[1]);
  43.  
  44. /*
  45. for(int i=0;i<ADDR_RANGE;i+=16)
  46. {
  47. printf("%05X:",i);
  48. for(int j=0;j<16;j++)
  49. printf("%02X",buffer[i+j]);
  50. printf("\n");
  51. }
  52.  
  53. buffer[0x1DFF0] = 0x4e;
  54. buffer[0x1DFF1] = 0x6f;
  55. buffer[0x1DFF2] = 0x20;
  56. buffer[0x1DFF3] = 0x69;
  57. buffer[0x1DFF4] = 0x6e;
  58. buffer[0x1DFF5] = 0x66;
  59. buffer[0x1DFF6] = 0x6f;
  60. buffer[0x1DFF7] = 0x00;
  61. buffer[0x1DFF8] = 0x00;
  62. buffer[0x1DFF9] = 0x00;
  63. buffer[0x1DFFA] = 0x00;
  64. buffer[0x1DFFB] = 0x00;
  65. buffer[0x1DFFC] = 0x76;
  66. buffer[0x1DFFD] = 0xa9;
  67. */
  68.  
  69.  
  70.         // calc CRC and put it into last two bytes of the buffer
  71.         if( !was_error )
  72.         {
  73.                 crc = calc_crc(buffer,ADDR_RANGE-2);
  74.  
  75.                 buffer[ADDR_RANGE-2] = crc>>8;
  76.                 buffer[ADDR_RANGE-1] = crc;
  77.         }
  78.  
  79.  
  80.  
  81. //printf("crc=%04x\n",crc);
  82.  
  83.  
  84. /*
  85. printf("<none>: %04x\n",calc_crc(NULL,0));
  86.  
  87. char * a="A";
  88. printf("%s: %04x\n",a,calc_crc(a,strlen(a)));
  89.  
  90. a="123456789";
  91. printf("%s: %04x\n",a,calc_crc(a,strlen(a)));
  92.  
  93. char b[256];
  94. for(int i=0;i<256;i++) b[i]='A';
  95. printf("256*\"A\": %04x\n",calc_crc(b,256));
  96. */
  97.  
  98. //printf("write_ihex! was_error=%d\n",was_error);
  99.  
  100.  
  101.  
  102.         // write back new IHEX with embedded CRC
  103.         was_error = was_error || !write_ihex(buffer,0,0,ADDR_RANGE,argv[2]);
  104.  
  105.  
  106.  
  107.         return was_error ? 1 : 0;
  108. }
  109.  
  110.