]>
Commit | Line | Data |
---|---|---|
0c7f189e SB |
1 | # @file\r |
2 | # Script to Build ArmVirtPkg UEFI firmware\r | |
3 | #\r | |
4 | # Copyright (c) Microsoft Corporation.\r | |
5 | # SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
6 | ##\r | |
7 | import os\r | |
8 | import logging\r | |
9 | import io\r | |
10 | \r | |
11 | from edk2toolext.environment import shell_environment\r | |
12 | from edk2toolext.environment.uefi_build import UefiBuilder\r | |
13 | from edk2toolext.invocables.edk2_platform_build import BuildSettingsManager\r | |
14 | from edk2toolext.invocables.edk2_setup import SetupSettingsManager, RequiredSubmodule\r | |
15 | from edk2toolext.invocables.edk2_update import UpdateSettingsManager\r | |
16 | from edk2toolext.invocables.edk2_pr_eval import PrEvalSettingsManager\r | |
17 | from edk2toollib.utility_functions import RunCmd\r | |
18 | from edk2toollib.utility_functions import GetHostInfo\r | |
19 | \r | |
20 | # ####################################################################################### #\r | |
21 | # Common Configuration #\r | |
22 | # ####################################################################################### #\r | |
23 | \r | |
24 | \r | |
25 | class CommonPlatform():\r | |
26 | ''' Common settings for this platform. Define static data here and use\r | |
27 | for the different parts of stuart\r | |
28 | '''\r | |
29 | PackagesSupported = ("ArmVirtPkg",)\r | |
30 | ArchSupported = ("AARCH64", "ARM")\r | |
31 | TargetsSupported = ("DEBUG", "RELEASE", "NOOPT")\r | |
32 | Scopes = ('armvirt', 'edk2-build')\r | |
33 | WorkspaceRoot = os.path.realpath(os.path.join(\r | |
34 | os.path.dirname(os.path.abspath(__file__)), "..", ".."))\r | |
35 | \r | |
36 | # ####################################################################################### #\r | |
37 | # Configuration for Update & Setup #\r | |
38 | # ####################################################################################### #\r | |
39 | \r | |
40 | \r | |
41 | class SettingsManager(UpdateSettingsManager, SetupSettingsManager, PrEvalSettingsManager):\r | |
42 | \r | |
43 | def GetPackagesSupported(self):\r | |
44 | ''' return iterable of edk2 packages supported by this build.\r | |
45 | These should be edk2 workspace relative paths '''\r | |
46 | return CommonPlatform.PackagesSupported\r | |
47 | \r | |
48 | def GetArchitecturesSupported(self):\r | |
49 | ''' return iterable of edk2 architectures supported by this build '''\r | |
50 | return CommonPlatform.ArchSupported\r | |
51 | \r | |
52 | def GetTargetsSupported(self):\r | |
53 | ''' return iterable of edk2 target tags supported by this build '''\r | |
54 | return CommonPlatform.TargetsSupported\r | |
55 | \r | |
56 | def GetRequiredSubmodules(self):\r | |
57 | ''' return iterable containing RequiredSubmodule objects.\r | |
58 | If no RequiredSubmodules return an empty iterable\r | |
59 | '''\r | |
60 | rs = []\r | |
61 | \r | |
62 | # intentionally declare this one with recursive false to avoid overhead\r | |
63 | rs.append(RequiredSubmodule(\r | |
64 | "CryptoPkg/Library/OpensslLib/openssl", False))\r | |
65 | \r | |
66 | # To avoid maintenance of this file for every new submodule\r | |
67 | # lets just parse the .gitmodules and add each if not already in list.\r | |
68 | # The GetRequiredSubmodules is designed to allow a build to optimize\r | |
69 | # the desired submodules but it isn't necessary for this repository.\r | |
70 | result = io.StringIO()\r | |
71 | ret = RunCmd("git", "config --file .gitmodules --get-regexp path", workingdir=self.GetWorkspaceRoot(), outstream=result)\r | |
72 | # Cmd output is expected to look like:\r | |
73 | # submodule.CryptoPkg/Library/OpensslLib/openssl.path CryptoPkg/Library/OpensslLib/openssl\r | |
74 | # submodule.SoftFloat.path ArmPkg/Library/ArmSoftFloatLib/berkeley-softfloat-3\r | |
75 | if ret == 0:\r | |
76 | for line in result.getvalue().splitlines():\r | |
77 | _, _, path = line.partition(" ")\r | |
78 | if path is not None:\r | |
79 | if path not in [x.path for x in rs]:\r | |
80 | rs.append(RequiredSubmodule(path, True)) # add it with recursive since we don't know\r | |
81 | return rs\r | |
82 | \r | |
83 | def SetArchitectures(self, list_of_requested_architectures):\r | |
84 | ''' Confirm the requests architecture list is valid and configure SettingsManager\r | |
85 | to run only the requested architectures.\r | |
86 | \r | |
87 | Raise Exception if a list_of_requested_architectures is not supported\r | |
88 | '''\r | |
89 | unsupported = set(list_of_requested_architectures) - \\r | |
90 | set(self.GetArchitecturesSupported())\r | |
91 | if(len(unsupported) > 0):\r | |
92 | errorString = (\r | |
93 | "Unsupported Architecture Requested: " + " ".join(unsupported))\r | |
94 | logging.critical(errorString)\r | |
95 | raise Exception(errorString)\r | |
96 | self.ActualArchitectures = list_of_requested_architectures\r | |
97 | \r | |
98 | def GetWorkspaceRoot(self):\r | |
99 | ''' get WorkspacePath '''\r | |
100 | return CommonPlatform.WorkspaceRoot\r | |
101 | \r | |
102 | def GetActiveScopes(self):\r | |
103 | ''' return tuple containing scopes that should be active for this process '''\r | |
104 | \r | |
105 | scopes = CommonPlatform.Scopes\r | |
106 | ActualToolChainTag = shell_environment.GetBuildVars().GetValue("TOOL_CHAIN_TAG", "")\r | |
107 | \r | |
108 | if GetHostInfo().os.upper() == "LINUX" and ActualToolChainTag.upper().startswith("GCC"):\r | |
109 | if "AARCH64" in self.ActualArchitectures:\r | |
110 | scopes += ("gcc_aarch64_linux",)\r | |
111 | if "ARM" in self.ActualArchitectures:\r | |
112 | scopes += ("gcc_arm_linux",)\r | |
113 | return 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 | \r | |
134 | return build_these_packages\r | |
135 | \r | |
136 | def GetPlatformDscAndConfig(self) -> tuple:\r | |
137 | ''' If a platform desires to provide its DSC then Policy 4 will evaluate if\r | |
138 | any of the changes will be built in the dsc.\r | |
139 | \r | |
140 | The tuple should be (<workspace relative path to dsc file>, <input dictionary of dsc key value pairs>)\r | |
141 | '''\r | |
142 | return (os.path.join("ArmVirtPkg", "ArmVirtQemu.dsc"), {})\r | |
143 | \r | |
144 | \r | |
145 | # ####################################################################################### #\r | |
146 | # Actual Configuration for Platform Build #\r | |
147 | # ####################################################################################### #\r | |
148 | \r | |
149 | \r | |
150 | class PlatformBuilder(UefiBuilder, BuildSettingsManager):\r | |
151 | def __init__(self):\r | |
152 | UefiBuilder.__init__(self)\r | |
153 | \r | |
154 | def AddCommandLineOptions(self, parserObj):\r | |
155 | ''' Add command line options to the argparser '''\r | |
156 | parserObj.add_argument('-a', "--arch", dest="build_arch", type=str, default="AARCH64",\r | |
157 | help="Optional - Architecture to build. Default = AARCH64")\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(\r | |
163 | "TARGET_ARCH", args.build_arch.upper(), "From CmdLine")\r | |
164 | \r | |
165 | shell_environment.GetBuildVars().SetValue(\r | |
166 | "ACTIVE_PLATFORM", "ArmVirtPkg/ArmVirtQemu.dsc", "From CmdLine")\r | |
167 | \r | |
168 | def GetWorkspaceRoot(self):\r | |
169 | ''' get WorkspacePath '''\r | |
170 | return CommonPlatform.WorkspaceRoot\r | |
171 | \r | |
172 | def GetPackagesPath(self):\r | |
173 | ''' Return a list of workspace relative paths that should be mapped as edk2 PackagesPath '''\r | |
174 | return ()\r | |
175 | \r | |
176 | def GetActiveScopes(self):\r | |
177 | ''' return tuple containing scopes that should be active for this process '''\r | |
178 | scopes = CommonPlatform.Scopes\r | |
179 | ActualToolChainTag = shell_environment.GetBuildVars().GetValue("TOOL_CHAIN_TAG", "")\r | |
180 | Arch = shell_environment.GetBuildVars().GetValue("TARGET_ARCH", "")\r | |
181 | \r | |
182 | if GetHostInfo().os.upper() == "LINUX" and ActualToolChainTag.upper().startswith("GCC"):\r | |
183 | if "AARCH64" == Arch:\r | |
184 | scopes += ("gcc_aarch64_linux",)\r | |
185 | elif "ARM" == Arch:\r | |
186 | scopes += ("gcc_arm_linux",)\r | |
187 | return scopes\r | |
188 | \r | |
189 | def GetName(self):\r | |
190 | ''' Get the name of the repo, platform, or product being build '''\r | |
191 | ''' Used for naming the log file, among others '''\r | |
192 | # check the startup nsh flag and if set then rename the log file.\r | |
193 | # this helps in CI so we don't overwrite the build log since running\r | |
194 | # uses the stuart_build command.\r | |
195 | if(shell_environment.GetBuildVars().GetValue("MAKE_STARTUP_NSH", "FALSE") == "TRUE"):\r | |
196 | return "ArmVirtPkg_With_Run"\r | |
197 | return "ArmVirtPkg"\r | |
198 | \r | |
199 | def GetLoggingLevel(self, loggerType):\r | |
200 | ''' Get the logging level for a given type\r | |
201 | base == lowest logging level supported\r | |
202 | con == Screen logging\r | |
203 | txt == plain text file logging\r | |
204 | md == markdown file logging\r | |
205 | '''\r | |
206 | return logging.DEBUG\r | |
207 | \r | |
208 | def SetPlatformEnv(self):\r | |
209 | logging.debug("PlatformBuilder SetPlatformEnv")\r | |
210 | self.env.SetValue("PRODUCT_NAME", "ArmVirtQemu", "Platform Hardcoded")\r | |
211 | self.env.SetValue("MAKE_STARTUP_NSH", "FALSE", "Default to false")\r | |
212 | self.env.SetValue("QEMU_HEADLESS", "FALSE", "Default to false")\r | |
213 | return 0\r | |
214 | \r | |
215 | def PlatformPreBuild(self):\r | |
216 | return 0\r | |
217 | \r | |
218 | def PlatformPostBuild(self):\r | |
219 | return 0\r | |
220 | \r | |
221 | def FlashRomImage(self):\r | |
222 | VirtualDrive = os.path.join(self.env.GetValue(\r | |
223 | "BUILD_OUTPUT_BASE"), "VirtualDrive")\r | |
224 | os.makedirs(VirtualDrive, exist_ok=True)\r | |
225 | OutputPath_FV = os.path.join(\r | |
226 | self.env.GetValue("BUILD_OUTPUT_BASE"), "FV")\r | |
227 | Built_FV = os.path.join(OutputPath_FV, "QEMU_EFI.fd")\r | |
228 | \r | |
229 | # pad fd to 64mb\r | |
230 | with open(Built_FV, "ab") as fvfile:\r | |
231 | fvfile.seek(0, os.SEEK_END)\r | |
232 | additional = b'\0' * ((64 * 1024 * 1024)-fvfile.tell())\r | |
233 | fvfile.write(additional)\r | |
234 | \r | |
235 | # QEMU must be on that path\r | |
236 | \r | |
237 | # Unique Command and Args parameters per ARCH\r | |
238 | if (self.env.GetValue("TARGET_ARCH").upper() == "AARCH64"):\r | |
239 | cmd = "qemu-system-aarch64"\r | |
240 | args = "-M virt"\r | |
241 | args += " -cpu cortex-a57" # emulate cpu\r | |
242 | elif(self.env.GetValue("TARGET_ARCH").upper() == "ARM"):\r | |
243 | cmd = "qemu-system-arm"\r | |
244 | args = "-M virt"\r | |
245 | args += " -cpu cortex-a15" # emulate cpu\r | |
246 | else:\r | |
247 | raise NotImplementedError()\r | |
248 | \r | |
249 | # Common Args\r | |
250 | args += " -pflash " + Built_FV # path to fw\r | |
251 | args += " -m 1024" # 1gb memory\r | |
252 | # turn off network\r | |
253 | args += " -net none"\r | |
254 | # Serial messages out\r | |
255 | args += " -serial stdio"\r | |
256 | # Mount disk with startup.nsh\r | |
257 | args += f" -drive file=fat:rw:{VirtualDrive},format=raw,media=disk"\r | |
258 | \r | |
259 | # Conditional Args\r | |
260 | if (self.env.GetValue("QEMU_HEADLESS").upper() == "TRUE"):\r | |
261 | args += " -display none" # no graphics\r | |
262 | \r | |
263 | if (self.env.GetValue("MAKE_STARTUP_NSH").upper() == "TRUE"):\r | |
264 | f = open(os.path.join(VirtualDrive, "startup.nsh"), "w")\r | |
265 | f.write("BOOT SUCCESS !!! \n")\r | |
266 | # add commands here\r | |
267 | f.write("reset -s\n")\r | |
268 | f.close()\r | |
269 | \r | |
270 | ret = RunCmd(cmd, args)\r | |
271 | \r | |
272 | if ret == 0xc0000005:\r | |
273 | # for some reason getting a c0000005 on successful return\r | |
274 | return 0\r | |
275 | \r | |
276 | return ret\r |