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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
| diff --git a/beken_freertos_sdk_release-SDK_3.0.21/beken378/app/config/sys_config_bk7231n.h b/beken_freertos_sdk_release-SDK_3.0.21/beken378/app/config/sys_config_bk7231n.h
index 601f3d63..bbbe8d4c 100644
--- a/beken_freertos_sdk_release-SDK_3.0.21/beken378/app/config/sys_config_bk7231n.h
+++ b/beken_freertos_sdk_release-SDK_3.0.21/beken378/app/config/sys_config_bk7231n.h
@@ -308,4 +308,6 @@
#define CONFIG_MBEDTLS_SSL_OUT_CONTENT_LEN 4096
#endif
+#define CFG_RAM_DUMP_ENABLE 1
+
#endif // _SYS_CONFIG_H_
diff --git a/beken_freertos_sdk_release-SDK_3.0.21/beken378/driver/intc/intc.c b/beken_freertos_sdk_release-SDK_3.0.21/beken378/driver/intc/intc.c
index bb17af8e..d069d95d 100644
--- a/beken_freertos_sdk_release-SDK_3.0.21/beken378/driver/intc/intc.c
+++ b/beken_freertos_sdk_release-SDK_3.0.21/beken378/driver/intc/intc.c
@@ -365,8 +365,112 @@ void bk_show_register (struct arm_registers *regs)
}
os_printf("\r\n");
+#if CFG_RAM_DUMP_ENABLE
+ os_printf("; CPU Registers:\r\n");
+ os_printf("reg_cmm_start:\r\n");
+ os_printf("register.set cpsr 0x%08x\r\n", regs->cpsr);
+ os_printf("register.set spsr 0x%08x\r\n", regs->spsr);
+
+ os_printf("register.set pc 0x%08x\r\n", regs->pc);
+
+ os_printf("register.set r0 0x%08x\r\n", regs->r0);
+ os_printf("register.set r1 0x%08x\r\n", regs->r1);
+ os_printf("register.set r2 0x%08x\r\n", regs->r2);
+ os_printf("register.set r3 0x%08x\r\n", regs->r3);
+ os_printf("register.set r4 0x%08x\r\n", regs->r4);
+ os_printf("register.set r5 0x%08x\r\n", regs->r5);
+ os_printf("register.set r6 0x%08x\r\n", regs->r6);
+ os_printf("register.set r7 0x%08x\r\n", regs->r7);
+ os_printf("register.set r8 0x%08x\r\n", regs->r8);
+ os_printf("register.set r9 0x%08x\r\n", regs->r8);
+ os_printf("register.set r10 0x%08x\r\n", regs->r8);
+ os_printf("register.set r11 0x%08x\r\n", regs->fp);
+ os_printf("register.set r12 0x%08x\r\n", regs->ip);
+
+ if((regs->spsr & 0x3f) == 0x20)
+ {
+ os_printf("register.set r13 0x%08x\r\n", regs->sp);
+ os_printf("register.set r14 0x%08x\r\n", regs->lr);
+ }
+ else if((regs->spsr & 0x3f) == 0x21)
+ {
+ reg1 = (const unsigned int *)0x400068;
+ os_printf("register.set r13 0x%08x\r\n", *(reg1+7));
+ os_printf("register.set r14 0x%08x\r\n", *(reg1+8));
+ }
+ else if((regs->spsr & 0x3f) == 0x22)
+ {
+ reg1 = (const unsigned int *)0x400044;
+ os_printf("register.set r13 0x%08x\r\n", *(reg1+7));
+ os_printf("register.set r14 0x%08x\r\n", *(reg1+8));
+ }
+ else if((regs->spsr & 0x3f) == 0x23)
+ {
+ reg1 = (const unsigned int *)0x4000d4;
+ os_printf("register.set r13 0x%08x\r\n", *(reg1+7));
+ os_printf("register.set r14 0x%08x\r\n", *(reg1+8));
+ }
+ else if((regs->spsr & 0x3f) == 0x27)
+ {
+ reg1 = (const unsigned int *)0x40008c;
+ os_printf("register.set r13 0x%08x\r\n", *(reg1+7));
+ os_printf("register.set r14 0x%08x\r\n", *(reg1+8));
+ }
+ else if((regs->spsr & 0x3f) == 0x33)
+ {
+ reg1 = (const unsigned int *)0x4000b0;
+ os_printf("register.set r13 0x%08x\r\n", *(reg1+7));
+ os_printf("register.set r14 0x%08x\r\n", *(reg1+8));
+ }
+ else if((regs->spsr & 0x3f) == 0x3f)
+ {
+ reg1 = (const unsigned int *)0x400024;
+ os_printf("register.set r13 0x%08x\r\n", *(reg1+6));
+ os_printf("register.set r14 0x%08x\r\n", *(reg1+7));
+ }
+ os_printf("\r\nreg_cmm_end:\r\n");
+ os_printf("\r\n");
+
+#endif
}
+#if CFG_RAM_DUMP_ENABLE
+void bk_ram_dump(void)
+{
+ unsigned char *tcm_start = (unsigned char *)0x003F0000;
+ // unsigned char *itcm_start = (unsigned char *)0x003FF000;
+ unsigned char *ram_start = (unsigned char *)0x00400100;
+
+ bk_wdg_finalize();
+ os_printf("dump tcm:\r\n");
+ os_printf("tcm_start:\r\n");
+ for (size_t i = 0; i < (1024 *60); i++)
+ {
+ if(i%16 == 0)
+ {
+ os_printf("\r\n");
+ }
+ os_printf("%02x ", tcm_start[i]);
+
+ }
+ os_printf("\r\ntcm_end:\r\n");
+ os_printf("\r\n");
+
+ os_printf("dump ram:\r\n");
+ os_printf("ram_start:\r\n");
+ for (size_t i = 0; i < (1024 *192-0x100); i++)
+ {
+ if(i%16 == 0)
+ {
+ os_printf("\r\n");
+ }
+ os_printf("%02x ", ram_start[i]);
+
+ }
+ os_printf("\r\nram_end:\r\n");
+ os_printf("\r\n");
+}
+#endif
void bk_trap_udef(struct arm_registers *regs)
{
@@ -377,6 +481,9 @@ void bk_trap_udef(struct arm_registers *regs)
#endif
os_printf("undefined instruction\n");
bk_show_register(regs);
+#if CFG_RAM_DUMP_ENABLE
+ bk_ram_dump();
+#endif
bk_cpu_shutdown();
}
@@ -389,6 +496,9 @@ void bk_trap_pabt(struct arm_registers *regs)
#endif
os_printf("prefetch abort\n");
bk_show_register(regs);
+#if CFG_RAM_DUMP_ENABLE
+ bk_ram_dump();
+#endif
bk_cpu_shutdown();
}
@@ -401,6 +511,9 @@ void bk_trap_dabt(struct arm_registers *regs)
#endif
os_printf("data abort\n");
bk_show_register(regs);
+#if CFG_RAM_DUMP_ENABLE
+ bk_ram_dump();
+#endif
bk_cpu_shutdown();
}
@@ -413,6 +526,9 @@ void bk_trap_resv(struct arm_registers *regs)
#endif
os_printf("not used\n");
bk_show_register(regs);
+#if CFG_RAM_DUMP_ENABLE
+ bk_ram_dump();
+#endif
bk_cpu_shutdown();
}
diff --git a/beken_freertos_sdk_release-SDK_3.0.21/beken378/func/wlan_ui/wlan_cli.c b/beken_freertos_sdk_release-SDK_3.0.21/beken378/func/wlan_ui/wlan_cli.c
index c90de09e..50b3adb1 100644
--- a/beken_freertos_sdk_release-SDK_3.0.21/beken378/func/wlan_ui/wlan_cli.c
+++ b/beken_freertos_sdk_release-SDK_3.0.21/beken378/func/wlan_ui/wlan_cli.c
@@ -3306,6 +3306,12 @@ void pwr_Command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv
rw_msg_set_power(0,pwr);
}
+extern void do_undefined( void );
+
+void dump_test_Command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv)
+{
+ do_undefined();
+}
static void Deep_Sleep_Command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv)
{
PS_DEEP_CTRL_PARAM deep_sleep_param;
@@ -3974,6 +3980,9 @@ static const struct cli_command user_clis[] =
#if (CFG_SOC_NAME == SOC_BK7221U)
{"sec", "sec help", sec_Command },
#endif
+#if CFG_RAM_DUMP_ENABLE
+ {"dump_test", "dump_test", dump_test_Command},
+#endif
};
diff --git a/beken_freertos_sdk_release-SDK_3.0.21/quectel_build/scripts/bk_dump_parser.py b/beken_freertos_sdk_release-SDK_3.0.21/quectel_build/scripts/bk_dump_parser.py
new file mode 100644
index 00000000..f59289b4
--- /dev/null
+++ b/beken_freertos_sdk_release-SDK_3.0.21/quectel_build/scripts/bk_dump_parser.py
@@ -0,0 +1,91 @@
+#!/usr/bin/env python3
+
+import os
+import sys
+import optparse
+import binascii
+import re
+
+
+def parse_dump_log_file(filename):
+ reg_cmm = ""
+ tcm_data = ""
+ ram_data = ""
+ f = open(filename, "r")
+ while True:
+ line = f.readline()
+ if line == "":
+ break
+ if "reg_cmm_start:" in line:
+ while True:
+ line = f.readline()
+ if line == "":
+ break
+ if "reg_cmm_end:" in line:
+ break
+ pattern = re.compile(r'register\.set [^\n]+')
+ matches = pattern.findall(line)
+ if len(matches) > 0:
+ reg_cmm += matches[0] + "\r\n"
+ if "tcm_start:" in line:
+ while True:
+ line = f.readline()
+ if line == "":
+ break
+ if "tcm_end:" in line:
+ break
+
+ pattern = re.compile(r'(?:\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\]\s*)?((?:[0-9a-fA-F]{2}\s*){16})')
+ matches = pattern.findall(line)
+ if len(matches) > 0:
+ tcm_data += matches[0]
+
+ if "ram_start:" in line:
+ while True:
+ line = f.readline()
+ if line == "":
+ break
+ if "ram_end:" in line:
+ break
+
+ pattern = re.compile(r'(?:\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\]\s*)?((?:[0-9a-fA-F]{2}\s*){16})')
+ matches = pattern.findall(line)
+ if len(matches) > 0:
+ ram_data += matches[0]
+ break
+ f.close()
+ return (reg_cmm, tcm_data, ram_data)
+
+def main(argv):
+ opt = optparse.OptionParser(usage="""usage %prog [options]
+ """)
+
+ opt.add_option("--log", action="store", dest="log",
+ help="dump log file.")
+
+ opt, argv = opt.parse_args(argv)
+
+ if not opt.log:
+ print("No log file specified!")
+ return 1
+ reg_cmm, tcm_data, ram_data = parse_dump_log_file(opt.log)
+
+ if reg_cmm != "":
+ with open("reg.cmm", "w") as f:
+ f.write(reg_cmm)
+ if tcm_data != "":
+ tcm_data = tcm_data.replace(" ", "").replace("\n", "").replace("\r", "")
+ bin_data = binascii.unhexlify(tcm_data)
+ with open("tcm.bin", "wb") as f:
+ f.write(bin_data)
+
+ if ram_data != "":
+ ram_data = ram_data.replace(" ", "").replace("\n", "").replace("\r", "")
+ bin_data = binascii.unhexlify(ram_data)
+ with open("ram.bin", "wb") as f:
+ f.write(bin_data)
+
+
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv[1:]))
\ No newline at end of file
|