summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikhil Devshatwar2020-03-19 10:18:49 -0500
committerNikhil Devshatwar2020-03-19 10:19:12 -0500
commit74c209e14806a5c5dc166109c7f91388bd8b0f28 (patch)
tree0401748d58583e02def308910383e237ff639057
parent41eb3b9988929dca33c6184fee7cde2844f7dd6e (diff)
downloadhost-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-xrespart/RM-autogen-data.py165
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
2import subprocess, time, os, sys
3import argparse, string, re
4import xlrd, xlwt
5from xlwt.Utils import rowcol_to_cell
6
7COL_COMMENT = 0
8COL_RES_TYPE = 1
9COL_SUB_TYPE = 2
10COL_RES_FIELD = 3
11COL_RES_COUNT = 5
12COL_RES_START = 6
13COL_HOST_START = 7
14
15ROW_HOST_ID = 0
16ROW_RES_START = 2
17
18dict_dev = {}
19dict_subtype = {}
20dict_host = {}
21devtypes = {}
22
23def evalcmd(cmd):
24 out = subprocess.check_output(cmd, shell=True).decode("utf-8")
25 return out
26
27def gen_soc_py_data(soc):
28 output = '''%s
29
30RESASG_TYPE_SHIFT = 6
31RESASG_SUBTYPE_SHIFT = 0
32
33const_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
49def 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
86parser = argparse.ArgumentParser(prog='RM-autogen.py', formatter_class=argparse.RawTextHelpFormatter,
87 description='RM-autogen.py - Auto generate the Resource Management data')
88
89parser.add_argument('-s', '--soc', required=True, dest='soc',
90 action='store', choices=['j721e', 'am65x'],
91 help='SoC name')
92
93parser.add_argument('-o', '--output', required=True, dest='output',
94 action='store',
95 help='output file name')
96
97parser.add_argument('--sysfw_path', required=True, dest='prefix',
98 action='store',
99 help='Path to system firmware repo')
100
101args = parser.parse_args()
102print(args)
103
104# Parse docuemntation and extract the different defines
105output = evalcmd('cat %s/output/%s/sec_proxy/hosts.h | grep "#define HOST_ID" | awk -F"[ ()]*" \'{print $2" " $3}\'' % (args.prefix, args.soc))
106for 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'''
115output = evalcmd('cat %s/output/%s/rm/ | grep SUBTYPE | awk -F" " \'{ print $2" "$4" "$6" "$8" "$10 }\'' % (args.prefix, args.soc))
116dev = dev_id = None
117for 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'''
136output = 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))
137for 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
156data = gen_soc_py_data(args.soc)
157ofile = open("%s.py" % args.soc, "w")
158ofile.write(data)
159ofile.close()
160
161#Generate the excel sheet with default values
162workbook = xlwt.Workbook()
163sheet = workbook.add_sheet(args.soc)
164gen_rm_resasg_sheet(sheet)
165workbook.save(args.output)