SDP Module API

Module implementing the SDP communication protocol.

SDP Communication protocol

Module implementing the SDP communication protocol.

class spsdk.sdp.sdp.SDP(device, cmd_exception=False)

Bases: object

Serial Downloader Protocol.

Initialize the SDP object.

Parameters
  • device (Interface) – Interface to a device

  • cmd_exception (bool) – True if commands should raise in exception, defaults to False

close()

Disconnect i.MX device.

Return type

None

property cmd_status

Get the response value from the command.

Return type

int

property hab_status

Get the response value from hab.

Return type

int

property is_opened

Indicates whether the underlying interface is open.

Return type

bool

Returns

True if device is open, False if it’s closed

jump_and_run(address)

Jump to specified address and run code from there.

Parameters

address (int) – Destination address

Return type

bool

Returns

Return True if success else False.

open()

Connect to i.MX device.

Return type

None

read(address, length, data_format=32)

Read value from reg/mem at specified address.

Parameters
  • address (int) – Start address of first register

  • length (int) – Count of bytes

  • data_format (int) – Register access format 8, 16, 32 bits

Return type

Optional[bytes]

Returns

Return bytes if success else None.

read_safe(address, length=None, data_format=32, align_count=False)

Read value from reg/mem at specified address.

This method is safe, because is validating input arguments and prevents fault execution.

Parameters
  • address (int) – Start address of first register

  • length (Optional[int]) – Count of bytes

  • data_format (int) – Register access format 8, 16, 32 bits

  • align_count (bool) – Align the count to data_format , default False

Return type

Optional[bytes]

Returns

Return bytes if success else None.

Raises

SdpError – If the address is not properly aligned

read_status()

Read Error Status.

Return type

Optional[int]

Returns

Return status value if success else None

skip_dcd()

Skip DCD blob from loaded file.

Return type

bool

Returns

Return True if success else False.

Raises

SdpCommandError – If command failed and the ‘cmd_exception’ is set to True

property status_code

Get status code from SDP.

Return type

StatusCode

write(address, value, count=4, data_format=32)

Write value into reg/mem at specified address.

Parameters
  • address (int) – Start address of first register

  • value (int) – Register value

  • count (int) – Count of bytes (max 4)

  • data_format (int) – Register access format 8, 16, 32 bits

Return type

bool

Returns

Return True if success else False.

Raises

SdpCommandError – If command failed and the ‘cmd_exception’ is set to True

write_csf(address, data)

Write CSF Data at specified address.

Parameters
  • address (int) – Start Address

  • data (bytes) – The CSF data in binary format

Return type

bool

Returns

Return True if success else False.

write_dcd(address, data)

Write DCD values at specified address.

Parameters
  • address (int) – Start Address

  • data (bytes) – The DCD data in binary format

Return type

bool

Returns

Return True if success else False.

write_file(address, data)

Write File/Data at specified address.

Parameters
  • address (int) – Start Address

  • data (bytes) – The boot image data in binary format

Return type

bool

Returns

Return True if success else False.

write_safe(address, value, count=4, data_format=32)

Write value into reg/mem at specified address.

This method is safe, because is validating input arguments and prevents fault execution.

Parameters
  • address (int) – Start address of first register

  • value (int) – Register value

  • count (int) – Count of bytes (max 4)

  • data_format (int) – Register access format 8, 16, 32 bits

Return type

bool

Returns

Return True if success else False.

Raises

SdpError – If the address is not properly aligned or invalid data_format

SDP Commands

Commands and responses used by SDP module.

class spsdk.sdp.commands.CmdPacket(tag, address, pformat, count, value=0)

Bases: object

Class representing a command packet to be sent to device.

Initialize the struct.

Parameters
  • tag (CommandTag) – Tag number representing the command

  • address (int) – Address used by the command

  • pformat (int) – Format of the data: 8 = byte, 16 = half-word, 32 = word

  • count (int) – Count used by individual command

  • value (int, optional) – Value to use in a particular command, defaults to 0

EMPTY_VALUE = 0
FORMAT = '>HIB2IB'
info()

String representation of the command packet.

Return type

str

to_bytes()

Return command packet as bytes.

Return type

bytes

class spsdk.sdp.commands.CmdResponse(hab, raw_data)

Bases: object

Response on the previously issued command.

Initialize the response object.

Parameters
  • hab (bool) – HAB status response

  • raw_data (bytes) – Data sent by the device

info()

Return stringified information about the command response.

Return type

str

property value

Return a integer representation of the response.

Return type

int

class spsdk.sdp.commands.CommandTag

Bases: spsdk.utils.easy_enum.Enum

SDP Commands.

ERROR_STATUS = 1285
JUMP_ADDRESS = 2827
PING = 23206
READ_REGISTER = 257
SET_BAUDRATE = 3341
SKIP_DCD_HEADER = 3084
WRITE_CSF = 1542
WRITE_DCD = 2570
WRITE_FILE = 1028
WRITE_REGISTER = 514
class spsdk.sdp.commands.ResponseValue

Bases: spsdk.utils.easy_enum.Enum

SDP Response Values.

HAB_SUCCESS = 4042322160
LOCKED = 305411090
SKIP_DCD_HEADER_OK = 2416824329
UNLOCKED = 1450735702
WRITE_DATA_OK = 311069202
WRITE_FILE_OK = 2290649224

SDPS communication protocol

Module implementing the SDPS communication protocol.

class spsdk.sdp.sdps.SDPS(device, device_name)

Bases: object

Secure Serial Downloader Protocol.

Initialize SDPS object.

Parameters
  • device (Interface) – USB device

  • device_name (str) – target platform name used to determine ROM settings

close()

Disconnect i.MX device.

Return type

None

property is_opened

Indicates whether the underlying interface is open.

Return type

bool

Returns

True if device is open, False if it’s closed

property name

Get name.

Return type

str

open()

Connect to i.MX device.

Return type

None

static swap32(x)

Swap 32 bit integer.

Parameters

x (int) – integer to be swapped

Return type

int

Returns

swapped value

write_file(data)

Write data to the target.

Parameters

data (bytes) – The boot image data in binary format

Raises

SdpConnectionError – Timeout or Connection error

Return type

None

SDP Error/Status codes

Error codes defined by the SDP protocol.

class spsdk.sdp.error_codes.HabErrorContext

Bases: spsdk.utils.easy_enum.Enum

HAB Error Context.

AUTH_DATA_BLOCK = 219
HAB_CTX_ANY = 0
HAB_FAB_TEST = 255
HAB_RVT_ENTRY = 225
RVT_ASSERT = 160
RVT_AUTHENTICATE_IMG = 10
RVT_CHECK_TARGET = 51
RVT_CSF_DCD_CMD = 192
RVT_EXIT = 238
RVT_RUN_CSF = 207
RVT_RUN_DCD = 221
class spsdk.sdp.error_codes.HabErrorReason

Bases: spsdk.utils.easy_enum.Enum

HAB Error Reason.

CALL_OUT_OF_SEQUENCE = 40
ENGINE_FAILURE = 48
EXHAUSTED_STORAGE_REGION = 45
EXPIRED_POLL_COUNT = 43
FAILED_CALLBACK = 30
INVALID_ADDRESS = 34
INVALID_ASSERTION = 12
INVALID_BLOB = 49
INVALID_CERTIFICATE = 33
INVALID_COMMAND = 6
INVALID_CSF = 17
INVALID_DATA_SIZE = 23
INVALID_DCD = 39
INVALID_INDEX = 15
INVALID_IVT = 5
INVALID_KEY = 29
INVALID_MAC = 50
INVALID_SIGNATURE = 24
MEMORY_FAILURE = 46
UNKNOWN = 0
UNSUITABLE_STATE = 9
UNSUPPORTED_ALGORITHM = 18
UNSUPPORTED_COMMAND = 3
UNSUPPORTED_CONF_ITEM = 36
UNSUPPORTED_ENGINE = 10
UNSUPPORTED_KEY_OR_PARAM = 27
UNSUPPORTED_PROTOCOL = 20
class spsdk.sdp.error_codes.HabStatusInfo

Bases: spsdk.utils.easy_enum.Enum

HAB status codes.

ERROR = 51
SUCCESS = 240
UNKNOWN = 0
WARNING = 105
class spsdk.sdp.error_codes.StatusCode

Bases: spsdk.utils.easy_enum.Enum

SDP status codes.

CMD_FAILURE = 1
HAB_IS_LOCKED = 2
READ_DATA_FAILURE = 10
SKIP_DCD_HEADER_FAILURE = 15
SUCCESS = 0
WRITE_CSF_FAILURE = 14
WRITE_DCD_FAILURE = 13
WRITE_IMAGE_FAILURE = 12
WRITE_REGISTER_FAILURE = 11

SDP Exceptions

Exceptions used in the SDP module.

exception spsdk.sdp.exceptions.SdpCommandError(cmd, value)

Bases: spsdk.sdp.exceptions.SdpError

SDP Module: Command Exception.

Initialize the Exception object.

Parameters
  • cmd (str) – Name of the command causing the exception

  • value (int) – Response value causing the exception

fmt = 'SDP: {cmd_name} interrupted -> {description}'
exception spsdk.sdp.exceptions.SdpConnectionError(desc=None)

Bases: spsdk.sdp.exceptions.SdpError

SDP Module: Connection Exception.

Initialize the base SPSDK Exception.

fmt = 'SDP: Connection issue -> {description}'
exception spsdk.sdp.exceptions.SdpError(desc=None)

Bases: spsdk.exceptions.SPSDKError

SDP Module: Base Exception.

Initialize the base SPSDK Exception.

fmt = 'SDP: {description}'