Skip to content

Commit e82958a

Browse files
crawfxrdjackpot51
authored andcommitted
bios: Preserve BootOrder when flashing
1 parent f2294a3 commit e82958a

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

src/app/bios.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use ecflash::{Ec, EcFlash};
66
use intel_spi::{HsfStsCtl, Spi, SpiKbl, SpiCnl};
77
use plain::Plain;
88
use std::fs::{find, load};
9+
use std::vars::{get_boot_item, get_boot_order, set_boot_item, set_boot_order};
910
use uefi::status::{Error, Result};
1011

1112
use crate::key::raw_key;
@@ -390,9 +391,38 @@ impl Component for BiosComponent {
390391
} else {
391392
find(FIRMWARENSH)?;
392393

393-
let cmd = format!("{} {} bios flash", FIRMWARENSH, FIRMWAREDIR);
394+
let mut boot_options: Vec<(u16, Vec<u8>)> = vec!();
394395

396+
let order = get_boot_order();
397+
if order.is_ok() {
398+
println!("Preserving boot order");
399+
for num in order.clone().unwrap() {
400+
if let Ok(item) = get_boot_item(num) {
401+
boot_options.push((num, item));
402+
} else {
403+
println!("Failed to read Boot{:>04X}", num);
404+
}
405+
}
406+
} else {
407+
println!("Failed to preserve boot order");
408+
}
409+
410+
let cmd = format!("{} {} bios flash", FIRMWARENSH, FIRMWAREDIR);
395411
let status = shell(&cmd)?;
412+
413+
if order.is_ok() {
414+
if set_boot_order(&order.unwrap()).is_ok() {
415+
for (num, data) in boot_options {
416+
if set_boot_item(num, &data).is_err() {
417+
println!("Failed to write Boot{:>04X}", num);
418+
}
419+
}
420+
println!("Restored boot order");
421+
} else {
422+
println!("Failed to restore boot order");
423+
}
424+
}
425+
396426
if status != 0 {
397427
println!("{} Flash Error: {}", self.name(), status);
398428
return Err(Error::DeviceError);

0 commit comments

Comments
 (0)