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
471 changes: 272 additions & 199 deletions Cargo.lock

Large diffs are not rendered by default.

26 changes: 15 additions & 11 deletions framework_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
name = "framework_lib"
version = "0.1.0"
edition = "2021"
rust-version = "1.61"
# Minimum Supported Rust Version
# Ubuntu 24.04 LTS ships 1.75
rust-version = "1.74"
build = "build.rs"

[features]
Expand Down Expand Up @@ -44,24 +46,26 @@ built = { version = "0.5", features = ["chrono", "git2"] }

[dependencies]
lazy_static = "1.4.0"
sha2 = { version = "0.10.6", default-features = false, features = [ "force-soft" ] }
regex = { version = "1.10.0", default-features = false }
sha2 = { version = "0.10.8", default-features = false, features = [ "force-soft" ] }
regex = { version = "1.10.6", default-features = false }
redox_hwio = { git = "https://github.com/FrameworkComputer/rust-hwio", branch = "freebsd", default-features = false }
libc = { version = "0.2.155", optional = true }
clap = { version = "4.0", features = ["derive"], optional = true }
clap-verbosity-flag = { version = "2.0.1", optional = true }
nix = { version = "0.25.0", optional = true }
clap = { version = "4.5", features = ["derive"], optional = true }
clap-verbosity-flag = { version = "2.2.1", optional = true }
nix = { version = "0.29.0", features = ["ioctl", "user"], optional = true }
num = { version = "0.4", default-features = false }
num-derive = { version = "0.4", default-features = false }
num-traits = { version = "0.2", default-features = false }
env_logger = { version = "0.10.0", optional = true }
env_logger = { version = "0.11", optional = true }
log = { version = "0.4", default-features = true }
uefi = { version = "0.20", features = ["alloc"], optional = true }
uefi-services = { version = "0.17", optional = true }
plain = { version = "0.2.3", optional = true }
spin = { version = "0.9.4", optional = false }
hidapi = { version = "2.1.0", optional = true }
rusb = { version = "0.9.1", optional = true }
spin = { version = "0.9.8", optional = false }
# hidapi 2.6.2 needs nightly
# See: https://github.com/ruabmbua/hidapi-rs/pull/158
hidapi = { version = "=2.6.1", optional = true }
rusb = { version = "0.9.4", optional = true }
no-std-compat = { version = "0.4.1", features = [ "alloc" ] }
guid_macros = { path = "../guid_macros" }
wmi = { version = "0.13.3", optional = true }
Expand All @@ -78,7 +82,7 @@ default-features = false

[dependencies.windows]
optional = true
version = "0.42.0"
version = "0.59.0"
features = [
"Win32_Foundation",
"Win32_Storage_FileSystem",
Expand Down
2 changes: 1 addition & 1 deletion framework_lib/src/audio_card.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub fn check_synaptics_fw_version() {
{
continue;
}
let mut handle = dev.open().unwrap();
let handle = dev.open().unwrap();

let interface_number = if let Some(num) = find_hid_interface(&handle) {
num
Expand Down
16 changes: 11 additions & 5 deletions framework_lib/src/chromium_ec/cros_ec.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use nix::ioctl_readwrite;
use num_traits::FromPrimitive;
use std::os::unix::io::AsRawFd;
use std::sync::{Arc, Mutex};

use crate::chromium_ec::command::EcCommands;
use crate::chromium_ec::{EcError, EcResponseStatus, EcResult, EC_MEMMAP_SIZE};
Expand Down Expand Up @@ -56,9 +57,9 @@ struct CrosEcCommandV2 {

const DEV_PATH: &str = "/dev/cros_ec";

// TODO: Make sure this is thread-safe!
// Are file descriptors threadsafe? Or do I need to open one per thread?
static mut CROS_EC_FD: Option<std::fs::File> = None;
lazy_static! {
static ref CROS_EC_FD: Arc<Mutex<Option<std::fs::File>>> = Arc::new(Mutex::new(None));
}

const CROS_EC_IOC_MAGIC: u8 = 0xEC;
ioctl_readwrite!(cros_ec_cmd, CROS_EC_IOC_MAGIC, 0, _CrosEcCommandV2);
Expand All @@ -67,14 +68,19 @@ ioctl_readwrite!(cros_ec_mem, CROS_EC_IOC_MAGIC, 1, CrosEcReadMem);
//ioctl_none!(cros_ec_eventmask, CROS_EC_IOC_MAGIC, 2);

fn get_fildes() -> i32 {
unsafe { CROS_EC_FD.as_ref().unwrap().as_raw_fd() }
let fd = CROS_EC_FD.lock().unwrap();
fd.as_ref().unwrap().as_raw_fd()
}

// TODO: Also de-init
fn init() {
let mut device = CROS_EC_FD.lock().unwrap();
if (*device).is_some() {
return;
}
match std::fs::File::open(DEV_PATH) {
Err(why) => println!("Failed to open {}. Because: {:?}", DEV_PATH, why),
Ok(file) => unsafe { CROS_EC_FD = Some(file) },
Ok(file) => *device = Some(file),
};
// 2. Read max 80 bytes and check if equal to "1.0.0"
// 3. Make sure it's v2
Expand Down
32 changes: 24 additions & 8 deletions framework_lib/src/chromium_ec/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::sync::{Arc, Mutex};
#[allow(unused_imports)]
use windows::{
core::*,
w,
Win32::Foundation::*,
Win32::{
Storage::FileSystem::*,
Expand All @@ -15,8 +14,14 @@ use windows::{
use crate::chromium_ec::EC_MEMMAP_SIZE;
use crate::chromium_ec::{EcError, EcResponseStatus, EcResult};

// Create a wrapper around HANDLE to mark it as Send.
// I'm not sure, but I think it's safe to do that for this type of HANDL.
#[derive(Copy, Clone)]
struct DevHandle(HANDLE);
unsafe impl Send for DevHandle {}

lazy_static! {
static ref DEVICE: Arc<Mutex<Option<HANDLE>>> = Arc::new(Mutex::new(None));
static ref DEVICE: Arc<Mutex<Option<DevHandle>>> = Arc::new(Mutex::new(None));
}

fn init() {
Expand All @@ -27,18 +32,18 @@ fn init() {

let path = w!(r"\\.\GLOBALROOT\Device\CrosEC");
unsafe {
*device = Some(
*device = Some(DevHandle(
CreateFileW(
path,
FILE_GENERIC_READ | FILE_GENERIC_WRITE,
FILE_GENERIC_READ.0 | FILE_GENERIC_WRITE.0,
FILE_SHARE_READ | FILE_SHARE_WRITE,
None,
OPEN_EXISTING,
FILE_FLAGS_AND_ATTRIBUTES(0),
None,
)
.unwrap(),
);
));
}
}

Expand All @@ -56,8 +61,13 @@ pub fn read_memory(offset: u16, length: u16) -> EcResult<Vec<u8>> {
let retb: u32 = 0;
unsafe {
let device = DEVICE.lock().unwrap();
let device = if let Some(device) = *device {
device
} else {
return EcResult::Err(EcError::DeviceError("No EC device".to_string()));
};
DeviceIoControl(
*device,
device.0,
IOCTL_CROSEC_RDMEM,
Some(const_ptr),
ptr_size,
Expand Down Expand Up @@ -94,16 +104,22 @@ pub fn send_command(command: u16, command_version: u8, data: &[u8]) -> EcResult<

unsafe {
let device = DEVICE.lock().unwrap();
let device = if let Some(device) = *device {
device
} else {
return EcResult::Err(EcError::DeviceError("No EC device".to_string()));
};
DeviceIoControl(
*device,
device.0,
IOCTL_CROSEC_XCMD,
Some(const_ptr),
size.try_into().unwrap(),
Some(mut_ptr),
size.try_into().unwrap(),
Some(&mut returned as *mut u32),
None,
);
)
.unwrap();
}

match FromPrimitive::from_u32(cmd.result) {
Expand Down
7 changes: 4 additions & 3 deletions framework_lib/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ pub enum Platform {

#[derive(Debug)]
pub struct Config {
pub verbose: bool,
// TODO: Actually set and read this
pub _verbose: bool,
pub platform: Platform,
}

Expand All @@ -49,7 +50,7 @@ impl Config {

if (*config).is_none() {
*config = Some(Config {
verbose: false,
_verbose: false,
platform,
});
}
Expand All @@ -76,7 +77,7 @@ impl Config {
// get_platform will call Config::get() recursively,
// can't hold the lock when calling it
smbios::get_platform().map(|platform| Config {
verbose: false,
_verbose: false,
platform,
})
} else {
Expand Down
3 changes: 2 additions & 1 deletion framework_uefi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
name = "framework_uefi"
version = "0.1.0"
edition = "2021"
rust-version = "1.68"
# Minimum Supported Rust Version
rust-version = "1.74"

[[bin]]
name = "uefitool"
Expand Down
1 change: 0 additions & 1 deletion framework_uefi/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,4 @@ $(BUILD)/boot.efi: ../Cargo.lock $(SRC_DIR)/Cargo.toml $(SRC_DIR)/src/*
--target $(TARGET) \
--release \
-- \
-C soft-float \
--emit link=framework_uefi/$@
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[toolchain]
profile = "default"
channel = "1.68.2"
channel = "stable"
components = ["rust-src", "clippy", "rustfmt"]
targets = ["x86_64-unknown-uefi"]