1 #!/usr/bin/python
2 #
3 # Copyright (c) 2021, Texas Instruments Incorporated
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 #
10 # * Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 #
13 # * Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in the
15 # documentation and/or other materials provided with the distribution.
16 #
17 # * Neither the name of Texas Instruments Incorporated nor the names of
18 # its contributors may be used to endorse or promote products derived
19 # from this software without specific prior written permission.
20 #
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28 # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
31 # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #
34 from __future__ import print_function
35 import re
36 import sys
38 if len(sys.argv) != 2:
39 print() # Empty line
40 print(sys.argv[0], "help:\n")
41 print("Please pass the rd1 file to this script, e.g.:")
42 print("", sys.argv[0], "am57xx-avs-abb_yyyy-mm-dd_hhmmss.rd1\n")
43 print("Output file will have same base name as input, "
44 "but csv file type.\n")
45 sys.exit(1)
47 # Inputs:
48 # Data - 32-bit register value
49 # Upper - Highest bit to keep
50 # Lower - Lowest bit to keep
51 # (bit 0 refers to LSB, bit 31 to MSB)
52 # Return: right aligned data
53 def bits32(data, upper, lower):
54 data = data >> lower # unsigned right-shift
55 upper = upper - lower
56 bitmask = 0xFFFFFFFF >> (31 - upper)
57 return (data & bitmask)
59 def get_data(reg_addr):
60 valid = 1
61 try:
62 reg_index = address_list.index(reg_addr)
63 except ValueError:
64 print("Error finding address", hex(reg_addr))
65 valid = 0
66 return (valid, 0)
67 return (valid, data_list[reg_index])
69 # Input: address of CTRL_CORE_STD_FUSE_OPP_VMIN_x register
70 # Returns decoded values for voltage, abb_en, and the ABB LDO voltage
71 def decode_fuse_opp_vmin_reg(reg_addr):
72 valid = 1
73 value = get_data(reg_addr)
74 if value[0]:
75 voltage = bits32(value[1], 11, 0)
76 abb_en = bits32(value[1], 25, 25)
77 vsetabb = bits32(value[1], 24, 20)
78 return (valid, voltage, abb_en, vsetabb)
79 else:
80 return (0, 0, 0, 0)
82 try:
83 rd1 = open(sys.argv[1], "rt")
84 except IOError:
85 print("Error: input file", sys.argv[1], "not accessible.")
86 sys.exit(1)
88 try:
89 csv_filename = sys.argv[1]
90 csv_filename = csv_filename.replace(".rd1", ".csv")
91 csv = open(csv_filename, "w+")
92 except IOError:
93 print("Error creating file", csv_filename)
95 # CSV files must use \r\n for all line endings
96 # Create header row
97 csv.write("Rail,OPP,Voltage,ABB,ABB_LDO\r\n")
98 csv_string = "%s,%s,%s,%d,0x%02x\r\n"
100 # Throw away header row
101 header = rd1.readline()
103 # Read rd1 file into separate lists for address and data
104 address_list = [] # empty list to contain addresses
105 data_list = [] # empty list to contain data
106 for lines in rd1:
107 # Use regular expression to extract address and data from rd1
108 m = re.match(r'(0x[0-9a-fA-F]{8})\s+(0x[0-9a-fA-F]{8})', lines, 0)
109 if m:
110 alphanum1 = m.group(1) # address (string)
111 alphanum2 = m.group(2) # data (string)
112 address = int(alphanum1, 16) # convert from string to number
113 register_value = int(alphanum2, 16) # convert from string
114 address_list.append(address)
115 data_list.append(register_value)
117 rd1.close()
118 csv.close()