Skip to content

Commit 7733545

Browse files
committed
Add support for setting serial using AMIDE if found
1 parent 20ad823 commit 7733545

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/app/bios.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::fs::{find, load};
99
use std::vars::{get_boot_item, get_boot_order, set_boot_item, set_boot_order};
1010
use uefi::status::{Error, Result};
1111

12-
use super::{FIRMWAREDIR, FIRMWARENSH, FIRMWAREROM, UEFIFLASH, shell, Component};
12+
use super::{AMIDE, FIRMWAREDIR, FIRMWARENSH, FIRMWAREROM, SERIAL, UEFIFLASH, shell, Component};
1313

1414
pub struct BiosComponent {
1515
bios_vendor: String,
@@ -107,6 +107,23 @@ impl BiosComponent {
107107
println!("Failed to locate EC");
108108
}
109109
}
110+
111+
fn set_serial(&self, serial: &str) -> Result<()> {
112+
if find(AMIDE).is_ok() {
113+
let cmd = format!("{} /SS {}", AMIDE, serial);
114+
let status = shell(&cmd)?;
115+
116+
if status == 0 {
117+
Ok(())
118+
} else {
119+
println!("{} Set Serial Error: {}", self.name(), status);
120+
Err(Error::DeviceError)
121+
}
122+
} else {
123+
//TODO
124+
Err(Error::NotFound)
125+
}
126+
}
110127
}
111128

112129
impl Component for BiosComponent {
@@ -427,6 +444,25 @@ impl Component for BiosComponent {
427444
}
428445
}
429446

447+
if let Ok(serial_vec) = load(SERIAL) {
448+
match String::from_utf8(serial_vec) {
449+
Ok(serial_str) => {
450+
let serial = serial_str.trim();
451+
match self.set_serial(&serial) {
452+
Ok(()) => {
453+
println!("Set serial to '{}'", serial);
454+
},
455+
Err(err) => {
456+
println!("Failed to set serial to '{}': {:?}", serial, err);
457+
}
458+
}
459+
},
460+
Err(err) => {
461+
println!("Failed to parse serial: {:?}", err);
462+
}
463+
}
464+
}
465+
430466
Ok(())
431467
}
432468
}

src/app/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ mod bios;
3131
mod component;
3232
mod ec;
3333

34+
static AMIDE: &'static str = concat!("\\", env!("BASEDIR"), "\\firmware\\amide.efi");
3435
static ECROM: &'static str = concat!("\\", env!("BASEDIR"), "\\firmware\\ec.rom");
3536
static EC2ROM: &'static str = concat!("\\", env!("BASEDIR"), "\\firmware\\ec2.rom");
3637
static FIRMWAREDIR: &'static str = concat!("\\", env!("BASEDIR"), "\\firmware");
3738
static FIRMWARENSH: &'static str = concat!("\\", env!("BASEDIR"), "\\res\\firmware.nsh");
3839
static FIRMWAREROM: &'static str = concat!("\\", env!("BASEDIR"), "\\firmware\\firmware.rom");
3940
static MESETTAG: &'static str = concat!("\\", env!("BASEDIR"), "\\firmware\\meset.tag");
41+
static SERIAL: &'static str = concat!("\\", env!("BASEDIR"), "\\serial");
4042
static SHELLEFI: &'static str = concat!("\\", env!("BASEDIR"), "\\res\\shell.efi");
4143
static SPLASHBMP: &'static str = concat!("\\", env!("BASEDIR"), "\\res\\splash.bmp");
4244
static UEFIFLASH: &'static str = concat!("\\", env!("BASEDIR"), "\\firmware\\uefiflash.efi");

0 commit comments

Comments
 (0)