Skip to content

ec_binary: Make it less misleading if legacy cookie not found #159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions framework_lib/src/ec_binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,38 +145,47 @@ pub fn parse_ec_version_str(version: &str) -> Option<ImageVersionDetails> {

/// Parse version information from EC FW image buffer
pub fn read_ec_version(data: &[u8], ro: bool) -> Option<ImageVersionData> {
// First try to find the legacy EC version
let offset = if ro {
EC_RO_VER_OFFSET
} else {
EC_RW_VER_OFFSET
};
let offset_zephyr = if ro {
EC_RO_VER_OFFSET_ZEPHYR
} else {
EC_RW_VER_OFFSET_ZEPHYR
};

if data.len() < offset + core::mem::size_of::<_ImageVersionData>() {
return None;
}
let v: _ImageVersionData = unsafe { std::ptr::read(data[offset..].as_ptr() as *const _) };
if v.cookie1 != CROS_EC_IMAGE_DATA_COOKIE1 {
debug!("Failed to find Cookie 1. Found: {:X?}", { v.cookie1 });
debug!("Failed to find legacy Cookie 1. Found: {:X?}", {
v.cookie1
});
} else if v.cookie2 != CROS_EC_IMAGE_DATA_COOKIE2 {
debug!("Failed to find Cookie 2. Found: {:X?}", { v.cookie2 });
debug!("Failed to find legacy Cookie 2. Found: {:X?}", {
v.cookie2
});
} else {
return parse_ec_version(&v);
}

// If not present, find Zephyr EC version
let offset_zephyr = if ro {
EC_RO_VER_OFFSET_ZEPHYR
} else {
EC_RW_VER_OFFSET_ZEPHYR
};
if data.len() < offset_zephyr + core::mem::size_of::<_ImageVersionData>() {
return None;
}
let v: _ImageVersionData =
unsafe { std::ptr::read(data[offset_zephyr..].as_ptr() as *const _) };
if v.cookie1 != CROS_EC_IMAGE_DATA_COOKIE1 {
debug!("Failed to find Cookie 1. Found: {:X?}", { v.cookie1 });
debug!("Failed to find Zephyr Cookie 1. Found: {:X?}", {
v.cookie1
});
} else if v.cookie2 != CROS_EC_IMAGE_DATA_COOKIE2 {
debug!("Failed to find Cookie 2. Found: {:X?}", { v.cookie2 });
debug!("Failed to find Zephyr Cookie 2. Found: {:X?}", {
v.cookie2
});
} else {
return parse_ec_version(&v);
}
Expand Down
Loading