]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/mcsdk-tools.git/blob - program_evm/program_evm.js
Merge branch 'next'
[keystone-rtos/mcsdk-tools.git] / program_evm / program_evm.js
1 // factory_defaults dss script
2 // Import the DSS packages into our namespace to save on typing
3 importPackage(Packages.com.ti.debug.engine.scripting);
4 importPackage(Packages.com.ti.ccstudio.scripting.environment);
5 importPackage(Packages.java.lang);
6 importPackage(Packages.java.io);
7 importPackage(Packages.java.util);
9 // Create our scripting environment object - which is the main entry point into
10 // any script and the factory for creating other Scriptable ervers and Sessions
11 var script = ScriptingEnvironment.instance()
13 var debugScriptEnv = ScriptingEnvironment.instance();
14 // program_evm environment.
15 testEnv = {};
17 // Get the Debug Server and start a Debug Session
18 var debugServer = script.getServer("DebugServer.1");
20 //***************Functions define***************************
23 function isFile(path)
24 {
25         try
26         {   
27                 file = new java.io.FileReader(path);
28         }
29         catch (ex)
30         {
31                 return false;
32         }
34         return true;
36 }
39 //****************Get New Time Stamp***********************
40 function localTime()
41 {
42         // get time stamp
43         var currentTime = new Date();
44         var year = currentTime.getFullYear();
45         var month = currentTime.getMonth() + 1;
46         month = month + "";
47         if (month.length == 1)
48         {
49                 month = "0" + month;
50         }
51         var day = currentTime.getDate();
52         var hour = currentTime.getHours();
53         var minute = currentTime.getMinutes();
54         minute = minute + "";
55         if (minute.length == 1)
56         {
57                 minute = "0" + minute;
58         }
59         var second = currentTime.getSeconds();
60         second = second + "";
61         if (second.length == 1)
62         {
63                 second = "0" + second;
64         }
65     
66         return (year+"_"+month+"_"+day+"_"+hour+minute+second);
67 }
69 /**
70  * Get error code from the given exception.
71  * @param {exception} The exception from which to get the error code.
72  */
73 function getErrorCode(exception)
74 {
75         var ex2 = exception.javaException;
76         if (ex2 instanceof Packages.com.ti.ccstudio.scripting.environment.ScriptingException) {
77                 return ex2.getErrorID();
78         }
79         return 0;
80 }
81 function fileCopy(source,destination)
82 {
83         inputFile = new File(source);
84     outputFile = new File(destination);
85     infile = new  java.io.FileReader(inputFile);
86     out = new java.io.FileWriter(outputFile);
87     var c;
89     while ((c = infile.read()) != -1)
90       out.write(c);
92     infile.close();
93     out.close();
94 }
96 function pausecomp(millis)
97  {
98   var date = new Date();
99   var curDate = null;
100   do { curDate = new Date(); }
101   while(curDate-date < millis)
102   { 
103   //print("Waiting "+millis+"ms...\r\n") 
104   }
107 //*******************************************
108 // Declarations and Inititalizations
109 var nandwriter_dir    = java.lang.System.getProperty("user.dir");
110 var dss_script_dir    = java.lang.System.getenv("DSS_SCRIPT_DIR");
111 var host_os           = "";
112 var script_logs    = nandwriter_dir+"/logs/";
113 var script_configs = nandwriter_dir+"/configs/";
114 var script_binaries = nandwriter_dir+"/binaries/";
115 var targetConfig = "";
116 var writeAll = false;
117 var big_endian = false;
118 var targetFlag = "unknown";
119 var targetConfig = "unknown";
120 var emul560 = false;
121 testEnv.cioFile = null;
123 if (java.lang.System.getProperty("os.name").match(/Linux/i))
125         host_os = "-linuxhost";
128 // Parse the arguments
129 if (arguments.length > 0 && arguments.length < 3)
131     // parse the board spec
132     var board_spec = arguments[0].toLowerCase();
133     board_spec = board_spec.replace(/^tmd(x|s)/, "");
134     board_spec = board_spec.replace(/^evmc/, "evm");
135     
136     // find endian, user wants
137     if (board_spec.match(/-be$/))
138     {
139         big_endian = true;
140         board_spec = board_spec.replace(/-be$/, "");
141     }
142     else
143         board_spec = board_spec.replace(/-le$/, "");
144         
145     // find onboard emulation option for this board 
146     if (board_spec.match(/lx?e$/))
147     {
148         emul560 = true;
149         board_spec = board_spec.replace(/e$/, "");
150     }
151         
152     // for now, use the same software for lx and l variants
153     board_spec = board_spec.replace(/lx$/, "l");
154     
155     // for now, treat evm6618l as an alias for evm6670l
156     board_spec = board_spec.replace(/evm6618/, "evm6670");
157         
158     targetFlag = board_spec;
159     
160     endian_spec = (big_endian ? "-be" : "");
161     
162     board_binaries = script_binaries + targetFlag + endian_spec + "/";
163     targetConfig = java.lang.System.getenv("PROGRAM_EVM_TARGET_CONFIG_FILE");
164     if (!targetConfig)    
165         targetConfig = script_configs + targetFlag + "/" + targetFlag + (emul560 ? "e" : "") + host_os + ".ccxml";
167     print("board: " + targetFlag);
168     print("endian: " + (big_endian ? "Big" : "Little"));
169     print("emulation: " + (emul560 ? "XDS560 mezzanine" : "onboard XDS100"));
170     print("binaries: " + board_binaries);
171     print("ccxml: " + targetConfig);
172     
173     var dir = new File(board_binaries);
174     if (!dir.exists())
175     {
176         print("board binaries directory not found");
177         java.lang.System.exit(2);
178     }
179     
180     if(arguments[1])
181         var writerImages = arguments[1];
182     else
183         writeAll = true;   
185 else
187   print("Syntax error in command line");
188         print("Syntax: program_evm.js [tmdx|tmds]evm[c](<device>)l[x][e][-le|-be] [images_to_write]")
189   
190         print("    tmdx: TMDX type EVM")
191         print("    tmds: TMDS type EVM")
192         print("    c: Not used, for backward compatibility")
193         print("    <device> is the board name e.g 6472,6678 etc")
194         print("    l: Low cost EVM")
195         print("    x: EVM supports encryption")
196         print("    e: EVM uses 560 Mezzanine Emulator daughter card")
197         print("    le: Little Endian")
198         print("    be: Big Endian")
200         print("    example: TMDXEVM6678L-le")   
201         print("    [images_to_write] OPTIONAL is a list of the images to be written")
202         print("    example: eeprom50,nor")
203         print("    If not specified all (eeprom50,eeprom51,nand,nor) will be written")
204         java.lang.System.exit(0);
207 var i2cwriterbinary = board_binaries + "eepromwriter_" + targetFlag + ".out";
208 var nandwriterbinary = board_binaries + "nandwriter_" + targetFlag + ".out";
209 var norwriterbinary = board_binaries + "norwriter_" + targetFlag + ".out";
210 var eepromwriter_input51 = board_binaries + "eepromwriter_input51.txt";
211 var eepromwriter_input50 = board_binaries + "eepromwriter_input50.txt";
212 var eepromwriter_input = board_binaries + "eepromwriter_input.txt";
213 var eeprom50 = board_binaries + "eeprom50.bin";
214 var eeprom51 = board_binaries + "eeprom51.bin";
215 var nand = board_binaries + "nand.bin";
216 var nor = board_binaries + "nor.bin";
218 switch (targetFlag)
220         case "evm6457l":
221                 cpu_id = "C64XP_1";
222                 var nAddress = 0x800000;
223     var iblByteSwap = false;
224                 break;
225         case "evm6474l":
226                 cpu_id = "C64XP_0";
227     var nAddress = 0x800000;
228     var iblByteSwap = false;
229                 break;
230         case "evm6455":
231     cpu_id = "C64XP_0";
232     var nAddress = 0x800000;
233     var iblByteSwap = false;
234     break;
235         case "evm6474":
236     cpu_id = "C64XP_1A";
237     var nAddress = 0x800000;
238     var iblByteSwap = false;
239     break;
240         case "evm6472l":
241                 cpu_id = "C64XP_A";
242     var nAddress = 0x800000;
243     var iblByteSwap = false;
244                 break;
245         case "evm6670l":
246                 cpu_id = "C66xx_0";
247     var nAddress = 0x80000000;
248     var iblByteSwap = false;
249                 break;
250         case "evm6678l":
251                 cpu_id = "C66xx_0";
252     var nAddress = 0x80000000;
253     var iblByteSwap = false;
254                 break;
255         default:
256                 script.traceWrite("Could not file cpu id for target " + targetFlag + "\n");
261 start = localTime();
262 testEnv.cioFile = script_logs+targetFlag+"_"+start+"-cio"+".txt";
263 // Create a log file in the current directory to log script execution
264 script.traceBegin(script_logs+targetFlag+"_"+start+"-trace"+".txt")
266 // Configure target
267 debugServer.setConfig(targetConfig);
268 pausecomp(1000);
269 debugSession = debugServer.openSession("*",cpu_id);
271 if (testEnv.cioFile != null)
272         debugSession.beginCIOLogging(testEnv.cioFile);
273 pausecomp(1000);
274 debugSession.target.connect();
275 pausecomp(1000);
276 debugSession.target.reset();
277 pausecomp(1000);
279 //POST
280 if(writeAll || writerImages.match(/eeprom50/))
282         //Write EEPROM
283         start = localTime();
284         script.traceWrite("Start writing eeprom50");
285         script.traceWrite("Writer:" + i2cwriterbinary + "\r\n");
286         script.traceWrite("Image:" + eeprom50 + "\r\n");
287         if (isFile(i2cwriterbinary) && isFile(eeprom50)) 
288         {
289                 fileCopy(eepromwriter_input50,eepromwriter_input);
290                 debugSession.memory.loadProgram(i2cwriterbinary);
291                 var nPage = 0x0;
292         //      var nAddress = 0x80000000;
293                 var sFilename = eeprom50 ;
294                 var nTypeSize = 32;
295                 var bByteSwap = false;
296                 try
297                 {
298                         debugSession.memory.loadRaw(nPage, nAddress, sFilename, nTypeSize, bByteSwap);
299                 }
300                 catch (ex)
301                 {
302                    errCode = getErrorCode(ex);
303                    script.traceWrite("Error code #" + errCode + ", could not load file " + sFilename +
304                                         " to target memory!");
305                 }
306                 debugSession.target.run()
307                 end = localTime();
308         }
309         else
310         {
311                 script.traceWrite("Required EEPROM50 files do not exist in " + board_binaries + "\n");
312          
313         }
316 //IBL 
317 if(writeAll || writerImages.match(/eeprom51/))
319         start = localTime();
320         script.traceWrite("Start writing eeprom51");
321         script.traceWrite("Writer:" + i2cwriterbinary + "\r\n");
322         script.traceWrite("Image:" + eeprom51 + "\r\n");
323         
324         if (isFile(i2cwriterbinary) && isFile(eeprom51)) 
325         {
326                 fileCopy(eepromwriter_input51,eepromwriter_input);
327                 debugSession.memory.loadProgram(i2cwriterbinary);
328                 var nPage = 0x0;
329         //      var nAddress = 0x80000000;
330                 var sFilename = eeprom51;
331                 var nTypeSize = 32;
332                 var bByteSwap = iblByteSwap;
333                 try
334                 {
335                         debugSession.memory.loadRaw(nPage, nAddress, sFilename, nTypeSize, bByteSwap);
336                 }
337                 catch (ex)
338                 {
339                    errCode = getErrorCode(ex);
340                    script.traceWrite("Error code #" + errCode + ", could not load file " + sFilename +
341                                         " to target memory!");
342                 }
344                 debugSession.target.run()
345                 end = localTime();
346         }
347         else
348         {
349                 script.traceWrite("Required EEPROM51 files do not exist in " + board_binaries + "\n");
350          
351         }
355 //NAND
356 if(writeAll || writerImages.match(/nand/))
359         start_nand = localTime();
360         script.traceWrite("Writer:" + nandwriterbinary + "\r\n");
361         script.traceWrite("NAND:" + nand + "\r\n");
362         if (isFile(nand) && isFile(nandwriterbinary)) 
363         {
364                 debugSession.memory.loadProgram(nandwriterbinary);
365                 var nPage = 0x0;
366         //      var nAddress = 0x80000000;
367                 var sFilename = nand;
368                 var nTypeSize = 32;
369                 var bByteSwap = false;
371                 try
372                 {   
373                         script.traceWrite("Start loading nand.bin");
374                         debugSession.memory.loadRaw(nPage, nAddress, sFilename, nTypeSize, bByteSwap);
376                 }
377                 catch (ex)
378                 {
379                    errCode = getErrorCode(ex);
380                    script.traceWrite("Error code #" + errCode + ", could not load file " + sFilename +
381                                         " to target memory!");
382                 }
383                 script.traceWrite("Start programming NAND");
384                 debugSession.target.run()
385                 script.traceWrite("End programming NAND");
386                 end_nand = localTime();
387         }
388         else
389         {
390                 script.traceWrite("Required NAND files does not exist in " + board_binaries + "\n");
391          
392         }
395 //NOR
396 if(writeAll || writerImages.match(/nor/))
398         start_nor = localTime();
399         script.traceWrite("Writer:" + norwriterbinary + "\r\n");
400         script.traceWrite("NOR:" + nor + "\r\n");
402         
403         if (isFile(nor) && isFile(norwriterbinary)) 
404         {
405         
406                 debugSession.memory.loadProgram(norwriterbinary);
407                 var nPage = 0x0;
408         //      var nAddress = 0x80000000;
409                 var sFilename = nor ;
410                 var nTypeSize = 32;
411                 var bByteSwap = false;
412                 try
413                 {   
414                         script.traceWrite("Start loading nor.bin");
415                         debugSession.memory.loadRaw(nPage, nAddress, sFilename, nTypeSize, bByteSwap);
417                 }
418                 catch (ex)
419                 {
420                    errCode = getErrorCode(ex);
421                    script.traceWrite("Error code #" + errCode + ", could not load file " + sFilename +
422                                         " to target memory!");
423                 }
424                 script.traceWrite("Start programming NOR");
425                 script.traceWrite(localTime());
426                 debugSession.target.run()
427                 script.traceWrite("End programming NOR");
428                 end_nor = localTime();
429     }
430         else
431         {
432                 script.traceWrite("Required NOR files does not exist in " + board_binaries + "\n");
433          
434         }
438 if (testEnv.cioFile != null)
440         // Stop CIO logging.
441         debugSession.endCIOLogging();
444 debugSession.terminate();
445 debugServer.stop()
447 // Stop logging and exit.
448 script.traceEnd();
449 java.lang.System.exit(0);