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(device=None, revision=None, user_config=None)
Bases:
object
Base for CMPA and CFPA classes.
Initialize an instance.
- Parameters
device (
Optional
[str
]) – device to use, list of supported devices is available via ‘devices’ methodrevision (
Optional
[str
]) – silicon revision, if not specified, the latest is being useduser_config (
Optional
[PfrConfiguration
]) – PfrConfiguration with 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
- CONFIG_FILE = 'database.json'
- DESCRIPTION = 'Base Config Area'
- IMAGE_PREFILL_PATTERN = 0
- MARK = b'SEAL'
- ROTKH_REGISTER = 'ROTKH'
- ROTKH_SIZE = 32
- classmethod devices()
Classmethod to get list of supported devices.
- Return type
List
[str
]- Returns
List of supported devices.
- export(add_seal=False, keys=None)
Generate binary output.
- Parameters
add_seal (
bool
) – The export is finished in the PFR record by seal.keys (
Optional
[List
[Union
[RSAPublicKey
,EllipticCurvePublicKey
]]]) – List of Keys to compute ROTKH field.
- Return type
bytes
- Returns
Binary block with PFR configuration(CMPA or CFPA).
- Raises
SPSDKPfrRotkhIsNotPresent – This PFR block doesn’t contains ROTKH field.
SPSDKError – The size of data is {len(data)}, is not equal to {self.BINARY_SIZE}.
- generate_config(exclude_computed=True)
Generate configuration structure for user configuration.
- Parameters
exclude_computed (
bool
) – Exclude computed fields, defaults to True.- Return type
CommentedMap
- Returns
YAML commented map with PFR configuration in reset state.
- get_yaml_config(exclude_computed=True, diff=False, indent=0)
Return YAML configuration from loaded registers.
- Parameters
exclude_computed (
bool
) – Omit computed registers and fields.diff (
bool
) – Get only configuration with difference value to reset state.indent (
int
) – YAML start indent.
- Return type
CommentedMap
- Returns
YAML PFR configuration in commented map(ordered dict).
- 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.
- 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(config, raw=False)
Apply configuration from file.
- Parameters
config (
PfrConfiguration
) – PFR configuration.raw (
bool
) – When set all (included computed fields) configuration will be applied.
- Raises
SPSDKError – When device is not provided.
SPSDKError – When revision is not provided.
SPSDKPfrConfigError – Invalid config file.
- Return type
None
- class spsdk.pfr.pfr.CFPA(device=None, revision=None, user_config=None)
Bases:
spsdk.pfr.pfr.BaseConfigArea
Customer In-Field Configuration Area.
Initialize an instance.
- Parameters
device (
Optional
[str
]) – device to use, list of supported devices is available via ‘devices’ methodrevision (
Optional
[str
]) – silicon revision, if not specified, the latest is being useduser_config (
Optional
[PfrConfiguration
]) – PfrConfiguration with 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
- DESCRIPTION = 'Customer In-field Programmable Area'
- class spsdk.pfr.pfr.CMPA(device=None, revision=None, user_config=None)
Bases:
spsdk.pfr.pfr.BaseConfigArea
Customer Manufacturing Configuration Area.
Initialize an instance.
- Parameters
device (
Optional
[str
]) – device to use, list of supported devices is available via ‘devices’ methodrevision (
Optional
[str
]) – silicon revision, if not specified, the latest is being useduser_config (
Optional
[PfrConfiguration
]) – PfrConfiguration with 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
- DESCRIPTION = 'Customer Manufacturing Programable 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
Boolean result and values for translated keys
Translator is responsible for converting stringified keys into values.
- class spsdk.pfr.translator.Translator(cmpa, cfpa)
Bases:
object
Translates single strings (register/key names) into values.
Initialize CMPA and CFPA data.
- Parameters
cmpa (
PfrConfiguration
) – configuration data loaded from CMPA config filecfpa (
PfrConfiguration
) – configuration data loaded from CFPA config file
- 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
PFR Exceptions
Module provides exceptions for PFR module.
- exception spsdk.pfr.exceptions.SPSDKPfrConfigError(desc=None)
Bases:
spsdk.pfr.exceptions.SPSDKPfrError
General PFR configuration error.
Initialize the base SPSDK Exception.
- exception spsdk.pfr.exceptions.SPSDKPfrConfigReadError(desc=None)
Bases:
spsdk.pfr.exceptions.SPSDKPfrConfigError
Configuration file decode error.
Initialize the base SPSDK Exception.
- exception spsdk.pfr.exceptions.SPSDKPfrError(desc=None)
Bases:
spsdk.exceptions.SPSDKError
General PFR error.
Initialize the base SPSDK Exception.
- exception spsdk.pfr.exceptions.SPSDKPfrRotkhIsNotPresent(desc=None)
Bases:
spsdk.pfr.exceptions.SPSDKPfrError
The configuration area doesn’t provide ROTKH field.
Initialize the base SPSDK Exception.