|
| 1 | +use uefi::prelude::*; |
| 2 | +use uefi::proto::misc::{ResetNotification, Timestamp}; |
| 3 | +use uefi::table::runtime; |
| 4 | + |
| 5 | +/// |
| 6 | +/// you may see those log, it's nothing just for your computer firmware does not support the new UEFI feature. |
| 7 | +/// |
| 8 | +/// ```sh |
| 9 | +/// [ INFO]: uefi-test-runner\src\proto\misc.rs@012: Running loaded Timestamp Protocol test |
| 10 | +/// [ WARN]: uefi-test-runner\src\proto\misc.rs@026: Failed to open Timestamp Protocol: Error { status: UNSUPPORTED, data: () } |
| 11 | +/// [ INFO]: uefi-test-runner\src\proto\misc.rs@033: Running loaded ResetNotification protocol test |
| 12 | +/// [ WARN]: uefi-test-runner\src\proto\misc.rs@068: Failed to open ResetNotification Protocol: Error { status: UNSUPPORTED, data: () } |
| 13 | +/// ``` |
| 14 | +pub fn test(image: Handle, bt: &BootServices) { |
| 15 | + test_timestamp(image, bt); |
| 16 | + test_reset_notification(image, bt); |
| 17 | +} |
| 18 | + |
| 19 | +pub fn test_timestamp(image: Handle, bt: &BootServices) { |
| 20 | + info!("Running loaded Timestamp Protocol test"); |
| 21 | + |
| 22 | + let result = bt |
| 23 | + .open_protocol_exclusive::<Timestamp>(image); |
| 24 | + |
| 25 | + match result { |
| 26 | + Ok(timestamp_proto) => { |
| 27 | + let timestamp = timestamp_proto.get_timestamp(); |
| 28 | + info!("Timestamp Protocol's timestamp: {:?}", timestamp); |
| 29 | + |
| 30 | + let properties = timestamp_proto.get_properties(); |
| 31 | + info!("Timestamp Protocol's properties: {:?}", properties); |
| 32 | + } |
| 33 | + Err(err) => { |
| 34 | + warn!("Failed to open Timestamp Protocol: {:?}", err); |
| 35 | + } |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | + |
| 40 | +pub fn test_reset_notification(image: Handle, bt: &BootServices) { |
| 41 | + info!("Running loaded ResetNotification protocol test"); |
| 42 | + |
| 43 | + let result = bt |
| 44 | + .open_protocol_exclusive::<ResetNotification>(image); |
| 45 | + |
| 46 | + match result { |
| 47 | + Ok(mut reset_notif_proto) => { |
| 48 | + let result = reset_notif_proto.register_reset_notify(None); |
| 49 | + info!("ResetNotification Protocol register null test: {:?}", result); |
| 50 | + |
| 51 | + let result = reset_notif_proto.unregister_reset_notify(None); |
| 52 | + info!("ResetNotification Protocol unregister null test: {:?}", result); |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | + // value efi_reset_fn is the type of ResetSystemFn, a function pointer |
| 57 | + unsafe extern "efiapi" fn efi_reset_fn( |
| 58 | + rt: runtime::ResetType, |
| 59 | + status: Status, |
| 60 | + data_size: usize, |
| 61 | + data: *const u8, |
| 62 | + ) { |
| 63 | + info!("Inside the event callback, hi, efi_reset_fn"); |
| 64 | + info!("rt: {:?} status: {:?}", rt, status); |
| 65 | + info!("size: {:?} data: {:?}", data_size, data); |
| 66 | + // do what you want |
| 67 | + } |
| 68 | + |
| 69 | + let result = reset_notif_proto.register_reset_notify(Some(efi_reset_fn)); |
| 70 | + info!("ResetNotification Protocol register efi_reset_fn test: {:?}", result); |
| 71 | + |
| 72 | + let result = reset_notif_proto.unregister_reset_notify(Some(efi_reset_fn)); |
| 73 | + info!("ResetNotification Protocol unregister efi_reset_fn test: {:?}", result); |
| 74 | + } |
| 75 | + Err(err) => { |
| 76 | + warn!("Failed to open ResetNotification Protocol: {:?}", err); |
| 77 | + } |
| 78 | + } |
| 79 | +} |
| 80 | + |
0 commit comments