-
Notifications
You must be signed in to change notification settings - Fork 212
opentmk: add config-patch protocol and bootable VHD build #3953
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mayank-microsoft
wants to merge
6
commits into
microsoft:main
Choose a base branch
from
mayank-microsoft:mayank/opentmk-config-vhd
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
011e604
opentmk: add config-patch protocol and bootable VHD build
mayank-microsoft adaddd2
chore: PR review improvements
mayank-microsoft 64057d5
chore: remove stale comments
mayank-microsoft 5a9aff9
chore: resolve PR feedback
mayank-microsoft 1e1aaeb
Merge branch 'main' into mayank/opentmk-config-vhd
mayank-microsoft b12986c
opentmk: fix merge resolution in tests/hyperv/mod.rs
mayank-microsoft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| //! See [`BuildOpentmkCli`] | ||
|
|
||
| use crate::pipelines::build_igvm::bail_if_running_in_ci; | ||
| use crate::pipelines_shared::cfg_common_params::CommonArchCli; | ||
| use flowey::node::prelude::ReadVar; | ||
| use flowey::pipeline::prelude::*; | ||
| use flowey_lib_hvlite::common::CommonArch; | ||
| use std::path::PathBuf; | ||
|
|
||
| /// Build OpenTMK and package it into a bootable VHD. | ||
| #[derive(clap::Args)] | ||
| pub struct BuildOpentmkCli { | ||
| /// Target architecture for the OpenTMK build. Defaults to x86-64. | ||
| #[clap(default_value = "x86-64")] | ||
| pub arch: CommonArchCli, | ||
|
|
||
| /// Custom name for the output `.efi`, `.vhd`, and `.pdb` (default `opentmk`). | ||
| #[clap(long)] | ||
| pub name: Option<String>, | ||
|
|
||
| /// Path to a JSON test-selection config to embed in the built VHD. If | ||
| /// omitted, the VHD boots the unconfigured `opentmk.efi`. | ||
| #[clap(long)] | ||
| pub config: Option<PathBuf>, | ||
|
|
||
| /// Build using release profile. | ||
| #[clap(long)] | ||
| pub release: bool, | ||
|
|
||
| /// Directory for the output artifacts. | ||
| #[clap(long, default_value = "flowey-out/build-opentmk")] | ||
| pub dir: PathBuf, | ||
|
|
||
| /// pass `--verbose` to cargo | ||
| #[clap(long)] | ||
| pub verbose: bool, | ||
|
|
||
| /// pass `--locked` to cargo | ||
| #[clap(long)] | ||
| pub locked: bool, | ||
|
|
||
| /// Automatically install any missing required dependencies. | ||
| #[clap(long)] | ||
| pub install_missing_deps: bool, | ||
| } | ||
|
|
||
| impl IntoPipeline for BuildOpentmkCli { | ||
| fn into_pipeline(self, backend_hint: PipelineBackendHint) -> anyhow::Result<Pipeline> { | ||
| if !matches!(backend_hint, PipelineBackendHint::Local) { | ||
| anyhow::bail!("build-opentmk is for local use only") | ||
| } | ||
|
|
||
| bail_if_running_in_ci()?; | ||
|
|
||
| let openvmm_repo = flowey_lib_common::git_checkout::RepoSource::ExistingClone( | ||
| ReadVar::from_static(crate::repo_root()), | ||
| ); | ||
|
|
||
| let Self { | ||
| arch, | ||
| name, | ||
| config, | ||
| release, | ||
| dir, | ||
| verbose, | ||
| locked, | ||
| install_missing_deps, | ||
| } = self; | ||
|
|
||
| let arch: CommonArch = arch.into(); | ||
|
|
||
| std::fs::create_dir_all(&dir)?; | ||
|
|
||
| let mut pipeline = Pipeline::new(); | ||
|
|
||
| pipeline | ||
| .new_job( | ||
| FlowPlatform::host(backend_hint), | ||
| FlowArch::host(backend_hint), | ||
| "build-opentmk", | ||
| ) | ||
| .dep_on(|_| flowey_lib_hvlite::_jobs::cfg_versions::Request::Init) | ||
| .dep_on( | ||
| |_| flowey_lib_hvlite::_jobs::cfg_hvlite_reposource::Params { | ||
| hvlite_repo_source: openvmm_repo, | ||
| }, | ||
| ) | ||
| .dep_on(|_| flowey_lib_hvlite::_jobs::cfg_common::Params { | ||
| local_only: Some(flowey_lib_hvlite::_jobs::cfg_common::LocalOnlyParams { | ||
| interactive: true, | ||
| auto_install: install_missing_deps, | ||
| ignore_rust_version: true, | ||
| }), | ||
| verbose: ReadVar::from_static(verbose), | ||
| locked, | ||
| deny_warnings: false, | ||
| no_incremental: false, | ||
| }) | ||
| .dep_on( | ||
| |ctx| flowey_lib_hvlite::_jobs::local_build_opentmk::Params { | ||
| artifact_dir: ReadVar::from_static(dir), | ||
| done: ctx.new_done_handle(), | ||
| arch, | ||
| release, | ||
| name, | ||
| config, | ||
| }, | ||
| ) | ||
| .finish(); | ||
|
|
||
| Ok(pipeline) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
flowey/flowey_lib_hvlite/src/_jobs/local_build_opentmk.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| //! A local-only job that supports the `cargo xflowey build-opentmk` CLI | ||
|
|
||
| use flowey::node::prelude::*; | ||
|
|
||
| flowey_request! { | ||
| pub struct Params { | ||
| pub artifact_dir: ReadVar<PathBuf>, | ||
| pub done: WriteVar<SideEffect>, | ||
|
|
||
| pub arch: crate::common::CommonArch, | ||
| pub release: bool, | ||
| /// Custom name for the output `.efi`, `.vhd`, and `.pdb`. Defaults to "opentmk". | ||
| pub name: Option<String>, | ||
| /// Optional JSON test-selection config to embed in the built VHD. | ||
| pub config: Option<PathBuf>, | ||
| } | ||
| } | ||
|
|
||
| new_simple_flow_node!(struct Node); | ||
|
|
||
| impl SimpleFlowNode for Node { | ||
| type Request = Params; | ||
|
|
||
| fn imports(ctx: &mut ImportCtx<'_>) { | ||
| ctx.import::<crate::build_opentmk::Node>(); | ||
| } | ||
|
|
||
| fn process_request(request: Self::Request, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> { | ||
| let Params { | ||
| artifact_dir, | ||
| done, | ||
| arch, | ||
| release, | ||
| name, | ||
| config, | ||
| } = request; | ||
|
|
||
| let profile = if release { | ||
| crate::common::CommonProfile::Release | ||
| } else { | ||
| crate::common::CommonProfile::Debug | ||
| }; | ||
|
|
||
| let name = name.unwrap_or_else(|| "opentmk".to_string()); | ||
|
|
||
| let opentmk_output = ctx.reqv(|v| crate::build_opentmk::Request { | ||
| arch, | ||
| profile, | ||
| out_name: Some(name.clone()), | ||
| opentmk: v, | ||
| }); | ||
|
|
||
| ctx.emit_rust_step("package opentmk into VHD", |ctx| { | ||
| done.claim(ctx); | ||
| let artifact_dir = artifact_dir.claim(ctx); | ||
| let opentmk_output = opentmk_output.claim(ctx); | ||
| move |rt| { | ||
| let crate::build_opentmk::OpentmkOutput { efi, pdb } = rt.read(opentmk_output); | ||
|
|
||
| let output_dir = rt.read(artifact_dir); | ||
| let output_dir = output_dir.absolute()?; | ||
| fs_err::create_dir_all(&output_dir)?; | ||
|
|
||
| // Build the bootable VHD, patching in the test config if one was given. | ||
| let disk_arch = match arch { | ||
| crate::common::CommonArch::X86_64 => opentmk_disk::Arch::X86_64, | ||
| crate::common::CommonArch::Aarch64 => opentmk_disk::Arch::Aarch64, | ||
| }; | ||
| let efi_bytes = fs_err::read(&efi)?; | ||
| let vhd_path = output_dir.join(format!("{name}.vhd")); | ||
| let image = if let Some(cfg_path) = &config { | ||
| let config_json = fs_err::read(cfg_path.absolute()?)?; | ||
| opentmk_disk::build_opentmk_vhd_with_config( | ||
| &efi_bytes, | ||
| disk_arch, | ||
| &config_json, | ||
| )? | ||
| } else { | ||
| opentmk_disk::build_opentmk_vhd(&efi_bytes, disk_arch)? | ||
| }; | ||
| if vhd_path.exists() { | ||
| fs_err::remove_file(&vhd_path)?; | ||
| } | ||
| image.persist(&vhd_path)?; | ||
|
mayank-microsoft marked this conversation as resolved.
|
||
|
|
||
| fs_err::copy(&efi, output_dir.join(format!("{name}.efi")))?; | ||
| fs_err::copy(&pdb, output_dir.join(format!("{name}.pdb")))?; | ||
|
|
||
| log::info!("EFI: {}", output_dir.join(format!("{name}.efi")).display()); | ||
| log::info!("VHD: {}", vhd_path.display()); | ||
| log::info!("PDB: {}", output_dir.join(format!("{name}.pdb")).display()); | ||
|
|
||
| Ok(()) | ||
| } | ||
| }); | ||
|
|
||
| Ok(()) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.