diff options
author | Nikhil Devshatwar | 2020-03-19 10:18:49 -0500 |
---|---|---|
committer | Nikhil Devshatwar | 2020-03-19 10:19:12 -0500 |
commit | 74c209e14806a5c5dc166109c7f91388bd8b0f28 (patch) | |
tree | 0401748d58583e02def308910383e237ff639057 | |
parent | 41eb3b9988929dca33c6184fee7cde2844f7dd6e (diff) | |
download | host-tools-74c209e14806a5c5dc166109c7f91388bd8b0f28.tar.gz host-tools-74c209e14806a5c5dc166109c7f91388bd8b0f28.tar.xz host-tools-74c209e14806a5c5dc166109c7f91388bd8b0f28.zip |
RM-autogen-data.py: Auto generate the excel sheet and soc data
Signed-off-by: Nikhil Devshatwar <nikhil.nd@ti.com>
-rwxr-xr-x | respart/RM-autogen-data.py | 165 |
1 files changed, 165 insertions, 0 deletions
diff --git a/respart/RM-autogen-data.py b/respart/RM-autogen-data.py new file mode 100755 index 0000000..4346a80 --- /dev/null +++ b/respart/RM-autogen-data.py | |||
@@ -0,0 +1,165 @@ | |||
1 | #!/usr/bin/python | ||
2 | import subprocess, time, os, sys | ||
3 | import argparse, string, re | ||
4 | import xlrd, xlwt | ||
5 | from xlwt.Utils import rowcol_to_cell | ||
6 | |||
7 | COL_COMMENT = 0 | ||
8 | COL_RES_TYPE = 1 | ||
9 | COL_SUB_TYPE = 2 | ||
10 | COL_RES_FIELD = 3 | ||
11 | COL_RES_COUNT = 5 | ||
12 | COL_RES_START = 6 | ||
13 | COL_HOST_START = 7 | ||
14 | |||
15 | ROW_HOST_ID = 0 | ||
16 | ROW_RES_START = 2 | ||
17 | |||
18 | dict_dev = {} | ||
19 | dict_subtype = {} | ||
20 | dict_host = {} | ||
21 | devtypes = {} | ||
22 | |||
23 | def evalcmd(cmd): | ||
24 | out = subprocess.check_output(cmd, shell=True).decode("utf-8") | ||
25 | return out | ||
26 | |||
27 | def gen_soc_py_data(soc): | ||
28 | output = '''%s | ||
29 | |||
30 | RESASG_TYPE_SHIFT = 6 | ||
31 | RESASG_SUBTYPE_SHIFT = 0 | ||
32 | |||
33 | const_values = { | ||
34 | %s | ||
35 | %s | ||
36 | %s}''' | ||
37 | header = "# %s.py - Auto generated SoC data\n" % soc | ||
38 | devs = "" | ||
39 | for i in dict_dev: | ||
40 | devs += '"%s" : %d,\n' % (i, dict_dev[i]) | ||
41 | subtypes = "" | ||
42 | for i in dict_subtype: | ||
43 | subtypes += '"%s" : %d,\n' % (i, dict_subtype[i]) | ||
44 | hosts = "" | ||
45 | for i in dict_host: | ||
46 | hosts += '"%s" : %d,\n' % (i, dict_host[i]) | ||
47 | return output % (header, devs, subtypes, hosts) | ||
48 | |||
49 | def gen_rm_resasg_sheet(sheet): | ||
50 | |||
51 | fmt_header = xlwt.easyxf('font: color-index blue, bold on') | ||
52 | fmt_grayed = xlwt.easyxf('font: bold on; align: horiz center; pattern: pattern solid, fore-colour gray25') | ||
53 | |||
54 | sheet.write(0, COL_RES_TYPE, "Type", fmt_header) | ||
55 | sheet.write(0, COL_SUB_TYPE, "Subtype", fmt_header) | ||
56 | sheet.write(0, COL_RES_COUNT, "Availalbe count", fmt_header) | ||
57 | sheet.write(0, COL_RES_START, "start", fmt_header) | ||
58 | col = COL_HOST_START | ||
59 | for item in sorted(dict_host.items(), key=lambda x: x[1]): | ||
60 | (host, host_id) = item | ||
61 | sheet.write(0, col, host, fmt_header) | ||
62 | if (host == "HOST_ID_ALL"): | ||
63 | COL_BALANCE = col | ||
64 | col = col + 1 | ||
65 | row = 1 | ||
66 | for dev in devtypes.keys(): | ||
67 | for entry in devtypes[dev]: | ||
68 | (subtype, start, count) = entry | ||
69 | sheet.write(row, COL_RES_TYPE, dev) | ||
70 | sheet.write(row, COL_SUB_TYPE, subtype) | ||
71 | sheet.write(row, COL_RES_START, start) | ||
72 | sheet.write(row, COL_RES_COUNT, count) | ||
73 | formula = xlwt.Formula('%s - SUM(%s:%s)' % ( | ||
74 | rowcol_to_cell(row, COL_RES_COUNT), | ||
75 | rowcol_to_cell(row, COL_HOST_START), | ||
76 | rowcol_to_cell(row, COL_BALANCE - 1) | ||
77 | )) | ||
78 | sheet.write(row, COL_BALANCE, formula, fmt_grayed) | ||
79 | row = row + 1 | ||
80 | |||
81 | |||
82 | ################################################################################ | ||
83 | ## Main program starts here ## | ||
84 | ################################################################################ | ||
85 | |||
86 | parser = argparse.ArgumentParser(prog='RM-autogen.py', formatter_class=argparse.RawTextHelpFormatter, | ||
87 | description='RM-autogen.py - Auto generate the Resource Management data') | ||
88 | |||
89 | parser.add_argument('-s', '--soc', required=True, dest='soc', | ||
90 | action='store', choices=['j721e', 'am65x'], | ||
91 | help='SoC name') | ||
92 | |||
93 | parser.add_argument('-o', '--output', required=True, dest='output', | ||
94 | action='store', | ||
95 | help='output file name') | ||
96 | |||
97 | parser.add_argument('--sysfw_path', required=True, dest='prefix', | ||
98 | action='store', | ||
99 | help='Path to system firmware repo') | ||
100 | |||
101 | args = parser.parse_args() | ||
102 | print(args) | ||
103 | |||
104 | # Parse docuemntation and extract the different defines | ||
105 | output = evalcmd('cat %s/output/%s/sec_proxy/hosts.h | grep "#define HOST_ID" | awk -F"[ ()]*" \'{print $2" " $3}\'' % (args.prefix, args.soc)) | ||
106 | for line in output.split('\n'): | ||
107 | if (line == ''): | ||
108 | continue | ||
109 | (host, host_id) = line.split(' ') | ||
110 | host_id = int(host_id.strip(string.ascii_letters), 0) | ||
111 | dict_host[host] = host_id | ||
112 | |||
113 | #Following is a simpler way to generate this data from public documentation | ||
114 | ''' | ||
115 | output = evalcmd('cat %s/output/%s/rm/ | grep SUBTYPE | awk -F" " \'{ print $2" "$4" "$6" "$8" "$10 }\'' % (args.prefix, args.soc)) | ||
116 | dev = dev_id = None | ||
117 | for line in output.split('\n'): | ||
118 | if (line == ''): | ||
119 | continue | ||
120 | array = line.split(' ') | ||
121 | #print(array) | ||
122 | if (array[0] != '|'): | ||
123 | (dev, dev_id, subtype, subtype_id, utype_id) = array | ||
124 | else: | ||
125 | (dummy, subtype, subtype_id, utype_id, dummy) = array | ||
126 | |||
127 | #print (dev, dev_id, subtype, subtype_id, utype_id) | ||
128 | dict_dev[dev] = int(dev_id, 0) | ||
129 | dict_subtype[subtype] = int(subtype_id, 0) | ||
130 | if (dev in devtypes.keys()): | ||
131 | devtypes[dev].append(subtype) | ||
132 | else: | ||
133 | devtypes[dev] = [subtype] | ||
134 | |||
135 | ''' | ||
136 | output = evalcmd('cat %s/output/%s/rm/boardcfg_rm_data.c | grep -A100000 "resasg_entries" | awk \'BEGIN { FS="\\n"; RS="{" } { print $2 " " $3 " " $4 }\' | awk -F" " \'{print $3 " " $4 " " $7 " " $10}\'' % (args.prefix, args.soc)) | ||
137 | for line in output.split('\n'): | ||
138 | if (line == ''): | ||
139 | continue | ||
140 | match = re.match("RESASG_UTYPE.(.*), (.*)., (.*)U, (.*)U,.*", line) | ||
141 | if (match == None): | ||
142 | continue | ||
143 | (dev, subtype, start, count) = match.groups(0) | ||
144 | start = int(start) | ||
145 | count = int(count) | ||
146 | #print((dev, subtype, start, count)) | ||
147 | if (dev in devtypes.keys()): | ||
148 | devtypes[dev].append((subtype, start, count)) | ||
149 | else: | ||
150 | devtypes[dev] = [(subtype, start, count)] | ||
151 | #print(dict_dev) | ||
152 | #print(dict_subtype) | ||
153 | #print(devtypes) | ||
154 | |||
155 | #Generate the soc data defines | ||
156 | data = gen_soc_py_data(args.soc) | ||
157 | ofile = open("%s.py" % args.soc, "w") | ||
158 | ofile.write(data) | ||
159 | ofile.close() | ||
160 | |||
161 | #Generate the excel sheet with default values | ||
162 | workbook = xlwt.Workbook() | ||
163 | sheet = workbook.add_sheet(args.soc) | ||
164 | gen_rm_resasg_sheet(sheet) | ||
165 | workbook.save(args.output) | ||