/
Setup.gdb
192 lines (159 loc) · 4.65 KB
/
Setup.gdb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# v7.1
####################################################################
######################## debug config. #############################
####################################################################
# Set debug phase:
# 1: Attach at TF-A BL2
# 2: Attach at TF-A BL32 or OP-TEE
# 3: Attach at SSBL (U-Boot)
# 4: Attach at Linux kernel
set $debug_phase = 3
# Set debug mode:
# 0: Attach at boot
# 1: Attach running target
set $debug_mode = 0
# Set debug trusted bootchain:
# 0: TF-A BL2 / TF-A BL32 / U-Boot / Linux kernel
# 1: TF-A BL2 / OP-TEE / U-Boot / Linux kernel
set $debug_trusted_bootchain = 1
####################################################################
# Force reset mode in case where debug_phase is 1(TF-A BL2) or 2(TF-A BL32 or OP-TEE)
if $debug_phase <= 2
set $debug_mode = 0
end
# Set environment configuration
source Path_env.py
define symadd_bl32
if $debug_trusted_bootchain == 0
python gdb.execute("add-symbol-file " + path_elf_tf_a_bl32 + " -s ro " + bl32_load_addr)
else
python gdb.execute("add-symbol-file " + path_elf_op_tee_bl32)
end
end
document symadd_bl32
Load BL32 symbols on top of current symbols
end
define symload_bl2
python gdb.execute("symbol-file " + path_elf_tf_a_bl2)
end
document symload_bl2
Load BL2 symbols
end
define symload_uboot
python gdb.execute("symbol-file " + path_elf_u_boot)
end
document symload_uboot
Load U-Boot symbols
end
define symadd_uboot
set $offset_gdb = ((gd_t *)$r9)->relocaddr
python offset_py = gdb.convenience_variable("offset_gdb")
python gdb.execute("add-symbol-file " + path_elf_u_boot + " " + str(offset_py))
python gdb.set_convenience_variable("offset_gdb", None)
end
document symadd_uboot
Load U-Boot relocated symbols on top of current symbols
end
define symload_vmlinux
python gdb.execute("symbol-file " + path_elf_vmlinux)
end
document symload_vmlinux
Load Linux symbols
end
####################################################################
########################## functions ###############################
####################################################################
define break_boot_bl32
if $debug_trusted_bootchain == 0
thbreak sp_min_entrypoint
else
thbreak entry_a32.S:_start
end
c
end
define break_boot_uboot
thbreak vectors.S:_start
c
end
define break_boot_linuxkernel
thbreak stext
c
end
define mem_enable
mem auto
end
define mem_disable
mem 0 4 ro 8 nocache
end
####################################################################
######################## common config. ############################
# Disables confirmation requests
set confirm off
set mem inaccessible-by-default
mem_disable
# set debug remote 1
# Connection to the host gdbserver port for Cortex-A7 SMP
target extended-remote localhost:3333
# Configure GDB for OpenOCD
set remote hardware-breakpoint-limit 6
set remote hardware-watchpoint-limit 4
# Switch to Core0, no SMP for the moment. We'll re-enable it in kernel
monitor cortex_a smp off
monitor if {[target current] == "stm32mp15x.cpu1"} {targets stm32mp15x.cpu0}
####################################################################
# Reset the system and halt in bootrom to attach at boot
if $debug_mode == 0
symload_bl2
monitor reset halt
monitor gdb_sync
stepi
# Invalid on STM32MP13; ignore the returned error
monitor catch {if {[stm32mp15x.cpu1 curstate] == "halted"} {targets stm32mp15x.cpu1;resume;targets stm32mp15x.cpu0}}
# we halt at tf-a entry point. Nothing to do for $debug_phase == 1
# Stop at TF-A BL32 or OP-TEE entry point
if $debug_phase == 2
symadd_bl32
break_boot_bl32
end
# Stop at U-Boot entry point
if $debug_phase == 3
symload_uboot
break_boot_uboot
end
# Stop at Linux kernel entry point
if $debug_phase == 4
symload_vmlinux
break_boot_linuxkernel
# in kernel re-enable SMP
monitor cortex_a smp on
end
end
# Target state is now aligned with gdb, enable memory read
mem_enable
####################################################################
# Set hardware breakpoint mode for TF-A OP-TEE and U-Boot
if $debug_phase <= 3
monitor gdb_breakpoint_override hard
end
####################################################################
# Attach running target
if $debug_mode == 1
# Halt in U-Boot
if $debug_phase == 3
# Invalid on STM32MP13; ignore the returned error
monitor catch {if {[stm32mp15x.cpu1 curstate] == "halted"} {targets stm32mp15x.cpu1;resume;targets stm32mp15x.cpu0}}
symload_uboot
# Relocate U-Boot symbols
symadd_uboot
symadd_bl32
end
# Halt in Linux kernel
if $debug_phase == 4
symload_vmlinux
symadd_bl32
# in kernel re-enable SMP
monitor cortex_a smp on
end
monitor gdb_sync
stepi
end