Skip to content

Commit e4b0416

Browse files
jackpot51crawfxrd
authored andcommitted
Add support for setting serial using AMIDE if found
1 parent 5e3fd2f commit e4b0416

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
@@ -13,7 +13,7 @@ use std::vars::{get_boot_item, get_boot_order, set_boot_item, set_boot_order};
1313
use std::uefi::reset::ResetType;
1414
use std::uefi::status::{Error, Result, Status};
1515

16-
use super::{FIRMWARECAP, FIRMWAREDIR, FIRMWARENSH, FIRMWAREROM, H2OFFT, IFLASHV, UEFIFLASH, shell, Component, pci_mcfg, UefiMapper};
16+
use super::{AMIDE, FIRMWARECAP, FIRMWAREDIR, FIRMWARENSH, FIRMWAREROM, H2OFFT, IFLASHV, SERIAL, UEFIFLASH, shell, Component, pci_mcfg, UefiMapper};
1717

1818
fn copy_region(region: intelflash::RegionKind, old_data: &[u8], new_data: &mut [u8]) -> core::result::Result<bool, String> {
1919
let old_opt = intelflash::Rom::new(old_data)?.get_region_base_limit(region)?;
@@ -188,6 +188,23 @@ impl BiosComponent {
188188
println!("Failed to locate EC");
189189
}
190190
}
191+
192+
fn set_serial(&self, serial: &str) -> Result<()> {
193+
if find(AMIDE).is_ok() {
194+
let cmd = format!("{} /SS {}", AMIDE, serial);
195+
let status = shell(&cmd)?;
196+
197+
if status == 0 {
198+
Ok(())
199+
} else {
200+
println!("{} Set Serial Error: {}", self.name(), status);
201+
Err(Error::DeviceError)
202+
}
203+
} else {
204+
//TODO
205+
Err(Error::NotFound)
206+
}
207+
}
191208
}
192209

193210
impl Component for BiosComponent {
@@ -541,6 +558,25 @@ impl Component for BiosComponent {
541558
}
542559
}
543560

561+
if let Ok(serial_vec) = load(SERIAL) {
562+
match String::from_utf8(serial_vec) {
563+
Ok(serial_str) => {
564+
let serial = serial_str.trim();
565+
match self.set_serial(&serial) {
566+
Ok(()) => {
567+
println!("Set serial to '{}'", serial);
568+
},
569+
Err(err) => {
570+
println!("Failed to set serial to '{}': {:?}", serial, err);
571+
}
572+
}
573+
},
574+
Err(err) => {
575+
println!("Failed to parse serial: {:?}", err);
576+
}
577+
}
578+
}
579+
544580
Ok(())
545581
}
546582
}

src/app/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ mod ec;
3838
mod mapper;
3939
mod pci;
4040

41+
static AMIDE: &str = concat!("\\", env!("BASEDIR"), "\\firmware\\amide.efi");
4142
static ECROM: &str = concat!("\\", env!("BASEDIR"), "\\firmware\\ec.rom");
4243
static ECTAG: &str = concat!("\\", env!("BASEDIR"), "\\firmware\\ec.tag");
4344
static EC2ROM: &str = concat!("\\", env!("BASEDIR"), "\\firmware\\ec2.rom");
@@ -50,6 +51,7 @@ static IFLASHV: &str = concat!("\\", env!("BASEDIR"), "\\firmware\\iflashv.efi")
5051
static IFLASHVTAG: &str = concat!("\\", env!("BASEDIR"), "\\firmware\\iflashv.tag");
5152
static IPXEEFI: &str = concat!("\\", env!("BASEDIR"), "\\firmware\\ipxe.efi");
5253
static MESETTAG: &str = concat!("\\", env!("BASEDIR"), "\\firmware\\meset.tag");
54+
static SERIAL: &str = concat!("\\", env!("BASEDIR"), "\\serial");
5355
static SHELLEFI: &str = concat!("\\", env!("BASEDIR"), "\\res\\shell.efi");
5456
static SPLASHBMP: &str = concat!("\\", env!("BASEDIR"), "\\res\\splash.bmp");
5557
static UEFIFLASH: &str = concat!("\\", env!("BASEDIR"), "\\firmware\\uefiflash.efi");

0 commit comments

Comments
 (0)