##// END OF EJS Templates
dsu3plugin:...
Jeandet Alexis -
r88:f17adb028d26 default draft
parent child
Show More
@@ -1,339 +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 SocExplorerEngine::message(this,"Can't any compatible memory controller",1);
101 return false;
100 SocExplorerEngine::message(this,"Can't find any compatible memory controller",1);
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 133 usleep(1000*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 unsigned int ramSize=SocExplorerEngine::self()->memMeasureSize(this->parentPlugin(),0x40000000);
141 SocExplorerEngine::message(this,QString("Measured memory size=%1").arg(ramSize),0);
142
140 143 memSet(DSUBASEADDRESS+0x300000,0,1567);
141 144 WriteRegs(uIntlist()<<0<<0xF30000E0<<0x00000002<<0x40000000<<0x40000000<<0x40000004<<0x1000000,(unsigned int)DSUBASEADDRESS+0x400000);
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);
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);
143 146 WriteRegs(uIntlist()<<0x000002EF,(unsigned int)DSUBASEADDRESS);
144 147
145 148 //Disable interrupts
146 149 unsigned int APBIRQCTRLRBASEADD = (unsigned int)SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,1,0x0d,0);
147 150 if(APBIRQCTRLRBASEADD == (unsigned int)-1)
148 151 return false;
149 152 WriteRegs(uIntlist()<<0x00000000,APBIRQCTRLRBASEADD+0x040);
150 153 WriteRegs(uIntlist()<<0xFFFE0000,APBIRQCTRLRBASEADD+0x080);
151 154 WriteRegs(uIntlist()<<0<<0,APBIRQCTRLRBASEADD);
152 155
153 156 //Set up timer
154 157 unsigned int APBTIMERBASEADD = (unsigned int)SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,1,0x11,0);
155 158 if(APBTIMERBASEADD == (unsigned int)-1)
156 159 return false;
157 160 WriteRegs(uIntlist()<<0xffffffff,APBTIMERBASEADD+0x014);
158 161 WriteRegs(uIntlist()<<0x00000018,APBTIMERBASEADD+0x04);
159 162 WriteRegs(uIntlist()<<0x00000007,APBTIMERBASEADD+0x018);
160 163 return true;
161 164 }
162 165
163 166 bool dsu3plugin::cacheDisable()
164 167 {
165 168 return setCacheEnable(false);
166 169 }
167 170
168 171 bool dsu3plugin::cacheEnable()
169 172 {
170 173 return setCacheEnable(true);
171 174 }
172 175
173 176 bool dsu3plugin::cacheIsEnable()
174 177 {
175 178 if(parent==NULL)
176 179 return false;
177 180 unsigned int DSUBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01 , 0x004,0);
178 181 if(DSUBASEADDRESS == (unsigned int)-1)
179 182 DSUBASEADDRESS = 0x90000000;
180 183 WriteRegs(uIntlist()<<2,DSUBASEADDRESS+0x400024);
181 184 unsigned int reg = ReadReg(DSUBASEADDRESS+0x700000);
182 185 return ((reg&0x0F)==0x0F);
183 186 }
184 187
185 188 bool dsu3plugin::setCacheEnable(bool enabled)
186 189 {
187 190 if(parent==NULL)
188 191 return false;
189 192 unsigned int DSUBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01 , 0x004,0);
190 193 if(DSUBASEADDRESS == (unsigned int)-1)
191 194 DSUBASEADDRESS = 0x90000000;
192 195 WriteRegs(uIntlist()<<2,DSUBASEADDRESS+0x400024);
193 196 unsigned int reg = ReadReg(DSUBASEADDRESS+0x700000);
194 197 if(enabled)
195 198 {
196 199 WriteRegs(uIntlist()<<(0x0001000F|reg),DSUBASEADDRESS+0x700000);
197 200 //flushes cache.
198 201 WriteRegs(uIntlist()<<(0x0061000F|reg),DSUBASEADDRESS+0x700000);
199 202 }
200 203 else
201 204 {
202 205 WriteRegs(uIntlist()<<((!0x0001000F)&reg),DSUBASEADDRESS+0x700000);
203 206 WriteRegs(uIntlist()<<(0x00600000|reg),DSUBASEADDRESS+0x700000);
204 207 }
205 208 return true;
206 209 }
207 210
208 211 bool dsu3plugin::flashTarget()
209 212 {
210 213 stop();
211 214 cacheDisable();
212 215 configureTarget();
213 216 /*Write .text*/
214 217 this->writeSection(".text");
215 218 /*Write .data*/
216 219 this->writeSection(".data");
217 220 return true;
218 221 }
219 222
220 223 void dsu3plugin::run()
221 224 {
222 225 unsigned int DSUBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01 , 0x004,0);
223 226 if(DSUBASEADDRESS == (unsigned int)-1)
224 227 DSUBASEADDRESS = 0x90000000;
225 228 WriteRegs(uIntlist()<<0,DSUBASEADDRESS+0x020);
226 229 this->running = true;
227 230 this->UI->setRunning(true);
228 231 }
229 232
230 233 void dsu3plugin::stop()
231 234 {
232 235 unsigned int DSUBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01 , 0x004,0);
233 236 if(DSUBASEADDRESS == (unsigned int)-1)
234 237 DSUBASEADDRESS = 0x90000000;
235 238 WriteRegs(uIntlist()<<0xFFFF,DSUBASEADDRESS+0x020);
236 239 this->running = false;
237 240 this->UI->setRunning(false);
238 241 }
239 242
240 243 void dsu3plugin::toggleRun()
241 244 {
242 245 if(this->running)
243 246 this->stop();
244 247 else
245 248 this->run();
246 249 }
247 250
248 251 bool dsu3plugin::dumpSymbol(const QString &symbolName, QString file, const QString &format)
249 252 {
250 253 if(this->elfFile->isopened())
251 254 {
252 255 int symbolIndex=this->elfFile->getSymbolIndex(symbolName);
253 256 if(symbolIndex!=-1)
254 257 return this->dumpMemory(this->elfFile->getSymbolAddress(symbolIndex),this->elfFile->getSymbolSize(symbolIndex)/4,file,format);
255 258 }
256 259 return false;
257 260 }
258 261
259 262 QVariantList dsu3plugin::readSymbol(const QString &symbolName)
260 263 {
261 264 if(this->elfFile->isopened())
262 265 {
263 266 int symbolIndex=this->elfFile->getSymbolIndex(symbolName);
264 267 if(symbolIndex!=-1)
265 268 return socexplorerplugin::Read((unsigned int)this->elfFile->getSymbolAddress(symbolIndex),(unsigned int)this->elfFile->getSymbolSize(symbolIndex)/4);
266 269 }
267 270 return QVariantList();
268 271 }
269 272
270 273 void dsu3plugin::WriteRegs(uIntlist Values, unsigned int address)
271 274 {
272 275 unsigned int* buff;
273 276 buff = (unsigned int*)malloc(Values.count()*sizeof(unsigned int));
274 277 for(int i=0;i<Values.count();i++)
275 278 {
276 279 buff[i]=Values.at(i);
277 280 }
278 281 parent->Write(buff,(unsigned int)Values.count(),address);
279 282 free(buff);
280 283 }
281 284
282 285 unsigned int dsu3plugin::ReadReg(unsigned int address)
283 286 {
284 287 unsigned int buff;
285 288 parent->Read(&buff,1,address);
286 289 return buff;
287 290 }
288 291
289 292 void dsu3plugin::writeSection(int index)
290 293 {
291 294 char* buffch=NULL;
292 295 unsigned int* buff;
293 296 int size = this->elfFile->getSectionDatasz(index);
294 297 int sizeInt = size/4;
295 298 if(parent==NULL)
296 299 return;
297 300 this->elfFile->getSectionData(index,&buffch);
298 301 buff = (unsigned int*)malloc(((size/4)+1)*sizeof(unsigned int));
299 302 for(int i=0;i<sizeInt;i++)
300 303 {
301 304 buff[i] = 0x0FF & ((unsigned int)buffch[4*i]);
302 305 buff[i] = (buff[i]<<8) + (0x0FF & ((unsigned int)buffch[(4*i)+1]));
303 306 buff[i] = (buff[i]<<8) + (0x0FF & ((unsigned int)buffch[(4*i)+2]));
304 307 buff[i] = (buff[i]<<8) + (0x0FF & ((unsigned int)buffch[(4*i)+3]));
305 308 }
306 309 if(size%4)
307 310 {
308 311 buff[sizeInt]=0;
309 312 for(int i=(size%4);i>0;i--)
310 313 {
311 314 buff[sizeInt] = (buff[sizeInt]<<8) + (0x0FF & ((unsigned int)buffch[size-i]));
312 315 }
313 316 sizeInt++;
314 317 }
315 318 parent->Write(buff,(unsigned int)sizeInt,(unsigned int)this->elfFile->getSectionPaddr(index));
316 319 free(buff);
317 320 }
318 321
319 322 void dsu3plugin::writeSection(const QString &name)
320 323 {
321 324 if(elfFile->isopened())
322 325 {
323 326 writeSection(this->elfFile->getSectionIndex(name));
324 327 }
325 328 }
326 329
327 330
328 331 bool dsu3plugin::memSet(unsigned int address,int value, unsigned int count)
329 332 {
330 333 unsigned int* buffer = (unsigned int*)malloc(count*sizeof(unsigned int));
331 334 if(buffer!=NULL)
332 335 {
333 336 memset((void*)buffer,value,count*sizeof(unsigned int));
334 337 parent->Write(buffer,count,address);
335 338 free(buffer );
336 339 return true;
337 340 }
338 341 return false;
339 342 }
General Comments 0
You need to be logged in to leave comments. Login now