platform_debug.c 13 KB

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