]>
git.proxmox.com Git - mirror_edk2.git/blob - UefiPayloadPkg/UniversalPayloadBuild.py
99410d244dd70e909f97a1fe59eb9131ad481d7c
2 # This file contains the script to build UniversalPayload
4 # Copyright (c) 2021, Intel Corporation. All rights reserved.<BR>
5 # SPDX-License-Identifier: BSD-2-Clause-Patent
15 sys
.dont_write_bytecode
= True
17 class UPLD_INFO_HEADER(LittleEndianStructure
):
20 ('Identifier', ARRAY(c_char
, 4)),
21 ('HeaderLength', c_uint32
),
22 ('SpecRevision', c_uint16
),
23 ('Reserved', c_uint16
),
24 ('Revision', c_uint32
),
25 ('Attribute', c_uint32
),
26 ('Capability', c_uint32
),
27 ('ProducerId', ARRAY(c_char
, 16)),
28 ('ImageId', ARRAY(c_char
, 16)),
32 self
.Identifier
= b
'UPLD'
33 self
.HeaderLength
= sizeof(UPLD_INFO_HEADER
)
34 self
.HeaderRevision
= 0x0075
35 self
.Revision
= 0x0000010105
36 self
.ImageId
= b
'UEFI'
37 self
.ProducerId
= b
'INTEL'
41 p
= subprocess
.Popen(cmd
, shell
=True, stdout
=subprocess
.PIPE
, stderr
=subprocess
.STDOUT
,cwd
=os
.environ
['WORKSPACE'])
43 line
= p
.stdout
.readline()
46 print(line
.strip().decode(errors
='ignore'))
50 print("- Failed - error happened when run command: %s"%cmd
)
51 raise Exception("ERROR: when run command: %s"%cmd
)
53 def BuildUniversalPayload(Args
, MacroList
):
54 BuildTarget
= Args
.Target
55 ToolChain
= Args
.ToolChain
56 Quiet
= "--quiet" if Args
.Quiet
else ""
57 BuildArch
= "X64" if Args
.Arch
== 'X64' else "IA32 -a X64"
58 ElfToolChain
= 'CLANGDWARF'
60 EntryModuleInf
= os
.path
.normpath("UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.inf")
61 DscPath
= os
.path
.normpath("UefiPayloadPkg/UefiPayloadPkg.dsc")
62 BuildDir
= os
.path
.join(os
.environ
['WORKSPACE'], os
.path
.normpath("Build/UefiPayloadPkgX64"))
63 FvOutputDir
= os
.path
.join(BuildDir
, f
"{BuildTarget}_{ToolChain}", os
.path
.normpath("FV/DXEFV.Fv"))
64 EntryOutputDir
= os
.path
.join(BuildDir
, f
"{BuildTarget}_{ElfToolChain}", os
.path
.normpath("X64/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry/DEBUG/UniversalPayloadEntry.dll"))
65 PayloadReportPath
= os
.path
.join(BuildDir
, "UefiUniversalPayload.txt")
66 ModuleReportPath
= os
.path
.join(BuildDir
, "UefiUniversalPayloadEntry.txt")
67 UpldInfoFile
= os
.path
.join(BuildDir
, "UniversalPayloadInfo.bin")
69 if "CLANG_BIN" in os
.environ
:
70 LlvmObjcopyPath
= os
.path
.join(os
.environ
["CLANG_BIN"], "llvm-objcopy")
72 LlvmObjcopyPath
= "llvm-objcopy"
74 RunCommand('"%s" --version'%LlvmObjcopyPath
)
76 print("- Failed - Please check if LLVM is installed or if CLANG_BIN is set correctly")
81 Defines
+=" -D {0}={1}".format(key
, MacroList
[key
])
84 # Building DXE core and DXE drivers as DXEFV.
86 BuildPayload
= f
"build -p {DscPath} -b {BuildTarget} -a X64 -t {ToolChain} -y {PayloadReportPath} {Quiet}"
87 BuildPayload
+= Defines
88 RunCommand(BuildPayload
)
90 # Building Universal Payload entry.
92 BuildModule
= f
"build -p {DscPath} -b {BuildTarget} -a {BuildArch} -m {EntryModuleInf} -t {ElfToolChain} -y {ModuleReportPath} {Quiet}"
93 BuildModule
+= Defines
94 RunCommand(BuildModule
)
97 # Buid Universal Payload Information Section ".upld_info"
99 upld_info_hdr
= UPLD_INFO_HEADER()
100 upld_info_hdr
.ImageId
= Args
.ImageId
.encode()[:16]
101 fp
= open(UpldInfoFile
, 'wb')
102 fp
.write(bytearray(upld_info_hdr
))
106 # Copy the DXEFV as a section in elf format Universal Payload entry.
108 remove_section
= '"%s" -I elf64-x86-64 -O elf64-x86-64 --remove-section .upld_info --remove-section .upld.uefi_fv %s'%(LlvmObjcopyPath
, EntryOutputDir
)
109 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
)
110 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
)
111 RunCommand(remove_section
)
112 RunCommand(add_section
)
113 RunCommand(set_section
)
115 shutil
.copy (EntryOutputDir
, os
.path
.join(BuildDir
, 'UniversalPayload.elf'))
118 parser
= argparse
.ArgumentParser(description
='For building Universal Payload')
119 parser
.add_argument('-t', '--ToolChain')
120 parser
.add_argument('-b', '--Target', default
='DEBUG')
121 parser
.add_argument('-a', '--Arch', choices
=['IA32', 'X64'], help='Specify the ARCH for payload entry module. Default build X64 image.', default
='X64')
122 parser
.add_argument("-D", "--Macro", action
="append", default
=["UNIVERSAL_PAYLOAD=TRUE"])
123 parser
.add_argument('-i', '--ImageId', type=str, help='Specify payload ID (16 bytes maximal).', default
='UEFI')
124 parser
.add_argument('-q', '--Quiet', action
='store_true', help='Disable all build messages except FATAL ERRORS.')
126 args
= parser
.parse_args()
127 if args
.Macro
is not None:
128 for Argument
in args
.Macro
:
129 if Argument
.count('=') != 1:
130 print("Unknown variable passed in: %s"%Argument
)
131 raise Exception("ERROR: Unknown variable passed in: %s"%Argument
)
132 tokens
= Argument
.strip().split('=')
133 MacroList
[tokens
[0].upper()] = tokens
[1]
134 BuildUniversalPayload(args
, MacroList
)
135 print ("Successfully build Universal Payload")
137 if __name__
== '__main__':