cros_ec_python.commands.features

List the features supported by the firmware

  1"""
  2List the features supported by the firmware
  3"""
  4
  5from typing import Final
  6from enum import Enum
  7import struct
  8from ..baseclass import CrosEcClass
  9from ..constants.COMMON import *
 10
 11EC_CMD_GET_FEATURES: Final = 0x000D
 12
 13
 14class EcFeatureCode(Enum):
 15    """Supported Features"""
 16
 17    EC_FEATURE_LIMITED = 0
 18    "This image contains a limited set of features. Another image in RW partition may support more features."
 19
 20    EC_FEATURE_FLASH = 1
 21    "Commands for probing/reading/writing/erasing the flash in the EC are present."
 22
 23    EC_FEATURE_PWM_FAN = 2
 24    "Can control the fan speed directly."
 25
 26    EC_FEATURE_PWM_KEYB = 3
 27    "Can control the intensity of the keyboard backlight."
 28
 29    EC_FEATURE_LIGHTBAR = 4
 30    "Support Google lightbar, introduced on Pixel."
 31
 32    EC_FEATURE_LED = 5
 33    "Control of LEDs"
 34
 35    EC_FEATURE_MOTION_SENSE = 6
 36    """
 37    Exposes an interface to control gyro and sensors.
 38    The host goes through the EC to access these sensors.
 39    In addition, the EC may provide composite sensors, like lid angle.
 40    """
 41
 42    EC_FEATURE_KEYB = 7
 43    "The keyboard is controlled by the EC"
 44
 45    EC_FEATURE_PSTORE = 8
 46    "The AP can use part of the EC flash as persistent storage."
 47
 48    EC_FEATURE_PORT80 = 9
 49    "The EC monitors BIOS port 80h, and can return POST codes."
 50
 51    EC_FEATURE_THERMAL = 10
 52    """
 53    Thermal management: include TMP specific commands.
 54    Higher level than direct fan control.
 55    """
 56
 57    EC_FEATURE_BKLIGHT_SWITCH = 11
 58    "Can switch the screen backlight on/off"
 59
 60    EC_FEATURE_WIFI_SWITCH = 12
 61    "Can switch the wifi module on/off"
 62
 63    EC_FEATURE_HOST_EVENTS = 13
 64    "Monitor host events, through for example SMI or SCI"
 65
 66    EC_FEATURE_GPIO = 14
 67    "The EC exposes GPIO commands to control/monitor connected devices."
 68
 69    EC_FEATURE_I2C = 15
 70    "The EC can send i2c messages to downstream devices."
 71
 72    EC_FEATURE_CHARGER = 16
 73    "Command to control charger are included"
 74
 75    EC_FEATURE_BATTERY = 17
 76    "Simple battery support."
 77
 78    EC_FEATURE_SMART_BATTERY = 18
 79    """
 80    Support Smart battery protocol
 81    (Common Smart Battery System Interface Specification)
 82    """
 83
 84    EC_FEATURE_HANG_DETECT = 19
 85    "EC can detect when the host hangs."
 86
 87    EC_FEATURE_PMU = 20
 88    "Report power information, for pit only"
 89
 90    EC_FEATURE_SUB_MCU = 21
 91    "Another Cros EC device is present downstream of this one"
 92
 93    EC_FEATURE_USB_PD = 22
 94    "Support USB Power delivery (PD) commands"
 95
 96    EC_FEATURE_USB_MUX = 23
 97    "Control USB multiplexer, for audio through USB port for instance."
 98
 99    EC_FEATURE_MOTION_SENSE_FIFO = 24
100    "Motion Sensor code has an internal software FIFO"
101
102    EC_FEATURE_VSTORE = 25
103    "Support temporary secure vstore"
104
105    EC_FEATURE_USBC_SS_MUX_VIRTUAL = 26
106    "EC decides on USB-C SS mux state, muxes configured by host"
107
108    EC_FEATURE_RTC = 27
109    "EC has RTC feature that can be controlled by host commands"
110
111    EC_FEATURE_FINGERPRINT = 28
112    "The MCU exposes a Fingerprint sensor"
113
114    EC_FEATURE_TOUCHPAD = 29
115    "The MCU exposes a Touchpad"
116
117    EC_FEATURE_RWSIG = 30
118    "The MCU has RWSIG task enabled"
119
120    EC_FEATURE_DEVICE_EVENT = 31
121    "EC has device events support"
122
123    EC_FEATURE_UNIFIED_WAKE_MASKS = 32
124    "EC supports the unified wake masks for LPC/eSPI systems"
125
126    EC_FEATURE_HOST_EVENT64 = 33
127    "EC supports 64-bit host events"
128
129    EC_FEATURE_EXEC_IN_RAM = 34
130    "EC runs code in RAM (not in place, a.k.a. XIP)"
131
132    EC_FEATURE_CEC = 35
133    "EC supports CEC commands"
134
135    EC_FEATURE_MOTION_SENSE_TIGHT_TIMESTAMPS = 36
136    "EC supports tight sensor timestamping."
137    #
138
139    EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS = 37
140    """
141    EC supports tablet mode detection aligned to Chrome and allows
142    setting of threshold by host command using
143    MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE.
144    """
145
146    EC_FEATURE_SCP = 39
147    "The MCU is a System Companion Processor (SCP)."
148
149    EC_FEATURE_ISH = 40
150    "The MCU is an Integrated Sensor Hub"
151
152    EC_FEATURE_TYPEC_CMD = 41
153    "New TCPMv2 TYPEC_ prefaced commands supported"
154
155    EC_FEATURE_TYPEC_REQUIRE_AP_MODE_ENTRY = 42
156    "The EC will wait for direction from the AP to enter Type-C alternate modes or USB4."
157
158    EC_FEATURE_TYPEC_MUX_REQUIRE_AP_ACK = 43
159    "The EC will wait for an acknowledge from the AP after setting the mux."
160
161    EC_FEATURE_S4_RESIDENCY = 44
162    "The EC supports entering and residing in S4."
163
164    EC_FEATURE_TYPEC_AP_MUX_SET = 45
165    "The EC supports the AP directing mux sets for the board."
166
167    EC_FEATURE_TYPEC_AP_VDM_SEND = 46
168    "The EC supports the AP composing VDMs for us to send."
169
170
171def get_features(ec: CrosEcClass) -> UInt64:
172    """
173    List the features supported by the firmware
174    :param ec: The CrOS_EC object.
175    :return: The features as a bitmask. Use EcFeatureCode to decode.
176    """
177    resp = ec.command(0, EC_CMD_GET_FEATURES, 0, 8)
178    return struct.unpack("<Q", resp)[0]
179
180
181def decode_features(features: UInt32) -> list[EcFeatureCode]:
182    """
183    Decode the features bitmask into a list of EcFeatureCode enums
184    :param features: The features bitmask.
185    :return: The features as a list of EcFeatureCode enums.
186    """
187    return [feature for feature in EcFeatureCode if features & BIT(feature.value)]
EC_CMD_GET_FEATURES: Final = 13
class EcFeatureCode(enum.Enum):
 15class EcFeatureCode(Enum):
 16    """Supported Features"""
 17
 18    EC_FEATURE_LIMITED = 0
 19    "This image contains a limited set of features. Another image in RW partition may support more features."
 20
 21    EC_FEATURE_FLASH = 1
 22    "Commands for probing/reading/writing/erasing the flash in the EC are present."
 23
 24    EC_FEATURE_PWM_FAN = 2
 25    "Can control the fan speed directly."
 26
 27    EC_FEATURE_PWM_KEYB = 3
 28    "Can control the intensity of the keyboard backlight."
 29
 30    EC_FEATURE_LIGHTBAR = 4
 31    "Support Google lightbar, introduced on Pixel."
 32
 33    EC_FEATURE_LED = 5
 34    "Control of LEDs"
 35
 36    EC_FEATURE_MOTION_SENSE = 6
 37    """
 38    Exposes an interface to control gyro and sensors.
 39    The host goes through the EC to access these sensors.
 40    In addition, the EC may provide composite sensors, like lid angle.
 41    """
 42
 43    EC_FEATURE_KEYB = 7
 44    "The keyboard is controlled by the EC"
 45
 46    EC_FEATURE_PSTORE = 8
 47    "The AP can use part of the EC flash as persistent storage."
 48
 49    EC_FEATURE_PORT80 = 9
 50    "The EC monitors BIOS port 80h, and can return POST codes."
 51
 52    EC_FEATURE_THERMAL = 10
 53    """
 54    Thermal management: include TMP specific commands.
 55    Higher level than direct fan control.
 56    """
 57
 58    EC_FEATURE_BKLIGHT_SWITCH = 11
 59    "Can switch the screen backlight on/off"
 60
 61    EC_FEATURE_WIFI_SWITCH = 12
 62    "Can switch the wifi module on/off"
 63
 64    EC_FEATURE_HOST_EVENTS = 13
 65    "Monitor host events, through for example SMI or SCI"
 66
 67    EC_FEATURE_GPIO = 14
 68    "The EC exposes GPIO commands to control/monitor connected devices."
 69
 70    EC_FEATURE_I2C = 15
 71    "The EC can send i2c messages to downstream devices."
 72
 73    EC_FEATURE_CHARGER = 16
 74    "Command to control charger are included"
 75
 76    EC_FEATURE_BATTERY = 17
 77    "Simple battery support."
 78
 79    EC_FEATURE_SMART_BATTERY = 18
 80    """
 81    Support Smart battery protocol
 82    (Common Smart Battery System Interface Specification)
 83    """
 84
 85    EC_FEATURE_HANG_DETECT = 19
 86    "EC can detect when the host hangs."
 87
 88    EC_FEATURE_PMU = 20
 89    "Report power information, for pit only"
 90
 91    EC_FEATURE_SUB_MCU = 21
 92    "Another Cros EC device is present downstream of this one"
 93
 94    EC_FEATURE_USB_PD = 22
 95    "Support USB Power delivery (PD) commands"
 96
 97    EC_FEATURE_USB_MUX = 23
 98    "Control USB multiplexer, for audio through USB port for instance."
 99
100    EC_FEATURE_MOTION_SENSE_FIFO = 24
101    "Motion Sensor code has an internal software FIFO"
102
103    EC_FEATURE_VSTORE = 25
104    "Support temporary secure vstore"
105
106    EC_FEATURE_USBC_SS_MUX_VIRTUAL = 26
107    "EC decides on USB-C SS mux state, muxes configured by host"
108
109    EC_FEATURE_RTC = 27
110    "EC has RTC feature that can be controlled by host commands"
111
112    EC_FEATURE_FINGERPRINT = 28
113    "The MCU exposes a Fingerprint sensor"
114
115    EC_FEATURE_TOUCHPAD = 29
116    "The MCU exposes a Touchpad"
117
118    EC_FEATURE_RWSIG = 30
119    "The MCU has RWSIG task enabled"
120
121    EC_FEATURE_DEVICE_EVENT = 31
122    "EC has device events support"
123
124    EC_FEATURE_UNIFIED_WAKE_MASKS = 32
125    "EC supports the unified wake masks for LPC/eSPI systems"
126
127    EC_FEATURE_HOST_EVENT64 = 33
128    "EC supports 64-bit host events"
129
130    EC_FEATURE_EXEC_IN_RAM = 34
131    "EC runs code in RAM (not in place, a.k.a. XIP)"
132
133    EC_FEATURE_CEC = 35
134    "EC supports CEC commands"
135
136    EC_FEATURE_MOTION_SENSE_TIGHT_TIMESTAMPS = 36
137    "EC supports tight sensor timestamping."
138    #
139
140    EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS = 37
141    """
142    EC supports tablet mode detection aligned to Chrome and allows
143    setting of threshold by host command using
144    MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE.
145    """
146
147    EC_FEATURE_SCP = 39
148    "The MCU is a System Companion Processor (SCP)."
149
150    EC_FEATURE_ISH = 40
151    "The MCU is an Integrated Sensor Hub"
152
153    EC_FEATURE_TYPEC_CMD = 41
154    "New TCPMv2 TYPEC_ prefaced commands supported"
155
156    EC_FEATURE_TYPEC_REQUIRE_AP_MODE_ENTRY = 42
157    "The EC will wait for direction from the AP to enter Type-C alternate modes or USB4."
158
159    EC_FEATURE_TYPEC_MUX_REQUIRE_AP_ACK = 43
160    "The EC will wait for an acknowledge from the AP after setting the mux."
161
162    EC_FEATURE_S4_RESIDENCY = 44
163    "The EC supports entering and residing in S4."
164
165    EC_FEATURE_TYPEC_AP_MUX_SET = 45
166    "The EC supports the AP directing mux sets for the board."
167
168    EC_FEATURE_TYPEC_AP_VDM_SEND = 46
169    "The EC supports the AP composing VDMs for us to send."

Supported Features

EC_FEATURE_LIMITED = <EcFeatureCode.EC_FEATURE_LIMITED: 0>

This image contains a limited set of features. Another image in RW partition may support more features.

EC_FEATURE_FLASH = <EcFeatureCode.EC_FEATURE_FLASH: 1>

Commands for probing/reading/writing/erasing the flash in the EC are present.

EC_FEATURE_PWM_FAN = <EcFeatureCode.EC_FEATURE_PWM_FAN: 2>

Can control the fan speed directly.

EC_FEATURE_PWM_KEYB = <EcFeatureCode.EC_FEATURE_PWM_KEYB: 3>

Can control the intensity of the keyboard backlight.

EC_FEATURE_LIGHTBAR = <EcFeatureCode.EC_FEATURE_LIGHTBAR: 4>

Support Google lightbar, introduced on Pixel.

EC_FEATURE_LED = <EcFeatureCode.EC_FEATURE_LED: 5>

Control of LEDs

EC_FEATURE_MOTION_SENSE = <EcFeatureCode.EC_FEATURE_MOTION_SENSE: 6>

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.

EC_FEATURE_KEYB = <EcFeatureCode.EC_FEATURE_KEYB: 7>

The keyboard is controlled by the EC

EC_FEATURE_PSTORE = <EcFeatureCode.EC_FEATURE_PSTORE: 8>

The AP can use part of the EC flash as persistent storage.

EC_FEATURE_PORT80 = <EcFeatureCode.EC_FEATURE_PORT80: 9>

The EC monitors BIOS port 80h, and can return POST codes.

EC_FEATURE_THERMAL = <EcFeatureCode.EC_FEATURE_THERMAL: 10>

Thermal management: include TMP specific commands. Higher level than direct fan control.

EC_FEATURE_BKLIGHT_SWITCH = <EcFeatureCode.EC_FEATURE_BKLIGHT_SWITCH: 11>

Can switch the screen backlight on/off

EC_FEATURE_WIFI_SWITCH = <EcFeatureCode.EC_FEATURE_WIFI_SWITCH: 12>

Can switch the wifi module on/off

EC_FEATURE_HOST_EVENTS = <EcFeatureCode.EC_FEATURE_HOST_EVENTS: 13>

Monitor host events, through for example SMI or SCI

EC_FEATURE_GPIO = <EcFeatureCode.EC_FEATURE_GPIO: 14>

The EC exposes GPIO commands to control/monitor connected devices.

EC_FEATURE_I2C = <EcFeatureCode.EC_FEATURE_I2C: 15>

The EC can send i2c messages to downstream devices.

EC_FEATURE_CHARGER = <EcFeatureCode.EC_FEATURE_CHARGER: 16>

Command to control charger are included

EC_FEATURE_BATTERY = <EcFeatureCode.EC_FEATURE_BATTERY: 17>

Simple battery support.

EC_FEATURE_SMART_BATTERY = <EcFeatureCode.EC_FEATURE_SMART_BATTERY: 18>

Support Smart battery protocol (Common Smart Battery System Interface Specification)

EC_FEATURE_HANG_DETECT = <EcFeatureCode.EC_FEATURE_HANG_DETECT: 19>

EC can detect when the host hangs.

EC_FEATURE_PMU = <EcFeatureCode.EC_FEATURE_PMU: 20>

Report power information, for pit only

EC_FEATURE_SUB_MCU = <EcFeatureCode.EC_FEATURE_SUB_MCU: 21>

Another Cros EC device is present downstream of this one

EC_FEATURE_USB_PD = <EcFeatureCode.EC_FEATURE_USB_PD: 22>

Support USB Power delivery (PD) commands

EC_FEATURE_USB_MUX = <EcFeatureCode.EC_FEATURE_USB_MUX: 23>

Control USB multiplexer, for audio through USB port for instance.

EC_FEATURE_MOTION_SENSE_FIFO = <EcFeatureCode.EC_FEATURE_MOTION_SENSE_FIFO: 24>

Motion Sensor code has an internal software FIFO

EC_FEATURE_VSTORE = <EcFeatureCode.EC_FEATURE_VSTORE: 25>

Support temporary secure vstore

EC_FEATURE_USBC_SS_MUX_VIRTUAL = <EcFeatureCode.EC_FEATURE_USBC_SS_MUX_VIRTUAL: 26>

EC decides on USB-C SS mux state, muxes configured by host

EC_FEATURE_RTC = <EcFeatureCode.EC_FEATURE_RTC: 27>

EC has RTC feature that can be controlled by host commands

EC_FEATURE_FINGERPRINT = <EcFeatureCode.EC_FEATURE_FINGERPRINT: 28>

The MCU exposes a Fingerprint sensor

EC_FEATURE_TOUCHPAD = <EcFeatureCode.EC_FEATURE_TOUCHPAD: 29>

The MCU exposes a Touchpad

EC_FEATURE_RWSIG = <EcFeatureCode.EC_FEATURE_RWSIG: 30>

The MCU has RWSIG task enabled

EC_FEATURE_DEVICE_EVENT = <EcFeatureCode.EC_FEATURE_DEVICE_EVENT: 31>

EC has device events support

EC_FEATURE_UNIFIED_WAKE_MASKS = <EcFeatureCode.EC_FEATURE_UNIFIED_WAKE_MASKS: 32>

EC supports the unified wake masks for LPC/eSPI systems

EC_FEATURE_HOST_EVENT64 = <EcFeatureCode.EC_FEATURE_HOST_EVENT64: 33>

EC supports 64-bit host events

EC_FEATURE_EXEC_IN_RAM = <EcFeatureCode.EC_FEATURE_EXEC_IN_RAM: 34>

EC runs code in RAM (not in place, a.k.a. XIP)

EC_FEATURE_CEC = <EcFeatureCode.EC_FEATURE_CEC: 35>

EC supports CEC commands

EC_FEATURE_MOTION_SENSE_TIGHT_TIMESTAMPS = <EcFeatureCode.EC_FEATURE_MOTION_SENSE_TIGHT_TIMESTAMPS: 36>

EC supports tight sensor timestamping.

EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS = <EcFeatureCode.EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS: 37>

EC supports tablet mode detection aligned to Chrome and allows setting of threshold by host command using MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE.

EC_FEATURE_SCP = <EcFeatureCode.EC_FEATURE_SCP: 39>

The MCU is a System Companion Processor (SCP).

EC_FEATURE_ISH = <EcFeatureCode.EC_FEATURE_ISH: 40>

The MCU is an Integrated Sensor Hub

EC_FEATURE_TYPEC_CMD = <EcFeatureCode.EC_FEATURE_TYPEC_CMD: 41>

New TCPMv2 TYPEC_ prefaced commands supported

EC_FEATURE_TYPEC_REQUIRE_AP_MODE_ENTRY = <EcFeatureCode.EC_FEATURE_TYPEC_REQUIRE_AP_MODE_ENTRY: 42>

The EC will wait for direction from the AP to enter Type-C alternate modes or USB4.

EC_FEATURE_TYPEC_MUX_REQUIRE_AP_ACK = <EcFeatureCode.EC_FEATURE_TYPEC_MUX_REQUIRE_AP_ACK: 43>

The EC will wait for an acknowledge from the AP after setting the mux.

EC_FEATURE_S4_RESIDENCY = <EcFeatureCode.EC_FEATURE_S4_RESIDENCY: 44>

The EC supports entering and residing in S4.

EC_FEATURE_TYPEC_AP_MUX_SET = <EcFeatureCode.EC_FEATURE_TYPEC_AP_MUX_SET: 45>

The EC supports the AP directing mux sets for the board.

EC_FEATURE_TYPEC_AP_VDM_SEND = <EcFeatureCode.EC_FEATURE_TYPEC_AP_VDM_SEND: 46>

The EC supports the AP composing VDMs for us to send.

def get_features(ec: cros_ec_python.baseclass.CrosEcClass) -> int:
172def get_features(ec: CrosEcClass) -> UInt64:
173    """
174    List the features supported by the firmware
175    :param ec: The CrOS_EC object.
176    :return: The features as a bitmask. Use EcFeatureCode to decode.
177    """
178    resp = ec.command(0, EC_CMD_GET_FEATURES, 0, 8)
179    return struct.unpack("<Q", resp)[0]

List the features supported by the firmware

Parameters
  • ec: The CrOS_EC object.
Returns

The features as a bitmask. Use EcFeatureCode to decode.

def decode_features(features: int) -> list[EcFeatureCode]:
182def decode_features(features: UInt32) -> list[EcFeatureCode]:
183    """
184    Decode the features bitmask into a list of EcFeatureCode enums
185    :param features: The features bitmask.
186    :return: The features as a list of EcFeatureCode enums.
187    """
188    return [feature for feature in EcFeatureCode if features & BIT(feature.value)]

Decode the features bitmask into a list of EcFeatureCode enums

Parameters
  • features: The features bitmask.
Returns

The features as a list of EcFeatureCode enums.