@@ -6,6 +6,7 @@ use ecflash::{Ec, EcFlash};
66use intel_spi:: { HsfStsCtl , Spi , SpiKbl , SpiCnl } ;
77use plain:: Plain ;
88use std:: fs:: { find, load} ;
9+ use std:: vars:: { get_boot_item, get_boot_order, set_boot_item, set_boot_order} ;
910use uefi:: status:: { Error , Result } ;
1011
1112use 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