--- /dev/null
+## @file\r
+# Core CI configuration for ArmVirtPkg\r
+#\r
+# ArmVirtPkg is part of Platform Ci for builds so this is only\r
+# used for code analysis.\r
+#\r
+# Copyright (c) Microsoft Corporation\r
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
+##\r
+{\r
+ ## options defined .pytool/Plugin/CompilerPlugin\r
+ "CompilerPlugin": {\r
+ "DscPath": "" # Don't support this test\r
+ },\r
+\r
+ ## options defined .pytool/Plugin/HostUnitTestCompilerPlugin\r
+ "HostUnitTestCompilerPlugin": {\r
+ "DscPath": "" # Don't support this test\r
+ },\r
+\r
+ ## options defined .pytool/Plugin/CharEncodingCheck\r
+ "CharEncodingCheck": {\r
+ "IgnoreFiles": []\r
+ },\r
+\r
+ ## options defined .pytool/Plugin/DependencyCheck\r
+ "DependencyCheck": {\r
+ "AcceptableDependencies": [\r
+ "MdePkg/MdePkg.dec",\r
+ "MdeModulePkg/MdeModulePkg.dec",\r
+ "ArmVirtPkg/ArmVirtPkg.dec",\r
+ "NetworkPkg/NetworkPkg.dec",\r
+ "ArmPkg/ArmPkg.dec",\r
+ "OvmfPkg/OvmfPkg.dec",\r
+ "EmbeddedPkg/EmbeddedPkg.dec",\r
+ "ArmPlatformPkg/ArmPlatformPkg.dec",\r
+ "SecurityPkg/SecurityPkg.dec",\r
+ "ShellPkg/ShellPkg.dec" #Is this ok?\r
+ ],\r
+ # For host based unit tests\r
+ "AcceptableDependencies-HOST_APPLICATION":[\r
+ "UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec"\r
+ ],\r
+ # For UEFI shell based apps\r
+ "AcceptableDependencies-UEFI_APPLICATION":[\r
+\r
+ ],\r
+ "IgnoreInf": []\r
+ },\r
+\r
+ ## options defined .pytool/Plugin/DscCompleteCheck\r
+ "DscCompleteCheck": {\r
+ "IgnoreInf": [""],\r
+ "DscPath": "" # Don't support this test\r
+ },\r
+\r
+ ## options defined .pytool/Plugin/HostUnitTestDscCompleteCheck\r
+ "HostUnitTestDscCompleteCheck": {\r
+ "IgnoreInf": [""],\r
+ "DscPath": "" # Don't support this test\r
+ },\r
+\r
+ ## options defined .pytool/Plugin/GuidCheck\r
+ "GuidCheck": {\r
+ "IgnoreGuidName": [],\r
+ "IgnoreGuidValue": [],\r
+ "IgnoreFoldersAndFiles": [],\r
+ "IgnoreDuplicates": [],\r
+ },\r
+\r
+ ## options defined .pytool/Plugin/LibraryClassCheck\r
+ "LibraryClassCheck": {\r
+ "IgnoreHeaderFile": []\r
+ },\r
+\r
+ ## options defined .pytool/Plugin/SpellCheck\r
+ "SpellCheck": {\r
+ "AuditOnly": False, # Fails right now with over 270 errors\r
+ "IgnoreFiles": [], # use gitignore syntax to ignore errors in matching files\r
+ "ExtendWords": [\r
+ "setjump",\r
+ "plong",\r
+ "lparam",\r
+ "lpdword",\r
+ "lpthread",\r
+ "lresult",\r
+ "bootable",\r
+ "bsymbolic",\r
+ "endiannness",\r
+ "fvmain",\r
+ "multiboot",\r
+ "qemu's",\r
+ "ramdisk",\r
+ "ramfb",\r
+ "unbootable",\r
+ "virt's",\r
+ "werror",\r
+ "xenio"\r
+ ], # words to extend to the dictionary for this package\r
+ "IgnoreStandardPaths": [], # Standard Plugin defined paths that should be ignore\r
+ "AdditionalIncludePaths": [] # Additional paths to spell check (wildcards supported)\r
+ }\r
+}\r
--- /dev/null
+# @file\r
+# Script to Build ArmVirtPkg UEFI firmware\r
+#\r
+# Copyright (c) Microsoft Corporation.\r
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
+##\r
+import os\r
+import logging\r
+import io\r
+\r
+from edk2toolext.environment import shell_environment\r
+from edk2toolext.environment.uefi_build import UefiBuilder\r
+from edk2toolext.invocables.edk2_platform_build import BuildSettingsManager\r
+from edk2toolext.invocables.edk2_setup import SetupSettingsManager, RequiredSubmodule\r
+from edk2toolext.invocables.edk2_update import UpdateSettingsManager\r
+from edk2toolext.invocables.edk2_pr_eval import PrEvalSettingsManager\r
+from edk2toollib.utility_functions import RunCmd\r
+from edk2toollib.utility_functions import GetHostInfo\r
+\r
+# ####################################################################################### #\r
+# Common Configuration #\r
+# ####################################################################################### #\r
+\r
+\r
+class CommonPlatform():\r
+ ''' Common settings for this platform. Define static data here and use\r
+ for the different parts of stuart\r
+ '''\r
+ PackagesSupported = ("ArmVirtPkg",)\r
+ ArchSupported = ("AARCH64", "ARM")\r
+ TargetsSupported = ("DEBUG", "RELEASE", "NOOPT")\r
+ Scopes = ('armvirt', 'edk2-build')\r
+ WorkspaceRoot = os.path.realpath(os.path.join(\r
+ os.path.dirname(os.path.abspath(__file__)), "..", ".."))\r
+\r
+ # ####################################################################################### #\r
+ # Configuration for Update & Setup #\r
+ # ####################################################################################### #\r
+\r
+\r
+class SettingsManager(UpdateSettingsManager, SetupSettingsManager, PrEvalSettingsManager):\r
+\r
+ def GetPackagesSupported(self):\r
+ ''' return iterable of edk2 packages supported by this build.\r
+ These should be edk2 workspace relative paths '''\r
+ return CommonPlatform.PackagesSupported\r
+\r
+ def GetArchitecturesSupported(self):\r
+ ''' return iterable of edk2 architectures supported by this build '''\r
+ return CommonPlatform.ArchSupported\r
+\r
+ def GetTargetsSupported(self):\r
+ ''' return iterable of edk2 target tags supported by this build '''\r
+ return CommonPlatform.TargetsSupported\r
+\r
+ def GetRequiredSubmodules(self):\r
+ ''' return iterable containing RequiredSubmodule objects.\r
+ If no RequiredSubmodules return an empty iterable\r
+ '''\r
+ rs = []\r
+\r
+ # intentionally declare this one with recursive false to avoid overhead\r
+ rs.append(RequiredSubmodule(\r
+ "CryptoPkg/Library/OpensslLib/openssl", False))\r
+\r
+ # To avoid maintenance of this file for every new submodule\r
+ # lets just parse the .gitmodules and add each if not already in list.\r
+ # The GetRequiredSubmodules is designed to allow a build to optimize\r
+ # the desired submodules but it isn't necessary for this repository.\r
+ result = io.StringIO()\r
+ ret = RunCmd("git", "config --file .gitmodules --get-regexp path", workingdir=self.GetWorkspaceRoot(), outstream=result)\r
+ # Cmd output is expected to look like:\r
+ # submodule.CryptoPkg/Library/OpensslLib/openssl.path CryptoPkg/Library/OpensslLib/openssl\r
+ # submodule.SoftFloat.path ArmPkg/Library/ArmSoftFloatLib/berkeley-softfloat-3\r
+ if ret == 0:\r
+ for line in result.getvalue().splitlines():\r
+ _, _, path = line.partition(" ")\r
+ if path is not None:\r
+ if path not in [x.path for x in rs]:\r
+ rs.append(RequiredSubmodule(path, True)) # add it with recursive since we don't know\r
+ return rs\r
+\r
+ def SetArchitectures(self, list_of_requested_architectures):\r
+ ''' Confirm the requests architecture list is valid and configure SettingsManager\r
+ to run only the requested architectures.\r
+\r
+ Raise Exception if a list_of_requested_architectures is not supported\r
+ '''\r
+ unsupported = set(list_of_requested_architectures) - \\r
+ set(self.GetArchitecturesSupported())\r
+ if(len(unsupported) > 0):\r
+ errorString = (\r
+ "Unsupported Architecture Requested: " + " ".join(unsupported))\r
+ logging.critical(errorString)\r
+ raise Exception(errorString)\r
+ self.ActualArchitectures = list_of_requested_architectures\r
+\r
+ def GetWorkspaceRoot(self):\r
+ ''' get WorkspacePath '''\r
+ return CommonPlatform.WorkspaceRoot\r
+\r
+ def GetActiveScopes(self):\r
+ ''' return tuple containing scopes that should be active for this process '''\r
+\r
+ scopes = CommonPlatform.Scopes\r
+ ActualToolChainTag = shell_environment.GetBuildVars().GetValue("TOOL_CHAIN_TAG", "")\r
+\r
+ if GetHostInfo().os.upper() == "LINUX" and ActualToolChainTag.upper().startswith("GCC"):\r
+ if "AARCH64" in self.ActualArchitectures:\r
+ scopes += ("gcc_aarch64_linux",)\r
+ if "ARM" in self.ActualArchitectures:\r
+ scopes += ("gcc_arm_linux",)\r
+ return scopes\r
+\r
+ def FilterPackagesToTest(self, changedFilesList: list, potentialPackagesList: list) -> list:\r
+ ''' Filter other cases that this package should be built\r
+ based on changed files. This should cover things that can't\r
+ be detected as dependencies. '''\r
+ build_these_packages = []\r
+ possible_packages = potentialPackagesList.copy()\r
+ for f in changedFilesList:\r
+ # BaseTools files that might change the build\r
+ if "BaseTools" in f:\r
+ if os.path.splitext(f) not in [".txt", ".md"]:\r
+ build_these_packages = possible_packages\r
+ break\r
+\r
+ # if the azure pipeline platform template file changed\r
+ if "platform-build-run-steps.yml" in f:\r
+ build_these_packages = possible_packages\r
+ break\r
+\r
+\r
+ return build_these_packages\r
+\r
+ def GetPlatformDscAndConfig(self) -> tuple:\r
+ ''' If a platform desires to provide its DSC then Policy 4 will evaluate if\r
+ any of the changes will be built in the dsc.\r
+\r
+ The tuple should be (<workspace relative path to dsc file>, <input dictionary of dsc key value pairs>)\r
+ '''\r
+ return (os.path.join("ArmVirtPkg", "ArmVirtQemu.dsc"), {})\r
+\r
+\r
+ # ####################################################################################### #\r
+ # Actual Configuration for Platform Build #\r
+ # ####################################################################################### #\r
+\r
+\r
+class PlatformBuilder(UefiBuilder, BuildSettingsManager):\r
+ def __init__(self):\r
+ UefiBuilder.__init__(self)\r
+\r
+ def AddCommandLineOptions(self, parserObj):\r
+ ''' Add command line options to the argparser '''\r
+ parserObj.add_argument('-a', "--arch", dest="build_arch", type=str, default="AARCH64",\r
+ help="Optional - Architecture to build. Default = AARCH64")\r
+\r
+ def RetrieveCommandLineOptions(self, args):\r
+ ''' Retrieve command line options from the argparser '''\r
+\r
+ shell_environment.GetBuildVars().SetValue(\r
+ "TARGET_ARCH", args.build_arch.upper(), "From CmdLine")\r
+\r
+ shell_environment.GetBuildVars().SetValue(\r
+ "ACTIVE_PLATFORM", "ArmVirtPkg/ArmVirtQemu.dsc", "From CmdLine")\r
+\r
+ def GetWorkspaceRoot(self):\r
+ ''' get WorkspacePath '''\r
+ return CommonPlatform.WorkspaceRoot\r
+\r
+ def GetPackagesPath(self):\r
+ ''' Return a list of workspace relative paths that should be mapped as edk2 PackagesPath '''\r
+ return ()\r
+\r
+ def GetActiveScopes(self):\r
+ ''' return tuple containing scopes that should be active for this process '''\r
+ scopes = CommonPlatform.Scopes\r
+ ActualToolChainTag = shell_environment.GetBuildVars().GetValue("TOOL_CHAIN_TAG", "")\r
+ Arch = shell_environment.GetBuildVars().GetValue("TARGET_ARCH", "")\r
+\r
+ if GetHostInfo().os.upper() == "LINUX" and ActualToolChainTag.upper().startswith("GCC"):\r
+ if "AARCH64" == Arch:\r
+ scopes += ("gcc_aarch64_linux",)\r
+ elif "ARM" == Arch:\r
+ scopes += ("gcc_arm_linux",)\r
+ return scopes\r
+\r
+ def GetName(self):\r
+ ''' Get the name of the repo, platform, or product being build '''\r
+ ''' Used for naming the log file, among others '''\r
+ # check the startup nsh flag and if set then rename the log file.\r
+ # this helps in CI so we don't overwrite the build log since running\r
+ # uses the stuart_build command.\r
+ if(shell_environment.GetBuildVars().GetValue("MAKE_STARTUP_NSH", "FALSE") == "TRUE"):\r
+ return "ArmVirtPkg_With_Run"\r
+ return "ArmVirtPkg"\r
+\r
+ def GetLoggingLevel(self, loggerType):\r
+ ''' Get the logging level for a given type\r
+ base == lowest logging level supported\r
+ con == Screen logging\r
+ txt == plain text file logging\r
+ md == markdown file logging\r
+ '''\r
+ return logging.DEBUG\r
+\r
+ def SetPlatformEnv(self):\r
+ logging.debug("PlatformBuilder SetPlatformEnv")\r
+ self.env.SetValue("PRODUCT_NAME", "ArmVirtQemu", "Platform Hardcoded")\r
+ self.env.SetValue("MAKE_STARTUP_NSH", "FALSE", "Default to false")\r
+ self.env.SetValue("QEMU_HEADLESS", "FALSE", "Default to false")\r
+ return 0\r
+\r
+ def PlatformPreBuild(self):\r
+ return 0\r
+\r
+ def PlatformPostBuild(self):\r
+ return 0\r
+\r
+ def FlashRomImage(self):\r
+ VirtualDrive = os.path.join(self.env.GetValue(\r
+ "BUILD_OUTPUT_BASE"), "VirtualDrive")\r
+ os.makedirs(VirtualDrive, exist_ok=True)\r
+ OutputPath_FV = os.path.join(\r
+ self.env.GetValue("BUILD_OUTPUT_BASE"), "FV")\r
+ Built_FV = os.path.join(OutputPath_FV, "QEMU_EFI.fd")\r
+\r
+ # pad fd to 64mb\r
+ with open(Built_FV, "ab") as fvfile:\r
+ fvfile.seek(0, os.SEEK_END)\r
+ additional = b'\0' * ((64 * 1024 * 1024)-fvfile.tell())\r
+ fvfile.write(additional)\r
+\r
+ # QEMU must be on that path\r
+\r
+ # Unique Command and Args parameters per ARCH\r
+ if (self.env.GetValue("TARGET_ARCH").upper() == "AARCH64"):\r
+ cmd = "qemu-system-aarch64"\r
+ args = "-M virt"\r
+ args += " -cpu cortex-a57" # emulate cpu\r
+ elif(self.env.GetValue("TARGET_ARCH").upper() == "ARM"):\r
+ cmd = "qemu-system-arm"\r
+ args = "-M virt"\r
+ args += " -cpu cortex-a15" # emulate cpu\r
+ else:\r
+ raise NotImplementedError()\r
+\r
+ # Common Args\r
+ args += " -pflash " + Built_FV # path to fw\r
+ args += " -m 1024" # 1gb memory\r
+ # turn off network\r
+ args += " -net none"\r
+ # Serial messages out\r
+ args += " -serial stdio"\r
+ # Mount disk with startup.nsh\r
+ args += f" -drive file=fat:rw:{VirtualDrive},format=raw,media=disk"\r
+\r
+ # Conditional Args\r
+ if (self.env.GetValue("QEMU_HEADLESS").upper() == "TRUE"):\r
+ args += " -display none" # no graphics\r
+\r
+ if (self.env.GetValue("MAKE_STARTUP_NSH").upper() == "TRUE"):\r
+ f = open(os.path.join(VirtualDrive, "startup.nsh"), "w")\r
+ f.write("BOOT SUCCESS !!! \n")\r
+ # add commands here\r
+ f.write("reset -s\n")\r
+ f.close()\r
+\r
+ ret = RunCmd(cmd, args)\r
+\r
+ if ret == 0xc0000005:\r
+ # for some reason getting a c0000005 on successful return\r
+ return 0\r
+\r
+ return ret\r
--- /dev/null
+# ArmVirtPkg - Platform CI\r
+\r
+This Readme.md describes the Azure DevOps based Platform CI for ArmVirtPkg and how\r
+to use the same Pytools based build infrastructure locally.\r
+\r
+## Supported Configuration Details\r
+\r
+This solution for building and running ArmVirtPkg has only been validated with Ubuntu\r
+18.04 and the GCC5 toolchain. Two different firmware builds are supported and are\r
+described below.\r
+\r
+| Configuration name | Architecture | DSC File |Additional Flags |\r
+| :---------- | :----- | :----- | :---- |\r
+| AARCH64 | AARCH64 | ArmVirtQemu.dsc | None |\r
+| ARM | ARM | ArmVirtQemu.dsc | None |\r
+\r
+## EDK2 Developer environment\r
+\r
+- [Python 3.8.x - Download & Install](https://www.python.org/downloads/)\r
+- [GIT - Download & Install](https://git-scm.com/download/)\r
+- [QEMU - Download, Install, and add to your path](https://www.qemu.org/download/)\r
+- [Edk2 Source](https://github.com/tianocore/edk2)\r
+- Additional packages found necessary for Ubuntu 18.04\r
+ - apt-get install gcc g++ make uuid-dev\r
+\r
+Note: edksetup, Submodule initialization and manual installation of NASM, iASL, or\r
+the required cross-compiler toolchains are **not** required, this is handled by the\r
+Pytools build system.\r
+\r
+## Building with Pytools for ArmVirtPkg\r
+\r
+1. [Optional] Create a Python Virtual Environment - generally once per workspace\r
+\r
+ ``` bash\r
+ python -m venv <name of virtual environment>\r
+ ```\r
+\r
+2. [Optional] Activate Virtual Environment - each time new shell opened\r
+ - Windows\r
+\r
+ ``` bash\r
+ <name of virtual environment>/Scripts/activate.bat\r
+ ```\r
+\r
+ - Linux\r
+\r
+ ```bash\r
+ source <name of virtual environment>/bin/activate\r
+ ```\r
+\r
+3. Install Pytools - generally once per virtual env or whenever pip-requirements.txt changes\r
+\r
+ ``` bash\r
+ pip install --upgrade -r pip-requirements.txt\r
+ ```\r
+\r
+4. Initialize & Update Submodules - only when submodules updated\r
+\r
+ ``` bash\r
+ stuart_setup -c ArmVirtPkg/PlatformCI/PlatformBuild.py TOOL_CHAIN_TAG=<TOOL_CHAIN_TAG> -a <TARGET_ARCH>\r
+ ```\r
+\r
+5. Initialize & Update Dependencies - only as needed when ext_deps change\r
+\r
+ ``` bash\r
+ stuart_update -c ArmVirtPkg/PlatformCI/PlatformBuild.py TOOL_CHAIN_TAG=<TOOL_CHAIN_TAG> -a <TARGET_ARCH>\r
+ ```\r
+\r
+6. Compile the basetools if necessary - only when basetools C source files change\r
+\r
+ ``` bash\r
+ python BaseTools/Edk2ToolsBuild.py -t <ToolChainTag>\r
+ ```\r
+\r
+7. Compile Firmware\r
+\r
+ ``` bash\r
+ stuart_build -c ArmVirtPkg/PlatformCI/PlatformBuild.py TOOL_CHAIN_TAG=<TOOL_CHAIN_TAG> -a <TARGET_ARCH>\r
+ ```\r
+\r
+ - use `stuart_build -c ArmVirtPkg/PlatformCI/PlatformBuild.py -h` option to see additional\r
+ options like `--clean`\r
+\r
+8. Running Emulator\r
+ - You can add `--FlashRom` to the end of your build command and the emulator will run after the\r
+ build is complete.\r
+ - or use the `--FlashOnly` feature to just run the emulator.\r
+\r
+ ``` bash\r
+ stuart_build -c ArmVirtPkg/PlatformCI/PlatformBuild.py TOOL_CHAIN_TAG=<TOOL_CHAIN_TAG> -a <TARGET_ARCH> --FlashOnly\r
+ ```\r
+\r
+### Notes\r
+\r
+1. Including the expected build architecture and toolchain to the _stuart_update_ command is critical.\r
+ This is because there are extra scopes and tools that will be resolved during the update step that\r
+ need to match your build step.\r
+2. Configuring *ACTIVE_PLATFORM* and *TARGET_ARCH* in Conf/target.txt is **not** required. This\r
+ environment is set by PlatformBuild.py based upon the `[-a <TARGET_ARCH>]` parameter.\r
+3. QEMU must be on your path. On Windows this is a manual process and not part of the QEMU installer.\r
+\r
+**NOTE:** Logging the execution output will be in the normal stuart log as well as to your console.\r
+\r
+### Custom Build Options\r
+\r
+**MAKE_STARTUP_NSH=TRUE** will output a *startup.nsh* file to the location mapped as fs0. This is\r
+used in CI in combination with the `--FlashOnly` feature to run QEMU to the UEFI shell and then execute\r
+the contents of *startup.nsh*.\r
+\r
+**QEMU_HEADLESS=TRUE** Since CI servers run headless QEMU must be told to run with no display otherwise\r
+an error occurs. Locally you don't need to set this.\r
+\r
+### Passing Build Defines\r
+\r
+To pass build defines through _stuart_build_, prepend `BLD_*_`to the define name and pass it on the\r
+command-line. _stuart_build_ currently requires values to be assigned, so add an`=1` suffix for bare defines.\r
+For example, to enable the TPM2 support, instead of the traditional "-D TPM2_ENABLE=TRUE", the stuart_build\r
+command-line would be:\r
+\r
+`stuart_build -c ArmVirtPkg/PlatformCI/PlatformBuild.py BLD_*_TPM2_ENABLE=TRUE`\r
+\r
+## References\r
+\r
+- [Installing and using Pytools](https://github.com/tianocore/edk2-pytool-extensions/blob/master/docs/using.md#installing)\r
+- More on [python virtual environments](https://docs.python.org/3/library/venv.html)\r