hvlite_core/emuplat/
firmware.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

//! Backing implementations of various UEFI platform requirements.

use firmware_pcat::PcatEvent;
use firmware_pcat::PcatLogger;
use firmware_uefi::platform::logger::UefiEvent;
use firmware_uefi::platform::logger::UefiLogger;
use get_resources::ged::FirmwareEvent;

/// Forwards UEFI and PCAT events to via the provided [`mesh::Sender`].
#[derive(Debug)]
pub struct MeshLogger {
    sender: Option<mesh::Sender<FirmwareEvent>>,
}

impl MeshLogger {
    pub fn new(sender: Option<mesh::Sender<FirmwareEvent>>) -> Self {
        Self { sender }
    }

    fn send(&self, event: FirmwareEvent) {
        if let Some(sender) = &self.sender {
            sender.send(event);
        }
    }
}

impl UefiLogger for MeshLogger {
    fn log_event(&self, event: UefiEvent) {
        let event = match event {
            UefiEvent::BootSuccess(_) => FirmwareEvent::BootSuccess,
            UefiEvent::BootFailure(_) => FirmwareEvent::BootFailed,
            UefiEvent::NoBootDevice => FirmwareEvent::NoBootDevice,
        };
        self.send(event);
    }
}

impl PcatLogger for MeshLogger {
    fn log_event(&self, event: PcatEvent) {
        let event = match event {
            PcatEvent::BootFailure => FirmwareEvent::BootFailed,
            PcatEvent::BootAttempt => FirmwareEvent::BootAttempt,
        };
        self.send(event);
    }
}