MCPcopy Create free account
hub / github.com/FrameworkComputer/framework-system / read_ec_version

Function read_ec_version

framework_lib/src/ec_binary.rs:149–193  ·  view source on GitHub ↗

Parse version information from EC FW image buffer

(data: &[u8], ro: bool)

Source from the content-addressed store, hash-verified

147
148/// Parse version information from EC FW image buffer
149pub 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)]
196mod tests {

Callers 3

can_parse_adl_ecFunction · 0.85
reflashMethod · 0.85
analyze_ec_fwFunction · 0.85

Calls 2

parse_ec_versionFunction · 0.85
getMethod · 0.80

Tested by 1

can_parse_adl_ecFunction · 0.68