From 63ead66a0f531ac13be9d483926d8936bb05823b Mon Sep 17 00:00:00 2001 From: Joey Vagedes Date: Thu, 22 Feb 2024 15:13:18 -0800 Subject: [PATCH] Use qemu external dependency (#851) ## Description Use an external dependency for qemu rather than relying on it being installed by the user. - [ ] Impacts functionality? - **Functionality** - Does the change ultimately impact how firmware functions? - Examples: Add a new library, publish a new PPI, update an algorithm, ... - [ ] Impacts security? - **Security** - Does the change have a direct security impact on an application, flow, or firmware? - Examples: Crypto algorithm change, buffer overflow fix, parameter validation improvement, ... - [ ] Breaking change? - **Breaking change** - Will anyone consuming this change experience a break in build or boot behavior? - Examples: Add a new library class, move a module to a different repo, call a function in a new library class in a pre-existing module, ... - [ ] Includes tests? - **Tests** - Does the change include any explicit test code? - Examples: Unit tests, integration tests, robot tests, ... - [ ] Includes documentation? - **Documentation** - Does the change contain explicit documentation additions outside direct code modifications (and comments)? - Examples: Update readme file, add feature readme file, link to documentation on an a separate Web page, ... ## How This Was Tested Ensured Boot to shell and Boot to windows using the Windows and Linux qemu external dependencies. Verified TPM Replay functionality continued to work as expected. ## Integration Instructions N/A --- .azurepipelines/Platform-Build-VS.yml | 6 ------ .../Plugins/QemuRunner/QemuRunner.py | 14 ++++++++++++-- .../Plugins/QemuRunner/QemuRunner.py | 13 ++++++++++--- QemuPkg/Binaries/qemu-linux_ext_dep.yaml | 19 +++++++++++++++++++ QemuPkg/Binaries/qemu-windows_ext_dep.yaml | 19 +++++++++++++++++++ 5 files changed, 60 insertions(+), 11 deletions(-) create mode 100644 QemuPkg/Binaries/qemu-linux_ext_dep.yaml create mode 100644 QemuPkg/Binaries/qemu-windows_ext_dep.yaml diff --git a/.azurepipelines/Platform-Build-VS.yml b/.azurepipelines/Platform-Build-VS.yml index 149ab432..84239549 100644 --- a/.azurepipelines/Platform-Build-VS.yml +++ b/.azurepipelines/Platform-Build-VS.yml @@ -20,12 +20,6 @@ jobs: - template: Platform-Build-Job.yml parameters: extra_install_step: - - powershell: | - $qemuVersion = (Get-Content -Path WindowsQemuVersion.json | ConvertFrom-Json).version - choco install qemu --version=$qemuVersion; Write-Host "##vso[task.prependpath]c:\Program Files\qemu" - workingDirectory: .azurepipelines/ - displayName: Install QEMU and Set QEMU on path # friendly name displayed in the UI - condition: and(gt(variables.pkg_count, 0), succeeded()) - template: Steps/InstallCoverageTools.yml@mu_devops tool_chain_tag: 'VS2022' vm_image: $(vm_image) diff --git a/Platforms/QemuQ35Pkg/Plugins/QemuRunner/QemuRunner.py b/Platforms/QemuQ35Pkg/Plugins/QemuRunner/QemuRunner.py index 8102d5d5..1cc98635 100644 --- a/Platforms/QemuQ35Pkg/Plugins/QemuRunner/QemuRunner.py +++ b/Platforms/QemuQ35Pkg/Plugins/QemuRunner/QemuRunner.py @@ -35,6 +35,8 @@ class QemuRunner(uefi_helper_plugin.IUefiHelperPlugin): result = io.StringIO() ret = utility_functions.RunCmd(exec, "--version", outstream=result) if ret != 0: + logging.error(result.getvalue()) + logging.error(ret) return None # expected version string will be "QEMU emulator version maj.min.rev" @@ -51,14 +53,22 @@ class QemuRunner(uefi_helper_plugin.IUefiHelperPlugin): OutputPath_FV = os.path.join(env.GetValue("BUILD_OUTPUT_BASE"), "FV") repo_version = env.GetValue("VERSION", "Unknown") - # Use a provided QEMU path. Default to the system path if not provided. - executable = env.GetValue("QEMU_PATH", "qemu-system-x86_64") + # Use a provided QEMU path. Otherwise use what is provided through the extdep + executable = env.GetValue("QEMU_PATH", None) + if not executable: + executable = str(Path(env.GetValue("QEMU_DIR", ''), "qemu-system-x86_64")) # First query the version qemu_version = QemuRunner.QueryQemuVersion(executable) # write messages to stdio args = "-debugcon stdio" + + # If we are using the QEMU external dependency, we need to tell it + # where to look for roms + if not env.GetValue("QEMU_PATH") and env.GetValue("QEMU_DIR"): + args += f" -L {str(Path(env.GetValue('QEMU_DIR'), 'share'))}" + # debug messages out thru virtual io port args += " -global isa-debugcon.iobase=0x402" # Turn off S3 support diff --git a/Platforms/QemuSbsaPkg/Plugins/QemuRunner/QemuRunner.py b/Platforms/QemuSbsaPkg/Plugins/QemuRunner/QemuRunner.py index cf2e7295..bdaf09e0 100644 --- a/Platforms/QemuSbsaPkg/Plugins/QemuRunner/QemuRunner.py +++ b/Platforms/QemuSbsaPkg/Plugins/QemuRunner/QemuRunner.py @@ -50,14 +50,21 @@ class QemuRunner(uefi_helper_plugin.IUefiHelperPlugin): OutputPath_FV = os.path.join(env.GetValue("BUILD_OUTPUT_BASE"), "FV") repo_version = env.GetValue("VERSION", "Unknown") - # Use a provided QEMU path. Default to the system path if not provided. - executable = env.GetValue("QEMU_PATH", "qemu-system-aarch64") - + # Use a provided QEMU path. Otherwise use what is provided through the extdep + executable = env.GetValue("QEMU_PATH", None) + if not executable: + executable = str(Path(env.GetValue("QEMU_DIR", ''),"qemu-system-aarch64")) + qemu_version = QemuRunner.QueryQemuVersion(executable) # turn off network args = "-net none" + # If we are using the QEMU external dependency, we need to tell it + # where to look for roms + if not env.GetValue("QEMU_PATH") and env.GetValue("QEMU_DIR"): + args += f" -L {str(Path(env.GetValue('QEMU_DIR'), 'share'))}" + # Mount disk with either startup.nsh or OS image path_to_os = env.GetValue("PATH_TO_OS") if path_to_os is not None: diff --git a/QemuPkg/Binaries/qemu-linux_ext_dep.yaml b/QemuPkg/Binaries/qemu-linux_ext_dep.yaml new file mode 100644 index 00000000..d6d4a854 --- /dev/null +++ b/QemuPkg/Binaries/qemu-linux_ext_dep.yaml @@ -0,0 +1,19 @@ +## +# Downloads the exact version of QEMU that is known to work for the +# current version of mu_tiano_platforms. +# +# Copyright (c) 2019, Microsoft Corporation +# SPDX-License-Identifier: BSD-2-Clause-Patent +## +{ + "scope": "global-nix", + "type": "web", + "name": "qemu", + "source": "https://github.com/microsoft/mu_tiano_platforms/releases/download/v5.1.0/qemu-linux-v5.1.0.tar.gz", + "version": "v5.1.0", + "sha256": "1792d2179113beebe58743680c8b142de83b27a506acb7eff8db1cb1651c730f", + "internal_path": "/bin/", + "compression_type": "tar", + "flags": ["set_path", "set_build_var"], + "var_name": "QEMU_DIR", +} diff --git a/QemuPkg/Binaries/qemu-windows_ext_dep.yaml b/QemuPkg/Binaries/qemu-windows_ext_dep.yaml new file mode 100644 index 00000000..0659923f --- /dev/null +++ b/QemuPkg/Binaries/qemu-windows_ext_dep.yaml @@ -0,0 +1,19 @@ +## +# Downloads the exact version of QEMU that is known to work for the +# current version of mu_tiano_platforms. +# +# Copyright (c) 2019, Microsoft Corporation +# SPDX-License-Identifier: BSD-2-Clause-Patent +## +{ + "scope": "global-win", + "type": "web", + "name": "qemu", + "source": "https://github.com/microsoft/mu_tiano_platforms/releases/download/v5.1.0/qemu-windows-v5.1.0.zip", + "version": "v5.1.0", + "sha256": "356f5ba4d110b33d0440945005f051ca4b40019162187f2929997020937ceb52", + "internal_path": "/bin/", + "compression_type": "zip", + "flags": ["set_path", "set_build_var"], + "var_name": "QEMU_DIR", +}