75ae7fc88b3b05607bb51e6892d69e78fb385d22
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_FIELD = 3
11 COL_RES_COUNT = 5
12 COL_RES_START = 6
13 COL_HOST_START = 7
15 ROW_HOST_ID = 0
16 ROW_RES_START = 2
18 dict_dev = {}
19 dict_subtype = {}
20 dict_host = {}
21 utypes = []
23 def evalcmd(cmd):
24 out = subprocess.check_output(cmd, shell=True).decode("utf-8")
25 return out
27 def gen_soc_py_data(soc):
28 output = '''%s
30 RESASG_TYPE_SHIFT = 6
31 RESASG_SUBTYPE_SHIFT = 0
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 sorted(dict_dev.items(), key=lambda x: x[1]):
40 (dev, dev_id) = i
41 devs += '"%s" : %d,\n' % (dev, dev_id)
43 subtypes = ""
44 for i in sorted(dict_subtype.items(), key=lambda x: x[1]):
45 (subtype, subtype_id) = i
46 subtypes += '"%s" : %d,\n' % (subtype, subtype_id)
48 hosts = ""
49 for i in sorted(dict_host.items(), key=lambda x: x[1]):
50 (host, host_id) = i
51 hosts += '"%s" : %d,\n' % (host, host_id)
53 return output % (header, devs, subtypes, hosts)
55 def gen_rm_resasg_sheet(sheet):
57 fmt_header = xlwt.easyxf('font: color-index blue, bold on')
58 fmt_grayed = xlwt.easyxf('font: bold on; align: horiz center; pattern: pattern solid, fore-colour gray25')
60 sheet.write(0, COL_RES_TYPE, "Type", fmt_header)
61 sheet.write(0, COL_SUB_TYPE, "Subtype", fmt_header)
62 sheet.write(0, COL_RES_COUNT, "Availalbe count", fmt_header)
63 sheet.write(0, COL_RES_START, "start", fmt_header)
64 col = COL_HOST_START
65 for item in sorted(dict_host.items(), key=lambda x: x[1]):
66 (host, host_id) = item
67 sheet.write(0, col, host, fmt_header)
68 if (host == "HOST_ID_ALL"):
69 COL_BALANCE = col
70 col = col + 1
71 row = 1
72 for entry in utypes:
73 (dev, subtype, start, count) = entry
74 sheet.write(row, COL_RES_TYPE, dev)
75 sheet.write(row, COL_SUB_TYPE, subtype)
76 sheet.write(row, COL_RES_START, start)
77 sheet.write(row, COL_RES_COUNT, count)
78 formula = xlwt.Formula('%s - SUM(%s:%s)' % (
79 rowcol_to_cell(row, COL_RES_COUNT),
80 rowcol_to_cell(row, COL_HOST_START),
81 rowcol_to_cell(row, COL_BALANCE - 1)
82 ))
83 sheet.write(row, COL_BALANCE, formula, fmt_grayed)
84 row = row + 1
87 ################################################################################
88 ## Main program starts here ##
89 ################################################################################
91 parser = argparse.ArgumentParser(prog='RM-autogen.py', formatter_class=argparse.RawTextHelpFormatter,
92 description='RM-autogen.py - Auto generate the Resource Management data')
94 parser.add_argument('-s', '--soc', required=True, dest='soc',
95 action='store', choices=['j721e', 'am65x'],
96 help='SoC name')
98 parser.add_argument('-o', '--output', required=True, dest='output',
99 action='store',
100 help='output file name')
102 parser.add_argument('--sysfw_path', required=True, dest='prefix',
103 action='store',
104 help='Path to system firmware repo')
106 args = parser.parse_args()
107 print(args)
109 # Parse docuemntation and extract host_id defines
110 output = evalcmd('cat %s/output/%s/sec_proxy/hosts.h | grep "#define HOST_ID" | awk -F"[ ()]*" \'{print $2" " $3}\'' % (args.prefix, args.soc))
111 for line in output.split('\n'):
112 if (line == ''):
113 continue
114 (host, host_id) = line.split(' ')
115 host_id = int(host_id.strip(string.ascii_letters), 0)
116 dict_host[host] = host_id
118 # Parse docuemntation and extract dev_id and subtype defines
119 output = evalcmd('cat %s/output/%s/rm/resasg_types.rst | grep -v "\------" | grep -A100000 "+======" | tail -n +2' % (args.prefix, args.soc))
120 dev = dev_id = None
121 for line in output.split('\n'):
122 array = line.replace(' ', '').split('|')
123 if(len(array) == 1):
124 continue
126 if (array[1] != ''):
127 (x, dev, dev_id, subtype, subtype_id, utype_id, start, count, x) = array
128 elif (array[3] != ''):
129 (x, x, x, subtype, subtype_id, utype_id, start, count, x) = array
130 else:
131 (x, x, x, x, x, x, start, count, x) = array
133 #print (dev, dev_id, subtype, subtype_id, utype_id, start, count)
134 dict_dev[dev] = int(dev_id, 0)
135 dict_subtype[subtype] = int(subtype_id, 0)
136 # TODO Add raneg parsing when documentation supports
137 utypes.append((dev, subtype, start, count))
139 '''
140 #Parse bordconfig to extract the dev, subtype and range of resources
141 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))
142 for line in output.split('\n'):
143 if (line == ''):
144 continue
145 match = re.match("RESASG_UTYPE.(.*), (.*)., (.*)U, (.*)U,.*", line)
146 if (match == None):
147 continue
148 (dev, subtype, start, count) = match.groups(0)
149 start = int(start)
150 count = int(count)
151 #print((dev, subtype, start, count))
152 utypes.append((dev, subtype, start, count))
153 '''
155 #print(dict_dev)
156 #print(dict_subtype)
157 #print(utypes)
159 #Generate the soc data defines
160 data = gen_soc_py_data(args.soc)
161 ofile = open("%s.py" % args.soc, "w")
162 ofile.write(data)
163 ofile.close()
165 #Generate the excel sheet with default values
166 workbook = xlwt.Workbook()
167 sheet = workbook.add_sheet(args.soc)
168 gen_rm_resasg_sheet(sheet)
169 workbook.save(args.output)