]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/PlatformCI/PlatformBuild.py
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / OvmfPkg / PlatformCI / PlatformBuild.py
1 # @file
2 # Script to Build OVMF UEFI firmware
3 #
4 # Copyright (c) Microsoft Corporation.
5 # SPDX-License-Identifier: BSD-2-Clause-Patent
6 ##
7 import os
8 import logging
9 import io
10
11 from edk2toolext.environment import shell_environment
12 from edk2toolext.environment.uefi_build import UefiBuilder
13 from edk2toolext.invocables.edk2_platform_build import BuildSettingsManager
14 from edk2toolext.invocables.edk2_setup import SetupSettingsManager, RequiredSubmodule
15 from edk2toolext.invocables.edk2_update import UpdateSettingsManager
16 from edk2toolext.invocables.edk2_pr_eval import PrEvalSettingsManager
17 from edk2toollib.utility_functions import RunCmd
18
19
20 # ####################################################################################### #
21 # Common Configuration #
22 # ####################################################################################### #
23 class CommonPlatform():
24 ''' Common settings for this platform. Define static data here and use
25 for the different parts of stuart
26 '''
27 PackagesSupported = ("OvmfPkg",)
28 ArchSupported = ("IA32", "X64")
29 TargetsSupported = ("DEBUG", "RELEASE", "NOOPT")
30 Scopes = ('ovmf', 'edk2-build')
31 WorkspaceRoot = os.path.realpath(os.path.join(
32 os.path.dirname(os.path.abspath(__file__)), "..", ".."))
33
34 @classmethod
35 def GetDscName(cls, ArchCsv: str) -> str:
36 ''' return the DSC given the architectures requested.
37
38 ArchCsv: csv string containing all architectures to build
39 '''
40 dsc = "OvmfPkg"
41 if "IA32" in ArchCsv.upper().split(","):
42 dsc += "Ia32"
43 if "X64" in ArchCsv.upper().split(","):
44 dsc += "X64"
45 dsc += ".dsc"
46 return dsc
47
48
49 # ####################################################################################### #
50 # Configuration for Update & Setup #
51 # ####################################################################################### #
52 class SettingsManager(UpdateSettingsManager, SetupSettingsManager, PrEvalSettingsManager):
53
54 def GetPackagesSupported(self):
55 ''' return iterable of edk2 packages supported by this build.
56 These should be edk2 workspace relative paths '''
57 return CommonPlatform.PackagesSupported
58
59 def GetArchitecturesSupported(self):
60 ''' return iterable of edk2 architectures supported by this build '''
61 return CommonPlatform.ArchSupported
62
63 def GetTargetsSupported(self):
64 ''' return iterable of edk2 target tags supported by this build '''
65 return CommonPlatform.TargetsSupported
66
67 def GetRequiredSubmodules(self):
68 ''' return iterable containing RequiredSubmodule objects.
69 If no RequiredSubmodules return an empty iterable
70 '''
71 rs = []
72
73 # intentionally declare this one with recursive false to avoid overhead
74 rs.append(RequiredSubmodule(
75 "CryptoPkg/Library/OpensslLib/openssl", False))
76
77 # To avoid maintenance of this file for every new submodule
78 # lets just parse the .gitmodules and add each if not already in list.
79 # The GetRequiredSubmodules is designed to allow a build to optimize
80 # the desired submodules but it isn't necessary for this repository.
81 result = io.StringIO()
82 ret = RunCmd("git", "config --file .gitmodules --get-regexp path", workingdir=self.GetWorkspaceRoot(), outstream=result)
83 # Cmd output is expected to look like:
84 # submodule.CryptoPkg/Library/OpensslLib/openssl.path CryptoPkg/Library/OpensslLib/openssl
85 # submodule.SoftFloat.path ArmPkg/Library/ArmSoftFloatLib/berkeley-softfloat-3
86 if ret == 0:
87 for line in result.getvalue().splitlines():
88 _, _, path = line.partition(" ")
89 if path is not None:
90 if path not in [x.path for x in rs]:
91 rs.append(RequiredSubmodule(path, True)) # add it with recursive since we don't know
92 return rs
93
94 def SetArchitectures(self, list_of_requested_architectures):
95 ''' Confirm the requests architecture list is valid and configure SettingsManager
96 to run only the requested architectures.
97
98 Raise Exception if a list_of_requested_architectures is not supported
99 '''
100 unsupported = set(list_of_requested_architectures) - set(self.GetArchitecturesSupported())
101 if(len(unsupported) > 0):
102 errorString = ( "Unsupported Architecture Requested: " + " ".join(unsupported))
103 logging.critical( errorString )
104 raise Exception( errorString )
105 self.ActualArchitectures = list_of_requested_architectures
106
107 def GetWorkspaceRoot(self):
108 ''' get WorkspacePath '''
109 return CommonPlatform.WorkspaceRoot
110
111 def GetActiveScopes(self):
112 ''' return tuple containing scopes that should be active for this process '''
113 return CommonPlatform.Scopes
114
115 def FilterPackagesToTest(self, changedFilesList: list, potentialPackagesList: list) -> list:
116 ''' Filter other cases that this package should be built
117 based on changed files. This should cover things that can't
118 be detected as dependencies. '''
119 build_these_packages = []
120 possible_packages = potentialPackagesList.copy()
121 for f in changedFilesList:
122 # BaseTools files that might change the build
123 if "BaseTools" in f:
124 if os.path.splitext(f) not in [".txt", ".md"]:
125 build_these_packages = possible_packages
126 break
127
128 # if the azure pipeline platform template file changed
129 if "platform-build-run-steps.yml" in f:
130 build_these_packages = possible_packages
131 break
132
133 return build_these_packages
134
135 def GetPlatformDscAndConfig(self) -> tuple:
136 ''' If a platform desires to provide its DSC then Policy 4 will evaluate if
137 any of the changes will be built in the dsc.
138
139 The tuple should be (<workspace relative path to dsc file>, <input dictionary of dsc key value pairs>)
140 '''
141 dsc = CommonPlatform.GetDscName(",".join(self.ActualArchitectures))
142 return (f"OvmfPkg/{dsc}", {})
143
144
145 # ####################################################################################### #
146 # Actual Configuration for Platform Build #
147 # ####################################################################################### #
148 class PlatformBuilder( UefiBuilder, BuildSettingsManager):
149 def __init__(self):
150 UefiBuilder.__init__(self)
151
152 def AddCommandLineOptions(self, parserObj):
153 ''' Add command line options to the argparser '''
154 parserObj.add_argument('-a', "--arch", dest="build_arch", type=str, default="IA32,X64",
155 help="Optional - CSV of architecture to build. IA32 will use IA32 for Pei & Dxe. "
156 "X64 will use X64 for both PEI and DXE. IA32,X64 will use IA32 for PEI and "
157 "X64 for DXE. default is IA32,X64")
158
159 def RetrieveCommandLineOptions(self, args):
160 ''' Retrieve command line options from the argparser '''
161
162 shell_environment.GetBuildVars().SetValue("TARGET_ARCH"," ".join(args.build_arch.upper().split(",")), "From CmdLine")
163 dsc = CommonPlatform.GetDscName(args.build_arch)
164 shell_environment.GetBuildVars().SetValue("ACTIVE_PLATFORM", f"OvmfPkg/{dsc}", "From CmdLine")
165
166 def GetWorkspaceRoot(self):
167 ''' get WorkspacePath '''
168 return CommonPlatform.WorkspaceRoot
169
170 def GetPackagesPath(self):
171 ''' Return a list of workspace relative paths that should be mapped as edk2 PackagesPath '''
172 return ()
173
174 def GetActiveScopes(self):
175 ''' return tuple containing scopes that should be active for this process '''
176 return CommonPlatform.Scopes
177
178 def GetName(self):
179 ''' Get the name of the repo, platform, or product being build '''
180 ''' Used for naming the log file, among others '''
181 # check the startup nsh flag and if set then rename the log file.
182 # this helps in CI so we don't overwrite the build log since running
183 # uses the stuart_build command.
184 if(shell_environment.GetBuildVars().GetValue("MAKE_STARTUP_NSH", "FALSE") == "TRUE"):
185 return "OvmfPkg_With_Run"
186 return "OvmfPkg"
187
188 def GetLoggingLevel(self, loggerType):
189 ''' Get the logging level for a given type
190 base == lowest logging level supported
191 con == Screen logging
192 txt == plain text file logging
193 md == markdown file logging
194 '''
195 return logging.DEBUG
196
197 def SetPlatformEnv(self):
198 logging.debug("PlatformBuilder SetPlatformEnv")
199 self.env.SetValue("PRODUCT_NAME", "OVMF", "Platform Hardcoded")
200 self.env.SetValue("MAKE_STARTUP_NSH", "FALSE", "Default to false")
201 self.env.SetValue("QEMU_HEADLESS", "FALSE", "Default to false")
202 return 0
203
204 def PlatformPreBuild(self):
205 return 0
206
207 def PlatformPostBuild(self):
208 return 0
209
210 def FlashRomImage(self):
211 VirtualDrive = os.path.join(self.env.GetValue("BUILD_OUTPUT_BASE"), "VirtualDrive")
212 os.makedirs(VirtualDrive, exist_ok=True)
213 OutputPath_FV = os.path.join(self.env.GetValue("BUILD_OUTPUT_BASE"), "FV")
214
215 #
216 # QEMU must be on the path
217 #
218 cmd = "qemu-system-x86_64"
219 args = "-debugcon stdio" # write messages to stdio
220 args += " -global isa-debugcon.iobase=0x402" # debug messages out thru virtual io port
221 args += " -net none" # turn off network
222 args += f" -drive file=fat:rw:{VirtualDrive},format=raw,media=disk" # Mount disk with startup.nsh
223
224 if (self.env.GetValue("QEMU_HEADLESS").upper() == "TRUE"):
225 args += " -display none" # no graphics
226
227 if (self.env.GetBuildValue("SMM_REQUIRE") == "1"):
228 args += " -machine q35,smm=on" #,accel=(tcg|kvm)"
229 #args += " -m ..."
230 #args += " -smp ..."
231 args += " -global driver=cfi.pflash01,property=secure,value=on"
232 args += " -drive if=pflash,format=raw,unit=0,file=" + os.path.join(OutputPath_FV, "OVMF_CODE.fd") + ",readonly=on"
233 args += " -drive if=pflash,format=raw,unit=1,file=" + os.path.join(OutputPath_FV, "OVMF_VARS.fd")
234 else:
235 args += " -pflash " + os.path.join(OutputPath_FV, "OVMF.fd") # path to firmware
236
237
238 if (self.env.GetValue("MAKE_STARTUP_NSH").upper() == "TRUE"):
239 f = open(os.path.join(VirtualDrive, "startup.nsh"), "w")
240 f.write("BOOT SUCCESS !!! \n")
241 ## add commands here
242 f.write("reset -s\n")
243 f.close()
244
245 ret = RunCmd(cmd, args)
246
247 if ret == 0xc0000005:
248 #for some reason getting a c0000005 on successful return
249 return 0
250
251 return ret
252
253
254