7746728ded8338d13bdf9b14dbb714760b6163e9
[sitara-dss-files/am57xx-dss-files.git] / am57xx-avs-abb-decode.dss
1 /*
2  * Copyright (c) 2019, 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  *
32  */
34  function printRegisterValue(ds, name, addr)
35 {
36         value = ds.memory.readWord(0,addr,false);
37         value_string = d2h(value);
38         file.write(name + " = 0x" + value_string + newline);
39         return value; // return the register value for interrogation
40 }
42 // helper function to create 8-digit hex numbers in ascii format
43 function d2h(d) {
44         // bottom half
45         bottom = d & 0xFFFF;
46         bottom_ascii = ("0000" + bottom.toString(16)).slice(-4);
48         // top half
49         top = d >>> 16;  // unsigned right shift - avoids major sign issues...
50         top_ascii = ("0000" + top.toString(16)).slice(-4);
51         return (top_ascii + bottom_ascii);
52 }
54 // helper function to create decimal numbers in ascii format
55 function d2d(d) {return ((+d).toString());}
57 // Inputs:
58 //   Data - 32-bit register value
59 //   Upper - Highest bit to keep
60 //   Lower - Lowest bit to keep
61 //   (bit 0 refers to LSB, bit 31 to MSB)
62 // Return: right aligned data
63 function bits32(data, upper, lower)
64 {
65         data = data >>> lower; // unsigned right-shift
66         upper = upper - lower;
67         bitmask =  0xFFFFFFFF >>> (31 - upper);
68         return (data & bitmask);
69 }
71 function decode_fuse_opp_vmin_reg(rail, opp, reg_addr) {
72         value = debugSessionDAP.memory.readWord(0,reg_addr,false);
73         voltage = bits32(value, 11, 0);
74         abb_en = bits32(value, 25, 25);
75         vsetabb = bits32(value, 24, 20);
76         file.write(rail + "|" + opp + "|  " + String(d2d(voltage) + " mV         ").slice(0,8) + " |");
77         if (abb_en == 1) {
78                 file.write("    1    |    0x" + vsetabb.toString(16) + "   |" + newline);
79         } else {
80                 file.write("    0    |     -     |" + newline);
81         }
82 }
84 function decode_ldovbb_voltage_ctrl(value) {
85         fbb_mux_ctrl = bits32(value, 10, 10);
86         fbb_vset_in = bits32(value, 9, 5);
87         fbb_vset_out = bits32(value, 4, 0);
88         if (fbb_mux_ctrl == 1) {
89                 file.write(" * override value used -> 0x" + fbb_vset_out.toString(16) + newline);
90         } else {
91                 file.write(" * efuse value used -> 0x" + fbb_vset_in.toString(16) + newline);
92         }
93 }
95 debugSessionDAP = ds.openSession("*","CS_DAP_DebugSS");
96 debugSessionDAP.target.connect();
98 //Build a filename that includes date/time
99 var today = new Date();
100 var year4digit = today.getFullYear();
101 var month2digit = ("0" + (today.getMonth()+1)).slice(-2);
102 var day2digit = ("0" + today.getDate()).slice(-2);
103 var hour2digit = ("0" + today.getHours()).slice(-2);
104 var minutes2digit = ("0" + today.getMinutes()).slice(-2);
105 var seconds2digit = ("0" + today.getSeconds()).slice(-2);
106 var filename_date = '_' + year4digit + '-' + month2digit + '-' + day2digit + '_' + hour2digit + minutes2digit + seconds2digit;
107 var userHomeFolder = System.getProperty("user.home");
108 var filename = userHomeFolder + '/Desktop/' + 'am57xx-avs-abb' + filename_date + '.txt';
110 file = new java.io.FileWriter(filename);
111 var newline = "\n";
113 /* Check ID_CODE register (address 0x4AE0C204) to determine which
114    AM57xx variant is being used */
115 try {
116         id_code = debugSessionDAP.memory.readWord(0,0x4AE0C204,false);
117 } catch(ex) {
118         print("\n Trouble reading ID_CODE.\n");
121 print("ID_CODE = 0x" + d2h(id_code));
123 // Check STD_FUSE_ID_2 register (address 0x4AE0C20C) for package type
124 try {
125         fuse_id_2 = debugSessionDAP.memory.readWord(0,0x4AE0C20C,false);
126 } catch(ex) {
127         print("\n Trouble reading STD_FUSE_ID_2.\n");
129 pkg_type = (fuse_id_2 & 0x00030000) >> 16;  // FUSE_ID_2[17:16] = pkg_type
131 switch(id_code) {
132         case 0x0B9BC02F:
133                 print("AM571x SR1.0 detected.\n");
134                 file.write("AM571x SR1.0 detected" + newline);
135                 device_type = 571;
136                 break;
137         case 0x1B9BC02F:
138                 if(pkg_type == 1) {
139                         print("AM570x SR2.0 detected.\n");
140                         file.write("AM570x SR2.0 detected" + newline);
141                         device_type = 570;
142                 } else if(pkg_type == 2) {
143                         print("AM571x SR2.0 detected.\n");
144                         file.write("AM571x SR2.0 detected" + newline);
145                         device_type = 571;
146                 } else
147                         print("AM571x/AM570x SR2.0 unrecognized package type\n")
148                 break;
149         case 0x2B9BC02F:
150                 if(pkg_type == 1) {
151                         print("AM570x SR2.1 detected.\n");
152                         file.write("AM570x SR2.1 detected" + newline);
153                         device_type = 570;
154                 } else if(pkg_type == 2) {
155                         print("AM571x SR2.1 detected.\n");
156                         file.write("AM571x SR2.1 detected" + newline);
157                         device_type = 571;
158                 } else
159                         print("AM571x/AM570x SR2.1 unrecognized package type\n")
160                 break;
161         case 0x0B99002F:
162                 print("AM572x SR1.0 detected.\n");
163                 file.write("AM572x SR1.0 detected" + newline);
164                 device_type = 572;
165                 break;
166         case 0x1B99002F:
167                 print("AM572x SR1.1 detected.\n");
168                 file.write("AM572x SR1.1 detected" + newline);
169                 device_type = 572;
170                 break;
171         case 0x2B99002F:
172                 print("AM572x SR2.0 detected.\n");
173                 file.write("AM572x SR2.0 detected" + newline);
174                 device_type = 572;
175                 break;
176         case 0x0BB5002F:
177                 print("AM574x SR1.0 detected.\n");
178                 file.write("AM574x SR1.0 detected" + newline);
179                 device_type = 574;
180                 break;
181         default:
182                 print("Unable to identify which AM57xx variant.\n");
183                 debugSessionDAP.target.disconnect();
184                 throw("Terminating script.\n")
185                 break;
187 file.write(newline);
189 // CTRL_WKUP_STD_FUSE_DIE_ID_0
190 reg_val = printRegisterValue(debugSessionDAP, "CTRL_WKUP_STD_FUSE_DIE_ID_0", 0x4AE0C200);
192 // CTRL_WKUP_STD_FUSE_DIE_ID_1
193 reg_val = printRegisterValue(debugSessionDAP, "CTRL_WKUP_STD_FUSE_DIE_ID_1", 0x4AE0C208);
195 // CTRL_WKUP_STD_FUSE_DIE_ID_2
196 reg_val = printRegisterValue(debugSessionDAP, "CTRL_WKUP_STD_FUSE_DIE_ID_2", 0x4AE0C20C);
198 // CTRL_WKUP_STD_FUSE_DIE_ID_3
199 reg_val = printRegisterValue(debugSessionDAP, "CTRL_WKUP_STD_FUSE_DIE_ID_3", 0x4AE0C210);
201 file.write(newline);
202 file.write("-------+--------+-----------+---------+-----------|" + newline);
203 file.write(" Rail  |  OPP   |  Voltage  |   ABB   |  ABB_LDO  |" + newline);
204 file.write("-------+--------+-----------+---------+-----------|" + newline);
205 // CTRL_CORE_STD_FUSE_OPP_VMIN_IVA_2
206 decode_fuse_opp_vmin_reg("  IVA  ", "  NOM   ", 0x4A0025CC);
207 // CTRL_CORE_STD_FUSE_OPP_VMIN_IVA_3
208 decode_fuse_opp_vmin_reg("  IVA  ", "   OD   ", 0x4A0025D0);
209 // CTRL_CORE_STD_FUSE_OPP_VMIN_IVA_4
210 decode_fuse_opp_vmin_reg("  IVA  ", "  HIGH  ", 0x4A0025D4);
211 if (device_type == 574) {
212         // CTRL_CORE_STD_FUSE_OPP_VMIN_IVA_5
213         decode_fuse_opp_vmin_reg("  IVA  ", "  PLUS  ", 0x4A0025C4);
215 file.write("-------+--------+-----------+---------+-----------|" + newline);
216 // CTRL_CORE_STD_FUSE_OPP_VMIN_DSPEVE_2
217 decode_fuse_opp_vmin_reg("  DSP  ", "  NOM   ", 0x4A0025E0);
218 // CTRL_CORE_STD_FUSE_OPP_VMIN_DSPEVE_3
219 decode_fuse_opp_vmin_reg("  DSP  ", "   OD   ", 0x4A0025E4);
220 // CTRL_CORE_STD_FUSE_OPP_VMIN_DSPEVE_4
221 decode_fuse_opp_vmin_reg("  DSP  ", "  HIGH  ", 0x4A0025E8);
222 if (device_type == 574) {
223         // CTRL_CORE_STD_FUSE_OPP_VMIN_DSPEVE_5
224         decode_fuse_opp_vmin_reg("  DSP  ", "  PLUS  ", 0x4A0025D8);
226 file.write("-------+--------+-----------+---------+-----------|" + newline);
227 // CTRL_CORE_STD_FUSE_OPP_VMIN_CORE_2
228 decode_fuse_opp_vmin_reg("  VDD  ", "  NOM   ", 0x4A0025F4);
229 file.write("-------+--------+-----------+---------+-----------|" + newline);
230 // CTRL_CORE_STD_FUSE_OPP_VMIN_GPU_2
231 decode_fuse_opp_vmin_reg("  GPU  ", "  NOM   ", 0x4A003B08);
232 // CTRL_CORE_STD_FUSE_OPP_VMIN_GPU_3
233 decode_fuse_opp_vmin_reg("  GPU  ", "   OD   ", 0x4A003B0C);
234 // CTRL_CORE_STD_FUSE_OPP_VMIN_GPU_4
235 decode_fuse_opp_vmin_reg("  GPU  ", "  HIGH  ", 0x4A003B10);
236 if (device_type == 574) {
237         // CTRL_CORE_STD_FUSE_OPP_VMIN_GPU_5
238         decode_fuse_opp_vmin_reg("  GPU  ", "  PLUS  ", 0x4A003B14);
240 file.write("-------+--------+-----------+---------+-----------|" + newline);
241 if (device_type == 574) {
242         // CTRL_CORE_STD_FUSE_OPP_VMIN_MPU_1
243         decode_fuse_opp_vmin_reg("  MPU  ", "  LOW   ", 0x4A003B1C);
245 // CTRL_CORE_STD_FUSE_OPP_VMIN_MPU_2
246 decode_fuse_opp_vmin_reg("  MPU  ", "  NOM   ", 0x4A003B20);
247 // CTRL_CORE_STD_FUSE_OPP_VMIN_MPU_3
248 decode_fuse_opp_vmin_reg("  MPU  ", "   OD   ", 0x4A003B24);
249 // CTRL_CORE_STD_FUSE_OPP_VMIN_MPU_4
250 decode_fuse_opp_vmin_reg("  MPU  ", "  HIGH  ", 0x4A003B28);
251 if (device_type == 574) {
252         // CTRL_CORE_STD_FUSE_OPP_VMIN_MPU_5
253         decode_fuse_opp_vmin_reg("  MPU  ", "  PLUS  ", 0x4A003B2C);
255 file.write("-------+--------+-----------+---------+-----------|" + newline);
256 file.write(newline);
258 // CTRL_CORE_LDOVBB_IVA_VOLTAGE_CTRL
259 reg_val = printRegisterValue(debugSessionDAP, "CTRL_CORE_LDOVBB_IVA_VOLTAGE_CTRL", 0x4A002470);
260 decode_ldovbb_voltage_ctrl(reg_val);
261 file.write(newline);
263 // CTRL_CORE_LDOVBB_DSPEVE_VOLTAGE_CTRL
264 reg_val = printRegisterValue(debugSessionDAP, "CTRL_CORE_LDOVBB_DSPEVE_VOLTAGE_CTRL", 0x4A00246C);
265 decode_ldovbb_voltage_ctrl(reg_val);
266 file.write(newline);
268 // CTRL_WKUP_LDOVBB_GPU_VOLTAGE_CTRL
269 reg_val = printRegisterValue(debugSessionDAP, "CTRL_WKUP_LDOVBB_GPU_VOLTAGE_CTRL", 0x4AE0C154);
270 decode_ldovbb_voltage_ctrl(reg_val);
271 file.write(newline);
272 // CTRL_WKUP_LDOVBB_MPU_VOLTAGE_CTRL
273 reg_val = printRegisterValue(debugSessionDAP, "CTRL_WKUP_LDOVBB_MPU_VOLTAGE_CTRL", 0x4AE0C158);
274 decode_ldovbb_voltage_ctrl(reg_val);
275 file.write(newline);
277 print("Data collection complete.");
279 file.close();
280 debugSessionDAP.target.disconnect();
281 print("Created file " + filename);