public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [`edk2-devel][PATCH] UefiPayloadPkg: Add ".upld_info" in universal payload
@ 2021-09-25  3:57 Guo Dong
  2021-09-25 16:30 ` [edk2-devel] " Andrew Fish
  0 siblings, 1 reply; 3+ messages in thread
From: Guo Dong @ 2021-09-25  3:57 UTC (permalink / raw)
  To: devel; +Cc: Guo Dong, Ray Ni, Maurice Ma, Benjamin You

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [edk2-devel] [`edk2-devel][PATCH] UefiPayloadPkg: Add ".upld_info" in universal payload
  2021-09-25  3:57 [`edk2-devel][PATCH] UefiPayloadPkg: Add ".upld_info" in universal payload Guo Dong
@ 2021-09-25 16:30 ` Andrew Fish
  2021-09-25 23:08   ` Guo Dong
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Fish @ 2021-09-25 16:30 UTC (permalink / raw)
  To: edk2-devel-groups-io, Dong, Guo; +Cc: Ray Ni, Maurice Ma, Benjamin You

[-- Attachment #1: Type: text/plain, Size: 5122 bytes --]



> On Sep 24, 2021, at 8:57 PM, Guo Dong <guo.dong@intel.com> wrote:
> 
> 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/UniversalPayloadBuild.py
> index b78c6a7620..842f92ac1a 100644
> --- a/UefiPayloadPkg/UniversalPayloadBuild.py
> +++ b/UefiPayloadPkg/UniversalPayloadBuild.py
> @@ -10,6 +10,31 @@ import subprocess
> import os
> import shutil
> import sys
> +from   ctypes import *
> +
> +sys.dont_write_bytecode = True
> +
> +class UPLD_INFO_HEADER(Structure):

Guo,

Structure is the endian of the machine running Python which might not be correct. It would be more correct to use LittleEndianStructure vs Structure. This is probably good practice like using “<“ vs “=“ or “@“ with struct.pack format strings. 

I don’t remember us requiring the edk2 build machine to be little endian? 

My M1 Mac mini is little endian like a lot of ARM machines, but big endian machines do exist. 
>>> import sys; sys.byteorder
'little'

Thanks,

Andrew Fish

> +    _pack_ = 1
> +    _fields_ = [
> +        ('Identifier',           ARRAY(c_char, 4)),
> +        ('HeaderLength',         c_uint32),
> +        ('SpecRevision',         c_uint16),
> +        ('Reserved',             c_uint16),
> +        ('Revision',             c_uint32),
> +        ('Attribute',            c_uint32),
> +        ('Capability',           c_uint32),
> +        ('ProducerId',           ARRAY(c_char, 16)),
> +        ('ImageId',              ARRAY(c_char, 16)),
> +        ]
> +
> +    def __init__(self):
> +        self.Identifier     =  b'UPLD'
> +        self.HeaderLength   = sizeof(UPLD_INFO_HEADER)
> +        self.HeaderRevision = 0x0075
> +        self.Revision       = 0x0000010105
> +        self.ImageId        = b'UEFI'
> +        self.ProducerId     = b'INTEL'
> 
> def RunCommand(cmd):
>     print(cmd)
> @@ -37,6 +62,7 @@ def BuildUniversalPayload(Args, MacroList):
>     EntryOutputDir = os.path.join(BuildDir, f"{BuildTarget}_{ElfToolChain}", os.path.normpath("X64/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry/DEBUG/UniversalPayloadEntry.dll"))
>     PayloadReportPath = os.path.join(BuildDir, "UefiUniversalPayload.txt")
>     ModuleReportPath = os.path.join(BuildDir, "UefiUniversalPayloadEntry.txt")
> +    UpldInfoFile = os.path.join(BuildDir, "UniversalPayloadInfo.bin")
> 
>     if "CLANG_BIN" in os.environ:
>         LlvmObjcopyPath = os.path.join(os.environ["CLANG_BIN"], "llvm-objcopy")
> @@ -65,12 +91,21 @@ def BuildUniversalPayload(Args, MacroList):
>     BuildModule += Defines
>     RunCommand(BuildModule)
> 
> +    #
> +    # Buid Universal Payload Information Section ".upld_info"
> +    #
> +    upld_info_hdr = UPLD_INFO_HEADER()
> +    upld_info_hdr.ImageId = Args.ImageId.encode()[:16]
> +    fp = open(UpldInfoFile, 'wb')
> +    fp.write(bytearray(upld_info_hdr))
> +    fp.close()
> +
>     #
>     # Copy the DXEFV as a section in elf format Universal Payload entry.
>     #
> -    remove_section = '"%s" -I elf64-x86-64 -O elf64-x86-64 --remove-section .upld.uefi_fv %s'%(LlvmObjcopyPath, EntryOutputDir)
> -    add_section = '"%s" -I elf64-x86-64 -O elf64-x86-64 --add-section .upld.uefi_fv=%s %s'%(LlvmObjcopyPath, FvOutputDir, EntryOutputDir)
> -    set_section = '"%s" -I elf64-x86-64 -O elf64-x86-64 --set-section-alignment .upld.uefi_fv=16 %s'%(LlvmObjcopyPath, EntryOutputDir)
> +    remove_section = '"%s" -I elf64-x86-64 -O elf64-x86-64 --remove-section .upld_info --remove-section .upld.uefi_fv %s'%(LlvmObjcopyPath, EntryOutputDir)
> +    add_section    = '"%s" -I elf64-x86-64 -O elf64-x86-64 --add-section .upld_info=%s --add-section .upld.uefi_fv=%s %s'%(LlvmObjcopyPath, UpldInfoFile, FvOutputDir, EntryOutputDir)
> +    set_section    = '"%s" -I elf64-x86-64 -O elf64-x86-64 --set-section-alignment .upld.upld_info=16 --set-section-alignment .upld.uefi_fv=16 %s'%(LlvmObjcopyPath, EntryOutputDir)
>     RunCommand(remove_section)
>     RunCommand(add_section)
>     RunCommand(set_section)
> @@ -82,6 +117,7 @@ def main():
>     parser.add_argument('-t', '--ToolChain')
>     parser.add_argument('-b', '--Target', default='DEBUG')
>     parser.add_argument("-D", "--Macro", action="append", default=["UNIVERSAL_PAYLOAD=TRUE"])
> +    parser.add_argument('-i', '--ImageId', type=str, help='Specify payload ID (16 bytes maximal).', default ='UEFI')
>     MacroList = {}
>     args = parser.parse_args()
>     if args.Macro is not None:
> -- 
> 2.32.0.windows.2
> 
> 
> 
> 
> 
> 


[-- Attachment #2: Type: text/html, Size: 9369 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [edk2-devel] [`edk2-devel][PATCH] UefiPayloadPkg: Add ".upld_info" in universal payload
  2021-09-25 16:30 ` [edk2-devel] " Andrew Fish
@ 2021-09-25 23:08   ` Guo Dong
  0 siblings, 0 replies; 3+ messages in thread
From: Guo Dong @ 2021-09-25 23:08 UTC (permalink / raw)
  To: Andrew Fish, edk2-devel-groups-io; +Cc: Ni, Ray, Ma, Maurice, You, Benjamin

[-- Attachment #1: Type: text/plain, Size: 5558 bytes --]


Thanks for the comments. I will update the patch to add LittleEndianStructure.

Thanks,
Guo

From: Andrew Fish <afish@apple.com>
Sent: Saturday, September 25, 2021 9:30 AM
To: edk2-devel-groups-io <devel@edk2.groups.io>; Dong, Guo <guo.dong@intel.com>
Cc: Ni, Ray <ray.ni@intel.com>; Ma, Maurice <maurice.ma@intel.com>; You, Benjamin <benjamin.you@intel.com>
Subject: Re: [edk2-devel] [`edk2-devel][PATCH] UefiPayloadPkg: Add ".upld_info" in universal payload




On Sep 24, 2021, at 8:57 PM, Guo Dong <guo.dong@intel.com<mailto:guo.dong@intel.com>> wrote:

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

diff --git a/UefiPayloadPkg/UniversalPayloadBuild.py b/UefiPayloadPkg/UniversalPayloadBuild.py
index b78c6a7620..842f92ac1a 100644
--- a/UefiPayloadPkg/UniversalPayloadBuild.py
+++ b/UefiPayloadPkg/UniversalPayloadBuild.py
@@ -10,6 +10,31 @@ import subprocess
import os
import shutil
import sys
+from   ctypes import *
+
+sys.dont_write_bytecode = True
+
+class UPLD_INFO_HEADER(Structure):

Guo,

Structure is the endian of the machine running Python which might not be correct. It would be more correct to use LittleEndianStructure vs Structure. This is probably good practice like using “<“ vs “=“ or “@“ with struct.pack format strings.

I don’t remember us requiring the edk2 build machine to be little endian?

My M1 Mac mini is little endian like a lot of ARM machines, but big endian machines do exist.
>>> import sys; sys.byteorder
'little'

Thanks,

Andrew Fish


+    _pack_ = 1
+    _fields_ = [
+        ('Identifier',           ARRAY(c_char, 4)),
+        ('HeaderLength',         c_uint32),
+        ('SpecRevision',         c_uint16),
+        ('Reserved',             c_uint16),
+        ('Revision',             c_uint32),
+        ('Attribute',            c_uint32),
+        ('Capability',           c_uint32),
+        ('ProducerId',           ARRAY(c_char, 16)),
+        ('ImageId',              ARRAY(c_char, 16)),
+        ]
+
+    def __init__(self):
+        self.Identifier     =  b'UPLD'
+        self.HeaderLength   = sizeof(UPLD_INFO_HEADER)
+        self.HeaderRevision = 0x0075
+        self.Revision       = 0x0000010105
+        self.ImageId        = b'UEFI'
+        self.ProducerId     = b'INTEL'

def RunCommand(cmd):
    print(cmd)
@@ -37,6 +62,7 @@ def BuildUniversalPayload(Args, MacroList):
    EntryOutputDir = os.path.join(BuildDir, f"{BuildTarget}_{ElfToolChain}", os.path.normpath("X64/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry/DEBUG/UniversalPayloadEntry.dll"))
    PayloadReportPath = os.path.join(BuildDir, "UefiUniversalPayload.txt")
    ModuleReportPath = os.path.join(BuildDir, "UefiUniversalPayloadEntry.txt")
+    UpldInfoFile = os.path.join(BuildDir, "UniversalPayloadInfo.bin")

    if "CLANG_BIN" in os.environ:
        LlvmObjcopyPath = os.path.join(os.environ["CLANG_BIN"], "llvm-objcopy")
@@ -65,12 +91,21 @@ def BuildUniversalPayload(Args, MacroList):
    BuildModule += Defines
    RunCommand(BuildModule)

+    #
+    # Buid Universal Payload Information Section ".upld_info"
+    #
+    upld_info_hdr = UPLD_INFO_HEADER()
+    upld_info_hdr.ImageId = Args.ImageId.encode()[:16]
+    fp = open(UpldInfoFile, 'wb')
+    fp.write(bytearray(upld_info_hdr))
+    fp.close()
+
    #
    # Copy the DXEFV as a section in elf format Universal Payload entry.
    #
-    remove_section = '"%s" -I elf64-x86-64 -O elf64-x86-64 --remove-section .upld.uefi_fv %s'%(LlvmObjcopyPath, EntryOutputDir)
-    add_section = '"%s" -I elf64-x86-64 -O elf64-x86-64 --add-section .upld.uefi_fv=%s %s'%(LlvmObjcopyPath, FvOutputDir, EntryOutputDir)
-    set_section = '"%s" -I elf64-x86-64 -O elf64-x86-64 --set-section-alignment .upld.uefi_fv=16 %s'%(LlvmObjcopyPath, EntryOutputDir)
+    remove_section = '"%s" -I elf64-x86-64 -O elf64-x86-64 --remove-section .upld_info --remove-section .upld.uefi_fv %s'%(LlvmObjcopyPath, EntryOutputDir)
+    add_section    = '"%s" -I elf64-x86-64 -O elf64-x86-64 --add-section .upld_info=%s --add-section .upld.uefi_fv=%s %s'%(LlvmObjcopyPath, UpldInfoFile, FvOutputDir, EntryOutputDir)
+    set_section    = '"%s" -I elf64-x86-64 -O elf64-x86-64 --set-section-alignment .upld.upld_info=16 --set-section-alignment .upld.uefi_fv=16 %s'%(LlvmObjcopyPath, EntryOutputDir)
    RunCommand(remove_section)
    RunCommand(add_section)
    RunCommand(set_section)
@@ -82,6 +117,7 @@ def main():
    parser.add_argument('-t', '--ToolChain')
    parser.add_argument('-b', '--Target', default='DEBUG')
    parser.add_argument("-D", "--Macro", action="append", default=["UNIVERSAL_PAYLOAD=TRUE"])
+    parser.add_argument('-i', '--ImageId', type=str, help='Specify payload ID (16 bytes maximal).', default ='UEFI')
    MacroList = {}
    args = parser.parse_args()
    if args.Macro is not None:
--
2.32.0.windows.2







[-- Attachment #2: Type: text/html, Size: 11899 bytes --]

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-09-25 23:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-09-25  3:57 [`edk2-devel][PATCH] UefiPayloadPkg: Add ".upld_info" in universal payload Guo Dong
2021-09-25 16:30 ` [edk2-devel] " Andrew Fish
2021-09-25 23:08   ` Guo Dong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox