@@ -724,6 +724,23 @@ impl CrosEc {
724
724
}
725
725
}
726
726
727
+ // Determine recommended flash parameters
728
+ let info = EcRequestFlashInfo { } . send_command ( self ) ?;
729
+
730
+ // Check that our hardcoded offsets are valid for the available flash
731
+ if FLASH_RO_SIZE + FLASH_RW_SIZE > info. flash_size {
732
+ return Err ( EcError :: DeviceError ( format ! (
733
+ "RO+RW larger than flash 0x{:X}" ,
734
+ { info. flash_size }
735
+ ) ) ) ;
736
+ }
737
+ if FLASH_RW_BASE + FLASH_RW_SIZE > info. flash_size {
738
+ return Err ( EcError :: DeviceError ( format ! (
739
+ "RW overruns end of flash 0x{:X}" ,
740
+ { info. flash_size }
741
+ ) ) ) ;
742
+ }
743
+
727
744
println ! ( "Unlocking flash" ) ;
728
745
self . flash_notify ( MecFlashNotify :: AccessSpi ) ?;
729
746
self . flash_notify ( MecFlashNotify :: FirmwareStart ) ?;
@@ -736,11 +753,22 @@ impl CrosEc {
736
753
if ft == EcFlashType :: Full || ft == EcFlashType :: Rw {
737
754
let rw_data = & data[ FLASH_RW_BASE as usize ..( FLASH_RW_BASE + FLASH_RW_SIZE ) as usize ] ;
738
755
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) ?;
756
+ println ! (
757
+ "Erasing RW region{}" ,
758
+ if dry_run { " (DRY RUN)" } else { "" }
759
+ ) ;
760
+ self . erase_ec_flash (
761
+ FLASH_BASE + FLASH_RW_BASE ,
762
+ FLASH_RW_SIZE ,
763
+ dry_run,
764
+ info. erase_block_size ,
765
+ ) ?;
741
766
println ! ( " Done" ) ;
742
767
743
- println ! ( "Writing RW region{}" , if dry_run { " (DRY RUN)" } else { "" } ) ;
768
+ println ! (
769
+ "Writing RW region{}" ,
770
+ if dry_run { " (DRY RUN)" } else { "" }
771
+ ) ;
744
772
self . write_ec_flash ( FLASH_BASE + FLASH_RW_BASE , rw_data, dry_run) ?;
745
773
println ! ( " Done" ) ;
746
774
@@ -758,7 +786,12 @@ impl CrosEc {
758
786
let ro_data = & data[ FLASH_RO_BASE as usize ..( FLASH_RO_BASE + FLASH_RO_SIZE ) as usize ] ;
759
787
760
788
println ! ( "Erasing RO region" ) ;
761
- self . erase_ec_flash ( FLASH_BASE + FLASH_RO_BASE , FLASH_RO_SIZE , dry_run) ?;
789
+ self . erase_ec_flash (
790
+ FLASH_BASE + FLASH_RO_BASE ,
791
+ FLASH_RO_SIZE ,
792
+ dry_run,
793
+ info. erase_block_size ,
794
+ ) ?;
762
795
println ! ( " Done" ) ;
763
796
764
797
println ! ( "Writing RO region" ) ;
@@ -840,10 +873,15 @@ impl CrosEc {
840
873
. send_command_extra ( self , data)
841
874
}
842
875
843
- fn erase_ec_flash ( & self , offset : u32 , size : u32 , dry_run : bool ) -> EcResult < ( ) > {
876
+ fn erase_ec_flash (
877
+ & self ,
878
+ offset : u32 ,
879
+ size : u32 ,
880
+ dry_run : bool ,
881
+ chunk_size : u32 ,
882
+ ) -> EcResult < ( ) > {
844
883
// Erasing a big section takes too long sometimes and the linux kernel driver times out, so
845
- // split it up into chunks. One chunk is 1/8 of EC ROM size.
846
- let chunk_size = 0x10000 ;
884
+ // split it up into chunks.
847
885
let mut cur_offset = offset;
848
886
849
887
while cur_offset < offset + size {
0 commit comments