Commit 45738d3a71f6d5137303f9eea0d0a23bfa5eea0d

Authored by oliverhaag
1 parent c3b81871

Checking for End of File Record now since the length doesn't always seem to be c…

…orrect for the firmware files
dsoextractfw/ChangeLog
... ... @@ -5,4 +5,7 @@
5 5  
6 6 2010-08-16 Oliver Haag <oliver.haag@gmail.com>
7 7 * Version 0.6.1:
8   -* USB-devices can be used by any user in the plugdev group now
9 8 \ No newline at end of file
  9 +* USB-devices can be used by any user in the plugdev group now
  10 +
  11 +2010-08-20 Oliver Haag <oliver.haag@gmail.com>
  12 +* Added checking for End of File Record to the hex-writing routine
10 13 \ No newline at end of file
... ...
dsoextractfw/dsoextractfw.c
... ... @@ -2,7 +2,7 @@
2 2 //
3 3 // OpenHantek
4 4 // dsoextractfw.c
5   -// Copyright (C) 2008, 2009 Oleg Khudyakov
  5 +// Copyright (C) 2008 Oleg Khudyakov
6 6 // prcoder@potrebitel.ru
7 7 // Copyright (C) 2010 Oliver Haag
8 8 // oliver.haag@gmail.com
... ... @@ -39,28 +39,35 @@ int extractFirmware(const char* model);
39 39  
40 40 int writeSRecords(const char *filename, unsigned char *ptr, bfd_size_type len)
41 41 {
42   - unsigned char n, *p, crc=0;
  42 + unsigned char n, *p, crc=0, eof;
43 43 bfd_size_type i, t;
44 44 FILE *f;
45   -
  45 +
46 46 if ((f=fopen(filename, "wt")) == NULL)
47 47 {
48 48 perror("Cant' open file for writing");
49 49 fclose(f);
50 50 return -1;
51 51 }
52   -
  52 +
53 53 for(t=0; t <len; t+=22)
54 54 {
  55 + eof = -1; // Always check for End of File Record
55 56 p = ptr + t;
56 57 n = *p;
57 58 fprintf(f, ":%02X", n);
  59 + if(n != 0)
  60 + eof = 0;
58 61 crc = *p++;
59 62 p++;
60 63 fprintf(f, "%04X", *(unsigned short *)p);
  64 + if(*(unsigned short *)p != 0)
  65 + eof = 0;
61 66 crc += *p++;
62 67 crc += *p++;
63 68 fprintf(f, "%02X", *p);
  69 + if(*p != 0x01)
  70 + eof = 0;
64 71 crc += *p++;
65 72 for(i=0; i<n; i++)
66 73 {
... ... @@ -69,9 +76,12 @@ int writeSRecords(const char *filename, unsigned char *ptr, bfd_size_type len)
69 76 }
70 77 crc = 1 + ~crc;
71 78 fprintf(f, "%02X\n", crc);
  79 +
  80 + if(eof)
  81 + break;
72 82 }
73 83 fclose(f);
74   -
  84 +
75 85 return 0;
76 86 }
77 87  
... ...