Skip to content

opentmk: add config-patch protocol and bootable VHD build#3953

Open
mayank-microsoft wants to merge 4 commits into
microsoft:mainfrom
mayank-microsoft:mayank/opentmk-config-vhd
Open

opentmk: add config-patch protocol and bootable VHD build#3953
mayank-microsoft wants to merge 4 commits into
microsoft:mainfrom
mayank-microsoft:mayank/opentmk-config-vhd

Conversation

@mayank-microsoft

@mayank-microsoft mayank-microsoft commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Add OpenTMK's test-selection config mechanism and the tooling to build a
bootable OpenTMK VHD.

OpenTMK tests are selected by patching a small config region embedded in
the built .efi, rather than by rebuilding per test. This PR adds that
protocol, the guest-side dispatch that reads it, and a
cargo xflowey build-opentmk pipeline that builds the .efi and
packages it into a bootable VHD.

Changes

  • New crate opentmk_protocol — the embedded config region format
    (OPENTMK_CONFIG_MAGIC / OpenTmkConfig / TestConfig) and
    patch_opentmk_config, which patches a built .efi in place to select
    the backend/test to run.
  • New crate opentmk/opentmk_disk — builds a fixed VHD (GPT + EFI
    system partition) around an OpenTMK .efi, optionally patching the
    config.
  • OpenTMK guest — reads the embedded .tmkcfg config region and
    dispatches to the selected backend/test via the opentmk_tests! /
    opentmk_backends! macros.
  • flowey cargo xflowey build-opentmk pipeline — builds the .efi
    and packages it into a VHD using opentmk_disk.
  • Register the two new crates in the workspace.

No new external dependencies: opentmk_disk's deps (gptman,
fscommon, disk_vhd1, guid, tempfile) are already workspace
dependencies.

Testing

  • cargo build -p opentmk_protocol -p opentmk_disk
  • cargo build -p opentmk --target x86_64-unknown-uefi (stable)
  • cargo build -p flowey_hvlite -p flowey_lib_hvlite
  • cargo xflowey build-opentmk --help

Add the OpenTMK test-selection config mechanism and the tooling to build
a bootable OpenTMK VHD:

- New `opentmk_protocol` crate: the embedded config region format
  (OPENTMK_CONFIG_MAGIC / OpenTmkConfig / TestConfig) and
  `patch_opentmk_config`, which patches a built `.efi` in place to select
  the backend/test to run.
- New `opentmk/opentmk_disk` crate: builds a fixed VHD (GPT + EFI system
  partition) around an OpenTMK `.efi`, optionally patching the config.
- OpenTMK guest: read the embedded `.tmkcfg` config region and dispatch
  to the selected backend/test via the `tmk_tests!` / `tmk_backends!`
  macros (`opentmk/src/tests`). Interrupt tests remain `#[cfg(nightly)]`
  gated (dropping that requirement is a separate change).
- flowey `cargo xflowey build-opentmk` pipeline: build the `.efi` and
  package it into a VHD, using `opentmk_disk`.
- Register the two new crates in the workspace.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 34167341-e52b-4594-9f87-97bec95ae81c
Copilot AI review requested due to automatic review settings July 16, 2026 15:36
@github-actions github-actions Bot added the unsafe Related to unsafe code label Jul 16, 2026
@github-actions

Copy link
Copy Markdown

⚠️ Unsafe Code Detected

This PR modifies files containing unsafe Rust code. Extra scrutiny is required during review.

For more on why we check whole files, instead of just diffs, check out the Rustonomicon

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a host-patchable “config region” protocol for selecting OpenTMK tests without rebuilding, plus shared tooling to package an OpenTMK UEFI binary into a bootable fixed VHD, and a new local-only cargo xflowey build-opentmk pipeline to produce those artifacts.

Changes:

  • Add opentmk_protocol defining the embedded config region layout, JSON schema, and an in-place patcher for .efi/disk images.
  • Add opentmk_disk to build a GPT + FAT32 ESP fixed VHD containing the OpenTMK .efi, optionally patched with test-selection config.
  • Update OpenTMK guest-side test dispatch to read the embedded .tmkcfg config region, and add a local-only flowey pipeline (build-opentmk) to build and package artifacts.

Reviewed changes

Copilot reviewed 15 out of 16 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
opentmk/src/tests/mod.rs Adds backend/test dispatch macros, embeds the .tmkcfg config static, and reads it via volatile load to drive test selection.
opentmk/src/tests/hyperv/mod.rs Switches Hyper-V tests to macro-driven registration/dispatch with per-test cfg gating.
opentmk/opentmk_disk/src/lib.rs New crate that builds a bootable fixed VHD (GPT + FAT32 ESP) around an OpenTMK .efi, with optional config patching.
opentmk/opentmk_disk/Cargo.toml Declares opentmk_disk dependencies (reusing existing workspace deps).
opentmk/Cargo.toml Adds dependency on opentmk_protocol for guest-side config parsing/static.
opentmk_protocol/src/lib.rs New no-std protocol crate defining the config region format, JSON schema, and patching logic (+ unit tests).
opentmk_protocol/Cargo.toml Declares opentmk_protocol dependencies (serde, serde_json, thiserror).
flowey/flowey_lib_hvlite/src/lib.rs Exposes the new build_opentmk flow node module.
flowey/flowey_lib_hvlite/src/build_opentmk.rs New flowey node to build opentmk as a UEFI binary and report .efi/.pdb outputs.
flowey/flowey_lib_hvlite/src/_jobs/mod.rs Registers the new local-only build job for OpenTMK.
flowey/flowey_lib_hvlite/src/_jobs/local_build_opentmk.rs New local job that packages the built .efi into a VHD via opentmk_disk (optionally patching config).
flowey/flowey_lib_hvlite/Cargo.toml Adds dependency on opentmk_disk for the packaging step.
flowey/flowey_hvlite/src/pipelines/mod.rs Adds the BuildOpentmk CLI subcommand entry point.
flowey/flowey_hvlite/src/pipelines/build_opentmk.rs New local-only cargo xflowey build-opentmk pipeline wiring + CLI flags.
Cargo.toml Registers opentmk_protocol and opentmk_disk as workspace dependencies.
Cargo.lock Locks the new workspace crates into the dependency graph.

Comment thread opentmk_protocol/src/lib.rs
Comment thread opentmk_protocol/src/lib.rs
Comment thread flowey/flowey_hvlite/src/pipelines/mod.rs
Copilot AI review requested due to automatic review settings July 16, 2026 19:47
@mayank-microsoft
mayank-microsoft marked this pull request as ready for review July 16, 2026 19:49
@mayank-microsoft
mayank-microsoft requested a review from a team as a code owner July 16, 2026 19:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 16 changed files in this pull request and generated 1 comment.

Comment thread flowey/flowey_lib_hvlite/src/_jobs/local_build_opentmk.rs
Copilot AI review requested due to automatic review settings July 20, 2026 18:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 16 changed files in this pull request and generated 3 comments.

Comment thread opentmk_protocol/src/lib.rs Outdated
Comment thread flowey/flowey_lib_hvlite/src/build_opentmk.rs Outdated
Comment thread flowey/flowey_hvlite/src/pipelines/build_opentmk.rs
Copilot AI review requested due to automatic review settings July 20, 2026 18:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 16 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

flowey/flowey_hvlite/src/pipelines/build_opentmk.rs:16

  • This PR adds a new cargo xflowey build-opentmk pipeline, but the Guide’s list of notable cargo xflowey pipelines doesn’t mention it yet (see Guide/src/dev_guide/dev_tools/xflowey.md, which currently lists build-igvm/restore-packages/vmm-tests-run/cca-tests). Adding at least a brief entry for build-opentmk would help discoverability and keep the dev-tool docs in sync.
/// 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.

Comment thread opentmk/src/tests/mod.rs
Comment thread opentmk/opentmk_disk/src/lib.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

unsafe Related to unsafe code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants