Debian Codegraph @

cmotfile.cxx

raw symbols SCIP
1 /***************************************************************************
2 cmotfile.cxx - class for handling Motorola files.
3
4 begin : Wed Sep 25 18:58:35 BST 2002
5 copyright : (C) 2002 by Greg Reynolds, Jim Hawkridge
6 email : [email protected]
7
8 2005-11-17: modified by Thomas Fischl <[email protected]>
9 - added support for S1-Files
10 - new parse method
11
12 ***************************************************************************/
13
14 /***************************************************************************
15 * *
16 * This program is free software; you can redistribute it and/or modify *
17 * it under the terms of the GNU General Public License as published by *
18 * the Free Software Foundation; either version 2 of the License, or *
19 * (at your option) any later version. *
20 * *
21 ***************************************************************************/
22 #include "cmotfile.h"cxx . . $ `<file>/cmotfile.h`/
23
24 CMOTFilecxx . . $ CMOTFile#::CMOTFilecxx . . $ CMOTFile#CMOTFile(49f6e7a06ebc5aa8).()
25 {
26 m_fpcxx . . $ CMOTFile#m_fp. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
27 m_pHeadcxx . . $ CMOTFile#m_pHead. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
28 m_pTailcxx . . $ CMOTFile#m_pTail. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
29 }
30
31 CMOTFilecxx . . $ CMOTFile#::~cxx . . $ CMOTFile#`~CMOTFile`(ced63f7c635d850d).CMOTFilecxx . . $ CMOTFile#()
32 {
33
34 }
35
36 int CMOTFilecxx . . $ CMOTFile#::readFilecxx . . $ CMOTFile#readFile(cb7559238bb26814).(const char* pszFilename, int nPageSize)
37 {
38 assertcxx . . $ `<external>/4398592474888995393/assert.h:102:11`!( pszFilename );
39
40 unsigned int nType;
41 unsigned int nLength;
42
43 m_fpcxx . . $ CMOTFile#m_fp. = fopen(pszFilename, "r");
44
45 if( m_fpcxx . . $ CMOTFile#m_fp. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! ) {
46 printf("\nM16 Flash ERROR: couldn't open specified file.");
47 fflush(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!);
48 return 0;
49 }
50
51 if( fscanf(m_fpcxx . . $ CMOTFile#m_fp., "S%1u%2X", &nType, &nLength) != 2 ) {
52 printf("\nM16 Flash ERROR: badly formatted S-record file.");
53 fflush(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!);
54 fclose(m_fpcxx . . $ CMOTFile#m_fp.);
55 return 0;
56 }
57
58 if( nType != 0 ) {
59 printf("\nM16 Flash ERROR: there must be an S0 record (a dummy will do).");
60 fflush(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!);
61 fclose(m_fpcxx . . $ CMOTFile#m_fp.);
62 return 0;
63 }
64
65 /* if we got here then there is an S0 record which is a good start */
66 /* advance m_fp to point to the start of the next line */
67 fscanf(m_fpcxx . . $ CMOTFile#m_fp., "%*[^\n]s");
68 fscanf(m_fpcxx . . $ CMOTFile#m_fp., "\n");
69
70 /* we should check for \r\n in case S records created on windows */
71
72 /* now read the file into our linked list of pages */
73 if( processFilecxx . . $ CMOTFile#processFile(7864480464b09eea).(nPageSize) == 0 )
74 return 0;
75 else
76 return 1;
77 }
78
79 /* return page which belongs to given address. NULL if page does not exist */
80 CPagecxx . . $ CPage#* CMOTFilecxx . . $ CMOTFile#::getPageToAddresscxx . . $ CMOTFile#getPageToAddress(a3f4b00e51c04876).(int nPageSize, long lAddress)
81 {
82 long lBaseAddress = lAddress - (lAddress % nPageSize);
83
84 /* if no page in list */
85 if (m_pTailcxx . . $ CMOTFile#m_pTail. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
86
87 if (m_pTailcxx . . $ CMOTFile#m_pTail.->getAddresscxx . . $ CPage#getAddress(da6335ded91d79c2).() == lBaseAddress) return m_pTailcxx . . $ CMOTFile#m_pTail.;
88
89 /* search for page with given base address */
90 CPagecxx . . $ CPage#* pCurrent = m_pHeadcxx . . $ CMOTFile#m_pHead.;
91 do {
92 if (pCurrent->getAddresscxx . . $ CPage#getAddress(da6335ded91d79c2).() == lBaseAddress) return pCurrent;
93 pCurrent = pCurrent->getNextcxx . . $ CPage#getNext(b1c0934cbb896107).();
94 } while (pCurrent != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
95
96 /* no page found */
97 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
98 }
99
100 /* convert the file contents into a linked list of pPages */
101 int CMOTFilecxx . . $ CMOTFile#::processFilecxx . . $ CMOTFile#processFile(7864480464b09eea).(int nPageSize)
102 {
103 assertcxx . . $ `<external>/4398592474888995393/assert.h:102:11`!( m_fp );
104 assertcxx . . $ `<external>/4398592474888995393/assert.h:102:11`!( nPageSize > 0 );
105
106 unsigned int nType;
107 unsigned int nLength;
108 unsigned long lAddress;
109 unsigned int nVal;
110 unsigned int n;
111
112
113 while( true ) {
114
115 /* read a line's header data */
116 if( fscanf(m_fpcxx . . $ CMOTFile#m_fp., "S%1u%2X", &nType, &nLength) != 2 ) {
117 printf("\nM16 Flash ERROR: badly formatted input file.");
118 fflush(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!);
119 return 0;
120 }
121
122 /* extract address */
123 switch (nType) {
124 case 1:
125 // 16 bit addresses
126 if( fscanf(m_fpcxx . . $ CMOTFile#m_fp., "%4lX", &lAddress) != 1 ) {
127 printf("\nM16 Flash ERROR: bad address format.");
128 fflush(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!);
129 return 0;
130 }
131 nLength-=3;
132 break;
133 case 2:
134 // 24 bit addresses
135 if( fscanf(m_fpcxx . . $ CMOTFile#m_fp., "%6lX", &lAddress) != 1 ) {
136 printf("\nM16 Flash ERROR: bad address format.");
137 fflush(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!);
138 return 0;
139 }
140 nLength-=4;
141 break;
142 default:
143 // no address
144 break;
145 }
146
147 /* process file */
148 switch (nType) {
149 case 1:
150 case 2:
151
152 CPagecxx . . $ CPage#* page;
153 /* now read the data */
154 for( n = 0; n < nLength; n++ ) {
155
156 if( fscanf(m_fpcxx . . $ CMOTFile#m_fp., "%2X", &nVal) != 1 ) {
157 printf("\nM16 Flash ERROR: bad data record in file.");
158 fflush(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!);
159 fclose(m_fpcxx . . $ CMOTFile#m_fp.);
160 return 0;
161 }
162
163 page = getPageToAddresscxx . . $ CMOTFile#getPageToAddress(a3f4b00e51c04876).(nPageSize, lAddress);
164 if (page == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) {
165 /* new page */
166
167 page = new CPagecxx . . $ CPage#(nPageSize);
168 page->setAddresscxx . . $ CPage#setAddress(1624ee8275b10bda).(lAddress - (lAddress % nPageSize));
169
170 if (m_pHeadcxx . . $ CMOTFile#m_pHead. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) m_pHeadcxx . . $ CMOTFile#m_pHead. = page;
171 else m_pTailcxx . . $ CMOTFile#m_pTail.->setNextcxx . . $ CPage#setNext(6c8a29529bc7b2bf).(page);
172
173 m_pTailcxx . . $ CMOTFile#m_pTail. = page;
174 }
175
176 // printf("adr: %6lX base: %6lX val: %2X\n", lAddress, page->getAddress(), nVal);
177 page->setBytecxx . . $ CPage#setByte(9633529ce3c4ff50).(lAddress % nPageSize, nVal);
178
179 lAddress++;
180 }
181
182 break;
183
184 case 8:
185 case 9:
186 /* S8 and S9 indicates end of file, so clean exit */
187 fclose(m_fpcxx . . $ CMOTFile#m_fp.);
188 return 8;
189 break;
190 case 0:
191 /* header do nothing */
192 break;
193 default:
194 /* unknown record type */
195 printf("\nM16 Flash ERROR: unknown record type");
196 fflush(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!);
197 fclose(m_fpcxx . . $ CMOTFile#m_fp.);
198 return 0;
199 }
200
201 /* loose the checksum and end of line */
202 fscanf(m_fpcxx . . $ CMOTFile#m_fp., "%*[^\n]");
203 fscanf(m_fpcxx . . $ CMOTFile#m_fp., "\n");
204 }
205 }