Skip to content

Commit dc28506

Browse files
committed
Load platform settings from config
This is useful instead of the commandline parameters --has-mec --pd-ports --pd-addrs when SMBIOS doesn't correctly detect the correct platform settings. - [x] Read from CWD - [x] Test on Windows - [ ] Test on Linux - [ ] Test on UEFI - [x] Read from same folder as binary - [x] Test on Windows - [ ] Test on Linux - [ ] Test on UEFI - [ ] Read from $XDG_CONFIG_HOME on Linux Sample config for Framework 13 AMD: ``` [platform] has_mec = false pd_addrs = [ 0x42, 0x40 ] pd_ports = [ 1, 2 ] ``` Signed-off-by: Daniel Schaefer <[email protected]>
1 parent 96a7ed9 commit dc28506

File tree

6 files changed

+154
-21
lines changed

6 files changed

+154
-21
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
target/
22
build/
3+
framework_tool_config.toml

Cargo.lock

Lines changed: 97 additions & 21 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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ win_driver = []
4545
built = { version = "0.5", features = ["chrono", "git2"] }
4646

4747
[dependencies]
48+
toml = "0.8.20"
49+
serde = "1.0.217"
4850
lazy_static = "1.4.0"
4951
sha2 = { version = "0.10.8", default-features = false, features = [ "force-soft" ] }
5052
regex = { version = "1.10.6", default-features = false }

framework_lib/src/commandline/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ use crate::chromium_ec::commands::RebootEcCmd;
3838
use crate::chromium_ec::EcResponseStatus;
3939
use crate::chromium_ec::{print_err, EcFlashType};
4040
use crate::chromium_ec::{EcError, EcResult};
41+
use crate::config;
4142
#[cfg(feature = "linux")]
4243
use crate::csme;
4344
use crate::ec_binary;
@@ -644,6 +645,11 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
644645
.init();
645646
}
646647

648+
if let Some(loaded_config) = config::load_config() {
649+
println!("{:?}", loaded_config);
650+
Config::set(loaded_config);
651+
}
652+
647653
// Must be run before any application code to set the config
648654
if args.pd_addrs.is_some() && args.pd_ports.is_some() && args.has_mec.is_some() {
649655
let platform = Platform::GenericFramework(

framework_lib/src/config.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
use serde::Deserialize;
2+
3+
use crate::util;
4+
5+
#[derive(Debug, Deserialize)]
6+
struct Config {
7+
platform: Option<Platform>,
8+
}
9+
10+
#[derive(Debug, Deserialize)]
11+
struct Platform {
12+
has_mec: bool,
13+
pd_addrs: Vec<u16>,
14+
pd_ports: Vec<u8>,
15+
}
16+
17+
const CONFIG_FILE: &str = "framework_tool_config.toml";
18+
19+
pub fn load_config() -> Option<util::Platform> {
20+
let mut path = std::env::current_exe().unwrap();
21+
path.pop();
22+
path.push(CONFIG_FILE);
23+
24+
let toml_str = if let Ok(str) = std::fs::read_to_string(path) {
25+
str
26+
} else {
27+
path = CONFIG_FILE.into();
28+
std::fs::read_to_string(path).unwrap()
29+
};
30+
31+
let decoded: Config = toml::from_str(&toml_str).unwrap();
32+
println!("{:?}", decoded);
33+
34+
let decoded = decoded.platform.unwrap();
35+
let first_pd = (decoded.pd_addrs[0], decoded.pd_ports[0]);
36+
let second_pd = if decoded.pd_addrs.is_empty() || decoded.pd_ports.is_empty() {
37+
first_pd
38+
} else {
39+
(decoded.pd_addrs[1], decoded.pd_ports[1])
40+
};
41+
42+
Some(util::Platform::GenericFramework(
43+
(first_pd.0, second_pd.0),
44+
(first_pd.1, second_pd.1),
45+
decoded.has_mec,
46+
))
47+
}

framework_lib/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub mod capsule_content;
2424
pub mod ccgx;
2525
pub mod chromium_ec;
2626
pub mod commandline;
27+
mod config;
2728
pub mod csme;
2829
pub mod ec_binary;
2930
pub mod esrt;

0 commit comments

Comments
 (0)