3afaf885ab895e549a8ddb32497a976a136f8c31
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
7 COL_COMMENT = 0
8 COL_RES_TYPE = 1
9 COL_SUB_TYPE = 2
10 COL_RES_COUNT = 3
11 COL_RES_START = 4
12 COL_HOST_START = 5
14 ROW_HOST_ID = 0
15 ROW_RES_START = 1
17 dict_dev = {}
18 dict_subtype = {}
19 dict_host = {}
20 utypes = []
22 def evalcmd(cmd):
23 out = subprocess.check_output(cmd, shell=True).decode("utf-8")
24 return out
26 def gen_soc_py_data(soc):
27 output = '''%s
29 RESASG_TYPE_SHIFT = 6
30 RESASG_SUBTYPE_SHIFT = 0
32 const_values = {
33 %s
34 %s
35 %s}'''
36 header = "# %s.py - Auto generated SoC data\n" % soc
37 devs = ""
38 for i in sorted(dict_dev.items(), key=lambda x: x[1]):
39 (dev, dev_id) = i
40 devs += '"%s" : %d,\n' % (dev, dev_id)
42 subtypes = ""
43 for i in sorted(dict_subtype.items(), key=lambda x: x[1]):
44 (subtype, subtype_id) = i
45 subtypes += '"%s" : %d,\n' % (subtype, subtype_id)
47 hosts = ""
48 for i in sorted(dict_host.items(), key=lambda x: x[1]):
49 (host, host_id) = i
50 hosts += '"%s" : %d,\n' % (host, host_id)
52 return output % (header, devs, subtypes, hosts)
54 def gen_rm_resasg_csv():
55 output = ""
56 for entry in utypes:
57 (dev, subtype, start, count) = entry
58 output += "%s,%s,%d,%d\n" % (dev, subtype, start, count)
59 return output
61 def gen_rm_resasg_sheet(sheet):
63 fmt_header = xlwt.easyxf('font: color-index blue, bold on')
64 fmt_grayed = xlwt.easyxf('font: bold on; align: horiz center; pattern: pattern solid, fore-colour gray25')
66 sheet.write(0, COL_RES_TYPE, "Type", fmt_header)
67 sheet.write(0, COL_SUB_TYPE, "Subtype", fmt_header)
68 sheet.write(0, COL_RES_COUNT, "Availalbe count", fmt_header)
69 sheet.write(0, COL_RES_START, "start", fmt_header)
70 col = COL_HOST_START
71 for item in sorted(dict_host.items(), key=lambda x: x[1]):
72 (host, host_id) = item
73 sheet.write(0, col, host, fmt_header)
74 if (host == "HOST_ID_ALL"):
75 COL_BALANCE = col
76 col = col + 1
77 row = 1
78 for entry in utypes:
79 (dev, subtype, start, count) = entry
80 sheet.write(row, COL_RES_TYPE, dev)
81 sheet.write(row, COL_SUB_TYPE, subtype)
82 sheet.write(row, COL_RES_START, start)
83 sheet.write(row, COL_RES_COUNT, count)
84 formula = xlwt.Formula('%s - SUM(%s:%s)' % (
85 rowcol_to_cell(row, COL_RES_COUNT),
86 rowcol_to_cell(row, COL_HOST_START),
87 rowcol_to_cell(row, COL_BALANCE - 1)
88 ))
89 sheet.write(row, COL_BALANCE, formula, fmt_grayed)
90 row = row + 1
93 ################################################################################
94 ## Main program starts here ##
95 ################################################################################
97 parser = argparse.ArgumentParser(prog='RM-autogen.py', formatter_class=argparse.RawTextHelpFormatter,
98 description='RM-autogen.py - Auto generate the Resource Management data')
100 parser.add_argument('-s', '--soc', required=True, dest='soc',
101 action='store', choices=['j721e', 'am65x'],
102 help='SoC name')
104 parser.add_argument('-o', '--output', required=True, dest='output',
105 action='store',
106 help='output file name')
108 parser.add_argument('--sysfw_path', required=True, dest='prefix',
109 action='store',
110 help='Path to system firmware repo')
112 args = parser.parse_args()
113 print(args)
115 # Parse docuemntation and extract host_id defines
116 output = evalcmd('cat %s/output/%s/sec_proxy/hosts.h | grep "#define HOST_ID" | awk -F"[ ()]*" \'{print $2" " $3}\'' % (args.prefix, args.soc))
117 for line in output.split('\n'):
118 if (line == ''):
119 continue
120 (host, host_id) = line.split(' ')
121 host_id = int(host_id.strip(string.ascii_letters), 0)
122 dict_host[host] = host_id
124 # Parse docuemntation and extract dev_id and subtype defines
125 output = evalcmd('cat %s/output/%s/rm/resasg_types.rst | grep -v "\------" | grep -A100000 "+======" | tail -n +2' % (args.prefix, args.soc))
126 dev = dev_id = None
127 for line in output.split('\n'):
128 array = line.replace(' ', '').split('|')
129 if(len(array) == 1):
130 continue
132 if (array[1] != ''):
133 (x, dev, dev_id, subtype, subtype_id, utype_id, start, count, x) = array
134 elif (array[3] != ''):
135 (x, x, x, subtype, subtype_id, utype_id, start, count, x) = array
136 else:
137 (x, x, x, x, x, x, start, count, x) = array
138 start=int(start, 0)
139 count=int(count, 0)
141 #print (dev, dev_id, subtype, subtype_id, utype_id, start, count)
142 dict_dev[dev] = int(dev_id, 0)
143 dict_subtype[subtype] = int(subtype_id, 0)
144 utypes.append((dev, subtype, start, count))
146 '''
147 #Parse bordconfig to extract the dev, subtype and range of resources
148 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))
149 for line in output.split('\n'):
150 if (line == ''):
151 continue
152 match = re.match("RESASG_UTYPE.(.*), (.*)., (.*)U, (.*)U,.*", line)
153 if (match == None):
154 continue
155 (dev, subtype, start, count) = match.groups(0)
156 start = int(start)
157 count = int(count)
158 #print((dev, subtype, start, count))
159 utypes.append((dev, subtype, start, count))
160 '''
162 #print(dict_dev)
163 #print(dict_subtype)
164 #print(utypes)
166 #Generate the soc data defines
167 data = gen_soc_py_data(args.soc)
168 ofile = open("%s.py" % args.soc, "w")
169 ofile.write(data)
170 ofile.close()
172 #Generate the csv file with default values
173 data = gen_rm_resasg_csv()
174 ofile = open("%s.csv" % args.soc, "w")
175 ofile.write(data)
176 ofile.close()
178 #Generate the excel sheet with default values
179 workbook = xlwt.Workbook()
180 sheet = workbook.add_sheet(args.soc)
181 gen_rm_resasg_sheet(sheet)
182 workbook.save(args.output)