Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

ODP QEMU Platform

This book documents the Open Device Partnership reference platform for the QEMU arm-virt and x64 Q35 platforms. The repository assembles the platform firmware, embedded controller firmware, secure services, UEFI, Windows image, and end-to-end tests needed for development and validation.

ARCH defaults to aarch64; use ARCH=x86_64 for Q35 firmware and Windows. Secure-service tests are ARM-only.

Quick start

Open the repository in its devcontainer, then build all firmware artifacts:

make all

Boot the UEFI-only configuration:

make run

Build and boot the Windows image:

make run_os

Build and run the virtual EC:

make run_ec

Run the end-to-end test suite:

make e2e-test

See the repository README for project status and contribution information.

Devcontainer Image

This project uses a devcontainer for CI and local development. The image is defined in .devcontainer/Dockerfile and configured by .devcontainer/devcontainer.json.

How the CI cache works

The GitHub Actions workflow (.github/workflows/build.yml) builds the devcontainer using the devcontainers/ci action. That action wraps the Dockerfile in a generated Dockerfile-with-features which renames the build stage to dev_container_auto_added_stage_label. The BuildKit cache is keyed on the full build graph including stage names, so cache images must be built with the same wrapper to get cache hits.

Pre-seeding the cache

When the Dockerfile changes, the first CI run will rebuild every layer from scratch. To avoid this, you can pre-seed the GHCR cache from your local machine:

# 1. Log in to GHCR
gh auth token | docker login ghcr.io -u "$(gh api user --jq .login)" --password-stdin

# 2. Run the push script
./scripts/push-devcontainer-cache.sh

The script uses the devcontainer build CLI to generate the same Dockerfile wrapper that CI uses (with the dev_container_auto_added_stage_label stage name). It then runs docker buildx build with --cache-to type=registry,mode=max to push all intermediate layers as registry cache. This avoids the limitations of BUILDKIT_INLINE_CACHE=1 (inline cache), which can silently drop cache metadata for some layers in multi-platform builds.

By default the script pushes to ghcr.io/<your-gh-user>/odp-platform-qemu-arm-virt-devcontainer:cache. You can override this by passing an image name:

./scripts/push-devcontainer-cache.sh ghcr.io/myorg/my-image

Cache lookup order

Both CI and Common.mk try multiple cache sources in order:

  1. ghcr.io/dymk/odp-platform-qemu-arm-virt-devcontainer:cache
  2. ghcr.io/dymk/odp-platform-qemu-arm-virt-devcontainer:latest
  3. ghcr.io/opendevicepartnership/odp-platform-qemu-arm-virt/devcontainer:cache
  4. ghcr.io/opendevicepartnership/odp-platform-qemu-arm-virt/devcontainer:latest

This means PRs from forks can benefit from the upstream org cache, and contributors can push their own cache to speed up their PRs.

Pinned external images

The Dockerfile copies QEMU binaries from a builder image. This image is pinned by SHA digest (not :latest) to ensure deterministic builds. The digest is set once at the top of the Dockerfile via the QEMU_BUILDER_IMAGE build arg:

ARG QEMU_BUILDER_IMAGE=ghcr.io/opendevicepartnership/odp-qemu-builder/qemu@sha256:376bc8a3...
FROM ${QEMU_BUILDER_IMAGE} AS qemu-builder
...
COPY --from=qemu-builder /usr/local/bin/qemu-system-aarch64 /usr/local/bin/qemu-system-aarch64

To update the pinned digest, pull the new image and grab its digest:

docker pull ghcr.io/opendevicepartnership/odp-qemu-builder/qemu:latest
docker inspect --format='{{index .RepoDigests 0}}' ghcr.io/opendevicepartnership/odp-qemu-builder/qemu:latest

Then update the digest in the QEMU_BUILDER_IMAGE ARG default in .devcontainer/Dockerfile. That is the only place the digest needs to change.

E2E Tests for Secure Partition Services

End-to-end tests that exercise the EC Secure Partition (SP) running inside QEMU by sending FF-A messages from the non-secure world and validating responses.

Overview

The test harness is a set of standalone Rust UEFI applications targeting aarch64-unknown-uefi. Each test binary boots in the UEFI Shell, issues FF-A SMC calls directly to the Secure Partition Manager Core (SPMC / Hafnium), and reports results over serial.

graph LR
    subgraph QEMU["QEMU (virt machine)"]
        subgraph NS["Non-Secure World"]
            Shell["UEFI Shell<br/>thermal.efi / tpm.efi"]
        end
        subgraph S["Secure World"]
            SPMC["Hafnium (SPMC)"]
            SP["EC SP (0x8002)<br/>Thermal / TPM / FwMgmt / Notify"]
        end
        Shell -- "FFA_MSG_SEND_DIRECT_REQ2<br/>(SMC #0)" --> SPMC
        SPMC --> SP
        SP --> SPMC
        SPMC -- "FFA_MSG_SEND_DIRECT_RESP2" --> Shell
    end
    Shell -- "Serial output<br/>[PASS] / [FAIL]" --> Host["Host / CI"]

Why UEFI Applications?

  • Fast iteration — rebuild only the test .efi binary, not the entire BIOS. The firmware (SECURE_FLASH0.fd + QEMU_EFI.fd) is reused as-is.
  • Lightweight — each binary is ~32 KB. No OS needed.
  • Direct FF-A access — UEFI apps run at EL1 and can issue smc #0 directly, the same way the SP's own C test app (FfaPartitionTestApp.efi) does.
  • Same language as the SP — Rust, with shared types from the odp-ffa crate.

Directory Structure

DirectoryPurpose
ffa/FFA calling library — thin wrapper around odp-ffa with FFA_PARTITION_INFO_GET_REGS
test-support/Shared test harness: run_tests(), send_direct_req2(), result reporting
uart-logger/Minimal PL011 UART logging crate for serial output
tests/thermal/Thermal service test suite (thermal.efi)
tests/tpm/TPM service test suite (tpm.efi)
coverage-plugin/QEMU TCG plugin for SP code coverage collection
scripts/Post-processing tools (e.g., pcs-to-lcov.py)
Build/Build artifacts: test output, coverage logs/reports, virtual drive

How It Works

1. Build

Test binaries are compiled with cargo build --release inside the devcontainer, targeting aarch64-unknown-uefi. The output is a PE/COFF .efi executable.

2. Virtual Drive Preparation

The Makefile creates a temporary directory (Build/vdrive/) containing:

  • The compiled .efi test binaries.
  • A startup.nsh script that auto-runs the tests when UEFI Shell starts.

3. QEMU Launch

QEMU boots with:

  • The pre-built BIOS firmware (pflash units 0 and 1) — includes TF-A, Hafnium, the EC Secure Partition, and UEFI.
  • A virtual FAT drive (-drive file=fat:rw:Build/vdrive,...) mounted as a disk visible to the UEFI Shell.
  • -nographic — all output goes to serial/stdio.

4. Test Execution

The UEFI Shell finds the FAT drive, executes startup.nsh, which launches thermal.efi. The test app:

  1. Negotiates FF-A version — calls FFA_VERSION requesting v1.2.
  2. Gets its own partition ID — calls FFA_ID_GET.
  3. Discovers the EC SP — calls FFA_PARTITION_INFO_GET_REGS with the Thermal service UUID (31f56da7-593c-4d72-a4b3-8fc7171ac073) to find partition 0x8002.
  4. Sends a Direct Request v2 — FFA_MSG_SEND_DIRECT_REQ2 with thermal get_temperature command (opcode 0x01, sensor ID 0).
  5. Validates the response — checks status == 0 in the MsgSendDirectResp2 payload.
  6. Reports results — prints [PASS] or [FAIL] for each test to serial.
  7. Shuts down QEMU — calls uefi::runtime::reset(SHUTDOWN).

5. Result Collection

The make test-sp-services target wraps QEMU execution with timeout, captures serial output to Build/test-output.log, then greps for [PASS]/[FAIL] lines to determine the overall result.

FFA Library (ffa/ crate)

The ffa crate is a thin wrapper around odp-ffa (the same FFA crate used by the Secure Partition itself). It:

  • Re-exports all of odp_ffa — Version, IdGet, MsgSendDirectReq2, MsgSendDirectResp2, DirectMessagePayload, Function, Error, etc.
  • Adds FFA_PARTITION_INFO_GET_REGS — the only function not yet in odp-ffa. Uses raw inline-asm SMC since odp_ffa::smc is pub(crate). Marked with TODO(odp-ffa) for future upstreaming.

This means test code uses the same types and UUID encoding as the SP, preventing drift between the two sides.

FF-A Messaging Protocol

Tests communicate with the EC SP using FF-A Direct Message v2 (Req2/Resp2). The register layout for an FFA_MSG_SEND_DIRECT_REQ2 SMC is:

RegisterContents
x0Function ID (0xC400008D)
x1(source_id << 16) | destination_id
x2Service UUID high 64 bits (big-endian u64)
x3Service UUID low 64 bits (big-endian u64)
x4–x17Payload arguments (Arg0–Arg13)

The payload is serialized as a DirectMessagePayload — a 112-byte (14 × 8) register blob accessed via u8_at(), u16_at(), u64_at(), etc.

For the Thermal get_temperature command specifically:

  • Request: byte 0 = opcode (0x01), byte 1 = sensor_id (0x00)
  • Response: bytes 0–7 = status (i64), bytes 8–15 = temperature (u64)

Running

Prerequisites

  • BIOS firmware must be built first: make all from the repo root.
  • The devcontainer must have the aarch64-unknown-uefi Rust target installed (included in the Dockerfile).

Commands

# Build test EFI binaries only
make -C e2e-tests build

# Run with timeout + pass/fail reporting (for CI)
make -C e2e-tests test-sp-services

# Full pipeline: build everything then run tests
make e2e-test

TimeAlarm CPU-retention fixture

Opt-in time_alarm_retention.efi tests firmware CPU standby, not OS sleep or system suspend; it is outside make e2e-test. Build wake-capable EC/library, GPIO1-capable QEMU and PL061-mapped Patina with the normal relay SP, not secure-services-test. The runner never updates these prerequisites.

# Compile only; does not build EC/UEFI or start QEMU.
make -C e2e-tests retention-build
make -C e2e-tests retention-run TIME_ALARM_SOURCE=ac
make -C e2e-tests retention-run TIME_ALARM_SOURCE=dc TIME_ALARM_WIRE=disconnected

Mandatory TIME_ALARM_SOURCE=ac|dc builds separate time-alarm-wake EC fixtures using ODP_WAKE_SOURCE, not source detection or a fallback. Run both sources with both TIME_ALARM_WIRE=connected|disconnected (default: connected). RETENTION_EC_QEMU=/path/to/bin/qemu-system-riscv32 selects an isolated EC QEMU whose install prefix must exist in the devcontainer; do not change host PATH. Logs/vdrives remain in e2e-tests/Build/retention/.

Connected runs require inactive-timer guard, selected-timer wake and clear/rearm (six passes); disconnected runs require the EC wake latch but a host guard (four passes), omitting only host GPIO1, not HID/I2C/relay. Wake requires INTID 39, exclusive pin1 cause, ISR/EOI and 1–10 seconds residency (upper bound exclusive). Guards require CNTV/PPI 27 and 9–11 seconds; HID, early returns and external timeouts cannot pass. Clear acknowledges pin-low before clearing pending IRQs. Admission checks precede device writes; firmware IRQ/timer/device state is restored on failure too, with failed cleanup rejecting the run.

Host-only checks: from e2e-tests/, compile tests/time-alarm-retention/src/interrupt.rs with rustc --edition=2021 --test and run the resulting test binary.

Emulated runtime power-input command-path test

retention-power-input reuses the same EFI and normal FF-A/SP/EC commands. It needs the GPIO2 model and EC time-alarm-power-input feature. It builds one runtime-input EC artifact, without ODP_WAKE_SOURCE; TIME_ALARM_SOURCE selects the model's explicit cold-start seed, not a compile-time fallback.

make -C e2e-tests retention-power-input TIME_ALARM_SOURCE=ac \
  RETENTION_EC_QEMU=/path/to/gpio2-enabled/qemu-system-riscv32
make -C e2e-tests retention-power-input TIME_ALARM_SOURCE=dc \
  RETENTION_EC_QEMU=/path/to/gpio2-enabled/qemu-system-riscv32

The runner supplies odp-gpio.input-reset-mask=4 and input-reset=4 (AC) or 0 (DC) before EC boot. The EC checks the model's input-validity register. Its separate ec-gpio2 connection receives only raw 01/00 from the source helper, and nothing on initial connection. Host PL061 GPIO2 is not connected: its reset pull-down must not overwrite the explicit EC seed. GPIO1 remains exclusively driven by the EC's real wake consumer; GPIO0/HID is unchanged.

Five numbered TA_SOURCE requests select seed, other, seed, other, seed. The helper frames each fresh per-run log independently and preserves its origin; raw host/EC bytes are never merged. After a source write it waits for the EC's corresponding TimeAlarm power input: ... record, which follows set_power_source(), before acknowledging the sequence through the existing USB keyboard via a private host QMP socket. UEFI waits on normal console/timer events with a ten-second bound. These keys are control-plane acknowledgments while UEFI is awake, never wake evidence. There are no source-settling sleeps; the EC decoder emits message-only live records and the helper follows regular log files without putting a pipe behind host UART. Before each GPIO2 write it snapshots the EC log's byte position: an older record, including a partial record completed later, cannot acknowledge that write. The controller drains both log streams through EOF before accepting completion and records the origin/offset of every control record.

Each cold-start run must report six passes (three FF-A setup plus three cases):

CaseEvidence
Startup sourceExisting selected-timer test: real retention return, INTID39, GPIO1 and ISR evidence
INSTANTLYSwitch away; expire that source's five-second timer with only the ten-second guard; switch back; bounded real GetWakeStatus reads observe status 3 and physical GPIO1 high; clear returns low
NEVERSame inactive expiry with NEVER; after confirmed source return, another full guard window retains status 1 and GPIO1 low

The source transitions themselves are awake command-path qualification, not proof of transition-time CPU resume or Windows sleep/resume. Normal clear/disable commands and the existing IRQ restoration run on failure too. The helper must additionally report all five applied/acknowledged stages; a stale six-pass retention run is insufficient. Source-control errors propagate and terminate the owned runner. Logs include source-controller.log alongside the usual host/EC logs in e2e-tests/Build/retention/<source>-power-input.*. Disconnect/EC-reset hold semantics are covered by the model/component tests, not by this target.

Host-only checks (local socket/log fixtures, no VM):

PYTHONDONTWRITEBYTECODE=1 python3 scripts/tests/test_retention_power_input.py

Adjusting the Timeout

The default QEMU timeout is 180 seconds. Override with:

make -C e2e-tests test-sp-services QEMU_TIMEOUT=60

Expected Output

=== EC Secure Partition E2E Tests ===
  FFA version: 1.2
[PASS] ffa_version
  Our partition ID: 0x0000
[PASS] ffa_id_get
  Found EC partition: id=0x8002 ctx=1 props=0x00000603
[PASS] partition_discovery
  get_temperature response: status=0, temp=0x1234
[PASS] thermal_get_temperature
--- Results: 4 passed, 0 failed ---

Adding New Tests

New test for an existing service

Add a new fn test_*() function in the relevant test binary (e.g., tests/thermal/src/main.rs) and call it from main().

New test binary for a different service

  1. Create e2e-tests/tests/<service>/Cargo.toml and src/main.rs.
  2. Add it to the workspace in e2e-tests/Cargo.toml:
    members = ["ffa", "uart-logger", "test-support", "tests/thermal", "tests/<service>"]
    
  3. Update e2e-tests/Makefile:
    • Add the new .efi path (e.g. <SERVICE>_EFI := $(TARGET_DIR)/<service>.efi).
    • Add a per-test vdrive dir (e.g. VDRIVE_<SERVICE>_DIR := Build/vdrive-<service>) and a target that stages it: $(call make-vdrive,$(VDRIVE_<SERVICE>_DIR),$(<SERVICE>_EFI)).
    • No startup script needed — the shared generic startup.nsh runs whichever single .efi is on the vdrive.

Service UUIDs

The EC Secure Partition (0x8002) handles these services:

ServiceUUID
Inter-Partition / Notificatione474d87e-5731-4044-a727-cb3e8cf3c8df
EC Management330c1273-fde5-4757-9819-5b6539037502
EC Power7157addf-2fbe-4c63-ae95-efac16e3b01c
EC Battery25cb5207-ac36-427d-aaef-3aa78877d27e
EC Thermal31f56da7-593c-4d72-a4b3-8fc7171ac073
TPM 2.017b862a4-1806-4faf-86b3-089a58353861

These are defined in the SP's device tree manifest (secure-services/platform/linker/qemu-ec-sp.dts).

Code Coverage

E2E tests automatically collect code coverage for the EC Secure Partition using a QEMU TCG plugin. Every make test-sp-services run produces a coverage log at Build/coverage.log.

How it works

  1. TCG plugin (coverage-plugin/coverage.c) — a small shared library loaded into QEMU via -plugin. During translation, it instruments every instruction whose address falls within the SP memory range (0x20802000–0x21002000, matching the linker script). On execution, it sets a bit in a lock-free bitmap. At exit, it writes all unique executed PCs to the output file.

  2. Post-processing (scripts/pcs-to-lcov.py) — extracts all instruction addresses from the SP ELF via llvm-objdump, resolves every address to a source file and line via llvm-addr2line, then overlays the executed PCs to produce an lcov tracefile. Lines that exist but weren't executed appear as DA:line,0, giving accurate coverage percentages.

  3. HTML report — genhtml converts the lcov tracefile into a browsable HTML report.

Prerequisites

The SP ELF must be built with debug info so llvm-addr2line can resolve addresses. This is configured via debug = true in the [profile.coverage] section of secure-services/platform/Cargo.toml, which is used for e2e test and coverage builds.

Commands

# Run tests with coverage (builds secure-services with coverage profile)
make e2e-test

# Generate HTML coverage report
make -C e2e-tests coverage-report
# Output: e2e-tests/Build/coverage-html/index.html

# Build only the coverage plugin
make -C e2e-tests Build/libcoverage.so

Directory structure

e2e-tests/
├── coverage-plugin/
│   ├── coverage.c          # QEMU TCG plugin source
│   ├── qemu-plugin.h       # Vendored minimal plugin API header
│   └── Makefile             # Builds Build/libcoverage.so
├── scripts/
│   └── pcs-to-lcov.py      # PC-to-lcov conversion script
└── Build/
    ├── libcoverage.so       # Compiled coverage plugin
    ├── coverage.log         # Raw PCs (one hex address per line)
    ├── coverage.info        # lcov tracefile
    └── coverage-html/       # HTML report (genhtml output)

Embedded Controller

This section covers how to get started developing and testing with the virtual Embedded Controller (EC).

What this is

ODP provides a fully virtual embedded controller modeled on a QEMU 32-bit RISC-V machine. This also includes, in addition to the virtual UART bus provided by QEMU, a virtual I2C bus and virtual GPIOs.

These virtual peripherals present a memory-mapped register interface to the EC, just like real hardware, but send data over a socket acting as the virtual wire.

Along with a host OS running inside an ARM virt or x64 Q35 QEMU instance, this enables a completely virtual end-to-end development environment. ARM supports ODP ACPI services and HID-over-I2C; Q35 supports direct Windows user-mode serial access to the EC.

What this is not

The intent of this virtual EC is to aid in the development and testing of application logic sitting on top of hardware.

For example, a properly designed thermal management system in Rust can be written largely independently of the underlying hardware (as in, it shouldn't necessarily depend on the architecture of the microcontroller, specific sensors, which bus they use, etc.).

Likewise, logic for communicating with the host over a transport such as HIDI2C shouldn't necessarily be dependent on details of the specific underlying I2C peripheral as those details are abstracted away through generic traits.

Thus, this virtual EC is NOT intended to emulate the specific hardware quirks or timing details of any specific platform. For such a use case, tools like Renode would be more appropriate.

How to use it

First, check out QEMU setup for the basics of getting started with QEMU.

ARM virt

Once you have the repo cloned and the devcontainer set up, you can verify host-to-EC communications by following these steps:

  • Run make all to build UEFI firmware and secure services.

  • Run make run_ec which will build the dev-qemu platform in the mod/ec folder (the odp-embedded-controller submodule) and start a headless QEMU instance running the firmware on the RISC-V ec machine while displaying logs.

  • In a separate terminal, run make run_os QEMU_DISPLAY=gtk which will download our bundled WinVOS image containing all drivers and EC applications needed to interface with the EC, then boot it in an ARM virt QEMU instance running in a display window (alternatively, if you prefer connecting remotely via VNC, make run_os alone will start a headless instance with no local display window). This QEMU instance will automatically connect to the EC QEMU instance via sockets for virtual bus communications.

  • In the WinVOS terminal, run cd C:\ectest.

  • Run ec-test-tui.exe --source acpi (which ultimately goes through the virtual serial/UART bus). If everything is working correctly, you should see the TUI app open with an overview of EC subsystems with a green * indicating successful communication (don't worry if the data seems nonsensical; that is because some subsystems currently provide more realistic mock data than others):

    EC test TUI showing subsystem status

  • To verify virtual I2C/GPIO communication, run ec-test-cli.exe --source windows rtc get-real-time (currently, only the time-alarm service supports HIDI2C), which goes through a custom Windows driver that ultimately talks HID over I2C. If successful, you should receive output that looks like:

    EC test CLI showing real-time clock output

x86_64 Q35

You can also talk to the EC from an x86_64 Q35 host, but currently only over the virtual UART bus. Unlike ARM, this exposes a COM port directly to Windows, so the apps use --source serial instead of --source acpi:

  • Run make all ARCH=x86_64 to build the Q35 UEFI firmware.
  • Run make run_ec to build and start the same RISC-V EC instance used with ARM.
  • In a separate terminal, run make run_os ARCH=x86_64 QEMU_DISPLAY=gtk to boot WinVOS in a display window (alternatively, use make run_os ARCH=x86_64 for VNC). This connects the EC's virtual UART to COM3 in Windows.
  • In the WinVOS terminal, run cd C:\ectest.
  • Run ec-test-tui.exe --source serial --port COM3. If everything is working correctly, you should see the TUI app open with thermal, battery, and time-alarm data from the EC.
  • To test an individual service, run a CLI command such as ec-test-cli.exe --source serial --port COM3 rtc get-real-time. Close the TUI first, since only one app can use the COM port at a time.

Virtual I2C/GPIO communication is not yet supported on Q35.

If everything is working, then you have successfully set up your environment and can begin developing on your own. The best way to start is by navigating to mod/ec/platform/dev-qemu/src to see the current, basic reference implementation provided by ODP and start tweaking it to suit your needs. Running make run_ec again will build and launch your changes, and you can continue using the test apps running in the host QEMU instance to test your changes.

While the nitty-gritty details of how this all works under the hood aren't required for development, if you're curious, continue reading below.

How it works

At its core is a modified QEMU binary which adds a few nice features:

  • An emulated I2C target peripheral
  • An emulated I2C controller peripheral
  • An emulated GPIO peripheral
  • A new RISC-V ec machine which wires up the I2C target and GPIO peripherals as memory-mapped registers
  • A modified ARM virt machine which additionally wires up the I2C controller and GPIO peripherals as memory-mapped registers

The important thing to note is that the peripherals expose a socket allowing two QEMU instances or any other external program to connect. This is what enables the QEMU ARM host machine to connect its virtual I2C controller peripheral to the QEMU EC machine's virtual I2C target peripheral. This mirrors how the existing virtual UART peripherals in QEMU work.

Q35 uses QEMU's existing ISA UART model and the EC UART socket, without changes to QEMU or the EC firmware. Its I2C/GPIO connections remain unsupported.

Fortunately, knowing the nitty-gritty of how this works isn't required if you just want to get started developing your EC application logic. For those who are curious or need to modify QEMU themselves, the relevant repos and details are included below:

  • odp-qemu-builder: This is where ODP modifications to QEMU live as they are not yet upstreamed. The patch for I2C and GPIO emulation can be found here. As mentioned, this is responsible for implementing the new peripherals and wiring them up into the respective machines.
  • qemu-riscv-rs: This repo contains a peripheral access crate (PAC) and Embassy hardware abstraction layer (HAL) targeting the QEMU ec machine. The PAC and HAL hide the specific memory-mapped registers of the virtual peripherals, so knowledge of them is not required for writing application code. However, if one needs to modify the register map presented by the QEMU ec machine, then the SVD file MUST be updated as well since this is the source of truth from which the PAC is generated and the HAL is built upon.
  • odp-embedded-controller: This contains reference EC implementations for several platforms supported by ODP, including, of course dev-qemu. This is the primary repo that EC firmware developers will need to concern themselves with as this is where application logic lives. Currently, the dev-qemu platform contains mock/virtual sensors, fans, batteries, and a real-time clock (RTC) to demonstrate the ODP embedded-services. Additionally, the MCTP/UART service and HIDI2C time-alarm service are implemented over the virtual bus peripherals to demonstrate communication with a host.
  • odp-platform-common: The TUI and CLI apps that interface with the EC from the host OS live here. The apps are designed so that the underlying "source" (or transport) is configurable at runtime depending on the platform (for example, direct serial/UART, ACPI, Windows class interface, etc.). These are great tools to test host-to-EC communications end-to-end.

QEMU Guide

This guide covers:

  • Setting up QEMU (both for Windows and the virtual EC)
  • Booting a Windows image
  • Enabling WinDbg
  • Customizing ACPI content for the QEMU platform

QEMU Setup

This section covers how to setup QEMU (for the host and EC) and boot the windows image. We use QEMU as a reference for developing features that are not yet fully supported in hardware. This also gives us a HW agnostic platform that any SV or OEM can use for development.

Downloading and building QEMU

QEMU Builder has patches and HW features such as an I2C controller that we've added to QEMU. The QEMU that is included in the docker image already picks up the latest QEMU from here. If you want to make further modifications to QEMU download the odp-qemu-builder and follow the instructions there.

Running QEMU with Windows

The windows image generation is done by .github/workflows/build-os.yml. This downloads the latest version of Validation OS and injects the required drivers for ARM and x64 into a reusable base image. On pushes to main the image is zipped and published as the os-image.zip (ARM) or os-image-x86_64.zip (x64) asset on the rolling latest prerelease; pull requests only build it for validation. Running make run_os downloads that ACPI-free base, compiles the current platform ACPI and injects it into a local qcow2 overlay for ARM only, and boots the overlay.

If you want to create your own windows image you can modify the one downloaded at postbuild/os/prebuilt/<arch>/ValidationOS.vhdx and place your updated image there.

Connecting Windows to the virtual EC

The EC binary is built from the dev-qemu platform in the odp-embedded-controller repo (pulled in here as a submodule). This is a minimum platform that runs the ODP services using a mock temperature sensor, fan, battery, and real-time clock, along with a HAL written for the RISC-V QEMU ec platform to communicate over the virtual UART and I2C buses with the host. This platform can be modified locally during development.

Build and run the virtual EC with make run_ec. However, the EC running on its own won't do much. To then connect the host, run make run_os for ARM or make run_os ARCH=x86_64 for Q35 as mentioned above (in a separate terminal window). The EC QEMU instance creates the sockets and the host connects to them, but the order you run these in does not matter since the host will attempt to reconnect periodically to the EC if it's not available.

If using VS Code, you can also run either the run_os_ec task (for the default headless host) or run_os_ec_windowed (for a GTK window), and select the host architecture when prompted.

From within Windows running on the host QEMU instance, you can verify the connection is successful by following these steps:

  • Run cd C:\ectest
  • On ARM, run ec-test-tui.exe --source acpi.
  • On Q35, run ec-test-tui.exe --source serial --port COM3.
  • Verify all tabs show green (successful) status, indicating the host is sending commands to the EC and receiving data.

ACPI Customization

Adding Test Content to ACPI

See details under mod/uefi/platform/README.md for details on how to modify ACPI content for QEMU platforms.

Modifying Windows Image

Injecting Drivers into Vhdx Windows Image

Injecting drivers and registry entries into your VHDX image is straight forward using DISM. You will need the driver binaries and inf file to install the driver.

  1. Mount the VHDX by double clicking on it and noting the drive letter that is mounted

  2. Inject your driver using DISM

    dism /Image:e:\ /Add-Driver /Driver:d:\drivers\testdrv

  3. This will execute the installation steps in the INF including copying your driver into the mounted image and updating the registry. Make sure the operation completes successfully. If you have multiple drivers you can use the /Recurse option to install all inf files.

  4. Make sure to cleanly unmount your VHDX drive.

  5. Copy the ValidationOS.vhdx to postbuild/os/prebuilt/<arch>.

  6. Run make -C postbuild/os qcow2 ARCH=<arch> to regenerate the qcow file for QEMU.

  7. Run make run_os ARCH=<arch> to boot your new windows image.

Injecting Executables and Autorun

To inject executable content you can simply click on the VHDX file to mount it and make a folder and copy content to the device. If you are trying to overwrite existing system content you may need to make yourself the owener and allow overwrite permissions. Sfpcopy can also be used to accomplish secure copy.

takeown /f <filename>
icacls <filename> /grant everyone:f
copy <localfile> <destfile>

To automatically run an executable in WinVOS you can edit the registry in the VHDX.

  1. Mount the VHDX image by double clicking on it and noting the drive letter.
  2. Run regedit as administrator.
  3. Select the root of HKLM.
  4. File -> Load Hive and browse to your mounted drive under e:\windows\system32\config\SOFTWARE
  5. Name the mount location "Offline"
  6. Browse to the following key Computer\HKEY_LOCAL_MACHINE\offline\Microsoft\Windows NT\CurrentVersion\Winlogon
  7. Modify the "Shell" REG_SZ entry which just runs cmd.exe by default.
  8. After you've modified the key be sure to select the root of the offline folder and select File -> Unload Hive
  9. Unmount your VDHX file to make sure it is saved
  10. Convert windows image to qcow2 and load in QEMU

Shell Registry

Windbg Setup for QEMU

For general instructions see postbuild/os/README.md

Enabling Windbg

If Windows doesn't boot properly on QEMU you are basically stuck wondering what is happening with no output after bootmgr starts there will be no further update in the serial port. To debug windows we need to connect windbg to the QEMU to see what is happening as drivers boot.

As long as you pull the published windows image it has Windbg enabled by default. If you don't attach the debugger it will continue to boot after 30 seconds.

    Write-Host "Enabling debug"
    bcdedit /store ${efiLetter}:\EFI\Microsoft\Boot\BCD /set "{default}" debug on

If you want to debug early boot process because it is not making it into NTOS you can enable bootdebug as well

bcdedit /store BCD /set {globalsettings} bootdebug yes

Windbg can be connected on windbg -k com:ipport=56789,port=127.0.0.1 -v (endpoint configured by default for ARM)

Windbg QEMU

Debugging QEMU with GDB (ARM example)

When debugging in UEFI, secure world, or when system isn't responding you will often find yourself needing a GDB connection to the device. QEMU has built in support for GDB interface and makes it very easy to debug with GDB.

Ffter your system starts or is in the state you want to connect you can use

gdb-multiarch
(gdb) set debug aarch64
(gdb) target extended-remote localhost:5555

For more details debugging with GDB or using Windbg with GDB you can read the following documents. Patina Debugging