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, revision=None)#
Bases:
object
Base for CMPA and CFPA classes.
Initialize an instance.
- Parameters:
family (
str
) – Family to use, list of supported families is available via ‘get_supported_families’ methodrevision (
Optional
[str
]) – silicon revision, if not specified, the latest is being useduser_config – User configuration to use with initialization
- Raises:
SPSDKError – When no device is provided
SPSDKError – When no device is not supported
SPSDKError – When there is invalid revision
- BINARY_SIZE = 512#
-
DB_SUB_KEYS:
List
[str
] = []#
- DESCRIPTION = 'Base Config Area'#
- FEATURE_NAME = 'pfr'#
- IMAGE_PREFILL_PATTERN = '0x00'#
- MARK = b'SEAL'#
- ROTKH_REGISTER = 'ROTKH'#
- ROTKH_SIZE = 32#
- export(add_seal=False, keys=None, rotkh=None)#
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.
- 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}.
- generate_config()#
Generate configuration structure for user configuration.
- Return type:
Dict
- Returns:
YAML commented map with PFR configuration in reset state.
- classmethod get_cert_block_class(family)#
Return the seal count.
- Parameters:
family (
str
) – The device name, if not specified, the general value is used.- Return type:
Type
[RKHT
]- Returns:
The seal count.
- Raises:
SPSDKError – When there is invalid seal count
- get_config(diff=False)#
Return configuration from loaded PFR.
- Parameters:
diff (
bool
) – Get only configuration with difference value to reset state.- Return type:
Dict
[str
,Union
[str
,Dict
[str
,Any
]]]- Returns:
PFR configuration in dictionary.
- classmethod get_supported_families()#
Classmethod to get list of supported families.
- Return type:
List
[str
]- Returns:
List of supported families.
- classmethod get_validation_schemas(family, revision='latest')#
Create the validation schema.
- Parameters:
family (
str
) – Family description.revision (
str
) – Chip revision specification, as default, latest is used.
- Raises:
SPSDKError – Family or revision is not supported.
- Return type:
List
[Dict
[str
,Any
]]- Returns:
List of validation schemas.
- classmethod get_validation_schemas_family()#
Create the validation schema just for supported families.
- Return type:
List
[Dict
[str
,Any
]]- Returns:
List of validation schemas for Shadow registers supported families.
- static load_from_config(config)#
Get Configuration class from configuration.
- Parameters:
config (
Dict
[str
,Any
]) – PFR configuration.- Return type:
- Returns:
BaseConfigArea obejct
- parse(data)#
Parse input binary data to registers.
- Parameters:
data (
bytes
) – Input binary data of PFR block.- Return type:
None
- 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.
- reg_computed_fields_handler(val, context)#
Recalculate all fields for given register value.
- Parameters:
val (
bytes
) – Input register value.context (
Any
) – The method context (fields).
- Return type:
bytes
- Returns:
recomputed value.
- Raises:
SPSDKPfrError – Raises when the computing routine is not found.
- set_config(cfg)#
Set a new values configuration.
- Parameters:
cfg (
Dict
[str
,Any
]) – Registers configuration.- Return type:
None
- classmethod validate_config(cfg)#
Validate input PFR configuration.
- Parameters:
cfg (
Dict
[str
,Any
]) – PFR configuration- Return type:
None
- class spsdk.pfr.pfr.CFPA(family, revision=None)#
Bases:
BaseConfigArea
Customer In-Field Configuration Area.
Initialize an instance.
- Parameters:
family (
str
) – Family to use, list of supported families is available via ‘get_supported_families’ methodrevision (
Optional
[str
]) – silicon revision, if not specified, the latest is being useduser_config – User configuration to use with initialization
- Raises:
SPSDKError – When no device is provided
SPSDKError – When no device is not supported
SPSDKError – When there is invalid revision
-
DB_SUB_KEYS:
List
[str
] = ['cfpa']#
- DESCRIPTION = 'Customer In-field Programmable Area'#
- class spsdk.pfr.pfr.CMPA(family, revision=None)#
Bases:
BaseConfigArea
Customer Manufacturing Configuration Area.
Initialize an instance.
- Parameters:
family (
str
) – Family to use, list of supported families is available via ‘get_supported_families’ methodrevision (
Optional
[str
]) – silicon revision, if not specified, the latest is being useduser_config – User configuration to use with initialization
- Raises:
SPSDKError – When no device is provided
SPSDKError – When no device is not supported
SPSDKError – When there is invalid revision
-
DB_SUB_KEYS:
List
[str
] = ['cmpa']#
- DESCRIPTION = 'Customer Manufacturing Programmable Area'#
Protected Flash Region Checker for brick-conditions#
Processor for conditions in rules.
- class spsdk.pfr.processor.Processor(translator)#
Bases:
object
Class 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:
object
Translates 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:
SPSDKPfrError
General PFR configuration error.
Initialize the base SPSDK Exception.
- exception spsdk.pfr.exceptions.SPSDKPfrConfigReadError(desc=None)#
Bases:
SPSDKPfrConfigError
Configuration file decode error.
Initialize the base SPSDK Exception.
- exception spsdk.pfr.exceptions.SPSDKPfrError(desc=None)#
Bases:
SPSDKError
General PFR error.
Initialize the base SPSDK Exception.
- exception spsdk.pfr.exceptions.SPSDKPfrRotkhIsNotPresent(desc=None)#
Bases:
SPSDKPfrError
The configuration area doesn’t provide ROTKH field.
Initialize the base SPSDK Exception.
- exception spsdk.pfr.exceptions.SPSDKPfrcMissingConfigError(desc=None)#
Bases:
SPSDKPfrError
The translation of conditions failed.
Initialize the base SPSDK Exception.