platform_debug.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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) 2016. 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 <stdlib.h>
  32. #include <dev/aee_platform_debug.h>
  33. #ifdef MTK_GPT_SCHEME_SUPPORT
  34. #include <platform/partition.h>
  35. #else
  36. #include <mt_partition.h>
  37. #endif
  38. #include <printf.h>
  39. #include <arch/arm/mmu.h>
  40. #include <platform/plat_atf_dbg_info.h>
  41. #include <part_interface.h>
  42. unsigned int (* plat_dfd20_get)(u64 offset, int *len, CALLBACK dev_write) = NULL;
  43. unsigned int (* plat_dram_get)(u64 offset, int *len, CALLBACK dev_write) = NULL;
  44. unsigned int (* plat_cpu_bus_get)(u64 offset, int *len, CALLBACK dev_write) = NULL;
  45. unsigned int (* plat_spm_data_get)(u64 offset, int *len, CALLBACK dev_write) = NULL;
  46. unsigned int (* plat_spm_sram_data_get)(u64 offset, int *len, CALLBACK dev_write) = NULL;
  47. unsigned int (* plat_atf_log_get)(u64 offset, int *len, CALLBACK dev_write) = NULL;
  48. unsigned int (* plat_atf_crash_get)(u64 offset, int *len, CALLBACK dev_write) = NULL;
  49. unsigned int (* plat_atf_raw_log_get)(u64 offset, int *len, CALLBACK dev_write) = NULL;
  50. unsigned int (* plat_atf_rdump_get)(u64 offset, int *len, CALLBACK dev_write) = NULL;
  51. unsigned int (* plat_hvfs_get)(u64 offset, int *len, CALLBACK dev_write) = NULL;
  52. #ifdef MTK_TINYSYS_SSPM_SUPPORT
  53. unsigned int (* plat_sspm_coredump_get)(u64 offset, int *len, CALLBACK dev_write) = NULL;
  54. unsigned int (* plat_sspm_data_get)(u64 offset, int *len, CALLBACK dev_write) = NULL;
  55. unsigned int (* plat_sspm_xfile_get)(u64 offset, int *len, CALLBACK dev_write) = NULL;
  56. unsigned int (* plat_sspm_log_get)(u64 offset, int *len, CALLBACK dev_write) = NULL;
  57. #endif
  58. unsigned int (* plat_pllk_last_log_get)(u64 offset, int *len, CALLBACK dev_write) = NULL;
  59. unsigned int (* plat_dur_lkdump_get)(u64 offset, int *len, CALLBACK dev_write) = NULL;
  60. unsigned int (* plat_mcdi_get)(u64 offset, int *len, CALLBACK dev_write) = NULL;
  61. #ifdef MTK_TINYSYS_SCP_SUPPORT
  62. unsigned int (* plat_scp_coredump_get)(u64 offset, int *len, CALLBACK dev_write) = NULL;
  63. #endif
  64. unsigned int (* plat_infra_cg_get)(u64 offset, int *len, CALLBACK dev_write) = NULL;
  65. #ifdef MTK_AUDIODSP_SUPPORT
  66. unsigned int (* plat_adsp_coredump_get)(u64 offset, int *len, CALLBACK dev_write) = NULL;
  67. #endif
  68. #ifdef MTK_TINYSYS_MCUPM_SUPPORT
  69. unsigned int (* plat_mcupm_coredump_get)(u64 offset, int *len, CALLBACK dev_write) = NULL;
  70. unsigned int (* plat_mcupm_data_get)(u64 offset, int *len, CALLBACK dev_write) = NULL;
  71. unsigned int (* plat_mcupm_xfile_get)(u64 offset, int *len, CALLBACK dev_write) = NULL;
  72. unsigned int (* plat_mcupm_log_get)(u64 offset, int *len, CALLBACK dev_write) = NULL;
  73. #endif
  74. #ifdef MTK_PICACHU_SUPPORT
  75. unsigned int (* plat_picachu_log_get)(u64 offset, int *len, CALLBACK dev_write) = NULL;
  76. #endif
  77. /* in case that platform didn't support platform_debug_init() */
  78. int platform_debug_init(void) __attribute__((weak));
  79. int platform_debug_init(void)
  80. {
  81. return 0;
  82. }
  83. int lkdump_debug_init(void)
  84. {
  85. if (g_boot_arg->boot_mode != DOWNLOAD_BOOT)
  86. atf_log_init();
  87. return platform_debug_init();
  88. }
  89. /* function pointer should be set after platform_debug_init() */
  90. unsigned int kedump_plat_savelog(int condition, u64 offset, int *len, CALLBACK dev_write)
  91. {
  92. switch (condition) {
  93. case AEE_PLAT_DFD20:
  94. return (!plat_dfd20_get ? 0 : plat_dfd20_get(offset, len, dev_write));
  95. case AEE_PLAT_DRAM:
  96. return (!plat_dram_get ? 0 : plat_dram_get(offset, len, dev_write));
  97. case AEE_PLAT_CPU_BUS:
  98. return (!plat_cpu_bus_get ? 0 : plat_cpu_bus_get(offset, len, dev_write));
  99. case AEE_PLAT_SPM_DATA:
  100. return (!plat_spm_data_get ? 0 : plat_spm_data_get(offset, len, dev_write));
  101. case AEE_PLAT_SPM_SRAM_DATA:
  102. return (!plat_spm_sram_data_get ? 0 : plat_spm_sram_data_get(offset, len, dev_write));
  103. case AEE_PLAT_ATF_LAST_LOG:
  104. return (!plat_atf_log_get ? 0 : plat_atf_log_get(offset, len, dev_write));
  105. case AEE_PLAT_ATF_CRASH_REPORT:
  106. return (!plat_atf_crash_get ? 0 : plat_atf_crash_get(offset, len, dev_write));
  107. case AEE_PLAT_ATF_RAW_LOG:
  108. return (!plat_atf_raw_log_get ? 0 : plat_atf_raw_log_get(offset, len, dev_write));
  109. case AEE_PLAT_ATF_RDUMP_LOG:
  110. return (!plat_atf_rdump_get ? 0 : plat_atf_rdump_get(offset, len, dev_write));
  111. case AEE_PLAT_HVFS:
  112. return (!plat_hvfs_get ? 0 : plat_hvfs_get(offset, len, dev_write));
  113. #ifdef MTK_TINYSYS_SSPM_SUPPORT
  114. case AEE_PLAT_SSPM_COREDUMP:
  115. return (!plat_sspm_coredump_get ? 0 : plat_sspm_coredump_get(offset, len, dev_write));
  116. case AEE_PLAT_SSPM_DATA:
  117. return (!plat_sspm_data_get ? 0 : plat_sspm_data_get(offset, len, dev_write));
  118. case AEE_PLAT_SSPM_XFILE:
  119. return (!plat_sspm_xfile_get ? 0 : plat_sspm_xfile_get(offset, len, dev_write));
  120. case AEE_PLAT_SSPM_LAST_LOG:
  121. return (!plat_sspm_log_get ? 0 : plat_sspm_log_get(offset, len, dev_write));
  122. #endif
  123. case AEE_PLAT_PLLK_LAST_LOG:
  124. return (!plat_pllk_last_log_get ? 0 : plat_pllk_last_log_get(offset, len, dev_write));
  125. case AEE_PLAT_LOG_DUR_LKDUMP:
  126. return (!plat_dur_lkdump_get ? 0 : plat_dur_lkdump_get(offset, len, dev_write));
  127. case AEE_PLAT_MCDI_DATA:
  128. return (!plat_mcdi_get ? 0 : plat_mcdi_get(offset, len, dev_write));
  129. #ifdef MTK_TINYSYS_SCP_SUPPORT
  130. case AEE_PLAT_SCP_COREDUMP:
  131. return (!plat_scp_coredump_get ? 0 : plat_scp_coredump_get(offset, len, dev_write));
  132. #endif
  133. case AEE_PLAT_INFRA_CG:
  134. return (!plat_infra_cg_get ? 0 : plat_infra_cg_get(offset, len, dev_write));
  135. #ifdef MTK_AUDIODSP_SUPPORT
  136. case AEE_PLAT_ADSP_COREDUMP:
  137. return (!plat_adsp_coredump_get ? 0 : plat_adsp_coredump_get(offset, len, dev_write));
  138. #endif
  139. #ifdef MTK_PICACHU_SUPPORT
  140. case AEE_PLAT_PICACHU_LOG:
  141. return (!plat_picachu_log_get ? 0 : plat_picachu_log_get(offset, len, dev_write));
  142. #endif
  143. default:
  144. break;
  145. }
  146. return 0;
  147. }
  148. void mrdump_write_log(u64 offset_dst, void *data, int len)
  149. {
  150. dprintf(CRITICAL, "%s: Enter\n", __func__);
  151. if ((offset_dst > MRDUMP_EXPDB_DRAM_KLOG_OFFSET) || (offset_dst < MRDUMP_EXPDB_BOTTOM_OFFSET)) {
  152. dprintf(CRITICAL, "%s: access not permitted. offset(0x%llx).\n", __func__, offset_dst);
  153. return;
  154. }
  155. if ((offset_dst - len) < MRDUMP_EXPDB_BOTTOM_OFFSET) {
  156. dprintf(CRITICAL, "%s: log size(0x%x) too big.\n", __func__, len);
  157. return;
  158. }
  159. int index = partition_get_index("expdb");
  160. part_dev_t *dev = mt_part_get_device();
  161. if (index == -1 || dev == NULL) {
  162. dprintf(CRITICAL, "%s: no %s partition[%d]\n", __func__, "expdb", index);
  163. return;
  164. }
  165. #if defined(MTK_NEW_COMBO_EMMC_SUPPORT) || defined(MTK_TLC_NAND_SUPPORT) || defined(MTK_MLC_NAND_SUPPORT) || defined(MTK_UFS_SUPPORT)
  166. int part_id = partition_get_region(index);
  167. #endif
  168. u64 part_size = partition_get_size(index);
  169. if (part_size < offset_dst) {
  170. dprintf(CRITICAL, "%s: partition size(%llx) is less then reserved (%llx)\n", __func__, part_size, offset_dst);
  171. return;
  172. }
  173. u64 part_offset = partition_get_offset(index) + part_size - offset_dst;
  174. dprintf(CRITICAL, "%s: offset %lld size %lld\n", __func__, part_offset, part_size);
  175. #if defined(MTK_EMMC_SUPPORT) || defined(MTK_UFS_SUPPORT)
  176. #if defined(MTK_NEW_COMBO_EMMC_SUPPORT) || defined(MTK_UFS_SUPPORT)
  177. dev->write(dev, (uchar *)data, part_offset, len, part_id);
  178. #else
  179. dev->write(dev, (uchar *)data, part_offset, len);
  180. #endif
  181. #else
  182. dev->write(dev, (uchar *)data, part_offset, len, part_id);
  183. #endif
  184. }
  185. void mrdump_read_log(void *data, int len, u64 offset_src)
  186. {
  187. dprintf(CRITICAL, "%s: Enter\n", __func__);
  188. if ((offset_src > MRDUMP_EXPDB_DRAM_KLOG_OFFSET) || (offset_src < MRDUMP_EXPDB_BOTTOM_OFFSET)) {
  189. dprintf(CRITICAL, "%s: access not permitted. offset(0x%llx).\n", __func__, offset_src);
  190. return;
  191. }
  192. if ((offset_src - len) < MRDUMP_EXPDB_BOTTOM_OFFSET) {
  193. dprintf(CRITICAL, "%s: log size(0x%x) too big.\n", __func__, len);
  194. return;
  195. }
  196. int index = partition_get_index("expdb");
  197. part_dev_t *dev = mt_part_get_device();
  198. if (index == -1 || dev == NULL) {
  199. dprintf(CRITICAL, "%s: no %s partition[%d]\n", __func__, "expdb", index);
  200. return;
  201. }
  202. #if defined(MTK_NEW_COMBO_EMMC_SUPPORT) || defined(MTK_TLC_NAND_SUPPORT) || defined(MTK_MLC_NAND_SUPPORT) || defined(MTK_UFS_SUPPORT)
  203. int part_id = partition_get_region(index);
  204. #endif
  205. u64 part_size = partition_get_size(index);
  206. if (part_size < offset_src) {
  207. dprintf(CRITICAL, "%s: partition size(%llx) is less then reserved (%llx)\n", __func__, part_size, offset_src);
  208. return;
  209. }
  210. u64 part_offset = partition_get_offset(index) + part_size - offset_src;
  211. dprintf(CRITICAL, "%s: offset %lld size %lld\n", __func__, part_offset, part_size);
  212. #if defined(MTK_EMMC_SUPPORT) || defined(MTK_UFS_SUPPORT)
  213. #if defined(MTK_NEW_COMBO_EMMC_SUPPORT) || defined(MTK_UFS_SUPPORT)
  214. dev->read(dev, part_offset, (uchar *)data, len, part_id);
  215. #else
  216. dev->read(dev, part_offset, (uchar *)data, len);
  217. #endif
  218. #else
  219. dev->read(dev, part_offset, (uchar *)data, len, part_id);
  220. #endif
  221. }
  222. void mrdump_read_expdb(void *data, int len, u64 offset_src)
  223. {
  224. dprintf(CRITICAL, "%s: Enter\n", __func__);
  225. int index = partition_get_index("expdb");
  226. part_dev_t *dev = mt_part_get_device();
  227. if (index == -1 || dev == NULL) {
  228. dprintf(CRITICAL, "%s: no %s partition[%d]\n", __func__, "expdb", index);
  229. return;
  230. }
  231. #if defined(MTK_NEW_COMBO_EMMC_SUPPORT) || defined(MTK_TLC_NAND_SUPPORT) || defined(MTK_MLC_NAND_SUPPORT) || defined(MTK_UFS_SUPPORT)
  232. int part_id = partition_get_region(index);
  233. #endif
  234. u64 part_size = partition_get_size(index);
  235. if (part_size < offset_src) {
  236. dprintf(CRITICAL, "%s: partition size(%llx) is less then reserved (%llx)\n", __func__, part_size, offset_src);
  237. return;
  238. }
  239. if ((offset_src + len) > (part_size - MRDUMP_EXPDB_DRAM_KLOG_OFFSET)) {
  240. dprintf(CRITICAL, "%s: log size(0x%x) too big.\n", __func__, len);
  241. return;
  242. }
  243. u64 part_offset = partition_get_offset(index) + offset_src;
  244. dprintf(CRITICAL, "%s: offset %lld size %lld\n", __func__, part_offset, part_size);
  245. #if defined(MTK_EMMC_SUPPORT) || defined(MTK_UFS_SUPPORT)
  246. #if defined(MTK_NEW_COMBO_EMMC_SUPPORT) || defined(MTK_UFS_SUPPORT)
  247. dev->read(dev, part_offset, (uchar *)data, len, part_id);
  248. #else
  249. dev->read(dev, part_offset, (uchar *)data, len);
  250. #endif
  251. #else
  252. dev->read(dev, part_offset, (uchar *)data, len, part_id);
  253. #endif
  254. }