@@ -1,323 +1,323 | |||
|
1 | 1 | /*------------------------------------------------------------------------------ |
|
2 | 2 | -- This file is a part of the SocExplorer Software |
|
3 | 3 | -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS |
|
4 | 4 | -- |
|
5 | 5 | -- This program is free software; you can redistribute it and/or modify |
|
6 | 6 | -- it under the terms of the GNU General Public License as published by |
|
7 | 7 | -- the Free Software Foundation; either version 3 of the License, or |
|
8 | 8 | -- (at your option) any later version. |
|
9 | 9 | -- |
|
10 | 10 | -- This program is distributed in the hope that it will be useful, |
|
11 | 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 | 13 | -- GNU General Public License for more details. |
|
14 | 14 | -- |
|
15 | 15 | -- You should have received a copy of the GNU General Public License |
|
16 | 16 | -- along with this program; if not, write to the Free Software |
|
17 | 17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 | 18 | -------------------------------------------------------------------------------*/ |
|
19 | 19 | /*-- Author : Alexis Jeandet |
|
20 | 20 | -- Mail : alexis.jeandet@lpp.polytechnique.fr |
|
21 | 21 | ----------------------------------------------------------------------------*/ |
|
22 | 22 | #include "dsu3plugin.h" |
|
23 | 23 | #include <QFileDialog> |
|
24 | 24 | #include <QDir> |
|
25 | 25 | #include "dsu3pluginpywrapper.h" |
|
26 | 26 | #include <socexplorerengine.h> |
|
27 | 27 | |
|
28 | 28 | |
|
29 | 29 | struct acceptedMemctrlr_str |
|
30 | 30 | { |
|
31 | 31 | int vid; |
|
32 | 32 | int pid; |
|
33 | 33 | const char* name; |
|
34 | 34 | }; |
|
35 | 35 | |
|
36 | 36 | const struct acceptedMemctrlr_str acceptedMemctrlr[]= |
|
37 | 37 | { |
|
38 |
{0x0f |
|
|
38 | {0x04,0x0f,"MCTRL"}, | |
|
39 | 39 | {0x01,0x51,"FTSRCTRL"}, |
|
40 | 40 | {0x20,0x01,"SRCTRLE_0WS" }, |
|
41 | 41 | {0x20,0x02,"SRCTRLE_1WS" } |
|
42 | 42 | }; |
|
43 | 43 | |
|
44 |
#define acceptedMemctrlrCnt |
|
|
44 | #define acceptedMemctrlrCnt 4 | |
|
45 | 45 | |
|
46 | 46 | dsu3plugin::dsu3plugin(QWidget *parent):socexplorerplugin(parent,false) |
|
47 | 47 | { |
|
48 | 48 | this->UI = new dsu3pluginui(); |
|
49 | 49 | this->setWidget((QWidget*)this->UI); |
|
50 | 50 | this->elfparserInst = new elfparser(); |
|
51 | 51 | this->pyObject = new dsu3pluginPywrapper(this); |
|
52 | 52 | QObject::connect(((dsu3pluginPywrapper*)this->pyObject),SIGNAL(openFile(QString)),this,SLOT(openFile(QString))); |
|
53 | 53 | QObject::connect(((dsu3pluginPywrapper*)this->pyObject),SIGNAL(loadFile()),this,SLOT(flashTarget())); |
|
54 | 54 | QObject::connect(((dsu3pluginPywrapper*)this->pyObject),SIGNAL(run()),this,SLOT(run())); |
|
55 | 55 | QObject::connect(((dsu3pluginPywrapper*)this->pyObject),SIGNAL(stop()),this,SLOT(stop())); |
|
56 | 56 | QObject::connect(((dsu3pluginPywrapper*)this->pyObject),SIGNAL(cacheEnable()),this,SLOT(cacheEnable())); |
|
57 | 57 | QObject::connect(((dsu3pluginPywrapper*)this->pyObject),SIGNAL(cacheDisable()),this,SLOT(cacheDisable())); |
|
58 | 58 | QObject::connect(((dsu3pluginPywrapper*)this->pyObject),SIGNAL(setCacheEnable(bool)),this,SLOT(setCacheEnable(bool))); |
|
59 | 59 | |
|
60 | 60 | connect(this->UI,SIGNAL(openFile()),this,SLOT(openFile())); |
|
61 | 61 | connect(this->UI,SIGNAL(flashTarget()),this,SLOT(flashTarget())); |
|
62 | 62 | connect(this->UI,SIGNAL(run()),this,SLOT(toggleRun())); |
|
63 | 63 | connect(this,SIGNAL(updateInfo(elfparser*)),this->UI,SIGNAL(updateInfo(elfparser*))); |
|
64 | 64 | this->running = false; |
|
65 | 65 | } |
|
66 | 66 | |
|
67 | 67 | |
|
68 | 68 | dsu3plugin::~dsu3plugin() |
|
69 | 69 | { |
|
70 | 70 | |
|
71 | 71 | } |
|
72 | 72 | |
|
73 | 73 | |
|
74 | 74 | void dsu3plugin::openFile() |
|
75 | 75 | { |
|
76 | 76 | QString filename = QFileDialog::getOpenFileName(this,tr("Open elf File"), QDir::homePath(), tr("Elf Files (*)")); |
|
77 | 77 | if(filename!="") |
|
78 | 78 | { |
|
79 | 79 | this->openFile(filename); |
|
80 | 80 | } |
|
81 | 81 | } |
|
82 | 82 | |
|
83 | 83 | void dsu3plugin::openFile(QString fileName) |
|
84 | 84 | { |
|
85 | 85 | this->elfparserInst->setFilename(fileName); |
|
86 | 86 | emit this->updateInfo(this->elfparserInst); |
|
87 | 87 | } |
|
88 | 88 | |
|
89 | 89 | bool dsu3plugin::configureTarget() |
|
90 | 90 | { |
|
91 | 91 | if(parent==NULL) |
|
92 | 92 | return false; |
|
93 | 93 | unsigned int DSUBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01 , 0x004,0); |
|
94 | 94 | if(DSUBASEADDRESS == (unsigned int)-1) |
|
95 | 95 | DSUBASEADDRESS = 0x90000000; |
|
96 | 96 | unsigned int MCTRLBASEADDRESS =-1; |
|
97 | 97 | for(int i=0; i<acceptedMemctrlrCnt;i++) |
|
98 | 98 | { |
|
99 | 99 | MCTRLBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,acceptedMemctrlr[i].vid , acceptedMemctrlr[i].pid,0); |
|
100 | 100 | if(MCTRLBASEADDRESS != (unsigned int)-1) |
|
101 | 101 | { |
|
102 | 102 | SocExplorerEngine::message(this,QString("Found %1 @%2").arg(acceptedMemctrlr[i].name).arg(MCTRLBASEADDRESS,8,16),1); |
|
103 | 103 | break; |
|
104 | 104 | } |
|
105 | 105 | } |
|
106 | 106 | if(MCTRLBASEADDRESS == (unsigned int)-1) |
|
107 | 107 | { |
|
108 | 108 | SocExplorerEngine::message(this,"Can't any compatible memory controller",1); |
|
109 | 109 | return false; |
|
110 | 110 | } |
|
111 | 111 | |
|
112 | 112 | |
|
113 | 113 | //Force a debug break |
|
114 | 114 | WriteRegs(uIntlist()<<0x0000002f,(unsigned int)DSUBASEADDRESS); |
|
115 | 115 | WriteRegs(uIntlist()<<0x0000ffff,(unsigned int)DSUBASEADDRESS+0x20); |
|
116 | 116 | //Clear time tag counter |
|
117 | 117 | WriteRegs(uIntlist()<<0,(unsigned int)DSUBASEADDRESS+0x8); |
|
118 | 118 | |
|
119 | 119 | //Clear ASR registers |
|
120 | 120 | WriteRegs(uIntlist()<<0<<0<<0,(unsigned int)DSUBASEADDRESS+0x400040); |
|
121 | 121 | WriteRegs(uIntlist()<<0x2,(unsigned int)DSUBASEADDRESS+0x400024); |
|
122 | 122 | WriteRegs(uIntlist()<<0<<0<<0<<0<<0<<0<<0<<0,(unsigned int)DSUBASEADDRESS+0x400060); |
|
123 | 123 | WriteRegs(uIntlist()<<0,(unsigned int)DSUBASEADDRESS+0x48); |
|
124 | 124 | WriteRegs(uIntlist()<<0,(unsigned int)DSUBASEADDRESS+0x000004C); |
|
125 | 125 | WriteRegs(uIntlist()<<0,(unsigned int)DSUBASEADDRESS+0x400040); |
|
126 | 126 | |
|
127 | 127 | |
|
128 | 128 | |
|
129 | 129 | WriteRegs(uIntlist()<<0x2FF<<0xE60<<0,(unsigned int)MCTRLBASEADDRESS); |
|
130 | 130 | |
|
131 | 131 | |
|
132 | 132 | WriteRegs(uIntlist()<<0<<0<<0<<0,(unsigned int)DSUBASEADDRESS+0x400060); |
|
133 | 133 | WriteRegs(uIntlist()<<0x0000FFFF,(unsigned int)DSUBASEADDRESS+0x24); |
|
134 | 134 | |
|
135 | 135 | unsigned int buff=0; |
|
136 | 136 | // for(int i=0;i<1567;i++) |
|
137 | 137 | // { |
|
138 | 138 | // parent->Write(&buff,(unsigned int)1,DSUBASEADDRESS+0x300000+(4*i)); |
|
139 | 139 | // } |
|
140 | 140 | memSet(DSUBASEADDRESS+0x300000,0,1567); |
|
141 | 141 | WriteRegs(uIntlist()<<0<<0xF30000E0<<0x00000002<<0x40000000<<0x40000000<<0x40000004<<0x1000000,(unsigned int)DSUBASEADDRESS+0x400000); |
|
142 | 142 | WriteRegs(uIntlist()<<0<<0<<0<<0<<0<<0<<0x403ffff0<<0<<0<<0<<0<<0<<0<<0<<0<<0<<0<<0<<0<<0<<0<<0<<0<<0,(unsigned int)DSUBASEADDRESS+0x300020); |
|
143 | 143 | WriteRegs(uIntlist()<<0x000002EF,(unsigned int)DSUBASEADDRESS); |
|
144 | 144 | |
|
145 | 145 | //Disable interrupts |
|
146 | 146 | unsigned int APBIRQCTRLRBASEADD = (unsigned int)SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,1,0x0d,0); |
|
147 | 147 | if(APBIRQCTRLRBASEADD == (unsigned int)-1) |
|
148 | 148 | return false; |
|
149 | 149 | WriteRegs(uIntlist()<<0x00000000,APBIRQCTRLRBASEADD+0x040); |
|
150 | 150 | WriteRegs(uIntlist()<<0xFFFE0000,APBIRQCTRLRBASEADD+0x080); |
|
151 | 151 | WriteRegs(uIntlist()<<0<<0,APBIRQCTRLRBASEADD); |
|
152 | 152 | |
|
153 | 153 | //Set up timer |
|
154 | 154 | unsigned int APBTIMERBASEADD = (unsigned int)SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,1,0x11,0); |
|
155 | 155 | if(APBTIMERBASEADD == (unsigned int)-1) |
|
156 | 156 | return false; |
|
157 | 157 | WriteRegs(uIntlist()<<0xffffffff,APBTIMERBASEADD+0x014); |
|
158 | 158 | WriteRegs(uIntlist()<<0x00000018,APBTIMERBASEADD+0x04); |
|
159 | 159 | WriteRegs(uIntlist()<<0x00000007,APBTIMERBASEADD+0x018); |
|
160 | 160 | return true; |
|
161 | 161 | } |
|
162 | 162 | |
|
163 | 163 | bool dsu3plugin::cacheDisable() |
|
164 | 164 | { |
|
165 | 165 | return setCacheEnable(false); |
|
166 | 166 | } |
|
167 | 167 | |
|
168 | 168 | bool dsu3plugin::cacheEnable() |
|
169 | 169 | { |
|
170 | 170 | return setCacheEnable(true); |
|
171 | 171 | } |
|
172 | 172 | |
|
173 | 173 | bool dsu3plugin::setCacheEnable(bool enabled) |
|
174 | 174 | { |
|
175 | 175 | if(parent==NULL) |
|
176 | 176 | return false; |
|
177 | 177 | unsigned int DSUBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01 , 0x004,0); |
|
178 | 178 | if(DSUBASEADDRESS == (unsigned int)-1) |
|
179 | 179 | DSUBASEADDRESS = 0x90000000; |
|
180 | 180 | WriteRegs(uIntlist()<<2,DSUBASEADDRESS+0x400024); |
|
181 | 181 | unsigned int reg = ReadReg(DSUBASEADDRESS+0x700000); |
|
182 | 182 | if(enabled) |
|
183 | 183 | { |
|
184 | 184 | WriteRegs(uIntlist()<<(0x0001000F|reg),DSUBASEADDRESS+0x700000); |
|
185 | 185 | //flushes cache. |
|
186 | 186 | WriteRegs(uIntlist()<<(0x0061000F|reg),DSUBASEADDRESS+0x700000); |
|
187 | 187 | } |
|
188 | 188 | else |
|
189 | 189 | { |
|
190 | 190 | WriteRegs(uIntlist()<<((!0x0001000F)®),DSUBASEADDRESS+0x700000); |
|
191 | 191 | WriteRegs(uIntlist()<<(0x00600000|reg),DSUBASEADDRESS+0x700000); |
|
192 | 192 | } |
|
193 | 193 | return true; |
|
194 | 194 | } |
|
195 | 195 | |
|
196 | 196 | bool dsu3plugin::flashTarget() |
|
197 | 197 | { |
|
198 | 198 | stop(); |
|
199 | 199 | cacheDisable(); |
|
200 | 200 | configureTarget(); |
|
201 | 201 | /*Write .text*/ |
|
202 | 202 | this->writeSection(".text"); |
|
203 | 203 | /*Write .data*/ |
|
204 | 204 | this->writeSection(".data"); |
|
205 | 205 | return true; |
|
206 | 206 | } |
|
207 | 207 | |
|
208 | 208 | void dsu3plugin::run() |
|
209 | 209 | { |
|
210 | 210 | unsigned int DSUBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01 , 0x004,0); |
|
211 | 211 | if(DSUBASEADDRESS == (unsigned int)-1) |
|
212 | 212 | DSUBASEADDRESS = 0x90000000; |
|
213 | 213 | WriteRegs(uIntlist()<<0,DSUBASEADDRESS+0x020); |
|
214 | 214 | this->running = true; |
|
215 | 215 | this->UI->setRunning(true); |
|
216 | 216 | } |
|
217 | 217 | |
|
218 | 218 | void dsu3plugin::stop() |
|
219 | 219 | { |
|
220 | 220 | unsigned int DSUBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01 , 0x004,0); |
|
221 | 221 | if(DSUBASEADDRESS == (unsigned int)-1) |
|
222 | 222 | DSUBASEADDRESS = 0x90000000; |
|
223 | 223 | WriteRegs(uIntlist()<<0xFFFF,DSUBASEADDRESS+0x020); |
|
224 | 224 | this->running = false; |
|
225 | 225 | this->UI->setRunning(false); |
|
226 | 226 | } |
|
227 | 227 | |
|
228 | 228 | void dsu3plugin::toggleRun() |
|
229 | 229 | { |
|
230 | 230 | if(this->running) |
|
231 | 231 | this->stop(); |
|
232 | 232 | else |
|
233 | 233 | this->run(); |
|
234 | 234 | } |
|
235 | 235 | |
|
236 | 236 | void dsu3plugin::WriteRegs(uIntlist Values, unsigned int address) |
|
237 | 237 | { |
|
238 | 238 | unsigned int* buff; |
|
239 | 239 | buff = (unsigned int*)malloc(Values.count()*sizeof(unsigned int)); |
|
240 | 240 | for(int i=0;i<Values.count();i++) |
|
241 | 241 | { |
|
242 | 242 | buff[i]=Values.at(i); |
|
243 | 243 | } |
|
244 | 244 | parent->Write(buff,(unsigned int)Values.count(),address); |
|
245 | 245 | free(buff); |
|
246 | 246 | } |
|
247 | 247 | |
|
248 | 248 | unsigned int dsu3plugin::ReadReg(unsigned int address) |
|
249 | 249 | { |
|
250 | 250 | unsigned int buff; |
|
251 | 251 | parent->Read(&buff,1,address); |
|
252 | 252 | return buff; |
|
253 | 253 | } |
|
254 | 254 | |
|
255 | 255 | void dsu3plugin::writeSection(int index) |
|
256 | 256 | { |
|
257 | 257 | char* buffch=NULL; |
|
258 | 258 | unsigned int* buff; |
|
259 | 259 | int size = this->elfparserInst->getSectionDatasz(index); |
|
260 | 260 | int sizeInt = size/4; |
|
261 | 261 | if(parent==NULL) |
|
262 | 262 | return; |
|
263 | 263 | this->elfparserInst->getSectionData(index,&buffch); |
|
264 | 264 | buff = (unsigned int*)malloc(((size/4)+1)*sizeof(unsigned int)); |
|
265 | 265 | for(int i=0;i<sizeInt;i++) |
|
266 | 266 | { |
|
267 | 267 | buff[i] = 0x0FF & ((unsigned int)buffch[4*i]); |
|
268 | 268 | buff[i] = (buff[i]<<8) + (0x0FF & ((unsigned int)buffch[(4*i)+1])); |
|
269 | 269 | buff[i] = (buff[i]<<8) + (0x0FF & ((unsigned int)buffch[(4*i)+2])); |
|
270 | 270 | buff[i] = (buff[i]<<8) + (0x0FF & ((unsigned int)buffch[(4*i)+3])); |
|
271 | 271 | } |
|
272 | 272 | if(size%4) |
|
273 | 273 | { |
|
274 | 274 | buff[sizeInt]=0; |
|
275 | 275 | for(int i=(size%4);i>0;i--) |
|
276 | 276 | { |
|
277 | 277 | buff[sizeInt] = (buff[sizeInt]<<8) + (0x0FF & ((unsigned int)buffch[size-i])); |
|
278 | 278 | } |
|
279 | 279 | sizeInt++; |
|
280 | 280 | } |
|
281 | 281 | parent->Write(buff,(unsigned int)sizeInt,(unsigned int)this->elfparserInst->getSectionPaddr(index)); |
|
282 | 282 | free(buff); |
|
283 | 283 | } |
|
284 | 284 | |
|
285 | 285 | void dsu3plugin::writeSection(const QString &name) |
|
286 | 286 | { |
|
287 | 287 | for(int i=0;i<this->elfparserInst->getSectioncount();i++) |
|
288 | 288 | { |
|
289 | 289 | if(!this->elfparserInst->getSectionName(i).compare(name)) |
|
290 | 290 | { |
|
291 | 291 | printf("about to write section %s @ 0x%x size = %d\n",elfparserInst->getSectionName(i).toStdString().c_str(),elfparserInst->getSectionPaddr(i),elfparserInst->getSectionMemsz(i)); |
|
292 | 292 | writeSection(i); |
|
293 | 293 | } |
|
294 | 294 | } |
|
295 | 295 | } |
|
296 | 296 | |
|
297 | 297 | |
|
298 | 298 | unsigned int dsu3plugin::Write(unsigned int *Value,unsigned int count,unsigned int address) |
|
299 | 299 | { |
|
300 | 300 | if(parent!=NULL) |
|
301 | 301 | return parent->Write(Value,count,address); |
|
302 | 302 | return 0; |
|
303 | 303 | } |
|
304 | 304 | |
|
305 | 305 | bool dsu3plugin::memSet(unsigned int address,int value, unsigned int count) |
|
306 | 306 | { |
|
307 | 307 | unsigned int* buffer = (unsigned int*)malloc(count*sizeof(unsigned int)); |
|
308 | 308 | if(buffer!=NULL) |
|
309 | 309 | { |
|
310 | 310 | memset((void*)buffer,value,count*sizeof(unsigned int)); |
|
311 | 311 | parent->Write(buffer,count,address); |
|
312 | 312 | free(buffer ); |
|
313 | 313 | return true; |
|
314 | 314 | } |
|
315 | 315 | return false; |
|
316 | 316 | } |
|
317 | 317 | |
|
318 | 318 | unsigned int dsu3plugin::Read(unsigned int *Value,unsigned int count, unsigned int address) |
|
319 | 319 | { |
|
320 | 320 | if(parent!=NULL) |
|
321 | 321 | return parent->Read(Value,count,address); |
|
322 | 322 | return 0; |
|
323 | 323 | } |
General Comments 0
You need to be logged in to leave comments.
Login now