Skip to content

Commit

Permalink
Merge pull request #7 from FrameworkComputer/updates
Browse files Browse the repository at this point in the history
Properly support TGL, RPL, avoiding panicking
  • Loading branch information
JohnAZoidberg authored Oct 18, 2023
2 parents 7ebfe61 + 2a3d7c5 commit 00d2e36
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 64 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 23 additions & 12 deletions framework_lib/src/ccgx/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,22 @@ impl PdPort {
}

/// I2C port on the EC
fn i2c_port(&self) -> u8 {
fn i2c_port(&self) -> EcResult<u8> {
let config = Config::get();
let platform = &(*config).as_ref().unwrap().platform;

match (platform, self) {
Ok(match (platform, self) {
(Platform::IntelGen11, _) => 6,
(Platform::IntelGen12, PdPort::Left01) => 6,
(Platform::IntelGen12, PdPort::Right23) => 7,
(Platform::IntelGen13, PdPort::Left01) => 6,
(Platform::IntelGen13, PdPort::Right23) => 7,
(_, _) => panic!("Unsupported platform: {:?} {:?}", platform, self),
}
// TODO: AMD
(_, _) => Err(EcError::DeviceError(format!(
"Unsupported platform: {:?} {:?}",
platform, self
)))?,
})
}
}

Expand Down Expand Up @@ -176,7 +180,7 @@ impl PdController {
let msgs_buffer: &[u8] = unsafe { util::any_vec_as_u8_slice(&messages) };

let params = EcParamsI2cPassthru {
port: self.port.i2c_port(),
port: self.port.i2c_port()?,
messages: messages.len() as u8,
msg: [], // Messages are copied right after this struct
};
Expand Down Expand Up @@ -280,13 +284,20 @@ impl PdController {

pub fn print_fw_info(&self) {
let data = self.ccgx_read(ControlRegisters::BootLoaderVersion, 8);
let data = data.unwrap();
let data = match data {
Ok(data) => data,
Err(err) => {
println!("Failed to get PD Info: {:?}", err);
return;
}
};

assert!(data.len() >= 8);
debug_assert_eq!(data.len(), 8);
let base_ver = BaseVersion::from(&data[..4]);
let app_ver = AppVersion::try_from(&data[4..]);
let app_ver = AppVersion::from(&data[4..]);
println!(
" Bootloader Version: Base: {}, App: {:?}",
" Bootloader Version: Base: {}, App: {}",
base_ver, app_ver
);

Expand All @@ -295,9 +306,9 @@ impl PdController {
assert!(data.len() >= 8);
debug_assert_eq!(data.len(), 8);
let base_ver = BaseVersion::from(&data[..4]);
let app_ver = AppVersion::try_from(&data[4..]);
let app_ver = AppVersion::from(&data[4..]);
println!(
" FW1 (Backup) Version: Base: {}, App: {:?}",
" FW1 (Backup) Version: Base: {}, App: {}",
base_ver, app_ver
);

Expand All @@ -306,9 +317,9 @@ impl PdController {
assert!(data.len() >= 8);
debug_assert_eq!(data.len(), 8);
let base_ver = BaseVersion::from(&data[..4]);
let app_ver = AppVersion::try_from(&data[4..]);
let app_ver = AppVersion::from(&data[4..]);
println!(
" FW2 (Main) Version: Base: {}, App: {:?}",
" FW2 (Main) Version: Base: {}, App: {}",
base_ver, app_ver
);
}
Expand Down
26 changes: 9 additions & 17 deletions framework_lib/src/ccgx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ pub struct AppVersion {
/// Curcuit part of the version. Z of X.Y.Z
pub circuit: u8,
}

impl fmt::Display for AppVersion {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
Expand All @@ -166,34 +167,25 @@ impl fmt::Display for AppVersion {
}
}

impl TryFrom<&[u8]> for AppVersion {
type Error = ();

fn try_from(data: &[u8]) -> Result<Self, Self::Error> {
impl From<&[u8]> for AppVersion {
fn from(data: &[u8]) -> Self {
let application = match &[data[1], data[0]] {
b"nb" => Application::Notebook,
b"md" => Application::Monitor,
b"aa" => Application::AA,
_ => {
debug!(
"Couldn't parse application 0x{:X}, 0x{:X}",
data[0], data[1]
);
return Err(());
}
_ => Application::Invalid,
};
Ok(Self {
Self {
application,
circuit: data[2],
major: (data[3] & 0xF0) >> 4,
minor: data[3] & 0x0F,
})
}
}
}
impl TryFrom<u32> for AppVersion {
type Error = ();
fn try_from(data: u32) -> Result<Self, Self::Error> {
Self::try_from(u32::to_le_bytes(data).as_slice())
impl From<u32> for AppVersion {
fn from(data: u32) -> Self {
Self::from(u32::to_le_bytes(data).as_slice())
}
}

Expand Down
50 changes: 35 additions & 15 deletions framework_lib/src/commandline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,24 +303,26 @@ fn print_versions(ec: &CrosEc) {
if let Some(esrt) = esrt::get_esrt() {
for entry in &esrt.entries {
match entry.fw_class {
esrt::RETIMER01_GUID
| esrt::RETIMER23_GUID
| esrt::GEN13_RETIMER01_GUID
| esrt::GEN13_RETIMER23_GUID => {
esrt::TGL_RETIMER01_GUID
| esrt::TGL_RETIMER23_GUID
| esrt::ADL_RETIMER01_GUID
| esrt::ADL_RETIMER23_GUID
| esrt::RPL_RETIMER01_GUID
| esrt::RPL_RETIMER23_GUID => {
if !found_retimer {
found_retimer = true;
}
}
_ => {}
}
match entry.fw_class {
esrt::RETIMER01_GUID | esrt::GEN13_RETIMER01_GUID => {
esrt::TGL_RETIMER01_GUID | esrt::ADL_RETIMER01_GUID | esrt::RPL_RETIMER01_GUID => {
println!(
" Left: 0x{:X} ({})",
entry.fw_version, entry.fw_version
);
}
esrt::RETIMER23_GUID | esrt::GEN13_RETIMER23_GUID => {
esrt::TGL_RETIMER23_GUID | esrt::ADL_RETIMER23_GUID | esrt::RPL_RETIMER23_GUID => {
println!(
" Right: 0x{:X} ({})",
entry.fw_version, entry.fw_version
Expand All @@ -329,7 +331,8 @@ fn print_versions(ec: &CrosEc) {
_ => {}
}
}
} else if !found_retimer {
}
if !found_retimer {
println!(" Unknown");
}

Expand Down Expand Up @@ -710,7 +713,7 @@ fn smbios_info() {
}
}
DefinedStruct::SystemInformation(data) => {
println!("BIOS Information");
println!("System Information");
if let Some(version) = dmidecode_string_val(&data.version()) {
println!(" Version: {}", version);
}
Expand Down Expand Up @@ -784,19 +787,31 @@ pub fn analyze_capsule(data: &[u8]) -> Option<capsule::EfiCapsuleHeader> {
capsule::print_capsule_header(&header);

match header.capsule_guid {
esrt::BIOS_GUID => {
println!(" Type: Framework Insyde BIOS");
esrt::TGL_BIOS_GUID => {
println!(" Type: Framework TGL Insyde BIOS");
}
esrt::ADL_BIOS_GUID => {
println!(" Type: Framework ADL Insyde BIOS");
}
esrt::RPL_BIOS_GUID => {
println!(" Type: Framework RPL Insyde BIOS");
}
esrt::TGL_RETIMER01_GUID => {
println!(" Type: Framework TGL Retimer01 (Left)");
}
esrt::TGL_RETIMER23_GUID => {
println!(" Type: Framework TGL Retimer23 (Right)");
}
esrt::RETIMER01_GUID => {
esrt::ADL_RETIMER01_GUID => {
println!(" Type: Framework ADL Retimer01 (Left)");
}
esrt::RETIMER23_GUID => {
esrt::ADL_RETIMER23_GUID => {
println!(" Type: Framework ADL Retimer23 (Right)");
}
esrt::GEN13_RETIMER01_GUID => {
esrt::RPL_RETIMER01_GUID => {
println!(" Type: Framework RPL Retimer01 (Left)");
}
esrt::GEN13_RETIMER23_GUID => {
esrt::RPL_RETIMER23_GUID => {
println!(" Type: Framework RPL Retimer23 (Right)");
}
esrt::WINUX_GUID => {
Expand All @@ -810,7 +825,12 @@ pub fn analyze_capsule(data: &[u8]) -> Option<capsule::EfiCapsuleHeader> {
}

match esrt::match_guid_kind(&header.capsule_guid) {
esrt::FrameworkGuidKind::Retimer01 | esrt::FrameworkGuidKind::Retimer23 => {
esrt::FrameworkGuidKind::TglRetimer01
| esrt::FrameworkGuidKind::TglRetimer23
| esrt::FrameworkGuidKind::AdlRetimer01
| esrt::FrameworkGuidKind::AdlRetimer23
| esrt::FrameworkGuidKind::RplRetimer01
| esrt::FrameworkGuidKind::RplRetimer23 => {
if let Some(ver) = find_retimer_version(data) {
println!(" Version: {:>18?}", ver);
}
Expand Down
45 changes: 30 additions & 15 deletions framework_lib/src/esrt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,18 @@ pub fn guid_from_str(string: &str) -> Option<Guid> {
))
}

pub const BIOS_GUID: Guid = guid!("a30a8cf3-847f-5e59-bd59-f9ec145c1a8c");
pub const RETIMER01_GUID: Guid = guid!("a9c91b0c-c0b8-463d-a7da-a5d6ec646333");
pub const RETIMER23_GUID: Guid = guid!("ba2e4e6e-3b0c-4f25-8a59-4c553fc86ea2");
pub const GEN13_RETIMER01_GUID: Guid = guid!("0c42b824-818f-428f-8687-5efcaf059bea");
pub const GEN13_RETIMER23_GUID: Guid = guid!("268ccbde-e087-420b-bf82-2212bd3f9bfc");
pub const TGL_BIOS_GUID: Guid = guid!("b3bdb2e4-c5cb-5c1b-bdc3-e6fc132462ff");
pub const ADL_BIOS_GUID: Guid = guid!("a30a8cf3-847f-5e59-bd59-f9ec145c1a8c");
pub const RPL_BIOS_GUID: Guid = guid!("13fd4ed2-cba9-50ba-bb91-aece0acb4cc3");
pub const TGL_RETIMER01_GUID: Guid = guid!("832af090-2ef9-7c47-8f6d-b405c8c7f156");
pub const TGL_RETIMER23_GUID: Guid = guid!("20ef4108-6c64-d049-b6de-11ee35980b8f");
pub const ADL_RETIMER01_GUID: Guid = guid!("a9c91b0c-c0b8-463d-a7da-a5d6ec646333");
pub const ADL_RETIMER23_GUID: Guid = guid!("ba2e4e6e-3b0c-4f25-8a59-4c553fc86ea2");
pub const RPL_RETIMER01_GUID: Guid = guid!("0c42b824-818f-428f-8687-5efcaf059bea");
pub const RPL_RETIMER23_GUID: Guid = guid!("268ccbde-e087-420b-bf82-2212bd3f9bfc");
pub const FL16_BIOS_GUID: Guid = guid!("4496aebc-2421-5dfb-9e75-03ec44245994");
pub const AMD13_BIOS_GUID: Guid = guid!("b5f7dcc1-568c-50f8-a4dd-e39d1f93fda1");
pub const RPL_CSME_GUID: Guid = guid!("865d322c-6ac7-4734-b43e-55db5a557d63");

// In EDK2
// Handled by MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c
Expand All @@ -83,11 +88,16 @@ pub const WINUX_GUID: Guid = guid!("3b8c8162-188c-46a4-aec9-be43f1d65697");

#[derive(Debug)]
pub enum FrameworkGuidKind {
Bios,
Retimer01,
Retimer23,
Gen13Retimer01,
Gen13Retimer23,
TglBios,
AdlBios,
RplBios,
TglRetimer01,
TglRetimer23,
AdlRetimer01,
AdlRetimer23,
RplRetimer01,
RplRetimer23,
RplCsme,
Fl16Bios,
Amd13Bios,
WinUx,
Expand All @@ -96,11 +106,16 @@ pub enum FrameworkGuidKind {

pub fn match_guid_kind(guid: &Guid) -> FrameworkGuidKind {
match *guid {
BIOS_GUID => FrameworkGuidKind::Bios,
RETIMER01_GUID => FrameworkGuidKind::Retimer01,
RETIMER23_GUID => FrameworkGuidKind::Retimer23,
GEN13_RETIMER01_GUID => FrameworkGuidKind::Gen13Retimer01,
GEN13_RETIMER23_GUID => FrameworkGuidKind::Gen13Retimer23,
TGL_BIOS_GUID => FrameworkGuidKind::TglBios,
ADL_BIOS_GUID => FrameworkGuidKind::AdlBios,
RPL_BIOS_GUID => FrameworkGuidKind::RplBios,
TGL_RETIMER01_GUID => FrameworkGuidKind::TglRetimer01,
TGL_RETIMER23_GUID => FrameworkGuidKind::TglRetimer23,
ADL_RETIMER01_GUID => FrameworkGuidKind::AdlRetimer01,
ADL_RETIMER23_GUID => FrameworkGuidKind::AdlRetimer23,
RPL_RETIMER01_GUID => FrameworkGuidKind::RplRetimer01,
RPL_RETIMER23_GUID => FrameworkGuidKind::RplRetimer23,
RPL_CSME_GUID => FrameworkGuidKind::RplCsme,
FL16_BIOS_GUID => FrameworkGuidKind::Fl16Bios,
AMD13_BIOS_GUID => FrameworkGuidKind::Amd13Bios,
WINUX_GUID => FrameworkGuidKind::WinUx,
Expand Down
6 changes: 3 additions & 3 deletions framework_lib/src/power.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,14 @@ pub fn get_and_print_power_info(ec: &CrosEc) {
}

fn print_battery_information(power_info: &PowerInfo) {
print!(" AC is ");
print!(" AC is: ");
if power_info.ac_present {
println!("connected.");
println!("connected");
} else {
println!("not connected");
}

print!(" Battery is: ");
print!(" Battery is: ");
if let Some(battery) = &power_info.battery {
println!("connected");
println!(
Expand Down
3 changes: 2 additions & 1 deletion framework_lib/src/smbios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,15 @@ pub fn get_platform() -> Option<Platform> {
if let DefinedStruct::SystemInformation(data) = undefined_struct.defined_struct() {
if let Some(product_name) = dmidecode_string_val(&data.product_name()) {
match product_name.as_str() {
"Laptop" => return Some(Platform::IntelGen11),
"Laptop (12th Gen Intel Core)" => return Some(Platform::IntelGen12),
"Laptop (13th Gen Intel Core)" => return Some(Platform::IntelGen13),
_ => {}
}
}
if let Some(family) = dmidecode_string_val(&data.family()) {
match family.as_str() {
// TGL Mainboard
// TGL Mainboard (I don't this ever appears in family)
"FRANBMCP" => return Some(Platform::IntelGen11),
// ADL Mainboard (I don't this ever appears in family)
"FRANMACP" => return Some(Platform::IntelGen12),
Expand Down

0 comments on commit 00d2e36

Please sign in to comment.