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::download_uefi_mu_msvm::MuMsvmArch;
15use flowey::node::prelude::*;
16use std::collections::BTreeMap;
17
18flowey_request! {
19    pub struct Request {
20        pub arch: MuMsvmArch,
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<MuMsvmArch, 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
69                        .join(format!(
70                            "hyperv.uefi.mscoreuefi.{}.RELEASE",
71                            match arch {
72                                MuMsvmArch::Aarch64 => "AARCH64",
73                                MuMsvmArch::X86_64 => "x64",
74                            }
75                        ))
76                        .join(format!(
77                            "Msvm{}",
78                            match arch {
79                                MuMsvmArch::Aarch64 => "AARCH64",
80                                MuMsvmArch::X86_64 => "X64",
81                            }
82                        ))
83                        .join("RELEASE_VS2022/FV");
84                    let dst = dst_folder.join("MSVM.fd");
85
86                    if msvm_fd.absolute()? != dst.absolute()? {
87                        fs_err::create_dir_all(&dst_folder)?;
88                        fs_err::copy(msvm_fd, dst)?;
89                    }
90                }
91                Ok(())
92            }
93        });
94
95        Ok(())
96    }
97}