Skip to content

Commit 270cac9

Browse files
Merge pull request #56 from FrameworkComputer/rust-1.75
Update Rust to stable and update dependencies
2 parents 7d6f99d + ec3b577 commit 270cac9

File tree

9 files changed

+330
-230
lines changed

9 files changed

+330
-230
lines changed

Cargo.lock

Lines changed: 272 additions & 199 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

framework_lib/Cargo.toml

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
name = "framework_lib"
33
version = "0.1.0"
44
edition = "2021"
5-
rust-version = "1.61"
5+
# Minimum Supported Rust Version
6+
# Ubuntu 24.04 LTS ships 1.75
7+
rust-version = "1.74"
68
build = "build.rs"
79

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

4547
[dependencies]
4648
lazy_static = "1.4.0"
47-
sha2 = { version = "0.10.6", default-features = false, features = [ "force-soft" ] }
48-
regex = { version = "1.10.0", default-features = false }
49+
sha2 = { version = "0.10.8", default-features = false, features = [ "force-soft" ] }
50+
regex = { version = "1.10.6", default-features = false }
4951
redox_hwio = { git = "https://github.com/FrameworkComputer/rust-hwio", branch = "freebsd", default-features = false }
5052
libc = { version = "0.2.155", optional = true }
51-
clap = { version = "4.0", features = ["derive"], optional = true }
52-
clap-verbosity-flag = { version = "2.0.1", optional = true }
53-
nix = { version = "0.25.0", optional = true }
53+
clap = { version = "4.5", features = ["derive"], optional = true }
54+
clap-verbosity-flag = { version = "2.2.1", optional = true }
55+
nix = { version = "0.29.0", features = ["ioctl", "user"], optional = true }
5456
num = { version = "0.4", default-features = false }
5557
num-derive = { version = "0.4", default-features = false }
5658
num-traits = { version = "0.2", default-features = false }
57-
env_logger = { version = "0.10.0", optional = true }
59+
env_logger = { version = "0.11", optional = true }
5860
log = { version = "0.4", default-features = true }
5961
uefi = { version = "0.20", features = ["alloc"], optional = true }
6062
uefi-services = { version = "0.17", optional = true }
6163
plain = { version = "0.2.3", optional = true }
62-
spin = { version = "0.9.4", optional = false }
63-
hidapi = { version = "2.1.0", optional = true }
64-
rusb = { version = "0.9.1", optional = true }
64+
spin = { version = "0.9.8", optional = false }
65+
# hidapi 2.6.2 needs nightly
66+
# See: https://github.com/ruabmbua/hidapi-rs/pull/158
67+
hidapi = { version = "=2.6.1", optional = true }
68+
rusb = { version = "0.9.4", optional = true }
6569
no-std-compat = { version = "0.4.1", features = [ "alloc" ] }
6670
guid_macros = { path = "../guid_macros" }
6771
wmi = { version = "0.13.3", optional = true }
@@ -78,7 +82,7 @@ default-features = false
7882

7983
[dependencies.windows]
8084
optional = true
81-
version = "0.42.0"
85+
version = "0.59.0"
8286
features = [
8387
"Win32_Foundation",
8488
"Win32_Storage_FileSystem",

framework_lib/src/audio_card.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub fn check_synaptics_fw_version() {
4646
{
4747
continue;
4848
}
49-
let mut handle = dev.open().unwrap();
49+
let handle = dev.open().unwrap();
5050

5151
let interface_number = if let Some(num) = find_hid_interface(&handle) {
5252
num

framework_lib/src/chromium_ec/cros_ec.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use nix::ioctl_readwrite;
22
use num_traits::FromPrimitive;
33
use std::os::unix::io::AsRawFd;
4+
use std::sync::{Arc, Mutex};
45

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

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

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

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

6970
fn get_fildes() -> i32 {
70-
unsafe { CROS_EC_FD.as_ref().unwrap().as_raw_fd() }
71+
let fd = CROS_EC_FD.lock().unwrap();
72+
fd.as_ref().unwrap().as_raw_fd()
7173
}
7274

7375
// TODO: Also de-init
7476
fn init() {
77+
let mut device = CROS_EC_FD.lock().unwrap();
78+
if (*device).is_some() {
79+
return;
80+
}
7581
match std::fs::File::open(DEV_PATH) {
7682
Err(why) => println!("Failed to open {}. Because: {:?}", DEV_PATH, why),
77-
Ok(file) => unsafe { CROS_EC_FD = Some(file) },
83+
Ok(file) => *device = Some(file),
7884
};
7985
// 2. Read max 80 bytes and check if equal to "1.0.0"
8086
// 3. Make sure it's v2

framework_lib/src/chromium_ec/windows.rs

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use std::sync::{Arc, Mutex};
44
#[allow(unused_imports)]
55
use windows::{
66
core::*,
7-
w,
87
Win32::Foundation::*,
98
Win32::{
109
Storage::FileSystem::*,
@@ -15,8 +14,14 @@ use windows::{
1514
use crate::chromium_ec::EC_MEMMAP_SIZE;
1615
use crate::chromium_ec::{EcError, EcResponseStatus, EcResult};
1716

17+
// Create a wrapper around HANDLE to mark it as Send.
18+
// I'm not sure, but I think it's safe to do that for this type of HANDL.
19+
#[derive(Copy, Clone)]
20+
struct DevHandle(HANDLE);
21+
unsafe impl Send for DevHandle {}
22+
1823
lazy_static! {
19-
static ref DEVICE: Arc<Mutex<Option<HANDLE>>> = Arc::new(Mutex::new(None));
24+
static ref DEVICE: Arc<Mutex<Option<DevHandle>>> = Arc::new(Mutex::new(None));
2025
}
2126

2227
fn init() {
@@ -27,18 +32,18 @@ fn init() {
2732

2833
let path = w!(r"\\.\GLOBALROOT\Device\CrosEC");
2934
unsafe {
30-
*device = Some(
35+
*device = Some(DevHandle(
3136
CreateFileW(
3237
path,
33-
FILE_GENERIC_READ | FILE_GENERIC_WRITE,
38+
FILE_GENERIC_READ.0 | FILE_GENERIC_WRITE.0,
3439
FILE_SHARE_READ | FILE_SHARE_WRITE,
3540
None,
3641
OPEN_EXISTING,
3742
FILE_FLAGS_AND_ATTRIBUTES(0),
3843
None,
3944
)
4045
.unwrap(),
41-
);
46+
));
4247
}
4348
}
4449

@@ -56,8 +61,13 @@ pub fn read_memory(offset: u16, length: u16) -> EcResult<Vec<u8>> {
5661
let retb: u32 = 0;
5762
unsafe {
5863
let device = DEVICE.lock().unwrap();
64+
let device = if let Some(device) = *device {
65+
device
66+
} else {
67+
return EcResult::Err(EcError::DeviceError("No EC device".to_string()));
68+
};
5969
DeviceIoControl(
60-
*device,
70+
device.0,
6171
IOCTL_CROSEC_RDMEM,
6272
Some(const_ptr),
6373
ptr_size,
@@ -94,16 +104,22 @@ pub fn send_command(command: u16, command_version: u8, data: &[u8]) -> EcResult<
94104

95105
unsafe {
96106
let device = DEVICE.lock().unwrap();
107+
let device = if let Some(device) = *device {
108+
device
109+
} else {
110+
return EcResult::Err(EcError::DeviceError("No EC device".to_string()));
111+
};
97112
DeviceIoControl(
98-
*device,
113+
device.0,
99114
IOCTL_CROSEC_XCMD,
100115
Some(const_ptr),
101116
size.try_into().unwrap(),
102117
Some(mut_ptr),
103118
size.try_into().unwrap(),
104119
Some(&mut returned as *mut u32),
105120
None,
106-
);
121+
)
122+
.unwrap();
107123
}
108124

109125
match FromPrimitive::from_u32(cmd.result) {

framework_lib/src/util.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ pub enum Platform {
3636

3737
#[derive(Debug)]
3838
pub struct Config {
39-
pub verbose: bool,
39+
// TODO: Actually set and read this
40+
pub _verbose: bool,
4041
pub platform: Platform,
4142
}
4243

@@ -49,7 +50,7 @@ impl Config {
4950

5051
if (*config).is_none() {
5152
*config = Some(Config {
52-
verbose: false,
53+
_verbose: false,
5354
platform,
5455
});
5556
}
@@ -76,7 +77,7 @@ impl Config {
7677
// get_platform will call Config::get() recursively,
7778
// can't hold the lock when calling it
7879
smbios::get_platform().map(|platform| Config {
79-
verbose: false,
80+
_verbose: false,
8081
platform,
8182
})
8283
} else {

framework_uefi/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
name = "framework_uefi"
33
version = "0.1.0"
44
edition = "2021"
5-
rust-version = "1.68"
5+
# Minimum Supported Rust Version
6+
rust-version = "1.74"
67

78
[[bin]]
89
name = "uefitool"

framework_uefi/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,4 @@ $(BUILD)/boot.efi: ../Cargo.lock $(SRC_DIR)/Cargo.toml $(SRC_DIR)/src/*
4545
--target $(TARGET) \
4646
--release \
4747
-- \
48-
-C soft-float \
4948
--emit link=framework_uefi/$@

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[toolchain]
22
profile = "default"
3-
channel = "1.68.2"
3+
channel = "stable"
44
components = ["rust-src", "clippy", "rustfmt"]
55
targets = ["x86_64-unknown-uefi"]

0 commit comments

Comments
 (0)