06e426aa16bb8c86b5bf1a6aae3f267f52b28444
3 # Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.<BR>
4 # This program and the accompanying materials are licensed and made available under
5 # the terms and conditions of the BSD License that accompanies this distribution.
6 # The full text of the license may be found at
7 # http://opensource.org/licenses/bsd-license.php.
9 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 from datetime
import date
20 # Generated file copyright header
22 __copyright_txt__
= """## @file
24 # THIS IS AUTO-GENERATED FILE BY BUILD TOOLS AND PLEASE DO NOT MAKE MODIFICATION.
26 # This file lists all VPD informations for a platform collected by build.exe.
28 # Copyright (c) %4d, Intel Corporation. All rights reserved.<BR>
29 # This program and the accompanying materials
30 # are licensed and made available under the terms and conditions of the BSD License
31 # which accompanies this distribution. The full text of the license may be found at
32 # http://opensource.org/licenses/bsd-license.php
34 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
35 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
39 __copyright_bsf__
= """/** @file
41 Boot Setting File for Platform Configuration.
43 Copyright (c) %4d, Intel Corporation. All rights reserved.<BR>
44 This program and the accompanying materials
45 are licensed and made available under the terms and conditions of the BSD License
46 which accompanies this distribution. The full text of the license may be found at
47 http://opensource.org/licenses/bsd-license.php
49 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
50 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
52 This file is automatically generated. Please do NOT modify !!!
58 __copyright_h__
= """/** @file
60 Copyright (c) %4d, Intel Corporation. All rights reserved.<BR>
62 Redistribution and use in source and binary forms, with or without modification,
63 are permitted provided that the following conditions are met:
65 * Redistributions of source code must retain the above copyright notice, this
66 list of conditions and the following disclaimer.
67 * Redistributions in binary form must reproduce the above copyright notice, this
68 list of conditions and the following disclaimer in the documentation and/or
69 other materials provided with the distribution.
70 * Neither the name of Intel Corporation nor the names of its contributors may
71 be used to endorse or promote products derived from this software without
72 specific prior written permission.
74 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
75 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
76 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
77 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
78 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
79 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
80 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
81 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
82 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
83 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
84 THE POSSIBILITY OF SUCH DAMAGE.
86 This file is automatically generated. Please do NOT modify !!!
95 self
._GlobalDataDef
= """
101 self
._BuidinOptionTxt
= """
103 Selection 0x1 , "Enabled"
104 Selection 0x0 , "Disabled"
109 self
._BsfKeyList
= ['FIND','NAME','HELP','TYPE','PAGE','OPTION','ORDER']
110 self
._HdrKeyList
= ['HEADER','STRUCT']
111 self
._BuidinOption
= {'$EN_DIS' : 'EN_DIS'}
114 self
._CfgBlkDict
= {}
115 self
._CfgPageDict
= {}
116 self
._CfgItemList
= []
121 def ParseMacros (self
, MacroDefStr
):
122 # ['-DABC=1', '-D', 'CFG_DEBUG=1', '-D', 'CFG_OUTDIR=Build']
125 for Macro
in MacroDefStr
:
126 if Macro
.startswith('-D'):
134 Match
= re
.match("(\w+)=(.+)", Macro
)
136 self
._MacroDict
[Match
.group(1)] = Match
.group(2)
138 Match
= re
.match("(\w+)", Macro
)
140 self
._MacroDict
[Match
.group(1)] = ''
141 if len(self
._MacroDict
) == 0:
142 self
.Error
= "Invalid MACRO arguments"
149 def ParseDscFile (self
, DscFile
, FvDir
):
150 self
._CfgItemList
= []
151 self
._CfgPageDict
= {}
152 self
._CfgBlkDict
= {}
153 self
._DscFile
= DscFile
165 DscFd
= open(DscFile
, "r")
166 DscLines
= DscFd
.readlines()
171 for DscLine
in DscLines
:
173 DscLine
= DscLine
.strip()
174 Match
= re
.match("^\[(.+)\]", DscLine
)
175 if Match
is not None:
176 if Match
.group(1).lower() == "Defines".lower():
180 elif Match
.group(1).lower() == "PcdsDynamicVpd".lower():
182 ConfigDict
['header'] = 'ON'
183 ConfigDict
['region'] = 'VPD'
184 ConfigDict
['order'] = -1
185 ConfigDict
['page'] = ''
186 ConfigDict
['name'] = ''
187 ConfigDict
['find'] = ''
188 ConfigDict
['struct'] = ''
189 ConfigDict
['subreg'] = []
193 elif Match
.group(1).lower() == "PcdsDynamicVpd.Upd".lower():
195 ConfigDict
['header'] = 'ON'
196 ConfigDict
['region'] = 'UPD'
197 ConfigDict
['order'] = -1
198 ConfigDict
['page'] = ''
199 ConfigDict
['name'] = ''
200 ConfigDict
['find'] = ''
201 ConfigDict
['struct'] = ''
202 ConfigDict
['subreg'] = []
212 if IsDefSect
or IsUpdSect
or IsVpdSect
:
213 if DscLine
== "!else":
214 IfStack
[-1] = not IfStack
[-1]
215 elif DscLine
== "!endif":
217 Level
= ElifStack
.pop()
223 Match
= re
.match("!(ifdef|ifndef)\s+\$\((\w+)\)", DscLine
)
224 if Match
is not None:
225 if Match
.group(2) in self
._MacroDict
:
226 if Match
.group(1) == 'ifdef':
229 if Match
.group(1) == 'ifndef':
232 IfStack
.append(Result
)
234 Match
= re
.match("!(if|elseif)\s+\$\\((\w+)\)\s*==\s*(\w+|\$\(\w+\))", DscLine
)
235 if Match
is not None:
236 if Match
.group(2) in self
._MacroDict
:
237 MacroName
= self
._MacroDict
[Match
.group(2)]
240 Value
= Match
.group(3)
241 if Value
.startswith('$'):
242 if Value
[2:-1] in self
._MacroDict
:
243 Value
= self
._MacroDict
[Value
[2:-1]]
246 if MacroName
== Value
:
248 if Match
.group(1) == "if":
250 IfStack
.append(Result
)
252 IfStack
[-1] = not IfStack
[-1]
253 IfStack
.append(Result
)
254 ElifStack
[-1] = ElifStack
[-1] + 1
256 if len(DscLine
) > 0 and DscLine
[0] == '!':
258 # Current it can only handle build switch.
259 # It does not support INF file in included dsc.
262 if reduce(lambda x
,y
: x
and y
, IfStack
):
269 #DEFINE UPD_TOOL_GUID = 8C3D856A-9BE6-468E-850A-24F7A8D38E09
270 Match
= re
.match("^\s*(?:DEFINE\s+)*(\w+)\s*=\s*([-\w]+)", DscLine
)
272 self
._MacroDict
[Match
.group(1)] = Match
.group(2)
274 Match
= re
.match("^\s*#\s+!(BSF|HDR)\s+(.+)", DscLine
)
276 Remaining
= Match
.group(2)
277 if Match
.group(1) == 'BSF':
278 Match
= re
.match("(?:^|.+\s+)PAGES:{(.+?)}", Remaining
)
280 # !BSF PAGES:{HSW:"Haswell System Agent", LPT:"Lynx Point PCH"}
281 PageList
= Match
.group(1).split(',')
282 for Page
in PageList
:
284 Match
= re
.match("(\w+):\"(.+)\"", Page
)
285 self
._CfgPageDict
[Match
.group(1)] = Match
.group(2)
287 Match
= re
.match("(?:^|.+\s+)BLOCK:{NAME:\"(.+)\"\s*,\s*VER:\"(.+)\"\s*}", Remaining
)
289 self
._CfgBlkDict
['name'] = Match
.group(1)
290 self
._CfgBlkDict
['ver'] = Match
.group(2)
292 for Key
in self
._BsfKeyList
:
293 Match
= re
.match("(?:^|.+\s+)%s:{(.+?)}" % Key
, Remaining
)
295 if Key
in ['HELP', 'OPTION'] and Match
.group(1).startswith('+'):
296 ConfigDict
[Key
.lower()] += Match
.group(1)[1:]
298 ConfigDict
[Key
.lower()] = Match
.group(1)
300 for Key
in self
._HdrKeyList
:
301 Match
= re
.match("(?:^|.+\s+)%s:{(.+?)}" % Key
, Remaining
)
303 ConfigDict
[Key
.lower()] = Match
.group(1)
307 Match
= re
.match("^([_a-zA-Z0-9]+).([_a-zA-Z0-9]+)\s*\|\s*(0x[0-9A-F]{4})\s*\|\s*(\d+|0x[0-9a-fA-F]+)\s*\|\s*(.+)",DscLine
)
309 Match
= re
.match("^([_a-zA-Z0-9]+).([_a-zA-Z0-9]+)\s*\|\s*(0x[0-9A-F]+)(?:\s*\|\s*(.+))?", DscLine
)
311 ConfigDict
['space'] = Match
.group(1)
312 ConfigDict
['cname'] = Match
.group(2)
313 ConfigDict
['offset'] = int (Match
.group(3), 16)
314 if ConfigDict
['order'] == -1:
315 ConfigDict
['order'] = ConfigDict
['offset'] << 8
317 (Major
, Minor
) = ConfigDict
['order'].split('.')
318 ConfigDict
['order'] = (int (Major
, 16) << 8 ) + int (Minor
, 16)
320 Value
= Match
.group(5).strip()
321 if Match
.group(4).startswith("0x"):
322 Length
= int (Match
.group(4), 16)
324 Length
= int (Match
.group(4))
326 Value
= Match
.group(4)
329 Value
= Value
.strip()
331 Match
= re
.match("^.+\s*\|\s*(.+)", Value
)
333 Value
= Match
.group(1)
336 ConfigDict
['length'] = Length
337 Match
= re
.match("\$\((\w+)\)", Value
)
339 if Match
.group(1) in self
._MacroDict
:
340 Value
= self
._MacroDict
[Match
.group(1)]
341 ConfigDict
['value'] = Value
342 if ConfigDict
['name'] == '':
343 # Clear BSF specific items
344 ConfigDict
['help'] = ''
345 ConfigDict
['type'] = ''
346 ConfigDict
['option'] = ''
348 self
._CfgItemList
.append(ConfigDict
.copy())
349 ConfigDict
['name'] = ''
350 ConfigDict
['find'] = ''
351 ConfigDict
['struct'] = ''
352 ConfigDict
['order'] = -1
353 ConfigDict
['subreg'] = []
355 # It could be a virtual item as below
356 # !BSF FIELD:{1:SerialDebugPortAddress0}
357 Match
= re
.match("^\s*#\s+!BSF\s+FIELD:{(.+):(\d+)}", DscLine
)
359 SubCfgDict
= ConfigDict
360 SubCfgDict
['cname'] = Match
.group(1)
361 SubCfgDict
['length'] = int (Match
.group(2))
362 if SubCfgDict
['length'] > 0:
363 LastItem
= self
._CfgItemList
[-1]
364 if len(LastItem
['subreg']) == 0:
367 SubOffset
+= LastItem
['subreg'][-1]['length']
368 SubCfgDict
['offset'] = SubOffset
369 LastItem
['subreg'].append (SubCfgDict
.copy())
370 ConfigDict
['name'] = ''
373 def UpdateSubRegionDefaultValue (self
):
375 for Item
in self
._CfgItemList
:
376 if len(Item
['subreg']) == 0:
379 if Item
['value'][0] == '{':
380 binlist
= Item
['value'][1:-1].split(',')
383 if each
.startswith('0x'):
384 value
= int(each
, 16)
387 bytearray
.append(value
)
389 if Item
['value'].startswith('0x'):
390 value
= int(Item
['value'], 16)
392 value
= int(Item
['value'])
394 while idx
< Item
['length']:
395 bytearray
.append(value
& 0xFF)
398 for SubItem
in Item
['subreg']:
399 if SubItem
['length'] in (1,2,4,8):
400 valuelist
= [b
for b
in bytearray
[SubItem
['offset']:SubItem
['offset']+SubItem
['length']]]
402 valuestr
= "".join('%02X' % b
for b
in valuelist
)
403 SubItem
['value'] = '0x%s' % valuestr
405 valuestr
= ",".join('0x%02X' % b
for b
in bytearray
[SubItem
['offset']:SubItem
['offset']+SubItem
['length']])
406 SubItem
['value'] = '{%s}' % valuestr
409 def UpdateVpdSizeField (self
):
412 if 'VPD_TOOL_GUID' not in self
._MacroDict
:
413 self
.Error
= "VPD_TOOL_GUID definition is missing in DSC file"
416 VpdMapFile
= os
.path
.join(FvDir
, self
._MacroDict
['VPD_TOOL_GUID'] + '.map')
417 if not os
.path
.exists(VpdMapFile
):
418 self
.Error
= "VPD MAP file '%s' does not exist" % VpdMapFile
421 MapFd
= open(VpdMapFile
, "r")
422 MapLines
= MapFd
.readlines()
427 for MapLine
in MapLines
:
428 #gPlatformFspPkgTokenSpaceGuid.PcdVpdRegionSign | DEFAULT | 0x0000 | 8 | 0x534450565F425346
429 #gPlatformFspPkgTokenSpaceGuid.PcdVpdRegionSign | 0x0000 | 8 | 0x534450565F425346
430 #gPlatformFspPkgTokenSpaceGuid.PcdTest | 0x0008 | 5 | {0x01,0x02,0x03,0x04,0x05}
431 Match
= re
.match("([_a-zA-Z0-9]+).([_a-zA-Z0-9]+)(\s\|\sDEFAULT)?\s\|\s(0x[0-9A-F]{4})\s\|\s(\d+|0x[0-9a-fA-F]+)\s\|\s(\{?[x0-9a-fA-F,\s]+\}?)", MapLine
)
433 Space
= Match
.group(1)
434 Name
= Match
.group(2)
435 if (self
._MapVer
== 0) and (Match
.group(3) != None):
437 Offset
= int (Match
.group(4), 16)
438 if Match
.group(5).startswith("0x"):
439 Length
= int (Match
.group(5), 16)
441 Length
= int (Match
.group(5))
442 PcdDict
["len"] = Length
443 PcdDict
["value"] = Match
.group(6)
444 VpdDict
[Space
+'.'+Name
] = dict(PcdDict
)
446 for Item
in self
._CfgItemList
:
447 if Item
['value'] == '':
448 Item
['value'] = VpdDict
[Item
['space']+'.'+Item
['cname']]['value']
449 if Item
['length'] == -1:
450 Item
['length'] = VpdDict
[Item
['space']+'.'+Item
['cname']]['len']
451 if Item
['struct'] != '':
452 Type
= Item
['struct'].strip()
453 if Type
.endswith('*') and (Item
['length'] != 4):
454 self
.Error
= "Struct pointer '%s' has invalid size" % Type
459 def CreateUpdTxtFile (self
, UpdTxtFile
):
461 if 'UPD_TOOL_GUID' not in self
._MacroDict
:
462 self
.Error
= "UPD_TOOL_GUID definition is missing in DSC file"
466 UpdTxtFile
= os
.path
.join(FvDir
, self
._MacroDict
['UPD_TOOL_GUID'] + '.txt')
469 if not os
.path
.exists(UpdTxtFile
):
472 DscTime
= os
.path
.getmtime(self
._DscFile
)
473 TxtTime
= os
.path
.getmtime(UpdTxtFile
)
474 if DscTime
> TxtTime
:
478 # DSC has not been modified yet
479 # So don't have to re-generate other files
480 self
.Error
= 'No DSC file change, skip to create UPD TXT file'
483 TxtFd
= open(UpdTxtFile
, "w")
484 TxtFd
.write("%s\n" % (__copyright_txt__
% date
.today().year
))
488 if self
._MapVer
== 1:
492 for Item
in self
._CfgItemList
:
493 if Item
['region'] != 'UPD':
495 Offset
= Item
['offset']
496 if NextOffset
< Offset
:
498 TxtFd
.write("%s.UnusedUpdSpace%d|%s0x%04X|0x%04X|{0}\n" % (Item
['space'], SpaceIdx
, Default
, NextOffset
, Offset
- NextOffset
))
499 SpaceIdx
= SpaceIdx
+ 1
500 NextOffset
= Offset
+ Item
['length']
501 TxtFd
.write("%s.%s|%s0x%04X|%s|%s\n" % (Item
['space'],Item
['cname'],Default
,Item
['offset'],Item
['length'],Item
['value']))
505 def CreateField (self
, Name
, Length
, Offset
, Struct
):
527 Name
= Name
+ '[%d]' % Length
529 if len(Type
) < PosName
:
530 Space1
= PosName
- len(Type
)
534 if len(Name
) < PosComment
:
535 Space2
= PosComment
- len(Name
)
539 return " %s%s%s;%s/* Offset 0x%04X */\n" % (Type
, ' ' * Space1
, Name
, ' ' * Space2
, Offset
)
542 def CreateHeaderFile (self
, InputHeaderFile
, IsInternal
):
547 HeaderFile
= os
.path
.join(FvDir
, 'VpdHeader.h')
549 HeaderFile
= os
.path
.join(FvDir
, 'fsp_vpd.h')
551 # Check if header needs to be recreated
554 if not os
.path
.exists(HeaderFile
):
557 DscTime
= os
.path
.getmtime(self
._DscFile
)
558 HeadTime
= os
.path
.getmtime(HeaderFile
)
559 if not os
.path
.exists(InputHeaderFile
):
562 InpTime
= os
.path
.getmtime(InputHeaderFile
)
563 if DscTime
> HeadTime
or InpTime
> HeadTime
:
567 self
.Error
= "No DSC or input header file is changed, skip the header file generating"
570 HeaderFd
= open(HeaderFile
, "w")
571 FileBase
= os
.path
.basename(HeaderFile
)
572 FileName
= FileBase
.replace(".", "_").upper()
573 HeaderFd
.write("%s\n" % (__copyright_h__
% date
.today().year
))
574 HeaderFd
.write("#ifndef __%s__\n" % FileName
)
575 HeaderFd
.write("#define __%s__\n\n" % FileName
)
576 HeaderFd
.write("#pragma pack(1)\n\n")
578 if InputHeaderFile
!= '':
579 if not os
.path
.exists(InputHeaderFile
):
580 self
.Error
= "Input header file '%s' does not exist" % InputHeaderFile
583 InFd
= open(InputHeaderFile
, "r")
584 IncLines
= InFd
.readlines()
588 for Line
in IncLines
:
589 Match
= re
.search ("!EXPORT\s+EXTERNAL_BOOTLOADER_STRUCT_(BEGIN|END)\s+", Line
)
591 if Match
.group(1) == "BEGIN":
599 HeaderFd
.write("\n\n")
601 for Region
in ['UPD', 'VPD']:
603 # Write PcdVpdRegionSign and PcdImageRevision
605 if 'VPD_TOOL_GUID' not in self
._MacroDict
:
606 self
.Error
= "VPD_TOOL_GUID definition is missing in DSC file"
610 BinFile
= os
.path
.join(FvDir
, self
._MacroDict
['VPD_TOOL_GUID'] + ".bin")
611 if not os
.path
.exists(BinFile
):
612 self
.Error
= "VPD binary file '%s' does not exist" % BinFile
616 BinFd
= open(BinFile
, "rb")
617 IdStr
= BinFd
.read(0x08)
618 ImageId
= struct
.unpack('<Q', IdStr
)
619 ImageRev
= struct
.unpack('<I', BinFd
.read(0x04))
622 HeaderFd
.write("#define VPD_IMAGE_ID 0x%016X /* '%s' */\n" % (ImageId
[0], IdStr
))
623 HeaderFd
.write("#define VPD_IMAGE_REV 0x%08X \n\n" % ImageRev
[0])
625 HeaderFd
.write("typedef struct _" + Region
[0] + "PD_DATA_REGION {\n")
634 for Item
in self
._CfgItemList
:
635 if Item
['region'] != Region
:
638 NextVisible
= LastVisible
640 if LastVisible
and (Item
['header'] == 'OFF'):
642 ResvOffset
= Item
['offset']
643 elif (not LastVisible
) and Item
['header'] == 'ON':
645 Name
= "Reserved" + Region
[0] + "pdSpace%d" % ResvIdx
646 ResvIdx
= ResvIdx
+ 1
647 HeaderFd
.write(self
.CreateField (Name
, Item
["offset"] - ResvOffset
, ResvOffset
, ''))
649 if Offset
< Item
["offset"]:
650 if IsInternal
or LastVisible
:
651 Name
= "Unused" + Region
[0] + "pdSpace%d" % SpaceIdx
652 LineBuffer
.append(self
.CreateField (Name
, Item
["offset"] - Offset
, Offset
, ''))
653 SpaceIdx
= SpaceIdx
+ 1
654 Offset
= Item
["offset"]
656 if Offset
!= Item
["offset"]:
657 print "Unsorted offset 0x%04X\n" % Item
["offset"]
661 LastVisible
= NextVisible
663 Offset
= Offset
+ Item
["length"]
664 if IsInternal
or LastVisible
:
665 for Each
in LineBuffer
:
666 HeaderFd
.write (Each
)
668 HeaderFd
.write(self
.CreateField (Item
["cname"], Item
["length"], Item
["offset"], Item
['struct']))
670 HeaderFd
.write("} " + Region
[0] + "PD_DATA_REGION;\n\n")
671 HeaderFd
.write("#pragma pack()\n\n")
672 HeaderFd
.write("#endif\n")
677 def WriteBsfStruct (self
, BsfFd
, Item
):
678 if Item
['type'] == "None":
679 Space
= "gPlatformFspPkgTokenSpaceGuid"
681 Space
= Item
['space']
682 Line
= " $%s_%s" % (Space
, Item
['cname'])
683 Match
= re
.match("\s*\{([x0-9a-fA-F,\s]+)\}\s*", Item
['value'])
685 DefaultValue
= Match
.group(1).strip()
687 DefaultValue
= Item
['value'].strip()
688 BsfFd
.write(" %s%s%4d bytes $_DEFAULT_ = %s\n" % (Line
, ' ' * (64 - len(Line
)), Item
['length'], DefaultValue
))
690 if Item
['type'] == "Combo":
691 if not Item
['option'] in self
._BuidinOption
:
692 OptList
= Item
['option'].split(',')
693 for Option
in OptList
:
694 Option
= Option
.strip()
695 (OpVal
, OpStr
) = Option
.split(':')
696 TmpList
.append((OpVal
, OpStr
))
699 def WriteBsfOption (self
, BsfFd
, Item
):
700 PcdName
= Item
['space'] + '_' + Item
['cname']
702 if Item
['type'] == "Combo":
703 if Item
['option'] in self
._BuidinOption
:
704 Options
= self
._BuidinOption
[Item
['option']]
707 BsfFd
.write(' %s $%s, "%s", &%s,\n' % (Item
['type'], PcdName
, Item
['name'], Options
));
709 elif Item
['type'].startswith("EditNum"):
710 Match
= re
.match("EditNum\s*,\s*(HEX|DEC)\s*,\s*\((\d+|0x[0-9A-Fa-f]+)\s*,\s*(\d+|0x[0-9A-Fa-f]+)\)", Item
['type'])
712 BsfFd
.write(' EditNum $%s, "%s", %s,\n' % (PcdName
, Item
['name'], Match
.group(1)));
714 elif Item
['type'].startswith("EditText"):
715 BsfFd
.write(' %s $%s, "%s",\n' % (Item
['type'], PcdName
, Item
['name']));
719 HelpLines
= Item
['help'].split('\\n\\r')
721 for HelpLine
in HelpLines
:
724 BsfFd
.write(' Help "%s"\n' % (HelpLine
));
726 BsfFd
.write(' "%s"\n' % (HelpLine
));
728 BsfFd
.write(' "Valid range: %s ~ %s"\n' % (Match
.group(2), Match
.group(3)));
730 def GenerateBsfFile (self
, BsfFile
):
733 self
.Error
= "BSF output file '%s' is invalid" % BsfFile
738 BsfFd
= open(BsfFile
, "w")
739 BsfFd
.write("%s\n" % (__copyright_bsf__
% date
.today().year
))
740 BsfFd
.write("%s\n" % self
._GlobalDataDef
);
741 BsfFd
.write("StructDef\n")
743 for Item
in self
._CfgItemList
:
744 if Item
['find'] != '':
745 BsfFd
.write('\n Find "%s"\n' % Item
['find'])
746 NextOffset
= Item
['offset'] + Item
['length']
747 if Item
['name'] != '':
748 if NextOffset
!= Item
['offset']:
749 BsfFd
.write(" Skip %d bytes\n" % (Item
['offset'] - NextOffset
))
750 if len(Item
['subreg']) > 0:
751 NextOffset
= Item
['offset']
752 for SubItem
in Item
['subreg']:
753 NextOffset
+= SubItem
['length']
754 if SubItem
['name'] == '':
755 BsfFd
.write(" Skip %d bytes\n" % (SubItem
['length']))
757 Options
= self
.WriteBsfStruct(BsfFd
, SubItem
)
759 OptionDict
[SubItem
['space']+'_'+SubItem
['cname']] = Options
760 if (Item
['offset'] + Item
['length']) < NextOffset
:
761 self
.Error
= "BSF sub region '%s' length does not match" % (Item
['space']+'.'+Item
['cname'])
764 NextOffset
= Item
['offset'] + Item
['length']
765 Options
= self
.WriteBsfStruct(BsfFd
, Item
)
767 OptionDict
[Item
['space']+'_'+Item
['cname']] = Options
768 BsfFd
.write("\nEndStruct\n\n")
770 BsfFd
.write("%s" % self
._BuidinOptionTxt
);
772 for Each
in OptionDict
:
773 BsfFd
.write("List &%s\n" % Each
);
774 for Item
in OptionDict
[Each
]:
775 BsfFd
.write(' Selection %s , "%s"\n' % (Item
[0], Item
[1]));
776 BsfFd
.write("EndList\n\n");
778 BsfFd
.write("BeginInfoBlock\n");
779 BsfFd
.write(' PPVer "%s"\n' % (self
._CfgBlkDict
['ver']));
780 BsfFd
.write(' Description "%s"\n' % (self
._CfgBlkDict
['name']));
781 BsfFd
.write("EndInfoBlock\n\n");
783 for Each
in self
._CfgPageDict
:
784 BsfFd
.write('Page "%s"\n' % self
._CfgPageDict
[Each
]);
786 for Item
in self
._CfgItemList
:
787 if Item
['name'] != '':
788 if Item
['page'] != Each
:
790 if len(Item
['subreg']) > 0:
791 for SubItem
in Item
['subreg']:
792 if SubItem
['name'] != '':
793 BsfItems
.append(SubItem
)
795 BsfItems
.append(Item
)
797 BsfItems
.sort(key
=lambda x
: x
['order'])
799 for Item
in BsfItems
:
800 self
.WriteBsfOption (BsfFd
, Item
)
801 BsfFd
.write("EndPage\n\n");
808 print "GenCfgOpt Version 0.50"
810 print " GenCfgOpt UPDTXT PlatformDscFile BuildFvDir [TxtOutFile] [-D Macros]"
811 print " GenCfgOpt HEADER PlatformDscFile BuildFvDir [InputHFile] [-D Macros]"
812 print " GenCfgOpt GENBSF PlatformDscFile BuildFvDir BsfOutFile [-D Macros]"
816 # Parse the options and args
818 GenCfgOpt
= CGenCfgOpt()
824 DscFile
= sys
.argv
[2]
825 if not os
.path
.exists(DscFile
):
826 print "ERROR: Cannot open DSC file '%s' !" % DscFile
831 if sys
.argv
[4][0] == '-':
834 OutFile
= sys
.argv
[4]
836 if GenCfgOpt
.ParseMacros(sys
.argv
[Start
:]) != 0:
837 print "ERROR: %s !" % GenCfgOpt
.Error
841 if not os
.path
.isdir(FvDir
):
842 print "ERROR: FV folder '%s' is invalid !" % FvDir
845 if GenCfgOpt
.ParseDscFile(DscFile
, FvDir
) != 0:
846 print "ERROR: %s !" % GenCfgOpt
.Error
850 if GenCfgOpt
.UpdateVpdSizeField() != 0:
851 print "ERROR: %s !" % GenCfgOpt
.Error
854 if GenCfgOpt
.UpdateSubRegionDefaultValue() != 0:
855 print "ERROR: %s !" % GenCfgOpt
.Error
858 if sys
.argv
[1] == "UPDTXT":
859 Ret
= GenCfgOpt
.CreateUpdTxtFile(OutFile
)
861 # No change is detected
863 print "INFO: %s !" % (GenCfgOpt
.Error
)
865 print "ERROR: %s !" % (GenCfgOpt
.Error
)
867 elif sys
.argv
[1] == "HEADER":
868 Ret
= GenCfgOpt
.CreateHeaderFile(OutFile
, True)
870 # No change is detected
872 print "INFO: %s !" % (GenCfgOpt
.Error
)
874 print "ERROR: %s !" % (GenCfgOpt
.Error
)
876 if GenCfgOpt
.CreateHeaderFile(OutFile
, False) != 0:
877 print "ERROR: %s !" % GenCfgOpt
.Error
879 elif sys
.argv
[1] == "GENBSF":
880 if GenCfgOpt
.GenerateBsfFile(OutFile
) != 0:
881 print "ERROR: %s !" % GenCfgOpt
.Error
887 print "ERROR: Unknown command '%s' !" % sys
.argv
[1]
894 if __name__
== '__main__':