]>
git.proxmox.com Git - mirror_edk2.git/blob - IntelFsp2Pkg/Tools/FspDscBsf2Yaml.py
3 # This script convert DSC or BSF format file into YAML format
5 # Copyright(c) 2021, Intel Corporation. All rights reserved.<BR>
6 # SPDX-License-Identifier: BSD-2-Clause-Patent
13 from datetime
import date
14 from collections
import OrderedDict
15 from functools
import reduce
17 from GenCfgOpt
import CGenCfgOpt
19 __copyright_tmp__
= """## @file
21 # YAML CFGDATA %s File.
23 # Copyright(c) %4d, Intel Corporation. All rights reserved.<BR>
24 # SPDX-License-Identifier: BSD-2-Clause-Patent
29 __copyright_dsc__
= """## @file
31 # Copyright (c) %04d, Intel Corporation. All rights reserved.<BR>
32 # SPDX-License-Identifier: BSD-2-Clause-Patent
38 # Global definitions in BSF
39 # !BSF BLOCK:{NAME:"FSP UPD Configuration", VER:"0.1"}
46 return reduce(lambda x
, y
: (x
<< 8) | y
, Bytes
[::-1])
49 def Str2Bytes(Value
, Blen
):
50 Result
= bytearray(Value
[1:-1], 'utf-8') # Excluding quotes
51 if len(Result
) < Blen
:
52 Result
.extend(b
'\x00' * (Blen
- len(Result
)))
58 def __init__(self
, bsf_file
):
59 self
.cfg_list
= CFspBsf2Dsc
.parse_bsf(bsf_file
)
61 def get_dsc_lines(self
):
62 return CFspBsf2Dsc
.generate_dsc(self
.cfg_list
)
64 def save_dsc(self
, dsc_file
):
65 return CFspBsf2Dsc
.generate_dsc(self
.cfg_list
, dsc_file
)
68 def parse_bsf(bsf_file
):
70 fd
= open(bsf_file
, 'r')
75 regex
= re
.compile(r
'\s+Find\s+"(.*?)"(.*?)^\s+\$(.*?)\s+', re
.S | re
.MULTILINE
)
76 for match
in regex
.finditer(bsf_txt
):
79 if not name
.endswith('_Revision'):
80 raise Exception("Unexpected CFG item following 'Find' !")
81 find_list
.append((name
, find
))
88 cfg_temp
= {'find': '', 'cname': '', 'length': 0, 'value': '0', 'type': 'Reserved',
89 'embed': '', 'page': '', 'option': '', 'instance': 0}
90 regex
= re
.compile(r
'^\s+(\$(.*?)|Skip)\s+(\d+)\s+bytes(\s+\$_DEFAULT_\s+=\s+(.+?))?$',
93 for match
in regex
.finditer(bsf_txt
):
94 dlen
= int(match
.group(3))
95 if match
.group(1) == 'Skip':
96 key
= 'gPlatformFspPkgTokenSpaceGuid_BsfSkip%d' % idx
97 val
= ', '.join(['%02X' % ord(i
) for i
in '\x00' * dlen
])
105 cfg_item
= dict(cfg_temp
)
106 finds
= [i
for i
in find_list
if i
[0] == key
]
110 cfg_item
['cname'] = 'Dummy'
111 cfg_list
.append(dict(cfg_item
))
112 cfg_list
[-1]['embed'] = '%s:TAG_%03X:END' % (prefix
, ord(prefix
[-1]))
114 cfg_item
['embed'] = '%s:TAG_%03X:START' % (prefix
, ord(prefix
[-1]))
115 cfg_item
['find'] = prefix
116 cfg_item
['cname'] = 'Signature'
117 cfg_item
['length'] = len(finds
[0][1])
118 str2byte
= Str2Bytes("'" + finds
[0][1] + "'", len(finds
[0][1]))
119 cfg_item
['value'] = '0x%X' % Bytes2Val(str2byte
)
120 cfg_list
.append(dict(cfg_item
))
121 cfg_item
= dict(cfg_temp
)
125 cfg_item
['cname'] = key
126 cfg_item
['length'] = dlen
127 cfg_item
['value'] = val
128 cfg_item
['option'] = option
130 if key
not in chk_dict
.keys():
134 cfg_item
['instance'] = chk_dict
[key
]
136 cfg_list
.append(cfg_item
)
140 cfg_item
= dict(cfg_temp
)
141 cfg_item
['cname'] = 'Dummy'
142 cfg_item
['embed'] = '%s:%03X:END' % (prefix
, ord(prefix
[-1]))
143 cfg_list
.append(cfg_item
)
146 selreg
= re
.compile(r
'\s+Selection\s*(.+?)\s*,\s*"(.*?)"$', re
.S | re
.MULTILINE
)
147 regex
= re
.compile(r
'^List\s&(.+?)$(.+?)^EndList$', re
.S | re
.MULTILINE
)
148 for match
in regex
.finditer(bsf_txt
):
150 option_dict
[key
] = []
151 for select
in selreg
.finditer(match
.group(2)):
152 option_dict
[key
].append((int(select
.group(1), 0), select
.group(2)))
155 pagereg
= re
.compile(r
'^Page\s"(.*?)"$(.+?)^EndPage$', re
.S | re
.MULTILINE
)
156 for match
in pagereg
.finditer(bsf_txt
):
157 page
= match
.group(1)
158 for line
in match
.group(2).splitlines():
159 match
= re
.match(r
'\s+(Combo|EditNum)\s\$(.+?),\s"(.*?)",\s(.+?),$', line
)
161 cname
= match
.group(2)
162 if cname
not in chk_dict
.keys():
166 instance
= chk_dict
[cname
]
167 cfg_idxs
= [i
for i
, j
in enumerate(cfg_list
) if j
['cname'] == cname
and j
['instance'] == instance
]
168 if len(cfg_idxs
) != 1:
169 raise Exception("Multiple CFG item '%s' found !" % cname
)
170 cfg_item
= cfg_list
[cfg_idxs
[0]]
171 cfg_item
['page'] = page
172 cfg_item
['type'] = match
.group(1)
173 cfg_item
['prompt'] = match
.group(3)
174 cfg_item
['range'] = None
175 if cfg_item
['type'] == 'Combo':
176 cfg_item
['option'] = option_dict
[match
.group(4)[1:]]
177 elif cfg_item
['type'] == 'EditNum':
178 cfg_item
['option'] = match
.group(4)
179 match
= re
.match(r
'\s+ Help\s"(.*?)"$', line
)
181 cfg_item
['help'] = match
.group(1)
183 match
= re
.match(r
'\s+"Valid\srange:\s(.*)"$', line
)
185 parts
= match
.group(1).split()
186 cfg_item
['option'] = (
187 (int(parts
[0], 0), int(parts
[2], 0), cfg_item
['option']))
192 def generate_dsc(option_list
, dsc_file
=None):
194 header
= '%s' % (__copyright_dsc__
% date
.today().year
)
195 dsc_lines
.extend(header
.splitlines())
198 for cfg_item
in option_list
:
199 if cfg_item
['page'] and (cfg_item
['page'] not in pages
):
200 pages
.append(cfg_item
['page'])
204 dsc_lines
.append(' # !BSF PAGES:{PG%02X::"%s"}' % (page_id
, page
))
209 for option
in option_list
:
211 default
= option
['value']
212 pos
= option
['cname'].find('_')
213 name
= option
['cname'][pos
+ 1:]
216 dsc_lines
.append(' # !BSF FIND:{%s}' % option
['find'])
219 if option
['instance'] > 0:
220 name
= name
+ '_%s' % option
['instance']
223 dsc_lines
.append(' # !HDR EMBED:{%s}' % option
['embed'])
225 if option
['type'] == 'Reserved':
226 dsc_lines
.append(' # !BSF NAME:{Reserved} TYPE:{Reserved}')
227 if option
['option'] == '$SKIP':
228 dsc_lines
.append(' # !BSF OPTION:{$SKIP}')
230 prompt
= option
['prompt']
232 if last_page
!= option
['page']:
233 last_page
= option
['page']
234 dsc_lines
.append(' # !BSF PAGE:{PG%02X}' % (pages
.index(option
['page'])))
236 if option
['type'] == 'Combo':
237 dsc_lines
.append(' # !BSF NAME:{%s} TYPE:{%s}' %
238 (prompt
, option
['type']))
240 for val
, text
in option
['option']:
241 ops
.append('0x%x:%s' % (val
, text
))
242 dsc_lines
.append(' # !BSF OPTION:{%s}' % (', '.join(ops
)))
243 elif option
['type'] == 'EditNum':
244 cfg_len
= option
['length']
245 if ',' in default
and cfg_len
> 8:
246 dsc_lines
.append(' # !BSF NAME:{%s} TYPE:{Table}' % (prompt
))
250 for i
in range(cfg_len
):
251 ops
.append('%X:1:HEX' % i
)
252 dsc_lines
.append(' # !BSF OPTION:{%s}' % (', '.join(ops
)))
255 ' # !BSF NAME:{%s} TYPE:{%s, %s,(0x%X, 0x%X)}' %
256 (prompt
, option
['type'], option
['option'][2],
257 option
['option'][0], option
['option'][1]))
258 dsc_lines
.append(' # !BSF HELP:{%s}' % option
['help'])
261 default
= '{%s}' % default
262 dsc_lines
.append(' gCfgData.%-30s | * | 0x%04X | %s' %
263 (name
, option
['length'], default
))
266 fd
= open(dsc_file
, 'w')
267 fd
.write('\n'.join(dsc_lines
))
273 class CFspDsc2Yaml():
276 self
._Hdr
_key
_list
= ['EMBED', 'STRUCT']
277 self
._Bsf
_key
_list
= ['NAME', 'HELP', 'TYPE', 'PAGE', 'PAGES', 'OPTION',
278 'CONDITION', 'ORDER', 'MARKER', 'SUBT', 'FIELD', 'FIND']
279 self
.gen_cfg_data
= None
280 self
.cfg_reg_exp
= re
.compile(r
"^([_a-zA-Z0-9$\(\)]+)\s*\|\s*(0x[0-9A-F]+|\*)\s*\|"
281 + r
"\s*(\d+|0x[0-9a-fA-F]+)\s*\|\s*(.+)")
282 self
.bsf_reg_exp
= re
.compile(r
"(%s):{(.+?)}(?:$|\s+)" % '|'.join(self
._Bsf
_key
_list
))
283 self
.hdr_reg_exp
= re
.compile(r
"(%s):{(.+?)}" % '|'.join(self
._Hdr
_key
_list
))
289 def load_config_data_from_dsc(self
, file_name
):
291 Load and parse a DSC CFGDATA file.
293 gen_cfg_data
= CGenCfgOpt('FSP')
294 if file_name
.endswith('.dsc'):
295 # if gen_cfg_data.ParseDscFileYaml(file_name, '') != 0:
296 if gen_cfg_data
.ParseDscFile(file_name
, '') != 0:
297 raise Exception('DSC file parsing error !')
298 if gen_cfg_data
.CreateVarDict() != 0:
299 raise Exception('DSC variable creation error !')
301 raise Exception('Unsupported file "%s" !' % file_name
)
302 self
.gen_cfg_data
= gen_cfg_data
304 def print_dsc_line(self
):
306 Debug function to print all DSC lines.
308 for line
in self
.gen_cfg_data
._DscLines
:
311 def format_value(self
, field
, text
, indent
=''):
313 Format a CFGDATA item into YAML format.
315 if(not text
.startswith('!expand')) and (': ' in text
):
316 tgt
= ':' if field
== 'option' else '- '
317 text
= text
.replace(': ', tgt
)
318 lines
= text
.splitlines()
319 if len(lines
) == 1 and field
!= 'help':
322 return '>\n ' + '\n '.join([indent
+ i
.lstrip() for i
in lines
])
324 def reformat_pages(self
, val
):
325 # Convert XXX:YYY into XXX::YYY format for page definition
326 parts
= val
.split(',')
332 nodes
= each
.split(':')
334 each
= '%s::%s' % (nodes
[0], nodes
[1])
336 ret
= ','.join(new_val
)
339 def reformat_struct_value(self
, utype
, val
):
340 # Convert DSC UINT16/32/64 array into new format by
341 # adding prefix 0:0[WDQ] to provide hint to the array format
342 if utype
in ['UINT16', 'UINT32', 'UINT64']:
343 if val
and val
[0] == '{' and val
[-1] == '}':
344 if utype
== 'UINT16':
346 elif utype
== 'UINT32':
350 val
= '{ 0:0%s, %s }' % (unit
, val
[1:-1])
353 def process_config(self
, cfg
):
355 cfg
['page'] = self
.reformat_pages(cfg
['page'])
358 cfg
['value'] = self
.reformat_struct_value(cfg
['struct'], cfg
['value'])
360 def parse_dsc_line(self
, dsc_line
, config_dict
, init_dict
, include
):
362 Parse a line in DSC and update the config dictionary accordingly.
365 match
= re
.match(r
'g(CfgData|\w+FspPkgTokenSpaceGuid)\.(.+)', dsc_line
)
367 match
= self
.cfg_reg_exp
.match(match
.group(2))
370 config_dict
['cname'] = self
.prefix
+ match
.group(1)
371 value
= match
.group(4).strip()
372 length
= match
.group(3).strip()
373 config_dict
['length'] = length
374 config_dict
['value'] = value
375 if match
.group(2) == '*':
376 self
.offset
+= int(length
, 0)
378 org_offset
= int(match
.group(2), 0)
380 self
.base_offset
= self
.offset
381 offset
= org_offset
+ self
.base_offset
382 if self
.offset
!= offset
:
383 if offset
> self
.offset
:
384 init_dict
['padding'] = offset
- self
.offset
385 self
.offset
= offset
+ int(length
, 0)
388 match
= re
.match(r
"^\s*#\s+!([<>])\s+include\s+(.+)", dsc_line
)
389 if match
and len(config_dict
) == 0:
390 # !include should not be inside a config field
391 # if so, do not convert include into YAML
392 init_dict
= dict(config_dict
)
394 config_dict
['cname'] = '$ACTION'
395 if match
.group(1) == '<':
396 config_dict
['include'] = match
.group(2)
398 config_dict
['include'] = ''
401 match
= re
.match(r
"^\s*#\s+(!BSF|!HDR)\s+(.+)", dsc_line
)
405 remaining
= match
.group(2)
406 if match
.group(1) == '!BSF':
407 result
= self
.bsf_reg_exp
.findall(remaining
)
412 key
= each
[0].lower()
417 raise Exception('Incorrect bit field format !')
418 parts
= name
.split(':')
419 config_dict
['length'] = parts
[1]
420 config_dict
['cname'] = '@' + parts
[0]
422 elif key
in ['pages', 'page', 'find']:
423 init_dict
= dict(config_dict
)
425 config_dict
['cname'] = '$ACTION'
427 config_dict
['find'] = val
429 config_dict
['page'] = val
433 parts
= each
[1].split(':')
434 tmp_name
= parts
[0][:-5]
435 if tmp_name
== 'CFGHDR':
437 sval
= '!expand { %s_TMPL : [ ' % tmp_name
+ '%s, %s, ' % (parts
[1], cfg_tag
) \
438 + ', '.join(parts
[2:]) + ' ] }'
440 sval
= '!expand { %s_TMPL : [ ' % tmp_name
+ ', '.join(parts
[1:]) + ' ] }'
442 config_dict
['cname'] = tmp_name
443 config_dict
['expand'] = sval
446 if key
in ['name', 'help', 'option'] and val
.startswith('+'):
447 val
= config_dict
[key
] + '\n' + val
[1:]
448 if val
.strip() == '':
450 config_dict
[key
] = val
453 match
= self
.hdr_reg_exp
.match(remaining
)
457 remaining
= match
.group(2)
459 parts
= remaining
.split(':')
460 names
= parts
[0].split(',')
461 if parts
[-1] == 'END':
466 if parts
[1].startswith('TAG_'):
467 tag_txt
= '%s:%s' % (names
[0], parts
[1])
470 if parts
[2] in ['START', 'END']:
471 if names
[0] == 'PCIE_RP_PIN_CTRL[]':
474 tag_txt
= '%s:%s' % (names
[0], parts
[1])
477 config_dict
['cname'] = prefix
+ tag_txt
481 text
= remaining
.strip()
482 config_dict
[key
.lower()] = text
486 def process_template_lines(self
, lines
):
488 Process a line in DSC template section.
491 bsf_temp_dict
= OrderedDict()
492 temp_file_dict
= OrderedDict()
496 match
= re
.match(r
"^\s*#\s+!([<>])\s+include\s+(.+)", line
)
498 if match
.group(1) == '<':
499 include_file
.append(match
.group(2))
503 match
= re
.match(r
"^\s*#\s+(!BSF)\s+DEFT:{(.+?):(START|END)}", line
)
505 if match
.group(3) == 'START' and not template_name
:
506 template_name
= match
.group(2).strip()
507 temp_file_dict
[template_name
] = list(include_file
)
508 bsf_temp_dict
[template_name
] = []
509 if match
.group(3) == 'END' and (template_name
== match
.group(2).strip()) \
514 bsf_temp_dict
[template_name
].append(line
)
515 return bsf_temp_dict
, temp_file_dict
517 def process_option_lines(self
, lines
):
519 Process a line in DSC config section.
527 ret
= self
.parse_dsc_line(line
, config_dict
, init_dict
, include
)
529 if 'padding' in init_dict
:
530 num
= init_dict
['padding']
533 cfgs
.append(padding_dict
)
534 padding_dict
['cname'] = 'UnusedUpdSpace%d' % self
.unused_idx
535 padding_dict
['length'] = '0x%x' % num
536 padding_dict
['value'] = '{ 0 }'
539 if cfgs
and cfgs
[-1]['cname'][0] != '@' and config_dict
['cname'][0] == '@':
540 # it is a bit field, mark the previous one as virtual
541 cname
= cfgs
[-1]['cname']
542 new_cfg
= dict(cfgs
[-1])
543 new_cfg
['cname'] = '@$STRUCT'
545 cfgs
[-1]['cname'] = cname
548 if cfgs
and cfgs
[-1]['cname'] == 'CFGHDR' and config_dict
['cname'][0] == '<':
549 # swap CfgHeader and the CFG_DATA order
550 if ':' in config_dict
['cname']:
551 # replace the real TAG for CFG_DATA
552 cfgs
[-1]['expand'] = cfgs
[-1]['expand'].replace(
554 config_dict
['cname'].split(':')[1][4:])
555 cfgs
.insert(-1, config_dict
)
557 self
.process_config(config_dict
)
560 cfgs
.insert(-1, config_dict
)
562 cfgs
.append(config_dict
)
563 if config_dict
['cname'][0] == '>':
566 config_dict
= dict(init_dict
)
569 def variable_fixup(self
, each
):
571 Fix up some variable definitions for SBL.
574 val
= self
.gen_cfg_data
._MacroDict
[each
]
577 def template_fixup(self
, tmp_name
, tmp_list
):
579 Fix up some special config templates for SBL
583 def config_fixup(self
, cfg_list
):
585 Fix up some special config items for SBL.
588 # Insert FSPT_UPD/FSPM_UPD/FSPS_UPD tag so as to create C strcture
590 for idx
, cfg
in enumerate(cfg_list
):
591 if cfg
['cname'].startswith('<FSP_UPD_HEADER'):
597 # Handle insert backwards so that the index does not change in the loop
600 for idx
in idxs
[::-1]:
601 # Add current FSP?_UPD start tag
603 cfgfig_dict
['cname'] = '<FSP%s_UPD' % fsp_comp
[idx_comp
]
604 cfg_list
.insert(idx
, cfgfig_dict
)
606 # Add previous FSP?_UPD end tag
608 cfgfig_dict
['cname'] = '>FSP%s_UPD' % fsp_comp
[idx_comp
+ 1]
609 cfg_list
.insert(idx
, cfgfig_dict
)
612 # Add final FSPS_UPD end tag
614 cfgfig_dict
['cname'] = '>FSP%s_UPD' % fsp_comp
[0]
615 cfg_list
.append(cfgfig_dict
)
619 def get_section_range(self
, section_name
):
621 Extract line number range from config file for a given section name.
625 for idx
, line
in enumerate(self
.gen_cfg_data
._DscLines
):
626 if start
< 0 and line
.startswith('[%s]' % section_name
):
628 elif start
>= 0 and line
.startswith('['):
634 end
= len(self
.gen_cfg_data
._DscLines
)
637 def normalize_file_name(self
, file, is_temp
=False):
639 Normalize file name convention so that it is consistent.
641 if file.endswith('.dsc'):
642 file = file[:-4] + '.yaml'
643 dir_name
= os
.path
.dirname(file)
644 base_name
= os
.path
.basename(file)
646 if 'Template_' not in file:
647 base_name
= base_name
.replace('Template', 'Template_')
649 if 'CfgData_' not in file:
650 base_name
= base_name
.replace('CfgData', 'CfgData_')
652 path
= dir_name
+ '/' + base_name
657 def output_variable(self
):
659 Output variable block into a line list.
662 for each
in self
.gen_cfg_data
._MacroDict
:
663 key
, value
= self
.variable_fixup(each
)
664 lines
.append('%-30s : %s' % (key
, value
))
667 def output_template(self
):
669 Output template block into a line list.
673 start
, end
= self
.get_section_range('PcdsDynamicVpd.Tmp')
674 bsf_temp_dict
, temp_file_dict
= self
.process_template_lines(self
.gen_cfg_data
._DscLines
[start
:end
])
675 template_dict
= dict()
679 file_lines
[last_file
] = []
681 for tmp_name
in temp_file_dict
:
682 temp_file_dict
[tmp_name
][-1] = self
.normalize_file_name(temp_file_dict
[tmp_name
][-1], True)
683 if len(temp_file_dict
[tmp_name
]) > 1:
684 temp_file_dict
[tmp_name
][-2] = self
.normalize_file_name(temp_file_dict
[tmp_name
][-2], True)
686 for tmp_name
in bsf_temp_dict
:
687 file = temp_file_dict
[tmp_name
][-1]
688 if last_file
!= file and len(temp_file_dict
[tmp_name
]) > 1:
689 inc_file
= temp_file_dict
[tmp_name
][-2]
690 file_lines
[inc_file
].extend(['', '- !include %s' % temp_file_dict
[tmp_name
][-1], ''])
692 if file not in file_lines
:
693 file_lines
[file] = []
694 lines
= file_lines
[file]
695 text
= bsf_temp_dict
[tmp_name
]
696 tmp_list
= self
.process_option_lines(text
)
697 self
.template_fixup(tmp_name
, tmp_list
)
698 template_dict
[tmp_name
] = tmp_list
699 lines
.append('%s: >' % tmp_name
)
700 lines
.extend(self
.output_dict(tmp_list
, False)['.'])
704 def output_config(self
):
706 Output config block into a line list.
710 start
, end
= self
.get_section_range('PcdsDynamicVpd.Upd')
711 cfgs
= self
.process_option_lines(self
.gen_cfg_data
._DscLines
[start
:end
])
712 self
.config_fixup(cfgs
)
713 file_lines
= self
.output_dict(cfgs
, True)
716 def output_dict(self
, cfgs
, is_configs
):
718 Output one config item into a line list.
724 if 'length' in each
and int(each
['length'], 0) == 0:
727 if 'include' in each
:
729 each
['include'] = self
.normalize_file_name(each
['include'])
730 file_lines
[file].extend(['', '- !include %s' % each
['include'], ''])
731 file = each
['include']
736 if file not in file_lines
:
737 file_lines
[file] = []
739 lines
= file_lines
[file]
746 padding
= ' ' * level
747 if prefix
not in '<>@':
755 parts
= name
.split(':')
758 padding
= padding
[2:] if is_configs
else padding
762 lines
.append('%s- %s' % (padding
, each
['expand']))
764 lines
.append('%s- %-12s :' % (padding
, name
))
767 if field
in ['cname', 'expand', 'include']:
769 value_str
= self
.format_value(field
, each
[field
], padding
+ ' ' * 16)
770 full_line
= ' %s %-12s : %s' % (padding
, field
, value_str
)
771 lines
.extend(full_line
.splitlines())
781 def bsf_to_dsc(bsf_file
, dsc_file
):
782 fsp_dsc
= CFspBsf2Dsc(bsf_file
)
783 dsc_lines
= fsp_dsc
.get_dsc_lines()
784 fd
= open(dsc_file
, 'w')
785 fd
.write('\n'.join(dsc_lines
))
790 def dsc_to_yaml(dsc_file
, yaml_file
):
791 dsc2yaml
= CFspDsc2Yaml()
792 dsc2yaml
.load_config_data_from_dsc(dsc_file
)
795 for cfg
in ['Template', 'Option']:
796 if cfg
== 'Template':
797 file_lines
= dsc2yaml
.output_template()
799 file_lines
= dsc2yaml
.output_config()
800 for file in file_lines
:
801 lines
= file_lines
[file]
805 if('/' in file or '\\' in file):
807 file = os
.path
.basename(file)
808 fo
= open(os
.path
.join(file), 'w')
809 fo
.write(__copyright_tmp__
% (cfg
, date
.today().year
) + '\n\n')
811 fo
.write(line
+ '\n')
814 variables
= dsc2yaml
.output_variable()
815 fo
= open(yaml_file
, 'w')
816 fo
.write(__copyright_tmp__
% ('Default', date
.today().year
))
817 if len(variables
) > 0:
818 fo
.write('\n\nvariable:\n')
819 for line
in variables
:
820 fo
.write(' ' + line
+ '\n')
822 fo
.write('\n\ntemplate:\n')
823 for line
in cfgs
['Template']:
825 fo
.write(' ' + line
+ '\n')
827 fo
.write('\n\nconfigs:\n')
828 for line
in cfgs
['Option']:
830 fo
.write(' ' + line
+ '\n')
835 def get_fsp_name_from_path(bsf_file
):
837 parts
= bsf_file
.split(os
.sep
)
839 if part
.endswith('FspBinPkg'):
843 raise Exception('Could not get FSP name from file path!')
849 "FspDscBsf2Yaml Version 0.10",
851 " FspDscBsf2Yaml BsfFile|DscFile YamlFile"
857 # Parse the options and args
864 bsf_file
= sys
.argv
[1]
865 yaml_file
= sys
.argv
[2]
866 if os
.path
.isdir(yaml_file
):
867 yaml_file
= os
.path
.join(yaml_file
, get_fsp_name_from_path(bsf_file
) + '.yaml')
869 if bsf_file
.endswith('.dsc'):
873 dsc_file
= os
.path
.splitext(yaml_file
)[0] + '.dsc'
874 bsf_to_dsc(bsf_file
, dsc_file
)
876 dsc_to_yaml(dsc_file
, yaml_file
)
878 print("'%s' was created successfully!" % yaml_file
)
883 if __name__
== '__main__':