]>
git.proxmox.com Git - mirror_edk2.git/blob - IntelFsp2Pkg/Tools/GenCfgOpt.py
3 # Copyright (c) 2014 - 2018, Intel Corporation. All rights reserved.<BR>
4 # SPDX-License-Identifier: BSD-2-Clause-Patent
12 from datetime
import date
14 # Generated file copyright header
16 __copyright_txt__
= """## @file
18 # THIS IS AUTO-GENERATED FILE BY BUILD TOOLS AND PLEASE DO NOT MAKE MODIFICATION.
20 # This file lists all VPD informations for a platform collected by build.exe.
22 # Copyright (c) %4d, Intel Corporation. All rights reserved.<BR>
23 # This program and the accompanying materials
24 # are licensed and made available under the terms and conditions of the BSD License
25 # which accompanies this distribution. The full text of the license may be found at
26 # http://opensource.org/licenses/bsd-license.php
28 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
29 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
33 __copyright_bsf__
= """/** @file
35 Boot Setting File for Platform Configuration.
37 Copyright (c) %4d, Intel Corporation. All rights reserved.<BR>
38 This program and the accompanying materials
39 are licensed and made available under the terms and conditions of the BSD License
40 which accompanies this distribution. The full text of the license may be found at
41 http://opensource.org/licenses/bsd-license.php
43 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
44 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
46 This file is automatically generated. Please do NOT modify !!!
52 __copyright_h__
= """/** @file
54 Copyright (c) %4d, Intel Corporation. All rights reserved.<BR>
56 Redistribution and use in source and binary forms, with or without modification,
57 are permitted provided that the following conditions are met:
59 * Redistributions of source code must retain the above copyright notice, this
60 list of conditions and the following disclaimer.
61 * Redistributions in binary form must reproduce the above copyright notice, this
62 list of conditions and the following disclaimer in the documentation and/or
63 other materials provided with the distribution.
64 * Neither the name of Intel Corporation nor the names of its contributors may
65 be used to endorse or promote products derived from this software without
66 specific prior written permission.
68 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
69 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
70 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
71 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
72 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
73 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
74 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
75 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
76 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
77 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
78 THE POSSIBILITY OF SUCH DAMAGE.
80 This file is automatically generated. Please do NOT modify !!!
87 class CLogicalExpression
:
92 def errExit(self
, err
= ''):
93 print "ERROR: Express parsing for:"
94 print " %s" % self
.string
95 print " %s^" % (' ' * self
.index
)
97 print "INFO : %s" % err
100 def getNonNumber (self
, n1
, n2
):
107 def getCurr(self
, lens
= 1):
110 return self
.string
[self
.index
:]
112 if self
.index
+ lens
> len(self
.string
):
113 lens
= len(self
.string
) - self
.index
114 return self
.string
[self
.index
: self
.index
+ lens
]
119 return self
.index
== len(self
.string
)
121 def moveNext(self
, len = 1):
125 while not self
.isLast():
126 if self
.getCurr() in ' \t':
131 def normNumber (self
, val
):
132 return True if val
else False
134 def getNumber(self
, var
):
136 if re
.match('^0x[a-fA-F0-9]+$', var
):
138 elif re
.match('^[+-]?\d+$', var
):
144 def parseValue(self
):
147 while not self
.isLast():
148 char
= self
.getCurr()
149 if re
.match('^[\w.]', char
):
154 val
= self
.getNumber(var
)
161 def parseSingleOp(self
):
163 if re
.match('^NOT\W', self
.getCurr(-1)):
165 op
= self
.parseBrace()
166 val
= self
.getNumber (op
)
168 self
.errExit ("'%s' is not a number" % op
)
169 return "%d" % (not self
.normNumber(int(op
)))
171 return self
.parseValue()
173 def parseBrace(self
):
175 char
= self
.getCurr()
178 value
= self
.parseExpr()
180 if self
.getCurr() != ')':
181 self
.errExit ("Expecting closing brace or operator")
185 value
= self
.parseSingleOp()
188 def parseCompare(self
):
189 value
= self
.parseBrace()
192 char
= self
.getCurr()
193 if char
in ['<', '>']:
195 next
= self
.getCurr()
201 result
= self
.parseBrace()
202 test
= self
.getNonNumber(result
, value
)
204 value
= "%d" % self
.normNumber(eval (value
+ op
+ result
))
206 self
.errExit ("'%s' is not a valid number for comparision" % test
)
207 elif char
in ['=', '!']:
209 if op
in ['==', '!=']:
211 result
= self
.parseBrace()
212 test
= self
.getNonNumber(result
, value
)
214 value
= "%d" % self
.normNumber((eval (value
+ op
+ result
)))
216 value
= "%d" % self
.normNumber(eval ("'" + value
+ "'" + op
+ "'" + result
+ "'"))
224 value
= self
.parseCompare()
227 if re
.match('^AND\W', self
.getCurr(-1)):
229 result
= self
.parseCompare()
230 test
= self
.getNonNumber(result
, value
)
232 value
= "%d" % self
.normNumber(int(value
) & int(result
))
234 self
.errExit ("'%s' is not a valid op number for AND" % test
)
239 def parseOrXor(self
):
240 value
= self
.parseAnd()
245 if re
.match('^XOR\W', self
.getCurr(-1)):
248 elif re
.match('^OR\W', self
.getCurr(-1)):
254 result
= self
.parseAnd()
255 test
= self
.getNonNumber(result
, value
)
257 value
= "%d" % self
.normNumber(eval (value
+ op
+ result
))
259 self
.errExit ("'%s' is not a valid op number for XOR/OR" % test
)
263 return self
.parseOrXor()
266 value
= self
.parseExpr()
268 if not self
.isLast():
269 self
.errExit ("Unexpected character found '%s'" % self
.getCurr())
270 test
= self
.getNumber(value
)
272 self
.errExit ("Result '%s' is not a number" % value
)
275 def evaluateExpress (self
, Expr
):
289 self
._GlobalDataDef
= """
295 self
._BuidinOptionTxt
= """
297 Selection 0x1 , "Enabled"
298 Selection 0x0 , "Disabled"
303 self
._BsfKeyList
= ['FIND','NAME','HELP','TYPE','PAGE','OPTION','ORDER']
304 self
._HdrKeyList
= ['HEADER','STRUCT', 'EMBED', 'COMMENT']
305 self
._BuidinOption
= {'$EN_DIS' : 'EN_DIS'}
309 self
._CfgBlkDict
= {}
310 self
._CfgPageDict
= {}
311 self
._CfgItemList
= []
316 def ParseMacros (self
, MacroDefStr
):
317 # ['-DABC=1', '-D', 'CFG_DEBUG=1', '-D', 'CFG_OUTDIR=Build']
320 for Macro
in MacroDefStr
:
321 if Macro
.startswith('-D'):
329 Match
= re
.match("(\w+)=(.+)", Macro
)
331 self
._MacroDict
[Match
.group(1)] = Match
.group(2)
333 Match
= re
.match("(\w+)", Macro
)
335 self
._MacroDict
[Match
.group(1)] = ''
336 if len(self
._MacroDict
) == 0:
341 print "INFO : Macro dictionary:"
342 for Each
in self
._MacroDict
:
343 print " $(%s) = [ %s ]" % (Each
, self
._MacroDict
[Each
])
346 def EvaulateIfdef (self
, Macro
):
347 Result
= Macro
in self
._MacroDict
349 print "INFO : Eval Ifdef [%s] : %s" % (Macro
, Result
)
352 def ExpandMacros (self
, Input
):
354 Match
= re
.findall("\$\(\w+\)", Input
)
357 Variable
= Each
[2:-1]
358 if Variable
in self
._MacroDict
:
359 Line
= Line
.replace(Each
, self
._MacroDict
[Variable
])
362 print "WARN : %s is not defined" % Each
363 Line
= Line
.replace(Each
, Each
[2:-1])
366 def ExpandPcds (self
, Input
):
368 Match
= re
.findall("(\w+\.\w+)", Input
)
370 for PcdName
in Match
:
371 if PcdName
in self
._PcdsDict
:
372 Line
= Line
.replace(PcdName
, self
._PcdsDict
[PcdName
])
375 print "WARN : %s is not defined" % PcdName
378 def EvaluateExpress (self
, Expr
):
379 ExpExpr
= self
.ExpandPcds(Expr
)
380 ExpExpr
= self
.ExpandMacros(ExpExpr
)
381 LogExpr
= CLogicalExpression()
382 Result
= LogExpr
.evaluateExpress (ExpExpr
)
384 print "INFO : Eval Express [%s] : %s" % (Expr
, Result
)
387 def FormatListValue(self
, ConfigDict
):
388 Struct
= ConfigDict
['struct']
389 if Struct
not in ['UINT8','UINT16','UINT32','UINT64']:
393 binlist
= ConfigDict
['value'][1:-1].split(',')
396 if each
.startswith('0x'):
397 value
= int(each
, 16)
400 dataarray
.append(value
)
402 unit
= int(Struct
[4:]) / 8
403 if int(ConfigDict
['length']) != unit
* len(dataarray
):
404 raise Exception("Array size is not proper for '%s' !" % ConfigDict
['cname'])
407 for each
in dataarray
:
409 for loop
in xrange(unit
):
410 bytearray
.append("0x%02X" % (value
& 0xFF))
412 newvalue
= '{' + ','.join(bytearray
) + '}'
413 ConfigDict
['value'] = newvalue
416 def ParseDscFile (self
, DscFile
, FvDir
):
419 self
._CfgItemList
= []
420 self
._CfgPageDict
= {}
421 self
._CfgBlkDict
= {}
422 self
._DscFile
= DscFile
435 DscFd
= open(DscFile
, "r")
436 DscLines
= DscFd
.readlines()
439 MaxAlign
= 32 #Default align to 32, but if there are 64 bit unit, align to 64
440 SizeAlign
= 0 #record the struct max align
442 DscLine
= DscLines
.pop(0).strip()
444 Match
= re
.match("^\[(.+)\]", DscLine
)
445 if Match
is not None:
450 if Match
.group(1).lower() == "Defines".lower():
452 if (Match
.group(1).lower() == "PcdsFeatureFlag".lower() or Match
.group(1).lower() == "PcdsFixedAtBuild".lower()):
454 elif Match
.group(1).lower() == "PcdsDynamicVpd.Upd".lower():
456 ConfigDict
['header'] = 'ON'
457 ConfigDict
['region'] = 'UPD'
458 ConfigDict
['order'] = -1
459 ConfigDict
['page'] = ''
460 ConfigDict
['name'] = ''
461 ConfigDict
['find'] = ''
462 ConfigDict
['struct'] = ''
463 ConfigDict
['embed'] = ''
464 ConfigDict
['comment'] = ''
465 ConfigDict
['subreg'] = []
469 if IsDefSect
or IsPcdSect
or IsUpdSect
or IsVpdSect
:
470 if re
.match("^!else($|\s+#.+)", DscLine
):
472 IfStack
[-1] = not IfStack
[-1]
474 print("ERROR: No paired '!if' found for '!else' for line '%s'" % DscLine
)
476 elif re
.match("^!endif($|\s+#.+)", DscLine
):
479 Level
= ElifStack
.pop()
483 print("ERROR: No paired '!if' found for '!endif' for line '%s'" % DscLine
)
487 Match
= re
.match("!(ifdef|ifndef)\s+(.+)", DscLine
)
489 Result
= self
.EvaulateIfdef (Match
.group(2))
490 if Match
.group(1) == 'ifndef':
492 IfStack
.append(Result
)
495 Match
= re
.match("!(if|elseif)\s+(.+)", DscLine
.split("#")[0])
497 Result
= self
.EvaluateExpress(Match
.group(2))
498 if Match
.group(1) == "if":
500 IfStack
.append(Result
)
503 IfStack
[-1] = not IfStack
[-1]
504 IfStack
.append(Result
)
505 ElifStack
[-1] = ElifStack
[-1] + 1
507 print("ERROR: No paired '!if' found for '!elif' for line '%s'" % DscLine
)
511 Handle
= reduce(lambda x
,y
: x
and y
, IfStack
)
515 Match
= re
.match("!include\s+(.+)", DscLine
)
517 IncludeFilePath
= Match
.group(1)
518 IncludeFilePath
= self
.ExpandMacros(IncludeFilePath
)
519 PackagesPath
= os
.getenv("PACKAGES_PATH")
521 for PackagePath
in PackagesPath
.split(os
.pathsep
):
522 IncludeFilePathAbs
= os
.path
.join(os
.path
.normpath(PackagePath
), os
.path
.normpath(IncludeFilePath
))
523 if os
.path
.exists(IncludeFilePathAbs
):
524 IncludeDsc
= open(IncludeFilePathAbs
, "r")
527 IncludeDsc
= open(IncludeFilePath
, "r")
528 if IncludeDsc
== None:
529 print("ERROR: Cannot open file '%s'" % IncludeFilePath
)
531 NewDscLines
= IncludeDsc
.readlines()
533 DscLines
= NewDscLines
+ DscLines
536 if DscLine
.startswith('!'):
537 print("ERROR: Unrecoginized directive for line '%s'" % DscLine
)
543 #DEFINE UPD_TOOL_GUID = 8C3D856A-9BE6-468E-850A-24F7A8D38E09
544 #DEFINE FSP_T_UPD_TOOL_GUID = 34686CA3-34F9-4901-B82A-BA630F0714C6
545 #DEFINE FSP_M_UPD_TOOL_GUID = 39A250DB-E465-4DD1-A2AC-E2BD3C0E2385
546 #DEFINE FSP_S_UPD_TOOL_GUID = CAE3605B-5B34-4C85-B3D7-27D54273C40F
547 Match
= re
.match("^\s*(?:DEFINE\s+)*(\w+)\s*=\s*([-.\w]+)", DscLine
)
549 self
._MacroDict
[Match
.group(1)] = Match
.group(2)
551 print "INFO : DEFINE %s = [ %s ]" % (Match
.group(1), Match
.group(2))
553 #gSiPkgTokenSpaceGuid.PcdTxtEnable|FALSE
554 #gSiPkgTokenSpaceGuid.PcdOverclockEnable|TRUE
555 Match
= re
.match("^\s*([\w\.]+)\s*\|\s*(\w+)", DscLine
)
557 self
._PcdsDict
[Match
.group(1)] = Match
.group(2)
559 print "INFO : PCD %s = [ %s ]" % (Match
.group(1), Match
.group(2))
561 while i
< len(BuildOptionPcd
):
562 Match
= re
.match("\s*([\w\.]+)\s*\=\s*(\w+)", BuildOptionPcd
[i
])
564 self
._PcdsDict
[Match
.group(1)] = Match
.group(2)
567 Match
= re
.match("^\s*#\s+(!BSF|@Bsf|!HDR)\s+(.+)", DscLine
)
569 Remaining
= Match
.group(2)
570 if Match
.group(1) == '!BSF' or Match
.group(1) == '@Bsf':
571 Match
= re
.match("(?:^|.+\s+)PAGES:{(.+?)}", Remaining
)
573 # !BSF PAGES:{HSW:"Haswell System Agent", LPT:"Lynx Point PCH"}
574 PageList
= Match
.group(1).split(',')
575 for Page
in PageList
:
577 Match
= re
.match("(\w+):\"(.+)\"", Page
)
578 self
._CfgPageDict
[Match
.group(1)] = Match
.group(2)
580 Match
= re
.match("(?:^|.+\s+)BLOCK:{NAME:\"(.+)\"\s*,\s*VER:\"(.+)\"\s*}", Remaining
)
582 self
._CfgBlkDict
['name'] = Match
.group(1)
583 self
._CfgBlkDict
['ver'] = Match
.group(2)
585 for Key
in self
._BsfKeyList
:
586 Match
= re
.match("(?:^|.+\s+)%s:{(.+?)}" % Key
, Remaining
)
588 if Key
in ['NAME', 'HELP', 'OPTION'] and Match
.group(1).startswith('+'):
589 ConfigDict
[Key
.lower()] += Match
.group(1)[1:]
591 ConfigDict
[Key
.lower()] = Match
.group(1)
593 for Key
in self
._HdrKeyList
:
594 Match
= re
.match("(?:^|.+\s+)%s:{(.+?)}" % Key
, Remaining
)
596 ConfigDict
[Key
.lower()] = Match
.group(1)
598 Match
= re
.match("^\s*#\s+@Prompt\s+(.+)", DscLine
)
600 ConfigDict
['name'] = Match
.group(1)
602 Match
= re
.match("^\s*#\s*@ValidList\s*(.+)\s*\|\s*(.+)\s*\|\s*(.+)\s*", DscLine
)
604 if Match
.group(2).strip() in self
._BuidinOption
:
605 ConfigDict
['option'] = Match
.group(2).strip()
607 OptionValueList
= Match
.group(2).split(',')
608 OptionStringList
= Match
.group(3).split(',')
610 for Option
in OptionValueList
:
611 Option
= Option
.strip()
612 ConfigDict
['option'] = ConfigDict
['option'] + str(Option
) + ':' + OptionStringList
[Index
].strip()
614 if Index
in range(len(OptionValueList
)):
615 ConfigDict
['option'] += ', '
616 ConfigDict
['type'] = "Combo"
618 Match
= re
.match("^\s*#\s*@ValidRange\s*(.+)\s*\|\s*(.+)\s*-\s*(.+)\s*", DscLine
)
620 if "0x" in Match
.group(2) or "0x" in Match
.group(3):
621 ConfigDict
['type'] = "EditNum, HEX, (%s,%s)" % (Match
.group(2), Match
.group(3))
623 ConfigDict
['type'] = "EditNum, DEC, (%s,%s)" % (Match
.group(2), Match
.group(3))
625 Match
= re
.match("^\s*##\s+(.+)", DscLine
)
627 ConfigDict
['help'] = Match
.group(1)
631 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
)
633 Match
= re
.match("^([_a-zA-Z0-9]+).([_a-zA-Z0-9]+)\s*\|\s*(0x[0-9A-F]+)(?:\s*\|\s*(.+))?", DscLine
)
635 ConfigDict
['space'] = Match
.group(1)
636 ConfigDict
['cname'] = Match
.group(2)
637 if Match
.group(3) != '*':
639 Offset
= int (Match
.group(3), 16)
643 if Hardcode
and AutoAlign
:
644 print("Hardcode and auto-align mixed mode is not supported by GenCfgOpt")
646 ConfigDict
['offset'] = Offset
647 if ConfigDict
['order'] == -1:
648 ConfigDict
['order'] = ConfigDict
['offset'] << 8
650 (Major
, Minor
) = ConfigDict
['order'].split('.')
651 ConfigDict
['order'] = (int (Major
, 16) << 8 ) + int (Minor
, 16)
653 Value
= Match
.group(5).strip()
654 if Match
.group(4).startswith("0x"):
655 Length
= int (Match
.group(4), 16)
657 Length
= int (Match
.group(4))
660 Value
= Match
.group(4)
663 Value
= Value
.strip()
665 Match
= re
.match("^.+\s*\|\s*(.+)", Value
)
667 Value
= Match
.group(1)
670 ConfigDict
['length'] = Length
671 Match
= re
.match("\$\((\w+)\)", Value
)
673 if Match
.group(1) in self
._MacroDict
:
674 Value
= self
._MacroDict
[Match
.group(1)]
676 ConfigDict
['value'] = Value
677 if (len(Value
) > 0) and (Value
[0] == '{'):
678 Value
= self
.FormatListValue(ConfigDict
)
680 if ConfigDict
['name'] == '':
681 # Clear BSF specific items
682 ConfigDict
['bsfname'] = ''
683 ConfigDict
['help'] = ''
684 ConfigDict
['type'] = ''
685 ConfigDict
['option'] = ''
686 if IsUpdSect
and AutoAlign
:
687 ItemLength
= int(ConfigDict
['length'])
688 ItemOffset
= int(ConfigDict
['offset'])
689 ItemStruct
= ConfigDict
['struct']
691 if ItemLength
in [1, 2, 4, 8] and not ConfigDict
['value'].startswith('{'):
693 # If there are 64 bit unit, align to 64
698 UnitDict
= {'UINT8':1, 'UINT16':2, 'UINT32':4, 'UINT64':8}
699 if ItemStruct
in ['UINT8', 'UINT16', 'UINT32', 'UINT64']:
700 Unit
= UnitDict
[ItemStruct
]
701 # If there are 64 bit unit, align to 64
704 SizeAlign
= max(SizeAlign
, Unit
)
705 if (ConfigDict
['embed'].find(':START') != -1):
707 SubOffset
= ItemOffset
- Base
708 SubRemainder
= SubOffset
% Unit
710 Diff
= Unit
- SubRemainder
711 Offset
= Offset
+ Diff
712 ItemOffset
= ItemOffset
+ Diff
714 if (ConfigDict
['embed'].find(':END') != -1):
715 Remainder
= Offset
% (MaxAlign
/8) # MaxAlign is either 32 or 64
717 Diff
= (MaxAlign
/8) - Remainder
718 Offset
= Offset
+ Diff
719 ItemOffset
= ItemOffset
+ Diff
720 MaxAlign
= 32 # Reset to default 32 align when struct end
721 if (ConfigDict
['cname'] == 'UpdTerminator'):
722 # ItemLength is the size of UpdTerminator
723 # Itemlength might be 16, 32, or 64
724 # Struct align to 64 if UpdTerminator
725 # or struct size is 64 bit, else align to 32
726 Remainder
= Offset
% max(ItemLength
/8, 4, SizeAlign
)
727 Offset
= Offset
+ ItemLength
729 Diff
= max(ItemLength
/8, 4, SizeAlign
) - Remainder
730 ItemOffset
= ItemOffset
+ Diff
731 ConfigDict
['offset'] = ItemOffset
733 self
._CfgItemList
.append(ConfigDict
.copy())
734 ConfigDict
['name'] = ''
735 ConfigDict
['find'] = ''
736 ConfigDict
['struct'] = ''
737 ConfigDict
['embed'] = ''
738 ConfigDict
['comment'] = ''
739 ConfigDict
['order'] = -1
740 ConfigDict
['subreg'] = []
741 ConfigDict
['option'] = ''
743 # It could be a virtual item as below
744 # !BSF FIELD:{SerialDebugPortAddress0:1}
746 # @Bsf FIELD:{SerialDebugPortAddress0:1b}
747 Match
= re
.match("^\s*#\s+(!BSF|@Bsf)\s+FIELD:{(.+):(\d+)([Bb])?}", DscLine
)
749 SubCfgDict
= ConfigDict
.copy()
750 if (Match
.group(4) == None) or (Match
.group(4) == 'B'):
752 elif Match
.group(4) == 'b':
755 print("ERROR: Invalide BSF FIELD length for line '%s'" % DscLine
)
757 SubCfgDict
['cname'] = Match
.group(2)
758 SubCfgDict
['bitlength'] = int (Match
.group(3)) * UnitBitLen
759 if SubCfgDict
['bitlength'] > 0:
760 LastItem
= self
._CfgItemList
[-1]
761 if len(LastItem
['subreg']) == 0:
764 SubOffset
= LastItem
['subreg'][-1]['bitoffset'] + LastItem
['subreg'][-1]['bitlength']
765 SubCfgDict
['bitoffset'] = SubOffset
766 LastItem
['subreg'].append (SubCfgDict
.copy())
767 ConfigDict
['name'] = ''
770 def GetBsfBitFields (self
, subitem
, bytes
):
771 start
= subitem
['bitoffset']
772 end
= start
+ subitem
['bitlength']
773 bitsvalue
= ''.join('{0:08b}'.format(i
) for i
in bytes
[::-1])
774 bitsvalue
= bitsvalue
[::-1]
775 bitslen
= len(bitsvalue
)
776 if start
> bitslen
or end
> bitslen
:
777 print "Invalid bits offset [%d,%d] for %s" % (start
, end
, subitem
['name'])
779 return hex(int(bitsvalue
[start
:end
][::-1], 2))
781 def UpdateSubRegionDefaultValue (self
):
783 for Item
in self
._CfgItemList
:
784 if len(Item
['subreg']) == 0:
787 if Item
['value'][0] == '{':
788 binlist
= Item
['value'][1:-1].split(',')
791 if each
.startswith('0x'):
792 value
= int(each
, 16)
795 bytearray
.append(value
)
797 if Item
['value'].startswith('0x'):
798 value
= int(Item
['value'], 16)
800 value
= int(Item
['value'])
802 while idx
< Item
['length']:
803 bytearray
.append(value
& 0xFF)
806 for SubItem
in Item
['subreg']:
807 valuestr
= self
.GetBsfBitFields(SubItem
, bytearray
)
808 SubItem
['value'] = valuestr
811 def CreateSplitUpdTxt (self
, UpdTxtFile
):
812 GuidList
= ['FSP_T_UPD_TOOL_GUID','FSP_M_UPD_TOOL_GUID','FSP_S_UPD_TOOL_GUID']
813 SignatureList
= ['0x545F', '0x4D5F','0x535F'] # _T, _M, and _S signature for FSPT, FSPM, FSPS
814 for Index
in range(len(GuidList
)):
817 if GuidList
[Index
] not in self
._MacroDict
:
818 self
.Error
= "%s definition is missing in DSC file" % (GuidList
[Index
])
822 UpdTxtFile
= os
.path
.join(FvDir
, self
._MacroDict
[GuidList
[Index
]] + '.txt')
825 if not os
.path
.exists(UpdTxtFile
):
828 DscTime
= os
.path
.getmtime(self
._DscFile
)
829 TxtTime
= os
.path
.getmtime(UpdTxtFile
)
830 if DscTime
> TxtTime
:
834 # DSC has not been modified yet
835 # So don't have to re-generate other files
836 self
.Error
= 'No DSC file change, skip to create UPD TXT file'
839 TxtFd
= open(UpdTxtFile
, "w")
840 TxtFd
.write("%s\n" % (__copyright_txt__
% date
.today().year
))
848 for Item
in self
._CfgItemList
:
849 if Item
['cname'] == 'Signature' and str(Item
['value'])[0:6] == SignatureList
[Index
]:
850 StartAddr
= Item
['offset']
851 NextOffset
= StartAddr
853 if Item
['cname'] == 'UpdTerminator' and InRange
== True:
854 EndAddr
= Item
['offset']
857 for Item
in self
._CfgItemList
:
858 if Item
['cname'] == 'Signature' and str(Item
['value'])[0:6] == SignatureList
[Index
]:
862 if Item
['cname'] == 'UpdTerminator':
864 if Item
['region'] != 'UPD':
866 Offset
= Item
['offset']
867 if StartAddr
> Offset
or EndAddr
< Offset
:
869 if NextOffset
< Offset
:
871 TxtFd
.write("%s.UnusedUpdSpace%d|%s0x%04X|0x%04X|{0}\n" % (Item
['space'], SpaceIdx
, Default
, NextOffset
- StartAddr
, Offset
- NextOffset
))
872 SpaceIdx
= SpaceIdx
+ 1
873 NextOffset
= Offset
+ Item
['length']
874 TxtFd
.write("%s.%s|%s0x%04X|%s|%s\n" % (Item
['space'],Item
['cname'],Default
,Item
['offset'] - StartAddr
,Item
['length'],Item
['value']))
878 def ProcessMultilines (self
, String
, MaxCharLength
):
880 StringLength
= len(String
)
881 CurrentStringStart
= 0
884 if len(String
) <= MaxCharLength
:
885 while (StringOffset
< StringLength
):
886 if StringOffset
>= 1:
887 if String
[StringOffset
- 1] == '\\' and String
[StringOffset
] == 'n':
888 BreakLineDict
.append (StringOffset
+ 1)
890 if BreakLineDict
!= []:
891 for Each
in BreakLineDict
:
892 Multilines
+= " %s\n" % String
[CurrentStringStart
:Each
].lstrip()
893 CurrentStringStart
= Each
894 if StringLength
- CurrentStringStart
> 0:
895 Multilines
+= " %s\n" % String
[CurrentStringStart
:].lstrip()
897 Multilines
= " %s\n" % String
901 FoundSpaceChar
= False
902 while (StringOffset
< StringLength
):
903 if StringOffset
>= 1:
904 if NewLineCount
>= MaxCharLength
- 1:
905 if String
[StringOffset
] == ' ' and StringLength
- StringOffset
> 10:
906 BreakLineDict
.append (NewLineStart
+ NewLineCount
)
907 NewLineStart
= NewLineStart
+ NewLineCount
909 FoundSpaceChar
= True
910 elif StringOffset
== StringLength
- 1 and FoundSpaceChar
== False:
911 BreakLineDict
.append (0)
912 if String
[StringOffset
- 1] == '\\' and String
[StringOffset
] == 'n':
913 BreakLineDict
.append (StringOffset
+ 1)
914 NewLineStart
= StringOffset
+ 1
918 if BreakLineDict
!= []:
919 BreakLineDict
.sort ()
920 for Each
in BreakLineDict
:
922 Multilines
+= " %s\n" % String
[CurrentStringStart
:Each
].lstrip()
923 CurrentStringStart
= Each
924 if StringLength
- CurrentStringStart
> 0:
925 Multilines
+= " %s\n" % String
[CurrentStringStart
:].lstrip()
928 def CreateField (self
, Item
, Name
, Length
, Offset
, Struct
, BsfName
, Help
, Option
):
936 if Length
in [1,2,4,8]:
937 Type
= "UINT%d" % (Length
* 8)
938 if Name
.startswith("UnusedUpdSpace") and Length
!= 1:
945 if Item
and Item
['value'].startswith('{'):
951 if Struct
in ['UINT8','UINT16','UINT32','UINT64']:
953 Unit
= int(Type
[4:]) / 8
954 Length
= Length
/ Unit
959 Name
= Name
+ '[%d]' % Length
961 if len(Type
) < PosName
:
962 Space1
= PosName
- len(Type
)
967 NameLine
=" - %s\n" % BsfName
972 HelpLine
= self
.ProcessMultilines (Help
, 80)
975 OptionLine
= self
.ProcessMultilines (Option
, 80)
980 OffsetStr
= '0x%04X' % Offset
982 return "\n/** Offset %s%s%s%s**/\n %s%s%s;\n" % (OffsetStr
, NameLine
, HelpLine
, OptionLine
, Type
, ' ' * Space1
, Name
,)
984 def PostProcessBody (self
, TextBody
):
990 IsUpdHdrDefined
= False
992 for Line
in TextBody
:
993 SplitToLines
= Line
.splitlines()
994 MatchComment
= re
.match("^/\*\sCOMMENT:(\w+):([\w|\W|\s]+)\s\*/\s([\s\S]*)", SplitToLines
[0])
996 if MatchComment
.group(1) == 'FSP_UPD_HEADER':
1000 if IsUpdHdrDefined
!= True or IsUpdHeader
!= True:
1001 CommentLine
= " " + MatchComment
.group(2) + "\n"
1002 NewTextBody
.append("/**" + CommentLine
+ "**/\n")
1003 Line
= Line
[(len(SplitToLines
[0]) + 1):]
1005 Match
= re
.match("^/\*\sEMBED_STRUCT:(\w+):(\w+):(START|END)\s\*/\s([\s\S]*)", Line
)
1007 Line
= Match
.group(4)
1008 if Match
.group(1) == 'FSP_UPD_HEADER':
1013 if Match
and Match
.group(3) == 'START':
1014 if IsUpdHdrDefined
!= True or IsUpdHeader
!= True:
1015 NewTextBody
.append ('typedef struct {\n')
1016 StructName
= Match
.group(1)
1017 VariableName
= Match
.group(2)
1018 MatchOffset
= re
.search('/\*\*\sOffset\s0x([a-fA-F0-9]+)', Line
)
1020 Offset
= int(MatchOffset
.group(1), 16)
1025 OldTextBody
.append (self
.CreateField (None, VariableName
, 0, Offset
, StructName
, '', '', ''))
1027 if IsUpdHdrDefined
!= True or IsUpdHeader
!= True:
1028 NewTextBody
.append (Line
)
1030 OldTextBody
.append (Line
)
1032 if Match
and Match
.group(3) == 'END':
1033 if (StructName
!= Match
.group(1)) or (VariableName
!= Match
.group(2)):
1034 print "Unmatched struct name '%s' and '%s' !" % (StructName
, Match
.group(1))
1036 if IsUpdHdrDefined
!= True or IsUpdHeader
!= True:
1037 NewTextBody
.append ('} %s;\n\n' % StructName
)
1038 IsUpdHdrDefined
= True
1040 NewTextBody
.extend(OldTextBody
)
1043 def WriteLinesWithoutTailingSpace (self
, HeaderFd
, Line
):
1044 TxtBody2
= Line
.splitlines(True)
1045 for Line2
in TxtBody2
:
1046 Line2
= Line2
.rstrip()
1048 HeaderFd
.write (Line2
)
1050 def CreateHeaderFile (self
, InputHeaderFile
):
1053 HeaderFileName
= 'FspUpd.h'
1054 HeaderFile
= os
.path
.join(FvDir
, HeaderFileName
)
1056 # Check if header needs to be recreated
1060 for Item
in self
._CfgItemList
:
1061 if str(Item
['cname']) == 'Signature' and Item
['length'] == 8:
1062 Value
= int(Item
['value'], 16)
1065 Chars
.append(chr(Value
& 0xFF))
1067 SignatureStr
= ''.join(Chars
)
1068 # Signature will be _T / _M / _S for FSPT / FSPM / FSPS accordingly
1069 if '_T' in SignatureStr
[6:6+2]:
1070 TxtBody
.append("#define FSPT_UPD_SIGNATURE %s /* '%s' */\n\n" % (Item
['value'], SignatureStr
))
1071 elif '_M' in SignatureStr
[6:6+2]:
1072 TxtBody
.append("#define FSPM_UPD_SIGNATURE %s /* '%s' */\n\n" % (Item
['value'], SignatureStr
))
1073 elif '_S' in SignatureStr
[6:6+2]:
1074 TxtBody
.append("#define FSPS_UPD_SIGNATURE %s /* '%s' */\n\n" % (Item
['value'], SignatureStr
))
1075 TxtBody
.append("\n")
1077 for Region
in ['UPD']:
1079 UpdSignature
= ['0x545F', '0x4D5F', '0x535F'] #['_T', '_M', '_S'] signature for FSPT, FSPM, FSPS
1080 UpdStructure
= ['FSPT_UPD', 'FSPM_UPD', 'FSPS_UPD']
1081 for Item
in self
._CfgItemList
:
1082 if Item
["cname"] == 'Signature' and Item
["value"][0:6] in UpdSignature
:
1083 UpdOffsetTable
.append (Item
["offset"])
1085 for UpdIdx
in range(len(UpdOffsetTable
)):
1087 for Item
in self
._CfgItemList
:
1088 if Item
["comment"] != '' and Item
["offset"] >= UpdOffsetTable
[UpdIdx
]:
1089 MatchComment
= re
.match("^(U|V)PD_DATA_REGION:([\w|\W|\s]+)", Item
["comment"])
1090 if MatchComment
and MatchComment
.group(1) == Region
[0]:
1091 CommentLine
= " " + MatchComment
.group(2) + "\n"
1092 TxtBody
.append("/**" + CommentLine
+ "**/\n")
1093 elif Item
["offset"] >= UpdOffsetTable
[UpdIdx
] and Item
["comment"] == '':
1094 Match
= re
.match("^FSP([\w|\W|\s])_UPD", UpdStructure
[UpdIdx
])
1096 TxtBody
.append("/** Fsp " + Match
.group(1) + " UPD Configuration\n**/\n")
1097 TxtBody
.append("typedef struct {\n")
1107 for Item
in self
._CfgItemList
:
1108 if Item
['cname'] == 'Signature' and str(Item
['value'])[0:6] == UpdSignature
[UpdIdx
] or Region
[0] == 'V':
1112 if Item
['cname'] == 'UpdTerminator':
1115 if Item
['region'] != Region
:
1118 if Item
["offset"] < UpdOffsetTable
[UpdIdx
]:
1121 NextVisible
= LastVisible
1123 if LastVisible
and (Item
['header'] == 'OFF'):
1125 ResvOffset
= Item
['offset']
1126 elif (not LastVisible
) and Item
['header'] == 'ON':
1128 Name
= "Reserved" + Region
[0] + "pdSpace%d" % ResvIdx
1129 ResvIdx
= ResvIdx
+ 1
1130 TxtBody
.append(self
.CreateField (Item
, Name
, Item
["offset"] - ResvOffset
, ResvOffset
, '', '', '', ''))
1132 if Offset
< Item
["offset"]:
1134 Name
= "Unused" + Region
[0] + "pdSpace%d" % SpaceIdx
1135 LineBuffer
.append(self
.CreateField (Item
, Name
, Item
["offset"] - Offset
, Offset
, '', '', '', ''))
1136 SpaceIdx
= SpaceIdx
+ 1
1137 Offset
= Item
["offset"]
1139 LastVisible
= NextVisible
1141 Offset
= Offset
+ Item
["length"]
1143 for Each
in LineBuffer
:
1144 TxtBody
.append (Each
)
1146 Comment
= Item
["comment"]
1147 Embed
= Item
["embed"].upper()
1148 if Embed
.endswith(':START') or Embed
.endswith(':END'):
1149 if not Comment
== '' and Embed
.endswith(':START'):
1150 Marker
= '/* COMMENT:%s */ \n' % Item
["comment"]
1151 Marker
= Marker
+ '/* EMBED_STRUCT:%s */ ' % Item
["embed"]
1153 Marker
= '/* EMBED_STRUCT:%s */ ' % Item
["embed"]
1158 self
.Error
= "Invalid embedded structure format '%s'!\n" % Item
["embed"]
1160 Line
= Marker
+ self
.CreateField (Item
, Item
["cname"], Item
["length"], Item
["offset"], Item
['struct'], Item
['name'], Item
['help'], Item
['option'])
1161 TxtBody
.append(Line
)
1162 if Item
['cname'] == 'UpdTerminator':
1164 TxtBody
.append("} " + UpdStructure
[UpdIdx
] + ";\n\n")
1166 # Handle the embedded data structure
1167 TxtBody
= self
.PostProcessBody (TxtBody
)
1169 HeaderTFileName
= 'FsptUpd.h'
1170 HeaderMFileName
= 'FspmUpd.h'
1171 HeaderSFileName
= 'FspsUpd.h'
1173 UpdRegionCheck
= ['FSPT', 'FSPM', 'FSPS'] # FSPX_UPD_REGION
1174 UpdConfigCheck
= ['FSP_T', 'FSP_M', 'FSP_S'] # FSP_X_CONFIG, FSP_X_TEST_CONFIG, FSP_X_RESTRICTED_CONFIG
1175 UpdSignatureCheck
= ['FSPT_UPD_SIGNATURE', 'FSPM_UPD_SIGNATURE', 'FSPS_UPD_SIGNATURE']
1176 ExcludedSpecificUpd
= 'FSPM_ARCH_UPD'
1178 if InputHeaderFile
!= '':
1179 if not os
.path
.exists(InputHeaderFile
):
1180 self
.Error
= "Input header file '%s' does not exist" % InputHeaderFile
1183 InFd
= open(InputHeaderFile
, "r")
1184 IncLines
= InFd
.readlines()
1187 for item
in range(len(UpdRegionCheck
)):
1188 if UpdRegionCheck
[item
] == 'FSPT':
1189 HeaderFd
= open(os
.path
.join(FvDir
, HeaderTFileName
), "w")
1190 FileBase
= os
.path
.basename(os
.path
.join(FvDir
, HeaderTFileName
))
1191 elif UpdRegionCheck
[item
] == 'FSPM':
1192 HeaderFd
= open(os
.path
.join(FvDir
, HeaderMFileName
), "w")
1193 FileBase
= os
.path
.basename(os
.path
.join(FvDir
, HeaderMFileName
))
1194 elif UpdRegionCheck
[item
] == 'FSPS':
1195 HeaderFd
= open(os
.path
.join(FvDir
, HeaderSFileName
), "w")
1196 FileBase
= os
.path
.basename(os
.path
.join(FvDir
, HeaderSFileName
))
1197 FileName
= FileBase
.replace(".", "_").upper()
1198 HeaderFd
.write("%s\n" % (__copyright_h__
% date
.today().year
))
1199 HeaderFd
.write("#ifndef __%s__\n" % FileName
)
1200 HeaderFd
.write("#define __%s__\n\n" % FileName
)
1201 HeaderFd
.write("#include <%s>\n\n" % HeaderFileName
)
1202 HeaderFd
.write("#pragma pack(1)\n\n")
1205 for Line
in IncLines
:
1206 Match
= re
.search ("!EXPORT\s+([A-Z]+)\s+EXTERNAL_BOOTLOADER_STRUCT_(BEGIN|END)\s+", Line
)
1208 if Match
.group(2) == "BEGIN" and Match
.group(1) == UpdRegionCheck
[item
]:
1215 HeaderFd
.write(Line
)
1216 HeaderFd
.write("\n")
1222 StructStartWithComment
= []
1224 for Line
in TxtBody
:
1226 Match
= re
.match("(typedef struct {)", Line
)
1228 StartIndex
= Index
- 1
1229 Match
= re
.match("}\s([_A-Z0-9]+);", Line
)
1230 if Match
and (UpdRegionCheck
[item
] in Match
.group(1) or UpdConfigCheck
[item
] in Match
.group(1)) and (ExcludedSpecificUpd
not in Match
.group(1)):
1232 StructStart
.append(StartIndex
)
1233 StructEnd
.append(EndIndex
)
1235 for Line
in TxtBody
:
1237 for Item
in range(len(StructStart
)):
1238 if Index
== StructStart
[Item
]:
1239 Match
= re
.match("^(/\*\*\s*)", Line
)
1241 StructStartWithComment
.append(StructStart
[Item
])
1243 StructStartWithComment
.append(StructStart
[Item
] + 1)
1245 for Line
in TxtBody
:
1247 for Item
in range(len(StructStart
)):
1248 if Index
>= StructStartWithComment
[Item
] and Index
<= StructEnd
[Item
]:
1249 self
.WriteLinesWithoutTailingSpace(HeaderFd
, Line
)
1250 HeaderFd
.write("#pragma pack()\n\n")
1251 HeaderFd
.write("#endif\n")
1254 HeaderFd
= open(HeaderFile
, "w")
1255 FileBase
= os
.path
.basename(HeaderFile
)
1256 FileName
= FileBase
.replace(".", "_").upper()
1257 HeaderFd
.write("%s\n" % (__copyright_h__
% date
.today().year
))
1258 HeaderFd
.write("#ifndef __%s__\n" % FileName
)
1259 HeaderFd
.write("#define __%s__\n\n" % FileName
)
1260 HeaderFd
.write("#include <FspEas.h>\n\n")
1261 HeaderFd
.write("#pragma pack(1)\n\n")
1263 for item
in range(len(UpdRegionCheck
)):
1268 StructStartWithComment
= []
1270 for Line
in TxtBody
:
1272 Match
= re
.match("(typedef struct {)", Line
)
1274 StartIndex
= Index
- 1
1275 Match
= re
.match("#define\s([_A-Z0-9]+)\s*", Line
)
1276 if Match
and (UpdSignatureCheck
[item
] in Match
.group(1) or UpdSignatureCheck
[item
] in Match
.group(1)):
1277 StructStart
.append(Index
- 1)
1278 StructEnd
.append(Index
)
1280 for Line
in TxtBody
:
1282 for Item
in range(len(StructStart
)):
1283 if Index
== StructStart
[Item
]:
1284 Match
= re
.match("^(/\*\*\s*)", Line
)
1286 StructStartWithComment
.append(StructStart
[Item
])
1288 StructStartWithComment
.append(StructStart
[Item
] + 1)
1290 for Line
in TxtBody
:
1292 for Item
in range(len(StructStart
)):
1293 if Index
>= StructStartWithComment
[Item
] and Index
<= StructEnd
[Item
]:
1294 self
.WriteLinesWithoutTailingSpace(HeaderFd
, Line
)
1295 HeaderFd
.write("#pragma pack()\n\n")
1296 HeaderFd
.write("#endif\n")
1301 def WriteBsfStruct (self
, BsfFd
, Item
):
1302 LogExpr
= CLogicalExpression()
1303 if Item
['type'] == "None":
1304 Space
= "gPlatformFspPkgTokenSpaceGuid"
1306 Space
= Item
['space']
1307 Line
= " $%s_%s" % (Space
, Item
['cname'])
1308 Match
= re
.match("\s*\{([x0-9a-fA-F,\s]+)\}\s*", Item
['value'])
1310 DefaultValue
= Match
.group(1).strip()
1312 DefaultValue
= Item
['value'].strip()
1313 if 'bitlength' in Item
:
1314 BsfFd
.write(" %s%s%4d bits $_DEFAULT_ = %s\n" % (Line
, ' ' * (64 - len(Line
)), Item
['bitlength'], DefaultValue
))
1316 BsfFd
.write(" %s%s%4d bytes $_DEFAULT_ = %s\n" % (Line
, ' ' * (64 - len(Line
)), Item
['length'], DefaultValue
))
1318 if Item
['type'] == "Combo":
1319 if not Item
['option'] in self
._BuidinOption
:
1320 OptList
= Item
['option'].split(',')
1321 for Option
in OptList
:
1322 Option
= Option
.strip()
1323 (OpVal
, OpStr
) = Option
.split(':')
1324 test
= LogExpr
.getNumber (OpVal
)
1326 raise Exception("Selection Index '%s' is not a number" % OpVal
)
1327 TmpList
.append((OpVal
, OpStr
))
1330 def WriteBsfOption (self
, BsfFd
, Item
):
1331 PcdName
= Item
['space'] + '_' + Item
['cname']
1333 if Item
['type'] == "Combo":
1334 if Item
['option'] in self
._BuidinOption
:
1335 Options
= self
._BuidinOption
[Item
['option']]
1338 BsfFd
.write(' %s $%s, "%s", &%s,\n' % (Item
['type'], PcdName
, Item
['name'], Options
))
1340 elif Item
['type'].startswith("EditNum"):
1341 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'])
1343 BsfFd
.write(' EditNum $%s, "%s", %s,\n' % (PcdName
, Item
['name'], Match
.group(1)))
1345 elif Item
['type'].startswith("EditText"):
1346 BsfFd
.write(' %s $%s, "%s",\n' % (Item
['type'], PcdName
, Item
['name']))
1348 elif Item
['type'] == "Table":
1349 Columns
= Item
['option'].split(',')
1350 if len(Columns
) != 0:
1351 BsfFd
.write(' %s $%s "%s",' % (Item
['type'], PcdName
, Item
['name']))
1353 Fmt
= Col
.split(':')
1355 raise Exception("Column format '%s' is invalid !" % Fmt
)
1357 Dtype
= int(Fmt
[1].strip())
1359 raise Exception("Column size '%s' is invalid !" % Fmt
[1])
1360 BsfFd
.write('\n Column "%s", %d bytes, %s' % (Fmt
[0].strip(), Dtype
, Fmt
[2].strip()))
1365 HelpLines
= Item
['help'].split('\\n\\r')
1367 for HelpLine
in HelpLines
:
1370 BsfFd
.write(' Help "%s"\n' % (HelpLine
))
1372 BsfFd
.write(' "%s"\n' % (HelpLine
))
1374 BsfFd
.write(' "Valid range: %s ~ %s"\n' % (Match
.group(2), Match
.group(3)))
1376 def GenerateBsfFile (self
, BsfFile
):
1379 self
.Error
= "BSF output file '%s' is invalid" % BsfFile
1384 BsfFd
= open(BsfFile
, "w")
1385 BsfFd
.write("%s\n" % (__copyright_bsf__
% date
.today().year
))
1386 BsfFd
.write("%s\n" % self
._GlobalDataDef
)
1387 BsfFd
.write("StructDef\n")
1389 for Item
in self
._CfgItemList
:
1390 if Item
['find'] != '':
1391 BsfFd
.write('\n Find "%s"\n' % Item
['find'])
1392 NextOffset
= Item
['offset'] + Item
['length']
1393 if Item
['name'] != '':
1394 if NextOffset
!= Item
['offset']:
1395 BsfFd
.write(" Skip %d bytes\n" % (Item
['offset'] - NextOffset
))
1396 if len(Item
['subreg']) > 0:
1397 NextOffset
= Item
['offset']
1398 BitsOffset
= NextOffset
* 8
1399 for SubItem
in Item
['subreg']:
1400 BitsOffset
+= SubItem
['bitlength']
1401 if SubItem
['name'] == '':
1402 if 'bitlength' in SubItem
:
1403 BsfFd
.write(" Skip %d bits\n" % (SubItem
['bitlength']))
1405 BsfFd
.write(" Skip %d bytes\n" % (SubItem
['length']))
1407 Options
= self
.WriteBsfStruct(BsfFd
, SubItem
)
1408 if len(Options
) > 0:
1409 OptionDict
[SubItem
['space']+'_'+SubItem
['cname']] = Options
1411 NextBitsOffset
= (Item
['offset'] + Item
['length']) * 8
1412 if NextBitsOffset
> BitsOffset
:
1413 BitsGap
= NextBitsOffset
- BitsOffset
1414 BitsRemain
= BitsGap
% 8
1416 BsfFd
.write(" Skip %d bits\n" % BitsRemain
)
1417 BitsGap
-= BitsRemain
1418 BytesRemain
= BitsGap
/ 8
1420 BsfFd
.write(" Skip %d bytes\n" % BytesRemain
)
1421 NextOffset
= Item
['offset'] + Item
['length']
1423 NextOffset
= Item
['offset'] + Item
['length']
1424 Options
= self
.WriteBsfStruct(BsfFd
, Item
)
1425 if len(Options
) > 0:
1426 OptionDict
[Item
['space']+'_'+Item
['cname']] = Options
1427 BsfFd
.write("\nEndStruct\n\n")
1429 BsfFd
.write("%s" % self
._BuidinOptionTxt
)
1431 for Each
in OptionDict
:
1432 BsfFd
.write("List &%s\n" % Each
)
1433 for Item
in OptionDict
[Each
]:
1434 BsfFd
.write(' Selection %s , "%s"\n' % (Item
[0], Item
[1]))
1435 BsfFd
.write("EndList\n\n")
1437 BsfFd
.write("BeginInfoBlock\n")
1438 BsfFd
.write(' PPVer "%s"\n' % (self
._CfgBlkDict
['ver']))
1439 BsfFd
.write(' Description "%s"\n' % (self
._CfgBlkDict
['name']))
1440 BsfFd
.write("EndInfoBlock\n\n")
1442 for Each
in self
._CfgPageDict
:
1443 BsfFd
.write('Page "%s"\n' % self
._CfgPageDict
[Each
])
1445 for Item
in self
._CfgItemList
:
1446 if Item
['name'] != '':
1447 if Item
['page'] != Each
:
1449 if len(Item
['subreg']) > 0:
1450 for SubItem
in Item
['subreg']:
1451 if SubItem
['name'] != '':
1452 BsfItems
.append(SubItem
)
1454 BsfItems
.append(Item
)
1456 BsfItems
.sort(key
=lambda x
: x
['order'])
1458 for Item
in BsfItems
:
1459 self
.WriteBsfOption (BsfFd
, Item
)
1460 BsfFd
.write("EndPage\n\n")
1467 print "GenCfgOpt Version 0.53"
1469 print " GenCfgOpt UPDTXT PlatformDscFile BuildFvDir [-D Macros]"
1470 print " GenCfgOpt HEADER PlatformDscFile BuildFvDir InputHFile [-D Macros]"
1471 print " GenCfgOpt GENBSF PlatformDscFile BuildFvDir BsfOutFile [-D Macros]"
1475 # Parse the options and args
1479 GenCfgOpt
= CGenCfgOpt()
1480 while i
< len(sys
.argv
):
1481 if sys
.argv
[i
].strip().lower() == "--pcd":
1482 BuildOptionPcd
.append(sys
.argv
[i
+1])
1485 argc
= len(sys
.argv
)
1490 DscFile
= sys
.argv
[2]
1491 if not os
.path
.exists(DscFile
):
1492 print "ERROR: Cannot open DSC file '%s' !" % DscFile
1497 if sys
.argv
[4][0] == '-':
1500 OutFile
= sys
.argv
[4]
1503 if GenCfgOpt
.ParseMacros(sys
.argv
[Start
:]) != 0:
1504 print "ERROR: Macro parsing failed !"
1508 if not os
.path
.exists(FvDir
):
1511 if GenCfgOpt
.ParseDscFile(DscFile
, FvDir
) != 0:
1512 print "ERROR: %s !" % GenCfgOpt
.Error
1515 if GenCfgOpt
.UpdateSubRegionDefaultValue() != 0:
1516 print "ERROR: %s !" % GenCfgOpt
.Error
1519 if sys
.argv
[1] == "UPDTXT":
1520 Ret
= GenCfgOpt
.CreateSplitUpdTxt(OutFile
)
1522 # No change is detected
1524 print "INFO: %s !" % (GenCfgOpt
.Error
)
1526 print "ERROR: %s !" % (GenCfgOpt
.Error
)
1528 elif sys
.argv
[1] == "HEADER":
1529 if GenCfgOpt
.CreateHeaderFile(OutFile
) != 0:
1530 print "ERROR: %s !" % GenCfgOpt
.Error
1532 elif sys
.argv
[1] == "GENBSF":
1533 if GenCfgOpt
.GenerateBsfFile(OutFile
) != 0:
1534 print "ERROR: %s !" % GenCfgOpt
.Error
1540 print "ERROR: Unknown command '%s' !" % sys
.argv
[1]
1547 if __name__
== '__main__':