Skip to content
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
1,034 changes: 519 additions & 515 deletions Cargo.lock

Large diffs are not rendered by default.

19 changes: 5 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "inputmodules"
version = "0.3.17"
edition = "2021"
rust-version = "1.61"
rust-version = "1.89"
build = "build.rs"
readme = "../README.md"
license = "BSD-3-Clause"
Expand All @@ -13,34 +13,25 @@ qemu = []
azalea = []

[build-dependencies]
built = { version = "0.5.0", default-features = false, features = ["chrono", "git2"] }
built = { version = "0.8", default-features = false, features = ["chrono", "git2"] }

[dependencies]
cfg-if = "1.0.0"
embedded-graphics = "0.8.1"
getargs = { version = "0.5.0", default-features = false }
log = "0.4.27"
uefi = { version = "0.20", features = ["alloc"] }
uefi-services = "0.17"
uefi = { version = "0.41", features = ["alloc", "global_allocator", "logger", "panic_handler"] }
zune-core = "0.4.12"
redox_hwio = { git = "https://github.com/FrameworkComputer/rust-hwio", branch = "freebsd", default-features = false }
smbios-lib = { git = "https://github.com/FrameworkComputer/smbios-lib.git", branch = "no-std", default-features = false }

# Temporarily override because we need pending PRs for
# for the Shell and ShellParameters protocols
[patch.crates-io]
uefi = { git = "https://github.com/FrameworkComputer/uefi-rs", branch = "merged" }
uefi-services = { git = "https://github.com/FrameworkComputer/uefi-rs", branch = "merged" }
dmidecode = { version = "1", default-features = false }

[dependencies.zune-png]
version = "0.4.10"
default-features = false

[dependencies.framework_lib]
#path = "/home/zoid/clone/framework-system/framework_lib"
git = "https://github.com/FrameworkComputer/framework-system"
rev = "v0.4.3"
#branch = "main"
version = "0.6.7"
features = ["uefi"]
default-features = false

Expand Down
4 changes: 0 additions & 4 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,7 @@
cargoLock = {
lockFile = ./Cargo.lock;
outputHashes = {
"framework_lib-0.4.3" = "sha256-gO7ieyVQzK3BkNsy451WNtrx51jlzd6vhwJX8RDoj/o=";
"guid-create-0.4.1" = "sha256-tf38uNtC8YhDN4TZ3yfj4oOG3mYccHPa962YCLkVx4g=";
"redox_hwio-0.1.6" = "sha256-knLIZ7yp42SQYk32NGq3SUGvJFVumFhD64Njr5TRdFs=";
"smbios-lib-0.9.1" = "sha256-3L8JaA75j9Aaqg1z9lVs61m6CvXDeQprEFRq+UDCHQo=";
"uefi-0.20.0" = "sha256-2lUd2a+7NvS94LyAHE2BwGV4j6607mbPXE5htrwdz04=";
};
};

Expand Down
2 changes: 1 addition & 1 deletion src/drawing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use framework_lib::chromium_ec::input_deck::{InputModuleType, TopRowPositions};
use framework_lib::power::ReducedPowerInfo;
#[allow(unused_imports)]
use log::{debug, error, info, trace};
use uefi::boot::ScopedProtocol;
use uefi::proto::console::gop::GraphicsOutput;
use uefi::table::boot::ScopedProtocol;
use zune_core::result::DecodingResult;
use zune_png::PngDecoder;

Expand Down
9 changes: 9 additions & 0 deletions src/ec_comm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ pub fn get_input_deck(ec: &Option<CrosEc>) -> InputDeckStatus {
state: InputDeckState::On,
hubboard_present: true,
touchpad_present: true,
touchpad_id: InputModuleType::Touchpad as u8,
top_row: TopRowPositions {
pos0: InputModuleType::KeyboardA,
pos1: InputModuleType::Disconnected,
Expand All @@ -95,6 +96,7 @@ pub fn get_input_deck(ec: &Option<CrosEc>) -> InputDeckStatus {
state: InputDeckState::On,
hubboard_present: false,
touchpad_present: true,
touchpad_id: InputModuleType::Touchpad as u8,
top_row: TopRowPositions {
pos0: InputModuleType::GenericB,
pos1: InputModuleType::Disconnected,
Expand Down Expand Up @@ -350,6 +352,7 @@ pub fn keypress_mock_data(
state: input_deck::InputDeckState::Disconnected,
hubboard_present: true,
touchpad_present: true,
touchpad_id: InputModuleType::Touchpad as u8,
top_row: input_deck::TopRowPositions {
pos0: input_deck::InputModuleType::Disconnected,
pos1: input_deck::InputModuleType::Disconnected,
Expand All @@ -365,6 +368,7 @@ pub fn keypress_mock_data(
state: input_deck::InputDeckState::Disconnected,
hubboard_present: true,
touchpad_present: false,
touchpad_id: InputModuleType::Disconnected as u8,
top_row: input_deck::TopRowPositions {
pos0: input_deck::InputModuleType::Disconnected,
pos1: input_deck::InputModuleType::Disconnected,
Expand All @@ -380,6 +384,7 @@ pub fn keypress_mock_data(
state: input_deck::InputDeckState::Disconnected,
hubboard_present: true,
touchpad_present: false,
touchpad_id: InputModuleType::Disconnected as u8,
top_row: input_deck::TopRowPositions {
pos0: input_deck::InputModuleType::GenericC,
pos1: input_deck::InputModuleType::Disconnected,
Expand All @@ -395,6 +400,7 @@ pub fn keypress_mock_data(
state: input_deck::InputDeckState::Disconnected,
hubboard_present: true,
touchpad_present: false,
touchpad_id: InputModuleType::Disconnected as u8,
top_row: input_deck::TopRowPositions {
pos0: input_deck::InputModuleType::GenericC,
pos1: input_deck::InputModuleType::GenericC,
Expand All @@ -410,6 +416,7 @@ pub fn keypress_mock_data(
state: input_deck::InputDeckState::Disconnected,
hubboard_present: true,
touchpad_present: false,
touchpad_id: InputModuleType::Disconnected as u8,
top_row: input_deck::TopRowPositions {
pos0: input_deck::InputModuleType::GenericC,
pos1: input_deck::InputModuleType::GenericC,
Expand All @@ -425,6 +432,7 @@ pub fn keypress_mock_data(
state: input_deck::InputDeckState::On,
hubboard_present: true,
touchpad_present: true,
touchpad_id: InputModuleType::Touchpad as u8,
top_row: input_deck::TopRowPositions {
pos0: input_deck::InputModuleType::GenericC,
pos1: input_deck::InputModuleType::GenericC,
Expand All @@ -440,6 +448,7 @@ pub fn keypress_mock_data(
state: input_deck::InputDeckState::On,
hubboard_present: true,
touchpad_present: true,
touchpad_id: InputModuleType::Touchpad as u8,
top_row: input_deck::TopRowPositions {
pos0: input_deck::InputModuleType::FullWidth,
pos1: input_deck::InputModuleType::Disconnected,
Expand Down
70 changes: 30 additions & 40 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@

extern crate alloc;

use alloc::string::ToString;
use alloc::string::{String, ToString};
use alloc::vec::Vec;
use framework_lib::chromium_ec::input_deck::InputDeckState;
use framework_lib::chromium_ec::{print_err, CrosEc};
#[allow(unused_imports)]
use log::{debug, error, info, trace};
use uefi::boot::{self, OpenProtocolAttributes, OpenProtocolParams, SearchType};
use uefi::prelude::*;
use uefi::proto::shell_params::*;
use uefi::table::boot::{OpenProtocolAttributes, OpenProtocolParams, SearchType};
use uefi::proto::shell_params::ShellParameters;
use uefi::Identify;
#[allow(unused_imports)]
use uefi_services::{print, println};
use uefi::{print, println};

mod buffer;
mod drawing;
Expand All @@ -33,14 +34,10 @@ struct BiosSettings {
inputmodule_setting: Option<oem_variable::InputmoduleSetting>,
}

fn get_bios_settings(boot_services: &BootServices) -> Option<BiosSettings> {
fn get_bios_settings() -> Option<BiosSettings> {
// If the protocol isn't present, assume nothing is disabled and show the UI
let oem_handle = boot_services
.get_handle_for_protocol::<oem_variable::UefiVariable>()
.ok()?;
let oem = boot_services
.open_protocol_exclusive::<oem_variable::UefiVariable>(oem_handle)
.ok()?;
let oem_handle = boot::get_handle_for_protocol::<oem_variable::UefiVariable>().ok()?;
let oem = boot::open_protocol_exclusive::<oem_variable::UefiVariable>(oem_handle).ok()?;

Some(BiosSettings {
standalone_mode: oem.standalone_mode_enabled(),
Expand All @@ -57,8 +54,8 @@ fn get_bios_settings(boot_services: &BootServices) -> Option<BiosSettings> {
/// - dGPU PD is outdated
/// - Fan has issues
/// - Interposer or door has issues
fn show_ui(boot_services: &BootServices) -> Option<bool> {
let settings = get_bios_settings(boot_services)?;
fn show_ui() -> Option<bool> {
let settings = get_bios_settings()?;
let require_inputmodules =
settings.inputmodule_setting == Some(oem_variable::InputmoduleSetting::RequireModules);

Expand All @@ -85,24 +82,23 @@ pub unsafe extern "C" fn wcslen(s: *const u16) -> usize {
}

#[entry]
fn main(image_handle: Handle, mut system_table: SystemTable<Boot>) -> Status {
let event = uefi_services::init(&mut system_table).unwrap();
let boot_services = system_table.boot_services();
fn main() -> Status {
uefi::helpers::init().unwrap();

// Only error prints in release build
#[cfg(not(debug_assertions))]
log::set_max_level(log::LevelFilter::Error);

let arg = get_shell_action(boot_services);
let arg = get_shell_action();
if let Ok(ShellAction::Info) = arg {
println!("Provide Parameter: 'gui' to launch UI and show issues");
println!("Provide Parameter: 'force' to launch UI even if everything is ok");
println!("Provide Parameter: 'gop' to print GOP debugging info");
println!();
print_module_status(&boot_services);
print_module_status();
} else if let Ok(ShellAction::GopInfo) = arg {
println!("GOP Info");
state_machine::print_gop_info(boot_services);
state_machine::print_gop_info();
} else {
info!("No shell arg, launching GUI");

Expand All @@ -114,11 +110,11 @@ fn main(image_handle: Handle, mut system_table: SystemTable<Boot>) -> Status {
let force_ui = matches!(arg, Ok(ShellAction::Force));

// Show the UI if we can't tell the BIOS settings or they indicate we need to show the UI
let show_ui = show_ui(boot_services) != Some(false);
let show_ui = show_ui() != Some(false);

let reset = if force_ui || show_ui {
ec_comm::set_uefi_app_mode(&ec, true);
let gui_res = state_machine::start(boot_services, &system_table, &ec, force_ui);
let gui_res = state_machine::start(&ec, force_ui);
ec_comm::set_uefi_app_mode(&ec, false);
gui_res.unwrap()
} else {
Expand All @@ -129,20 +125,14 @@ fn main(image_handle: Handle, mut system_table: SystemTable<Boot>) -> Status {
if let Some(reset_type) = reset {
#[cfg(debug_assertions)]
info!("Shutting down");
boot_services.stall(1_000_000);
boot::stall(core::time::Duration::from_micros(1_000_000));

// Shut down the system
// TODO: I should do this outside of this function
let rt = system_table.runtime_services();
rt.reset(reset_type, Status::SUCCESS, None);
uefi::runtime::reset(reset_type, Status::SUCCESS, None);
}
}

if let Some(event) = event {
// Will crash when Linux boots if we don't call this
boot_services.close_event(event).unwrap();
}

Status::SUCCESS
}

Expand All @@ -154,17 +144,17 @@ enum ShellAction {
GopInfo,
}

fn get_shell_action(boot_services: &BootServices) -> uefi::Result<ShellAction> {
fn get_shell_action() -> uefi::Result<ShellAction> {
// TODO: I think I should open this from the ImageHandle?
let shell_params_h =
boot_services.locate_handle_buffer(SearchType::ByProtocol(&ShellParameters::GUID))?;
trace!("Found {} ShellParameters handles", (*shell_params_h).len());
for handle in &*shell_params_h {
boot::locate_handle_buffer(SearchType::ByProtocol(&ShellParameters::GUID))?;
trace!("Found {} ShellParameters handles", shell_params_h.len());
for handle in shell_params_h.iter() {
let params_handle = unsafe {
boot_services.open_protocol::<ShellParameters>(
boot::open_protocol::<ShellParameters>(
OpenProtocolParams {
handle: *handle,
agent: boot_services.image_handle(),
agent: boot::image_handle(),
controller: None,
},
OpenProtocolAttributes::GetProtocol,
Expand All @@ -173,11 +163,11 @@ fn get_shell_action(boot_services: &BootServices) -> uefi::Result<ShellAction> {

// Ehm why are there two and one has no args?
// Maybe one is the shell itself?
if params_handle.argc == 0 {
if params_handle.args_len() == 0 {
continue;
}

let args = params_handle.get_args();
let args: Vec<String> = params_handle.args().map(|arg| arg.to_string()).collect();
// First arg is the executable path
return Ok(if args.len() == 2 && args[1] == "gui" {
ShellAction::Gui
Expand All @@ -194,7 +184,7 @@ fn get_shell_action(boot_services: &BootServices) -> uefi::Result<ShellAction> {
Ok(ShellAction::Gui)
}

fn print_module_status(boot_services: &BootServices) {
fn print_module_status() {
print_tool_version();
println!("");

Expand Down Expand Up @@ -225,7 +215,7 @@ fn print_module_status(boot_services: &BootServices) {
}

println!(" Firmware Versions");
if let Ok(devices) = uefi_usb::get_usb_devices(boot_services) {
if let Ok(devices) = uefi_usb::get_usb_devices() {
for device in devices {
let name = if let Some(name) = device.get_name() {
name
Expand All @@ -240,7 +230,7 @@ fn print_module_status(boot_services: &BootServices) {
}

println!("BIOS Settings");
if let Some(settings) = get_bios_settings(boot_services) {
if let Some(settings) = get_bios_settings() {
println!(" Standalone Mode Enabled: {}", settings.standalone_mode);
println!(
" Inputmodule Setting: {:?}",
Expand Down
45 changes: 0 additions & 45 deletions src/shell_params.rs

This file was deleted.

Loading
Loading