1 /*
2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 * Description:PRESERVE INTERFACE for security core
15 * Author:
16 * Create:
17 */
18 #include "preserve.h"
19 #include "securec.h"
20 #if defined(BUILD_APPLICATION_STANDARD)
21 #include "log_printf.h"
22 #include "systick.h"
23 #include "log_oam_logger.h"
24 #include "log_def.h"
25 #endif
26 #include "debug_print.h"
27 #include "hal_reboot.h"
28 #ifdef SUPPORT_CRASH_DATA_RAM
29 #include "crash_data.h"
30 #endif
31
32 #define RIGHT_SHIFT_32BITS 32
33 #define WORD_MASK_VALUE 0xFFFFFFFF
34 #define TIME_S_TO_MS 1000
35 #define RESERVED_PC_INDEX 0
36 #define RESERVED_LR_INDEX 1
37 #define RESERVED_SP_INDEX 2
38
39 // all security core preserve data here, if want to add new,should add tail for compatible befor version
40 #pragma pack(4)
41 typedef struct {
42 #if ((ARCH == RISCV31) || (ARCH == RISCV32) || (ARCH == RISCV70))
43 exc_context_t exc_context;
44 #else
45 exception_stack_frame_t exception_stack_frame; // 32
46 #endif
47 exception_info_t exception_info; // 52
48 panic_desc_t last_panic; // 12
49 uint32_t entry_sleep_time[2]; // The size of the array is 2, which stores the high and low bits of sleep time.
50 uint32_t rtc_delay_count[2]; // The size of the array is 2, which stores the high and low bits of rtc delay count.
51 uint32_t excepted_delay_time;
52 uint32_t exception_time_s;
53 uint32_t reserved[3]; // The size of the reserved array n is 3, total 12 bytes.
54 reboot_cause_t cpu_utils_reset_cause; // 4
55 bool update_reset_cause_on_boot; // 4
56 unsigned long fault_reason; // 4
57 unsigned long fault_address; // 4
58 uint32_t intid; // error int num
59 uint32_t magic; // exception flag
60 uint32_t reboot_status;
61 unsigned int reboot_count; // reboot count since coldboot
62 unsigned int ep_reboot_count; // exception reboot count continuously
63 unsigned int enable_sha_check; // total size until here: 172 Byte
64 } preserve_data_t;
65 #pragma pack()
66
67 typedef struct {
68 uint32_t pc;
69 uint32_t lr;
70 uint32_t sp;
71 } preserve_cpu_info_t;
72
73 #ifdef __ICCARM__
74 #pragma location=PRESERVED_REGION_ORIGIN
75 __no_init preserve_data_t g_preserve_data_lib;
76 #else
77 PRESERVE preserve_data_t g_preserve_data_lib;
78 #endif
79 static preserve_data_t g_preserve_data_lib_ram;
80 #if !defined(BUILD_APPLICATION_ROM)
81 static preserve_data_t *g_preserve_data_lib_ptr = (preserve_data_t *)(uintptr_t)(PRESERVED_REGION_ORIGIN);
82 #endif
83
duplicate_preserve_mem(void)84 static void duplicate_preserve_mem(void)
85 {
86 UNUSED(g_preserve_data_lib_ram);
87 #if CORE == MASTER_BY_ALL
88 memcpy_s((void *)&g_preserve_data_lib_ram, sizeof(g_preserve_data_lib_ram), (void *)&g_preserve_data_lib,
89 sizeof(g_preserve_data_lib_ram));
90 #endif
91 }
92
93 #if (defined(CHIP_SW39) && (CHIP_SW39 == 1))
duplicate_app_preserve_mem(void)94 void duplicate_app_preserve_mem(void)
95 {
96 preserve_data_t *app_preserve_data = (preserve_data_t *)(uintptr_t)(APP_PRESERVED_REGION_ORIGIN);
97 if (app_preserve_data->magic != STANDARD_REBOOT_MAGIC && app_preserve_data->magic != ABNORMAL_REBOOT_MAGIC) {
98 memcpy_s((void *)app_preserve_data, sizeof(preserve_data_t), (void *)&g_preserve_data_lib_ram,
99 sizeof(g_preserve_data_lib_ram));
100 }
101 }
102 #endif
103
is_preserve_data_saved(uintptr_t preserve_ptr)104 bool is_preserve_data_saved(uintptr_t preserve_ptr)
105 {
106 preserve_data_t *preserve_data = (preserve_data_t *)preserve_ptr;
107 return preserve_data->magic == STANDARD_REBOOT_MAGIC || preserve_data->magic == ABNORMAL_REBOOT_MAGIC;
108 }
109
set_chip_system_boot_magic(uint32_t magic)110 static inline void set_chip_system_boot_magic(uint32_t magic)
111 {
112 g_preserve_data_lib.magic = magic;
113 }
114
system_set_reboot_status_by_crash_cause(void)115 static void system_set_reboot_status_by_crash_cause(void)
116 {
117 reboot_cause_t cause = g_preserve_data_lib.cpu_utils_reset_cause;
118 if ((REBOOT_CAUSE_BT_RESET_UNKNOWN <= cause && cause <= REBOOT_CAUSE_BT_END) ||
119 (REBOOT_CAUSE_GNSS_GLOBAL <= cause && cause <= REBOOT_CAUSE_GNSS_END) ||
120 (REBOOT_CAUSE_PROTOCOL_GLOBAL <= cause && cause <= REBOOT_CAUSE_PROTOCOL_END)) {
121 g_preserve_data_lib.reboot_status = REBOOT_OTHER_CORE_ABNORMAL_TRIGER_STATUS;
122 } else if (cause == REBOOT_CAUSE_APPLICATION_HARDFAULT) {
123 g_preserve_data_lib.reboot_status = REBOOT_HARD_FAULT_TRIGER_STATUS;
124 } else if (cause == REBOOT_CAUSE_APPLICATION_XIP_CTRL) {
125 g_preserve_data_lib.reboot_status = REBOOT_NMI_XIP_CTRL_TRIGER_STATUS;
126 } else if (cause == REBOOT_CAUSE_APPLICATION_XIP_CACHE) {
127 g_preserve_data_lib.reboot_status = REBOOT_NMI_XIP_CACHE_TRIGGER_STATUS;
128 } else if (cause == REBOOT_CAUSE_APPLICATION_CHIP_WDT) {
129 g_preserve_data_lib.reboot_status = REBOOT_NMI_WDGTIMEOUT_TRIGGER_STATUS;
130 } else if (cause == REBOOT_CAUSE_APPLICATION_PANIC) {
131 g_preserve_data_lib.reboot_status = REBOOT_SOFT_PANIC_TRIGGER_STATUS;
132 } else if (cause == REBOOT_CAUSE_APPLICATION_STD_BT_WDT_FRST) {
133 g_preserve_data_lib.reboot_status = REBOOT_BT_WDGTIMEOUT_TRIGER_STATUS;
134 } else if (cause == REBOOT_CAUSE_APPLICATION_STD_ULP_WDT_FRST) {
135 g_preserve_data_lib.reboot_status = REBOOT_ULP_WDGTIMEOUT_TRIGER_STATUS;
136 } else if (cause == REBOOT_CAUSE_APPLICATION_STD_ULP_PIN_FRST) {
137 g_preserve_data_lib.reboot_status = REBOOT_ULP_PIN_RST_TRIGER_STATUS;
138 } else if (cause == REBOOT_CAUSE_POWER_ON) {
139 g_preserve_data_lib.reboot_status = REBOOT_POWER_ON_TRIGGER_STATUS;
140 } else if (cause == REBOOT_CAUSE_UPG_COMPLETION) {
141 g_preserve_data_lib.reboot_status = REBOOT_UPG_COMPLETION_TRIGER_STATUS;
142 } else {
143 g_preserve_data_lib.reboot_status = REBOOT_UNDEFINED_TRIGER_STATUS;
144 }
145 }
146
147 #ifdef weak
watchdog_porting_pmu_reboot(void)148 weak void watchdog_porting_pmu_reboot(void)
149 {
150 }
151 #else
watchdog_porting_pmu_reboot(void)152 __attribute__((weak)) void watchdog_porting_pmu_reboot(void)
153 {
154 }
155 #endif
156
system_boot_status_init(void)157 void system_boot_status_init(void)
158 {
159 bool is_hardwdg_timeout = false;
160 if (!hal_reboot_get_ulp_aon_no_poweroff_flag()) {
161 hal_reboot_set_ulp_aon_no_poweroff_flag();
162 memset_s((void *)&g_preserve_data_lib, sizeof(g_preserve_data_lib), 0, sizeof(g_preserve_data_lib));
163 }
164 if (g_preserve_data_lib.magic == 0) { // Hard power-off restart
165 g_preserve_data_lib.reboot_status = REBOOT_POWER_ON_TRIGGER_STATUS;
166 g_preserve_data_lib.cpu_utils_reset_cause = REBOOT_CAUSE_POWER_ON;
167 g_preserve_data_lib.update_reset_cause_on_boot = true;
168 watchdog_porting_pmu_reboot();
169 }
170 is_hardwdg_timeout = hal_reboot_hard_wdg_timeout((uint16_t)g_preserve_data_lib.cpu_utils_reset_cause);
171 if (is_hardwdg_timeout) { // hard watchdog tiemout
172 set_update_reset_cause_on_boot(false);
173 g_preserve_data_lib.reboot_status = REBOOT_HARD_WDGTIMEOUT_TRIGER_STATUS;
174 g_preserve_data_lib.cpu_utils_reset_cause = REBOOT_CAUSE_APPLICATION_STD_CHIP_WDT_FRST;
175 } else { // normal soft restart
176 if (g_preserve_data_lib.magic == STANDARD_REBOOT_MAGIC) {
177 g_preserve_data_lib.reboot_status = REBOOT_SOFT_RESET_TRIGER_STATUS;
178 } else {
179 system_set_reboot_status_by_crash_cause();
180 }
181 }
182
183 if (get_update_reset_cause_on_boot()) { // the system is restarted by writing the reset register.
184 set_cpu_utils_reset_cause(REBOOT_CAUSE_UNKNOWN);
185 }
186
187 if (g_preserve_data_lib.reboot_status != REBOOT_POWER_ON_TRIGGER_STATUS) {
188 g_preserve_data_lib.reboot_count++;
189 if (g_preserve_data_lib.reboot_status == REBOOT_SOFT_RESET_TRIGER_STATUS) {
190 g_preserve_data_lib.ep_reboot_count = 0;
191 g_preserve_data_lib.enable_sha_check = 0;
192 } else {
193 g_preserve_data_lib.ep_reboot_count++;
194 }
195 } else {
196 g_preserve_data_lib.reboot_status = REBOOT_POWER_ON_TRIGGER_STATUS;
197 g_preserve_data_lib.cpu_utils_reset_cause = REBOOT_CAUSE_POWER_ON;
198 }
199 g_preserve_data_lib.magic = STANDARD_REBOOT_MAGIC;
200 }
201
get_system_boot_status(void)202 unsigned int get_system_boot_status(void)
203 {
204 return g_preserve_data_lib.reboot_status;
205 }
206
get_system_magic(void)207 uint32_t get_system_magic(void)
208 {
209 return g_preserve_data_lib.magic;
210 }
211
set_cpu_utils_system_boot_magic(void)212 void set_cpu_utils_system_boot_magic(void)
213 {
214 unsigned int magic = STANDARD_REBOOT_MAGIC;
215
216 switch (get_cpu_utils_reset_cause()) {
217 case REBOOT_CAUSE_BT_SYSRESETREQ:
218 case REBOOT_CAUSE_PROTOCOL_SYSRESETREQ:
219 case REBOOT_CAUSE_APPLICATION_SYSRESETREQ:
220 case REBOOT_CAUSE_UNKNOWN:
221 case REBOOT_CAUSE_POWER_ON:
222 case REBOOT_CAUSE_UPG_COMPLETION:
223 magic = STANDARD_REBOOT_MAGIC;
224 break;
225
226 default:
227 /* unidentified normal reboot cause */
228 magic = ABNORMAL_REBOOT_MAGIC;
229 break;
230 }
231
232 set_chip_system_boot_magic(magic);
233 }
234
set_cpu_utils_reset_cause(reboot_cause_t reset_cause)235 void set_cpu_utils_reset_cause(reboot_cause_t reset_cause)
236 {
237 set_update_reset_cause_on_boot(false);
238 g_preserve_data_lib.cpu_utils_reset_cause = reset_cause;
239 duplicate_preserve_mem();
240 }
241
get_cpu_utils_reset_count(void)242 unsigned int get_cpu_utils_reset_count(void)
243 {
244 return g_preserve_data_lib.reboot_count;
245 }
246
get_cpu_utils_epreset_count(void)247 unsigned int get_cpu_utils_epreset_count(void)
248 {
249 return g_preserve_data_lib.ep_reboot_count;
250 }
251
get_cpu_utils_reset_cause(void)252 reboot_cause_t get_cpu_utils_reset_cause(void)
253 {
254 return g_preserve_data_lib.cpu_utils_reset_cause;
255 }
256
set_update_reset_cause_on_boot(bool reset_cause_on_boot)257 void set_update_reset_cause_on_boot(bool reset_cause_on_boot)
258 {
259 g_preserve_data_lib.update_reset_cause_on_boot = reset_cause_on_boot;
260 }
261
get_update_reset_cause_on_boot(void)262 bool get_update_reset_cause_on_boot(void)
263 {
264 return g_preserve_data_lib.update_reset_cause_on_boot;
265 }
266
get_cpu_utils_check_sha_value(void)267 uint32_t get_cpu_utils_check_sha_value(void)
268 {
269 return g_preserve_data_lib.enable_sha_check;
270 }
271
set_cpu_utils_check_sha_fault_value(void)272 void set_cpu_utils_check_sha_fault_value(void)
273 {
274 g_preserve_data_lib.enable_sha_check = 0;
275 }
276
get_last_panic_id(void)277 uint8_t get_last_panic_id(void)
278 {
279 return g_preserve_data_lib.last_panic.origin;
280 }
281
get_last_panic_code(void)282 uint32_t get_last_panic_code(void)
283 {
284 return g_preserve_data_lib.last_panic.code;
285 }
286
get_last_panic_caller(void)287 uint32_t get_last_panic_caller(void)
288 {
289 return g_preserve_data_lib.last_panic.caller;
290 }
291
get_cpu_utils_exc_pc(void)292 uint32_t get_cpu_utils_exc_pc(void)
293 {
294 #if ((ARCH == RISCV31) || (ARCH == RISCV32) || (ARCH == RISCV70))
295 return g_preserve_data_lib.exc_context.task_context.mepc;
296 #else
297 return g_preserve_data_lib.exception_stack_frame.stacked_pc;
298 #endif
299 }
300
get_cpu_utils_exc_lr(void)301 uint32_t get_cpu_utils_exc_lr(void)
302 {
303 #if ((ARCH == RISCV31) || (ARCH == RISCV32) || (ARCH == RISCV70))
304 return g_preserve_data_lib.exc_context.task_context.ra;
305 #else
306 return g_preserve_data_lib.exception_stack_frame.stacked_lr;
307 #endif
308 }
309
set_entry_sleep_time(uint64_t time)310 void set_entry_sleep_time(uint64_t time)
311 {
312 g_preserve_data_lib.entry_sleep_time[0] = (uint32_t)(time & WORD_MASK_VALUE);
313 g_preserve_data_lib.entry_sleep_time[1] = (uint32_t)((time >> RIGHT_SHIFT_32BITS) & WORD_MASK_VALUE);
314 }
315
set_rtc_delay_count(uint64_t time)316 void set_rtc_delay_count(uint64_t time)
317 {
318 if ((get_system_boot_status() == REBOOT_POWER_ON_TRIGGER_STATUS) ||
319 (get_system_boot_status() == REBOOT_SOFT_RESET_TRIGER_STATUS)) {
320 g_preserve_data_lib.rtc_delay_count[0] = (uint32_t)(time & WORD_MASK_VALUE);
321 g_preserve_data_lib.rtc_delay_count[1] = (uint32_t)((time >> RIGHT_SHIFT_32BITS) & WORD_MASK_VALUE);
322 }
323 }
324
set_excepted_sleep_time(uint32_t time)325 void set_excepted_sleep_time(uint32_t time)
326 {
327 g_preserve_data_lib.excepted_delay_time = time;
328 }
329
set_exception_time_stamp(void)330 void set_exception_time_stamp(void)
331 {
332 #if defined(BUILD_APPLICATION_STANDARD)
333 g_preserve_data_lib.exception_time_s = (uint32_t)((uapi_systick_get_ms() + get_log_basetime_ms()) / TIME_S_TO_MS);
334 #endif
335 }
336
set_system_boot_status(unsigned int reboot_status)337 void set_system_boot_status(unsigned int reboot_status)
338 {
339 g_preserve_data_lib.reboot_status = reboot_status;
340 }
341
get_last_panic_handle(void)342 panic_desc_t *get_last_panic_handle(void)
343 {
344 return &g_preserve_data_lib.last_panic;
345 }
346
set_last_panic(panic_desc_t * last_panic)347 void set_last_panic(panic_desc_t *last_panic)
348 {
349 memcpy_s((void *)&g_preserve_data_lib.last_panic, sizeof(panic_desc_t), (void *)last_panic, sizeof(panic_desc_t));
350 duplicate_preserve_mem();
351 #ifdef SUPPORT_CRASH_DATA_RAM
352 crash_data_set_panic(last_panic);
353 #endif
354 }
355
356 #if ((ARCH == RISCV31) || (ARCH == RISCV32) || (ARCH == RISCV70))
set_exception_info_riscv(exc_context_t * exc_data)357 void set_exception_info_riscv(exc_context_t *exc_data)
358 {
359 memcpy_s((void *)&g_preserve_data_lib.exc_context, sizeof(exc_context_t),
360 (void *)exc_data, sizeof(exc_context_t));
361 duplicate_preserve_mem();
362 }
363
get_exception_info_riscv(void)364 task_context_t *get_exception_info_riscv(void)
365 {
366 return &g_preserve_data_lib.exc_context.task_context;
367 }
368 #else
get_exception_stack_frame_handle(void)369 exception_stack_frame_t *get_exception_stack_frame_handle(void)
370 {
371 return &g_preserve_data_lib.exception_stack_frame;
372 }
373
get_exception_info(void)374 exception_info_t *get_exception_info(void)
375 {
376 return &g_preserve_data_lib.exception_info;
377 }
378 #endif
379
set_exception_info(exception_info_t * exception_info)380 void set_exception_info(exception_info_t *exception_info)
381 {
382 if (exception_info == NULL) {
383 return;
384 }
385 memcpy_s((void *)&g_preserve_data_lib.exception_info, sizeof(exception_info_t),
386 (void *)exception_info, sizeof(exception_info_t));
387 duplicate_preserve_mem();
388 #ifdef SUPPORT_CRASH_DATA_RAM
389 crash_data_set_exception_info(exception_info);
390 #endif
391 }
392
set_exception_stack_frame(exception_stack_frame_t * exception_stack_frame_src)393 void set_exception_stack_frame(exception_stack_frame_t *exception_stack_frame_src)
394 {
395 #if ((ARCH == RISCV31) || (ARCH == RISCV32) || (ARCH == RISCV70))
396 g_preserve_data_lib.exc_context.task_context.ra = (uint32_t)exception_stack_frame_src->stacked_lr;
397 g_preserve_data_lib.exc_context.task_context.mepc = (uint32_t)exception_stack_frame_src->stacked_pc;
398 #else
399 memcpy_s((void *)&g_preserve_data_lib.exception_stack_frame, sizeof(exception_stack_frame_t),
400 (void *)exception_stack_frame_src, sizeof(exception_stack_frame_t));
401 #endif
402 duplicate_preserve_mem();
403 }
404
set_fault_address(uint32_t address)405 void set_fault_address(uint32_t address)
406 {
407 g_preserve_data_lib.fault_address = address;
408 duplicate_preserve_mem();
409 }
410
get_fault_address(void)411 uint32_t get_fault_address(void)
412 {
413 return (uint32_t)g_preserve_data_lib.fault_address;
414 }
415
set_fault_reason(uint32_t reason)416 void set_fault_reason(uint32_t reason)
417 {
418 g_preserve_data_lib.fault_reason = reason;
419 duplicate_preserve_mem();
420 }
421
set_fault_intid(uint32_t intid)422 void set_fault_intid(uint32_t intid)
423 {
424 g_preserve_data_lib.intid = intid;
425 duplicate_preserve_mem();
426 }
427
get_fault_reason(void)428 uint32_t get_fault_reason(void)
429 {
430 return (uint32_t)g_preserve_data_lib.fault_reason;
431 }
432
set_pc_lr_sp_value(uint32_t pc_value,uint32_t lr_value,uint32_t sp_value)433 void set_pc_lr_sp_value(uint32_t pc_value, uint32_t lr_value, uint32_t sp_value)
434 {
435 g_preserve_data_lib.reserved[RESERVED_PC_INDEX] = pc_value;
436 g_preserve_data_lib.reserved[RESERVED_LR_INDEX] = lr_value;
437 g_preserve_data_lib.reserved[RESERVED_SP_INDEX] = sp_value;
438 }
439
get_pc_lr_sp_value(uint32_t * pc_value,uint32_t * lr_value,uint32_t * sp_value)440 void get_pc_lr_sp_value(uint32_t *pc_value, uint32_t *lr_value, uint32_t *sp_value)
441 {
442 if (pc_value == NULL || lr_value == NULL || sp_value == NULL) {
443 return;
444 }
445 *pc_value = g_preserve_data_lib.reserved[RESERVED_PC_INDEX];
446 *lr_value = g_preserve_data_lib.reserved[RESERVED_LR_INDEX];
447 *sp_value = g_preserve_data_lib.reserved[RESERVED_SP_INDEX];
448 }
449
450
451 #if !defined(BUILD_APPLICATION_ROM)
get_last_slave_panic_id(cores_t core)452 uint8_t get_last_slave_panic_id(cores_t core)
453 {
454 UNUSED(core);
455 return g_preserve_data_lib_ptr->last_panic.origin;
456 }
457
get_last_slave_panic_code(cores_t core)458 uint32_t get_last_slave_panic_code(cores_t core)
459 {
460 UNUSED(core);
461 return g_preserve_data_lib_ptr->last_panic.code;
462 }
463
get_last_slave_panic_caller(cores_t core)464 uint32_t get_last_slave_panic_caller(cores_t core)
465 {
466 UNUSED(core);
467 return g_preserve_data_lib_ptr->last_panic.caller;
468 }
469 #endif
470
471 #if defined(BUILD_APPLICATION_STANDARD)
get_cpu_info(void)472 static preserve_cpu_info_t get_cpu_info(void)
473 {
474 preserve_cpu_info_t temp;
475 #if ((ARCH == RISCV31) || (ARCH == RISCV32) || (ARCH == RISCV70))
476 temp.pc = g_preserve_data_lib.exc_context.task_context.mepc;
477 temp.lr = g_preserve_data_lib.exc_context.task_context.ra;
478 temp.sp = g_preserve_data_lib.exc_context.task_context.sp;
479 #else
480 temp.pc = g_preserve_data_lib.exception_stack_frame.stacked_pc;
481 temp.lr = g_preserve_data_lib.exception_stack_frame.stacked_lr;
482 temp.sp = g_preserve_data_lib.exception_stack_frame.stacked_psr;
483 #endif
484 return temp;
485 }
486
system_boot_reason_print(void)487 void system_boot_reason_print(void)
488 {
489 switch (get_system_boot_status()) {
490 case REBOOT_SOFT_RESET_TRIGER_STATUS:
491 oml_pf_log_print0(LOG_BCORE_PLT_DRIVER_REBOOT, LOG_NUM_DRIVER_REBOOT, LOG_LEVEL_INFO, "System Boot Normal");
492 break;
493 case REBOOT_NMI_WDGTIMEOUT_TRIGGER_STATUS:
494 oml_pf_log_print0(LOG_BCORE_PLT_DRIVER_REBOOT, LOG_NUM_DRIVER_REBOOT, LOG_LEVEL_INFO, \
495 "System Boot Abnoraml, watchdog timeout");
496 break;
497 case REBOOT_SOFT_PANIC_TRIGGER_STATUS:
498 /* reboot from cpu fault & wdt int etc. */
499 oml_pf_log_print0(LOG_BCORE_PLT_DRIVER_REBOOT, LOG_NUM_DRIVER_REBOOT, LOG_LEVEL_INFO, "System Boot Panic");
500 break;
501 case REBOOT_NMI_XIP_CTRL_TRIGER_STATUS:
502 case REBOOT_NMI_XIP_CACHE_TRIGGER_STATUS:
503 oml_pf_log_print0(LOG_BCORE_PLT_DRIVER_REBOOT, LOG_NUM_DRIVER_REBOOT, LOG_LEVEL_INFO, \
504 "System Boot Abnoraml, xip crash");
505 break;
506 case REBOOT_HARD_FAULT_TRIGER_STATUS:
507 oml_pf_log_print0(LOG_BCORE_PLT_DRIVER_REBOOT, LOG_NUM_DRIVER_REBOOT, LOG_LEVEL_INFO, \
508 "System Boot Abnoraml, hard fault crash");
509 break;
510 case REBOOT_POWER_ON_TRIGGER_STATUS:
511 /* first power on, vsys power reset or power_on reset */
512 oml_pf_log_print0(LOG_BCORE_PLT_DRIVER_REBOOT, LOG_NUM_DRIVER_REBOOT, LOG_LEVEL_INFO, "System Power On");
513 break;
514 case REBOOT_OTHER_CORE_ABNORMAL_TRIGER_STATUS:
515 oml_pf_log_print0(LOG_BCORE_PLT_DRIVER_REBOOT, LOG_NUM_DRIVER_REBOOT, LOG_LEVEL_INFO,
516 "System Boot Abnoraml, other core crash");
517 break;
518 default:
519 oml_pf_log_print1(LOG_BCORE_PLT_DRIVER_REBOOT, LOG_NUM_DRIVER_REBOOT, LOG_LEVEL_INFO, \
520 "Unkown Sytem Boot Type:0x%x", get_system_boot_status());
521 break;
522 }
523 }
524
system_boot_reason_process(void)525 void system_boot_reason_process(void)
526 {
527 unsigned int reset_cause = (unsigned int)get_cpu_utils_reset_cause();
528 unsigned int reset_count = get_cpu_utils_reset_count();
529 unsigned int ep_reboot_count = get_cpu_utils_epreset_count();
530 oml_pf_log_print3(LOG_BCORE_PLT_DRIVER_REBOOT, LOG_NUM_DRIVER_REBOOT, LOG_LEVEL_INFO,\
531 "System Reboot cause:0x%x , total reboot count:%u, exception reboot count:%u",\
532 reset_cause, reset_count, ep_reboot_count);
533 if ((reset_cause == REBOOT_CAUSE_APPLICATION_HARDFAULT) || (reset_cause == REBOOT_CAUSE_BT_HARDFAULT)) {
534 oml_pf_log_print2(LOG_BCORE_PLT_DRIVER_REBOOT, LOG_NUM_DRIVER_REBOOT, LOG_LEVEL_INFO,\
535 "Exception reboot pc:0x%x , lr:%x",\
536 get_cpu_utils_exc_pc(), get_cpu_utils_exc_lr());
537 }
538 switch (reset_cause) {
539 case REBOOT_CAUSE_BT_PANIC:
540 oml_pf_log_print3(LOG_BCORE_PLT_DRIVER_REBOOT, LOG_NUM_DRIVER_REBOOT, LOG_LEVEL_INFO,"panic id:0x%x, \
541 panic code: 0x%x, panic caller: 0x%x" , get_last_slave_panic_id(CORES_BT_CORE), \
542 get_last_slave_panic_code(CORES_BT_CORE), get_last_slave_panic_caller(CORES_BT_CORE));
543 break;
544 case REBOOT_CAUSE_APPLICATION_PANIC:
545 oml_pf_log_print3(LOG_BCORE_PLT_DRIVER_REBOOT, LOG_NUM_DRIVER_REBOOT, LOG_LEVEL_INFO,"panic id:0x%x, \
546 panic code: 0x%x, panic caller: 0x%x" , get_last_panic_id(), \
547 get_last_panic_code(), get_last_panic_caller());
548 break;
549 case REBOOT_CAUSE_APPLICATION_STD_CHIP_WDT_FRST:
550 panic(PANIC_CHIP_WDT_FRST, 0);
551 break;
552 case REBOOT_CAUSE_BT_WATCHDOG:
553 case REBOOT_CAUSE_BT_HARDFAULT:
554 case REBOOT_CAUSE_BT_NNMIFAULT:
555 oml_pf_log_print2(LOG_BCORE_PLT_DRIVER_REBOOT, LOG_NUM_DRIVER_REBOOT, LOG_LEVEL_INFO, \
556 "bt exception reboot with pc:0x%x, lr: 0x%x" , \
557 get_cpu_info().pc, get_cpu_info().lr);
558 break;
559 case REBOOT_CAUSE_APPLICATION_HARDFAULT:
560 case REBOOT_CAUSE_APPLICATION_NNMIFAULT:
561 case REBOOT_CAUSE_APPLICATION_CHIP_WDT:
562 case REBOOT_CAUSE_APPLICATION_XIP_CTRL:
563 case REBOOT_CAUSE_APPLICATION_XIP_CACHE:
564 case REBOOT_CAUSE_APPLICATION_MDMA:
565 case REBOOT_CAUSE_APPLICATION_SMDMA:
566 oml_pf_log_print2(LOG_BCORE_PLT_DRIVER_REBOOT, LOG_NUM_DRIVER_REBOOT, LOG_LEVEL_INFO, \
567 "app exception reboot pc:0x%x, lr: 0x%x" , \
568 get_cpu_info().pc, get_cpu_info().lr);
569 break;
570 default:
571 break;
572 }
573 }
574 #endif
575
print_system_boot_status(void)576 static void print_system_boot_status(void)
577 {
578 unsigned int reset_cause = (unsigned int)get_cpu_utils_reset_cause();
579
580 switch (get_system_boot_status()) {
581 case REBOOT_SOFT_RESET_TRIGER_STATUS:
582 PRINT("System Boot Noraml" NEWLINE);
583 break;
584 case REBOOT_NMI_WDGTIMEOUT_TRIGGER_STATUS:
585 PRINT("System Boot watchdog timeout" NEWLINE);
586 break;
587 case REBOOT_NMI_XIP_CTRL_TRIGER_STATUS:
588 case REBOOT_NMI_XIP_CACHE_TRIGGER_STATUS:
589 PRINT("System Boot Abnoraml, XIP crash" NEWLINE);
590 break;
591 case REBOOT_HARD_FAULT_TRIGER_STATUS:
592 PRINT("System Boot Abnoraml, hard fault crash" NEWLINE);
593 break;
594 case REBOOT_POWER_ON_TRIGGER_STATUS:
595 /* normal system reboot, except reboot */
596 PRINT("System Power On" NEWLINE);
597 break;
598 case REBOOT_SOFT_PANIC_TRIGGER_STATUS:
599 PRINT("System Boot Abnoraml, panic crash" NEWLINE);
600 break;
601 case REBOOT_OTHER_CORE_ABNORMAL_TRIGER_STATUS:
602 PRINT("System Boot Abnoraml, other core crash" NEWLINE);
603 break;
604 case REBOOT_HARD_WDGTIMEOUT_TRIGER_STATUS:
605 PRINT("System Boot Abnoraml, chip watchdog timeout" NEWLINE);
606 break;
607 default:
608 PRINT("Unkown Sytem Boot Type 0x%x" NEWLINE, get_system_boot_status());
609 break;
610 }
611 PRINT("System Reboot cause:0x%x, total reboot count:%u, exception reboot count:%u\r\n",\
612 reset_cause, get_cpu_utils_reset_count(), get_cpu_utils_epreset_count());
613 if (reset_cause == REBOOT_CAUSE_BT_PANIC) {
614 PRINT("panic id:0x%x, panic code: 0x%x, panic caller: 0x%x\r\n", get_last_slave_panic_id(CORES_BT_CORE), \
615 get_last_slave_panic_code(CORES_BT_CORE), get_last_slave_panic_caller(CORES_BT_CORE));
616 } else if (reset_cause == REBOOT_CAUSE_APPLICATION_PANIC) {
617 PRINT("panic id:0x%x, panic code: 0x%x, panic caller: 0x%x\r\n", get_last_panic_id(), \
618 get_last_panic_code(), get_last_panic_caller());
619 } else if ((reset_cause == REBOOT_CAUSE_APPLICATION_HARDFAULT) || (reset_cause == REBOOT_CAUSE_BT_HARDFAULT)) {
620 PRINT("Exception reboot pc:0x%x , lr:%x", get_cpu_utils_exc_pc(), get_cpu_utils_exc_lr());
621 }
622 }
623
show_reboot_info(void)624 void show_reboot_info(void)
625 {
626 system_boot_status_init();
627 print_system_boot_status();
628 }
629