Example #1
0
def test_sdp_hab_locked():
    """Test send data returns TRUE if HAB locked"""
    sdp = SDP(
        VirtualDevice(respond_sequence=[
            CmdResponse(True, pack('>I', ResponseValue.LOCKED)),
            CmdResponse(True, pack('>I', ResponseValue.HAB_SUCCESS))
        ]))
    assert sdp.is_opened
    assert sdp._send_data(CmdPacket(0, 0, 0, 0), b'')
    assert sdp.status_code == StatusCode.HAB_IS_LOCKED
    assert sdp.response_value == ResponseValue.LOCKED
Example #2
0
def test_sdp_read_hab_locked():
    """Test `read` returns None if HAB locked"""
    sdp = SDP(
        VirtualDevice(respond_sequence=[
            CmdResponse(True, pack('>I', ResponseValue.LOCKED)),
            CmdResponse(False, b"0000"),
            CmdResponse(True, pack('>I', ResponseValue.HAB_SUCCESS))
        ]))
    assert sdp.is_opened
    assert sdp.read(0x20000000, 4)
    assert sdp.status_code == StatusCode.HAB_IS_LOCKED
    assert sdp.response_value == ResponseValue.LOCKED
Example #3
0
    def read(self, length: int = None) -> CmdResponse:
        """Read data from device.

        :return: data read from device
        """
        hab_info = self._read(length or 4)
        # raw_data = self._read(4) if self.expect_status else hab_info
        # return CmdResponse(hab_info, raw_data)
        return CmdResponse(self.expect_status, hab_info)
Example #4
0
    def read(self) -> CmdResponse:
        """Read data from device.

        :return: data read from device
        :rtype: spsdk.sdp.commands.CmdResponse
        """
        hab_info = self._read(4)
        # raw_data = self._read(4) if self.expect_status else hab_info
        # return CmdResponse(hab_info, raw_data)
        return CmdResponse(True, hab_info)
Example #5
0
def test_sdp_jump_and_run_hab_locked():
    """Test `jump_and_run` returns False if HAB locked (even the operation works)"""
    sdp = SDP(
        VirtualDevice(respond_sequence=[
            CmdResponse(True, pack('>I', ResponseValue.LOCKED))
        ]))
    assert sdp.is_opened
    assert sdp.jump_and_run(0x20000000)
    assert sdp.status_code == StatusCode.HAB_IS_LOCKED
    assert sdp.response_value == ResponseValue.LOCKED
Example #6
0
    def read(self, timeout: int = 1000) -> CmdResponse:
        """Read data from device.

        :param timeout: read timeout in milliseconds, defaults to 1000
        :type timeout: int, optional
        :return: data read from device
        :rtype: spsdk.sdp.commands.CmdResponse
        """
        hab_info = self._read(4)
        # raw_data = self._read(4) if self.expect_status else hab_info
        # return CmdResponse(hab_info, raw_data)
        return CmdResponse(True, hab_info)
Example #7
0
def test_sdp_send_data_errors():
    error_response = [
        CmdResponse(True, pack('>I', ResponseValue.UNLOCKED)),
        CmdResponse(True, pack('>I', 0x12345678))
    ]

    sdp = SDP(VirtualDevice(respond_sequence=error_response.copy()))

    sdp._device.respond_sequence = error_response.copy()
    assert not sdp._send_data(CmdPacket(CommandTag.WRITE_DCD, 0, 0, 0), b'')
    assert sdp.status_code == StatusCode.WRITE_DCD_FAILURE

    sdp._device.respond_sequence = error_response.copy()
    assert not sdp._send_data(CmdPacket(CommandTag.WRITE_CSF, 0, 0, 0), b'')
    assert sdp.status_code == StatusCode.WRITE_CSF_FAILURE

    sdp._device.respond_sequence = error_response.copy()
    assert not sdp._send_data(CmdPacket(CommandTag.WRITE_FILE, 0, 0, 0), b'')
    assert sdp.status_code == StatusCode.WRITE_IMAGE_FAILURE

    sdp._device.respond_sequence = error_response.copy()
    assert not sdp._send_data(CmdPacket(CommandTag.WRITE_DCD, 0, 0, 0), b'')
    assert sdp.status_code == StatusCode.WRITE_DCD_FAILURE
Example #8
0
 def read(self, timeout=1000):
     return CmdResponse(True, pack('>I', ResponseValue.LOCKED))