@@ -485,7 +485,7 @@ def __init__(self, dp, ap_address, idr=None, name="", flags=0, cmpid=None):
485
485
self ._cached_csw = - 1
486
486
487
487
## Supported transfer sizes.
488
- self ._transfer_sizes = (32 )
488
+ self ._transfer_sizes = (32 , )
489
489
490
490
## Auto-increment wrap modulus.
491
491
#
@@ -497,6 +497,9 @@ def __init__(self, dp, ap_address, idr=None, name="", flags=0, cmpid=None):
497
497
## Number of DAR registers.
498
498
self ._dar_count = 0
499
499
500
+ ## Mask of addresses. This indicates whether 32-bit or 64-bit addresses are supported.
501
+ self ._address_mask = 0xffffffff
502
+
500
503
# Ask the probe for an accelerated memory interface for this AP. If it provides one,
501
504
# then bind our memory interface APIs to its methods. Otherwise use our standard
502
505
# memory interface based on AP register accesses.
@@ -525,10 +528,7 @@ def init(self):
525
528
self ._init_transfer_sizes ()
526
529
self ._init_hprot ()
527
530
self ._init_rom_table_base ()
528
-
529
- # For v2 MEM-APs, read the CFG register.
530
- if self .ap_version == APVersion .APv2 :
531
- self ._init_cfg ()
531
+ self ._init_cfg ()
532
532
533
533
def _init_transfer_sizes (self ):
534
534
"""! @brief Determine supported transfer sizes.
@@ -593,44 +593,50 @@ def _init_hprot(self):
593
593
def _init_rom_table_base (self ):
594
594
"""! @brief Read ROM table base address."""
595
595
base = self .read_reg (self ._reg_offset + MEM_AP_BASE )
596
-
597
596
is_adiv5_base = (base & AP_BASE_FORMAT_MASK ) != 0
598
597
is_base_present = (base & AP_BASE_ENTRY_PRESENT_MASK ) != 0
599
- if (base == AP_BASE_LEGACY_NOTPRESENT ) or (is_adiv5_base and not is_base_present ):
598
+ is_legacy_base_present = not is_adiv5_base and not is_base_present
599
+ if is_legacy_base_present :
600
+ self .has_rom_table = True
601
+ self .rom_addr = base & AP_BASE_LEGACY_BASEADDR_MASK # clear format and present bits
602
+ elif (base == AP_BASE_LEGACY_NOTPRESENT ) or (not is_base_present ):
600
603
self .has_rom_table = False
601
604
self .rom_addr = 0
602
605
elif is_adiv5_base and is_base_present :
603
606
self .has_rom_table = True
604
607
self .rom_addr = base & AP_BASE_BASEADDR_MASK # clear format and present bits
605
- elif not is_adiv5_base :
606
- self .has_rom_table = True
607
- self .rom_addr = base & AP_BASE_LEGACY_BASEADDR_MASK # clear format and present bits
608
608
else :
609
- assert False , "Unhandled AP BASE value 0x%08x" % base
609
+ raise exceptions . TargetError ( "invalid AP BASE value 0x%08x" % base )
610
610
611
611
def _init_cfg (self ):
612
- """! @brief Read MEM-APv2 CFG register."""
612
+ """! @brief Read MEM-AP CFG register."""
613
613
cfg = self .read_reg (self ._reg_offset + MEM_AP_CFG )
614
614
615
- # Set autoinc page size if TARINC is non-zero. Otherwise we've already set the
616
- # default of 1 kB in the ctor.
617
- tarinc = (cfg & MEM_AP_CFG_TARINC_MASK ) >> MEM_AP_CFG_TARINC_SHIFT
618
- if tarinc != 0 :
619
- self .auto_increment_page_size = 1 << (9 + tarinc )
615
+ # Check for 64-bit address support.
616
+ if cfg & MEM_AP_CFG_LA_MASK :
617
+ self ._address_mask = 0xffffffffffffffff
618
+
619
+ # Check v2 MEM-AP CFG fields.
620
+ if self .ap_version == APVersion .APv2 :
621
+ # Set autoinc page size if TARINC is non-zero. Otherwise we've already set the
622
+ # default of 1 kB in the ctor.
623
+ tarinc = (cfg & MEM_AP_CFG_TARINC_MASK ) >> MEM_AP_CFG_TARINC_SHIFT
624
+ if tarinc != 0 :
625
+ self .auto_increment_page_size = 1 << (9 + tarinc )
620
626
621
- # Determine supported err mode.
622
- err = (cfg & MEM_AP_CFG_ERR_MASK ) >> MEM_AP_CFG_ERR_SHIFT
623
- if err == MEM_AP_CFG_ERR_V1 :
624
- # Configure the error mode such that errors are passed upstream, but they don't
625
- # prevent future transactions.
626
- self ._csw &= ~ (CSW_ERRSTOP | CSW_ERRNPASS )
627
+ # Determine supported err mode.
628
+ err = (cfg & MEM_AP_CFG_ERR_MASK ) >> MEM_AP_CFG_ERR_SHIFT
629
+ if err == MEM_AP_CFG_ERR_V1 :
630
+ # Configure the error mode such that errors are passed upstream, but they don't
631
+ # prevent future transactions.
632
+ self ._csw &= ~ (CSW_ERRSTOP | CSW_ERRNPASS )
627
633
628
- # Clear TRR in case we attach to a device with a sticky error already set.
629
- self .write_reg (self ._reg_offset + MEM_AP_TRR , MEM_AP_TRR_ERR_MASK )
634
+ # Clear TRR in case we attach to a device with a sticky error already set.
635
+ self .write_reg (self ._reg_offset + MEM_AP_TRR , MEM_AP_TRR_ERR_MASK )
630
636
631
- # Init size of DAR register window.
632
- darsize = (cfg & MEM_AP_CFG_DARSIZE_MASK ) >> MEM_AP_CFG_DARSIZE_SHIFT
633
- self ._dar_count = (1 << darsize ) // 4
637
+ # Init size of DAR register window.
638
+ darsize = (cfg & MEM_AP_CFG_DARSIZE_MASK ) >> MEM_AP_CFG_DARSIZE_SHIFT
639
+ self ._dar_count = (1 << darsize ) // 4
634
640
635
641
@locked
636
642
def find_components (self ):
@@ -758,7 +764,7 @@ def read_reg(self, addr, now=True):
758
764
ap_regaddr = addr & APREG_MASK
759
765
if ap_regaddr == self ._reg_offset + MEM_AP_CSW and self ._cached_csw != - 1 and now :
760
766
return self ._cached_csw
761
- return super ( MEM_AP , self ). read_reg ( addr , now )
767
+ return self . dp . read_ap ( self . address . address + addr , now )
762
768
763
769
@locked
764
770
def write_reg (self , addr , data ):
@@ -775,7 +781,7 @@ def write_reg(self, addr, data):
775
781
self ._cached_csw = data
776
782
777
783
try :
778
- super ( MEM_AP , self ). write_reg ( addr , data )
784
+ self . dp . write_ap ( self . address . address + addr , data )
779
785
except exceptions .ProbeError :
780
786
# Invalidate cached CSW on exception.
781
787
if ap_regaddr == self ._reg_offset + MEM_AP_CSW :
@@ -796,6 +802,7 @@ def _write_memory(self, addr, data, transfer_size=32):
796
802
@exception TransferError Raised if the requested transfer size is not supported by the AP.
797
803
"""
798
804
assert (addr & (transfer_size // 8 - 1 )) == 0
805
+ addr &= self ._address_mask
799
806
if transfer_size not in self ._transfer_sizes :
800
807
raise exceptions .TransferError ("%d-bit transfers are not supported by %s"
801
808
% (transfer_size , self .short_description ))
@@ -831,6 +838,7 @@ def _read_memory(self, addr, transfer_size=32, now=True):
831
838
@exception TransferError Raised if the requested transfer size is not supported by the AP.
832
839
"""
833
840
assert (addr & (transfer_size // 8 - 1 )) == 0
841
+ addr &= self ._address_mask
834
842
if transfer_size not in self ._transfer_sizes :
835
843
raise exceptions .TransferError ("%d-bit transfers are not supported by %s"
836
844
% (transfer_size , self .short_description ))
@@ -878,11 +886,12 @@ def read_mem_cb():
878
886
else :
879
887
return read_mem_cb
880
888
881
- @locked
882
- def _write_block32 (self , addr , data ):
889
+ def _write_block32_page (self , addr , data ):
883
890
"""! @brief Write a single transaction's worth of aligned words.
884
891
885
892
The transaction must not cross the MEM-AP's auto-increment boundary.
893
+
894
+ This method is not locked because it is only called by _write_memory_block32(), which is locked.
886
895
"""
887
896
assert (addr & 0x3 ) == 0
888
897
num = self .dp .next_access_number
@@ -904,11 +913,12 @@ def _write_block32(self, addr, data):
904
913
raise
905
914
TRACE .debug ("_write_block32:%06d }" , num )
906
915
907
- @locked
908
- def _read_block32 (self , addr , size ):
916
+ def _read_block32_page (self , addr , size ):
909
917
"""! @brief Read a single transaction's worth of aligned words.
910
918
911
919
The transaction must not cross the MEM-AP's auto-increment boundary.
920
+
921
+ This method is not locked because it is only called by _read_memory_block32(), which is locked.
912
922
"""
913
923
assert (addr & 0x3 ) == 0
914
924
num = self .dp .next_access_number
@@ -935,12 +945,13 @@ def _read_block32(self, addr, size):
935
945
def _write_memory_block32 (self , addr , data ):
936
946
"""! @brief Write a block of aligned words in memory."""
937
947
assert (addr & 0x3 ) == 0
948
+ addr &= self ._address_mask
938
949
size = len (data )
939
950
while size > 0 :
940
951
n = self .auto_increment_page_size - (addr & (self .auto_increment_page_size - 1 ))
941
952
if size * 4 < n :
942
953
n = (size * 4 ) & 0xfffffffc
943
- self ._write_block32 (addr , data [:n // 4 ])
954
+ self ._write_block32_page (addr , data [:n // 4 ])
944
955
data = data [n // 4 :]
945
956
size -= n // 4
946
957
addr += n
@@ -950,15 +961,16 @@ def _write_memory_block32(self, addr, data):
950
961
def _read_memory_block32 (self , addr , size ):
951
962
"""! @brief Read a block of aligned words in memory.
952
963
953
- @return An array of word values
964
+ @return A list of word values.
954
965
"""
955
966
assert (addr & 0x3 ) == 0
967
+ addr &= self ._address_mask
956
968
resp = []
957
969
while size > 0 :
958
970
n = self .auto_increment_page_size - (addr & (self .auto_increment_page_size - 1 ))
959
971
if size * 4 < n :
960
972
n = (size * 4 ) & 0xfffffffc
961
- resp += self ._read_block32 (addr , n // 4 )
973
+ resp += self ._read_block32_page (addr , n // 4 )
962
974
size -= n // 4
963
975
addr += n
964
976
return resp
@@ -970,54 +982,33 @@ def _handle_error(self, error, num):
970
982
class AHB_AP (MEM_AP ):
971
983
"""! @brief AHB-AP access port subclass.
972
984
973
- This subclass adds checking for the master type bit in the CSW register. Only the M3/M4 AHB-AP
974
- implements it. If supported, the master type is set to debugger .
985
+ This subclass checks for the AP_MSTRTYPE flag, and if set configures that field in the CSW
986
+ register to use debugger transactions. Only the M3 and M4 AHB-AP implements MSTRTYPE .
975
987
976
988
Another AHB-AP specific addition is that an attempt is made to set the TRCENA bit in the DEMCR
977
989
register before reading the ROM table. This is required on some Cortex-M devices, otherwise
978
- certain ROM table entries will read as zeroes.
990
+ certain ROM table entries will read as zeroes or other garbage .
979
991
"""
980
992
981
993
@locked
982
994
def init (self ):
983
995
super (AHB_AP , self ).init ()
984
996
985
997
# Check for and enable the Master Type bit on AHB-APs where it might be implemented.
986
- if (self .ap_version == APVersion .APv1 ) \
987
- or ((self ._cmpid is not None ) and (self ._cmpid .archid == UNKNOWN_AP_ARCHID )):
998
+ if self ._flags & AP_MSTRTYPE :
988
999
self ._init_mstrtype ()
989
1000
990
1001
def _init_mstrtype (self ):
991
- """! @brief Detect and set master type control in CSW.
1002
+ """! @brief Set master type control in CSW.
992
1003
993
1004
Only the v1 AHB-AP from Cortex-M3 and Cortex-M4 implements the MSTRTYPE flag to control
994
1005
whether transactions appear as debugger or internal accesses.
995
1006
"""
996
- # Read initial CSW value to check if the MSTRTYPE bit is implemented. It is most
997
- # likely already set.
998
- original_csw = AccessPort .read_reg (self , self ._reg_offset + MEM_AP_CSW )
999
- impl_master_type = original_csw & CSW_MSTRTYPE
1000
-
1001
- # If MSTRTYPE is not set, attempt to write it.
1002
- if impl_master_type == 0 :
1003
- # Verify no transfer is in progress.
1004
-
1005
- # Set MSTRTYPE and read back to see if it sticks.
1006
- AccessPort .write_reg (self , self ._reg_offset + MEM_AP_CSW , original_csw | CSW_MSTRTYPE )
1007
- csw = AccessPort .read_reg (self , self ._reg_offset + MEM_AP_CSW )
1008
-
1009
- # Restore unmodified value of CSW.
1010
- if csw != original_csw :
1011
- AccessPort .write_reg (self , self ._reg_offset + MEM_AP_CSW , original_csw )
1012
-
1013
- impl_master_type = csw & CSW_MSTRTYPE
1014
-
1015
- # Set the master type to debugger for AP's that support this field.
1016
- if impl_master_type != 0 :
1017
- self ._csw |= CSW_MSTRDBG
1007
+ # Set the master type to "debugger" for AP's that support this field.
1008
+ self ._csw |= CSW_MSTRDBG
1018
1009
1019
1010
def find_components (self ):
1020
- # Turn on DEMCR.TRCENA before reading the ROM table. Some ROM table entries will
1011
+ # Turn on DEMCR.TRCENA before reading the ROM table. Some ROM table entries can
1021
1012
# come back as garbage if TRCENA is not set.
1022
1013
try :
1023
1014
demcr = self .read32 (DEMCR )
@@ -1053,13 +1044,14 @@ def find_components(self):
1053
1044
# AP flags.
1054
1045
AP_4K_WRAP = 0x1 # The AP has a 4 kB auto-increment modulus.
1055
1046
AP_ALL_TX_SZ = 0x2 # The AP is known to support 8-, 16-, and 32-bit transfers.
1047
+ AP_MSTRTYPE = 0x4 # The AP is known to support the MSTRTYPE field.
1056
1048
1057
1049
## Map from AP IDR fields to AccessPort subclass.
1058
1050
#
1059
1051
# The dict maps from a 4-tuple of (JEP106 code, AP class, variant, type) to 2-tuple (name, class, flags).
1060
1052
#
1061
1053
# Known AP IDRs:
1062
- # 0x24770011 AHB-AP with 0x1000 wrap
1054
+ # 0x24770011 AHB-AP with 0x1000 wrap and MSTRTYPE
1063
1055
# Used on m4 & m3 - Documented in arm_cortexm4_processor_trm_100166_0001_00_en.pdf
1064
1056
# and arm_cortexm3_processor_trm_100165_0201_00_en.pdf
1065
1057
# 0x34770001 AHB-AP Documented in DDI0314H_coresight_components_trm.pdf
@@ -1078,7 +1070,7 @@ def find_components(self):
1078
1070
(AP_JEP106_ARM , AP_CLASS_JTAG_AP , 0 , 0 ): ("JTAG-AP" , AccessPort , 0 ),
1079
1071
(AP_JEP106_ARM , AP_CLASS_COM_AP , 0 , 0 ): ("SDC-600" , AccessPort , 0 ),
1080
1072
(AP_JEP106_ARM , AP_CLASS_MEM_AP , 0 , AP_TYPE_AHB ): ("AHB-AP" , AHB_AP , AP_ALL_TX_SZ ),
1081
- (AP_JEP106_ARM , AP_CLASS_MEM_AP , 1 , AP_TYPE_AHB ): ("AHB-AP" , AHB_AP , AP_ALL_TX_SZ | AP_4K_WRAP ),
1073
+ (AP_JEP106_ARM , AP_CLASS_MEM_AP , 1 , AP_TYPE_AHB ): ("AHB-AP" , AHB_AP , AP_ALL_TX_SZ | AP_4K_WRAP | AP_MSTRTYPE ),
1082
1074
(AP_JEP106_ARM , AP_CLASS_MEM_AP , 2 , AP_TYPE_AHB ): ("AHB-AP" , AHB_AP , AP_ALL_TX_SZ ),
1083
1075
(AP_JEP106_ARM , AP_CLASS_MEM_AP , 3 , AP_TYPE_AHB ): ("AHB-AP" , AHB_AP , AP_ALL_TX_SZ ),
1084
1076
(AP_JEP106_ARM , AP_CLASS_MEM_AP , 4 , AP_TYPE_AHB ): ("AHB-AP" , AHB_AP , AP_ALL_TX_SZ ),
0 commit comments