654cdfc835359d47367f3bd409d37d4c52a0f3bd
3 # Copyright (c) 2014 - 2016, 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 !!!
91 class CLogicalExpression
:
96 def errExit(self
, err
= ''):
97 print "ERROR: Express parsing for:"
98 print " %s" % self
.string
99 print " %s^" % (' ' * self
.index
)
101 print "INFO : %s" % err
104 def getNonNumber (self
, n1
, n2
):
111 def getCurr(self
, lens
= 1):
114 return self
.string
[self
.index
:]
116 if self
.index
+ lens
> len(self
.string
):
117 lens
= len(self
.string
) - self
.index
118 return self
.string
[self
.index
: self
.index
+ lens
]
123 return self
.index
== len(self
.string
)
125 def moveNext(self
, len = 1):
129 while not self
.isLast():
130 if self
.getCurr() in ' \t':
135 def normNumber (self
, val
):
136 return True if val
else False
138 def getNumber(self
, var
):
140 if re
.match('^0x[a-fA-F0-9]+$', var
):
142 elif re
.match('^[+-]?\d+$', var
):
148 def parseValue(self
):
151 while not self
.isLast():
152 char
= self
.getCurr()
153 if re
.match('^[\w.]', char
):
158 val
= self
.getNumber(var
)
165 def parseSingleOp(self
):
167 if re
.match('^NOT\W', self
.getCurr(-1)):
169 op
= self
.parseBrace()
170 val
= self
.getNumber (op
)
172 self
.errExit ("'%s' is not a number" % op
)
173 return "%d" % (not self
.normNumber(int(op
)))
175 return self
.parseValue()
177 def parseBrace(self
):
179 char
= self
.getCurr()
182 value
= self
.parseExpr()
184 if self
.getCurr() != ')':
185 self
.errExit ("Expecting closing brace or operator")
189 value
= self
.parseSingleOp()
192 def parseCompare(self
):
193 value
= self
.parseBrace()
196 char
= self
.getCurr()
197 if char
in ['<', '>']:
199 next
= self
.getCurr()
205 result
= self
.parseBrace()
206 test
= self
.getNonNumber(result
, value
)
208 value
= "%d" % self
.normNumber(eval (value
+ op
+ result
))
210 self
.errExit ("'%s' is not a valid number for comparision" % test
)
211 elif char
in ['=', '!']:
213 if op
in ['==', '!=']:
215 result
= self
.parseBrace()
216 test
= self
.getNonNumber(result
, value
)
218 value
= "%d" % self
.normNumber((eval (value
+ op
+ result
)))
220 value
= "%d" % self
.normNumber(eval ("'" + value
+ "'" + op
+ "'" + result
+ "'"))
228 value
= self
.parseCompare()
231 if re
.match('^AND\W', self
.getCurr(-1)):
233 result
= self
.parseCompare()
234 test
= self
.getNonNumber(result
, value
)
236 value
= "%d" % self
.normNumber(int(value
) & int(result
))
238 self
.errExit ("'%s' is not a valid op number for AND" % test
)
243 def parseOrXor(self
):
244 value
= self
.parseAnd()
249 if re
.match('^XOR\W', self
.getCurr(-1)):
252 elif re
.match('^OR\W', self
.getCurr(-1)):
258 result
= self
.parseAnd()
259 test
= self
.getNonNumber(result
, value
)
261 value
= "%d" % self
.normNumber(eval (value
+ op
+ result
))
263 self
.errExit ("'%s' is not a valid op number for XOR/OR" % test
)
267 return self
.parseOrXor()
270 value
= self
.parseExpr()
272 if not self
.isLast():
273 self
.errExit ("Unexpected character found '%s'" % self
.getCurr())
274 test
= self
.getNumber(value
)
276 self
.errExit ("Result '%s' is not a number" % value
)
279 def evaluateExpress (self
, Expr
):
292 self
.ReleaseMode
= True
294 self
._GlobalDataDef
= """
300 self
._BuidinOptionTxt
= """
302 Selection 0x1 , "Enabled"
303 Selection 0x0 , "Disabled"
308 self
._BsfKeyList
= ['FIND','NAME','HELP','TYPE','PAGE','OPTION','ORDER']
309 self
._HdrKeyList
= ['HEADER','STRUCT', 'EMBED', 'COMMENT']
310 self
._BuidinOption
= {'$EN_DIS' : 'EN_DIS'}
314 self
._CfgBlkDict
= {}
315 self
._CfgPageDict
= {}
316 self
._CfgItemList
= []
321 def ParseBuildMode (self
, OutputStr
):
322 if "RELEASE_" in OutputStr
:
323 self
.ReleaseMode
= True
324 if "DEBUG_" in OutputStr
:
325 self
.ReleaseMode
= False
328 def ParseMacros (self
, MacroDefStr
):
329 # ['-DABC=1', '-D', 'CFG_DEBUG=1', '-D', 'CFG_OUTDIR=Build']
332 for Macro
in MacroDefStr
:
333 if Macro
.startswith('-D'):
341 Match
= re
.match("(\w+)=(.+)", Macro
)
343 self
._MacroDict
[Match
.group(1)] = Match
.group(2)
345 Match
= re
.match("(\w+)", Macro
)
347 self
._MacroDict
[Match
.group(1)] = ''
348 if len(self
._MacroDict
) == 0:
353 print "INFO : Macro dictionary:"
354 for Each
in self
._MacroDict
:
355 print " $(%s) = [ %s ]" % (Each
, self
._MacroDict
[Each
])
358 def EvaulateIfdef (self
, Macro
):
359 Result
= Macro
in self
._MacroDict
361 print "INFO : Eval Ifdef [%s] : %s" % (Macro
, Result
)
364 def ExpandMacros (self
, Input
):
366 Match
= re
.findall("\$\(\w+\)", Input
)
369 Variable
= Each
[2:-1]
370 if Variable
in self
._MacroDict
:
371 Line
= Line
.replace(Each
, self
._MacroDict
[Variable
])
374 print "WARN : %s is not defined" % Each
375 Line
= Line
.replace(Each
, Each
[2:-1])
378 def ExpandPcds (self
, Input
):
380 Match
= re
.findall("(\w+\.\w+)", Input
)
382 for PcdName
in Match
:
383 if PcdName
in self
._PcdsDict
:
384 Line
= Line
.replace(PcdName
, self
._PcdsDict
[PcdName
])
387 print "WARN : %s is not defined" % PcdName
390 def EvaluateExpress (self
, Expr
):
391 ExpExpr
= self
.ExpandPcds(Expr
)
392 ExpExpr
= self
.ExpandMacros(ExpExpr
)
393 LogExpr
= CLogicalExpression()
394 Result
= LogExpr
.evaluateExpress (ExpExpr
)
396 print "INFO : Eval Express [%s] : %s" % (Expr
, Result
)
399 def FormatListValue(self
, ConfigDict
):
400 Struct
= ConfigDict
['struct']
401 if Struct
not in ['UINT8','UINT16','UINT32','UINT64']:
405 binlist
= ConfigDict
['value'][1:-1].split(',')
408 if each
.startswith('0x'):
409 value
= int(each
, 16)
412 dataarray
.append(value
)
414 unit
= int(Struct
[4:]) / 8
415 if int(ConfigDict
['length']) != unit
* len(dataarray
):
416 raise Exception("Array size is not proper for '%s' !" % ConfigDict
['cname'])
419 for each
in dataarray
:
421 for loop
in xrange(unit
):
422 bytearray
.append("0x%02X" % (value
& 0xFF))
424 newvalue
= '{' + ','.join(bytearray
) + '}'
425 ConfigDict
['value'] = newvalue
428 def ParseDscFile (self
, DscFile
, FvDir
):
429 self
._CfgItemList
= []
430 self
._CfgPageDict
= {}
431 self
._CfgBlkDict
= {}
432 self
._DscFile
= DscFile
445 DscFd
= open(DscFile
, "r")
446 DscLines
= DscFd
.readlines()
450 DscLine
= DscLines
.pop(0).strip()
452 Match
= re
.match("^\[(.+)\]", DscLine
)
453 if Match
is not None:
458 if Match
.group(1).lower() == "Defines".lower():
460 if Match
.group(1).lower() == "PcdsFeatureFlag".lower():
462 elif Match
.group(1).lower() == "PcdsDynamicVpd.Upd".lower():
464 ConfigDict
['header'] = 'ON'
465 ConfigDict
['region'] = 'UPD'
466 ConfigDict
['order'] = -1
467 ConfigDict
['page'] = ''
468 ConfigDict
['name'] = ''
469 ConfigDict
['find'] = ''
470 ConfigDict
['struct'] = ''
471 ConfigDict
['embed'] = ''
472 ConfigDict
['comment'] = ''
473 ConfigDict
['subreg'] = []
476 if IsDefSect
or IsPcdSect
or IsUpdSect
or IsVpdSect
:
477 if re
.match("^!else($|\s+#.+)", DscLine
):
479 IfStack
[-1] = not IfStack
[-1]
481 print("ERROR: No paired '!if' found for '!else' for line '%s'" % DscLine
)
483 elif re
.match("^!endif($|\s+#.+)", DscLine
):
486 Level
= ElifStack
.pop()
490 print("ERROR: No paired '!if' found for '!endif' for line '%s'" % DscLine
)
494 Match
= re
.match("!(ifdef|ifndef)\s+(.+)", DscLine
)
496 Result
= self
.EvaulateIfdef (Match
.group(2))
497 if Match
.group(1) == 'ifndef':
499 IfStack
.append(Result
)
502 Match
= re
.match("!(if|elseif)\s+(.+)", DscLine
)
504 Result
= self
.EvaluateExpress(Match
.group(2))
505 if Match
.group(1) == "if":
507 IfStack
.append(Result
)
510 IfStack
[-1] = not IfStack
[-1]
511 IfStack
.append(Result
)
512 ElifStack
[-1] = ElifStack
[-1] + 1
514 print("ERROR: No paired '!if' found for '!elif' for line '%s'" % DscLine
)
518 Handle
= reduce(lambda x
,y
: x
and y
, IfStack
)
522 Match
= re
.match("!include\s+(.+)", DscLine
)
524 IncludeFilePath
= Match
.group(1)
525 IncludeFilePath
= self
.ExpandMacros(IncludeFilePath
)
527 IncludeDsc
= open(IncludeFilePath
, "r")
529 print("ERROR: Cannot open file '%s'" % IncludeFilePath
)
531 NewDscLines
= IncludeDsc
.readlines()
533 DscLines
= NewDscLines
+ DscLines
535 if DscLine
.startswith('!'):
536 print("ERROR: Unrecoginized directive for line '%s'" % DscLine
)
542 #DEFINE UPD_TOOL_GUID = 8C3D856A-9BE6-468E-850A-24F7A8D38E09
543 #DEFINE FSP_T_UPD_TOOL_GUID = 34686CA3-34F9-4901-B82A-BA630F0714C6
544 #DEFINE FSP_M_UPD_TOOL_GUID = 39A250DB-E465-4DD1-A2AC-E2BD3C0E2385
545 #DEFINE FSP_S_UPD_TOOL_GUID = CAE3605B-5B34-4C85-B3D7-27D54273C40F
546 Match
= re
.match("^\s*(?:DEFINE\s+)*(\w+)\s*=\s*([-.\w]+)", DscLine
)
548 self
._MacroDict
[Match
.group(1)] = Match
.group(2)
550 print "INFO : DEFINE %s = [ %s ]" % (Match
.group(1), Match
.group(2))
552 #gSiPkgTokenSpaceGuid.PcdTxtEnable|FALSE
553 #gSiPkgTokenSpaceGuid.PcdOverclockEnable|TRUE
554 Match
= re
.match("^\s*([\w\.]+)\s*\|\s*(\w+)", DscLine
)
556 self
._PcdsDict
[Match
.group(1)] = Match
.group(2)
558 print "INFO : PCD %s = [ %s ]" % (Match
.group(1), Match
.group(2))
560 Match
= re
.match("^\s*#\s+(!BSF|@Bsf|!HDR)\s+(.+)", DscLine
)
562 Remaining
= Match
.group(2)
563 if Match
.group(1) == '!BSF' or Match
.group(1) == '@Bsf':
564 Match
= re
.match("(?:^|.+\s+)PAGES:{(.+?)}", Remaining
)
566 # !BSF PAGES:{HSW:"Haswell System Agent", LPT:"Lynx Point PCH"}
567 PageList
= Match
.group(1).split(',')
568 for Page
in PageList
:
570 Match
= re
.match("(\w+):\"(.+)\"", Page
)
571 self
._CfgPageDict
[Match
.group(1)] = Match
.group(2)
573 Match
= re
.match("(?:^|.+\s+)BLOCK:{NAME:\"(.+)\"\s*,\s*VER:\"(.+)\"\s*}", Remaining
)
575 self
._CfgBlkDict
['name'] = Match
.group(1)
576 self
._CfgBlkDict
['ver'] = Match
.group(2)
578 for Key
in self
._BsfKeyList
:
579 Match
= re
.match("(?:^|.+\s+)%s:{(.+?)}" % Key
, Remaining
)
581 if Key
in ['NAME', 'HELP', 'OPTION'] and Match
.group(1).startswith('+'):
582 ConfigDict
[Key
.lower()] += Match
.group(1)[1:]
584 ConfigDict
[Key
.lower()] = Match
.group(1)
586 for Key
in self
._HdrKeyList
:
587 Match
= re
.match("(?:^|.+\s+)%s:{(.+?)}" % Key
, Remaining
)
589 ConfigDict
[Key
.lower()] = Match
.group(1)
591 Match
= re
.match("^\s*#\s+@Prompt\s+(.+)", DscLine
)
593 ConfigDict
['name'] = Match
.group(1)
595 Match
= re
.match("^\s*#\s*@ValidList\s*(.+)\s*\|\s*(.+)\s*\|\s*(.+)\s*", DscLine
)
597 if Match
.group(2).strip() in self
._BuidinOption
:
598 ConfigDict
['option'] = Match
.group(2).strip()
600 OptionValueList
= Match
.group(2).split(',')
601 OptionStringList
= Match
.group(3).split(',')
603 for Option
in OptionValueList
:
604 Option
= Option
.strip()
605 ConfigDict
['option'] = ConfigDict
['option'] + str(Option
) + ':' + OptionStringList
[Index
].strip()
607 if Index
in range(len(OptionValueList
)):
608 ConfigDict
['option'] += ', '
609 ConfigDict
['type'] = "Combo"
611 Match
= re
.match("^\s*#\s*@ValidRange\s*(.+)\s*\|\s*(.+)\s*-\s*(.+)\s*", DscLine
)
613 if "0x" in Match
.group(2) or "0x" in Match
.group(3):
614 ConfigDict
['type'] = "EditNum, HEX, (%s,%s)" % (Match
.group(2), Match
.group(3))
616 ConfigDict
['type'] = "EditNum, DEC, (%s,%s)" % (Match
.group(2), Match
.group(3))
618 Match
= re
.match("^\s*##\s+(.+)", DscLine
)
620 ConfigDict
['help'] = Match
.group(1)
624 Match
= re
.match("^([_a-zA-Z0-9]+).([_a-zA-Z0-9]+)\s*\|\s*(0x[0-9A-F]+)\s*\|\s*(\d+|0x[0-9a-fA-F]+)\s*\|\s*(.+)",DscLine
)
626 Match
= re
.match("^([_a-zA-Z0-9]+).([_a-zA-Z0-9]+)\s*\|\s*(0x[0-9A-F]+)(?:\s*\|\s*(.+))?", DscLine
)
628 ConfigDict
['space'] = Match
.group(1)
629 ConfigDict
['cname'] = Match
.group(2)
630 ConfigDict
['offset'] = int (Match
.group(3), 16)
631 if ConfigDict
['order'] == -1:
632 ConfigDict
['order'] = ConfigDict
['offset'] << 8
634 (Major
, Minor
) = ConfigDict
['order'].split('.')
635 ConfigDict
['order'] = (int (Major
, 16) << 8 ) + int (Minor
, 16)
637 Value
= Match
.group(5).strip()
638 if Match
.group(4).startswith("0x"):
639 Length
= int (Match
.group(4), 16)
641 Length
= int (Match
.group(4))
643 Value
= Match
.group(4)
646 Value
= Value
.strip()
648 Match
= re
.match("^.+\s*\|\s*(.+)", Value
)
650 Value
= Match
.group(1)
653 ConfigDict
['length'] = Length
654 Match
= re
.match("\$\((\w+)\)", Value
)
656 if Match
.group(1) in self
._MacroDict
:
657 Value
= self
._MacroDict
[Match
.group(1)]
659 ConfigDict
['value'] = Value
660 if (len(Value
) > 0) and (Value
[0] == '{'):
661 Value
= self
.FormatListValue(ConfigDict
)
663 if ConfigDict
['name'] == '':
664 # Clear BSF specific items
665 ConfigDict
['bsfname'] = ''
666 ConfigDict
['help'] = ''
667 ConfigDict
['type'] = ''
668 ConfigDict
['option'] = ''
670 self
._CfgItemList
.append(ConfigDict
.copy())
671 ConfigDict
['name'] = ''
672 ConfigDict
['find'] = ''
673 ConfigDict
['struct'] = ''
674 ConfigDict
['embed'] = ''
675 ConfigDict
['comment'] = ''
676 ConfigDict
['order'] = -1
677 ConfigDict
['subreg'] = []
678 ConfigDict
['option'] = ''
680 # It could be a virtual item as below
681 # !BSF FIELD:{SerialDebugPortAddress0:1}
683 # @Bsf FIELD:{SerialDebugPortAddress0:1b}
684 Match
= re
.match("^\s*#\s+(!BSF|@Bsf)\s+FIELD:{(.+):(\d+)([Bb])?}", DscLine
)
686 SubCfgDict
= ConfigDict
.copy()
687 if (Match
.group(4) == None) or (Match
.group(4) == 'B'):
689 elif Match
.group(4) == 'b':
692 print("ERROR: Invalide BSF FIELD length for line '%s'" % DscLine
)
694 SubCfgDict
['cname'] = Match
.group(2)
695 SubCfgDict
['bitlength'] = int (Match
.group(3)) * UnitBitLen
696 if SubCfgDict
['bitlength'] > 0:
697 LastItem
= self
._CfgItemList
[-1]
698 if len(LastItem
['subreg']) == 0:
701 SubOffset
= LastItem
['subreg'][-1]['bitoffset'] + LastItem
['subreg'][-1]['bitlength']
702 SubCfgDict
['bitoffset'] = SubOffset
703 LastItem
['subreg'].append (SubCfgDict
.copy())
704 ConfigDict
['name'] = ''
707 def GetBsfBitFields (self
, subitem
, bytes
):
708 start
= subitem
['bitoffset']
709 end
= start
+ subitem
['bitlength']
710 bitsvalue
= ''.join('{0:08b}'.format(i
) for i
in bytes
[::-1])
711 bitsvalue
= bitsvalue
[::-1]
712 bitslen
= len(bitsvalue
)
713 if start
> bitslen
or end
> bitslen
:
714 print "Invalid bits offset [%d,%d] for %s" % (start
, end
, subitem
['name'])
716 return hex(int(bitsvalue
[start
:end
][::-1], 2))
718 def UpdateSubRegionDefaultValue (self
):
720 for Item
in self
._CfgItemList
:
721 if len(Item
['subreg']) == 0:
724 if Item
['value'][0] == '{':
725 binlist
= Item
['value'][1:-1].split(',')
728 if each
.startswith('0x'):
729 value
= int(each
, 16)
732 bytearray
.append(value
)
734 if Item
['value'].startswith('0x'):
735 value
= int(Item
['value'], 16)
737 value
= int(Item
['value'])
739 while idx
< Item
['length']:
740 bytearray
.append(value
& 0xFF)
743 for SubItem
in Item
['subreg']:
744 valuestr
= self
.GetBsfBitFields(SubItem
, bytearray
)
745 SubItem
['value'] = valuestr
748 def CreateSplitUpdTxt (self
, UpdTxtFile
):
749 GuidList
= ['FSP_T_UPD_TOOL_GUID','FSP_M_UPD_TOOL_GUID','FSP_S_UPD_TOOL_GUID']
750 SignatureList
= ['0x545F', '0x4D5F','0x535F'] # _T, _M, and _S signature for FSPT, FSPM, FSPS
751 for Index
in range(len(GuidList
)):
754 if GuidList
[Index
] not in self
._MacroDict
:
755 self
.Error
= "%s definition is missing in DSC file" % (GuidList
[Index
])
759 UpdTxtFile
= os
.path
.join(FvDir
, self
._MacroDict
[GuidList
[Index
]] + '.txt')
762 if not os
.path
.exists(UpdTxtFile
):
765 DscTime
= os
.path
.getmtime(self
._DscFile
)
766 TxtTime
= os
.path
.getmtime(UpdTxtFile
)
767 if DscTime
> TxtTime
:
771 # DSC has not been modified yet
772 # So don't have to re-generate other files
773 self
.Error
= 'No DSC file change, skip to create UPD TXT file'
776 TxtFd
= open(UpdTxtFile
, "w")
777 TxtFd
.write("%s\n" % (__copyright_txt__
% date
.today().year
))
785 for Item
in self
._CfgItemList
:
786 if Item
['cname'] == 'Signature' and str(Item
['value'])[0:6] == SignatureList
[Index
]:
787 StartAddr
= Item
['offset']
788 NextOffset
= StartAddr
790 if Item
['cname'] == 'UpdTerminator' and InRange
== True:
791 EndAddr
= Item
['offset']
794 for Item
in self
._CfgItemList
:
795 if Item
['cname'] == 'Signature' and str(Item
['value'])[0:6] == SignatureList
[Index
]:
799 if Item
['cname'] == 'UpdTerminator':
801 if Item
['region'] != 'UPD':
803 Offset
= Item
['offset']
804 if StartAddr
> Offset
or EndAddr
< Offset
:
806 if NextOffset
< Offset
:
808 TxtFd
.write("%s.UnusedUpdSpace%d|%s0x%04X|0x%04X|{0}\n" % (Item
['space'], SpaceIdx
, Default
, NextOffset
- StartAddr
, Offset
- NextOffset
))
809 SpaceIdx
= SpaceIdx
+ 1
810 NextOffset
= Offset
+ Item
['length']
811 if Item
['cname'] == 'PcdSerialIoUartDebugEnable':
812 if self
.ReleaseMode
== False:
814 TxtFd
.write("%s.%s|%s0x%04X|%s|%s\n" % (Item
['space'],Item
['cname'],Default
,Item
['offset'] - StartAddr
,Item
['length'],Item
['value']))
818 def ProcessMultilines (self
, String
, MaxCharLength
):
820 StringLength
= len(String
)
821 CurrentStringStart
= 0
824 if len(String
) <= MaxCharLength
:
825 while (StringOffset
< StringLength
):
826 if StringOffset
>= 1:
827 if String
[StringOffset
- 1] == '\\' and String
[StringOffset
] == 'n':
828 BreakLineDict
.append (StringOffset
+ 1)
830 if BreakLineDict
!= []:
831 for Each
in BreakLineDict
:
832 Multilines
+= " %s\n" % String
[CurrentStringStart
:Each
].lstrip()
833 CurrentStringStart
= Each
834 if StringLength
- CurrentStringStart
> 0:
835 Multilines
+= " %s\n" % String
[CurrentStringStart
:].lstrip()
837 Multilines
= " %s\n" % String
841 FoundSpaceChar
= False
842 while (StringOffset
< StringLength
):
843 if StringOffset
>= 1:
844 if NewLineCount
>= MaxCharLength
- 1:
845 if String
[StringOffset
] == ' ' and StringLength
- StringOffset
> 10:
846 BreakLineDict
.append (NewLineStart
+ NewLineCount
)
847 NewLineStart
= NewLineStart
+ NewLineCount
849 FoundSpaceChar
= True
850 elif StringOffset
== StringLength
- 1 and FoundSpaceChar
== False:
851 BreakLineDict
.append (0)
852 if String
[StringOffset
- 1] == '\\' and String
[StringOffset
] == 'n':
853 BreakLineDict
.append (StringOffset
+ 1)
854 NewLineStart
= StringOffset
+ 1
858 if BreakLineDict
!= []:
859 BreakLineDict
.sort ()
860 for Each
in BreakLineDict
:
862 Multilines
+= " %s\n" % String
[CurrentStringStart
:Each
].lstrip()
863 CurrentStringStart
= Each
864 if StringLength
- CurrentStringStart
> 0:
865 Multilines
+= " %s\n" % String
[CurrentStringStart
:].lstrip()
868 def CreateField (self
, Item
, Name
, Length
, Offset
, Struct
, BsfName
, Help
, Option
):
876 if Length
in [1,2,4,8]:
877 Type
= "UINT%d" % (Length
* 8)
878 if Name
.startswith("UnusedUpdSpace") and Length
!= 1:
885 if Item
and Item
['value'].startswith('{'):
891 if Struct
in ['UINT8','UINT16','UINT32','UINT64']:
893 Unit
= int(Type
[4:]) / 8
894 Length
= Length
/ Unit
899 Name
= Name
+ '[%d]' % Length
901 if len(Type
) < PosName
:
902 Space1
= PosName
- len(Type
)
907 NameLine
=" - %s\n" % BsfName
912 HelpLine
= self
.ProcessMultilines (Help
, 80)
915 OptionLine
= self
.ProcessMultilines (Option
, 80)
920 OffsetStr
= '0x%04X' % Offset
922 return "\n/** Offset %s%s%s%s**/\n %s%s%s;\n" % (OffsetStr
, NameLine
, HelpLine
, OptionLine
, Type
, ' ' * Space1
, Name
,)
924 def PostProcessBody (self
, TextBody
):
930 IsUpdHdrDefined
= False
932 for Line
in TextBody
:
933 SplitToLines
= Line
.splitlines()
934 MatchComment
= re
.match("^/\*\sCOMMENT:(\w+):([\w|\W|\s]+)\s\*/\s([\s\S]*)", SplitToLines
[0])
936 if MatchComment
.group(1) == 'FSP_UPD_HEADER':
940 if IsUpdHdrDefined
!= True or IsUpdHeader
!= True:
941 CommentLine
= " " + MatchComment
.group(2) + "\n"
942 NewTextBody
.append("/**" + CommentLine
+ "**/\n")
943 Line
= Line
[(len(SplitToLines
[0]) + 1):]
945 Match
= re
.match("^/\*\sEMBED_STRUCT:(\w+):(\w+):(START|END)\s\*/\s([\s\S]*)", Line
)
947 Line
= Match
.group(4)
948 if Match
.group(1) == 'FSP_UPD_HEADER':
953 if Match
and Match
.group(3) == 'START':
954 if IsUpdHdrDefined
!= True or IsUpdHeader
!= True:
955 NewTextBody
.append ('typedef struct {\n')
956 StructName
= Match
.group(1)
957 VariableName
= Match
.group(2)
958 MatchOffset
= re
.search('/\*\*\sOffset\s0x([a-fA-F0-9]+)', Line
)
960 Offset
= int(MatchOffset
.group(1), 16)
965 OldTextBody
.append (self
.CreateField (None, VariableName
, 0, Offset
, StructName
, '', '', ''))
967 if IsUpdHdrDefined
!= True or IsUpdHeader
!= True:
968 NewTextBody
.append (Line
)
970 OldTextBody
.append (Line
)
972 if Match
and Match
.group(3) == 'END':
973 if (StructName
!= Match
.group(1)) or (VariableName
!= Match
.group(2)):
974 print "Unmatched struct name '%s' and '%s' !" % (StructName
, Match
.group(1))
976 if IsUpdHdrDefined
!= True or IsUpdHeader
!= True:
977 NewTextBody
.append ('} %s;\n\n' % StructName
)
978 IsUpdHdrDefined
= True
980 NewTextBody
.extend(OldTextBody
)
983 def CreateHeaderFile (self
, InputHeaderFile
):
986 HeaderFileName
= 'FspUpd.h'
987 HeaderFile
= os
.path
.join(FvDir
, HeaderFileName
)
989 # Check if header needs to be recreated
993 for Item
in self
._CfgItemList
:
994 if str(Item
['cname']) == 'Signature' and Item
['length'] == 8:
995 Value
= int(Item
['value'], 16)
998 Chars
.append(chr(Value
& 0xFF))
1000 SignatureStr
= ''.join(Chars
)
1001 # Signature will be _T / _M / _S for FSPT / FSPM / FSPS accordingly
1002 if '_T' in SignatureStr
[6:6+2]:
1003 TxtBody
.append("#define FSPT_UPD_SIGNATURE %s /* '%s' */\n\n" % (Item
['value'], SignatureStr
))
1004 elif '_M' in SignatureStr
[6:6+2]:
1005 TxtBody
.append("#define FSPM_UPD_SIGNATURE %s /* '%s' */\n\n" % (Item
['value'], SignatureStr
))
1006 elif '_S' in SignatureStr
[6:6+2]:
1007 TxtBody
.append("#define FSPS_UPD_SIGNATURE %s /* '%s' */\n\n" % (Item
['value'], SignatureStr
))
1008 TxtBody
.append("\n")
1010 for Region
in ['UPD']:
1012 UpdSignature
= ['0x545F', '0x4D5F', '0x535F'] #['_T', '_M', '_S'] signature for FSPT, FSPM, FSPS
1013 UpdStructure
= ['FSPT_UPD', 'FSPM_UPD', 'FSPS_UPD']
1014 for Item
in self
._CfgItemList
:
1015 if Item
["cname"] == 'Signature' and Item
["value"][0:6] in UpdSignature
:
1016 UpdOffsetTable
.append (Item
["offset"])
1018 for UpdIdx
in range(len(UpdOffsetTable
)):
1020 for Item
in self
._CfgItemList
:
1021 if Item
["comment"] != '' and Item
["offset"] >= UpdOffsetTable
[UpdIdx
]:
1022 MatchComment
= re
.match("^(U|V)PD_DATA_REGION:([\w|\W|\s]+)", Item
["comment"])
1023 if MatchComment
and MatchComment
.group(1) == Region
[0]:
1024 CommentLine
= " " + MatchComment
.group(2) + "\n"
1025 TxtBody
.append("/**" + CommentLine
+ "**/\n")
1026 elif Item
["offset"] >= UpdOffsetTable
[UpdIdx
] and Item
["comment"] == '':
1027 Match
= re
.match("^FSP([\w|\W|\s])_UPD", UpdStructure
[UpdIdx
])
1029 TxtBody
.append("/** Fsp " + Match
.group(1) + " UPD Configuration\n**/\n")
1030 TxtBody
.append("typedef struct {\n")
1040 for Item
in self
._CfgItemList
:
1041 if Item
['cname'] == 'Signature' and str(Item
['value'])[0:6] == UpdSignature
[UpdIdx
] or Region
[0] == 'V':
1045 if Item
['cname'] == 'UpdTerminator':
1048 if Item
['region'] != Region
:
1051 if Item
["offset"] < UpdOffsetTable
[UpdIdx
]:
1054 NextVisible
= LastVisible
1056 if LastVisible
and (Item
['header'] == 'OFF'):
1058 ResvOffset
= Item
['offset']
1059 elif (not LastVisible
) and Item
['header'] == 'ON':
1061 Name
= "Reserved" + Region
[0] + "pdSpace%d" % ResvIdx
1062 ResvIdx
= ResvIdx
+ 1
1063 TxtBody
.append(self
.CreateField (Item
, Name
, Item
["offset"] - ResvOffset
, ResvOffset
, '', '', '', ''))
1065 if Offset
< Item
["offset"]:
1067 Name
= "Unused" + Region
[0] + "pdSpace%d" % SpaceIdx
1068 LineBuffer
.append(self
.CreateField (Item
, Name
, Item
["offset"] - Offset
, Offset
, '', '', '', ''))
1069 SpaceIdx
= SpaceIdx
+ 1
1070 Offset
= Item
["offset"]
1072 LastVisible
= NextVisible
1074 Offset
= Offset
+ Item
["length"]
1076 for Each
in LineBuffer
:
1077 TxtBody
.append (Each
)
1079 Comment
= Item
["comment"]
1080 Embed
= Item
["embed"].upper()
1081 if Embed
.endswith(':START') or Embed
.endswith(':END'):
1082 if not Comment
== '' and Embed
.endswith(':START'):
1083 Marker
= '/* COMMENT:%s */ \n' % Item
["comment"]
1084 Marker
= Marker
+ '/* EMBED_STRUCT:%s */ ' % Item
["embed"]
1086 Marker
= '/* EMBED_STRUCT:%s */ ' % Item
["embed"]
1091 self
.Error
= "Invalid embedded structure format '%s'!\n" % Item
["embed"]
1093 Line
= Marker
+ self
.CreateField (Item
, Item
["cname"], Item
["length"], Item
["offset"], Item
['struct'], Item
['name'], Item
['help'], Item
['option'])
1094 TxtBody
.append(Line
)
1095 if Item
['cname'] == 'UpdTerminator':
1097 TxtBody
.append("} " + UpdStructure
[UpdIdx
] + ";\n\n")
1099 # Handle the embedded data structure
1100 TxtBody
= self
.PostProcessBody (TxtBody
)
1102 HeaderTFileName
= 'FsptUpd.h'
1103 HeaderMFileName
= 'FspmUpd.h'
1104 HeaderSFileName
= 'FspsUpd.h'
1106 UpdRegionCheck
= ['FSPT', 'FSPM', 'FSPS'] # FSPX_UPD_REGION
1107 UpdConfigCheck
= ['FSP_T', 'FSP_M', 'FSP_S'] # FSP_X_CONFIG, FSP_X_TEST_CONFIG, FSP_X_RESTRICTED_CONFIG
1108 UpdSignatureCheck
= ['FSPT_UPD_SIGNATURE', 'FSPM_UPD_SIGNATURE', 'FSPS_UPD_SIGNATURE']
1109 ExcludedSpecificUpd
= 'FSPM_ARCH_UPD'
1111 if InputHeaderFile
!= '':
1112 if not os
.path
.exists(InputHeaderFile
):
1113 self
.Error
= "Input header file '%s' does not exist" % InputHeaderFile
1116 InFd
= open(InputHeaderFile
, "r")
1117 IncLines
= InFd
.readlines()
1120 for item
in range(len(UpdRegionCheck
)):
1121 if UpdRegionCheck
[item
] == 'FSPT':
1122 HeaderFd
= open(os
.path
.join(FvDir
, HeaderTFileName
), "w")
1123 FileBase
= os
.path
.basename(os
.path
.join(FvDir
, HeaderTFileName
))
1124 elif UpdRegionCheck
[item
] == 'FSPM':
1125 HeaderFd
= open(os
.path
.join(FvDir
, HeaderMFileName
), "w")
1126 FileBase
= os
.path
.basename(os
.path
.join(FvDir
, HeaderMFileName
))
1127 elif UpdRegionCheck
[item
] == 'FSPS':
1128 HeaderFd
= open(os
.path
.join(FvDir
, HeaderSFileName
), "w")
1129 FileBase
= os
.path
.basename(os
.path
.join(FvDir
, HeaderSFileName
))
1130 FileName
= FileBase
.replace(".", "_").upper()
1131 HeaderFd
.write("%s\n" % (__copyright_h__
% date
.today().year
))
1132 HeaderFd
.write("#ifndef __%s__\n" % FileName
)
1133 HeaderFd
.write("#define __%s__\n\n" % FileName
)
1134 HeaderFd
.write("#include <%s>\n\n" % HeaderFileName
)
1135 HeaderFd
.write("#pragma pack(1)\n\n")
1138 for Line
in IncLines
:
1139 Match
= re
.search ("!EXPORT\s+([A-Z]+)\s+EXTERNAL_BOOTLOADER_STRUCT_(BEGIN|END)\s+", Line
)
1141 if Match
.group(2) == "BEGIN" and Match
.group(1) == UpdRegionCheck
[item
]:
1148 HeaderFd
.write(Line
)
1149 HeaderFd
.write("\n")
1155 StructStartWithComment
= []
1157 for Line
in TxtBody
:
1159 Match
= re
.match("(typedef struct {)", Line
)
1161 StartIndex
= Index
- 1
1162 Match
= re
.match("}\s([_A-Z0-9]+);", Line
)
1163 if Match
and (UpdRegionCheck
[item
] in Match
.group(1) or UpdConfigCheck
[item
] in Match
.group(1)) and (ExcludedSpecificUpd
not in Match
.group(1)):
1165 StructStart
.append(StartIndex
)
1166 StructEnd
.append(EndIndex
)
1168 for Line
in TxtBody
:
1170 for Item
in range(len(StructStart
)):
1171 if Index
== StructStart
[Item
]:
1172 Match
= re
.match("^(/\*\*\s*)", Line
)
1174 StructStartWithComment
.append(StructStart
[Item
])
1176 StructStartWithComment
.append(StructStart
[Item
] + 1)
1178 for Line
in TxtBody
:
1180 for Item
in range(len(StructStart
)):
1181 if Index
>= StructStartWithComment
[Item
] and Index
<= StructEnd
[Item
]:
1182 HeaderFd
.write (Line
)
1183 HeaderFd
.write("#pragma pack()\n\n")
1184 HeaderFd
.write("#endif\n")
1187 HeaderFd
= open(HeaderFile
, "w")
1188 FileBase
= os
.path
.basename(HeaderFile
)
1189 FileName
= FileBase
.replace(".", "_").upper()
1190 HeaderFd
.write("%s\n" % (__copyright_h__
% date
.today().year
))
1191 HeaderFd
.write("#ifndef __%s__\n" % FileName
)
1192 HeaderFd
.write("#define __%s__\n\n" % FileName
)
1193 HeaderFd
.write("#include <FspEas.h>\n\n")
1194 HeaderFd
.write("#pragma pack(1)\n\n")
1196 for item
in range(len(UpdRegionCheck
)):
1201 StructStartWithComment
= []
1203 for Line
in TxtBody
:
1205 Match
= re
.match("(typedef struct {)", Line
)
1207 StartIndex
= Index
- 1
1208 Match
= re
.match("#define\s([_A-Z0-9]+)\s*", Line
)
1209 if Match
and (UpdSignatureCheck
[item
] in Match
.group(1) or UpdSignatureCheck
[item
] in Match
.group(1)):
1210 StructStart
.append(Index
- 1)
1211 StructEnd
.append(Index
)
1213 for Line
in TxtBody
:
1215 for Item
in range(len(StructStart
)):
1216 if Index
== StructStart
[Item
]:
1217 Match
= re
.match("^(/\*\*\s*)", Line
)
1219 StructStartWithComment
.append(StructStart
[Item
])
1221 StructStartWithComment
.append(StructStart
[Item
] + 1)
1223 for Line
in TxtBody
:
1225 for Item
in range(len(StructStart
)):
1226 if Index
>= StructStartWithComment
[Item
] and Index
<= StructEnd
[Item
]:
1227 HeaderFd
.write (Line
)
1228 HeaderFd
.write("#pragma pack()\n\n")
1229 HeaderFd
.write("#endif\n")
1234 def WriteBsfStruct (self
, BsfFd
, Item
):
1235 if Item
['type'] == "None":
1236 Space
= "gPlatformFspPkgTokenSpaceGuid"
1238 Space
= Item
['space']
1239 Line
= " $%s_%s" % (Space
, Item
['cname'])
1240 Match
= re
.match("\s*\{([x0-9a-fA-F,\s]+)\}\s*", Item
['value'])
1242 DefaultValue
= Match
.group(1).strip()
1244 DefaultValue
= Item
['value'].strip()
1245 if 'bitlength' in Item
:
1246 BsfFd
.write(" %s%s%4d bits $_DEFAULT_ = %s\n" % (Line
, ' ' * (64 - len(Line
)), Item
['bitlength'], DefaultValue
))
1248 BsfFd
.write(" %s%s%4d bytes $_DEFAULT_ = %s\n" % (Line
, ' ' * (64 - len(Line
)), Item
['length'], DefaultValue
))
1250 if Item
['type'] == "Combo":
1251 if not Item
['option'] in self
._BuidinOption
:
1252 OptList
= Item
['option'].split(',')
1253 for Option
in OptList
:
1254 Option
= Option
.strip()
1255 (OpVal
, OpStr
) = Option
.split(':')
1256 TmpList
.append((OpVal
, OpStr
))
1259 def WriteBsfOption (self
, BsfFd
, Item
):
1260 PcdName
= Item
['space'] + '_' + Item
['cname']
1262 if Item
['type'] == "Combo":
1263 if Item
['option'] in self
._BuidinOption
:
1264 Options
= self
._BuidinOption
[Item
['option']]
1267 BsfFd
.write(' %s $%s, "%s", &%s,\n' % (Item
['type'], PcdName
, Item
['name'], Options
))
1269 elif Item
['type'].startswith("EditNum"):
1270 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'])
1272 BsfFd
.write(' EditNum $%s, "%s", %s,\n' % (PcdName
, Item
['name'], Match
.group(1)))
1274 elif Item
['type'].startswith("EditText"):
1275 BsfFd
.write(' %s $%s, "%s",\n' % (Item
['type'], PcdName
, Item
['name']))
1277 elif Item
['type'] == "Table":
1278 Columns
= Item
['option'].split(',')
1279 if len(Columns
) != 0:
1280 BsfFd
.write(' %s $%s "%s",' % (Item
['type'], PcdName
, Item
['name']))
1282 Fmt
= Col
.split(':')
1284 raise Exception("Column format '%s' is invalid !" % Fmt
)
1286 Dtype
= int(Fmt
[1].strip())
1288 raise Exception("Column size '%s' is invalid !" % Fmt
[1])
1289 BsfFd
.write('\n Column "%s", %d bytes, %s' % (Fmt
[0].strip(), Dtype
, Fmt
[2].strip()))
1294 HelpLines
= Item
['help'].split('\\n\\r')
1296 for HelpLine
in HelpLines
:
1299 BsfFd
.write(' Help "%s"\n' % (HelpLine
))
1301 BsfFd
.write(' "%s"\n' % (HelpLine
))
1303 BsfFd
.write(' "Valid range: %s ~ %s"\n' % (Match
.group(2), Match
.group(3)))
1305 def GenerateBsfFile (self
, BsfFile
):
1308 self
.Error
= "BSF output file '%s' is invalid" % BsfFile
1313 BsfFd
= open(BsfFile
, "w")
1314 BsfFd
.write("%s\n" % (__copyright_bsf__
% date
.today().year
))
1315 BsfFd
.write("%s\n" % self
._GlobalDataDef
)
1316 BsfFd
.write("StructDef\n")
1318 for Item
in self
._CfgItemList
:
1319 if Item
['find'] != '':
1320 BsfFd
.write('\n Find "%s"\n' % Item
['find'])
1321 NextOffset
= Item
['offset'] + Item
['length']
1322 if Item
['name'] != '':
1323 if NextOffset
!= Item
['offset']:
1324 BsfFd
.write(" Skip %d bytes\n" % (Item
['offset'] - NextOffset
))
1325 if len(Item
['subreg']) > 0:
1326 NextOffset
= Item
['offset']
1327 BitsOffset
= NextOffset
* 8
1328 for SubItem
in Item
['subreg']:
1329 BitsOffset
+= SubItem
['bitlength']
1330 if SubItem
['name'] == '':
1331 if 'bitlength' in SubItem
:
1332 BsfFd
.write(" Skip %d bits\n" % (SubItem
['bitlength']))
1334 BsfFd
.write(" Skip %d bytes\n" % (SubItem
['length']))
1336 Options
= self
.WriteBsfStruct(BsfFd
, SubItem
)
1337 if len(Options
) > 0:
1338 OptionDict
[SubItem
['space']+'_'+SubItem
['cname']] = Options
1340 NextBitsOffset
= (Item
['offset'] + Item
['length']) * 8
1341 if NextBitsOffset
> BitsOffset
:
1342 BitsGap
= NextBitsOffset
- BitsOffset
1343 BitsRemain
= BitsGap
% 8
1345 BsfFd
.write(" Skip %d bits\n" % BitsRemain
)
1346 BitsGap
-= BitsRemain
1347 BytesRemain
= BitsGap
/ 8
1349 BsfFd
.write(" Skip %d bytes\n" % BytesRemain
)
1350 NextOffset
= Item
['offset'] + Item
['length']
1352 NextOffset
= Item
['offset'] + Item
['length']
1353 Options
= self
.WriteBsfStruct(BsfFd
, Item
)
1354 if len(Options
) > 0:
1355 OptionDict
[Item
['space']+'_'+Item
['cname']] = Options
1356 BsfFd
.write("\nEndStruct\n\n")
1358 BsfFd
.write("%s" % self
._BuidinOptionTxt
)
1360 for Each
in OptionDict
:
1361 BsfFd
.write("List &%s\n" % Each
)
1362 for Item
in OptionDict
[Each
]:
1363 BsfFd
.write(' Selection %s , "%s"\n' % (Item
[0], Item
[1]))
1364 BsfFd
.write("EndList\n\n")
1366 BsfFd
.write("BeginInfoBlock\n")
1367 BsfFd
.write(' PPVer "%s"\n' % (self
._CfgBlkDict
['ver']))
1368 BsfFd
.write(' Description "%s"\n' % (self
._CfgBlkDict
['name']))
1369 BsfFd
.write("EndInfoBlock\n\n")
1371 for Each
in self
._CfgPageDict
:
1372 BsfFd
.write('Page "%s"\n' % self
._CfgPageDict
[Each
])
1374 for Item
in self
._CfgItemList
:
1375 if Item
['name'] != '':
1376 if Item
['page'] != Each
:
1378 if len(Item
['subreg']) > 0:
1379 for SubItem
in Item
['subreg']:
1380 if SubItem
['name'] != '':
1381 BsfItems
.append(SubItem
)
1383 BsfItems
.append(Item
)
1385 BsfItems
.sort(key
=lambda x
: x
['order'])
1387 for Item
in BsfItems
:
1388 self
.WriteBsfOption (BsfFd
, Item
)
1389 BsfFd
.write("EndPage\n\n")
1396 print "GenCfgOpt Version 0.52"
1398 print " GenCfgOpt UPDTXT PlatformDscFile BuildFvDir [-D Macros]"
1399 print " GenCfgOpt HEADER PlatformDscFile BuildFvDir InputHFile [-D Macros]"
1400 print " GenCfgOpt GENBSF PlatformDscFile BuildFvDir BsfOutFile [-D Macros]"
1404 # Parse the options and args
1406 GenCfgOpt
= CGenCfgOpt()
1407 argc
= len(sys
.argv
)
1412 DscFile
= sys
.argv
[2]
1413 if not os
.path
.exists(DscFile
):
1414 print "ERROR: Cannot open DSC file '%s' !" % DscFile
1419 if sys
.argv
[4][0] == '-':
1422 OutFile
= sys
.argv
[4]
1424 GenCfgOpt
.ParseBuildMode(sys
.argv
[3])
1425 if GenCfgOpt
.ParseMacros(sys
.argv
[Start
:]) != 0:
1426 print "ERROR: Macro parsing failed !"
1430 if not os
.path
.exists(FvDir
):
1433 if GenCfgOpt
.ParseDscFile(DscFile
, FvDir
) != 0:
1434 print "ERROR: %s !" % GenCfgOpt
.Error
1437 if GenCfgOpt
.UpdateSubRegionDefaultValue() != 0:
1438 print "ERROR: %s !" % GenCfgOpt
.Error
1441 if sys
.argv
[1] == "UPDTXT":
1442 Ret
= GenCfgOpt
.CreateSplitUpdTxt(OutFile
)
1444 # No change is detected
1446 print "INFO: %s !" % (GenCfgOpt
.Error
)
1448 print "ERROR: %s !" % (GenCfgOpt
.Error
)
1450 elif sys
.argv
[1] == "HEADER":
1451 if GenCfgOpt
.CreateHeaderFile(OutFile
) != 0:
1452 print "ERROR: %s !" % GenCfgOpt
.Error
1454 elif sys
.argv
[1] == "GENBSF":
1455 if GenCfgOpt
.GenerateBsfFile(OutFile
) != 0:
1456 print "ERROR: %s !" % GenCfgOpt
.Error
1462 print "ERROR: Unknown command '%s' !" % sys
.argv
[1]
1469 if __name__
== '__main__':