Skip to content

Commit 0d6eb82

Browse files
committed
Make EC drivers optional
First step to getting the crate to support no_std so that we can use it in UEFI. Avoid compiling code to interface with Linux drivers and the dependencies we need for that. Signed-off-by: Daniel Schaefer <[email protected]>
1 parent 12cd455 commit 0d6eb82

File tree

4 files changed

+30
-7
lines changed

4 files changed

+30
-7
lines changed

.github/workflows/ci.yml

+7-1
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,17 @@ jobs:
1212
- name: Setup Rust toolchain
1313
run: rustup show
1414

15-
- name: Run cargo build
15+
- name: Build without optional features
1616
uses: actions-rs/cargo@v1
1717
with:
1818
command: build
1919

20+
- name: Build with all features enabled
21+
uses: actions-rs/cargo@v1
22+
with:
23+
command: build
24+
args: --all-features
25+
2026
test:
2127
name: Test Suite
2228
runs-on: ubuntu-latest

framework_lib/Cargo.toml

+13-3
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,31 @@ edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

8+
[features]
9+
default = []
10+
# EC communication via Port I/O on Linux
11+
linux_pio = ["dep:libc"]
12+
# EC communication via raw Port I/O (e.g. UEFI or other ring 0 code)
13+
raw_pio = []
14+
# EC communication via cros_ec driver on Linux
15+
cros_ec_driver = ["dep:nix"]
16+
817
[dependencies]
918
regex = "1.6.0" # TODO: Can update to 1.7.0
1019
# TODO: This doesn't work on:
1120
# - Windows
1221
# - Linux when SecureBoot (Lockdown) is enabled
1322
# Need to use the driver in those cases
1423
redox_hwio = "0.1.6"
15-
libc = "0.2.137"
24+
libc = { version = "0.2.137", optional = true }
1625
clap = { version = "4.0", features = ["derive"] }
17-
nix = "0.25.0"
26+
nix = { version = "0.25.0", optional = true }
1827
num = "0.4"
1928
num-derive = "0.3"
2029
num-traits = "0.2"
21-
#[target.'cfg(windows)'.dependencies]
30+
2231
[dependencies.windows]
32+
optional = true
2333
version = "0.42.0"
2434
features = [
2535
"Win32_Foundation",

framework_lib/src/chromium_ec/mod.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::util;
22

33
use num_derive::FromPrimitive;
4+
#[cfg(feature = "cros_ec_driver")]
45
mod cros_ec;
56
mod portio;
67
//mod windows;
@@ -57,7 +58,9 @@ pub fn read_memory(offset: u16, length: u16) -> Option<Vec<u8>> {
5758
match 0 {
5859
0 => portio::read_memory(offset, length),
5960
//1 => windows::read_memory(offset, length),
60-
_ => cros_ec::read_memory(offset, length),
61+
#[cfg(feature = "cros_ec_driver")]
62+
2 => cros_ec::read_memory(offset, length),
63+
_ => None,
6164
}
6265
}
6366

@@ -76,7 +79,9 @@ pub fn send_command(command: u16, command_version: u8, data: &[u8]) -> Option<Ve
7679
match 0 {
7780
0 => portio::send_command(command, command_version, data),
7881
//1 => windows::send_command(command, command_version, data),
79-
_ => cros_ec::send_command(command, command_version, data),
82+
#[cfg(feature = "cros_ec_driver")]
83+
2 => cros_ec::send_command(command, command_version, data),
84+
_ => None,
8085
}
8186
}
8287

framework_lib/src/chromium_ec/portio.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use core::convert::TryInto;
22
use hwio::{Io, Pio};
3+
#[cfg(feature = "linux_pio")]
4+
use libc::ioperm;
35

46
use crate::chromium_ec::EC_MEMMAP_SIZE;
57
use crate::os_specific;
@@ -277,10 +279,10 @@ fn transfer_read(address: u16, size: u16) -> Vec<u8> {
277279
buffer
278280
}
279281

280-
use libc::ioperm;
281282
fn init() {
282283
// In Linux userspace has to first request access to ioports
283284
// TODO: Close these again after we're done
285+
#[cfg(feature = "linux_pio")]
284286
unsafe {
285287
ioperm(EC_LPC_ADDR_HOST_DATA as u64, 8, 1);
286288
ioperm(MEC_LPC_ADDRESS_REGISTER0 as u64, 10, 1);

0 commit comments

Comments
 (0)