Fuses API

Contents

Fuses API#

SPSDK Fuses support utilities.

This module provides functionality for handling and managing fuses across NXP MCU portfolio within the SPSDK framework.

Fuses#

SPSDK fuse operations and management utilities.

This module provides comprehensive functionality for reading, writing, and managing fuses across NXP MCU devices. It includes abstract base classes for fuse operations, concrete implementations for different tools (blhost, nxpele), and utilities for fuse scripting and configuration management.

class spsdk.fuses.fuses.BlhostFuseOperator(mboot)#

Bases: FuseOperator

SPSDK Blhost fuse operator for MCU fuse operations.

This class provides fuse read/write operations using the Blhost protocol through McuBoot interface. It handles individual fuse programming, reading, and script generation for batch operations.

Variables:

NAME – Operator identifier for blhost protocol.

Initialize the Blhost fuse operator.

Creates a new instance of the fuse operator that uses the provided McuBoot interface for communication with the target device.

Parameters:

mboot (McuBoot) – McuBoot interface instance for device communication.

NAME: str | None = 'blhost'#
classmethod get_fuse_script(family, fuses)#

Generate BLHOST fuses programming script for given family and fuses.

Creates a complete script with header information including SPSDK version and chip family, followed by individual fuse programming commands with descriptive comments.

Parameters:
  • family (FamilyRevision) – Target chip family and revision information.

  • fuses (list[FuseRegister]) – List of fuse registers to be programmed.

Raises:

SPSDKAttributeError – When OTP index is not defined for a fuse register.

Return type:

str

Returns:

Complete BLHOST script as formatted string with programming commands.

classmethod get_fuse_write_cmd(index, value, lock=False, verify=False)#

Get fuse write command for programming eFuses.

Generates a command string for programming eFuse values with optional verification and locking capabilities.

Parameters:
  • index (int) – eFuse index to program.

  • value (int) – Value to write to the eFuse.

  • lock (bool) – Lock the eFuse after programming, defaults to False.

  • verify (bool) – Verify the programmed value, defaults to False.

Return type:

str

Returns:

Formatted eFuse programming command string.

read_fuse(index, length)#

Read a single fuse value from the device.

This method reads the value of a fuse at the specified index using the mboot interface. The length parameter specifies the expected bit length of the fuse data.

Parameters:
  • index (int) – Index of the fuse to read

  • length (int) – Length of fuse data in bits

Raises:
Return type:

int

Returns:

The value read from the specified fuse

write_fuse(index, value, length, lock=False, verify=True)#

Write a single fuse to the device.

The method programs a fuse at the specified index with the given value and optionally locks it to prevent further modifications.

Parameters:
  • index (int) – Index of the fuse to be written.

  • value (int) – Fuse value to be programmed.

  • length (int) – Length of fuse in bits.

  • lock (bool) – Lock fuse after write to prevent further modifications.

  • verify (bool) – Verify the fuse value after writing, defaults to True.

Raises:

SPSDKFuseOperationFailure – Writing of fuse failed.

Return type:

None

class spsdk.fuses.fuses.BlhostFuseOperatorLegacy(mboot)#

Bases: FuseOperator

Legacy Blhost fuse operator for backward compatibility.

This class provides fuse operations using legacy Blhost commands that differ from the standard implementation. It maintains compatibility with older systems while providing the same fuse read/write interface.

Variables:

NAME – Operator identifier for legacy Blhost operations.

Initialize the Blhost fuse operator.

Parameters:

mboot (McuBoot) – McuBoot instance for communication with the target device.

NAME: str | None = 'blhost_legacy'#
classmethod get_fuse_script(family, fuses)#

Generate BLHOST fuses programming script for given family and fuses.

Creates a complete BLHOST script that includes voltage setting, fuse programming commands, and proper reset sequence for safe fuse programming operations.

Parameters:
  • family (FamilyRevision) – Target MCU family and revision information.

  • fuses (list[FuseRegister]) – List of fuse registers to be programmed with their values.

Raises:

SPSDKAttributeError – When OTP index is not defined for a fuse register.

Return type:

str

Returns:

Complete BLHOST script as string with programming commands.

classmethod get_fuse_write_cmd(index, value, lock=False, verify=False)#

Get fuse write command.

Generates a command string for programming a fuse with the specified index and value.

Parameters:
  • index (int) – Fuse index to program.

  • value (int) – Value to write to the fuse.

  • lock (bool) – Whether to lock the fuse after programming (currently not used in command).

  • verify (bool) – Whether to verify the fuse after programming (currently not used in command).

Return type:

str

Returns:

Command string for fuse programming.

read_fuse(index, length)#

Read a single fuse value from the device.

This method reads a fuse at the specified index with the given bit length and returns the fuse value as an integer.

Parameters:
  • index (int) – Index of the fuse to read

  • length (int) – Length of fuse in bits

Return type:

int

Returns:

Fuse value as integer

Raises:
write_fuse(index, value, length, lock=False, verify=True)#

Write a single fuse.

This method programs a fuse at the specified index with the given value by setting the appropriate voltage, programming the fuse, and resetting the voltage.

Parameters:
  • index (int) – Index of the fuse to be written.

  • value (int) – Fuse value to be programmed.

  • length (int) – Length of fuse in bits (currently not used in implementation).

  • lock (bool) – Lock fuse after write (currently not implemented).

  • verify (bool) – Verify the fuse value after writing, defaults to True.

Raises:

SPSDKFuseOperationFailure – When the fuse programming operation fails.

Return type:

None

class spsdk.fuses.fuses.FuseCompareRecord(name, old, new, result, reason, description='')#

Bases: object

Single semantic fuse configuration comparison record.

Variables:
  • name – Canonical register or register.bitfield name.

  • old – Value from the first configuration, or None when absent.

  • new – Value from the second configuration, or None when absent.

  • result – Comparison result.

  • reason – Human-readable explanation of the result.

  • description – Register or bitfield description.

description: str = ''#
get_config()#

Create a dictionary representation suitable for a YAML report.

The old/new values are omitted when the field is absent in that configuration.

Return type:

dict[str, str]

Returns:

Dictionary with old/new/result/reason keys.

get_validation_schema()#

Create a JSON schema describing this comparison record.

Return type:

dict[str, Any]

Returns:

JSON schema dictionary for commented YAML generation.

name: str#
new: str | None#
old: str | None#
reason: str#
result: FuseCompareResult#
class spsdk.fuses.fuses.FuseCompareReport(first_family, second_family, records=<factory>)#

Bases: object

Semantic comparison report for two fuse configurations.

Variables:
  • first_family – Family revision loaded from the first configuration.

  • second_family – Family revision loaded from the second configuration.

  • records – Differing or non-verifiable fields.

first_family: FamilyRevision#
get_config()#

Create a plain dictionary representation of the report.

Return type:

dict[str, Any]

Returns:

Dictionary with status, family revisions, and field results.

get_report_yaml()#

Create a human-readable commented YAML comparison report.

Return type:

str

Returns:

Commented YAML comparison report.

get_validation_schema()#

Create the schema used to render the commented YAML report.

Return type:

list[dict[str, Any]]

Returns:

List containing the report validation schema.

records: list[FuseCompareRecord]#
second_family: FamilyRevision#
property status: FuseCompareStatus#

Get the overall comparison status.

Returns:

DIFFERENT when any field differs, PARTIAL when only non-verifiable fields are present, otherwise IDENTICAL.

class spsdk.fuses.fuses.FuseCompareResult(tag, label, description=None)#

Bases: SpsdkEnum

Per-field fuse configuration comparison result.

DIFFERENT = (0, 'DIFFERENT', 'The field values differ between configurations.')#
NOT_VERIFIABLE = (1, 'NOT_VERIFIABLE', 'The field cannot be reliably compared because it is not readable.')#
class spsdk.fuses.fuses.FuseCompareStatus(tag, label, description=None)#

Bases: SpsdkEnum

Overall fuse configuration comparison status.

DIFFERENT = (1, 'DIFFERENT', 'At least one fuse field differs.')#
IDENTICAL = (0, 'IDENTICAL', 'The fuse configurations are semantically identical.')#
PARTIAL = (2, 'PARTIAL', 'Comparable fields are identical, but at least one field is not verifiable.')#
class spsdk.fuses.fuses.FuseOperator#

Bases: object

Fuse operator abstract base class for device fuse management operations.

This abstract class defines the interface for reading, writing, and managing fuses across different NXP MCU devices. Concrete implementations provide device-specific fuse operation capabilities including script generation and command formatting.

Variables:

NAME – Operator name identifier for registration and lookup.

NAME: str | None = None#
abstract classmethod get_fuse_script(family, fuses)#

Get fuse script for specified family and fuse registers.

Generates a script containing fuse programming commands based on the provided family revision and list of fuse registers.

Parameters:
  • family (FamilyRevision) – Target MCU family and revision information.

  • fuses (list[FuseRegister]) – List of fuse registers to include in the script.

Return type:

str

Returns:

Generated fuse programming script as string.

abstract classmethod get_fuse_write_cmd(index, value, lock=False, verify=False)#

Get write command for a single fuse.

Parameters:
  • index (int) – Index of the fuse to write.

  • value (int) – Value to write to the fuse.

  • lock (bool) – Whether to lock the fuse after writing, defaults to False.

  • verify (bool) – Whether to verify the fuse value after writing, defaults to False.

Return type:

str

Returns:

Command string for writing the specified fuse.

classmethod get_operator_type(name)#

Get operator type by its name.

Searches through all FuseOperator subclasses to find the one matching the specified name.

Parameters:

name (str) – Name of the fuse operator to find.

Raises:

SPSDKKeyError – When no fuse operator with the specified name exists.

Return type:

type[FuseOperator]

Returns:

The FuseOperator subclass type matching the given name.

abstract read_fuse(index, length)#

Read a single fuse value from the device.

Parameters:
  • index (int) – Index of the fuse to read.

  • length (int) – Length of the fuse in bits.

Return type:

int

Returns:

The fuse value as an integer.

abstract write_fuse(index, value, length, lock=False, verify=True)#

Write a single fuse.

The method writes a value to the specified fuse index with given bit length and optionally locks the fuse to prevent further modifications.

Parameters:
  • index (int) – Index of the fuse to write.

  • value (int) – Fuse value to be written.

  • length (int) – Length of fuse in bits.

  • lock (bool) – Lock fuse after write to prevent further modifications.

  • verify (bool) – Verify the fuse value after writing, defaults to True.

Return type:

None

class spsdk.fuses.fuses.FuseScript(family, feature, index=None, fuses_key='fuses')#

Bases: object

SPSDK Fuse Script Generator.

This class generates programming scripts for writing fuses to NXP MCU devices. It manages fuse configuration data, validates settings against device databases, and produces executable scripts compatible with various programming tools like blhost.

Initialize FuseScript object.

Creates a new FuseScript instance for managing fuse operations on a specific device family and feature configuration.

Parameters:
  • family (FamilyRevision) – Device family and revision information.

  • feature (str) – Feature name to configure fuses for.

  • index (Optional[int]) – Optional index to append to fuses key for multiple configurations.

  • fuses_key (str) – Base key name for fuses configuration in database.

Raises:

SPSDKError – When the specified family has no fuses definition.

generate_file_header()#

Generate file header for fuses programming script.

Creates a formatted header containing operator name, fuse name, SPSDK version, and target family information for use in generated programming scripts.

Return type:

str

Returns:

Formatted header string with script metadata.

generate_script(attributes_object, info_only=False)#

Generate script for writing fuses.

This method generates a script for writing fuses based on the provided attributes object. The script includes the file header and the commands for setting the fuse values. Special attributes: - __str_value: Value with double underscore represents attribute of the object.

Parameters:
  • attributes_object (object) – An object containing the attributes used to set the fuse values.

  • info_only (bool) – If True, only the information about the fuses is generated, defaults to False.

Raises:

SPSDKError – OTP index is not defined for register.

Return type:

str

Returns:

The generated script for writing fuses or info string if info_only is True.

static get_object_value(value, attributes_object)#

Get object value from attributes object by attribute name.

Retrieves the value of an attribute from the given object. The method handles attribute names that start with double underscores by removing the prefix before attempting to access the attribute.

Parameters:
  • value (str) – Name of the attribute to retrieve, may start with “__” prefix.

  • attributes_object (object) – Object from which to retrieve the attribute value.

Raises:

SPSDKValueError – When the object does not contain the specified attribute.

Return type:

Any

Returns:

Value of the requested attribute from the object.

write_script(filename, output_dir, attributes_object, overwrite=True)#

Write script to file.

Generates a script using the provided attributes object and writes it to a file with the operator name appended to the filename.

Parameters:
  • filename (str) – Base name for the output script file (without extension).

  • output_dir (str) – Directory where the script file will be written.

  • attributes_object (Any) – Object containing attributes used for script generation.

  • overwrite (bool) – Whether to overwrite existing file if it exists.

Return type:

str

Returns:

The absolute path to the generated script file.

class spsdk.fuses.fuses.FuseVerifyRecord(name, expected, actual, result, reason=None, description='', mask=None)#

Bases: object

Single fuse verification record.

Represents the comparison outcome for one fuse register/field between the expected configuration value and the actual value read from the device.

Variables:
  • name – Name of the verified fuse register.

  • expected – Expected value of the fuse as hexadecimal string.

  • actual – Actual value read from the device as hexadecimal string, or None if the fuse could not be read.

  • result – Verification result for this fuse.

  • reason – Human-readable reason, set for MISMATCH and NOT_VERIFIABLE results.

  • description – Description of the fuse register, used to generate the commented YAML report.

  • mask – Mask of compared bits as hexadecimal string, or None when the whole register value is compared.

actual: str | None#
description: str = ''#
expected: str#
get_config()#

Create a plain dictionary representation suitable for a YAML report.

Optional values (actual, mask, reason) are omitted when they are not available.

Return type:

dict[str, Any]

Returns:

Dictionary with expected/actual/mask/result/reason keys.

get_validation_schema()#

Create a JSON schema describing this fuse record for YAML comment generation.

Return type:

dict[str, Any]

Returns:

JSON schema dictionary with a title/description taken from the fuse register and leaf schemas for each report field.

mask: str | None = None#
name: str#
reason: str | None = None#
result: FuseVerifyResult#
class spsdk.fuses.fuses.FuseVerifyReport(family, records=<factory>)#

Bases: object

Complete fuse verification report.

Aggregates individual fuse verification records and derives the overall verification status for the whole configuration.

Variables:
  • family – Family revision the verification was performed for.

  • records – List of individual per-fuse verification records.

family: FamilyRevision#
get_config()#

Create a plain dictionary representation of the report.

Return type:

dict[str, Any]

Returns:

Dictionary with status, family, revision, and per-fuse results.

get_report_yaml()#

Create a human-readable commented YAML report of the verification results.

Return type:

str

Returns:

YAML string with a header comment, overall status, family/revision, and per-fuse verification results, each annotated with the real fuse description as a YAML comment.

get_validation_schema()#

Create the JSON validation schema used to render the commented YAML report.

The schema is built dynamically from the actual verification records, so each fuse entry carries its real register description as a YAML comment, following the same pattern as Registers.get_validation_schema().

Return type:

list[dict[str, Any]]

Returns:

List with a single top-level validation schema dictionary.

records: list[FuseVerifyRecord]#
property status: FuseVerifyStatus#

Get the overall verification status derived from individual records.

Returns:

PASS if all records matched, FAIL if any mismatch occurred, PARTIAL if there was no mismatch but at least one record is not verifiable.

class spsdk.fuses.fuses.FuseVerifyResult(tag, label, description=None)#

Bases: SpsdkEnum

Per-fuse verification result enumeration.

This enumeration represents the outcome of comparing an expected fuse value (loaded from a configuration file) against the actual value read from the device during a verification operation.

MATCH = (0, 'MATCH', 'The actual fuse value matches the expected value.')#
MISMATCH = (1, 'MISMATCH', 'The actual fuse value does not match the expected value.')#
NOT_VERIFIABLE = (2, 'NOT_VERIFIABLE', 'The fuse value could not be read back from the device for comparison.')#
class spsdk.fuses.fuses.FuseVerifyStatus(tag, label, description=None)#

Bases: SpsdkEnum

Overall fuse verification status enumeration.

This enumeration represents the aggregated result of a complete fuse verification run across all fields defined in the expected configuration.

FAIL = (1, 'FAIL', 'At least one fuse value does not match the expected configuration.')#
PARTIAL = (2, 'PARTIAL', 'All readable fuses match, but at least one fuse could not be verified.')#
PASS = (0, 'PASS', 'All verifiable fuses match the expected configuration.')#
class spsdk.fuses.fuses.Fuses(family, fuse_operator=None, cache=True)#

Bases: FeatureBaseClassComm

SPSDK Fuses Manager.

This class provides a comprehensive interface for managing and manipulating fuse operations across NXP MCU families. It handles fuse register initialization, configuration loading, and communication with physical fuse hardware through configurable operators.

Variables:

FEATURE – Database feature identifier for fuses functionality.

Initialize Fuses class to control fuse operations.

The Fuses class provides functionality to manage and manipulate fuse registers for NXP MCU devices, including reading, writing, and configuring fuse values.

Parameters:
  • family (FamilyRevision) – Target MCU family and revision information for fuse operations.

  • fuse_operator (Optional[FuseOperator]) – Optional operator for performing actual fuse operations, defaults to None.

  • cache (bool) – Enable caching of lock fuse values to prevent multiple reads, defaults to True.

Raises:

SPSDKError – When the specified family has no fuses definition available.

FEATURE: str = 'fuses'#
add_to_cache(reg)#

Add a lock fuse register to the cache.

Only lock fuses are cached to optimize lock checking operations.

Parameters:

reg (FuseRegister) – Fuse register to add to cache.

Return type:

None

clear_cache()#

Clear the lock fuse read cache.

Removes all cached lock fuse values, forcing subsequent reads to fetch fresh data from the device.

Return type:

None

classmethod compare_configs(first, second)#

Compare two fuse configurations using register and bitfield semantics.

Values are normalized through the device database, so ordering, comments, numeric formatting, and enum formatting do not affect the result. Fields whose static access rights (from the device database) do not allow reading are classified as NOT_VERIFIABLE; read locks derived from configured lock fuse values are not taken into account.

Both configurations must target the same device family, but they may target different revisions. In that case each configuration is interpreted using the register definitions of its own revision and fields are matched by name.

Parameters:
  • first (Config) – First (old) fuse configuration.

  • second (Config) – Second (new) fuse configuration.

Raises:

SPSDKValueError – When configurations target different device families.

Return type:

FuseCompareReport

Returns:

Semantic field-level comparison report.

create_fuse_script(reg_list=None, loaded_only=False, non_default_only=False)#

Generate fuse programming script for blhost or nxpele tools.

This method processes all fuse registers in the context, handling both simple registers and group registers with sub-registers. For group registers, it processes sub-registers in the appropriate order based on the reverse_subregs_order flag.

Parameters:
  • reg_list (Optional[list[str]]) – Limit to list of registers.

  • loaded_only (bool) – Limit to registers loaded from config.

  • non_default_only (bool) – Limit to registers with non-default value.

Return type:

str

Returns:

Content of the fuse programming script file as a string.

property fuse_operator: FuseOperator#

Get fuse operator instance.

Property to access the fuse operator for performing fuse operations on the device.

Raises:

SPSDKError – Fuse operator is not defined.

Returns:

The fuse operator instance.

property fuse_operator_type: type[FuseOperator]#

Get fuse operator type for the current family.

Returns the appropriate FuseOperator class type that corresponds to the device family configured for this instance.

Returns:

FuseOperator class type for the configured family.

get_config(data_path='./', diff=False)#

Create fuse configuration object.

Generates a configuration object containing family information, revision details, and register settings that can be used for fuse programming or analysis.

Parameters:
  • data_path (str) – Path to store the data files of configuration.

  • diff (bool) – If set, only changed registers will be placed in configuration.

Return type:

Config

Returns:

Configuration object with family, revision and register data.

classmethod get_fuse_operator_type(family)#

Get operator type based on family.

Retrieves the appropriate FuseOperator type for the specified MCU family by querying the database configuration.

Parameters:

family (FamilyRevision) – MCU family and revision specification.

Return type:

type[FuseOperator]

Returns:

FuseOperator class type for the specified family.

Raises:

SPSDKError – If family is not supported or database query fails.

classmethod get_init_regs(family)#

Get initialized fuse registers.

Creates and returns a new FuseRegisters instance for the specified family revision.

Parameters:

family (FamilyRevision) – The family revision to initialize the fuse registers for.

Return type:

FuseRegisters

Returns:

Initialized fuse registers instance for the given family.

classmethod get_validation_schemas(family)#

Create the validation schema for fuses configuration.

The method builds validation schemas by combining basic family schemas with fuse-specific configuration schemas. It updates the family properties and integrates register validation schemas from initialization registers.

Parameters:

family (FamilyRevision) – Family description containing MCU family and revision information.

Return type:

list[dict[str, Any]]

Returns:

List of validation schemas for fuses configuration.

is_cached(reg)#

Check if a lock fuse register value is cached.

Only lock fuses are cached to prevent multiple reads during lock checks.

Parameters:

reg (FuseRegister) – Fuse register to check.

Return type:

bool

Returns:

True if the register is a lock fuse and its value is cached, False otherwise.

classmethod load_from_config(config, fuse_operator=None)#

Create fuses object from given configuration.

This class method instantiates a new fuses object using the provided configuration data, including family revision information and fuse-specific settings.

Parameters:
  • config (Config) – The configuration object containing fuses settings and family revision data.

  • fuse_operator (Optional[FuseOperator]) – Optional operator for performing actual fuse operations, defaults to None.

Return type:

Self

Returns:

New fuses object configured according to the provided configuration.

read_all(check_locks=True, force=False, progress_callback=None)#

Read all fuses from connected device.

Attempts to read every fuse register from the connected device. Failed reads are logged as warnings but do not stop the operation.

Raises:
  • SPSDKFuseOperationFailure – When individual fuse read operations fail (logged as warnings, does not interrupt the overall operation).

  • SPSDKError – When individual fuse read fails. It causes the exception after all registers are read

Return type:

None

read_single(name, check_locks=True, force=False)#

Read single fuse from device.

Reads the value of a specified fuse register from the device, with optional lock checking to ensure the fuse is readable before attempting the operation. Lock fuses are cached to avoid redundant reads during lock checking operations.

Parameters:
  • name (str) – Fuse name or uid to read from device.

  • check_locks (bool) – Check value of lock fuse before reading to prevent locked fuse access.

  • force (bool) – Force read even when the fuse is marked as non-readable

Raises:
Return type:

int

Returns:

Value read from the fuse register.

set_value(name, value, raw=False)#

Set the value of a fuse register without writing to device.

This method updates the local value of a fuse register identified by name, UID, or OTP index. The value is stored locally and can be written to the device later using write methods.

Parameters:
  • name (str) – Fuse register name, UID, or OTP index to set.

  • value (bytes | bytearray | int | str) – The value to set for the fuse register.

  • raw (bool) – If True, set raw value without applying modification hooks; if False, apply computed value with modification hooks, defaults to False.

Return type:

None

verify_loaded(force=False)#

Verify loaded (expected) fuse values against the actual device state.

For each fuse register that was loaded from the expected configuration (including derived antipole registers), the method reads back the current value from the device and compares it with the expected (configured) value. When a register is defined by individual bitfields, only those bitfields are compared, so bits not mentioned in the configuration do not cause a false MISMATCH. Fuses that cannot be read from the device (e.g. due to read-protection or write-only access rights) are reported as NOT_VERIFIABLE instead of causing the whole operation to fail.

Parameters:

force (bool) – Force reading of the fuse even when access rights or reserved flag would normally prevent it.

Return type:

FuseVerifyReport

Returns:

Verification report containing the per-fuse results and the overall verification status.

write_all(verify=True)#

Write all fuse registers to the device.

This method writes all fuse registers in the collection to the device. It processes registers in a specific order, writing non-lock fuses first to prevent lock fuses from blocking subsequent write operations.

Parameters:

verify (bool) – Verify write operation after writing each register, defaults to True.

Raises:
Return type:

None

write_loaded(verify=True)#

Update shadow registers in target using their local values.

This method iterates through all loaded registers and writes their current local values to the target device using the set_register method.

Parameters:

verify (bool) – Verify write operation after setting each register.

Raises:

SPSDKError – If register write operation fails.

Return type:

None

write_multiple(names, verify=True)#

Write multiple fuses to the device.

This method iterates through the provided list of fuse names or UIDs, finds the corresponding registers, and writes each one individually to the device.

Parameters:
  • names (list[str]) – List of fuse names or UIDs to be written to the device.

  • verify (bool) – Verify the fuse value after writing, defaults to True.

Raises:

SPSDKError – If any fuse name/UID is not found or write operation fails.

Return type:

None

write_single(name, lock=False, verify=True)#

Write single fuse to the device.

The method handles both individual fuses and group registers. It performs lock checks, validates write permissions, and manages individual write lock behavior according to fuse configuration. After writing a lock fuse, its cache entry is cleared to ensure fresh reads.

Parameters:
  • name (str) – Fuse name or uid to write.

  • lock (bool) – Set lock after write operation.

  • verify (bool) – Verify the fuse value after writing, defaults to True.

Raises:
Return type:

None

class spsdk.fuses.fuses.NxpeleFuseOperator(ele_handler)#

Bases: FuseOperator

NXP EdgeLock Enclave (ELE) fuse operator.

This class provides fuse operations for NXP EdgeLock Enclave devices, enabling reading and writing of fuse values through ELE message communication. It handles the low-level ELE protocol for secure fuse management operations.

Variables:

NAME – Operator identifier for NXP ELE fuse operations.

Initialize NXP ELE fuse operator.

Creates a new instance of the ELE fuse operator with the provided ELE message handler for secure fuse operations.

Parameters:

ele_handler (Any) – ELE message handler instance for communication with ELE.

Raises:

AssertionError – If ele_handler is not an instance of EleMessageHandler.

NAME: str | None = 'nxpele'#
classmethod get_fuse_script(family, fuses)#

Generate fuse programming script for specified family and fuse registers.

Creates a complete NXPELE fuses programming script with header information and individual fuse write commands for each provided fuse register.

Parameters:
  • family (FamilyRevision) – Target chip family and revision information.

  • fuses (list[FuseRegister]) – List of fuse registers to include in the programming script.

Raises:

SPSDKAttributeError – When OTP index is not defined for any fuse register.

Return type:

str

Returns:

Complete fuse programming script as formatted string.

classmethod get_fuse_write_cmd(index, value, lock=False, verify=False)#

Get write command for a single fuse.

Generates a command string for writing a value to a specific fuse index with optional locking. The verify parameter is not applicable for nxpele command.

Parameters:
  • index (int) – Index of the fuse to write to.

  • value (int) – Value to write to the fuse.

  • lock (bool) – Whether to lock the fuse after writing, defaults to False.

  • verify (bool) – Verification flag (not applicable for nxpele command), defaults to False.

Return type:

str

Returns:

Command string for writing the fuse.

read_fuse(index, length)#

Read a single fuse value from the device.

This method uses ELE (EdgeLock Enclave) messaging to read a common fuse value from the specified index position.

Parameters:
  • index (int) – Index of the fuse to read

  • length (int) – Length of fuse in bits (currently not used in implementation)

Raises:
Return type:

int

Returns:

The fuse value as an integer

write_fuse(index, value, length, lock=False, verify=True)#

Write a single fuse.

This method writes a value to a specific fuse register using the ELE (EdgeLock Enclave) messaging system. The fuse can optionally be locked after writing to prevent further modifications.

Parameters:
  • index (int) – Index of the fuse register to write to.

  • value (int) – Fuse value to be written to the register.

  • length (int) – Length of fuse in bits (currently unused, fixed at 32 bits).

  • lock (bool) – Lock fuse after write to prevent further modifications.

  • verify (bool) – Verify the fuse value after writing, defaults to True.

Return type:

None

exception spsdk.fuses.fuses.SPSDKFuseConfigurationError(desc=None)#

Bases: SPSDKError

SPSDK Fuse configuration error exception.

This exception is raised when fuse configuration operations fail due to invalid parameters, unsupported configurations, or other fuse-related errors.

Initialize the base SPSDK Exception.

Parameters:

desc (Optional[str]) – Optional description of the exception.

exception spsdk.fuses.fuses.SPSDKFuseOperationFailure(desc=None)#

Bases: SPSDKError

SPSDK Fuse operation failure exception.

Exception raised when fuse-related operations fail during device provisioning or configuration processes. This includes failures in fuse reading, writing, verification, or other fuse management operations.

Initialize the base SPSDK Exception.

Parameters:

desc (Optional[str]) – Optional description of the exception.

exception spsdk.fuses.fuses.SPSDKRegsInvalidAttribute(desc=None)#

Bases: SPSDKRegsError

Invalid attribute error for register operations.

Exception raised when attempting to access or use an invalid or undefined attribute on a register object, such as missing shadow register addresses, undefined OTP indices, or other required register properties.

Initialize the base SPSDK Exception.

Parameters:

desc (Optional[str]) – Optional description of the exception.

class spsdk.fuses.fuses.ShadowregsOperator(family, probe=None)#

Bases: FuseOperator

Shadow registers fuse operator for direct memory-mapped register access.

This class provides fuse operations through shadow registers, which are memory-mapped representations of OTP fuses. It enables reading and writing fuse values via debug probe access to shadow register addresses, supporting devices that expose fuses through memory-mapped registers rather than dedicated fuse programming commands.

The operator handles debug interface enablement, scratch register updates for some devices, and verification of written values with configurable verification masks.

Variables:

NAME – Operator identifier for shadow registers operations.

Initialize shadow registers operator.

Creates a new instance of the shadow registers operator for the specified family. If a debug probe is provided, it attempts to enable debug access on the device.

Parameters:
  • family (FamilyRevision) – Target MCU family and revision information.

  • probe (Optional[DebugProbe]) – Optional debug probe for device communication. If provided, debug interface will be enabled automatically.

Raises:

SPSDKError – When debug interface cannot be enabled with provided probe.

NAME: str | None = 'shadowregs'#
enable_debug()#

Enable debug access ports on devices with debug mailbox.

The method checks if AHB access is available and if not, attempts to unlock the device using debug mailbox system. It handles probe reconnection and validates the unlock operation.

Return type:

bool

Returns:

True if debug port is enabled, False otherwise.

Raises:

SPSDKError – Invalid input parameters or unlock method failed.

classmethod get_fuse_script(family, fuses)#

Get fuse script for programming Fuses.

Return type:

str

classmethod get_fuse_write_cmd(index, value, lock=False, verify=False)#

Get fuse write command for shadow registers.

Generates a BLHOST-compatible command string for programming shadow registers through efuse-program-once command with optional verification.

Parameters:
  • index (int) – OTP index of the fuse to write.

  • value (int) – Value to write to the fuse.

  • lock (bool) – Lock the fuse after writing (appends ‘lock’ to command).

  • verify (bool) – Verify the fuse value after writing.

Return type:

str

Returns:

Formatted fuse programming command string.

property probe: DebugProbe#

Get debug probe instance.

Property to access the debug probe for performing shadow register operations.

Raises:

SPSDKDebugProbeError – When debug probe is not defined.

Returns:

The debug probe instance.

read_fuse(index, length)#

Read a single fuse value from shadow register.

This method reads the fuse value from the memory-mapped shadow register address corresponding to the specified OTP index.

Parameters:
  • index (int) – OTP index of the fuse to read.

  • length (int) – Length of fuse in bits (not used for shadow registers).

Return type:

int

Returns:

The fuse value read from the shadow register.

Raises:

SPSDKRegsInvalidAttribute – When register has no shadow register address.

write_fuse(index, value, length, lock=False, verify=True)#

Write a single fuse value to shadow register.

This method writes a value to the memory-mapped shadow register address corresponding to the specified OTP index. It handles write address offsets, scratch register updates, and optional verification.

Parameters:
  • index (int) – OTP index of the fuse to write.

  • value (int) – Fuse value to be written.

  • length (int) – Length of fuse in bits (not used for shadow registers).

  • lock (bool) – Lock fuse after write (not supported for shadow registers).

  • verify (bool) – Verify the write operation after writing.

Raises:
Return type:

None

spsdk.fuses.fuses.mboot_operation_decorator(func)#

Decorator to handle MCUboot operations with automatic connection management.

This decorator ensures that the MCUboot interface is properly opened before executing the decorated method and closed afterwards, regardless of whether the operation succeeds or fails.

Parameters:

func (Callable) – Function to be decorated that performs MCUboot operations.

Return type:

Callable

Returns:

Wrapped function with automatic connection management.

spsdk.fuses.fuses.raise_mboot_read_failure(mboot, index)#

Raise the proper exception for a failed mboot fuse read.

A missing response from the device is a communication problem, while any other status code means the device refused the read (e.g. read-protected fuse).

Parameters:
  • mboot (McuBoot) – McuBoot instance used for the failed read.

  • index (int) – Index of the fuse that failed to be read.

Raises:
Return type:

NoReturn