microsoft/openvmm

Public

mirrored from https://github.com/microsoft/openvmmAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
a9618fabfbfd97c898b3cf5aea9dd4c283ff8e1a

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

Guide/src/dev_guide/getting_started/build_openhcl.md

179lines · modecode

1# Building OpenHCL
2
3**Prerequisites:**
4
5- [Getting started on Linux / WSL2](./linux.md).
6
7Reminder: OpenHCL cannot currently be built on Windows hosts!
8
9* * *
10
11An OpenHCL IGVM firmware image is composed of several distinct binaries and
12artifacts. For example: the `openvmm_hcl` usermode binary, the OpenHCL boot
13shim, the OpenHCL Linux kernel and initrd, etc....
14
15Some of these components are built directly out of the OpenVMM repo, whereas
16others must be downloaded as pre-built artifacts from other associated repos.
17Various tools and scripts will then transform, package, and re-package these
18artifacts into a final OpenHCL IGVM firmware binary.
19
20Fortunately, we don't expect you do to all those steps manually!
21
22All the complexity of installing the correct system dependencies, building the
23right binaries, downloading the right artifacts, etc... is neatly encapsulated
24behind a single `cargo xflowey build-igvm` command, which orchestrates the
25entire end-to-end OpenHCL build process.
26
27Using the `build-igvm` flow is as simple as running:
28
29```bash
30cargo xflowey build-igvm [RECIPE]
31```
32
33The first build will take some time as all the dependencies are
34installed/downloaded/built.
35
36**Note: At this time, OpenHCL can only be built on Linux (or WSL2)!**
37
38A "recipe" corresponds to one of the pre-defined IGVM SKUs that are actively
39supported and tested in OpenVMM's build infrastructure.
40
41A single recipe encodes _all_ the details of what goes into an individual IGVM
42file, such as what build flags `openvmm_hcl` should be built with, what goes
43into a VTL2 initrd, what `igvmfilegen` manifest is being used, etc...
44
45- e.g: `x64`, for a "standard" x64 IGVM
46- e.g: `aarch64`, for a "standard" aarch64 IGVM
47- e.g: `x64-cvm`, for a x64 CVM IGVM
48- e.g: `x64-test-linux-direct`, for x64 IGVM booting a test linux direct image
49- _for a full list of available recipes, please run `cargo xflowey build-igvm --help`_
50
51New recipes can be added by modifying the `build-igvm` source code.
52
53Build output is then binplaced to: `flowey-out/artifacts/build-igvm/{release-mode}/{recipe}/openhcl-{recipe}.bin`
54
55So, for example:
56
57```bash
58cargo xflowey build-igvm x64-cvm
59# output: flowey-out/artifacts/build-igvm/debug/x64-cvm/openhcl-x64-cvm.bin
60
61cargo xflowey build-igvm x64 --release
62# output: flowey-out/artifacts/build-igvm/release/x64/openhcl-x64.bin
63```
64
65```admonish warning
66`cargo xflowey build-igvm` is designed to be used as part of the
67developer inner-loop, and does _NOT_ have a stable CLI suitable for CI or any
68other form of production automation!
69
70In-tree pipelines and automation should interface with the underlying `flowey`
71infrastructure that powers `cargo xflowey build-igvm`, _without_ relying on
72the details of its CLI.
73```
74
75## Building ohcldiag-dev
76
77`ohcldiag-dev` is typically built as a Windows binary.
78
79This can be done directly from Windows, or using
80[cross-compilation from WSL2](../getting_started/cross_compile.md).
81
82The command to build `ohcldiag-dev` is simply:
83
84```sh
85# you may need to run `rustup target add x86_64-pc-windows-msvc` first
86cargo build -p ohcldiag-dev --target x86_64-pc-windows-msvc
87```
88
89**Note:** Thanks to x86 emulation built into Windows, `ohcldiag-dev.exe` that is
90built for x64 Windows will work on Aarch64 Windows as well.
91
92## Troubleshooting
93
94This section documents some common errors you may encounter while building
95OpenHCL.
96
97If you are still running into issues, consider filing an issue on the OpenVMM
98GitHub Issue tracker.
99
100### Help! The build failed due to a missing dependency
101
102If you don't mind having `xflowey` install some dependencies globally
103on your machine (i.e: via `apt install`, or `rustup toolchain add`),
104you can pass `--install-missing-deps` to your invocation of
105`build-igvm`:
106
107```bash
108cargo xflowey build-igvm x64 --install-missing-deps
109```
110
111This will automatically install all required dependencies, including
112the .NET SDK, Rust toolchains, Node.js, and any necessary system
113packages.
114
115Alternatively - `build-igvm` _should_ emit useful human-readable
116error messages when it encounters a dependency that isn't installed,
117with a suggestion on how to install it.
118
119If it doesn't - please file an Issue!
120
121### Help! Everything is rebuilding even though I only made a small change
122
123Cargo's target triple handling can be a bit buggy. Try running with:
124
125```bash
126CARGO_BUILD_TARGET=x86_64-unknown-linux-gnu cargo build-igvm [RECIPE]
127```
128
129or adding the below to your .bashrc:
130
131```bash
132export CARGO_BUILD_TARGET=x86_64-unknown-linux-gnu
133```
134
135## Build Customization
136
137Aside from building IGVM files corresponding the the built-in IGVM recipes,
138`build-igvm` also offers a plethora of customization options for developers who
139wish to build specialized custom IGVM files for local testing.
140
141Some examples of potentially useful customization include:
142
143- `--override-manifest`: Override the recipe's `igvmfilegen` manifest file
144 via, in order to tweak different kernel command line options, different VTL0
145 boot configuration, or different VTL2 memory sizes.
146
147- `--custom-openvmm-hcl`: Specify a pre-built `openvmm_hcl` binary. This is
148 useful in case you have already built it with some custom settings, e.g.:
149
150 ```bash
151 cargo build --target x86_64-unknown-linux-musl -p openvmm_hcl --features myfeature
152 cargo xflowey build-igvm x64 --custom-openvmm-hcl target/x86_64-unknown-linux-musl/debug/openvmm_hcl
153 ```
154
155- Specify a custom VTL2 kernel `vmlinux` / `Image`, instead of using a
156 pre-packed stable/dev kernel.
157
158 ```bash
159 cargo xflowey build-igvm x64 --custom-kernel path/to/my/prebuilt/vmlinux
160 ```
161
162For a full list of available customizations, refer to `build-igvm --help`.
163
164### Advanced
165
166Depending on what you're doing, you may need to build the individual components
167that go into an OpenHCL IGVM build.
168
169Our `flowey`-based pipelines handle the complexities of properly invoking and
170orchestrating the various individual build tools / scripts used to construct
171IGVM files, but a sufficiently motivated user can go through these steps
172manually.
173
174Please consult the source code for `cargo xflowey build-igvm` for a breakdown of
175all build steps and available customization options.
176
177Note that the canonical "source of truth" for how to build end-to-end OpenHCL
178IGVM files are these build scripts themselves, and the specific flow is subject
179to change over time!
180