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                            msvm_fd: v,
52                        }),
53                        dones,
54                    ),
55                )
56            })
57            .collect::<BTreeMap<_, _>>();
58
59        let openvmm_magicpath = ctx.reqv(crate::cfg_openvmm_magicpath::Request);
60
61        ctx.emit_rust_step("move MSVM.fd into its magic folder", move |ctx| {
62            let packages = packages.claim(ctx);
63            let openvmm_magicpath = openvmm_magicpath.claim(ctx);
64            move |rt| {
65                let openvmm_magicpath = rt.read(openvmm_magicpath);
66                for (arch, (msvm_fd, _dones)) in packages {
67                    let msvm_fd = rt.read(msvm_fd);
68                    let dst_folder = openvmm_magicpath.join(match arch {
69                        CommonArch::Aarch64 => {
70                            "hyperv.uefi.mscoreuefi.AARCH64.RELEASE/MsvmAARCH64/RELEASE_CLANGPDB/FV"
71                        }
72                        CommonArch::X86_64 => {
73                            "hyperv.uefi.mscoreuefi.x64.RELEASE/MsvmX64/RELEASE_VS2022/FV"
74                        }
75                    });
76                    let dst = dst_folder.join("MSVM.fd");
77
78                    if msvm_fd.absolute()? != dst.absolute()? {
79                        fs_err::create_dir_all(&dst_folder)?;
80                        fs_err::copy(msvm_fd, dst)?;
81                    }
82                }
83                Ok(())
84            }
85        });
86
87        Ok(())
88    }
89}