RM-autogen.py: Add support for sorting the entries
authorNikhil Devshatwar <nikhil.nd@ti.com>
Thu, 27 Feb 2020 13:26:59 +0000 (18:56 +0530)
committerNikhil Devshatwar <nikhil.nd@ti.com>
Thu, 27 Feb 2020 13:59:59 +0000 (19:29 +0530)
Starting from SYSFW 2020.01, All the RM boarconfig entries
need to be sorted in the following manner
* ascending order of utype, if same,
* ascending order of start_resource, if same
* ascending order of host_id

Implement this using custom_key for sorted function.
Use the j721e SoC data to use the values of the macros.

Signed-off-by: Nikhil Devshatwar <nikhil.nd@ti.com>
respart/RM-autogen.py

index 54705616dac20666ad81600d141b563d2be88732..00b33347c9ac6a416e77ce6afe9bd5e0ccc1471e 100755 (executable)
@@ -20,21 +20,11 @@ COL_HOST_START = 7
 ROW_HOST_ID = 0
 ROW_RES_START = 2
 
-def gen_rmcfg_data(sharing):
-
-       rmcfg = ''
-       num_entries = 0
-       rmconfig_comment = '''
-               /* %s */\n'''
-       rmconfig_templ = '''\
-               {
-                       .start_resource = %d,
-                       .num_resource = %d,
-                       .type = RESASG_UTYPE (%s,
-                                       %s),
-                       .host_id = %s,
-               },\n'''
+comments = {}
 
+def gen_rmcfg_data(sharing):
+       global comments
+       rmcfg = []
        for res in range(ROW_RES_START, sheet.nrows):
 
                comment = sheet.cell_value(res, COL_COMMENT)
@@ -43,6 +33,8 @@ def gen_rmcfg_data(sharing):
                start = sheet.cell_value(res, COL_RES_START)
                if (restype == '' or subtype == '' or start == ''):
                        continue
+               start = int(start)
+               comments[(restype, subtype)] = comment
 
                for host in range(COL_HOST_START, sheet.ncols):
 
@@ -54,25 +46,54 @@ def gen_rmcfg_data(sharing):
                        num = sheet.cell_value(res, host)
                        if (num == '' or int(num) == 0):
                                continue
+                       num = int(num)
 
-                       if (comment != None):
-                               rmcfg += rmconfig_comment % comment
-                               comment = None
-
-                       rmcfg += (rmconfig_templ % (start, num, restype, subtype, host_id))
-                       num_entries += 1
+                       rmcfg.append((start, num, restype, subtype, host_id))
 
                        for pair in sharing:
                                if (host_id != pair[0]):
                                        continue
 
                                shared_host = pair[1]
-                               rmcfg += (rmconfig_templ % (start, num, restype, subtype, shared_host))
-                               num_entries += 1
+                               rmcfg.append((start, num, restype, subtype, shared_host))
+
 
                        start += int(num)
-       return (rmcfg, num_entries)
+       return rmcfg
 
+def print_rmcfg(rmcfg):
+       comment_templ = '''
+               /* %s */\n'''
+       rmconfig_templ = '''\
+               {
+                       .start_resource = %d,
+                       .num_resource = %d,
+                       .type = RESASG_UTYPE (%s,
+                                       %s),
+                       .host_id = %s,
+               },\n'''
+       output = ""
+
+       def custom_key(entry):
+               (start, num, restype, subtype, host) = entry
+               restype = soc.const_values[restype]
+               subtype = soc.const_values[subtype]
+               host = soc.const_values[host]
+               utype = (restype << soc.RESASG_TYPE_SHIFT) | (subtype << soc.RESASG_SUBTYPE_SHIFT)
+               val = (utype << 24) | (start << 8) | (host << 0)
+               return val
+
+       sorted_rmcfg = sorted(rmcfg, key=custom_key)
+
+       comment = None
+       for entry in sorted_rmcfg:
+               (start, num, restype, subtype, host) = entry
+
+               if (comment != comments[(restype, subtype)]):
+                       comment = comments[(restype, subtype)]
+                       output += comment_templ % comment
+               output += rmconfig_templ % (start, num, restype, subtype, host)
+       return output
 
 ################################################################################
 ##                          Main program starts here                          ##
@@ -85,7 +106,7 @@ parser.add_argument('-f', '--format', required=True, dest='format',
        action='store', choices=["boardconfig", "rtos_rmcfg", "jailhouse_cell_config"],
        help='format to select the output file')
 
-parser.add_argument('-o', '--output', dest='output',
+parser.add_argument('-o', '--output', required=True, dest='output',
        action='store',
        help='output file name')
 
@@ -103,23 +124,16 @@ sheet = workbook.sheet_by_index(0)
 
 #sheet.nrows = 9
 if (args.format == 'boardconfig'):
-       (rmcfg, num_entries) = gen_rmcfg_data(args.share)
-       print ("Total entries = %d" % num_entries)
-       msg = "Generated rm-cfg.c"
-       data = rmcfg
-elif (args.format == 'rtos_rmcfg'):
-       (rtos_rmcfg, num_entries) = gen_rtos_rmcfg_data()
-       msg = "Generated udma_rm-cfg.c"
-       data = rtos_rmcfg
+       boardconfig = gen_rmcfg_data(args.share)
+       print ("Total entries = %d" % len(boardconfig))
+       data = print_rmcfg(boardconfig)
 else:
        print ("ERROR: format %s not supported")
+       exit(1)
 
 
-if (args.output):
-       ofile = open(args.output, "w")
-       ofile.write(data)
-       ofile.close()
-else:
-       print ("%s\n%s" % (msg, data))
+ofile = open(args.output, "w")
+ofile.write(data)
+ofile.close()
 
 # END OF FILE