Skip to content

Commit ec20c42

Browse files
committed
AP: property and method for checking if the AP is enabled.
- If the AP is enabled, find_components() will not attempt to read the ROM table.
1 parent 4396fb1 commit ec20c42

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

pyocd/coresight/ap.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,39 @@ def __init__(self, dp, ap_address, idr=None, name="", flags=0, cmpid=None):
528528
def supported_transfer_sizes(self):
529529
"""! @brief Tuple of transfer sizes supported by this AP."""
530530
return self._transfer_sizes
531+
532+
@property
533+
def is_enabled(self):
534+
"""! @brief Whether any memory transfers are allowed by this AP.
535+
536+
Memory transfers may be disabled by an input signal to the AP. This is often done when debug security
537+
is enabled on the device, to disallow debugger access to internal memory.
538+
"""
539+
return self.is_enabled_for(Target.SecurityState.NONSECURE)
540+
541+
def is_enabled_for(self, security_state):
542+
"""! @brief Checks whether memory transfers are allowed by this AP for the given security state.
543+
544+
Memory transfers may be disabled by an input signal to the AP. This is often done when debug security
545+
is enabled on the device, to disallow debugger access to internal memory.
546+
547+
@param self The AP instance.
548+
@param security_state One of the @ref pyocd.core.target.Target.SecurityState "SecurityState" enums.
549+
@return Boolean indicating whether memory transfers can be performed in the requested security state. You
550+
may change the security state used for transfers with the hnonsec property and hnonsec_lock() method.
551+
"""
552+
assert isinstance(security_state, Target.SecurityState)
553+
554+
# Call to superclass to read CSW. We want to bypass our CSW cache since the enable signal can change
555+
# asynchronously.
556+
csw = AccessPort.read_reg(self, self._reg_offset + MEM_AP_CSW)
557+
if security_state is Target.SecurityState.NONSECURE:
558+
# Nonsecure transfers are always allowed when security transfers are enabled.
559+
return (csw & (CSW_DEVICEEN | CSW_SDEVICEEN)) != 0
560+
elif security_state is Target.SecurityState.SECURE:
561+
return (csw & CSW_SDEVICEEN) != 0
562+
else:
563+
assert False, "unsupported security state"
531564

532565
@locked
533566
def init(self):
@@ -694,6 +727,10 @@ def _init_rom_table_base():
694727
def find_components(self):
695728
try:
696729
if self.has_rom_table:
730+
if not self.is_enabled:
731+
LOG.warning("Skipping CoreSight discovery for %s because it is disabled", self.short_description)
732+
return
733+
697734
# Import locally to work around circular import.
698735
from .rom_table import (CoreSightComponentID, ROMTable)
699736

0 commit comments

Comments
 (0)