Protected Flash Region API#
Support for Protected Flash Region areas (CMPA, CFPA).
Protected Flash Region#
Module provides support for Protected Flash Region areas (CMPA, CFPA).
- class spsdk.pfr.pfr.BaseConfigArea(family)#
Bases:
FeatureBaseClassBase for CMPA and CFPA classes.
Initialize an instance.
- Parameters:
family (
FamilyRevision) – Family to use, list of supported families is available via ‘get_supported_families’ method- Raises:
SPSDKError – When no device is provided
SPSDKError – When no device is not supported
- BINARY_SIZE = 512#
- DESCRIPTION = 'Base Config Area'#
-
FEATURE:
str= 'pfr'#
- IMAGE_PREFILL_PATTERN = '0x00'#
- MARK = b'SEAL'#
- ROTKH_REGISTER = 'ROTKH'#
- ROTKH_SIZE = 32#
-
SUB_FEATURE:
Optional[str] = 'SubClassDefineIt'#
- compute_register(reg, method)#
Recalculate register value.
- Parameters:
reg (
Register) – Register to be recalculated.method (
str) – Method name to be use to recalculation of register value.
- Raises:
SPSDKPfrError – Raises when the computing routine is not found.
- Return type:
None
- export(add_seal=False, keys=None, rotkh=None, draw=True)#
Generate binary output.
- Parameters:
add_seal (
bool) – The export is finished in the PFR record by seal.keys (
Optional[list[PublicKey]]) – List of Keys to compute ROTKH field.rotkh (
Optional[bytes]) – ROTKH binary value.draw (
bool) – Draw the configuration data in log
- Return type:
bytes- Returns:
Binary block with PFR configuration(CMPA or CFPA).
- Raises:
SPSDKPfrRotkhIsNotPresent – This PFR block doesn’t contain ROTKH field.
SPSDKError – The size of data is {len(data)}, is not equal to {self.BINARY_SIZE}.
- get_config(data_path='./', diff=False)#
Return configuration from loaded PFR.
- Parameters:
data_path (
str) – Data path is not used in PFRdiff (
bool) – Get only configuration with difference value to reset state.
- Return type:
Config- Returns:
PFR configuration in dictionary.
- classmethod get_supported_families(include_predecessors=False)#
Get supported families for the feature.
- Return type:
list[FamilyRevision]
- classmethod get_validation_schemas(family)#
Create the validation schema.
- Parameters:
family (
FamilyRevision) – Family description.- Raises:
SPSDKError – Family or revision is not supported.
- Return type:
list[dict[str,Any]]- Returns:
List of validation schemas.
- classmethod get_validation_schemas_basic()#
Create the validation schema just for supported families.
- Return type:
list[dict[str,Any]]- Returns:
List of validation schemas for Shadow registers supported families.
- classmethod get_validation_schemas_from_cfg(config)#
Get validation schema based on configuration.
If the class doesn’t behave generally, just override this implementation.
- Parameters:
config (
Config) – Valid configuration- Return type:
list[dict[str,Any]]- Returns:
Validation schemas
- classmethod load_from_config(config)#
Get Configuration class from configuration.
- Parameters:
config (
Config) – PFR configuration.- Return type:
Self- Returns:
BaseConfigArea object
- classmethod parse(data, family=None)#
Parse input binary data to registers.
- Parameters:
data (
bytes) – Input binary data of PFR block.family (
Optional[FamilyRevision]) – The MCU family name.
- Return type:
Self- Returns:
The PFR initialized class.
- static pfr_reg_inverse_high_half(val)#
Function that inverse low 16-bits of register value to high 16 bits.
- Parameters:
val (
int) – Input current reg value.- Return type:
int- Returns:
Returns the complete register value with updated higher half field.
- static pfr_reg_inverse_lower_8_bits(val)#
Function that inverse lower 8-bits of register value to 8-16 bits.
- Parameters:
val (
int) – Input current reg value.- Return type:
int- Returns:
Returns the complete register value with updated 8-16 bit field.
- set_config(cfg)#
Set a new values configuration.
- Parameters:
cfg (
Config) – Registers configuration.- Return type:
None
- class spsdk.pfr.pfr.CFPA(family)#
Bases:
BaseConfigAreaCustomer In-Field Configuration Area.
Initialize an instance.
- Parameters:
family (
FamilyRevision) – Family to use, list of supported families is available via ‘get_supported_families’ method- Raises:
SPSDKError – When no device is provided
SPSDKError – When no device is not supported
- DESCRIPTION = 'Customer In-field Programmable Area'#
-
SUB_FEATURE:
Optional[str] = 'cfpa'#
- class spsdk.pfr.pfr.CMPA(family)#
Bases:
BaseConfigAreaCustomer Manufacturing Configuration Area.
Initialize an instance.
- Parameters:
family (
FamilyRevision) – Family to use, list of supported families is available via ‘get_supported_families’ method- Raises:
SPSDKError – When no device is provided
SPSDKError – When no device is not supported
- DESCRIPTION = 'Customer Manufacturing Programmable Area'#
-
SUB_FEATURE:
Optional[str] = 'cmpa'#
Protected Flash Region Checker for brick-conditions#
Processor for conditions in rules.
- class spsdk.pfr.processor.Processor(translator)#
Bases:
objectClass responsible for processing conditions.
- Processor is responsible for processing condition
parsing the condition string (lookup)
calling translator for individual keys (registers)
Translator is responsible for looking up values for given keys
Initialize processor.
- Parameters:
translator (
Translator) – Translator instance
- process(condition)#
Process individual condition from rules.
- Parameters:
condition (
str) – condition to quantify- Return type:
tuple[bool,str]- Returns:
Tuple with boolean result and string with translated keys
Translator is responsible for converting stringified keys into values.
- class spsdk.pfr.translator.Translator(cmpa=None, cfpa=None)#
Bases:
objectTranslates single strings (register/key names) into values.
Initialize CMPA and CFPA data.
- Parameters:
- translate(key)#
Lookup register’s (or generic key’s) value.
- Parameters:
key (
str) – Register’s (key’s) stringified name- Return type:
int- Returns:
Register’s (key’s) value
- Raises:
SPSDKPfrcTranslationError – Raises when the configuration for given key is not defined
PFR Exceptions#
Module provides exceptions for PFR module.
- exception spsdk.pfr.exceptions.SPSDKPfrConfigError(desc=None)#
Bases:
SPSDKPfrErrorGeneral PFR configuration error.
Initialize the base SPSDK Exception.
- exception spsdk.pfr.exceptions.SPSDKPfrConfigReadError(desc=None)#
Bases:
SPSDKPfrConfigErrorConfiguration file decode error.
Initialize the base SPSDK Exception.
- exception spsdk.pfr.exceptions.SPSDKPfrError(desc=None)#
Bases:
SPSDKErrorGeneral PFR error.
Initialize the base SPSDK Exception.
- exception spsdk.pfr.exceptions.SPSDKPfrRotkhIsNotPresent(desc=None)#
Bases:
SPSDKPfrErrorThe configuration area doesn’t provide ROTKH field.
Initialize the base SPSDK Exception.
- exception spsdk.pfr.exceptions.SPSDKPfrcMissingConfigError(desc=None)#
Bases:
SPSDKPfrErrorThe translation of conditions failed.
Initialize the base SPSDK Exception.