]>
git.proxmox.com Git - mirror_edk2.git/blob - IntelFspPkg/Tools/GenCfgOpt.py
3 # Copyright (c) 2014, 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 ] == '!' :
257 self
. Error
= "Invalid DscLine ' %s '" % DscLine
261 if reduce ( lambda x
, y
: x
and y
, IfStack
):
268 #DEFINE UPD_TOOL_GUID = 8C3D856A-9BE6-468E-850A-24F7A8D38E09
269 Match
= re
. match ( "^\s*(?:DEFINE\s+)*(\w+)\s*=\s*([-\w]+)" , DscLine
)
271 self
._ MacroDict
[ Match
. group ( 1 )] = Match
. group ( 2 )
273 Match
= re
. match ( "^\s*#\s+!(BSF|HDR)\s+(.+)" , DscLine
)
275 Remaining
= Match
. group ( 2 )
276 if Match
. group ( 1 ) == 'BSF' :
277 Match
= re
. match ( "(?:^|.+\s+)PAGES:{(.+?)}" , Remaining
)
279 # !BSF PAGES:{HSW:"Haswell System Agent", LPT:"Lynx Point PCH"}
280 PageList
= Match
. group ( 1 ). split ( ',' )
281 for Page
in PageList
:
283 Match
= re
. match ( "(\w+): \" (.+) \" " , Page
)
284 self
._ CfgPageDict
[ Match
. group ( 1 )] = Match
. group ( 2 )
286 Match
= re
. match ( "(?:^|.+\s+)BLOCK:{NAME: \" (.+) \" \s*,\s*VER: \" (.+) \" \s*}" , Remaining
)
288 self
._ CfgBlkDict
[ 'name' ] = Match
. group ( 1 )
289 self
._ CfgBlkDict
[ 'ver' ] = Match
. group ( 2 )
291 for Key
in self
._ BsfKeyList
:
292 Match
= re
. match ( "(?:^|.+\s+) %s :{(.+?)}" % Key
, Remaining
)
294 if Key
in [ 'HELP' , 'OPTION' ] and Match
. group ( 1 ). startswith ( '+' ):
295 ConfigDict
[ Key
. lower ()] += Match
. group ( 1 )[ 1 :]
297 ConfigDict
[ Key
. lower ()] = Match
. group ( 1 )
299 for Key
in self
._ HdrKeyList
:
300 Match
= re
. match ( "(?:^|.+\s+) %s :{(.+?)}" % Key
, Remaining
)
302 ConfigDict
[ Key
. lower ()] = Match
. group ( 1 )
306 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
)
308 Match
= re
. match ( "^([_a-zA-Z0-9]+).([_a-zA-Z0-9]+)\s*\|\s*(0x[0-9A-F]+)(?:\s*\|\s*(.+))?" , DscLine
)
310 ConfigDict
[ 'space' ] = Match
. group ( 1 )
311 ConfigDict
[ 'cname' ] = Match
. group ( 2 )
312 ConfigDict
[ 'offset' ] = int ( Match
. group ( 3 ), 16 )
313 if ConfigDict
[ 'order' ] == - 1 :
314 ConfigDict
[ 'order' ] = ConfigDict
[ 'offset' ] << 8
316 ( Major
, Minor
) = ConfigDict
[ 'order' ]. split ( '.' )
317 ConfigDict
[ 'order' ] = ( int ( Major
, 16 ) << 8 ) + int ( Minor
, 16 )
319 Value
= Match
. group ( 5 ). strip ()
320 if Match
. group ( 4 ). startswith ( "0x" ):
321 Length
= int ( Match
. group ( 4 ), 16 )
323 Length
= int ( Match
. group ( 4 ))
325 Value
= Match
. group ( 4 )
328 Value
= Value
. strip ()
330 Match
= re
. match ( "^.+\s*\|\s*(.+)" , Value
)
332 Value
= Match
. group ( 1 )
335 ConfigDict
[ 'length' ] = Length
336 Match
= re
. match ( "\$\((\w+)\)" , Value
)
338 if Match
. group ( 1 ) in self
._ MacroDict
:
339 Value
= self
._ MacroDict
[ Match
. group ( 1 )]
340 ConfigDict
[ 'value' ] = Value
341 if ConfigDict
[ 'name' ] == '' :
342 # Clear BSF specific items
343 ConfigDict
[ 'help' ] = ''
344 ConfigDict
[ 'type' ] = ''
345 ConfigDict
[ 'option' ] = ''
347 self
._ CfgItemList
. append ( ConfigDict
. copy ())
348 ConfigDict
[ 'name' ] = ''
349 ConfigDict
[ 'find' ] = ''
350 ConfigDict
[ 'struct' ] = ''
351 ConfigDict
[ 'order' ] = - 1
352 ConfigDict
[ 'subreg' ] = []
354 # It could be a virtual item as below
355 # !BSF FIELD:{1:SerialDebugPortAddress0}
356 Match
= re
. match ( "^\s*#\s+!BSF\s+FIELD:{(.+):(\d+)}" , DscLine
)
358 SubCfgDict
= ConfigDict
359 SubCfgDict
[ 'cname' ] = Match
. group ( 1 )
360 SubCfgDict
[ 'length' ] = int ( Match
. group ( 2 ))
361 if SubCfgDict
[ 'length' ] > 0 :
362 LastItem
= self
._ CfgItemList
[- 1 ]
363 if len ( LastItem
[ 'subreg' ]) == 0 :
366 SubOffset
+= LastItem
[ 'subreg' ][- 1 ][ 'length' ]
367 SubCfgDict
[ 'offset' ] = SubOffset
368 LastItem
[ 'subreg' ]. append ( SubCfgDict
. copy ())
369 ConfigDict
[ 'name' ] = ''
372 def UpdateSubRegionDefaultValue ( self
):
374 for Item
in self
._ CfgItemList
:
375 if len ( Item
[ 'subreg' ]) == 0 :
378 if Item
[ 'value' ][ 0 ] == '{' :
379 binlist
= Item
[ 'value' ][ 1 :- 1 ]. split ( ',' )
382 if each
. startswith ( '0x' ):
383 value
= int ( each
, 16 )
386 bytearray
. append ( value
)
388 if Item
[ 'value' ]. startswith ( '0x' ):
389 value
= int ( Item
[ 'value' ], 16 )
391 value
= int ( Item
[ 'value' ])
393 while idx
< Item
[ 'length' ]:
394 bytearray
. append ( value
& 0xFF )
397 for SubItem
in Item
[ 'subreg' ]:
398 if SubItem
[ 'length' ] in ( 1 , 2 , 4 , 8 ):
399 valuelist
= [ b
for b
in bytearray
[ SubItem
[ 'offset' ]: SubItem
[ 'offset' ]+ SubItem
[ 'length' ]]]
401 valuestr
= "" . join ( ' %0 2X' % b
for b
in valuelist
)
402 SubItem
[ 'value' ] = '0x %s ' % valuestr
404 valuestr
= "," . join ( '0x %0 2X' % b
for b
in bytearray
[ SubItem
[ 'offset' ]: SubItem
[ 'offset' ]+ SubItem
[ 'length' ]])
405 SubItem
[ 'value' ] = '{ %s }' % valuestr
408 def UpdateVpdSizeField ( self
):
411 if 'VPD_TOOL_GUID' not in self
._ MacroDict
:
412 self
. Error
= "VPD_TOOL_GUID definition is missing in DSC file"
415 VpdMapFile
= os
. path
. join ( FvDir
, self
._ MacroDict
[ 'VPD_TOOL_GUID' ] + '.map' )
416 if not os
. path
. exists ( VpdMapFile
):
417 self
. Error
= "VPD MAP file ' %s ' does not exist" % VpdMapFile
420 MapFd
= open ( VpdMapFile
, "r" )
421 MapLines
= MapFd
. readlines ()
426 for MapLine
in MapLines
:
427 #gPlatformFspPkgTokenSpaceGuid.PcdVpdRegionSign | DEFAULT | 0x0000 | 8 | 0x534450565F425346
428 #gPlatformFspPkgTokenSpaceGuid.PcdVpdRegionSign | 0x0000 | 8 | 0x534450565F425346
429 #gPlatformFspPkgTokenSpaceGuid.PcdTest | 0x0008 | 5 | {0x01,0x02,0x03,0x04,0x05}
430 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
)
432 Space
= Match
. group ( 1 )
433 Name
= Match
. group ( 2 )
434 if ( self
._ MapVer
== 0 ) and ( Match
. group ( 3 ) != None ):
436 Offset
= int ( Match
. group ( 4 ), 16 )
437 if Match
. group ( 5 ). startswith ( "0x" ):
438 Length
= int ( Match
. group ( 5 ), 16 )
440 Length
= int ( Match
. group ( 5 ))
441 PcdDict
[ "len" ] = Length
442 PcdDict
[ "value" ] = Match
. group ( 6 )
443 VpdDict
[ Space
+ '.' + Name
] = dict ( PcdDict
)
445 for Item
in self
._ CfgItemList
:
446 if Item
[ 'value' ] == '' :
447 Item
[ 'value' ] = VpdDict
[ Item
[ 'space' ]+ '.' + Item
[ 'cname' ]][ 'value' ]
448 if Item
[ 'length' ] == - 1 :
449 Item
[ 'length' ] = VpdDict
[ Item
[ 'space' ]+ '.' + Item
[ 'cname' ]][ 'len' ]
450 if Item
[ 'struct' ] != '' :
451 Type
= Item
[ 'struct' ]. strip ()
452 if Type
. endswith ( '*' ) and ( Item
[ 'length' ] != 4 ):
453 self
. Error
= "Struct pointer ' %s ' has invalid size" % Type
458 def CreateUpdTxtFile ( self
, UpdTxtFile
):
460 if 'UPD_TOOL_GUID' not in self
._ MacroDict
:
461 self
. Error
= "UPD_TOOL_GUID definition is missing in DSC file"
465 UpdTxtFile
= os
. path
. join ( FvDir
, self
._ MacroDict
[ 'UPD_TOOL_GUID' ] + '.txt' )
468 if not os
. path
. exists ( UpdTxtFile
):
471 DscTime
= os
. path
. getmtime ( self
._ DscFile
)
472 TxtTime
= os
. path
. getmtime ( UpdTxtFile
)
473 if DscTime
> TxtTime
:
477 # DSC has not been modified yet
478 # So don't have to re-generate other files
479 self
. Error
= 'No DSC file change, skip to create UPD TXT file'
482 TxtFd
= open ( UpdTxtFile
, "w" )
483 TxtFd
. write ( " %s \n " % ( __copyright_txt__
% date
. today (). year
))
487 if self
._ MapVer
== 1 :
491 for Item
in self
._ CfgItemList
:
492 if Item
[ 'region' ] != 'UPD' :
494 Offset
= Item
[ 'offset' ]
495 if NextOffset
< Offset
:
497 TxtFd
. write ( " %s .UnusedUpdSpace %d | %s0x%0 4X|0x %0 4X| {0} \n " % ( Item
[ 'space' ], SpaceIdx
, Default
, NextOffset
, Offset
- NextOffset
))
498 SpaceIdx
= SpaceIdx
+ 1
499 NextOffset
= Offset
+ Item
[ 'length' ]
500 TxtFd
. write ( " %s . %s | %s0x%0 4X| %s | %s \n " % ( Item
[ 'space' ], Item
[ 'cname' ], Default
, Item
[ 'offset' ], Item
[ 'length' ], Item
[ 'value' ]))
504 def CreateField ( self
, Name
, Length
, Offset
, Struct
):
526 Name
= Name
+ '[ %d ]' % Length
528 if len ( Type
) < PosName
:
529 Space1
= PosName
- len ( Type
)
533 if len ( Name
) < PosComment
:
534 Space2
= PosComment
- len ( Name
)
538 return " %s%s%s ; %s /* Offset 0x %0 4X */ \n " % ( Type
, ' ' * Space1
, Name
, ' ' * Space2
, Offset
)
541 def CreateHeaderFile ( self
, InputHeaderFile
, IsInternal
):
546 HeaderFile
= os
. path
. join ( FvDir
, 'VpdHeader.h' )
548 HeaderFile
= os
. path
. join ( FvDir
, 'fsp_vpd.h' )
550 # Check if header needs to be recreated
553 if not os
. path
. exists ( HeaderFile
):
556 DscTime
= os
. path
. getmtime ( self
._ DscFile
)
557 HeadTime
= os
. path
. getmtime ( HeaderFile
)
558 if not os
. path
. exists ( InputHeaderFile
):
561 InpTime
= os
. path
. getmtime ( InputHeaderFile
)
562 if DscTime
> HeadTime
or InpTime
> HeadTime
:
566 self
. Error
= "No DSC or input header file is changed, skip the header file generating"
569 HeaderFd
= open ( HeaderFile
, "w" )
570 FileBase
= os
. path
. basename ( HeaderFile
)
571 FileName
= FileBase
. replace ( "." , "_" ). upper ()
572 HeaderFd
. write ( " %s \n " % ( __copyright_h__
% date
. today (). year
))
573 HeaderFd
. write ( "#ifndef __ %s __ \n " % FileName
)
574 HeaderFd
. write ( "#define __ %s __ \n\n " % FileName
)
575 HeaderFd
. write ( "#pragma pack(1) \n\n " )
577 if InputHeaderFile
!= '' :
578 if not os
. path
. exists ( InputHeaderFile
):
579 self
. Error
= "Input header file ' %s ' does not exist" % InputHeaderFile
582 InFd
= open ( InputHeaderFile
, "r" )
583 IncLines
= InFd
. readlines ()
587 for Line
in IncLines
:
588 Match
= re
. search ( "!EXPORT\s+EXTERNAL_BOOTLOADER_STRUCT_(BEGIN|END)\s+" , Line
)
590 if Match
. group ( 1 ) == "BEGIN" :
598 HeaderFd
. write ( " \n\n " )
600 for Region
in [ 'UPD' , 'VPD' ]:
602 # Write PcdVpdRegionSign and PcdImageRevision
604 if 'VPD_TOOL_GUID' not in self
._ MacroDict
:
605 self
. Error
= "VPD_TOOL_GUID definition is missing in DSC file"
609 BinFile
= os
. path
. join ( FvDir
, self
._ MacroDict
[ 'VPD_TOOL_GUID' ] + ".bin" )
610 if not os
. path
. exists ( BinFile
):
611 self
. Error
= "VPD binary file ' %s ' does not exist" % BinFile
615 BinFd
= open ( BinFile
, "rb" )
616 IdStr
= BinFd
. read ( 0x08 )
617 ImageId
= struct
. unpack ( 'Q' , IdStr
)
618 ImageRev
= struct
. unpack ( 'L' , BinFd
. read ( 0x04 ))
621 HeaderFd
. write ( "#define VPD_IMAGE_ID 0x %0 16X /* ' %s ' */ \n " % ( ImageId
[ 0 ], IdStr
))
622 HeaderFd
. write ( "#define VPD_IMAGE_REV 0x %0 8X \n\n " % ImageRev
[ 0 ])
624 HeaderFd
. write ( "typedef struct _" + Region
[ 0 ] + "PD_DATA_REGION { \n " )
633 for Item
in self
._ CfgItemList
:
634 if Item
[ 'region' ] != Region
:
637 NextVisible
= LastVisible
639 if LastVisible
and ( Item
[ 'header' ] == 'OFF' ):
641 ResvOffset
= Item
[ 'offset' ]
642 elif ( not LastVisible
) and Item
[ 'header' ] == 'ON' :
644 Name
= "Reserved" + Region
[ 0 ] + "pdSpace %d " % ResvIdx
645 ResvIdx
= ResvIdx
+ 1
646 HeaderFd
. write ( self
. CreateField ( Name
, Item
[ "offset" ] - ResvOffset
, ResvOffset
, '' ))
648 if Offset
< Item
[ "offset" ]:
649 if IsInternal
or LastVisible
:
650 Name
= "Unused" + Region
[ 0 ] + "pdSpace %d " % SpaceIdx
651 LineBuffer
. append ( self
. CreateField ( Name
, Item
[ "offset" ] - Offset
, Offset
, '' ))
652 SpaceIdx
= SpaceIdx
+ 1
653 Offset
= Item
[ "offset" ]
655 if Offset
!= Item
[ "offset" ]:
656 print "Unsorted offset 0x %0 4X \n " % Item
[ "offset" ]
660 LastVisible
= NextVisible
662 Offset
= Offset
+ Item
[ "length" ]
663 if IsInternal
or LastVisible
:
664 for Each
in LineBuffer
:
665 HeaderFd
. write ( Each
)
667 HeaderFd
. write ( self
. CreateField ( Item
[ "cname" ], Item
[ "length" ], Item
[ "offset" ], Item
[ 'struct' ]))
669 HeaderFd
. write ( "} " + Region
[ 0 ] + "PD_DATA_REGION; \n\n " )
670 HeaderFd
. write ( "#pragma pack() \n\n " )
671 HeaderFd
. write ( "#endif \n " )
676 def WriteBsfStruct ( self
, BsfFd
, Item
):
677 if Item
[ 'type' ] == "None" :
678 Space
= "gPlatformFspPkgTokenSpaceGuid"
680 Space
= Item
[ 'space' ]
681 Line
= " $ %s _ %s " % ( Space
, Item
[ 'cname' ])
682 Match
= re
. match ( "\s*\{([x0-9a-fA-F,\s]+)\}\s*" , Item
[ 'value' ])
684 DefaultValue
= Match
. group ( 1 ). strip ()
686 DefaultValue
= Item
[ 'value' ]. strip ()
687 BsfFd
. write ( " %s%s% 4d bytes $_DEFAULT_ = %s \n " % ( Line
, ' ' * ( 64 - len ( Line
)), Item
[ 'length' ], DefaultValue
))
689 if Item
[ 'type' ] == "Combo" :
690 if not Item
[ 'option' ] in self
._ BuidinOption
:
691 OptList
= Item
[ 'option' ]. split ( ',' )
692 for Option
in OptList
:
693 Option
= Option
. strip ()
694 ( OpVal
, OpStr
) = Option
. split ( ':' )
695 TmpList
. append (( OpVal
, OpStr
))
698 def WriteBsfOption ( self
, BsfFd
, Item
):
699 PcdName
= Item
[ 'space' ] + '_' + Item
[ 'cname' ]
701 if Item
[ 'type' ] == "Combo" :
702 if Item
[ 'option' ] in self
._ BuidinOption
:
703 Options
= self
._ BuidinOption
[ Item
[ 'option' ]]
706 BsfFd
. write ( ' %s $ %s , " %s ", & %s , \n ' % ( Item
[ 'type' ], PcdName
, Item
[ 'name' ], Options
));
708 elif Item
[ 'type' ]. startswith ( "EditNum" ):
709 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' ])
711 BsfFd
. write ( ' EditNum $ %s , " %s ", %s , \n ' % ( PcdName
, Item
[ 'name' ], Match
. group ( 1 )));
713 elif Item
[ 'type' ]. startswith ( "EditText" ):
714 BsfFd
. write ( ' %s $ %s , " %s ", \n ' % ( Item
[ 'type' ], PcdName
, Item
[ 'name' ]));
718 HelpLines
= Item
[ 'help' ]. split ( ' \\ n \\ r' )
720 for HelpLine
in HelpLines
:
723 BsfFd
. write ( ' Help " %s " \n ' % ( HelpLine
));
725 BsfFd
. write ( ' " %s " \n ' % ( HelpLine
));
727 BsfFd
. write ( ' "Valid range: %s ~ %s " \n ' % ( Match
. group ( 2 ), Match
. group ( 3 )));
729 def GenerateBsfFile ( self
, BsfFile
):
732 self
. Error
= "BSF output file ' %s ' is invalid" % BsfFile
737 BsfFd
= open ( BsfFile
, "w" )
738 BsfFd
. write ( " %s \n " % ( __copyright_bsf__
% date
. today (). year
))
739 BsfFd
. write ( " %s \n " % self
._ GlobalDataDef
);
740 BsfFd
. write ( "StructDef \n " )
742 for Item
in self
._ CfgItemList
:
743 if Item
[ 'find' ] != '' :
744 BsfFd
. write ( ' \n Find " %s " \n ' % Item
[ 'find' ])
745 NextOffset
= Item
[ 'offset' ] + Item
[ 'length' ]
746 if Item
[ 'name' ] != '' :
747 if NextOffset
!= Item
[ 'offset' ]:
748 BsfFd
. write ( " Skip %d bytes \n " % ( Item
[ 'offset' ] - NextOffset
))
749 if len ( Item
[ 'subreg' ]) > 0 :
750 NextOffset
= Item
[ 'offset' ]
751 for SubItem
in Item
[ 'subreg' ]:
752 NextOffset
+= SubItem
[ 'length' ]
753 if SubItem
[ 'name' ] == '' :
754 BsfFd
. write ( " Skip %d bytes \n " % ( SubItem
[ 'length' ]))
756 Options
= self
. WriteBsfStruct ( BsfFd
, SubItem
)
758 OptionDict
[ SubItem
[ 'space' ]+ '_' + SubItem
[ 'cname' ]] = Options
759 if ( Item
[ 'offset' ] + Item
[ 'length' ]) < NextOffset
:
760 self
. Error
= "BSF sub region ' %s ' length does not match" % ( Item
[ 'space' ]+ '.' + Item
[ 'cname' ])
763 NextOffset
= Item
[ 'offset' ] + Item
[ 'length' ]
764 Options
= self
. WriteBsfStruct ( BsfFd
, Item
)
766 OptionDict
[ Item
[ 'space' ]+ '_' + Item
[ 'cname' ]] = Options
767 BsfFd
. write ( " \n EndStruct \n\n " )
769 BsfFd
. write ( " %s " % self
._ BuidinOptionTxt
);
771 for Each
in OptionDict
:
772 BsfFd
. write ( "List & %s \n " % Each
);
773 for Item
in OptionDict
[ Each
]:
774 BsfFd
. write ( ' Selection %s , " %s " \n ' % ( Item
[ 0 ], Item
[ 1 ]));
775 BsfFd
. write ( "EndList \n\n " );
777 BsfFd
. write ( "BeginInfoBlock \n " );
778 BsfFd
. write ( ' PPVer " %s " \n ' % ( self
._ CfgBlkDict
[ 'ver' ]));
779 BsfFd
. write ( ' Description " %s " \n ' % ( self
._ CfgBlkDict
[ 'name' ]));
780 BsfFd
. write ( "EndInfoBlock \n\n " );
782 for Each
in self
._ CfgPageDict
:
783 BsfFd
. write ( 'Page " %s " \n ' % self
._ CfgPageDict
[ Each
]);
785 for Item
in self
._ CfgItemList
:
786 if Item
[ 'name' ] != '' :
787 if Item
[ 'page' ] != Each
:
789 if len ( Item
[ 'subreg' ]) > 0 :
790 for SubItem
in Item
[ 'subreg' ]:
791 if SubItem
[ 'name' ] != '' :
792 BsfItems
. append ( SubItem
)
794 BsfItems
. append ( Item
)
796 BsfItems
. sort ( key
= lambda x
: x
[ 'order' ])
798 for Item
in BsfItems
:
799 self
. WriteBsfOption ( BsfFd
, Item
)
800 BsfFd
. write ( "EndPage \n\n " );
807 print "GenCfgOpt Version 0.50"
809 print " GenCfgOpt UPDTXT PlatformDscFile BuildFvDir [TxtOutFile] [-D Macros]"
810 print " GenCfgOpt HEADER PlatformDscFile BuildFvDir [InputHFile] [-D Macros]"
811 print " GenCfgOpt GENBSF PlatformDscFile BuildFvDir BsfOutFile [-D Macros]"
815 # Parse the options and args
817 GenCfgOpt
= CGenCfgOpt ()
823 DscFile
= sys
. argv
[ 2 ]
824 if not os
. path
. exists ( DscFile
):
825 print "ERROR: Cannot open DSC file ' %s ' !" % DscFile
830 if sys
. argv
[ 4 ][ 0 ] == '-' :
833 OutFile
= sys
. argv
[ 4 ]
835 if GenCfgOpt
. ParseMacros ( sys
. argv
[ Start
:]) != 0 :
836 print "ERROR: %s !" % GenCfgOpt
. Error
840 if not os
. path
. isdir ( FvDir
):
841 print "ERROR: FV folder ' %s ' is invalid !" % FvDir
844 if GenCfgOpt
. ParseDscFile ( DscFile
, FvDir
) != 0 :
845 print "ERROR: %s !" % GenCfgOpt
. Error
849 if GenCfgOpt
. UpdateVpdSizeField () != 0 :
850 print "ERROR: %s !" % GenCfgOpt
. Error
853 if GenCfgOpt
. UpdateSubRegionDefaultValue () != 0 :
854 print "ERROR: %s !" % GenCfgOpt
. Error
857 if sys
. argv
[ 1 ] == "UPDTXT" :
858 Ret
= GenCfgOpt
. CreateUpdTxtFile ( OutFile
)
860 # No change is detected
862 print "INFO: %s !" % ( GenCfgOpt
. Error
)
864 print "ERROR: %s !" % ( GenCfgOpt
. Error
)
866 elif sys
. argv
[ 1 ] == "HEADER" :
867 Ret
= GenCfgOpt
. CreateHeaderFile ( OutFile
, True )
869 # No change is detected
871 print "INFO: %s !" % ( GenCfgOpt
. Error
)
873 print "ERROR: %s !" % ( GenCfgOpt
. Error
)
875 if GenCfgOpt
. CreateHeaderFile ( OutFile
, False ) != 0 :
876 print "ERROR: %s !" % GenCfgOpt
. Error
878 elif sys
. argv
[ 1 ] == "GENBSF" :
879 if GenCfgOpt
. GenerateBsfFile ( OutFile
) != 0 :
880 print "ERROR: %s !" % GenCfgOpt
. Error
886 print "ERROR: Unknown command ' %s ' !" % sys
. argv
[ 1 ]
893 if __name__
== '__main__' :