@@ -64,7 +64,8 @@ const EC_MEMMAP_SIZE: u16 = 0xFF;
6464/// representing 'EC' in ASCII (0x20 == 'E', 0x21 == 'C')
6565const EC_MEMMAP_ID : u16 = 0x20 ;
6666
67- const FLASH_BASE : u32 = 0x0 ; // 0x80000
67+ const FLASH_BASE : u32 = 0x0 ;
68+ const FLASH_SIZE : u32 = 0x80000 ;
6869const FLASH_RO_BASE : u32 = 0x0 ;
6970const FLASH_RO_SIZE : u32 = 0x3C000 ;
7071const FLASH_RW_BASE : u32 = 0x40000 ;
@@ -76,6 +77,7 @@ const FLASH_PROGRAM_OFFSET: u32 = 0x1000;
7677#[ derive( Clone , Debug , PartialEq ) ]
7778pub enum EcFlashType {
7879 Full ,
80+ Both ,
7981 Ro ,
8082 Rw ,
8183}
@@ -817,7 +819,7 @@ impl CrosEc {
817819 ) ) ;
818820 } ;
819821
820- if ft == EcFlashType :: Full || ft == EcFlashType :: Ro {
822+ if matches ! ( ft , EcFlashType :: Full | EcFlashType :: Both | EcFlashType :: Ro ) {
821823 if let Some ( version) = ec_binary:: read_ec_version ( data, true ) {
822824 println ! ( "EC RO Version in File: {:?}" , version. version) ;
823825 if version. details . platform != platform {
@@ -832,7 +834,7 @@ impl CrosEc {
832834 ) ) ;
833835 }
834836 }
835- if ft == EcFlashType :: Full || ft == EcFlashType :: Rw {
837+ if matches ! ( ft , EcFlashType :: Full | EcFlashType :: Both | EcFlashType :: Rw ) {
836838 if let Some ( version) = ec_binary:: read_ec_version ( data, false ) {
837839 println ! ( "EC RW Version in File: {:?}" , version. version) ;
838840 if version. details . platform != platform {
@@ -874,7 +876,41 @@ impl CrosEc {
874876 // 2. Read back two rows and make sure it's all 0xFF
875877 // 3. Write each row (128B) individually
876878
877- if ft == EcFlashType :: Full || ft == EcFlashType :: Rw {
879+ if ft == EcFlashType :: Full {
880+ if data. len ( ) < FLASH_SIZE as usize {
881+ return Err ( EcError :: DeviceError ( format ! (
882+ "Firmware file too small for full flash. Expected {} bytes, got {}" ,
883+ FLASH_SIZE ,
884+ data. len( )
885+ ) ) ) ;
886+ }
887+ let data = & data[ ..FLASH_SIZE as usize ] ;
888+
889+ println ! (
890+ "Erasing full flash{}" ,
891+ if dry_run { " (DRY RUN)" } else { "" }
892+ ) ;
893+ self . erase_ec_flash ( FLASH_BASE , FLASH_SIZE , dry_run, info. erase_block_size ) ?;
894+ println ! ( " Done" ) ;
895+
896+ println ! (
897+ "Writing full flash{}" ,
898+ if dry_run { " (DRY RUN)" } else { "" }
899+ ) ;
900+ self . write_ec_flash ( FLASH_BASE , data, dry_run) ?;
901+ println ! ( " Done" ) ;
902+
903+ println ! ( "Verifying full flash region" ) ;
904+ let flash_data = self . read_ec_flash ( FLASH_BASE , FLASH_SIZE ) ?;
905+ if data == flash_data {
906+ println ! ( " flash verify success" ) ;
907+ } else {
908+ error ! ( "Flash verify fail!" ) ;
909+ res = Err ( EcError :: DeviceError ( "Flash verify fail!" . to_string ( ) ) ) ;
910+ }
911+ }
912+
913+ if ft == EcFlashType :: Both || ft == EcFlashType :: Rw {
878914 let rw_data = & data[ FLASH_RW_BASE as usize ..( FLASH_RW_BASE + FLASH_RW_SIZE ) as usize ] ;
879915
880916 println ! (
@@ -906,7 +942,7 @@ impl CrosEc {
906942 }
907943 }
908944
909- if ft == EcFlashType :: Full || ft == EcFlashType :: Ro {
945+ if ft == EcFlashType :: Both || ft == EcFlashType :: Ro {
910946 let ro_data = & data[ FLASH_RO_BASE as usize ..( FLASH_RO_BASE + FLASH_RO_SIZE ) as usize ] ;
911947
912948 println ! ( "Erasing RO region" ) ;
0 commit comments