From 8e5015c217f0db852165de370742e165d7fd0723 Mon Sep 17 00:00:00 2001 From: "Ma, Maurice" Date: Tue, 2 Jun 2015 14:02:39 +0000 Subject: [PATCH] IntelFspPkg/GenCfgOpt tool add embed structure. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The EMBED command allows you to put one or more UPD data into a specify data structure. You can utilize it as a group of UPD for example. You must specify a start and an end for the specify data structure. Example: !HDR EMBED:{MY_DATA_STRUCT:MyDataStructure:START} gTokenSpaceGuid.Upd1 | 0x0020 | 0x01 | 0x00 gTokenSpaceGuid.Upd2 | 0x0021 | 0x01 | 0x00 !HDR EMBED:{MY_DATA_STRUCT:MyDataStructure:END} gTokenSpaceGuid.UpdN | 0x0022 | 0x01 | 0x00 Result: typedef struct { /** Offset 0x0020 **/ UINT8 Upd1; /** Offset 0x0021 **/ UINT8 Upd2; /** Offset 0x0022 **/ UINT8 UpdN; } MY_DATA_STRUCT; typedef struct _UPD_DATA_REGION { … /** Offset 0x0020 **/ MY_DATA_STRUCT MyDataStruct; … } UPD_DATA_REGION; Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: "Ma, Maurice" Reviewed-by: "Mudusuru, Giri P" Reviewed-by: "Rangarajan, Ravi P" Reviewed-by: "Yao, Jiewen" git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17549 6f19259b-4bc3-4df7-8a09-765794883524 --- IntelFspPkg/Tools/GenCfgOpt.py | 200 ++++++++++++++++++++++----------- 1 file changed, 136 insertions(+), 64 deletions(-) diff --git a/IntelFspPkg/Tools/GenCfgOpt.py b/IntelFspPkg/Tools/GenCfgOpt.py index 224010e694..77eaf6481f 100644 --- a/IntelFspPkg/Tools/GenCfgOpt.py +++ b/IntelFspPkg/Tools/GenCfgOpt.py @@ -305,7 +305,7 @@ EndList """ self._BsfKeyList = ['FIND','NAME','HELP','TYPE','PAGE','OPTION','ORDER'] - self._HdrKeyList = ['HEADER','STRUCT'] + self._HdrKeyList = ['HEADER','STRUCT', 'EMBED'] self._BuidinOption = {'$EN_DIS' : 'EN_DIS'} self._MacroDict = {} @@ -425,7 +425,7 @@ EndList DscFd.close() while len(DscLines): - DscLine = DscLines.pop(0).strip() + DscLine = DscLines.pop(0).strip() Handle = False Match = re.match("^\[(.+)\]", DscLine) if Match is not None: @@ -442,6 +442,7 @@ EndList ConfigDict['name'] = '' ConfigDict['find'] = '' ConfigDict['struct'] = '' + ConfigDict['embed'] = '' ConfigDict['subreg'] = [] IsDefSect = False IsVpdSect = True @@ -455,6 +456,7 @@ EndList ConfigDict['name'] = '' ConfigDict['find'] = '' ConfigDict['struct'] = '' + ConfigDict['embed'] = '' ConfigDict['subreg'] = [] IsDefSect = False IsUpdSect = True @@ -527,7 +529,6 @@ EndList if DscLine.startswith('!'): print("ERROR: Unrecoginized directive for line '%s'" % DscLine) raise SystemExit - if not Handle: continue @@ -560,7 +561,7 @@ EndList for Key in self._BsfKeyList: Match = re.match("(?:^|.+\s+)%s:{(.+?)}" % Key, Remaining) if Match: - if Key in ['HELP', 'OPTION'] and Match.group(1).startswith('+'): + if Key in ['NAME', 'HELP', 'OPTION'] and Match.group(1).startswith('+'): ConfigDict[Key.lower()] += Match.group(1)[1:] else: ConfigDict[Key.lower()] = Match.group(1) @@ -572,7 +573,7 @@ EndList # Check VPD/UPD if IsUpdSect: - 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) + 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) else: Match = re.match("^([_a-zA-Z0-9]+).([_a-zA-Z0-9]+)\s*\|\s*(0x[0-9A-F]+)(?:\s*\|\s*(.+))?", DscLine) if Match: @@ -613,6 +614,7 @@ EndList if ConfigDict['name'] == '': # Clear BSF specific items + ConfigDict['bsfname'] = '' ConfigDict['help'] = '' ConfigDict['type'] = '' ConfigDict['option'] = '' @@ -621,6 +623,7 @@ EndList ConfigDict['name'] = '' ConfigDict['find'] = '' ConfigDict['struct'] = '' + ConfigDict['embed'] = '' ConfigDict['order'] = -1 ConfigDict['subreg'] = [] else: @@ -774,9 +777,10 @@ EndList TxtFd.close() return 0 - def CreateField (self, Item, Name, Length, Offset, Struct, Help): + def CreateField (self, Item, Name, Length, Offset, Struct, BsfName, Help): PosName = 28 PosComment = 30 + NameLine='' HelpLine='' IsArray = False @@ -786,7 +790,7 @@ EndList IsArray = True Type = "UINT8" - if Item['value'].startswith('{'): + if Item and Item['value'].startswith('{'): Type = "UINT8" IsArray = True @@ -807,18 +811,57 @@ EndList else: Space1 = 1 - if len(Name) < PosComment: - Space2 = PosComment - len(Name) - else: - Space2 = 1 - if Help != '': - HelpLine=" %s \n" % Help + if BsfName != '': + NameLine=" %s\n" % BsfName - return "/**Offset 0x%04X \n%s**/\n %s%s%s;%s\n" % (Offset, HelpLine, Type, ' ' * Space1, Name, ' ' * Space2) + if Help != '': + HelpLine=" %s\n" % Help + if Offset is None: + OffsetStr = '????' + else: + OffsetStr = '0x%04X' % Offset + + return "/** Offset %s\n%s%s**/\n %s%s%s;\n" % (OffsetStr, NameLine, HelpLine, Type, ' ' * Space1, Name,) + + def PostProcessBody (self, TextBody): + NewTextBody = [] + OldTextBody = [] + IncludeLine = False + StructName = '' + VariableName = '' + for Line in TextBody: + Match = re.match("^/\*\sEMBED_STRUCT:(\w+):(\w+):(START|END)\s\*/\s([\s\S]*)", Line) + if Match: + Line = Match.group(4) + + if Match and Match.group(3) == 'START': + NewTextBody.append ('typedef struct {\n') + StructName = Match.group(1) + VariableName = Match.group(2) + MatchOffset = re.search('/\*\*\sOffset\s0x([a-fA-F0-9]+)', Line) + if MatchOffset: + Offset = int(MatchOffset.group(1), 16) + else: + Offset = None + Line + IncludeLine = True + OldTextBody.append (self.CreateField (None, VariableName, 0, Offset, StructName, '', '')) + if IncludeLine: + NewTextBody.append (Line) + else: + OldTextBody.append (Line) + + if Match and Match.group(3) == 'END': + if (StructName != Match.group(1)) or (VariableName != Match.group(2)): + print "Unmatched struct name '%s' and '%s' !" % (StructName, Match.group(1)) + else: + NewTextBody.append ('} %s;\n\n' % StructName) + IncludeLine = False + NewTextBody.extend(OldTextBody) + return NewTextBody def CreateHeaderFile (self, InputHeaderFile, IsInternal): - Error = 0 FvDir = self._FvDir if IsInternal: @@ -845,51 +888,19 @@ EndList self.Error = "No DSC or input header file is changed, skip the header file generating" return 256 - HeaderFd = open(HeaderFile, "w") - FileBase = os.path.basename(HeaderFile) - FileName = FileBase.replace(".", "_").upper() - HeaderFd.write("%s\n" % (__copyright_h__ % date.today().year)) - HeaderFd.write("#ifndef __%s__\n" % FileName) - HeaderFd.write("#define __%s__\n\n" % FileName) - HeaderFd.write("#pragma pack(1)\n\n") - - if InputHeaderFile != '': - if not os.path.exists(InputHeaderFile): - self.Error = "Input header file '%s' does not exist" % InputHeaderFile - return 2 - - InFd = open(InputHeaderFile, "r") - IncLines = InFd.readlines() - InFd.close() - - Export = False - for Line in IncLines: - Match = re.search ("!EXPORT\s+EXTERNAL_BOOTLOADER_STRUCT_(BEGIN|END)\s+", Line) - if Match: - if Match.group(1) == "BEGIN": - Export = True - continue - else: - Export = False - continue - if Export: - HeaderFd.write(Line) - HeaderFd.write("\n\n") - + TxtBody = [] for Region in ['UPD', 'VPD']: # Write PcdVpdRegionSign and PcdImageRevision if Region[0] == 'V': if 'VPD_TOOL_GUID' not in self._MacroDict: self.Error = "VPD_TOOL_GUID definition is missing in DSC file" - Error = 1 - break + return 1 BinFile = os.path.join(FvDir, self._MacroDict['VPD_TOOL_GUID'] + ".bin") if not os.path.exists(BinFile): self.Error = "VPD binary file '%s' does not exist" % BinFile - Error = 2 - break + return 2 BinFd = open(BinFile, "rb") IdStr = BinFd.read(0x08) @@ -897,10 +908,10 @@ EndList ImageRev = struct.unpack(' 0: HelpLines = Item['help'].split('\\n\\r') FirstLine = True @@ -1112,7 +1184,7 @@ def Main(): OutFile = sys.argv[4] Start = 5 if GenCfgOpt.ParseMacros(sys.argv[Start:]) != 0: - print "ERROR: %s !" % GenCfgOpt.Error + print "ERROR: Macro parsing failed !" return 3 FvDir = sys.argv[3] -- 2.39.2