Skip to main content

flowey_lib_hvlite/
init_openvmm_magicpath_uefi_mu_msvm.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Ensure the mu_msvm MSVM.fd file is copied into the "magic directory" to
5//! automatically work in the context of the OpenVMM repo.
6//!
7//! Eventually, this will only be required for interactive use-cases (i.e: to
8//! support openvmm's `X86_64_OPENVMM_UEFI_FIRMWARE` local-only `[env]` var).
9//!
10//! Work is ongoing to root out remaining hard-codes to this magic path by
11//! various other bits of repo tooling (notably: petri's `known_paths`
12//! resolver).
13
14use crate::common::CommonArch;
15use flowey::node::prelude::*;
16use std::collections::BTreeMap;
17
18flowey_request! {
19    pub struct Request {
20        pub arch: CommonArch,
21        pub done: WriteVar<SideEffect>,
22    }
23}
24
25new_flow_node!(struct Node);
26
27impl FlowNode for Node {
28    type Request = Request;
29
30    fn imports(ctx: &mut ImportCtx<'_>) {
31        ctx.import::<crate::cfg_openvmm_magicpath::Node>();
32        ctx.import::<crate::download_uefi_mu_msvm::Node>();
33    }
34
35    fn emit(requests: Vec<Self::Request>, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> {
36        let mut reqs: BTreeMap<CommonArch, Vec<WriteVar<SideEffect>>> = BTreeMap::new();
37        for Request { arch, done } in requests {
38            reqs.entry(arch).or_default().push(done);
39        }
40
41        // -- end of req processing -- //
42
43        let packages = reqs
44            .into_iter()
45            .map(|(arch, dones)| {
46                (
47                    arch,
48                    (
49                        ctx.reqv(|v| crate::download_uefi_mu_msvm::Request::GetMsvmFd {
50                            arch,
51                            flavor: None,
52                            msvm_fd: v,
53                        }),
54                        dones,
55                    ),
56                )
57            })
58            .collect::<BTreeMap<_, _>>();
59
60        let openvmm_magicpath = ctx.reqv(crate::cfg_openvmm_magicpath::Request);
61
62        ctx.emit_rust_step("move MSVM.fd into its magic folder", move |ctx| {
63            let packages = packages.claim(ctx);
64            let openvmm_magicpath = openvmm_magicpath.claim(ctx);
65            move |rt| {
66                let openvmm_magicpath = rt.read(openvmm_magicpath);
67                for (arch, (msvm_fd, _dones)) in packages {
68                    let msvm_fd = rt.read(msvm_fd);
69                    let dst_folder = openvmm_magicpath.join(match arch {
70                        CommonArch::Aarch64 => {
71                            "hyperv.uefi.mscoreuefi.AARCH64.RELEASE/MsvmAARCH64/RELEASE_CLANGPDB/FV"
72                        }
73                        CommonArch::X86_64 => {
74                            "hyperv.uefi.mscoreuefi.x64.RELEASE/MsvmX64/RELEASE_VS2022/FV"
75                        }
76                    });
77                    let dst = dst_folder.join("MSVM.fd");
78
79                    if msvm_fd.absolute()? != dst.absolute()? {
80                        fs_err::create_dir_all(&dst_folder)?;
81                        fs_err::copy(msvm_fd, dst)?;
82                    }
83                }
84                Ok(())
85            }
86        });
87
88        Ok(())
89    }
90}