Write a big section of EC flash. Must be unlocked already
(&self, addr: u32, data: &[u8], dry_run: bool)
| 1045 | |
| 1046 | /// Write a big section of EC flash. Must be unlocked already |
| 1047 | fn write_ec_flash(&self, addr: u32, data: &[u8], dry_run: bool) -> EcResult<()> { |
| 1048 | // TODO: Use flash info to help guide ideal chunk size |
| 1049 | // let info = EcRequestFlashInfo {}.send_command(self)?; |
| 1050 | //let chunk_size = ((0x80 / info.write_ideal_size) * info.write_ideal_size) as usize; |
| 1051 | |
| 1052 | let chunk_size = 0x80; |
| 1053 | |
| 1054 | let chunks = data.len() / chunk_size; |
| 1055 | println!( |
| 1056 | " Will write flash from 0x{:X} to 0x{:X} in {}*{}B chunks", |
| 1057 | addr, |
| 1058 | data.len(), |
| 1059 | chunks, |
| 1060 | chunk_size |
| 1061 | ); |
| 1062 | for chunk_no in 0..chunks { |
| 1063 | let offset = chunk_no * chunk_size; |
| 1064 | // Current chunk might be smaller if it's the last |
| 1065 | let cur_chunk_size = std::cmp::min(chunk_size, data.len() - chunk_no * chunk_size); |
| 1066 | |
| 1067 | if chunk_no % 100 == 0 { |
| 1068 | if chunk_no != 0 { |
| 1069 | println!(); |
| 1070 | } |
| 1071 | print!(" Chunk {:>4}: X", chunk_no); |
| 1072 | } else { |
| 1073 | print!("X"); |
| 1074 | } |
| 1075 | |
| 1076 | let chunk = &data[offset..offset + cur_chunk_size]; |
| 1077 | if !dry_run { |
| 1078 | let res = self.write_ec_flash_chunk(addr + offset as u32, chunk); |
| 1079 | if let Err(err) = res { |
| 1080 | println!(" Failed to write chunk: {:?}", err); |
| 1081 | return Err(err); |
| 1082 | } |
| 1083 | } |
| 1084 | } |
| 1085 | println!(); |
| 1086 | |
| 1087 | Ok(()) |
| 1088 | } |
| 1089 | |
| 1090 | fn write_ec_flash_chunk(&self, offset: u32, data: &[u8]) -> EcResult<()> { |
| 1091 | assert!(data.len() <= 0x80); // TODO: I think this is EC_LPC_HOST_PACKET_SIZE - size_of::<EcHostResponse>() |
no test coverage detected