示例#1
0
    def get_connected_probes(cls,
                             hardware_id: str = None,
                             user_params: Dict = None) -> list:
        """Get all connected probes over Virtual.

        This functions returns the list of all connected probes in system by Virtual package.
        :param hardware_id: None to list all probes, otherwise the the only probe with matching
            hardware id is listed.
        :param user_params: The user params dictionary
        :return: probe_description
        :raises SPSDKDebugProbeError: In case of invoked test Exception.
        """
        # pylint: disable=import-outside-toplevel
        from spsdk.debuggers.utils import DebugProbes, ProbeDescription

        probes = DebugProbes()

        if user_params is not None and "exc" in user_params.keys():
            raise SPSDKDebugProbeError(
                "Forced exception from discovery function.")

        # Find this 'probe' just in case of direct request (user must know the hardware id :-) )
        if hardware_id == DebugProbeVirtual.UNIQUE_SERIAL:
            probes.append(
                ProbeDescription(
                    "Virtual",
                    DebugProbeVirtual.UNIQUE_SERIAL,
                    "Special virtual debug probe used for product testing",
                    DebugProbeVirtual,
                ))
        return probes
示例#2
0
    def __init__(self, hardware_id: str, user_params: Dict = None) -> None:
        """The Virtual class initialization.

        The Virtual initialization function for SPSDK library to support various DEBUG PROBES.
        """
        super().__init__(hardware_id, user_params)

        set_logger(logging.root.level)

        self.opened = False
        self.enabled_memory_interface = False
        self.virtual_memory: Dict[Any, Any] = {}
        self.virtual_memory_substituted: Dict[Any, Any] = {}
        self.coresight_ap: Dict[Any, Any] = {}
        self.coresight_ap_substituted: Dict[Any, Any] = {}
        self.coresight_dp: Dict[Any, Any] = {}
        self.coresight_dp_write_exception = False
        self.coresight_dp_substituted: Dict[Any, Any] = {}

        if user_params is not None:
            if "exc" in user_params.keys():
                raise SPSDKDebugProbeError(
                    "Forced exception from constructor.")
            if "subs_ap" in user_params.keys():
                self.set_coresight_ap_substitute_data(
                    self._load_subs_from_param(user_params["subs_ap"]))
            if "subs_dp" in user_params.keys():
                self.set_coresight_dp_substitute_data(
                    self._load_subs_from_param(user_params["subs_dp"]))
            if "subs_mem" in user_params.keys():
                self.set_virtual_memory_substitute_data(
                    self._load_subs_from_param(user_params["subs_mem"]))

        logger.debug(f"The SPSDK Virtual Interface has been initialized")
示例#3
0
    def _load_subs_from_param(self, arg: str) -> Dict:
        """Get the substituted values from input arguments.

        :param arg: Input string arguments with substitute values.
        :return: List of values for the substituted values.
        :raises SPSDKDebugProbeError: The input string is not able do parse.
        """
        try:
            subs_data_raw = json.loads(arg)
            subs_data = {}
            for key in subs_data_raw.keys():
                subs_data[int(key)] = subs_data_raw[key]
            return subs_data
        except (TypeError, JSONDecodeError) as exc:
            raise SPSDKDebugProbeError(
                f"Cannot parse substituted values: ({str(exc)})")
示例#4
0
    def set_register(self, reg_name: str, data: Any) -> None:
        """The function sets the value of the specified register.

        param reg: The register name.
        param data: The new data to be stored to shadow register.
        raises SPSDKDebugProbeError: The debug probe is not specified.
        """
        if self.probe is None:
            raise SPSDKDebugProbeError("There is no debug probe.")

        try:
            reg = self.regs.find_reg(reg_name)
            value = value_to_bytes(data)

            start_address = self.offset + reg.offset
            width = reg.width

            if width < len(value) * 8:
                raise SPSDKError(
                    "Invalid length of data for shadow register write.")

            width = max(width, 32)

            data_aligned = bytearray(math.ceil(width / 8))
            data_aligned[len(data_aligned) -
                         len(value):len(data_aligned)] = value

            end_address = start_address + math.ceil(width / 8)
            addresses = range(start_address, end_address, 4)

            for i, addr in enumerate(addresses):
                val = data_aligned[i * 4:i * 4 + 4]
                self._write_shadow_reg(
                    addr,
                    int.from_bytes(
                        change_endianism(val) if reg.reverse else val, "big"),
                )

            reg.set_value(value, raw=True)

        except SPSDKError as exc:
            raise SPSDKError(
                f"The get shadow register failed({str(exc)}).") from exc
示例#5
0
    def _get_requested_value(self, values: Dict, subs_values: Dict,
                             addr: Any) -> int:
        """Method to return back the requested value.

        :param values: The dictionary with already loaded values.
        :param subs_values: The dictionary with substituted values.
        :param addr: Address of value.
        :return: Value by address.
        :raises SPSDKDebugProbeError: General virtual probe error.
        """
        if subs_values and addr in subs_values.keys():
            if len(subs_values[addr]) > 0:
                svalue = subs_values[addr].pop()
                if isinstance(svalue, int):
                    return svalue
                if isinstance(svalue, str) and svalue == "Exception":
                    raise SPSDKDebugProbeError(
                        "Simulated Debug probe exception")

        return int(values[addr]) if addr in values.keys() else 0
示例#6
0
    def get_register(self, reg_name: str) -> bytes:
        """The function returns value of the requested register.

        param reg: The register name.
        return: The value of requested register in bytes
        raises SPSDKDebugProbeError: The debug probe is not specified.
        """
        if self.probe is None:
            raise SPSDKDebugProbeError("There is no debug probe.")

        array = bytearray()
        try:
            reg = self.regs.find_reg(reg_name)

            start_address = self.offset + reg.offset
            width = reg.width

            if width < 32:
                width = 32

            if width == 32:
                array.extend(
                    self.probe.mem_reg_read(start_address).to_bytes(4, "big"))
            else:
                end_address = start_address + math.ceil(width / 8)
                addresses = range(start_address, end_address, 4)

                for addr in addresses:
                    array.extend(
                        self.probe.mem_reg_read(addr).to_bytes(4, "big"))

            result = reverse_bytes_in_longs(
                bytes(array)) if reg.reverse else bytes(array)

        except SPSDKError as exc:
            raise SPSDKError(f"The get shadow register failed({str(exc)}).")

        return result