[PATCH] BaseTools: Add support for SUBTYPE_GUID section generation


Konstantin Aladyshev
 

EFI_SECTION_FREEFORM_SUBTYPE_GUID is a leaf section type that contains
a single EFI_GUID in the header to describe the raw data.
Currently is is not possible to generate such section.
This patch adds initial support for the generation of such sections.
The added syntax for this type of section corresponds to EDKII
"[FV] section" documentation from the FDF Specification:
```
SECTION SUBTYPE_GUID <GUID> =3D <File>
```

Signed-off-by: Konstantin Aladyshev <aladyshev22@...>
---
.../Source/Python/CommonDataClass/FdfClass.py | 12 +++
BaseTools/Source/Python/GenFds/FdfParser.py | 22 ++++++
.../Python/GenFds/SubTypeGuidSection.py | 76 +++++++++++++++++++
3 files changed, 110 insertions(+)
create mode 100644 BaseTools/Source/Python/GenFds/SubTypeGuidSection.py

diff --git a/BaseTools/Source/Python/CommonDataClass/FdfClass.py b/BaseTool=
s/Source/Python/CommonDataClass/FdfClass.py
index 2fbb7b436a..c8cfdaae32 100644
--- a/BaseTools/Source/Python/CommonDataClass/FdfClass.py
+++ b/BaseTools/Source/Python/CommonDataClass/FdfClass.py
@@ -190,6 +190,18 @@ class GuidSectionClassObject (SectionClassObject) :
self.FvParentAddr =3D None=0D
self.IncludeFvSection =3D False=0D
=0D
+## SubType GUID section data in FDF=0D
+#=0D
+#=0D
+class SubTypeGuidSectionClassObject (SectionClassObject) :=0D
+ ## The constructor=0D
+ #=0D
+ # @param self The object pointer=0D
+ #=0D
+ def __init__(self):=0D
+ SectionClassObject.__init__(self)=0D
+ self.SubTypeGuid =3D None=0D
+=0D
## UI section data in FDF=0D
#=0D
#=0D
diff --git a/BaseTools/Source/Python/GenFds/FdfParser.py b/BaseTools/Source=
/Python/GenFds/FdfParser.py
index 5c8263f9bc..aa18fef09e 100644
--- a/BaseTools/Source/Python/GenFds/FdfParser.py
+++ b/BaseTools/Source/Python/GenFds/FdfParser.py
@@ -42,6 +42,7 @@ from .DataSection import DataSection
from .DepexSection import DepexSection=0D
from .CompressSection import CompressSection=0D
from .GuidSection import GuidSection=0D
+from .SubTypeGuidSection import SubTypeGuidSection=0D
from .Capsule import EFI_CERT_TYPE_PKCS7_GUID, EFI_CERT_TYPE_RSA2048_SHA25=
6_GUID, Capsule=0D
from .CapsuleData import CapsuleFfs, CapsulePayload, CapsuleFv, CapsuleFd,=
CapsuleAnyFile, CapsuleAfile=0D
from .RuleComplexFile import RuleComplexFile=0D
@@ -2892,6 +2893,27 @@ class FdfParser:
DepexSectionObj.Expression =3D self._SkippedChars.rstrip(T_CHA=
R_BRACE_R)=0D
Obj.SectionList.append(DepexSectionObj)=0D
=0D
+ elif self._IsKeyword("SUBTYPE_GUID"):=0D
+ if AlignValue =3D=3D 'Auto':=0D
+ raise Warning("Auto alignment can only be used in PE32 or =
TE section ", self.FileName, self.CurrentLineNumber)=0D
+ SubTypeGuidValue =3D None=0D
+ if not self._GetNextGuid():=0D
+ raise Warning.Expected("GUID", self.FileName, self.Current=
LineNumber)=0D
+ else:=0D
+ SubTypeGuidValue =3D self._Token=0D
+=0D
+ if not self._IsToken(TAB_EQUAL_SPLIT):=0D
+ raise Warning.ExpectedEquals(self.FileName, self.CurrentLi=
neNumber)=0D
+ if not self._GetNextToken():=0D
+ raise Warning.Expected("section file path", self.FileName,=
self.CurrentLineNumber)=0D
+ FileName =3D self._Token=0D
+=0D
+ SubTypeGuidSectionObj =3D SubTypeGuidSection()=0D
+ SubTypeGuidSectionObj.Alignment =3D AlignValue=0D
+ SubTypeGuidSectionObj.SubTypeGuid =3D SubTypeGuidValue=0D
+ SubTypeGuidSectionObj.SectFileName =3D FileName=0D
+ Obj.SectionList.append(SubTypeGuidSectionObj)=0D
+=0D
else:=0D
if not self._GetNextWord():=0D
raise Warning.Expected("section type", self.FileName, self=
.CurrentLineNumber)=0D
diff --git a/BaseTools/Source/Python/GenFds/SubTypeGuidSection.py b/BaseToo=
ls/Source/Python/GenFds/SubTypeGuidSection.py
new file mode 100644
index 0000000000..d522380117
--- /dev/null
+++ b/BaseTools/Source/Python/GenFds/SubTypeGuidSection.py
@@ -0,0 +1,76 @@
+## @file=0D
+# process Subtype GUIDed section generation=0D
+#=0D
+# Copyright (c) 2022, Konstantin Aladyshev <aladyshev22@...>=0D
+#=0D
+# SPDX-License-Identifier: BSD-2-Clause-Patent=0D
+#=0D
+=0D
+##=0D
+# Import Modules=0D
+#=0D
+from __future__ import absolute_import=0D
+from . import Section=0D
+import subprocess=0D
+from .Ffs import SectionSuffix=0D
+import Common.LongFilePathOs as os=0D
+from .GenFdsGlobalVariable import GenFdsGlobalVariable=0D
+from .GenFdsGlobalVariable import FindExtendTool=0D
+from CommonDataClass.FdfClass import SubTypeGuidSectionClassObject=0D
+import sys=0D
+from Common import EdkLogger=0D
+from Common.BuildToolError import *=0D
+from .FvImageSection import FvImageSection=0D
+from Common.LongFilePathSupport import OpenLongFilePath as open=0D
+from Common.DataType import *=0D
+=0D
+## generate SubType GUIDed section=0D
+#=0D
+#=0D
+class SubTypeGuidSection(SubTypeGuidSectionClassObject) :=0D
+=0D
+ ## The constructor=0D
+ #=0D
+ # @param self The object pointer=0D
+ #=0D
+ def __init__(self):=0D
+ SubTypeGuidSectionClassObject.__init__(self)=0D
+=0D
+ ## GenSection() method=0D
+ #=0D
+ # Generate GUIDed section=0D
+ #=0D
+ # @param self The object pointer=0D
+ # @param OutputPath Where to place output file=0D
+ # @param ModuleName Which module this section belongs to=0D
+ # @param SecNum Index of section=0D
+ # @param KeyStringList Filter for inputs of section generation=0D
+ # @param FfsInf FfsInfStatement object that contains this sect=
ion data=0D
+ # @param Dict dictionary contains macro and its value=0D
+ # @retval tuple (Generated file name, section alignment)=0D
+ #=0D
+ def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, Ff=
sInf=3DNone, Dict=3DNone, IsMakefile=3DFalse):=0D
+ #=0D
+ # Generate all section=0D
+ #=0D
+ self.KeyStringList =3D KeyStringList=0D
+ self.CurrentArchList =3D GenFdsGlobalVariable.ArchList=0D
+ if FfsInf is not None:=0D
+ self.Alignment =3D FfsInf.__ExtendMacro__(self.Alignment)=0D
+ self.SubTypeGuid =3D FfsInf.__ExtendMacro__(self.SubTypeGuid)=
=0D
+ self.SectionType =3D FfsInf.__ExtendMacro__(self.SectionType)=
=0D
+ self.CurrentArchList =3D [FfsInf.CurrentArch]=0D
+=0D
+ if Dict is None:=0D
+ Dict =3D {}=0D
+=0D
+ self.SectFileName =3D GenFdsGlobalVariable.ReplaceWorkspaceMacro(s=
elf.SectFileName)=0D
+ self.SectFileName =3D GenFdsGlobalVariable.MacroExtend(self.SectFi=
leName, Dict)=0D
+=0D
+ OutputFile =3D os.path.join(OutputPath, ModuleName + SUP_MODULE_SE=
C + SecNum + SectionSuffix.get("SUBTYPE_GUID"))=0D
+ GenFdsGlobalVariable.GenerateSection(OutputFile, [self.SectFileNam=
e], 'EFI_SECTION_FREEFORM_SUBTYPE_GUID', Guid=3Dself.SubTypeGuid, IsMakefil=
e=3DIsMakefile)=0D
+=0D
+ OutputFileList =3D []=0D
+ OutputFileList.append(OutputFile)=0D
+ return OutputFileList, self.Alignment=0D
+=0D
--=20
2.25.1

Join devel@edk2.groups.io to automatically receive all group messages.