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