-
Notifications
You must be signed in to change notification settings - Fork 1
/
gen_yocto_machine.py
417 lines (371 loc) · 20.7 KB
/
gen_yocto_machine.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
#!/usr/bin/env python3
# Copyright (C) 2021-2022, Xilinx, Inc. All rights reserved.
# Copyright (C) 2022-2023, Advanced Micro Devices, Inc. All rights reserved.
#
# Author:
# Raju Kumar Pothuraju <rajukumar.pothuraju@amd.com>
#
# SPDX-License-Identifier: MIT
from xilinx_mirrors import *
def generate_yocto_machine(args, hw_flow):
global default_cfgfile
default_cfgfile = os.path.join(args.output, 'config')
if not os.path.isfile(default_cfgfile):
logger.error('Failed to generate .conf file, Unable to find config'
' file at: %s' % args.output)
sys.exit(255)
arch = get_config_value('CONFIG_SUBSYSTEM_ARCH_',
default_cfgfile, 'choice', '=y').lower()
soc_family = args.soc_family
import yaml
if hw_flow == 'xsct':
plnx_syshw_file = os.path.join(args.output, 'plnx_syshw_data')
else:
plnx_syshw_file = os.path.join(args.output, 'petalinux_config.yaml')
with open(plnx_syshw_file, 'r') as plnx_syshw_file_f:
plnx_syshw_data = yaml.safe_load(plnx_syshw_file_f)
plnx_syshw_file_f.close()
# Get the device_id from plnx_syshw_data
device_id = ''
if 'device_id' in plnx_syshw_data.keys():
device_id = plnx_syshw_data['device_id']
soc_variant = get_config_value('CONFIG_SUBSYSTEM_VARIANT_%s'
% soc_family.upper(),
default_cfgfile, 'choice').lower()
# Include user given machine if INCLUDE_MACHINE_NAME set
req_conf_file = get_config_value('CONFIG_YOCTO_INCLUDE_MACHINE_NAME',
default_cfgfile)
# Include soc_variant specific generic machine if soc_variant found
# if not, include soc_family machine file.
if not req_conf_file:
if soc_variant:
req_conf_file = '%s-%s-generic' % (soc_family, soc_variant)
else:
req_conf_file = '%s-generic' % (soc_family)
# Machine conf json file
import json
machinejson_file = os.path.join(scripts_dir, 'data/machineconf.json')
if not os.path.isfile(machinejson_file):
logger.error('Machine json file doesnot exist at: %s' %
machinejson_file)
sys.exit(255)
# Get the machine file name from sys config
yocto_machine_name = get_config_value('CONFIG_YOCTO_MACHINE_NAME',
default_cfgfile)
dtg_machine = get_config_value('CONFIG_SUBSYSTEM_MACHINE_NAME',
default_cfgfile)
# Use the sysconfig machine name as yocto machine
machine_conf_file = yocto_machine_name
machine_conf_path = ''
dt_board_file = ''
json_yocto_vars = ''
board_overrides = ''
# Parse json to string
with open(machinejson_file, 'r') as data_file:
machinejson_data = json.load(data_file)
data_file.close()
# Get optional machine name from sysconfig and check with json
if yocto_machine_name and yocto_machine_name in machinejson_data.keys():
# These configs includes board dtsi files associated to machine file
if 'dt-boardfile' in machinejson_data[machine_conf_file].keys():
dt_board_file = machinejson_data[machine_conf_file]['dt-boardfile']
if 'machine-overrides' in machinejson_data[machine_conf_file].keys():
board_overrides = machinejson_data[machine_conf_file]['machine-overrides']
if 'extra-yocto-vars' in machinejson_data[machine_conf_file].keys():
json_yocto_vars = '\n'.join(var for var in
machinejson_data[machine_conf_file]['extra-yocto-vars'])
else:
# Check if machine name from sysconfig is generic machine
# or machine_name and include_machine_name is same then
# Append device_id/999 to yocto_machine_name
if machine_conf_file in machinejson_data['generic-machines'] \
or machine_conf_file == req_conf_file:
if device_id:
machine_conf_file += '-' + device_id
else:
machine_conf_file += '-999'
machine_conf_path = os.path.join(args.output, machine_conf_file + '.conf')
machine_override = machine_conf_file
# Generate the yocto machine if config file changed.
if validate_hashfile(args, 'SYSTEM_CONF', default_cfgfile, update=False) and \
os.path.exists(machine_conf_path):
return machine_conf_file
# Dont generate machineconf file from gen-machineconf if hw_flow SDT
# dt-processor.sh generates it
if hw_flow == 'sdt':
return machine_conf_file
logger.info('Generating machine conf file')
# Variable for constructing ${MACHINE}.conf files.
machine_override_string = ''
# Start of ${MACHINE}-${DEVICE_ID}.conf
machine_override_string += '#@TYPE: Machine\n'
machine_override_string += '#@NAME: %s\n' % machine_conf_file
machine_override_string += '#@DESCRIPTION: Machine configuration for the '\
'%s boards.\n' % machine_conf_file
# Add config machine overrides into machine conf file
overrides = get_config_value('CONFIG_YOCTO_ADD_OVERRIDES', default_cfgfile)
if overrides:
board_overrides += overrides
if board_overrides:
machine_override_string += '\n# Compatibility with old BOARD value.\n'
machine_override_string += 'MACHINEOVERRIDES =. "%s:"\n' % board_overrides
machine_override_string += '\n#### Preamble\n'
machine_override_string += 'MACHINEOVERRIDES =. "'"${@['', '%s:']['%s' !=" \
"'${MACHINE}']}"'"\n'\
% (machine_conf_file, machine_conf_file)
machine_override_string += '#### Regular settings follow\n'
# Update machine conf file with yocto variabls from json file
if json_yocto_vars:
machine_override_string += '\n# Machine specific yocto variables\n'
machine_override_string += '%s\n' % json_yocto_vars
machine_override_string += '\n# Yocto device-tree variables\n'
serial_manual = get_config_value('CONFIG_SUBSYSTEM_SERIAL_MANUAL_SELECT',
default_cfgfile)
serial_ipname = get_config_value('CONFIG_SUBSYSTEM_SERIAL_IP_NAME',
default_cfgfile)
if not serial_manual:
machine_override_string += 'YAML_CONSOLE_DEVICE_CONFIG:pn-device-tree ?= "%s"\n' \
% serial_ipname
memory_manual = get_config_value('CONFIG_SUBSYSTEM_MEMORY_MANUAL_SELECT',
default_cfgfile)
memory_ipname = get_config_value('CONFIG_SUBSYSTEM_MEMORY_IP_NAME',
default_cfgfile)
if not memory_manual:
machine_override_string += 'YAML_MAIN_MEMORY_CONFIG:pn-device-tree ?= "%s"\n' \
% memory_ipname
dt_padding_size = get_config_value('CONFIG_SUBSYSTEM_DTB_PADDING_SIZE',
default_cfgfile)
machine_override_string += 'DT_PADDING_SIZE:pn-device-tree ?= "%s"\n' \
% dt_padding_size
dt_compiler_flags = get_config_value('CONFIG_SUBSYSTEM_DEVICETREE_COMPILER_FLAGS',
default_cfgfile)
machine_override_string += 'DTC_FLAGS:pn-device-tree ?= "%s"\n' \
% dt_compiler_flags
processor_ipname = get_config_value('CONFIG_SUBSYSTEM_PROCESSOR0_IP_NAME',
default_cfgfile)
if soc_family == 'microblaze':
machine_override_string += 'XSCTH_PROC:pn-device-tree ?= "%s"\n' \
% processor_ipname
# Set dt board file as per the machine file
# if config set to template/auto/AUTO
if dtg_machine:
if (dtg_machine == 'template' or dtg_machine.lower() == 'auto') \
and dt_board_file:
machine_override_string += 'YAML_DT_BOARD_FLAGS ?= "{BOARD %s}"\n'\
% dt_board_file
elif dtg_machine.lower() != 'auto':
machine_override_string += 'YAML_DT_BOARD_FLAGS ?= "{BOARD %s}"\n'\
% dtg_machine
machine_override_string += '\n# Yocto u-boot-xlnx variables\n'
uboot_config = get_config_value('CONFIG_SUBSYSTEM_UBOOT_CONFIG_TARGET',
default_cfgfile)
if uboot_config and uboot_config.lower() != 'auto':
machine_override_string += 'UBOOT_MACHINE ?= "%s"\n' % uboot_config
if arch == 'aarch64':
baseaddr = get_config_value('CONFIG_SUBSYSTEM_MEMORY_',
default_cfgfile, 'asterisk', '_BASEADDR=')
machine_override_string += '\n# Yocto arm-trusted-firmware(TF-A) variables\n'
atf_serial_ip_name = get_config_value('CONFIG_SUBSYSTEM_SERIAL_TF-A_IP_NAME',
default_cfgfile)
atf_serial_manual = get_config_value('CONFIG_SUBSYSTEM_TF-A_SERIAL_MANUAL_SELECT',
default_cfgfile)
if not atf_serial_manual:
machine_override_string += 'ATF_CONSOLE ?= "%s"\n' % atf_serial_ip_name
atf_mem_settings = get_config_value('CONFIG_SUBSYSTEM_TF-A_MEMORY_SETTINGS',
default_cfgfile)
atf_mem_base = get_config_value('CONFIG_SUBSYSTEM_TF-A_MEM_BASE',
default_cfgfile)
atf_mem_size = get_config_value('CONFIG_SUBSYSTEM_TF-A_MEM_SIZE',
default_cfgfile)
if atf_mem_settings:
machine_override_string += 'ATF_MEM_BASE ?= "%s"\n' % atf_mem_base
machine_override_string += 'ATF_MEM_SIZE ?= "%s"\n' % atf_mem_size
atf_extra_settings = get_config_value('CONFIG_SUBSYSTEM_TF-A_EXTRA_COMPILER_FLAGS',
default_cfgfile)
atf_bl33_offset = get_config_value('CONFIG_SUBSYSTEM_PRELOADED_BL33_BASE',
default_cfgfile)
if atf_extra_settings:
machine_override_string += 'EXTRA_OEMAKE:append:pn-arm-trusted-firmware'\
' = " %s"\n' % atf_extra_settings
#appending the bl33 offset to baseaddr
if atf_bl33_offset:
machine_override_string += 'TFA_BL33_LOAD ?= "%s"\n' % hex(int(atf_bl33_offset, base=16) + int(baseaddr, base=16))
if soc_family == 'versal':
machine_override_string += '\n# Yocto PLM variables\n'
plm_serial_ip_name = get_config_value('CONFIG_SUBSYSTEM_SERIAL_PLM_IP_NAME',
default_cfgfile)
plm_serial_manual = get_config_value('CONFIG_SUBSYSTEM_PLM_SERIAL_MANUAL_SELECT',
default_cfgfile)
if not plm_serial_manual:
machine_override_string += 'YAML_SERIAL_CONSOLE_STDIN:pn-plm-firmware ?= "%s"\n' \
% plm_serial_ip_name
machine_override_string += 'YAML_SERIAL_CONSOLE_STDOUT:pn-plm-firmware ?= "%s"\n' \
% plm_serial_ip_name
if soc_family == 'zynqmp':
machine_override_string += '\n# Yocto PMUFW variables\n'
pmufw_extraflags = get_config_value('CONFIG_SUBSYSTEM_PMUFW_COMPILER_EXTRA_FLAGS',
default_cfgfile)
machine_override_string += 'YAML_COMPILER_FLAGS:append:pn-pmu-firmware = " %s"\n' \
% pmufw_extraflags
pmufw_serial_manual = get_config_value('CONFIG_SUBSYSTEM_PMUFW_SERIAL_MANUAL_SELECT',
default_cfgfile)
pmufw_serial_ipname = get_config_value('CONFIG_SUBSYSTEM_SERIAL_PMUFW_IP_NAME',
default_cfgfile)
if not pmufw_serial_manual:
machine_override_string += 'YAML_SERIAL_CONSOLE_STDIN:pn-pmu-firmware ?= "%s"\n' \
% pmufw_serial_ipname
machine_override_string += 'YAML_SERIAL_CONSOLE_STDOUT:pn-pmu-firmware ?= "%s"\n' \
% pmufw_serial_ipname
if soc_family in ['zynqmp', 'zynq']:
machine_override_string += '\n# Yocto FSBL variables\n'
fsbl_serial_manual = get_config_value('CONFIG_SUBSYSTEM_FSBL_SERIAL_MANUAL_SELECT',
default_cfgfile)
fsbl_serial_ipname = get_config_value(
'CONFIG_SUBSYSTEM_SERIAL_FSBL_IP_NAME', default_cfgfile)
if not fsbl_serial_manual:
machine_override_string += 'YAML_SERIAL_CONSOLE_STDIN:pn-fsbl-firmware ?= "%s"\n' \
% fsbl_serial_ipname
machine_override_string += 'YAML_SERIAL_CONSOLE_STDOUT:pn-fsbl-firmware ?= "%s"\n' \
% fsbl_serial_ipname
if soc_family == 'microblaze':
machine_override_string += '\n# Yocto FS-Boot variables\n'
fsboot_serial_ipname = get_config_value('CONFIG_SUBSYSTEM_SERIAL_FSBOOT_IP_NAME',
default_cfgfile)
fsboot_serial_manual = get_config_value('CONFIG_SUBSYSTEM_FSBOOT_SERIAL_MANUAL_SELECT',
default_cfgfile)
if not fsboot_serial_manual:
machine_override_string += 'YAML_SERIAL_CONSOLE_STDIN:pn-fs-boot ?= "%s"\n' \
% fsboot_serial_ipname
machine_override_string += 'YAML_SERIAL_CONSOLE_STDOUT:pn-fs-boot ?= "%s"\n' \
% fsboot_serial_ipname
fsboot_memory_manual = get_config_value('CONFIG_SUBSYSTEM_MEMORY_MANUAL_SELECT',
default_cfgfile)
fsboot_memory_ipname = get_config_value('CONFIG_SUBSYSTEM_MEMORY_IP_NAME',
default_cfgfile)
fsboot_flash_ipname = get_config_value('CONFIG_SUBSYSTEM_FLASH_IP_NAME',
default_cfgfile)
if not fsboot_memory_manual:
machine_override_string += 'YAML_MAIN_MEMORY_CONFIG:pn-fs-boot ?= "%s"\n' \
% fsboot_memory_ipname
machine_override_string += 'YAML_FLASH_MEMORY_CONFIG:pn-fs-boot ?= "%s"\n' \
% fsboot_flash_ipname
processor_ip_name = get_config_value('CONFIG_SUBSYSTEM_PROCESSOR0_IP_NAME',
default_cfgfile)
machine_override_string += 'XSCTH_PROC:pn-fs-boot ?= "%s"\n' % processor_ip_name
machine_override_string += '\n# Yocto KERNEL Variables\n'
# Additional kernel make command-line arguments
if soc_family == 'microblaze':
kernel_loadaddr = get_config_value('CONFIG_SUBSYSTEM_MEMORY_',
default_cfgfile, 'asterisk', '_BASEADDR=')
else:
kernel_baseaddr = get_config_value('CONFIG_SUBSYSTEM_MEMORY_',
default_cfgfile, 'asterisk', '_KERNEL_BASEADDR=')
if not kernel_baseaddr:
kernel_baseaddr = '0x0'
kernel_offset = '0x200000'
kernel_loadaddr = hex(int(kernel_baseaddr, 16) +
int(kernel_offset, 16))
kernel_loadaddr = '0x%s' % kernel_loadaddr[2:].upper()
if kernel_loadaddr and int(kernel_loadaddr, 16) >> 32:
MSB = '0x%s' % hex(int(kernel_loadaddr, 16) >> 32)[2:].upper()
LSB = '0x%s' % hex(int(kernel_loadaddr, 16) & 0x0ffffffff)[2:].upper()
loadaddr = '%s %s' % (MSB, LSB)
else:
loadaddr = kernel_loadaddr
machine_override_string += 'UBOOT_ENTRYPOINT ?= "%s"\n' % loadaddr
machine_override_string += 'UBOOT_LOADADDRESS ?= "%s"\n' % loadaddr
if arch != 'aarch64':
machine_override_string += 'KERNEL_EXTRA_ARGS += "UIMAGE_LOADADDR=${UBOOT_ENTRYPOINT}"\n'
serialname = get_config_value('CONFIG_SUBSYSTEM_SERIAL_', default_cfgfile,
'choice', '_SELECT=y')
if serialname != 'MANUAL':
serialipname = get_ipproperty(serialname, default_cfgfile)
baudrate = get_config_value('CONFIG_SUBSYSTEM_SERIAL_%s_BAUDRATE_'
% serialname, default_cfgfile, 'choice', '=y')
if serialipname == 'axi_uartlite' or serialipname == 'mdm':
serial_console = '%s;ttyUL0' % baudrate
elif serialipname == 'axi_uart16550':
serial_console = '%s;ttyS0' % baudrate
elif serialipname == 'psv_sbsauart' or serialipname == 'psx_sbsauart':
serial_console = '%s;ttyAMA0' % baudrate
else:
serial_console = '%s;ttyPS0' % baudrate
machine_override_string += '\n# %s Serial Console\n' \
% machine_conf_file
# parse the selected serial IP if no_alias selected to get the serial no.
# serial no. will be suffix to the serial ip name Ex:psu_uart_1 -> serial no. is 1.
no_alias = get_config_value(
'CONFIG_SUBSYSTEM_ENABLE_NO_ALIAS', default_cfgfile)
serial_no = ''
if no_alias == 'y':
if "_" in serialname:
serial_no = serialname.lower().split(serialipname + '_')[1]
serial_console = serial_console[:-1]
serial_console = serial_console + serial_no
else:
tmp = re.findall('[0-9]+', serialname)
serial_no = tmp[0]
serial_console = serial_console[:-1]
serial_console = serial_console + serial_no
machine_override_string += 'SERIAL_CONSOLES ?= "%s"\n' % serial_console
machine_override_string += 'YAML_SERIAL_CONSOLE_BAUDRATE ?= "%s"\n' \
% baudrate
ddr_baseaddr = get_config_value('CONFIG_SUBSYSTEM_MEMORY_', default_cfgfile,
'asterisk', '_BASEADDR=')
if not ddr_baseaddr:
ddr_baseaddr = '0x0'
machine_override_string += '\n# Set DDR Base address for u-boot-xlnx-scr '\
'variables\n'
machine_override_string += 'DDR_BASEADDR ?= "%s"\n' % ddr_baseaddr
skip_append_baseaddr = get_config_value('CONFIG_SUBSYSTEM_UBOOT_APPEND_BASEADDR',
default_cfgfile)
if skip_append_baseaddr:
machine_override_string += 'SKIP_APPEND_BASEADDR ?= "0"\n'
else:
machine_override_string += 'SKIP_APPEND_BASEADDR ?= "1"\n'
# Variables that changes based on hw design or board specific requirement must be
# defined before calling the required inclusion file else pre-expansion value
# defined in respective generic machine conf will be set.
machine_override_string += '\n# Required generic machine inclusion\n'
machine_override_string += 'require conf/machine/%s.conf\n' % \
req_conf_file
# Variable used for Vivado XSA path, name using local file or subversion
# path
if hw_flow == 'xsct':
machine_override_string += '\n# Add system XSA\n'
machine_override_string += 'HDF_EXT = "xsa"\n'
machine_override_string += 'HDF_BASE = "file://"\n'
machine_override_string += 'HDF_PATH = "%s"\n' % args.hw_file
# Set Tune Features for MicroBlaze
if soc_family == 'microblaze':
tune_settings = get_tunefeatures(soc_family, default_cfgfile)
# MicroBlaze Tune features Settings
machine_override_string += '\n# MicroBlaze Tune features Settings\n'
machine_override_string += 'TUNE_FEATURES:tune-microblaze = "%s"\n' \
% tune_settings
if soc_variant == 'ev' and soc_family == 'zynqmp':
machine_override_string += '\n# Yocto IMAGE_FEATURES Variable\n'
machine_override_string += 'MACHINE_HWCODECS = "libomxil-xlnx"\n'
machine_override_string += 'IMAGE_FEATURES += "hwcodecs"\n'
machine_features = ''
is_fpga_manager = get_config_value(
'CONFIG_SUBSYSTEM_FPGA_MANAGER', default_cfgfile)
if is_fpga_manager == 'y':
machine_features = ' fpga-overlay'
if check_ip('vdu', default_cfgfile):
machine_features += ' vdu'
if machine_features:
machine_override_string += '\n# Yocto MACHINE_FEATURES Variable\n'
machine_override_string += 'MACHINE_FEATURES += "%s"\n' % (
machine_features.strip())
machine_override_string += '\n#### No additional settings should be after '\
'the Postamble\n'
machine_override_string += '#### Postamble\n'
machine_override_string += 'PACKAGE_EXTRA_ARCHS:append = "'"${@['', " \
"' %s']['%s' != '${MACHINE}']}"'"\n'\
% (machine_conf_file.replace('-', '_'),
machine_conf_file)
with open(machine_conf_path, 'w') as machine_override_conf_f:
machine_override_conf_f.write(machine_override_string)
machine_override_conf_f.close()
return machine_conf_file