Skip to content

Commit bff2536

Browse files
Merge pull request #159 from FrameworkComputer/ec-bin-parse
ec_binary: Make it less misleading if legacy cookie not found
2 parents 3a96295 + 39e20f5 commit bff2536

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

framework_lib/src/ec_binary.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -145,38 +145,47 @@ pub fn parse_ec_version_str(version: &str) -> Option<ImageVersionDetails> {
145145

146146
/// Parse version information from EC FW image buffer
147147
pub fn read_ec_version(data: &[u8], ro: bool) -> Option<ImageVersionData> {
148+
// First try to find the legacy EC version
148149
let offset = if ro {
149150
EC_RO_VER_OFFSET
150151
} else {
151152
EC_RW_VER_OFFSET
152153
};
153-
let offset_zephyr = if ro {
154-
EC_RO_VER_OFFSET_ZEPHYR
155-
} else {
156-
EC_RW_VER_OFFSET_ZEPHYR
157-
};
158-
159154
if data.len() < offset + core::mem::size_of::<_ImageVersionData>() {
160155
return None;
161156
}
162157
let v: _ImageVersionData = unsafe { std::ptr::read(data[offset..].as_ptr() as *const _) };
163158
if v.cookie1 != CROS_EC_IMAGE_DATA_COOKIE1 {
164-
debug!("Failed to find Cookie 1. Found: {:X?}", { v.cookie1 });
159+
debug!("Failed to find legacy Cookie 1. Found: {:X?}", {
160+
v.cookie1
161+
});
165162
} else if v.cookie2 != CROS_EC_IMAGE_DATA_COOKIE2 {
166-
debug!("Failed to find Cookie 2. Found: {:X?}", { v.cookie2 });
163+
debug!("Failed to find legacy Cookie 2. Found: {:X?}", {
164+
v.cookie2
165+
});
167166
} else {
168167
return parse_ec_version(&v);
169168
}
170169

170+
// If not present, find Zephyr EC version
171+
let offset_zephyr = if ro {
172+
EC_RO_VER_OFFSET_ZEPHYR
173+
} else {
174+
EC_RW_VER_OFFSET_ZEPHYR
175+
};
171176
if data.len() < offset_zephyr + core::mem::size_of::<_ImageVersionData>() {
172177
return None;
173178
}
174179
let v: _ImageVersionData =
175180
unsafe { std::ptr::read(data[offset_zephyr..].as_ptr() as *const _) };
176181
if v.cookie1 != CROS_EC_IMAGE_DATA_COOKIE1 {
177-
debug!("Failed to find Cookie 1. Found: {:X?}", { v.cookie1 });
182+
debug!("Failed to find Zephyr Cookie 1. Found: {:X?}", {
183+
v.cookie1
184+
});
178185
} else if v.cookie2 != CROS_EC_IMAGE_DATA_COOKIE2 {
179-
debug!("Failed to find Cookie 2. Found: {:X?}", { v.cookie2 });
186+
debug!("Failed to find Zephyr Cookie 2. Found: {:X?}", {
187+
v.cookie2
188+
});
180189
} else {
181190
return parse_ec_version(&v);
182191
}

0 commit comments

Comments
 (0)