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