Skip to content

Allow uefi-services to work when the "logger" feature is disabled in uefi #552

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
`error!`. This removes an extraneous file name and line number from
the log message.

- Added a `logger` feature which reflects the same feature in `uefi`.
This allows using both crates while disabling `logger` in `uefi`,
which was previously impossible.

## uefi - 0.17.0

### Added
Expand Down
5 changes: 3 additions & 2 deletions uefi-services/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ is-it-maintained-issue-resolution = { repository = "rust-osdev/uefi-rs" }
is-it-maintained-open-issues = { repository = "rust-osdev/uefi-rs" }

[dependencies]
uefi = { version = "0.17.0", features = ["alloc", "logger"] }
uefi = { version = "0.17.0", features = ["alloc"] }
log = { version = "0.4.5", default-features = false }
cfg-if = "1.0.0"
qemu-exit = { version = "3.0.1", optional = true }

[features]
default = ["panic_handler"]
default = ["panic_handler", "logger"]
# Enable QEMU-specific functionality
qemu = ["qemu-exit"]
panic_handler = []
logger = ["uefi/logger"]
7 changes: 7 additions & 0 deletions uefi-services/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ use uefi::{Event, Result};
static mut SYSTEM_TABLE: Option<SystemTable<Boot>> = None;

/// Global logger object
#[cfg(feature = "logger")]
static mut LOGGER: Option<uefi::logger::Logger> = None;

/// Obtains a pointer to the system table.
Expand Down Expand Up @@ -77,7 +78,10 @@ pub fn init(st: &mut SystemTable<Boot>) -> Result {
SYSTEM_TABLE = Some(st.unsafe_clone());

// Setup logging and memory allocation

#[cfg(feature = "logger")]
init_logger(st);

let boot_services = st.boot_services();
uefi::alloc::init(boot_services);

Expand Down Expand Up @@ -144,6 +148,7 @@ macro_rules! println {
///
/// This is unsafe because you must arrange for the logger to be reset with
/// disable() on exit from UEFI boot services.
#[cfg(feature = "logger")]
unsafe fn init_logger(st: &mut SystemTable<Boot>) {
let stdout = st.stdout();

Expand All @@ -170,6 +175,8 @@ unsafe extern "efiapi" fn exit_boot_services(_e: Event, _ctx: Option<NonNull<c_v
//
// info!("Shutting down the UEFI utility library");
SYSTEM_TABLE = None;

#[cfg(feature = "logger")]
if let Some(ref mut logger) = LOGGER {
logger.disable();
}
Expand Down