##// END OF EJS Templates
dsu3plugin:...
Jeandet Alexis -
r94:8ff48a64ef09 default draft
parent child
Show More
@@ -1,342 +1,342
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 <socexplorerengine.h>
26 26
27 27
28 28 struct acceptedMemctrlr_str
29 29 {
30 30 int vid;
31 31 int pid;
32 32 const char* name;
33 33 };
34 34
35 35 const struct acceptedMemctrlr_str acceptedMemctrlr[]=
36 36 {
37 37 {0x04,0x0f,"MCTRL"},
38 38 {0x01,0x51,"FTSRCTRL"},
39 39 {0x20,0x01,"SRCTRLE_0WS" },
40 40 {0x20,0x02,"SRCTRLE_1WS" }
41 41 };
42 42
43 43 #define acceptedMemctrlrCnt 4
44 44
45 45 dsu3plugin::dsu3plugin(QWidget *parent):socexplorerplugin(parent,false)
46 46 {
47 47 this->UI = new dsu3pluginui();
48 48 this->setWidget((QWidget*)this->UI);
49 49 this->elfFile = new ElfFile();
50 50 connect(this->UI,SIGNAL(openFile()),this,SLOT(openFile()));
51 51 connect(this->UI,SIGNAL(flashTarget()),this,SLOT(flashTarget()));
52 52 connect(this->UI,SIGNAL(run()),this,SLOT(toggleRun()));
53 53 connect(this,SIGNAL(updateInfo(ElfFile*)),this->UI,SLOT(updateInfo(ElfFile*)));
54 54 this->running = false;
55 55 }
56 56
57 57
58 58 dsu3plugin::~dsu3plugin()
59 59 {
60 60
61 61 }
62 62
63 63
64 64 void dsu3plugin::openFile()
65 65 {
66 66 QString filename = QFileDialog::getOpenFileName(this,tr("Open elf File"), QDir::homePath(), tr("Elf Files (*)"));
67 67 if(filename!="")
68 68 {
69 69 this->openFile(filename);
70 70 }
71 71 }
72 72
73 73 void dsu3plugin::openFile(QString fileName)
74 74 {
75 75 this->elfFile->openFile(fileName);
76 76 emit this->updateInfo(this->elfFile);
77 77 }
78 78
79 79 bool dsu3plugin::configureTarget()
80 80 {
81 81 int detectedMctrlr=-1;
82 82 if(parent==NULL)
83 83 return false;
84 84 unsigned int DSUBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01 , 0x004,0);
85 85 if(DSUBASEADDRESS == (unsigned int)-1)
86 86 DSUBASEADDRESS = 0x90000000;
87 87 unsigned int MCTRLBASEADDRESS =-1;
88 88 for(int i=0; i<acceptedMemctrlrCnt;i++)
89 89 {
90 90 MCTRLBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,acceptedMemctrlr[i].vid , acceptedMemctrlr[i].pid,0);
91 91 if(MCTRLBASEADDRESS != (unsigned int)-1)
92 92 {
93 93 SocExplorerEngine::message(this,QString("Found %1 @%2").arg(acceptedMemctrlr[i].name).arg(MCTRLBASEADDRESS,8,16),1);
94 94 detectedMctrlr=i;
95 95 break;
96 96 }
97 97 }
98 98 if(MCTRLBASEADDRESS == (unsigned int)-1)
99 99 {
100 100 SocExplorerEngine::message(this,"Can't find any compatible memory controller",1);
101 101 // return false;
102 102 }
103 103
104 104
105 105 //Force a debug break
106 106 WriteRegs(uIntlist()<<0x0000002f,(unsigned int)DSUBASEADDRESS);
107 107 WriteRegs(uIntlist()<<0x0000ffff,(unsigned int)DSUBASEADDRESS+0x20);
108 108 //Clear time tag counter
109 109 WriteRegs(uIntlist()<<0,(unsigned int)DSUBASEADDRESS+0x8);
110 110
111 111 //Clear ASR registers
112 112 WriteRegs(uIntlist()<<0<<0<<0,(unsigned int)DSUBASEADDRESS+0x400040);
113 113 WriteRegs(uIntlist()<<0x2,(unsigned int)DSUBASEADDRESS+0x400024);
114 114 WriteRegs(uIntlist()<<0<<0<<0<<0<<0<<0<<0<<0,(unsigned int)DSUBASEADDRESS+0x400060);
115 115 WriteRegs(uIntlist()<<0,(unsigned int)DSUBASEADDRESS+0x48);
116 116 WriteRegs(uIntlist()<<0,(unsigned int)DSUBASEADDRESS+0x000004C);
117 117 WriteRegs(uIntlist()<<0,(unsigned int)DSUBASEADDRESS+0x400040);
118 118
119 119 // {0x04,0x0f,"MCTRL"},
120 120 // {0x01,0x51,"FTSRCTRL"},
121 121 // {0x20,0x01,"SRCTRLE_0WS" },
122 122 // {0x20,0x02,"SRCTRLE_1WS" }
123 123 if(QString(acceptedMemctrlr[detectedMctrlr].name)=="MCTRL" || QString(acceptedMemctrlr[detectedMctrlr].name)=="FTSRCTRL" )
124 124 {
125 125 WriteRegs(uIntlist()<<0x2FF<<0xE60<<0,(unsigned int)MCTRLBASEADDRESS);
126 126 }
127 127 if(QString(acceptedMemctrlr[detectedMctrlr].name)=="SRCTRLE_0WS" || QString(acceptedMemctrlr[detectedMctrlr].name)=="SRCTRLE_1WS" )
128 128 {
129 129 //let's perform a mem Wash
130 130 unsigned int val = ReadReg(MCTRLBASEADDRESS);
131 131 val |=1<<31;
132 132 WriteRegs(uIntlist()<<val,(unsigned int)MCTRLBASEADDRESS);
133 usleep(1000*1000);
133 usleep(2000*1000);
134 134 }
135 135
136 136
137 137 WriteRegs(uIntlist()<<0<<0<<0<<0,(unsigned int)DSUBASEADDRESS+0x400060);
138 138 WriteRegs(uIntlist()<<0x0000FFFF,(unsigned int)DSUBASEADDRESS+0x24);
139 139
140 140 unsigned int ramSize=SocExplorerEngine::self()->memMeasureSize(this->parentPlugin(),0x40000000);
141 141 SocExplorerEngine::message(this,QString("Measured memory size=%1").arg(ramSize),0);
142 142
143 143 memSet(DSUBASEADDRESS+0x300000,0,1567);
144 144 WriteRegs(uIntlist()<<0<<0xF30000E0<<0x00000002<<0x40000000<<0x40000000<<0x40000004<<0x1000000,(unsigned int)DSUBASEADDRESS+0x400000);
145 145 WriteRegs(uIntlist()<<0<<0<<0<<0<<0<<0<<0x40000000+ramSize-16<<0<<0<<0<<0<<0<<0<<0<<0<<0<<0<<0<<0<<0<<0<<0<<0<<0,(unsigned int)DSUBASEADDRESS+0x300020);
146 146 WriteRegs(uIntlist()<<0x000002EF,(unsigned int)DSUBASEADDRESS);
147 147
148 148 //Disable interrupts
149 149 unsigned int APBIRQCTRLRBASEADD = (unsigned int)SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,1,0x0d,0);
150 150 if(APBIRQCTRLRBASEADD == (unsigned int)-1)
151 151 return false;
152 152 WriteRegs(uIntlist()<<0x00000000,APBIRQCTRLRBASEADD+0x040);
153 153 WriteRegs(uIntlist()<<0xFFFE0000,APBIRQCTRLRBASEADD+0x080);
154 154 WriteRegs(uIntlist()<<0<<0,APBIRQCTRLRBASEADD);
155 155
156 156 //Set up timer
157 157 unsigned int APBTIMERBASEADD = (unsigned int)SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,1,0x11,0);
158 158 if(APBTIMERBASEADD == (unsigned int)-1)
159 159 return false;
160 160 WriteRegs(uIntlist()<<0xffffffff,APBTIMERBASEADD+0x014);
161 161 WriteRegs(uIntlist()<<0x00000018,APBTIMERBASEADD+0x04);
162 162 WriteRegs(uIntlist()<<0x00000007,APBTIMERBASEADD+0x018);
163 163 return true;
164 164 }
165 165
166 166 bool dsu3plugin::cacheDisable()
167 167 {
168 168 return setCacheEnable(false);
169 169 }
170 170
171 171 bool dsu3plugin::cacheEnable()
172 172 {
173 173 return setCacheEnable(true);
174 174 }
175 175
176 176 bool dsu3plugin::cacheIsEnable()
177 177 {
178 178 if(parent==NULL)
179 179 return false;
180 180 unsigned int DSUBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01 , 0x004,0);
181 181 if(DSUBASEADDRESS == (unsigned int)-1)
182 182 DSUBASEADDRESS = 0x90000000;
183 183 WriteRegs(uIntlist()<<2,DSUBASEADDRESS+0x400024);
184 184 unsigned int reg = ReadReg(DSUBASEADDRESS+0x700000);
185 185 return ((reg&0x0F)==0x0F);
186 186 }
187 187
188 188 bool dsu3plugin::setCacheEnable(bool enabled)
189 189 {
190 190 if(parent==NULL)
191 191 return false;
192 192 unsigned int DSUBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01 , 0x004,0);
193 193 if(DSUBASEADDRESS == (unsigned int)-1)
194 194 DSUBASEADDRESS = 0x90000000;
195 195 WriteRegs(uIntlist()<<2,DSUBASEADDRESS+0x400024);
196 196 unsigned int reg = ReadReg(DSUBASEADDRESS+0x700000);
197 197 if(enabled)
198 198 {
199 199 WriteRegs(uIntlist()<<(0x0001000F|reg),DSUBASEADDRESS+0x700000);
200 200 //flushes cache.
201 201 WriteRegs(uIntlist()<<(0x0061000F|reg),DSUBASEADDRESS+0x700000);
202 202 }
203 203 else
204 204 {
205 205 WriteRegs(uIntlist()<<((!0x0001000F)&reg),DSUBASEADDRESS+0x700000);
206 206 WriteRegs(uIntlist()<<(0x00600000|reg),DSUBASEADDRESS+0x700000);
207 207 }
208 208 return true;
209 209 }
210 210
211 211 bool dsu3plugin::flashTarget()
212 212 {
213 213 stop();
214 214 cacheDisable();
215 215 configureTarget();
216 216 /*Write .text*/
217 217 this->writeSection(".text");
218 218 /*Write .data*/
219 219 this->writeSection(".data");
220 220 return true;
221 221 }
222 222
223 223 void dsu3plugin::run()
224 224 {
225 225 unsigned int DSUBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01 , 0x004,0);
226 226 if(DSUBASEADDRESS == (unsigned int)-1)
227 227 DSUBASEADDRESS = 0x90000000;
228 228 WriteRegs(uIntlist()<<0,DSUBASEADDRESS+0x020);
229 229 this->running = true;
230 230 this->UI->setRunning(true);
231 231 }
232 232
233 233 void dsu3plugin::stop()
234 234 {
235 235 unsigned int DSUBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01 , 0x004,0);
236 236 if(DSUBASEADDRESS == (unsigned int)-1)
237 237 DSUBASEADDRESS = 0x90000000;
238 238 WriteRegs(uIntlist()<<0xFFFF,DSUBASEADDRESS+0x020);
239 239 this->running = false;
240 240 this->UI->setRunning(false);
241 241 }
242 242
243 243 void dsu3plugin::toggleRun()
244 244 {
245 245 if(this->running)
246 246 this->stop();
247 247 else
248 248 this->run();
249 249 }
250 250
251 251 bool dsu3plugin::dumpSymbol(const QString &symbolName, QString file, const QString &format)
252 252 {
253 253 if(this->elfFile->isopened())
254 254 {
255 255 int symbolIndex=this->elfFile->getSymbolIndex(symbolName);
256 256 if(symbolIndex!=-1)
257 257 return this->dumpMemory(this->elfFile->getSymbolAddress(symbolIndex),this->elfFile->getSymbolSize(symbolIndex)/4,file,format);
258 258 }
259 259 return false;
260 260 }
261 261
262 262 QVariantList dsu3plugin::readSymbol(const QString &symbolName)
263 263 {
264 264 if(this->elfFile->isopened())
265 265 {
266 266 int symbolIndex=this->elfFile->getSymbolIndex(symbolName);
267 267 if(symbolIndex!=-1)
268 268 return socexplorerplugin::Read((unsigned int)this->elfFile->getSymbolAddress(symbolIndex),(unsigned int)this->elfFile->getSymbolSize(symbolIndex)/4);
269 269 }
270 270 return QVariantList();
271 271 }
272 272
273 273 void dsu3plugin::WriteRegs(uIntlist Values, unsigned int address)
274 274 {
275 275 unsigned int* buff;
276 276 buff = (unsigned int*)malloc(Values.count()*sizeof(unsigned int));
277 277 for(int i=0;i<Values.count();i++)
278 278 {
279 279 buff[i]=Values.at(i);
280 280 }
281 281 parent->Write(buff,(unsigned int)Values.count(),address);
282 282 free(buff);
283 283 }
284 284
285 285 unsigned int dsu3plugin::ReadReg(unsigned int address)
286 286 {
287 287 unsigned int buff;
288 288 parent->Read(&buff,1,address);
289 289 return buff;
290 290 }
291 291
292 292 void dsu3plugin::writeSection(int index)
293 293 {
294 294 char* buffch=NULL;
295 295 unsigned int* buff;
296 296 int size = this->elfFile->getSectionDatasz(index);
297 297 int sizeInt = size/4;
298 298 if(parent==NULL)
299 299 return;
300 300 this->elfFile->getSectionData(index,&buffch);
301 301 buff = (unsigned int*)malloc(((size/4)+1)*sizeof(unsigned int));
302 302 for(int i=0;i<sizeInt;i++)
303 303 {
304 304 buff[i] = 0x0FF & ((unsigned int)buffch[4*i]);
305 305 buff[i] = (buff[i]<<8) + (0x0FF & ((unsigned int)buffch[(4*i)+1]));
306 306 buff[i] = (buff[i]<<8) + (0x0FF & ((unsigned int)buffch[(4*i)+2]));
307 307 buff[i] = (buff[i]<<8) + (0x0FF & ((unsigned int)buffch[(4*i)+3]));
308 308 }
309 309 if(size%4)
310 310 {
311 311 buff[sizeInt]=0;
312 312 for(int i=(size%4);i>0;i--)
313 313 {
314 314 buff[sizeInt] = (buff[sizeInt]<<8) + (0x0FF & ((unsigned int)buffch[size-i]));
315 315 }
316 316 sizeInt++;
317 317 }
318 318 parent->Write(buff,(unsigned int)sizeInt,(unsigned int)this->elfFile->getSectionPaddr(index));
319 319 free(buff);
320 320 }
321 321
322 322 void dsu3plugin::writeSection(const QString &name)
323 323 {
324 324 if(elfFile->isopened())
325 325 {
326 326 writeSection(this->elfFile->getSectionIndex(name));
327 327 }
328 328 }
329 329
330 330
331 331 bool dsu3plugin::memSet(unsigned int address,int value, unsigned int count)
332 332 {
333 333 unsigned int* buffer = (unsigned int*)malloc(count*sizeof(unsigned int));
334 334 if(buffer!=NULL)
335 335 {
336 336 memset((void*)buffer,value,count*sizeof(unsigned int));
337 337 parent->Write(buffer,count,address);
338 338 free(buffer );
339 339 return true;
340 340 }
341 341 return false;
342 342 }
General Comments 0
You need to be logged in to leave comments. Login now