## @file\r
# parse FDF file\r
#\r
-# Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>\r
# Copyright (c) 2015, Hewlett Packard Enterprise Development, L.P.<BR>\r
#\r
# This program and the accompanying materials\r
\r
from Common.Misc import tdict\r
\r
-import re\r
import Common.LongFilePathOs as os\r
from Common.LongFilePathSupport import OpenLongFilePath as open\r
\r
if Profile.IsLineInFile(Line):\r
return Profile.GetLineInFile(Line)\r
elif Line >= Profile.InsertStartLineNumber and Profile.Level == 1:\r
- InsertedLines += Profile.GetTotalLines()\r
+ InsertedLines += Profile.GetTotalLines()\r
\r
return (File, Line - InsertedLines)\r
\r
TotalLines = self.InsertAdjust + len(self.FileLinesList)\r
\r
for Profile in self.IncludeFileList:\r
- TotalLines += Profile.GetTotalLines()\r
+ TotalLines += Profile.GetTotalLines()\r
\r
return TotalLines\r
\r
% (FileLineTuple[1], self.CurrentOffsetWithinLine + 1, self.Profile.FileLinesList[self.CurrentLineNumber - 1][self.CurrentOffsetWithinLine :].rstrip('\n').rstrip('\r'))\r
raise\r
\r
+ ## SectionParser() method\r
+ #\r
+ # Parse the file section info\r
+ # Exception will be raised if syntax error found\r
+ #\r
+ # @param self The object pointer\r
+ # @param section The section string\r
+\r
+ def SectionParser(self, section):\r
+ S = section.upper()\r
+ if not S.startswith("[DEFINES") and not S.startswith("[FD.") and not S.startswith("[FV.") and not S.startswith("[CAPSULE.") \\r
+ and not S.startswith("[VTF.") and not S.startswith("[RULE.") and not S.startswith("[OPTIONROM.") and not S.startswith('[FMPPAYLOAD.'):\r
+ raise Warning("Unknown section or section appear sequence error (The correct sequence should be [DEFINES], [FD.], [FV.], [Capsule.], [VTF.], [Rule.], [OptionRom.], [FMPPAYLOAD.])", self.FileName, self.CurrentLineNumber)\r
+\r
## __GetDefines() method\r
#\r
# Get Defines section contents and store its data into AllMacrosList\r
\r
S = self.__Token.upper()\r
if S.startswith("[") and not S.startswith("[DEFINES"):\r
- if not S.startswith("[FD.") and not S.startswith("[FV.") and not S.startswith("[CAPSULE.") \\r
- and not S.startswith("[VTF.") and not S.startswith("[RULE.") and not S.startswith("[OPTIONROM."):\r
- raise Warning("Unknown section or section appear sequence error (The correct sequence should be [DEFINES], [FD.], [FV.], [Capsule.], [VTF.], [Rule.], [OptionRom.])", self.FileName, self.CurrentLineNumber)\r
+ self.SectionParser(S)\r
self.__UndoToken()\r
return False\r
\r
\r
S = self.__Token.upper()\r
if S.startswith("[") and not S.startswith("[FV."):\r
- if not S.startswith('[FMPPAYLOAD.') and not S.startswith("[CAPSULE.") \\r
- and not S.startswith("[VTF.") and not S.startswith("[RULE.") and not S.startswith("[OPTIONROM."):\r
- raise Warning("Unknown section or section appear sequence error (The correct sequence should be [FD.], [FV.], [Capsule.], [VTF.], [Rule.], [OptionRom.])", self.FileName, self.CurrentLineNumber)\r
+ self.SectionParser(S)\r
self.__UndoToken()\r
return False\r
\r
elif self.__Token in ("DEFINE", "APRIORI", "SECTION"):\r
self.__UndoToken()\r
self.__GetSectionData( FfsFileObj, MacroDict)\r
+\r
+ elif hasattr(FfsFileObj, 'FvFileType') and FfsFileObj.FvFileType == 'RAW':\r
+ self.__UndoToken()\r
+ self.__GetRAWData(FfsFileObj, MacroDict)\r
+\r
else:\r
FfsFileObj.CurrentLineNum = self.CurrentLineNumber\r
FfsFileObj.CurrentLineContent = self.__CurrentLine()\r
if not self.__IsToken( "}"):\r
raise Warning("expected '}'", self.FileName, self.CurrentLineNumber)\r
\r
+ ## __GetRAWData() method\r
+ #\r
+ # Get RAW data for FILE statement\r
+ #\r
+ # @param self The object pointer\r
+ # @param FfsFileObj for whom section is got\r
+ # @param MacroDict dictionary used to replace macro\r
+ #\r
+ def __GetRAWData(self, FfsFileObj, MacroDict = {}):\r
+ FfsFileObj.FileName = []\r
+ FfsFileObj.SubAlignment = []\r
+ while True:\r
+ AlignValue = None\r
+ if self.__GetAlignment():\r
+ if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K"):\r
+ raise Warning("Incorrect alignment '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)\r
+ AlignValue = self.__Token\r
+ if not self.__GetNextToken():\r
+ raise Warning("expected Filename value", self.FileName, self.CurrentLineNumber)\r
+\r
+ FileName = self.__Token.replace('$(SPACE)', ' ')\r
+ if FileName == '}':\r
+ self.__UndoToken()\r
+ raise Warning("expected Filename value", self.FileName, self.CurrentLineNumber)\r
+\r
+ self.__VerifyFile(FileName)\r
+ File = PathClass(NormPath(FileName), GenFdsGlobalVariable.WorkSpaceDir)\r
+ FfsFileObj.FileName.append(File.Path)\r
+ FfsFileObj.SubAlignment.append(AlignValue)\r
+\r
+ if self.__IsToken( "}"):\r
+ self.__UndoToken()\r
+ break\r
+\r
+ if len(FfsFileObj.SubAlignment) == 1:\r
+ FfsFileObj.SubAlignment = FfsFileObj.SubAlignment[0]\r
+ if len(FfsFileObj.FileName) == 1:\r
+ FfsFileObj.FileName = FfsFileObj.FileName[0]\r
+\r
## __GetFileOpts() method\r
#\r
# Get options for FILE statement\r
if not self.__GetNextToken():\r
return False\r
S = self.__Token.upper()\r
- if not S.startswith("[FMPPAYLOAD."):\r
- if not S.startswith("[CAPSULE.") and not S.startswith("[VTF.") and not S.startswith("[RULE.") and not S.startswith("[OPTIONROM."):\r
- raise Warning("Unknown section or section appear sequence error (The correct sequence should be [FD.], [FV.], [FmpPayload.], [Capsule.], [VTF.], [Rule.], [OptionRom.])", self.FileName, self.CurrentLineNumber)\r
+ if S.startswith("[") and not S.startswith("[FMPPAYLOAD."):\r
+ self.SectionParser(S)\r
self.__UndoToken()\r
return False\r
\r
\r
S = self.__Token.upper()\r
if S.startswith("[") and not S.startswith("[CAPSULE."):\r
- if not S.startswith("[VTF.") and not S.startswith("[RULE.") and not S.startswith("[OPTIONROM."):\r
- raise Warning("Unknown section or section appear sequence error (The correct sequence should be [FD.], [FV.], [Capsule.], [VTF.], [Rule.], [OptionRom.])", self.FileName, self.CurrentLineNumber)\r
+ self.SectionParser(S)\r
self.__UndoToken()\r
return False\r
\r
return True\r
\r
def __GetFmpStatement(self, CapsuleObj):\r
- if not self.__IsKeyword("FMP"):\r
- return False\r
+ if not self.__IsKeyword("FMP_PAYLOAD"):\r
+ if not self.__IsKeyword("FMP"):\r
+ return False\r
\r
- if not self.__IsKeyword("PAYLOAD"):\r
- self.__UndoToken()\r
- return False\r
+ if not self.__IsKeyword("PAYLOAD"):\r
+ self.__UndoToken()\r
+ return False\r
\r
if not self.__IsToken("="):\r
raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
\r
if not self.__GetNextToken():\r
- raise Warning("expected payload name after FMP PAYLOAD =", self.FileName, self.CurrentLineNumber)\r
+ raise Warning("expected payload name after FMP_PAYLOAD =", self.FileName, self.CurrentLineNumber)\r
Payload = self.__Token.upper()\r
if Payload not in self.Profile.FmpPayloadDict:\r
raise Warning("This FMP Payload does not exist: %s" % self.__Token, self.FileName, self.CurrentLineNumber)\r
\r
S = self.__Token.upper()\r
if S.startswith("[") and not S.startswith("[RULE."):\r
- if not S.startswith("[OPTIONROM."):\r
- raise Warning("Unknown section or section appear sequence error (The correct sequence should be [FD.], [FV.], [Capsule.], [VTF.], [Rule.], [OptionRom.])", self.FileName, self.CurrentLineNumber)\r
+ self.SectionParser(S)\r
self.__UndoToken()\r
return False\r
self.__UndoToken()\r
#\r
def __GetFileExtension(self):\r
if not self.__IsToken("."):\r
- raise Warning("expected '.'", self.FileName, self.CurrentLineNumber)\r
+ raise Warning("expected '.'", self.FileName, self.CurrentLineNumber)\r
\r
Ext = ""\r
if self.__GetNextToken():\r
\r
S = self.__Token.upper()\r
if S.startswith("[") and not S.startswith("[VTF."):\r
- if not S.startswith("[RULE.") and not S.startswith("[OPTIONROM."):\r
- raise Warning("Unknown section or section appear sequence error (The correct sequence should be [FD.], [FV.], [Capsule.], [VTF.], [Rule.], [OptionRom.])", self.FileName, self.CurrentLineNumber)\r
+ self.SectionParser(S)\r
self.__UndoToken()\r
return False\r
\r
\r
S = self.__Token.upper()\r
if S.startswith("[") and not S.startswith("[OPTIONROM."):\r
- raise Warning("Unknown section or section appear sequence error (The correct sequence should be [FD.], [FV.], [Capsule.], [VTF.], [Rule.], [OptionRom.])", self.FileName, self.CurrentLineNumber)\r
+ self.SectionParser(S)\r
+ self.__UndoToken()\r
+ return False\r
\r
self.__UndoToken()\r
if not self.__IsToken("[OptionRom.", True):\r