mt_debug_dump.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /* Copyright Statement:
  2. *
  3. * This software/firmware and related documentation ("MediaTek Software") are
  4. * protected under relevant copyright laws. The information contained herein
  5. * is confidential and proprietary to MediaTek Inc. and/or its licensors.
  6. * Without the prior written permission of MediaTek inc. and/or its licensors,
  7. * any reproduction, modification, use or disclosure of MediaTek Software,
  8. * and information contained herein, in whole or in part, shall be strictly prohibited.
  9. */
  10. /* MediaTek Inc. (C) 2015. All rights reserved.
  11. *
  12. * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  13. * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  14. * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
  15. * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  18. * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  19. * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  20. * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
  21. * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
  22. * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
  23. * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
  24. * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
  25. * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
  26. * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  27. * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  28. * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
  29. * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
  30. */
  31. #include <stdint.h>
  32. #include <string.h>
  33. #include <stdlib.h>
  34. #include <debug.h>
  35. #include <kernel/thread.h>
  36. #include <platform/boot_mode.h>
  37. #include <platform/ram_console.h>
  38. #include <mt_gic.h>
  39. #include <arch/arm/mmu.h>
  40. #include "mtk_secure_api.h"
  41. #include <platform.h> // for platform_uninit()
  42. #define TIMER_DUMP_REG 0x10008004
  43. enum {
  44. REG_LR = 18,
  45. REG_SP = 19,
  46. };
  47. struct atf_aee_regs {
  48. unsigned long long regs[31];
  49. unsigned long long sp;
  50. unsigned long long pc;
  51. unsigned long long pstate;
  52. };
  53. static void *atf_aee_debug_addr = NULL;
  54. static void lk_wdt_dump_regs(struct atf_aee_regs *regs)
  55. {
  56. dprintf(CRITICAL, "Dump register from ATF..\n");
  57. dprintf(CRITICAL, "CPSR: 0x%08lx\n", (unsigned long) regs->pstate);
  58. dprintf(CRITICAL, "PC: 0x%08lx\n", (unsigned long) regs->pc);
  59. dprintf(CRITICAL, "SP: 0x%08lx\n", (unsigned long) regs->regs[REG_SP]);
  60. dprintf(CRITICAL, "LR: 0x%08lx\n", (unsigned long) regs->regs[REG_LR]);
  61. if (regs->regs[REG_SP]!= 0) {
  62. unsigned long length, len_ahead = 64;
  63. if (current_thread->stack_size > 0) {
  64. length = (unsigned long)(current_thread->stack + current_thread->stack_size)- (unsigned long)regs->regs[REG_SP] + len_ahead;
  65. if ((length <= len_ahead) || (length > DEFAULT_STACK_SIZE))
  66. length = 4096; //4K
  67. }
  68. else //i.e.: idle thread
  69. length = 384;
  70. dprintf(CRITICAL, "top of stack at 0x%08lx:\n", (unsigned long)regs->regs[REG_SP]);
  71. hexdump((void*)(unsigned long)(regs->regs[REG_SP] - len_ahead), length);
  72. }
  73. dump_target_threads_stack();
  74. #ifdef DUMP_CODE_SECTION
  75. dump_code_section();
  76. #endif
  77. }
  78. static void lk_wdt_dump(void)
  79. {
  80. unsigned int reg;
  81. thread_t *thread = current_thread;
  82. dprintf(CRITICAL, "%s(): watchdog timeout in LK....\n", __func__);
  83. dprintf(CRITICAL, "current_thread = %s\n", thread->name);
  84. ram_console_set_exp_type(AEE_EXP_TYPE_LK_CRASH);
  85. if (atf_aee_debug_addr) {
  86. lk_wdt_dump_regs((struct atf_aee_regs *) atf_aee_debug_addr);
  87. }
  88. mt_irq_register_dump();
  89. reg = DRV_Reg32(TIMER_DUMP_REG);
  90. dprintf(CRITICAL, "timer_dump_reg: 0x%08x\n", reg);
  91. dprintf(CRITICAL, "%s(): finished...\n", __func__);
  92. /* try to flush all cache */
  93. platform_uninit();
  94. #ifdef HAVE_CACHE_PL310
  95. l2_disable();
  96. #endif
  97. arch_disable_cache(UCACHE);
  98. arch_disable_mmu();
  99. /* never return */
  100. platform_halt();
  101. }
  102. void lk_register_wdt_callback(void)
  103. {
  104. #ifndef MACH_FPGA
  105. if (g_boot_arg->boot_mode != DOWNLOAD_BOOT) {
  106. uint32_t start, size;
  107. atf_aee_debug_addr = (void *) mt_secure_call(MTK_SIP_LK_WDT, (unsigned long) &lk_wdt_dump, 0, 0, 0);
  108. start = ROUNDDOWN((uint32_t)atf_aee_debug_addr, PAGE_SIZE);
  109. size = sizeof(struct atf_aee_regs);
  110. size = ROUNDUP(((uint32_t)atf_aee_debug_addr - start + size), PAGE_SIZE);
  111. arch_mmu_map((uint64_t)start, (uint32_t)start,
  112. MMU_MEMORY_TYPE_NORMAL_WRITE_BACK | MMU_MEMORY_AP_P_RW_U_NA, ROUNDUP(size, PAGE_SIZE));
  113. }
  114. #endif
  115. }