public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] UefiPayloadPkg: Add script to build UniversalPayload in UefiPayloadPkg
@ 2021-09-10  8:01 duntan
  0 siblings, 0 replies; 4+ messages in thread
From: duntan @ 2021-09-10  8:01 UTC (permalink / raw)
  To: devel; +Cc: Guo Dong, Ray Ni, Maurice Ma, Benjamin You, Zhiguang Liu

Add script to build UniversalPayload, which can be used after edksetup rebuild
The final UPL.elf will be located at root folder of edk2

Cc: Guo Dong <guo.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Maurice Ma <maurice.ma@intel.com>
Cc: Benjamin You <benjamin.you@intel.com>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Signed-off-by: Dun Tan <dun.tan@intel.com>
---
 UefiPayloadPkg/UniversalPayloadBuild.py | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 95 insertions(+)

diff --git a/UefiPayloadPkg/UniversalPayloadBuild.py b/UefiPayloadPkg/UniversalPayloadBuild.py
new file mode 100644
index 0000000000..9bcc4e77a0
--- /dev/null
+++ b/UefiPayloadPkg/UniversalPayloadBuild.py
@@ -0,0 +1,95 @@
+## @file
+# This file contains the script to build UniversalPayload
+#
+# Copyright (c) 2021, Intel Corporation. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+import argparse
+import subprocess
+import os
+import shutil
+import sys
+
+def RunCommand(cmd):
+    print(cmd)
+    p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,cwd=os.environ['WORKSPACE'])
+    while True:
+        line = p.stdout.readline()
+        if not line:
+            break
+        print(line.strip().decode(errors='ignore'))
+
+    p.communicate()
+    if p.returncode != 0:
+        print("- Failed - error happened when run command: %s"%cmd)
+        raise Exception("ERROR: when run command: %s"%cmd)
+
+def BuildUniversalPayload(args, MacroList):
+    build_target = args.Target
+    tool_chain_tag = args.ToolChain
+    elf_tool_chain = 'CLANGDWARF'
+    entry_module_inf = os.path.join("UefiPayloadPkg", "UefiPayloadEntry", "UniversalPayloadEntry.inf")
+    fv = os.path.join(os.environ['WORKSPACE'], "Build", "UefiPayloadPkgX64", "%s_%s"%(build_target, tool_chain_tag), "FV", "DXEFV.Fv")
+    entry = os.path.join(os.environ['WORKSPACE'], "Build", "UefiPayloadPkgX64", "%s_%s"%(build_target, elf_tool_chain), "X64", "UefiPayloadPkg", "UefiPayloadEntry", "UniversalPayloadEntry", "DEBUG", "UniversalPayloadEntry.dll")
+    dsc_patch = os.path.join("UefiPayloadPkg", "UefiPayloadPkg.dsc")
+
+    if "CLANG_BIN" in os.environ:
+        llvm_objcopy_path = os.path.join(os.environ["CLANG_BIN"],"llvm-objcopy")
+    else:
+        llvm_objcopy_path = "llvm-objcopy"
+    try:
+        RunCommand('"%s" --version'%llvm_objcopy_path)
+    except:
+        print("- Failed - Please check if LLVM is installed or if CLANG_BIN is set correctly")
+        sys.exit(1)
+
+    macro_list = " "
+    for key in MacroList:
+        macro_list +="-D {0}={1} ".format(key, MacroList[key])
+
+    #
+    # Building DXE core and DXE drivers as DXEFV.
+    #
+    build_payload = "build -p %s -b %s -a X64 -t %s -y UplBuildReport.txt"%(dsc_patch, build_target, tool_chain_tag)
+    build_payload += macro_list
+    RunCommand(build_payload)
+    #
+    # Building Universal Payload entry.
+    #
+    build_module = "build -p %s -b %s -a X64 -m %s -t %s -y UplBuildReportEntry.txt"%(dsc_patch, build_target, entry_module_inf, elf_tool_chain)
+    build_module += macro_list
+    RunCommand(build_module)
+
+    #
+    # 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'%(llvm_objcopy_path,entry)
+    add_section = '"%s" -I elf64-x86-64 -O elf64-x86-64 --add-section .upld.uefi_fv=%s %s'%(llvm_objcopy_path,fv,entry)
+    set_section = '"%s" -I elf64-x86-64 -O elf64-x86-64 --set-section-alignment .upld.uefi_fv=16 %s'%(llvm_objcopy_path,entry)
+    RunCommand(remove_section)
+    RunCommand(add_section)
+    RunCommand(set_section)
+
+    shutil.copy (entry, os.path.join(os.environ['WORKSPACE'], 'UPL.elf'))
+
+def main():
+    print ("Begin to build Universal Payload...")
+    parser = argparse.ArgumentParser(description='For build Universal Payload')
+    parser.add_argument('-t', '--ToolChain', help="Using the ToolChain to build the UniversalPayload")
+    parser.add_argument('-b', '--Target', help="Using the TARGET to build the UniversalPayload")
+    parser.add_argument("-D", "--Macro", action="append", help="Macro: \"Name [= Value]\".")
+    MacroList = {}
+    args = parser.parse_args()
+    if args.Macro is not None:
+        for argument in args.Macro:
+            if argument.count('=') != 1:
+                print("Unknown variable passed in: %s"%argument)
+                raise Exception("ERROR: Unknown variable passed in: %s"%argument)
+            tokens = argument.strip().split('=')
+            MacroList[tokens[0].upper()] = tokens[1]
+    BuildUniversalPayload(args, MacroList)
+    print ("Successfully build Universal Payload")
+
+if __name__ == '__main__':
+    main()
-- 
2.31.1.windows.1


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

* [PATCH] UefiPayloadPkg: Add script to build UniversalPayload in UefiPayloadPkg
@ 2021-09-10  8:06 duntan
  0 siblings, 0 replies; 4+ messages in thread
From: duntan @ 2021-09-10  8:06 UTC (permalink / raw)
  To: devel; +Cc: Guo Dong, Ray Ni, Maurice Ma, Benjamin You, Zhiguang Liu

Add script to build UniversalPayload, which can be used after edksetup rebuild
The final UPL.elf will be located at root folder of edk2

Cc: Guo Dong <guo.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Maurice Ma <maurice.ma@intel.com>
Cc: Benjamin You <benjamin.you@intel.com>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Signed-off-by: Dun Tan <dun.tan@intel.com>
---
 UefiPayloadPkg/UniversalPayloadBuild.py | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 95 insertions(+)

diff --git a/UefiPayloadPkg/UniversalPayloadBuild.py b/UefiPayloadPkg/UniversalPayloadBuild.py
new file mode 100644
index 0000000000..9bcc4e77a0
--- /dev/null
+++ b/UefiPayloadPkg/UniversalPayloadBuild.py
@@ -0,0 +1,95 @@
+## @file
+# This file contains the script to build UniversalPayload
+#
+# Copyright (c) 2021, Intel Corporation. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+import argparse
+import subprocess
+import os
+import shutil
+import sys
+
+def RunCommand(cmd):
+    print(cmd)
+    p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,cwd=os.environ['WORKSPACE'])
+    while True:
+        line = p.stdout.readline()
+        if not line:
+            break
+        print(line.strip().decode(errors='ignore'))
+
+    p.communicate()
+    if p.returncode != 0:
+        print("- Failed - error happened when run command: %s"%cmd)
+        raise Exception("ERROR: when run command: %s"%cmd)
+
+def BuildUniversalPayload(args, MacroList):
+    build_target = args.Target
+    tool_chain_tag = args.ToolChain
+    elf_tool_chain = 'CLANGDWARF'
+    entry_module_inf = os.path.join("UefiPayloadPkg", "UefiPayloadEntry", "UniversalPayloadEntry.inf")
+    fv = os.path.join(os.environ['WORKSPACE'], "Build", "UefiPayloadPkgX64", "%s_%s"%(build_target, tool_chain_tag), "FV", "DXEFV.Fv")
+    entry = os.path.join(os.environ['WORKSPACE'], "Build", "UefiPayloadPkgX64", "%s_%s"%(build_target, elf_tool_chain), "X64", "UefiPayloadPkg", "UefiPayloadEntry", "UniversalPayloadEntry", "DEBUG", "UniversalPayloadEntry.dll")
+    dsc_patch = os.path.join("UefiPayloadPkg", "UefiPayloadPkg.dsc")
+
+    if "CLANG_BIN" in os.environ:
+        llvm_objcopy_path = os.path.join(os.environ["CLANG_BIN"],"llvm-objcopy")
+    else:
+        llvm_objcopy_path = "llvm-objcopy"
+    try:
+        RunCommand('"%s" --version'%llvm_objcopy_path)
+    except:
+        print("- Failed - Please check if LLVM is installed or if CLANG_BIN is set correctly")
+        sys.exit(1)
+
+    macro_list = " "
+    for key in MacroList:
+        macro_list +="-D {0}={1} ".format(key, MacroList[key])
+
+    #
+    # Building DXE core and DXE drivers as DXEFV.
+    #
+    build_payload = "build -p %s -b %s -a X64 -t %s -y UplBuildReport.txt"%(dsc_patch, build_target, tool_chain_tag)
+    build_payload += macro_list
+    RunCommand(build_payload)
+    #
+    # Building Universal Payload entry.
+    #
+    build_module = "build -p %s -b %s -a X64 -m %s -t %s -y UplBuildReportEntry.txt"%(dsc_patch, build_target, entry_module_inf, elf_tool_chain)
+    build_module += macro_list
+    RunCommand(build_module)
+
+    #
+    # 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'%(llvm_objcopy_path,entry)
+    add_section = '"%s" -I elf64-x86-64 -O elf64-x86-64 --add-section .upld.uefi_fv=%s %s'%(llvm_objcopy_path,fv,entry)
+    set_section = '"%s" -I elf64-x86-64 -O elf64-x86-64 --set-section-alignment .upld.uefi_fv=16 %s'%(llvm_objcopy_path,entry)
+    RunCommand(remove_section)
+    RunCommand(add_section)
+    RunCommand(set_section)
+
+    shutil.copy (entry, os.path.join(os.environ['WORKSPACE'], 'UPL.elf'))
+
+def main():
+    print ("Begin to build Universal Payload...")
+    parser = argparse.ArgumentParser(description='For build Universal Payload')
+    parser.add_argument('-t', '--ToolChain', help="Using the ToolChain to build the UniversalPayload")
+    parser.add_argument('-b', '--Target', help="Using the TARGET to build the UniversalPayload")
+    parser.add_argument("-D", "--Macro", action="append", help="Macro: \"Name [= Value]\".")
+    MacroList = {}
+    args = parser.parse_args()
+    if args.Macro is not None:
+        for argument in args.Macro:
+            if argument.count('=') != 1:
+                print("Unknown variable passed in: %s"%argument)
+                raise Exception("ERROR: Unknown variable passed in: %s"%argument)
+            tokens = argument.strip().split('=')
+            MacroList[tokens[0].upper()] = tokens[1]
+    BuildUniversalPayload(args, MacroList)
+    print ("Successfully build Universal Payload")
+
+if __name__ == '__main__':
+    main()
-- 
2.31.1.windows.1


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

* [PATCH] UefiPayloadPkg: Add script to build UniversalPayload in UefiPayloadPkg
@ 2021-09-10  8:15 duntan
  2021-09-10 10:04 ` Ni, Ray
  0 siblings, 1 reply; 4+ messages in thread
From: duntan @ 2021-09-10  8:15 UTC (permalink / raw)
  To: devel; +Cc: Guo Dong, Ray Ni, Maurice Ma, Benjamin You, Zhiguang Liu

Add script to build UniversalPayload, which can be used after edksetup rebuild
The final UPL.elf will be located at root folder of edk2

Cc: Guo Dong <guo.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Maurice Ma <maurice.ma@intel.com>
Cc: Benjamin You <benjamin.you@intel.com>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Signed-off-by: Dun Tan <dun.tan@intel.com>
---
 UefiPayloadPkg/UniversalPayloadBuild.py | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 95 insertions(+)

diff --git a/UefiPayloadPkg/UniversalPayloadBuild.py b/UefiPayloadPkg/UniversalPayloadBuild.py
new file mode 100644
index 0000000000..9bcc4e77a0
--- /dev/null
+++ b/UefiPayloadPkg/UniversalPayloadBuild.py
@@ -0,0 +1,95 @@
+## @file
+# This file contains the script to build UniversalPayload
+#
+# Copyright (c) 2021, Intel Corporation. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+import argparse
+import subprocess
+import os
+import shutil
+import sys
+
+def RunCommand(cmd):
+    print(cmd)
+    p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,cwd=os.environ['WORKSPACE'])
+    while True:
+        line = p.stdout.readline()
+        if not line:
+            break
+        print(line.strip().decode(errors='ignore'))
+
+    p.communicate()
+    if p.returncode != 0:
+        print("- Failed - error happened when run command: %s"%cmd)
+        raise Exception("ERROR: when run command: %s"%cmd)
+
+def BuildUniversalPayload(args, MacroList):
+    build_target = args.Target
+    tool_chain_tag = args.ToolChain
+    elf_tool_chain = 'CLANGDWARF'
+    entry_module_inf = os.path.join("UefiPayloadPkg", "UefiPayloadEntry", "UniversalPayloadEntry.inf")
+    fv = os.path.join(os.environ['WORKSPACE'], "Build", "UefiPayloadPkgX64", "%s_%s"%(build_target, tool_chain_tag), "FV", "DXEFV.Fv")
+    entry = os.path.join(os.environ['WORKSPACE'], "Build", "UefiPayloadPkgX64", "%s_%s"%(build_target, elf_tool_chain), "X64", "UefiPayloadPkg", "UefiPayloadEntry", "UniversalPayloadEntry", "DEBUG", "UniversalPayloadEntry.dll")
+    dsc_patch = os.path.join("UefiPayloadPkg", "UefiPayloadPkg.dsc")
+
+    if "CLANG_BIN" in os.environ:
+        llvm_objcopy_path = os.path.join(os.environ["CLANG_BIN"],"llvm-objcopy")
+    else:
+        llvm_objcopy_path = "llvm-objcopy"
+    try:
+        RunCommand('"%s" --version'%llvm_objcopy_path)
+    except:
+        print("- Failed - Please check if LLVM is installed or if CLANG_BIN is set correctly")
+        sys.exit(1)
+
+    macro_list = " "
+    for key in MacroList:
+        macro_list +="-D {0}={1} ".format(key, MacroList[key])
+
+    #
+    # Building DXE core and DXE drivers as DXEFV.
+    #
+    build_payload = "build -p %s -b %s -a X64 -t %s -y UplBuildReport.txt"%(dsc_patch, build_target, tool_chain_tag)
+    build_payload += macro_list
+    RunCommand(build_payload)
+    #
+    # Building Universal Payload entry.
+    #
+    build_module = "build -p %s -b %s -a X64 -m %s -t %s -y UplBuildReportEntry.txt"%(dsc_patch, build_target, entry_module_inf, elf_tool_chain)
+    build_module += macro_list
+    RunCommand(build_module)
+
+    #
+    # 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'%(llvm_objcopy_path,entry)
+    add_section = '"%s" -I elf64-x86-64 -O elf64-x86-64 --add-section .upld.uefi_fv=%s %s'%(llvm_objcopy_path,fv,entry)
+    set_section = '"%s" -I elf64-x86-64 -O elf64-x86-64 --set-section-alignment .upld.uefi_fv=16 %s'%(llvm_objcopy_path,entry)
+    RunCommand(remove_section)
+    RunCommand(add_section)
+    RunCommand(set_section)
+
+    shutil.copy (entry, os.path.join(os.environ['WORKSPACE'], 'UPL.elf'))
+
+def main():
+    print ("Begin to build Universal Payload...")
+    parser = argparse.ArgumentParser(description='For build Universal Payload')
+    parser.add_argument('-t', '--ToolChain', help="Using the ToolChain to build the UniversalPayload")
+    parser.add_argument('-b', '--Target', help="Using the TARGET to build the UniversalPayload")
+    parser.add_argument("-D", "--Macro", action="append", help="Macro: \"Name [= Value]\".")
+    MacroList = {}
+    args = parser.parse_args()
+    if args.Macro is not None:
+        for argument in args.Macro:
+            if argument.count('=') != 1:
+                print("Unknown variable passed in: %s"%argument)
+                raise Exception("ERROR: Unknown variable passed in: %s"%argument)
+            tokens = argument.strip().split('=')
+            MacroList[tokens[0].upper()] = tokens[1]
+    BuildUniversalPayload(args, MacroList)
+    print ("Successfully build Universal Payload")
+
+if __name__ == '__main__':
+    main()
-- 
2.31.1.windows.1


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

* Re: [PATCH] UefiPayloadPkg: Add script to build UniversalPayload in UefiPayloadPkg
  2021-09-10  8:15 duntan
@ 2021-09-10 10:04 ` Ni, Ray
  0 siblings, 0 replies; 4+ messages in thread
From: Ni, Ray @ 2021-09-10 10:04 UTC (permalink / raw)
  To: Tan, Dun, devel@edk2.groups.io, Feng, Bob C, Chen, Christine
  Cc: Dong, Guo, Ma, Maurice, You, Benjamin, Liu, Zhiguang

+ Bob for general python language level review.
more comments embedded.

> +def BuildUniversalPayload(args, MacroList):
> +    build_target = args.Target
> +    tool_chain_tag = args.ToolChain
> +    elf_tool_chain = 'CLANGDWARF'
> +    entry_module_inf = os.path.join("UefiPayloadPkg", "UefiPayloadEntry", "UniversalPayloadEntry.inf")

1. Lots of hardcode file/directory names here.
Can we write in below way?
entry_module_inf = "UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.inf"
entry_module_inf = os.path.normpath(entry_module_inf)

> +    fv = os.path.join(os.environ['WORKSPACE'], "Build", "UefiPayloadPkgX64", "%s_%s"%(build_target, tool_chain_tag), "FV",
> "DXEFV.Fv")
> +    entry = os.path.join(os.environ['WORKSPACE'], "Build", "UefiPayloadPkgX64", "%s_%s"%(build_target, elf_tool_chain), "X64",
> "UefiPayloadPkg", "UefiPayloadEntry", "UniversalPayloadEntry", "DEBUG", "UniversalPayloadEntry.dll")

2.
build_directory = os.path.join(os.environ['WORKSPACE'], os.path.normpath ("Build/UefiPayloadPkgX64")
fv = os.path.join(build_directory, "%s_%s"%(build_target, tool_chain_tag), os.path.normpath("FV/DXEFV.fv"))
entry = ......

> +    dsc_patch = os.path.join("UefiPayloadPkg", "UefiPayloadPkg.dsc")

3.
Similar change can be applied to dsc_patch (typo? dsc_path?)


> +    macro_list = " "
> +    for key in MacroList:
> +        macro_list +="-D {0}={1} ".format(key, MacroList[key])

4.  you can set macro_list = "", then insert space before each "-D" in the loop.

> +
> +    #
> +    # Building DXE core and DXE drivers as DXEFV.
> +    #
> +    build_payload = "build -p %s -b %s -a X64 -t %s -y UplBuildReport.txt"%(dsc_patch, build_target, tool_chain_tag)
> +    build_payload += macro_list

5. you could write in following way
build_payload = f"build -p {dsc_patch} ..."

> +    RunCommand(build_payload)
> +    #
> +    # Building Universal Payload entry.
> +    #
> +    build_module = "build -p %s -b %s -a X64 -m %s -t %s -y UplBuildReportEntry.txt"%(dsc_patch, build_target,
> entry_module_inf, elf_tool_chain)

6. can you please make sure that there is no file generated in the workspace directory. All files are generated under build directory including the report file and the ELF file.

> +    shutil.copy (entry, os.path.join(os.environ['WORKSPACE'], 'UPL.elf'))

7. do you copy out.

> +
> +def main():
> +    print ("Begin to build Universal Payload...")

8. above message is not needed when printing help. maybe just remove the above message completely.

> +    parser = argparse.ArgumentParser(description='For build Universal Payload')
> +    parser.add_argument('-t', '--ToolChain', help="Using the ToolChain to build the UniversalPayload")
> +    parser.add_argument('-b', '--Target', help="Using the TARGET to build the UniversalPayload")

9. set TARGET to DEBUG as default?


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

end of thread, other threads:[~2021-09-10 10:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-09-10  8:01 [PATCH] UefiPayloadPkg: Add script to build UniversalPayload in UefiPayloadPkg duntan
  -- strict thread matches above, loose matches on Subject: below --
2021-09-10  8:06 duntan
2021-09-10  8:15 duntan
2021-09-10 10:04 ` Ni, Ray

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