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