Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions framework_lib/src/chromium_ec/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ pub enum EcCommands {
I2cPassthrough = 0x9e,
ConsoleSnapshot = 0x97,
ConsoleRead = 0x98,
/// List the features supported by the firmware
GetFeatures = 0x0D,
/// Force reboot, causes host reboot as well
Reboot = 0xD1,
/// Control EC boot
Expand Down
149 changes: 144 additions & 5 deletions framework_lib/src/chromium_ec/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,146 @@ impl EcRequest<()> for EcRequestConsoleRead {
}
}

/// Supported features
#[derive(Debug, FromPrimitive)]
pub enum EcFeatureCode {
/// This image contains a limited set of features. Another image
/// in RW partition may support more features.
Limited = 0,
/// Commands for probing/reading/writing/erasing the flash in the
/// EC are present.
Flash = 1,
/// Can control the fan speed directly.
PwmFan = 2,
/// Can control the intensity of the keyboard backlight.
PwmKeyboardBacklight = 3,
/// Support Google lightbar, introduced on Pixel.
Lightbar = 4,
/// Control of LEDs
Led = 5,
/// Exposes an interface to control gyro and sensors.
/// The host goes through the EC to access these sensors.
/// In addition, the EC may provide composite sensors, like lid angle.
MotionSense = 6,
/// The keyboard is controlled by the EC
Keyboard = 7,
/// The AP can use part of the EC flash as persistent storage.
PersistentStorage = 8,
/// The EC monitors BIOS port 80h, and can return POST codes.
Port80 = 9,
/// Thermal management: include TMP specific commands.
/// Higher level than direct fan control.
Thermal = 10,
/// Can switch the screen backlight on/off
BacklightSwitch = 11,
/// Can switch the wifi module on/off
WifiSwitch = 12,
/// Monitor host events, through for example SMI or SCI
HostEvents = 13,
/// The EC exposes GPIO commands to control/monitor connected devices.
Gpio = 14,
/// The EC can send i2c messages to downstream devices.
I2c = 15,
/// Command to control charger are included
Charger = 16,
/// Simple battery support.
Battery = 17,
/// Support Smart battery protocol
/// (Common Smart Battery System Interface Specification)
SmartBattery = 18,
/// EC can detect when the host hangs.
HangDetect = 19,
/// Report power information, for pit only
Pmu = 20,
/// Another Cros EC device is present downstream of this one
SubMcu = 21,
/// Support USB Power delivery (PD) commands
UsbPd = 22,
/// Control USB multiplexer, for audio through USB port for instance.
UsbMux = 23,
/// Motion Sensor code has an internal software FIFO
MotionSenseFifo = 24,
/// Support temporary secure vstore
SecureVstore = 25,
/// EC decides on USB-C SS mux state, muxes configured by host
UsbcSsMuxVirtual = 26,
/// EC has RTC feature that can be controlled by host commands
Rtc = 27,
/// The MCU exposes a Fingerprint sensor
Fingerprint = 28,
/// The MCU exposes a Touchpad
Touchpad = 29,
/// The MCU has RWSIG task enabled
RwSig = 30,
/// EC has device events support
DeviceEvent = 31,
/// EC supports the unified wake masks for LPC/eSPI systems
UnifiedWakeMasks = 32,
/// EC supports 64-bit host events
HostEvent64 = 33,
/// EC runs code in RAM (not in place, a.k.a. XIP)
ExecInRam = 34,
/// EC supports CEC commands
Cec = 35,
/// EC supports tight sensor timestamping.
MotionSenseTightTimesStamps = 36,
///
/// EC supports tablet mode detection aligned to Chrome and allows
/// setting of threshold by host command using
/// MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE.
RefinedTabletModeHysteresis = 37,
/// Early Firmware Selection ver.2. Enabled by CONFIG_VBOOT_EFS2.
/// Note this is a RO feature. So, a query (EC_CMD_GET_FEATURES) should
/// be sent to RO to be precise.
Efs2 = 38,
/// The MCU is a System Companion Processor (SCP).
Scp = 39,
/// The MCU is an Integrated Sensor Hub
Ish = 40,
/// New TCPMv2 TYPEC_ prefaced commands supported
TypecCmd = 41,
/// The EC will wait for direction from the AP to enter Type-C alternate
/// modes or USB4.
TypecRequireApModeEntry = 42,
/// The EC will wait for an acknowledge from the AP after setting the
/// mux.
TypeCMuxRequireApAck = 43,
/// The EC supports entering and residing in S4.
S4Residency = 44,
/// The EC supports the AP directing mux sets for the board.
TypeCApMuxSet = 45,
/// The EC supports the AP composing VDMs for us to send.
TypeCApVdmSend = 46,
/// The EC supports system safe mode panic recovery.
SystemSafeMode = 47,
/// The EC will reboot on runtime assertion failures.
AssertReboots = 48,
/// The EC image is built with tokenized logging enabled.
TokenizedLogging = 49,
/// The EC supports triggering an STB dump.
AmdStbDump = 50,
/// The EC supports memory dump commands.
MemoryDump = 51,
/// The EC supports DP2.1 capability
Dp21 = 52,
/// The MCU is System Companion Processor Core 1
ScpC1 = 53,
/// The EC supports UCSI PPM.
UcsiPpm = 54,
}

pub struct EcRequestGetFeatures {}

pub struct EcResponseGetFeatures {
pub flags: [u32; 2],
}

impl EcRequest<EcResponseGetFeatures> for EcRequestGetFeatures {
fn command_id() -> EcCommands {
EcCommands::GetFeatures
}
}

#[repr(u8)]
pub enum RebootEcCmd {
/// Cancel a pending reboot
Expand Down Expand Up @@ -272,7 +412,8 @@ pub enum RebootEcFlags {
}

pub struct EcRequestRebootEc {
pub cmd: u8, /* enum RebootEcCmd */
/// See enum RebootEcCmd
pub cmd: u8,
pub flags: u8,
}

Expand Down Expand Up @@ -630,10 +771,8 @@ impl EcRequest<EcResponseChargeLimitControl> for EcRequestChargeLimitControl {
}
}

/*
* Configure the behavior of the charge limit control.
* TODO: Use this
*/
/// Configure the behavior of the charge limit control.
/// TODO: Use this
pub const EC_CHARGE_LIMIT_RESTORE: u8 = 0x7F;

#[repr(u8)]
Expand Down
17 changes: 17 additions & 0 deletions framework_lib/src/chromium_ec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,23 @@ impl CrosEc {
Ok(ascii)
}

/// Check features supported by the firmware
pub fn get_features(&self) -> EcResult<()> {
let data = EcRequestGetFeatures {}.send_command(self)?;
for i in 0..64 {
let byte = i / 32;
let bit = i % 32;
let val = (data.flags[byte] & (1 << bit)) > 0;
let feat: Option<EcFeatureCode> = FromPrimitive::from_usize(i);

if let Some(feat) = feat {
println!("{:>2}: {:>5} {:?}", i, val, feat);
}
}

Ok(())
}

/// Instantly reboot EC and host
pub fn reboot(&self) -> EcResult<()> {
EcRequestReboot {}.send_command(self)
Expand Down
5 changes: 5 additions & 0 deletions framework_lib/src/commandline/clap_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ struct ClapCli {
#[arg(long)]
version: bool,

/// Show features support by the firmware
#[arg(long)]
features: bool,

/// Display the UEFI ESRT table
#[arg(long)]
esrt: bool,
Expand Down Expand Up @@ -212,6 +216,7 @@ pub fn parse(args: &[String]) -> Cli {
verbosity: args.verbosity.log_level_filter(),
versions: args.versions,
version: args.version,
features: args.features,
esrt: args.esrt,
device: args.device,
compare_version: args.compare_version,
Expand Down
4 changes: 4 additions & 0 deletions framework_lib/src/commandline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ pub struct Cli {
pub verbosity: log::LevelFilter,
pub versions: bool,
pub version: bool,
pub features: bool,
pub esrt: bool,
pub device: Option<HardwareDeviceType>,
pub compare_version: Option<String>,
Expand Down Expand Up @@ -679,6 +680,8 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
print_versions(&ec);
} else if args.version {
print_tool_version();
} else if args.features {
ec.get_features().unwrap();
} else if args.esrt {
print_esrt();
} else if let Some(compare_version_ver) = &args.compare_version {
Expand Down Expand Up @@ -963,6 +966,7 @@ Options:
-q, --quiet... Less output per occurrence
--versions List current firmware versions
--version Show tool version information (Add -vv for more detailed information)
--features Show features support by the firmware
--esrt Display the UEFI ESRT table
--device <DEVICE> Device used to compare firmware version [possible values: bios, ec, pd0, pd1, rtm01, rtm23]
--compare-version Version string used to match firmware version (use with --device)
Expand Down
4 changes: 4 additions & 0 deletions framework_lib/src/commandline/uefi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ pub fn parse(args: &[String]) -> Cli {
paginate: false,
versions: false,
version: false,
features: false,
esrt: false,
device: None,
compare_version: None,
Expand Down Expand Up @@ -123,6 +124,9 @@ pub fn parse(args: &[String]) -> Cli {
} else if arg == "--version" {
cli.version = true;
found_an_option = true;
} else if arg == "--features" {
cli.features = true;
found_an_option = true;
} else if arg == "-b" {
cli.paginate = true;
found_an_option = true;
Expand Down