Skip to content

Commit b39270b

Browse files
committed
Rearchitect EFI GUID list
Original efivar library embeds a list of EFI GUIDs in its library. This is considered limiting, so rearchitct the list so it is loaded from a resource file. This allows the EFI GUID list to be updated without needed to recompile the library.
1 parent 12a3c43 commit b39270b

File tree

6 files changed

+365
-365
lines changed

6 files changed

+365
-365
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ path = "src/bin/efivar.rs"
1818

1919
[dependencies]
2020
clap = { version = "4.1.13", default-features = false, features = ["std", "cargo", "help", "wrap_help", "usage"] }
21-
lazy_static = "1.4.0"
21+
serde = { version = "1.0.160", default-features = false, features = ["derive", "std"] }
22+
serde_json = { version = "1.0.96", default-features = false, features = ["std"] }

build.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use std::env;
2+
use std::fs;
3+
use std::path;
4+
5+
fn main() {
6+
let prefix = env::var("OUT_DIR").unwrap();
7+
let sys_conf_dir = env::var("SYSCONFDIR").unwrap_or("share".to_string());
8+
9+
let target_dir = path::Path::new(&sys_conf_dir).join("refivar");
10+
let target_path = path::Path::new(&target_dir).join("guids.json");
11+
let dest_dir = path::Path::new(&prefix).join(&target_dir);
12+
let dest_path = path::Path::new(&prefix).join(&target_path);
13+
let src_path = path::Path::new(&std::env::current_dir().unwrap())
14+
.join("src")
15+
.join("lib")
16+
.join("efivar")
17+
.join("guids.json");
18+
19+
if !dest_dir.exists() {
20+
fs::create_dir_all(&dest_dir).unwrap();
21+
}
22+
fs::copy(src_path, dest_path).unwrap();
23+
24+
print!("cargo:rustc-env=GUIDS_LIST_PATH={}", target_path.display());
25+
}

src/bin/efivar.rs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clap;
2-
use efivar::{efi_guids, efi_variable_attributes, efivar_display};
2+
use efivar::efi_guids;
33
use std::process::ExitCode;
44

55
fn create_parser() -> clap::Command {
@@ -73,10 +73,18 @@ fn create_parser() -> clap::Command {
7373
.help("import variable from <file>")
7474
.action(clap::ArgAction::Set)
7575
)
76+
.arg(clap::Arg::new("guids-list-path")
77+
.short('g')
78+
.long("guids-list-path")
79+
.value_name("guids-list-path")
80+
.default_value(efi_guids::DEFAULT_GUIDS_LIST_PATH)
81+
.help(format!("specify path to GUIDs list file."))
82+
.action(clap::ArgAction::Set)
83+
)
7684
.arg(clap::Arg::new("list-guids")
7785
.short('L')
7886
.long("list-guids")
79-
.help("show internal GUID list")
87+
.help("show GUID list")
8088
.action(clap::ArgAction::SetTrue)
8189
)
8290
.arg(clap::Arg::new("write")
@@ -102,14 +110,18 @@ fn create_parser() -> clap::Command {
102110
fn main() -> ExitCode {
103111
let matches = create_parser().get_matches();
104112
if matches.get_flag("list-guids") {
105-
for g in efi_guids::EFI_WELL_KNOWN_GUIDS
106-
.sort_by_guid()
107-
.split_last()
108-
.unwrap()
109-
.1
110-
.iter()
111-
{
112-
print!("{}", g);
113+
let mut guid_list: efi_guids::EfiGuidList = Default::default();
114+
guid_list.load(matches.get_one("guids-list-path").unwrap());
115+
for g in guid_list.guids(efi_guids::GuidListSortField::Guid) {
116+
println!("{}", g);
117+
}
118+
println!("");
119+
for g in guid_list.guids(efi_guids::GuidListSortField::Id) {
120+
println!("{}", g);
121+
}
122+
println!("");
123+
for g in guid_list.guids(efi_guids::GuidListSortField::None) {
124+
println!("{}", g);
113125
}
114126
}
115127
return std::process::ExitCode::from(0);

0 commit comments

Comments
 (0)