@@ -1,247 +1,255 | |||
|
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 | dsu3plugin::dsu3plugin(QWidget *parent):socexplorerplugin(parent,false) |
|
29 | 29 | { |
|
30 | 30 | this->UI = new dsu3pluginui(); |
|
31 | 31 | this->setWidget((QWidget*)this->UI); |
|
32 | 32 | this->elfparserInst = new elfparser(); |
|
33 | 33 | this->pyObject = new dsu3pluginPywrapper(this); |
|
34 | 34 | QObject::connect(((dsu3pluginPywrapper*)this->pyObject),SIGNAL(openFile(QString)),this,SLOT(openFile(QString))); |
|
35 | 35 | QObject::connect(((dsu3pluginPywrapper*)this->pyObject),SIGNAL(loadFile()),this,SLOT(flashTarget())); |
|
36 | 36 | QObject::connect(((dsu3pluginPywrapper*)this->pyObject),SIGNAL(run()),this,SLOT(run())); |
|
37 | 37 | QObject::connect(((dsu3pluginPywrapper*)this->pyObject),SIGNAL(stop()),this,SLOT(stop())); |
|
38 | 38 | connect(this->UI,SIGNAL(openFile()),this,SLOT(openFile())); |
|
39 | 39 | connect(this->UI,SIGNAL(flashTarget()),this,SLOT(flashTarget())); |
|
40 | 40 | connect(this->UI,SIGNAL(run()),this,SLOT(toggleRun())); |
|
41 | 41 | connect(this,SIGNAL(updateInfo(elfparser*)),this->UI,SIGNAL(updateInfo(elfparser*))); |
|
42 | 42 | this->running = false; |
|
43 | 43 | } |
|
44 | 44 | |
|
45 | 45 | |
|
46 | 46 | dsu3plugin::~dsu3plugin() |
|
47 | 47 | { |
|
48 | 48 | |
|
49 | 49 | } |
|
50 | 50 | |
|
51 | 51 | |
|
52 | 52 | void dsu3plugin::openFile() |
|
53 | 53 | { |
|
54 | 54 | QString filename = QFileDialog::getOpenFileName(this,tr("Open elf File"), QDir::homePath(), tr("Elf Files (*)")); |
|
55 | 55 | if(filename!="") |
|
56 | 56 | { |
|
57 | 57 | this->openFile(filename); |
|
58 | 58 | } |
|
59 | 59 | } |
|
60 | 60 | |
|
61 | 61 | void dsu3plugin::openFile(QString fileName) |
|
62 | 62 | { |
|
63 | 63 | this->elfparserInst->setFilename(fileName); |
|
64 | 64 | emit this->updateInfo(this->elfparserInst); |
|
65 | 65 | } |
|
66 | 66 | |
|
67 | 67 | bool dsu3plugin::configureTarget() |
|
68 | 68 | { |
|
69 | 69 | if(parent==NULL) |
|
70 | 70 | return false; |
|
71 | 71 | unsigned int DSUBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01 , 0x004,0); |
|
72 | 72 | if(DSUBASEADDRESS == (unsigned int)-1) |
|
73 | 73 | DSUBASEADDRESS = 0x90000000; |
|
74 | 74 | unsigned int MCTRLBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x04 , 0x00F,0); |
|
75 | 75 | if(MCTRLBASEADDRESS == (unsigned int)-1) |
|
76 | return false; | |
|
76 | { | |
|
77 | SocExplorerEngine::message(this,"Can't find MemCtrlr",1); | |
|
78 | MCTRLBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01 , 0x051,0); | |
|
79 | if(MCTRLBASEADDRESS == (unsigned int)-1) | |
|
80 | { | |
|
81 | SocExplorerEngine::message(this,"Can't find FTMemCtrlr",1); | |
|
82 | return false; | |
|
83 | } | |
|
84 | } | |
|
77 | 85 | |
|
78 | 86 | //Force a debug break |
|
79 | 87 | WriteRegs(uIntlist()<<0x0000002f,(unsigned int)DSUBASEADDRESS); |
|
80 | 88 | WriteRegs(uIntlist()<<0x0000ffff,(unsigned int)DSUBASEADDRESS+0x20); |
|
81 | 89 | //Clear time tag counter |
|
82 | 90 | WriteRegs(uIntlist()<<0,(unsigned int)DSUBASEADDRESS+0x8); |
|
83 | 91 | |
|
84 | 92 | //Clear ASR registers |
|
85 | 93 | WriteRegs(uIntlist()<<0<<0<<0,(unsigned int)DSUBASEADDRESS+0x400040); |
|
86 | 94 | WriteRegs(uIntlist()<<0x2,(unsigned int)DSUBASEADDRESS+0x400024); |
|
87 | 95 | WriteRegs(uIntlist()<<0<<0<<0<<0<<0<<0<<0<<0,(unsigned int)DSUBASEADDRESS+0x400060); |
|
88 | 96 | WriteRegs(uIntlist()<<0,(unsigned int)DSUBASEADDRESS+0x48); |
|
89 | 97 | WriteRegs(uIntlist()<<0,(unsigned int)DSUBASEADDRESS+0x000004C); |
|
90 | 98 | WriteRegs(uIntlist()<<0,(unsigned int)DSUBASEADDRESS+0x400040); |
|
91 | 99 | |
|
92 | 100 | |
|
93 | 101 | |
|
94 | 102 | WriteRegs(uIntlist()<<0x2FF<<0xE60<<0,(unsigned int)MCTRLBASEADDRESS); |
|
95 | 103 | |
|
96 | 104 | |
|
97 | 105 | WriteRegs(uIntlist()<<0<<0<<0<<0,(unsigned int)DSUBASEADDRESS+0x400060); |
|
98 | 106 | WriteRegs(uIntlist()<<0x0000FFFF,(unsigned int)DSUBASEADDRESS+0x24); |
|
99 | 107 | |
|
100 | 108 | unsigned int buff=0; |
|
101 | 109 | // for(int i=0;i<1567;i++) |
|
102 | 110 | // { |
|
103 | 111 | // parent->Write(&buff,(unsigned int)1,DSUBASEADDRESS+0x300000+(4*i)); |
|
104 | 112 | // } |
|
105 | 113 | memSet(DSUBASEADDRESS+0x300000,0,1567); |
|
106 | 114 | WriteRegs(uIntlist()<<0<<0xF30000E0<<0x00000002<<0x40000000<<0x40000000<<0x40000004<<0x1000000,(unsigned int)DSUBASEADDRESS+0x400000); |
|
107 | 115 | 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); |
|
108 | 116 | WriteRegs(uIntlist()<<0x000002EF,(unsigned int)DSUBASEADDRESS); |
|
109 | 117 | |
|
110 | 118 | //Disable interrupts |
|
111 | 119 | unsigned int APBIRQCTRLRBASEADD = (unsigned int)SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,1,0x0d,0); |
|
112 | 120 | if(APBIRQCTRLRBASEADD == (unsigned int)-1) |
|
113 | 121 | return false; |
|
114 | 122 | WriteRegs(uIntlist()<<0x00000000,APBIRQCTRLRBASEADD+0x040); |
|
115 | 123 | WriteRegs(uIntlist()<<0xFFFE0000,APBIRQCTRLRBASEADD+0x080); |
|
116 | 124 | WriteRegs(uIntlist()<<0<<0,APBIRQCTRLRBASEADD); |
|
117 | 125 | |
|
118 | 126 | //Set up timer |
|
119 | 127 | unsigned int APBTIMERBASEADD = (unsigned int)SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,1,0x11,0); |
|
120 | 128 | if(APBTIMERBASEADD == (unsigned int)-1) |
|
121 | 129 | return false; |
|
122 | 130 | WriteRegs(uIntlist()<<0xffffffff,APBTIMERBASEADD+0x014); |
|
123 | 131 | WriteRegs(uIntlist()<<0x00000018,APBTIMERBASEADD+0x04); |
|
124 | 132 | WriteRegs(uIntlist()<<0x00000007,APBTIMERBASEADD+0x018); |
|
125 | 133 | return true; |
|
126 | 134 | } |
|
127 | 135 | |
|
128 | 136 | bool dsu3plugin::flashTarget() |
|
129 | 137 | { |
|
130 | 138 | configureTarget(); |
|
131 | 139 | |
|
132 | 140 | /*Write .text*/ |
|
133 | 141 | this->writeSection(".text"); |
|
134 | 142 | /*Write .data*/ |
|
135 | 143 | this->writeSection(".data"); |
|
136 | 144 | return true; |
|
137 | 145 | } |
|
138 | 146 | |
|
139 | 147 | void dsu3plugin::run() |
|
140 | 148 | { |
|
141 | 149 | unsigned int DSUBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01 , 0x004,0); |
|
142 | 150 | if(DSUBASEADDRESS == (unsigned int)-1) |
|
143 | 151 | DSUBASEADDRESS = 0x90000000; |
|
144 | 152 | WriteRegs(uIntlist()<<0,DSUBASEADDRESS+0x020); |
|
145 | 153 | this->running = true; |
|
146 | 154 | this->UI->setRunning(true); |
|
147 | 155 | } |
|
148 | 156 | |
|
149 | 157 | void dsu3plugin::stop() |
|
150 | 158 | { |
|
151 | 159 | unsigned int DSUBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01 , 0x004,0); |
|
152 | 160 | if(DSUBASEADDRESS == (unsigned int)-1) |
|
153 | 161 | DSUBASEADDRESS = 0x90000000; |
|
154 | 162 | WriteRegs(uIntlist()<<0xFFFF,DSUBASEADDRESS+0x020); |
|
155 | 163 | this->running = false; |
|
156 | 164 | this->UI->setRunning(false); |
|
157 | 165 | } |
|
158 | 166 | |
|
159 | 167 | void dsu3plugin::toggleRun() |
|
160 | 168 | { |
|
161 | 169 | if(this->running) |
|
162 | 170 | this->stop(); |
|
163 | 171 | else |
|
164 | 172 | this->run(); |
|
165 | 173 | } |
|
166 | 174 | |
|
167 | 175 | void dsu3plugin::WriteRegs(uIntlist Values, unsigned int address) |
|
168 | 176 | { |
|
169 | 177 | unsigned int* buff; |
|
170 | 178 | buff = (unsigned int*)malloc(Values.count()*sizeof(unsigned int)); |
|
171 | 179 | for(int i=0;i<Values.count();i++) |
|
172 | 180 | { |
|
173 | 181 | buff[i]=Values.at(i); |
|
174 | 182 | } |
|
175 | 183 | parent->Write(buff,(unsigned int)Values.count(),address); |
|
176 | 184 | free(buff); |
|
177 | 185 | } |
|
178 | 186 | |
|
179 | 187 | void dsu3plugin::writeSection(int index) |
|
180 | 188 | { |
|
181 | 189 | char* buffch=NULL; |
|
182 | 190 | unsigned int* buff; |
|
183 | 191 | int size = this->elfparserInst->getSectionDatasz(index); |
|
184 | 192 | int sizeInt = size/4; |
|
185 | 193 | if(parent==NULL) |
|
186 | 194 | return; |
|
187 | 195 | this->elfparserInst->getSectionData(index,&buffch); |
|
188 | 196 | buff = (unsigned int*)malloc(((size/4)+1)*sizeof(unsigned int)); |
|
189 | 197 | for(int i=0;i<sizeInt;i++) |
|
190 | 198 | { |
|
191 | 199 | buff[i] = 0x0FF & ((unsigned int)buffch[4*i]); |
|
192 | 200 | buff[i] = (buff[i]<<8) + (0x0FF & ((unsigned int)buffch[(4*i)+1])); |
|
193 | 201 | buff[i] = (buff[i]<<8) + (0x0FF & ((unsigned int)buffch[(4*i)+2])); |
|
194 | 202 | buff[i] = (buff[i]<<8) + (0x0FF & ((unsigned int)buffch[(4*i)+3])); |
|
195 | 203 | } |
|
196 | 204 | if(size%4) |
|
197 | 205 | { |
|
198 | 206 | buff[sizeInt]=0; |
|
199 | 207 | for(int i=(size%4);i>0;i--) |
|
200 | 208 | { |
|
201 | 209 | buff[sizeInt] = (buff[sizeInt]<<8) + (0x0FF & ((unsigned int)buffch[size-i])); |
|
202 | 210 | } |
|
203 | 211 | sizeInt++; |
|
204 | 212 | } |
|
205 | 213 | parent->Write(buff,(unsigned int)sizeInt,(unsigned int)this->elfparserInst->getSectionPaddr(index)); |
|
206 | 214 | free(buff); |
|
207 | 215 | } |
|
208 | 216 | |
|
209 | 217 | void dsu3plugin::writeSection(const QString &name) |
|
210 | 218 | { |
|
211 | 219 | for(int i=0;i<this->elfparserInst->getSectioncount();i++) |
|
212 | 220 | { |
|
213 | 221 | if(!this->elfparserInst->getSectionName(i).compare(name)) |
|
214 | 222 | { |
|
215 | 223 | printf("about to write section %s @ 0x%x size = %d\n",elfparserInst->getSectionName(i).toStdString().c_str(),elfparserInst->getSectionPaddr(i),elfparserInst->getSectionMemsz(i)); |
|
216 | 224 | writeSection(i); |
|
217 | 225 | } |
|
218 | 226 | } |
|
219 | 227 | } |
|
220 | 228 | |
|
221 | 229 | |
|
222 | 230 | unsigned int dsu3plugin::Write(unsigned int *Value,unsigned int count,unsigned int address) |
|
223 | 231 | { |
|
224 | 232 | if(parent!=NULL) |
|
225 | 233 | return parent->Write(Value,count,address); |
|
226 | 234 | return 0; |
|
227 | 235 | } |
|
228 | 236 | |
|
229 | 237 | bool dsu3plugin::memSet(unsigned int address,int value, unsigned int count) |
|
230 | 238 | { |
|
231 | 239 | unsigned int* buffer = (unsigned int*)malloc(count*sizeof(unsigned int)); |
|
232 | 240 | if(buffer!=NULL) |
|
233 | 241 | { |
|
234 | 242 | memset((void*)buffer,value,count*sizeof(unsigned int)); |
|
235 | 243 | parent->Write(buffer,count,address); |
|
236 | 244 | free(buffer ); |
|
237 | 245 | return true; |
|
238 | 246 | } |
|
239 | 247 | return false; |
|
240 | 248 | } |
|
241 | 249 | |
|
242 | 250 | unsigned int dsu3plugin::Read(unsigned int *Value,unsigned int count, unsigned int address) |
|
243 | 251 | { |
|
244 | 252 | if(parent!=NULL) |
|
245 | 253 | return parent->Read(Value,count,address); |
|
246 | 254 | return 0; |
|
247 | 255 | } |
General Comments 0
You need to be logged in to leave comments.
Login now