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 devicecmd_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 registerlength (
int
) – Count of bytesdata_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 registerlength (
Optional
[int
]) – Count of bytesdata_format (
int
) – Register access format 8, 16, 32 bitsalign_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
-
write
(address, value, count=4, data_format=32)¶ Write value into reg/mem at specified address.
- Parameters
address (
int
) – Start address of first registervalue (
int
) – Register valuecount (
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 Addressdata (
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 Addressdata (
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 Addressdata (
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 registervalue (
int
) – Register valuecount (
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 commandaddress (
int
) – Address used by the commandpformat (
int
) – Format of the data: 8 = byte, 16 = half-word, 32 = wordcount (
int
) – Count used by individual commandvalue (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 responseraw_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
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 devicedevice_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¶
-
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 exceptionvalue (
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}'¶
-