[`edk2-devel][PATCH] UefiPayloadPkg: Add ".upld_info" in universal payload

Guo Dong

From: Guo Dong <guo.dong@intel.com>

From the universal scalable firmware payload requirement V0.75,
Payload must have Universal Payload Information Section ".upld_info"
So update the build tool to add this section.

Cc: Ray Ni <ray.ni@intel.com>
Cc: Maurice Ma <maurice.ma@intel.com>
Cc: Benjamin You <benjamin.you@intel.com>
Signed-off-by: Guo Dong <guo.dong@intel.com>
UefiPayloadPkg/UniversalPayloadBuild.py | 42 +++++++++++++++++++++++++++++=
1 file changed, 39 insertions(+), 3 deletions(-)

diff --git a/UefiPayloadPkg/UniversalPayloadBuild.py b/UefiPayloadPkg/Unive=
index b78c6a7620..842f92ac1a 100644
--- a/UefiPayloadPkg/UniversalPayloadBuild.py
+++ b/UefiPayloadPkg/UniversalPayloadBuild.py
@@ -10,6 +10,31 @@ import subprocess
import os=0D
import shutil=0D
import sys=0D
+from ctypes import *=0D
+sys.dont_write_bytecode =3D True=0D
+class UPLD_INFO_HEADER(Structure):=0D
+ _pack_ =3D 1=0D
+ _fields_ =3D [=0D
+ ('Identifier', ARRAY(c_char, 4)),=0D
+ ('HeaderLength', c_uint32),=0D
+ ('SpecRevision', c_uint16),=0D
+ ('Reserved', c_uint16),=0D
+ ('Revision', c_uint32),=0D
+ ('Attribute', c_uint32),=0D
+ ('Capability', c_uint32),=0D
+ ('ProducerId', ARRAY(c_char, 16)),=0D
+ ('ImageId', ARRAY(c_char, 16)),=0D
+ ]=0D
+ def __init__(self):=0D
+ self.Identifier =3D b'UPLD'=0D
+ self.HeaderLength =3D sizeof(UPLD_INFO_HEADER)=0D
+ self.HeaderRevision =3D 0x0075=0D
+ self.Revision =3D 0x0000010105=0D
+ self.ImageId =3D b'UEFI'=0D
+ self.ProducerId =3D b'INTEL'=0D
def RunCommand(cmd):=0D
@@ -37,6 +62,7 @@ def BuildUniversalPayload(Args, MacroList):
EntryOutputDir =3D os.path.join(BuildDir, f"{BuildTarget}_{ElfToolChai=
n}", os.path.normpath("X64/UefiPayloadPkg/UefiPayloadEntry/UniversalPayload=
PayloadReportPath =3D os.path.join(BuildDir, "UefiUniversalPayload.txt=
ModuleReportPath =3D os.path.join(BuildDir, "UefiUniversalPayloadEntry=
+ UpldInfoFile =3D os.path.join(BuildDir, "UniversalPayloadInfo.bin")=0D
if "CLANG_BIN" in os.environ:=0D
LlvmObjcopyPath =3D os.path.join(os.environ["CLANG_BIN"], "llvm-ob=
@@ -65,12 +91,21 @@ def BuildUniversalPayload(Args, MacroList):
BuildModule +=3D Defines=0D
+ #=0D
+ # Buid Universal Payload Information Section ".upld_info"=0D
+ #=0D
+ upld_info_hdr =3D UPLD_INFO_HEADER()=0D
+ upld_info_hdr.ImageId =3D Args.ImageId.encode()[:16]=0D
+ fp =3D open(UpldInfoFile, 'wb')=0D
+ fp.write(bytearray(upld_info_hdr))=0D
+ fp.close()=0D
# Copy the DXEFV as a section in elf format Universal Payload entry.=0D
- remove_section =3D '"%s" -I elf64-x86-64 -O elf64-x86-64 --remove-sect=
ion .upld.uefi_fv %s'%(LlvmObjcopyPath, EntryOutputDir)=0D
- add_section =3D '"%s" -I elf64-x86-64 -O elf64-x86-64 --add-section .u=
pld.uefi_fv=3D%s %s'%(LlvmObjcopyPath, FvOutputDir, EntryOutputDir)=0D
- set_section =3D '"%s" -I elf64-x86-64 -O elf64-x86-64 --set-section-al=
ignment .upld.uefi_fv=3D16 %s'%(LlvmObjcopyPath, EntryOutputDir)=0D
+ remove_section =3D '"%s" -I elf64-x86-64 -O elf64-x86-64 --remove-sect=
ion .upld_info --remove-section .upld.uefi_fv %s'%(LlvmObjcopyPath, EntryOu=
+ add_section =3D '"%s" -I elf64-x86-64 -O elf64-x86-64 --add-section=
.upld_info=3D%s --add-section .upld.uefi_fv=3D%s %s'%(LlvmObjcopyPath, Upl=
dInfoFile, FvOutputDir, EntryOutputDir)=0D
+ set_section =3D '"%s" -I elf64-x86-64 -O elf64-x86-64 --set-section=
-alignment .upld.upld_info=3D16 --set-section-alignment .upld.uefi_fv=3D16 =
%s'%(LlvmObjcopyPath, EntryOutputDir)=0D
@@ -82,6 +117,7 @@ def main():
parser.add_argument('-t', '--ToolChain')=0D
parser.add_argument('-b', '--Target', default=3D'DEBUG')=0D
parser.add_argument("-D", "--Macro", action=3D"append", default=3D["UN=
+ parser.add_argument('-i', '--ImageId', type=3Dstr, help=3D'Specify pay=
load ID (16 bytes maximal).', default =3D'UEFI')=0D
MacroList =3D {}=0D
args =3D parser.parse_args()=0D
if args.Macro is not None:=0D

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