17
17
import logging
18
18
19
19
from ...core import exceptions
20
+ from ...core .target import Target
20
21
from ...coresight .coresight_target import CoreSightTarget
21
22
from ...core .memory_map import (RomRegion , FlashRegion , RamRegion , MemoryMap )
22
23
from ...probe .swj import SWJSequenceSender
30
31
31
32
# Flash algorithm as a hex string
32
33
'instructions' : [
33
- 0xe00abe00 ,
34
- 0xb085b5f0 , 0x447e4e1e , 0x28017830 , 0xf000d101 , 0x2001f839 , 0x70309004 , 0x46384f15 , 0xf00030f7 ,
35
- 0x4604f8a3 , 0x1c804813 , 0xf89ef000 , 0x46384605 , 0xf89af000 , 0x48109003 , 0xf896f000 , 0x480f9002 ,
36
- 0xf892f000 , 0x480b9001 , 0xf88ef000 , 0x47a04607 , 0x607447a8 , 0x980360b5 , 0x980260f0 , 0x98016130 ,
37
- 0x61b76170 , 0x70309804 , 0xb0052000 , 0x46c0bdf0 , 0x00004552 , 0x00005843 , 0x00005052 , 0x00004346 ,
38
- 0x0000027a , 0x4c07b510 , 0x7820447c , 0xd1062801 , 0x47806960 , 0x478069a0 , 0x70202000 , 0x2001bd10 ,
39
- 0x46c0bd10 , 0x000001f8 , 0x44784805 , 0x28007800 , 0x2001d101 , 0x48014770 , 0x46c04770 , 0x000070d0 ,
40
- 0x000001d6 , 0x4601b570 , 0x447a4a0e , 0x28017810 , 0x2301d10e , 0x2400071d , 0x46261b48 , 0x42a94166 ,
41
- 0x68d5d308 , 0x041a0319 , 0x47a823d8 , 0xbd704620 , 0xbd702001 , 0x44784804 , 0x4a042121 , 0xf000447a ,
42
- 0x46c0f855 , 0x000001b6 , 0x00000126 , 0x00000164 , 0xb081b5f0 , 0x4d10460b , 0x7829447d , 0xd10f2901 ,
43
- 0x070e2101 , 0x1b812400 , 0x41674627 , 0xd30b42b0 , 0x4608692d , 0x461a4611 , 0x462047a8 , 0xbdf0b001 ,
44
- 0x46202401 , 0xbdf0b001 , 0x44784804 , 0x4a042121 , 0xf000447a , 0x46c0f82b , 0x00000168 , 0x000000d2 ,
45
- 0x00000120 , 0xd4d4de00 , 0x2114b280 , 0x1e898809 , 0x2a00884a , 0x1d09d004 , 0xd1f94282 , 0x47708808 ,
46
- 0x44784803 , 0x4a03210e , 0xf000447a , 0x46c0f80f , 0x00000076 , 0x000000c8 , 0xd4d44770 , 0x49024801 ,
47
- 0x46c04770 , 0x4d94efcf , 0x7847d224 , 0xaf00b580 , 0x2300b088 , 0x4c079305 , 0x93039404 , 0x23019302 ,
48
- 0xab069301 , 0x91079300 , 0x46689006 , 0xf0004611 , 0xdefef803 , 0x00000244 , 0xaf00b580 , 0x9103b084 ,
49
- 0x48049002 , 0x48049001 , 0x46689000 , 0xffbaf7ff , 0x46c0defe , 0x00000244 , 0x00000244 , 0x636e7546 ,
50
- 0x746f6e20 , 0x756f6620 , 0x7273646e , 0x616d2f63 , 0x722e6e69 , 0xd4d4d473 , 0xd4d4d4d4 , 0xd4d4d4d4 ,
51
- 0x65747461 , 0x2074706d , 0x73206f74 , 0x72746275 , 0x20746361 , 0x68746977 , 0x65766f20 , 0x6f6c6672 ,
52
- 0xd4d4d477 , 0x00000199 , 0x00000000 , 0x00000001 , 0x0000019d , 0x0000020a , 0x0000000b , 0x00000014 ,
53
- 0x00000011 , 0x0000020a , 0x0000000b , 0x00000053 , 0x00000028 , 0x0000020a , 0x0000000b , 0x00000058 ,
54
- 0x0000002a , 0x00000000 , 0x00000000 , 0x00000000 , 0x00000000 , 0x00000000 , 0x00000000 , 0x00000000
34
+ 0xe7fdbe00 ,
35
+ 0xaf03b5f0 , 0x4614b087 , 0x447d4d5a , 0x28007828 , 0x485ed007 , 0x68004478 , 0x485d4780 , 0x68004478 ,
36
+ 0x26014780 , 0x1e60702e , 0xd3002803 , 0x4848e08d , 0xf90ef000 , 0x2800460c , 0x4846d15f , 0xf0001c80 ,
37
+ 0x2800f907 , 0x460cd001 , 0x9406e057 , 0x78102210 , 0x284d4c41 , 0x2311d151 , 0x28757818 , 0x2012d14d ,
38
+ 0x78009002 , 0xd00a2802 , 0xd1462801 , 0x92049303 , 0x20149105 , 0x21188800 , 0x4938880a , 0x9303e008 ,
39
+ 0x91059204 , 0xf8d4f000 , 0x88022016 , 0x21044833 , 0x4c334790 , 0x46222800 , 0x4602d000 , 0x99052800 ,
40
+ 0x9b039804 , 0x7800d029 , 0x284d4c2e , 0x7818d125 , 0xd1222875 , 0x78009802 , 0x91052802 , 0xd0079201 ,
41
+ 0xd11a2801 , 0x88002014 , 0x880a2118 , 0xe0054926 , 0xf8aef000 , 0x88022016 , 0x21044823 , 0x4c234790 ,
42
+ 0x46222800 , 0x4602d000 , 0xd0062800 , 0x48209204 , 0xf8aef000 , 0x2800460c , 0x4620d002 , 0xbdf0b007 ,
43
+ 0xf0004814 , 0x2800f8a5 , 0x9103d19d , 0x28009806 , 0x9806d019 , 0x98054780 , 0x48174780 , 0x99014478 ,
44
+ 0x48166001 , 0x99064478 , 0x48156001 , 0x99044478 , 0x48146001 , 0x60044478 , 0x44784813 , 0x60019903 ,
45
+ 0x2400702e , 0x9c05e7d9 , 0xf000e7d7 , 0x46c0f8ab , 0x00004649 , 0x00005843 , 0x10004552 , 0x00004552 ,
46
+ 0x20004552 , 0x10005052 , 0x00005052 , 0x20005052 , 0x00004346 , 0x0000029e , 0x00000194 , 0x00000188 ,
47
+ 0x00000188 , 0x00000184 , 0x00000182 , 0x000002a4 , 0x000002a0 , 0xaf02b5d0 , 0x447c4c08 , 0x28017820 ,
48
+ 0x4807d10a , 0x68004478 , 0x48064780 , 0x68004478 , 0x20004780 , 0xbdd07020 , 0xbdd02001 , 0x0000010e ,
49
+ 0x00000114 , 0x00000110 , 0xaf02b5d0 , 0x44794909 , 0x29017809 , 0x210fd10c , 0x18400709 , 0x44794906 ,
50
+ 0x2201680c , 0x04120311 , 0x47a023d8 , 0xbdd02000 , 0xbdd02001 , 0x000000da , 0x000000d2 , 0xaf02b5d0 ,
51
+ 0x4909460b , 0x78094479 , 0xd10a2901 , 0x0709210f , 0x49061840 , 0x680c4479 , 0x461a4611 , 0x200047a0 ,
52
+ 0x2001bdd0 , 0x46c0bdd0 , 0x000000a4 , 0x000000a0 , 0xf45f4806 , 0x60014140 , 0xf710ee30 , 0xec40d404 ,
53
+ 0xec400780 , 0xbf400781 , 0x00004770 , 0xe000ed88 , 0xaf02b5d0 , 0x2010b284 , 0x284d7800 , 0x2011d10f ,
54
+ 0x28757800 , 0x2012d10b , 0x28027800 , 0x2801d00b , 0x2014d105 , 0x21188800 , 0x4621880a , 0x2001e009 ,
55
+ 0x18610701 , 0xf7ffbdd0 , 0x2016ffd3 , 0x21048802 , 0x47904620 , 0x42404601 , 0x29004148 , 0x2101d1f2 ,
56
+ 0xe7ee0749 , 0xaf00b580 , 0xdefede00 , 0xd4d4d400 , 0x00000000 , 0x00000000 , 0x00000000 , 0x00000000 ,
57
+ 0x00000000
55
58
],
56
59
57
60
# Relative function addresses
58
61
'pc_init' : 0x20000005 ,
59
- 'pc_unInit' : 0x20000089 ,
60
- 'pc_program_page' : 0x20000115 ,
61
- 'pc_erase_sector' : 0x200000c9 ,
62
- # 'pc_eraseAll': 0x200000ad, # not implemented yet
63
-
64
- 'static_base' : 0x20000000 + 0x00000004 + 0x00000254 ,
65
- 'begin_stack' : 0x20000500 ,
62
+ 'pc_unInit' : 0x20000199 ,
63
+ 'pc_program_page' : 0x20000201 ,
64
+ 'pc_erase_sector' : 0x200001cd ,
65
+ 'pc_eraseAll' : 0x120000003 ,
66
+
67
+ 'static_base' : 0x20000000 + 0x00000004 + 0x000002c4 ,
68
+ 'begin_stack' : 0x200012d0 ,
69
+ 'end_stack' : 0x200002d0 ,
66
70
'begin_data' : 0x20000000 + 0x1000 ,
67
71
'page_size' : 0x0 ,
68
72
'analyzer_supported' : False ,
69
- 'analyzer_address' : 0x00000000 ,
70
- 'page_buffers' : [0x20001000 , 0x20001100 ], # Enable double buffering
73
+ 'page_buffers' : [0x20001400 , 0x20001500 ], # Enable double buffering
71
74
'min_program_length' : 256 ,
72
75
73
76
# Relative region addresses and sizes
74
- 'ro_start' : 0x0 ,
75
- 'ro_size' : 0x254 ,
76
- 'rw_start' : 0x254 ,
77
- 'rw_size' : 0x30 ,
78
- 'zi_start' : 0x284 ,
79
- 'zi_size' : 0x1c ,
77
+ 'ro_start' : 0x4 ,
78
+ 'ro_size' : 0x2c4 ,
79
+ 'rw_start' : 0x2c8 ,
80
+ 'rw_size' : 0x0 ,
81
+ 'zi_start' : 0x2c8 ,
82
+ 'zi_size' : 0x0 ,
80
83
}
81
84
82
85
def _parity32 (value ):
83
86
parity = sum ((value >> i ) for i in range (32 ))
84
87
return parity & 1
85
88
86
- class RP2040Base (CoreSightTarget ):
87
- """@brief Raspberry Pi RP2040.
88
-
89
- This device is very strange in that it as three DPs. The first two DPs each have a single AHB-AP
90
- for the two Cortex-M0+ cores. The third DP is a "Rescue DP" that has no APs, but the CDBGPWRUPREQ
91
- signal is repurposed as a rescue signal.
92
- """
93
-
94
- class Targetsel :
95
- """@brief DP TARGETEL values for each DP."""
96
- CORE_0 = 0x01002927
97
- CORE_1 = 0x11002927
98
- RESCUE_DP = 0xf1002927
99
-
89
+ class RP2Base (CoreSightTarget ):
100
90
VENDOR = "Raspberry Pi"
101
91
102
92
MEMORY_MAP = MemoryMap (
@@ -118,6 +108,75 @@ class Targetsel:
118
108
def __init__ (self , session ):
119
109
super ().__init__ (session , self .MEMORY_MAP )
120
110
111
+
112
+ class RP2350 (RP2Base ):
113
+ """@brief Raspberry Pi RP2350
114
+ """
115
+
116
+ def __init__ (self , session ):
117
+ super ().__init__ (session )
118
+
119
+ def create_init_sequence (self ):
120
+ seq = super ().create_init_sequence ()
121
+
122
+ # Secure mode is only needed for the flash algo.
123
+ seq .insert_before ('post_connect_hook' , ('set_set_secure_mode' , self ._set_secure_mode ))
124
+
125
+ return seq
126
+
127
+ def _set_secure_mode (self ):
128
+ # The RP2350 flash functions in ROM require the core to be in secure mode
129
+ state = self .session .board .target .get_security_state ()
130
+ if state == Target .SecurityState .SECURE :
131
+ LOG .debug ("target in secure mode" )
132
+ return
133
+
134
+ LOG .debug ("target not in secure mode, attempting to switch to secure mode" )
135
+ target = self .session .board .target
136
+
137
+ DCB_DSCSR = 0xE000EE08
138
+ DSCSR_CDSKEY = 1 << 17
139
+ DSCSR_CDS = 1 << 16
140
+ dscsr = target .read32 (DCB_DSCSR )
141
+ target .write32 (DCB_DSCSR , (dscsr & ~ DSCSR_CDSKEY ) | DSCSR_CDS )
142
+
143
+ state = self .session .board .target .get_security_state ()
144
+ if state != Target .SecurityState .SECURE :
145
+ LOG .debug ("target failed to enter secure mode" )
146
+ raise exceptions .TargetError ("Unable to set target to secure mode" )
147
+
148
+ # Attempt to enable secure access to SRAM
149
+ ACCESSCTRL_LOCK = 0x40060000
150
+ ACCESSCTRL_LOCK_DEBUG_BITS = 0x00000008
151
+
152
+ ACCESSCTRL_CFGRESET = 0x40060008
153
+ ACCESSCTRL_WRITE_PASSWORD = 0xacce0000
154
+ lock = target .read32 (ACCESSCTRL_LOCK )
155
+ if lock & ACCESSCTRL_LOCK_DEBUG_BITS :
156
+ # Warn instead of rasing an error in case the permissions are setup
157
+ # correctly.
158
+ log .warn ("ACCESSCTRL is locked. Unable to reset." )
159
+ else :
160
+ target .write32 (ACCESSCTRL_CFGRESET , ACCESSCTRL_WRITE_PASSWORD | 1 )
161
+
162
+
163
+ class RP2040Base (RP2Base ):
164
+ """@brief Raspberry Pi RP2040.
165
+
166
+ This device is very strange in that it as three DPs. The first two DPs each have a single AHB-AP
167
+ for the two Cortex-M0+ cores. The third DP is a "Rescue DP" that has no APs, but the CDBGPWRUPREQ
168
+ signal is repurposed as a rescue signal.
169
+ """
170
+
171
+ class Targetsel :
172
+ """@brief DP TARGETEL values for each DP."""
173
+ CORE_0 = 0x01002927
174
+ CORE_1 = 0x11002927
175
+ RESCUE_DP = 0xf1002927
176
+
177
+ def __init__ (self , session ):
178
+ super ().__init__ (session )
179
+
121
180
## The TARGETSEL value to be used.
122
181
self ._core_targetsel = None
123
182
@@ -210,4 +269,3 @@ class RP2040Core1(RP2040Base):
210
269
def __init__ (self , session ):
211
270
super ().__init__ (session )
212
271
self ._core_targetsel = self .Targetsel .CORE_1
213
-
0 commit comments