[processor-sdk/pdk.git] / packages / ti / drv / sciclient / tools / ccsLoadDmsc / am64x / launch_zebu.js
1 /*
2 * Copyright (c) 2020, Texas Instruments Incorporated
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
33 //
34 //File Name: launch_am64x.js
35 //Description:
36 // Launch the DMSC firmware and board configuration from R5F.
37 //
38 //Usage:
39 //
40 //From CCS Scripting console
41 // 1. loadJSFile "C:\\ti\\launch_am64x.js"
42 //
43 //Note:
44 // 1. Search for "edit this" to look at changes that need to be edited
45 // for your usage.
46 //
49 //<!!!!!! EDIT THIS !!!!!>
50 // Set this to 1 to allow loading the GEL files directly from the ccxml file.
51 disableGelLoad = 0;
52 // Set to 1 to use the firmware with Firewalls.
53 if (disableGelLoad == 0)
54 {
55 //Path to GEL files
56 gelFilePath = "k3-avv-repo/framework/gels/K3J7";
57 }
58 //PDK path. Edit this
59 pdkPath = "/ti/sitara/pdk";
61 //path to board config elf
62 ccs_init_elf_file = pdkPath+"/packages/ti/drv/sciclient/tools/ccsLoadDmsc/am64x/sciclient_ccs_init_mcu1_0_release.xer5f";
64 //path to sysfw bin
65 sysfw_bin = pdkPath+"/packages/ti/drv/sciclient/soc/sysfw/binaries/ti-sci-firmware-am64x-gp-zebu.bin"
67 //<!!!!!! EDIT THIS !!!!!>
69 // Import the DSS packages into our namespace to save on typing
70 importPackage(Packages.com.ti.debug.engine.scripting)
71 importPackage(Packages.com.ti.ccstudio.scripting.environment)
72 importPackage(Packages.java.lang)
73 importPackage(java.io);
74 importPackage(java.lang);
76 function updateScriptVars()
77 {
78 //Open a debug session
79 dsMCU1_0 = debugServer.openSession( ".*MAIN_Cortex_R5_0_0" );
80 dsDMSC_0 = debugServer.openSession( ".*DMSC_Cortex_M3_0" );
81 }
83 function printVars()
84 {
85 updateScriptVars();
86 }
88 function connectTargets()
89 {
90 /* Set timeout of 20 seconds */
91 script.setScriptTimeout(200000);
92 updateScriptVars();
93 // On VLAB the sys reset is not present. This will be required post silicon
94 //sysResetVar=dsDMSC_0.target.getResetType(1);
95 //sysResetVar.issueReset();
97 print("Connecting to DMSC_Cortex_M3_0!");
98 // Connect targets
99 dsDMSC_0.target.connect();
100 /* TODO: This will be required when the GEL files are done which does the R5F
101 * RAT Mapping.
102 */
103 print("Fill R5F ATCM memory...");
104 dsDMSC_0.memory.fill(0x78000000, 0, 0x2000, 0);
105 print("Writing While(1) for R5F")
106 dsDMSC_0.memory.writeWord(0, 0x78000000, 0xE59FF004); /* ldr pc, [pc, #4] */
107 dsDMSC_0.memory.writeWord(0, 0x78000004, 0x38); /* Address 0x38 */
108 dsDMSC_0.memory.writeWord(0, 0x78000038, 0xEAFFFFFE) /* b #0x38 */
110 /* RAT Config for OCSRAM SYSFW load */
111 dsDMSC_0.memory.writeWord(0, 0x44200024, 0x00060000);
112 dsDMSC_0.memory.writeWord(0, 0x44200028, 0x44060000);
113 dsDMSC_0.memory.writeWord(0, 0x4420002C, 0x00000000);
114 dsDMSC_0.memory.writeWord(0, 0x44200020, 0x80000011);
116 print("Loading DMSC Firmware ... " + sysfw_bin);
117 // Load the DMSC firmware
118 dsDMSC_0.memory.loadRaw(0, 0x44000, sysfw_bin, 32, false);
119 print("DMSC Firmware Load Done...");
120 // Set Stack pointer and Program Counter
121 stackPointer = dsDMSC_0.memory.readWord(0, 0x44000);
122 progCounter = dsDMSC_0.memory.readWord(0, 0x44004);
123 dsDMSC_0.memory.writeRegister("SP", stackPointer);
124 dsDMSC_0.memory.writeRegister("PC", progCounter);
125 print( "DMSC Firmware run starting now...");
126 // Run the DMSC firmware
127 dsDMSC_0.target.runAsynch();
128 print("Connecting to MCU Cortex_R5_0!");
130 // Connect the MCU R5F
131 dsMCU1_0.target.connect();
133 // Need to do this for VLAB
134 dsMCU1_0.target.runAsynch();
135 java.lang.Thread.sleep(2000);
136 // Halt the R5F and re-run.
137 dsMCU1_0.target.halt();
139 // Reset the R5F and run.
140 dsMCU1_0.target.reset();
142 print("Running the board configuration initialization from R5!");
143 // Load the board configuration init file.
144 dsMCU1_0.memory.loadProgram(ccs_init_elf_file);
145 // Halt the R5F and re-run.
146 dsMCU1_0.target.halt();
147 // Run Synchronously for the executable to finish
148 dsMCU1_0.target.run();
149 }
151 function disconnectTargets()
152 {
153 updateScriptVars();
154 // Reset the R5F to be in clean state.
155 dsMCU1_0.target.reset();
156 // Disconnect targets
157 dsDMSC_0.target.disconnect();
158 }
160 function doEverything()
161 {
162 printVars();
163 connectTargets();
164 disconnectTargets();
165 print("Okay you are good to go.. Happy Debugging!!");
166 }
168 var ds;
169 var debugServer;
170 var script;
172 // Check to see if running from within CCSv4 Scripting Console
173 var withinCCS = (ds !== undefined);
175 // Create scripting environment and get debug server if running standalone
176 if (!withinCCS)
177 {
178 // Import the DSS packages into our namespace to save on typing
179 importPackage(Packages.com.ti.debug.engine.scripting);
180 importPackage(Packages.com.ti.ccstudio.scripting.environment);
181 importPackage(Packages.java.lang);
183 // Create our scripting environment object - which is the main entry point into any script and
184 // the factory for creating other Scriptable ervers and Sessions
185 script = ScriptingEnvironment.instance();
187 // Get the Debug Server and start a Debug Session
188 debugServer = script.getServer("DebugServer.1");
189 }
190 else // otherwise leverage existing scripting environment and debug server
191 {
192 debugServer = ds;
193 script = env;
194 }
196 doEverything();