Parse version information from EC FW image buffer
(data: &[u8], ro: bool)
| 147 | |
| 148 | /// Parse version information from EC FW image buffer |
| 149 | pub fn read_ec_version(data: &[u8], ro: bool) -> Option<ImageVersionData> { |
| 150 | // First try to find the legacy EC version |
| 151 | let offset = if ro { |
| 152 | EC_RO_VER_OFFSET |
| 153 | } else { |
| 154 | EC_RW_VER_OFFSET |
| 155 | }; |
| 156 | let (v, _) = _ImageVersionData::read_from_prefix(data.get(offset..)?).ok()?; |
| 157 | if v.cookie1.get() != CROS_EC_IMAGE_DATA_COOKIE1 { |
| 158 | debug!( |
| 159 | "Failed to find legacy Cookie 1. Found: {:X?}", |
| 160 | v.cookie1.get() |
| 161 | ); |
| 162 | } else if v.cookie2.get() != CROS_EC_IMAGE_DATA_COOKIE2 { |
| 163 | debug!( |
| 164 | "Failed to find legacy Cookie 2. Found: {:X?}", |
| 165 | v.cookie2.get() |
| 166 | ); |
| 167 | } else { |
| 168 | return parse_ec_version(&v); |
| 169 | } |
| 170 | |
| 171 | // If not present, find Zephyr EC version |
| 172 | let offset_zephyr = if ro { |
| 173 | EC_RO_VER_OFFSET_ZEPHYR |
| 174 | } else { |
| 175 | EC_RW_VER_OFFSET_ZEPHYR |
| 176 | }; |
| 177 | let (v, _) = _ImageVersionData::read_from_prefix(data.get(offset_zephyr..)?).ok()?; |
| 178 | if v.cookie1.get() != CROS_EC_IMAGE_DATA_COOKIE1 { |
| 179 | debug!( |
| 180 | "Failed to find Zephyr Cookie 1. Found: {:X?}", |
| 181 | v.cookie1.get() |
| 182 | ); |
| 183 | } else if v.cookie2.get() != CROS_EC_IMAGE_DATA_COOKIE2 { |
| 184 | debug!( |
| 185 | "Failed to find Zephyr Cookie 2. Found: {:X?}", |
| 186 | v.cookie2.get() |
| 187 | ); |
| 188 | } else { |
| 189 | return parse_ec_version(&v); |
| 190 | } |
| 191 | |
| 192 | None |
| 193 | } |
| 194 | |
| 195 | #[cfg(test)] |
| 196 | mod tests { |