@@ -703,7 +703,7 @@ impl CrosEc {
703
703
/// | 3C000 | 3FFFF | 04000 | Preserved |
704
704
/// | 40000 | 3C000 | 39000 | RO Region |
705
705
/// | 79000 | 79FFF | 01000 | Flash Flags |
706
- pub fn reflash ( & self , data : & [ u8 ] , ft : EcFlashType ) -> EcResult < ( ) > {
706
+ pub fn reflash ( & self , data : & [ u8 ] , ft : EcFlashType , dry_run : bool ) -> EcResult < ( ) > {
707
707
let mut res = Ok ( ( ) ) ;
708
708
if ft == EcFlashType :: Full || ft == EcFlashType :: Ro {
709
709
if let Some ( version) = ec_binary:: read_ec_version ( data, true ) {
@@ -724,11 +724,6 @@ impl CrosEc {
724
724
}
725
725
}
726
726
727
- if ft == EcFlashType :: Full || ft == EcFlashType :: Ro {
728
- println ! ( "For safety reasons flashing RO firmware is disabled." ) ;
729
- return Ok ( ( ) ) ;
730
- }
731
-
732
727
println ! ( "Unlocking flash" ) ;
733
728
self . flash_notify ( MecFlashNotify :: AccessSpi ) ?;
734
729
self . flash_notify ( MecFlashNotify :: FirmwareStart ) ?;
@@ -741,12 +736,12 @@ impl CrosEc {
741
736
if ft == EcFlashType :: Full || ft == EcFlashType :: Rw {
742
737
let rw_data = & data[ FLASH_RW_BASE as usize ..( FLASH_RW_BASE + FLASH_RW_SIZE ) as usize ] ;
743
738
744
- println ! ( "Erasing RW region" ) ;
745
- self . erase_ec_flash ( FLASH_BASE + FLASH_RW_BASE , FLASH_RW_SIZE ) ?;
739
+ println ! ( "Erasing RW region{}" , if dry_run { " (DRY RUN)" } else { "" } ) ;
740
+ self . erase_ec_flash ( FLASH_BASE + FLASH_RW_BASE , FLASH_RW_SIZE , dry_run ) ?;
746
741
println ! ( " Done" ) ;
747
742
748
- println ! ( "Writing RW region" ) ;
749
- self . write_ec_flash ( FLASH_BASE + FLASH_RW_BASE , rw_data) ?;
743
+ println ! ( "Writing RW region{}" , if dry_run { " (DRY RUN)" } else { "" } ) ;
744
+ self . write_ec_flash ( FLASH_BASE + FLASH_RW_BASE , rw_data, dry_run ) ?;
750
745
println ! ( " Done" ) ;
751
746
752
747
println ! ( "Verifying RW region" ) ;
@@ -763,11 +758,11 @@ impl CrosEc {
763
758
let ro_data = & data[ FLASH_RO_BASE as usize ..( FLASH_RO_BASE + FLASH_RO_SIZE ) as usize ] ;
764
759
765
760
println ! ( "Erasing RO region" ) ;
766
- self . erase_ec_flash ( FLASH_BASE + FLASH_RO_BASE , FLASH_RO_SIZE ) ?;
761
+ self . erase_ec_flash ( FLASH_BASE + FLASH_RO_BASE , FLASH_RO_SIZE , dry_run ) ?;
767
762
println ! ( " Done" ) ;
768
763
769
764
println ! ( "Writing RO region" ) ;
770
- self . write_ec_flash ( FLASH_BASE + FLASH_RO_BASE , ro_data) ?;
765
+ self . write_ec_flash ( FLASH_BASE + FLASH_RO_BASE , ro_data, dry_run ) ?;
771
766
println ! ( " Done" ) ;
772
767
773
768
println ! ( "Verifying RO region" ) ;
@@ -791,7 +786,7 @@ impl CrosEc {
791
786
}
792
787
793
788
/// Write a big section of EC flash. Must be unlocked already
794
- fn write_ec_flash ( & self , addr : u32 , data : & [ u8 ] ) -> EcResult < ( ) > {
789
+ fn write_ec_flash ( & self , addr : u32 , data : & [ u8 ] , dry_run : bool ) -> EcResult < ( ) > {
795
790
// TODO: Use flash info to help guide ideal chunk size
796
791
// let info = EcRequestFlashInfo {}.send_command(self)?;
797
792
//let chunk_size = ((0x80 / info.write_ideal_size) * info.write_ideal_size) as usize;
@@ -821,10 +816,12 @@ impl CrosEc {
821
816
}
822
817
823
818
let chunk = & data[ offset..offset + cur_chunk_size] ;
824
- let res = self . write_ec_flash_chunk ( addr + offset as u32 , chunk) ;
825
- if let Err ( err) = res {
826
- println ! ( " Failed to write chunk: {:?}" , err) ;
827
- return Err ( err) ;
819
+ if !dry_run {
820
+ let res = self . write_ec_flash_chunk ( addr + offset as u32 , chunk) ;
821
+ if let Err ( err) = res {
822
+ println ! ( " Failed to write chunk: {:?}" , err) ;
823
+ return Err ( err) ;
824
+ }
828
825
}
829
826
}
830
827
println ! ( ) ;
@@ -842,7 +839,7 @@ impl CrosEc {
842
839
. send_command_extra ( self , data)
843
840
}
844
841
845
- fn erase_ec_flash ( & self , offset : u32 , size : u32 ) -> EcResult < ( ) > {
842
+ fn erase_ec_flash ( & self , offset : u32 , size : u32 , dry_run : bool ) -> EcResult < ( ) > {
846
843
// Erasing a big section takes too long sometimes and the linux kernel driver times out, so
847
844
// split it up into chunks. One chunk is 1/8 of EC ROM size.
848
845
let chunk_size = 0x10000 ;
@@ -859,11 +856,13 @@ impl CrosEc {
859
856
"EcRequestFlashErase (0x{:05X}, 0x{:05X})" ,
860
857
cur_offset, cur_size
861
858
) ;
862
- EcRequestFlashErase {
863
- offset : cur_offset,
864
- size : cur_size,
859
+ if !dry_run {
860
+ EcRequestFlashErase {
861
+ offset : cur_offset,
862
+ size : cur_size,
863
+ }
864
+ . send_command ( self ) ?;
865
865
}
866
- . send_command ( self ) ?;
867
866
cur_offset += chunk_size;
868
867
}
869
868
Ok ( ( ) )
0 commit comments