2 # SPDX-License-Identifier: GPL-2.0+
3 # Copyright (C) 2019 Luca Ceresoli <luca@lucaceresoli.net>
11 parser = argparse.ArgumentParser(
12 description='Convert a PMU configuration object from C source to a binary blob.')
13 parser.add_argument('-D', '--debug', action="store_true")
15 "in_file", metavar='INPUT_FILE',
16 help='PMU configuration object (C source as produced by Xilinx XSDK)')
18 "out_file", metavar='OUTPUT_FILE',
19 help='PMU configuration object binary blob')
20 args = parser.parse_args()
22 logging.basicConfig(format='%(levelname)s:%(message)s',
23 level=(logging.DEBUG if args.debug else logging.WARNING))
26 'PM_CAP_ACCESS' : 0x1,
27 'PM_CAP_CONTEXT' : 0x2,
28 'PM_CAP_WAKEUP' : 0x4,
41 'NODE_OCM_BANK_0' : 11,
42 'NODE_OCM_BANK_1' : 12,
43 'NODE_OCM_BANK_2' : 13,
44 'NODE_OCM_BANK_3' : 14,
87 'NODE_IPI_RPU_0' : 57,
94 'NODE_IPI_RPU_1' : 64,
102 'XILPM_RESET_PCIE_CFG' : 1000,
103 'XILPM_RESET_PCIE_BRIDGE' : 1001,
104 'XILPM_RESET_PCIE_CTRL' : 1002,
105 'XILPM_RESET_DP' : 1003,
106 'XILPM_RESET_SWDT_CRF' : 1004,
107 'XILPM_RESET_AFI_FM5' : 1005,
108 'XILPM_RESET_AFI_FM4' : 1006,
109 'XILPM_RESET_AFI_FM3' : 1007,
110 'XILPM_RESET_AFI_FM2' : 1008,
111 'XILPM_RESET_AFI_FM1' : 1009,
112 'XILPM_RESET_AFI_FM0' : 1010,
113 'XILPM_RESET_GDMA' : 1011,
114 'XILPM_RESET_GPU_PP1' : 1012,
115 'XILPM_RESET_GPU_PP0' : 1013,
116 'XILPM_RESET_GPU' : 1014,
117 'XILPM_RESET_GT' : 1015,
118 'XILPM_RESET_SATA' : 1016,
119 'XILPM_RESET_ACPU3_PWRON' : 1017,
120 'XILPM_RESET_ACPU2_PWRON' : 1018,
121 'XILPM_RESET_ACPU1_PWRON' : 1019,
122 'XILPM_RESET_ACPU0_PWRON' : 1020,
123 'XILPM_RESET_APU_L2' : 1021,
124 'XILPM_RESET_ACPU3' : 1022,
125 'XILPM_RESET_ACPU2' : 1023,
126 'XILPM_RESET_ACPU1' : 1024,
127 'XILPM_RESET_ACPU0' : 1025,
128 'XILPM_RESET_DDR' : 1026,
129 'XILPM_RESET_APM_FPD' : 1027,
130 'XILPM_RESET_SOFT' : 1028,
131 'XILPM_RESET_GEM0' : 1029,
132 'XILPM_RESET_GEM1' : 1030,
133 'XILPM_RESET_GEM2' : 1031,
134 'XILPM_RESET_GEM3' : 1032,
135 'XILPM_RESET_QSPI' : 1033,
136 'XILPM_RESET_UART0' : 1034,
137 'XILPM_RESET_UART1' : 1035,
138 'XILPM_RESET_SPI0' : 1036,
139 'XILPM_RESET_SPI1' : 1037,
140 'XILPM_RESET_SDIO0' : 1038,
141 'XILPM_RESET_SDIO1' : 1039,
142 'XILPM_RESET_CAN0' : 1040,
143 'XILPM_RESET_CAN1' : 1041,
144 'XILPM_RESET_I2C0' : 1042,
145 'XILPM_RESET_I2C1' : 1043,
146 'XILPM_RESET_TTC0' : 1044,
147 'XILPM_RESET_TTC1' : 1045,
148 'XILPM_RESET_TTC2' : 1046,
149 'XILPM_RESET_TTC3' : 1047,
150 'XILPM_RESET_SWDT_CRL' : 1048,
151 'XILPM_RESET_NAND' : 1049,
152 'XILPM_RESET_ADMA' : 1050,
153 'XILPM_RESET_GPIO' : 1051,
154 'XILPM_RESET_IOU_CC' : 1052,
155 'XILPM_RESET_TIMESTAMP' : 1053,
156 'XILPM_RESET_RPU_R50' : 1054,
157 'XILPM_RESET_RPU_R51' : 1055,
158 'XILPM_RESET_RPU_AMBA' : 1056,
159 'XILPM_RESET_OCM' : 1057,
160 'XILPM_RESET_RPU_PGE' : 1058,
161 'XILPM_RESET_USB0_CORERESET' : 1059,
162 'XILPM_RESET_USB1_CORERESET' : 1060,
163 'XILPM_RESET_USB0_HIBERRESET' : 1061,
164 'XILPM_RESET_USB1_HIBERRESET' : 1062,
165 'XILPM_RESET_USB0_APB' : 1063,
166 'XILPM_RESET_USB1_APB' : 1064,
167 'XILPM_RESET_IPI' : 1065,
168 'XILPM_RESET_APM_LPD' : 1066,
169 'XILPM_RESET_RTC' : 1067,
170 'XILPM_RESET_SYSMON' : 1068,
171 'XILPM_RESET_AFI_FM6' : 1069,
172 'XILPM_RESET_LPD_SWDT' : 1070,
173 'XILPM_RESET_FPD' : 1071,
174 'XILPM_RESET_RPU_DBG1' : 1072,
175 'XILPM_RESET_RPU_DBG0' : 1073,
176 'XILPM_RESET_DBG_LPD' : 1074,
177 'XILPM_RESET_DBG_FPD' : 1075,
178 'XILPM_RESET_APLL' : 1076,
179 'XILPM_RESET_DPLL' : 1077,
180 'XILPM_RESET_VPLL' : 1078,
181 'XILPM_RESET_IOPLL' : 1079,
182 'XILPM_RESET_RPLL' : 1080,
183 'XILPM_RESET_GPO3_PL_0' : 1081,
184 'XILPM_RESET_GPO3_PL_1' : 1082,
185 'XILPM_RESET_GPO3_PL_2' : 1083,
186 'XILPM_RESET_GPO3_PL_3' : 1084,
187 'XILPM_RESET_GPO3_PL_4' : 1085,
188 'XILPM_RESET_GPO3_PL_5' : 1086,
189 'XILPM_RESET_GPO3_PL_6' : 1087,
190 'XILPM_RESET_GPO3_PL_7' : 1088,
191 'XILPM_RESET_GPO3_PL_8' : 1089,
192 'XILPM_RESET_GPO3_PL_9' : 1090,
193 'XILPM_RESET_GPO3_PL_10' : 1091,
194 'XILPM_RESET_GPO3_PL_11' : 1092,
195 'XILPM_RESET_GPO3_PL_12' : 1093,
196 'XILPM_RESET_GPO3_PL_13' : 1094,
197 'XILPM_RESET_GPO3_PL_14' : 1095,
198 'XILPM_RESET_GPO3_PL_15' : 1096,
199 'XILPM_RESET_GPO3_PL_16' : 1097,
200 'XILPM_RESET_GPO3_PL_17' : 1098,
201 'XILPM_RESET_GPO3_PL_18' : 1099,
202 'XILPM_RESET_GPO3_PL_19' : 1100,
203 'XILPM_RESET_GPO3_PL_20' : 1101,
204 'XILPM_RESET_GPO3_PL_21' : 1102,
205 'XILPM_RESET_GPO3_PL_22' : 1103,
206 'XILPM_RESET_GPO3_PL_23' : 1104,
207 'XILPM_RESET_GPO3_PL_24' : 1105,
208 'XILPM_RESET_GPO3_PL_25' : 1106,
209 'XILPM_RESET_GPO3_PL_26' : 1107,
210 'XILPM_RESET_GPO3_PL_27' : 1108,
211 'XILPM_RESET_GPO3_PL_28' : 1109,
212 'XILPM_RESET_GPO3_PL_29' : 1110,
213 'XILPM_RESET_GPO3_PL_30' : 1111,
214 'XILPM_RESET_GPO3_PL_31' : 1112,
215 'XILPM_RESET_RPU_LS' : 1113,
216 'XILPM_RESET_PS_ONLY' : 1114,
217 'XILPM_RESET_PL' : 1115,
218 'XILPM_RESET_GPIO5_EMIO_92' : 1116,
219 'XILPM_RESET_GPIO5_EMIO_93' : 1117,
220 'XILPM_RESET_GPIO5_EMIO_94' : 1118,
221 'XILPM_RESET_GPIO5_EMIO_95' : 1119,
223 'PM_CONFIG_MASTER_SECTION_ID' : 0x101,
224 'PM_CONFIG_SLAVE_SECTION_ID' : 0x102,
225 'PM_CONFIG_PREALLOC_SECTION_ID' : 0x103,
226 'PM_CONFIG_POWER_SECTION_ID' : 0x104,
227 'PM_CONFIG_RESET_SECTION_ID' : 0x105,
228 'PM_CONFIG_SHUTDOWN_SECTION_ID' : 0x106,
229 'PM_CONFIG_SET_CONFIG_SECTION_ID' : 0x107,
230 'PM_CONFIG_GPO_SECTION_ID' : 0x108,
232 'PM_SLAVE_FLAG_IS_SHAREABLE' : 0x1,
233 'PM_MASTER_USING_SLAVE_MASK' : 0x2,
235 'PM_CONFIG_GPO1_MIO_PIN_34_MAP' : (1 << 10),
236 'PM_CONFIG_GPO1_MIO_PIN_35_MAP' : (1 << 11),
237 'PM_CONFIG_GPO1_MIO_PIN_36_MAP' : (1 << 12),
238 'PM_CONFIG_GPO1_MIO_PIN_37_MAP' : (1 << 13),
240 'PM_CONFIG_GPO1_BIT_2_MASK' : (1 << 2),
241 'PM_CONFIG_GPO1_BIT_3_MASK' : (1 << 3),
242 'PM_CONFIG_GPO1_BIT_4_MASK' : (1 << 4),
243 'PM_CONFIG_GPO1_BIT_5_MASK' : (1 << 5),
245 'SUSPEND_TIMEOUT' : 0xFFFFFFFF,
247 'PM_CONFIG_IPI_PSU_CORTEXA53_0_MASK' : 0x00000001,
248 'PM_CONFIG_IPI_PSU_CORTEXR5_0_MASK' : 0x00000100,
249 'PM_CONFIG_IPI_PSU_CORTEXR5_1_MASK' : 0x00000200,
252 in_file = open(args.in_file, mode='r')
253 out_file = open(args.out_file, mode='wb')
255 num_re = re.compile(r"^([0-9]+)U?$")
256 const_re = re.compile(r"^([A-Z_][A-Z0-9_]*)$")
258 def process_item(item):
259 logging.debug("* ITEM " + item)
262 for item in item.split('|'):
265 num_match = num_re .match(item)
266 const_match = const_re.match(item)
269 num = int(num_match.group(1))
270 logging.debug(" - num " + str(num))
273 name = const_match.group(1)
274 if not name in pm_define:
275 sys.stderr.write("Unknown define " + name + "!\n")
277 num = pm_define[name]
278 logging.debug(" - def " + hex(num))
281 logging.debug(" = res " + hex(value))
282 out_file.write(struct.pack('<L', value))
286 code = in_file.read()
289 code = re.sub('//.*?\n|/\*.*?\*/', '', code, flags=re.DOTALL)
291 # remove everything outside the XPm_ConfigObject array definition
292 code = re.search('const u32 XPm_ConfigObject.*= {\n(.*)};',
293 code, flags=re.DOTALL).group(1)
295 # Process each comma-separated array item
296 for item in code.split(','):
301 print("Wrote %d bytes" % out_file.tell())