-
Notifications
You must be signed in to change notification settings - Fork 2
/
dtconfig.py
executable file
·124 lines (97 loc) · 3.81 KB
/
dtconfig.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import yaml
import sys
"""
Example usage:
$> python dtconfig.py path/to/hwconfig.user [output_dt_overlay_filename]
"""
####### PARAMETER DEFINITIONS ###############
# value of "compatible" property for hls nodes
hls_compatible_string = "hls-target"
# value of "compatible" property for dmas
dma_compatible_string = "hls-dma"
# name of hls node's property that references input dmas
prop_name_dmas = "dmas"
# name of dma node's property that references parent hls node
prop_name_hls_ref = "hls-node"
# name of the property that contains device node's name
prop_name_node_name = "hw-name"
######## END OF PARAMETE DEFINITIONS ########
# check command-line args
usage_prompt = "usage: python dtconfig.py <path/to/hwconfig_file> [output_dt_overlay_filename]"
if(len(sys.argv) < 2):
print(usage_prompt)
exit()
cfg_file_path = sys.argv[1]
if (len(sys.argv) == 3):
dts_file_path = sys.argv[2]
else:
dts_file_path = "system-user-overlay.dtsi"
# read yaml file and convert to dictionary
with open(cfg_file_path, 'r') as cfg_file:
cfg = yaml.load(cfg_file)
if 'hw' not in cfg:
sys.exit("[dtconfig]: the 'hw' node not found in the provided hardware configuration file")
overlay = dict()
# overlay initialization
for hw_node in cfg['hw']:
node_type = hw_node['type']
node_name = hw_node['name']
if (node_type == 'dma' or node_type == 'hls'):
overlay[node_name] = dict()
overlay[node_name]['definition'] = hw_node
if(node_type == 'dma'):
overlay[node_name]['direction'] = 0
overlay[node_name]['hls-node'] = ""
else: # node_type == 'hls'
# not using set because we want to perserve order
overlay[node_name]['dmas'] = []
# filling in overlay info
for key in overlay:
node = overlay[key]['definition']
node_type = node['type']
node_name = node['name']
if(node_type == 'dma'):
if 'outputto' in node:
overlay[node_name]['direction'] += 1
outputto = node["outputto"].split('.')[0]
overlay[node_name]['hls-node'] = outputto
if node_name not in overlay[outputto]['dmas']:
overlay[outputto]['dmas'].append(node_name)
else:
if node['outputto'] in overlay and overlay[node['outputto']]['definition']['type'] == 'dma':
if node['outputto'] not in overlay[node_name]['dmas']:
overlay[node_name]['dmas'].append(node['outputto'])
overlay[node['outputto']]['hls-node'] = node_name
overlay[node['outputto']]['direction'] += 2
# creating dt overlay
dt_overlay = ""
for key in sorted(overlay.iterkeys()):
dt_overlay += "&" + key + " {"
dt_overlay += "\n\t" + prop_name_node_name + " = " + "\"" + overlay[key]['definition']['name'] + "\";"
if overlay[key]['definition']['type'] == 'dma':
if overlay[key]['hls-node'] == "":
dt_overlay += "\n\tcompatible = \"xilcam\";"
else:
dt_overlay += "\n\tcompatible = \"" + dma_compatible_string + "\";"
dt_overlay += "\n\tdirection = <" + str(overlay[key]['direction']) + ">;"
dt_overlay += "\n\t" + prop_name_hls_ref + " = <&" + overlay[key]['hls-node'] + ">;"
else:
dt_overlay += "\n\tcompatible = \"" + hls_compatible_string + "\";"
dt_overlay += "\n\tgpio = <&axi_gpio_1>;"
#input dmas
if len(overlay[key]['dmas']) == 0:
dt_overlay += "\n\t" + prop_name_dmas + " = <empty>;"
else:
dt_overlay += "\n\t" + prop_name_dmas + " = "
for counter, value in enumerate(overlay[key]['dmas']):
dt_overlay += "<&" + value + ">"
if(counter < len(overlay[key]['dmas']) - 1):
dt_overlay += ", "
else:
dt_overlay += ";"
dt_overlay += "\n};\n"
with open(dts_file_path, 'a') as dts_file:
dts_file.write(dt_overlay)
cfg_file.close()
dts_file.close()
print("[dtconfig] Device-tree overlay written to %s" % (dts_file_path))