blob: 8854e164982c641719788d899c8747036d4f92f9 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/*
2 * Copyright (c) 2018 MediaTek Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files
6 * (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23
24#include <arch/arm/mmu.h>
25#include <dev/aee_platform_debug.h>
26#include <part_interface.h>
27#include <platform/plat_atf_dbg_info.h>
28#include <printf.h>
29#include <stdlib.h>
30
31unsigned int (* plat_dfd20_get)(u64 offset, int *len, CALLBACK dev_write) = NULL;
32unsigned int (* plat_dram_get)(u64 offset, int *len, CALLBACK dev_write) = NULL;
33unsigned int (* plat_cpu_bus_get)(u64 offset, int *len, CALLBACK dev_write) = NULL;
34unsigned int (* plat_spm_data_get)(u64 offset, int *len, CALLBACK dev_write) = NULL;
35unsigned int (* plat_spm_sram_data_get)(u64 offset, int *len, CALLBACK dev_write) = NULL;
36unsigned int (* plat_atf_log_get)(u64 offset, int *len, CALLBACK dev_write) = NULL;
37unsigned int (* plat_atf_crash_get)(u64 offset, int *len, CALLBACK dev_write) = NULL;
38unsigned int (* plat_atf_raw_log_get)(u64 offset, int *len, CALLBACK dev_write) = NULL;
39unsigned int (* plat_atf_rdump_get)(u64 offset, int *len, CALLBACK dev_write) = NULL;
40unsigned int (* plat_hvfs_get)(u64 offset, int *len, CALLBACK dev_write) = NULL;
41#ifdef MTK_TINYSYS_SSPM_SUPPORT
42unsigned int (* plat_sspm_coredump_get)(u64 offset, int *len, CALLBACK dev_write) = NULL;
43unsigned int (* plat_sspm_data_get)(u64 offset, int *len, CALLBACK dev_write) = NULL;
44unsigned int (* plat_sspm_xfile_get)(u64 offset, int *len, CALLBACK dev_write) = NULL;
45unsigned int (* plat_sspm_log_get)(u64 offset, int *len, CALLBACK dev_write) = NULL;
46#endif
47unsigned int (* plat_pllk_last_log_get)(u64 offset, int *len, CALLBACK dev_write) = NULL;
48unsigned int (* plat_dur_lkdump_get)(u64 offset, int *len, CALLBACK dev_write) = NULL;
49unsigned int (* plat_mcdi_get)(u64 offset, int *len, CALLBACK dev_write) = NULL;
50#ifdef MTK_TINYSYS_SCP_SUPPORT
51unsigned int (* plat_scp_coredump_get)(u64 offset, int *len, CALLBACK dev_write) = NULL;
52#endif
53
54/* in case that platform didn't support platform_debug_init() */
55int platform_debug_init(void) __attribute__((weak));
56int platform_debug_init(void)
57{
58 return 0;
59}
60
61int lkdump_debug_init(void)
62{
63 if (g_boot_arg->boot_mode != DOWNLOAD_BOOT)
64 atf_log_init();
65
66 return platform_debug_init();
67}
68
69/* function pointer should be set after platform_debug_init() */
70unsigned int kedump_plat_savelog(int condition, u64 offset, int *len, CALLBACK dev_write)
71{
72 switch (condition) {
73 case AEE_PLAT_DFD20:
74 return (!plat_dfd20_get ? 0 : plat_dfd20_get(offset, len, dev_write));
75 case AEE_PLAT_DRAM:
76 return (!plat_dram_get ? 0 : plat_dram_get(offset, len, dev_write));
77 case AEE_PLAT_CPU_BUS:
78 return (!plat_cpu_bus_get ? 0 : plat_cpu_bus_get(offset, len, dev_write));
79 case AEE_PLAT_SPM_DATA:
80 return (!plat_spm_data_get ? 0 : plat_spm_data_get(offset, len, dev_write));
81 case AEE_PLAT_SPM_SRAM_DATA:
82 return (!plat_spm_sram_data_get ? 0 : plat_spm_sram_data_get(offset, len, dev_write));
83 case AEE_PLAT_ATF_LAST_LOG:
84 return (!plat_atf_log_get ? 0 : plat_atf_log_get(offset, len, dev_write));
85 case AEE_PLAT_ATF_CRASH_REPORT:
86 return (!plat_atf_crash_get ? 0 : plat_atf_crash_get(offset, len, dev_write));
87 case AEE_PLAT_ATF_RAW_LOG:
88 return (!plat_atf_raw_log_get ? 0 : plat_atf_raw_log_get(offset, len, dev_write));
89 case AEE_PLAT_ATF_RDUMP_LOG:
90 return (!plat_atf_rdump_get ? 0 : plat_atf_rdump_get(offset, len, dev_write));
91 case AEE_PLAT_HVFS:
92 return (!plat_hvfs_get ? 0 : plat_hvfs_get(offset, len, dev_write));
93#ifdef MTK_TINYSYS_SSPM_SUPPORT
94 case AEE_PLAT_SSPM_COREDUMP:
95 return (!plat_sspm_coredump_get ? 0 : plat_sspm_coredump_get(offset, len, dev_write));
96 case AEE_PLAT_SSPM_DATA:
97 return (!plat_sspm_data_get ? 0 : plat_sspm_data_get(offset, len, dev_write));
98 case AEE_PLAT_SSPM_XFILE:
99 return (!plat_sspm_xfile_get ? 0 : plat_sspm_xfile_get(offset, len, dev_write));
100 case AEE_PLAT_SSPM_LAST_LOG:
101 return (!plat_sspm_log_get ? 0 : plat_sspm_log_get(offset, len, dev_write));
102#endif
103 case AEE_PLAT_PLLK_LAST_LOG:
104 return (!plat_pllk_last_log_get ? 0 : plat_pllk_last_log_get(offset, len, dev_write));
105 case AEE_PLAT_LOG_DUR_LKDUMP:
106 return (!plat_dur_lkdump_get ? 0 : plat_dur_lkdump_get(offset, len, dev_write));
107 case AEE_PLAT_MCDI_DATA:
108 return (!plat_mcdi_get ? 0 : plat_mcdi_get(offset, len, dev_write));
109#ifdef MTK_TINYSYS_SCP_SUPPORT
110 case AEE_PLAT_SCP_COREDUMP:
111 return (!plat_scp_coredump_get ? 0 : plat_scp_coredump_get(offset, len, dev_write));
112#endif
113 default:
114 break;
115 }
116 return 0;
117}
118
119void mrdump_write_log(u64 offset_dst, void *data, int len)
120{
121 dprintf(CRITICAL, "%s: Enter\n", __func__);
122
123 if ((offset_dst > MRDUMP_EXPDB_DRAM_KLOG_OFFSET) || (offset_dst < MRDUMP_EXPDB_BOTTOM_OFFSET)) {
124 dprintf(CRITICAL, "%s: access not permitted. offset(0x%llx).\n", __func__, offset_dst);
125 return;
126 }
127
128 if ((offset_dst - len) < MRDUMP_EXPDB_BOTTOM_OFFSET) {
129 dprintf(CRITICAL, "%s: log size(0x%x) too big.\n", __func__, len);
130 return;
131 }
132
133 int index = partition_get_index("expdb");
134 part_dev_t *dev = mt_part_get_device();
135 if (index == -1 || dev == NULL) {
136 dprintf(CRITICAL, "%s: no %s partition[%d]\n", __func__, "expdb", index);
137 return;
138 }
139#if defined(MTK_NEW_COMBO_EMMC_SUPPORT) || defined(MTK_TLC_NAND_SUPPORT) || defined(MTK_MLC_NAND_SUPPORT) || defined(MTK_UFS_SUPPORT)
140 int part_id = partition_get_region(index);
141#endif
142 u64 part_size = partition_get_size(index);
143 if (part_size < offset_dst) {
144 dprintf(CRITICAL, "%s: partition size(%llx) is less then reserved (%llx)\n", __func__, part_size, offset_dst);
145 return;
146 }
147 u64 part_offset = partition_get_offset(index) + part_size - offset_dst;
148
149 dprintf(CRITICAL, "%s: offset %lld size %lld\n", __func__, part_offset, part_size);
150
151#if defined(MTK_EMMC_SUPPORT) || defined(MTK_UFS_SUPPORT)
152#if defined(MTK_NEW_COMBO_EMMC_SUPPORT) || defined(MTK_UFS_SUPPORT)
153 dev->write(dev, (uchar *)data, part_offset, len, part_id);
154#else
155 dev->write(dev, (uchar *)data, part_offset, len);
156#endif
157#else
158 dev->write(dev, (uchar *)data, part_offset, len, part_id);
159#endif
160}
161
162void mrdump_read_log(void *data, int len, u64 offset_src)
163{
164 dprintf(CRITICAL, "%s: Enter\n", __func__);
165
166 if ((offset_src > MRDUMP_EXPDB_DRAM_KLOG_OFFSET) || (offset_src < MRDUMP_EXPDB_BOTTOM_OFFSET)) {
167 dprintf(CRITICAL, "%s: access not permitted. offset(0x%llx).\n", __func__, offset_src);
168 return;
169 }
170
171 if ((offset_src - len) < MRDUMP_EXPDB_BOTTOM_OFFSET) {
172 dprintf(CRITICAL, "%s: log size(0x%x) too big.\n", __func__, len);
173 return;
174 }
175
176 int index = partition_get_index("expdb");
177 part_dev_t *dev = mt_part_get_device();
178 if (index == -1 || dev == NULL) {
179 dprintf(CRITICAL, "%s: no %s partition[%d]\n", __func__, "expdb", index);
180 return;
181 }
182#if defined(MTK_NEW_COMBO_EMMC_SUPPORT) || defined(MTK_TLC_NAND_SUPPORT) || defined(MTK_MLC_NAND_SUPPORT) || defined(MTK_UFS_SUPPORT)
183 int part_id = partition_get_region(index);
184#endif
185 u64 part_size = partition_get_size(index);
186 if (part_size < offset_src) {
187 dprintf(CRITICAL, "%s: partition size(%llx) is less then reserved (%llx)\n", __func__, part_size, offset_src);
188 return;
189 }
190 u64 part_offset = partition_get_offset(index) + part_size - offset_src;
191
192 dprintf(CRITICAL, "%s: offset %lld size %lld\n", __func__, part_offset, part_size);
193
194#if defined(MTK_EMMC_SUPPORT) || defined(MTK_UFS_SUPPORT)
195#if defined(MTK_NEW_COMBO_EMMC_SUPPORT) || defined(MTK_UFS_SUPPORT)
196 dev->read(dev, part_offset, (uchar *)data, len, part_id);
197#else
198 dev->read(dev, part_offset, (uchar *)data, len);
199#endif
200#else
201 dev->read(dev, part_offset, (uchar *)data, len, part_id);
202#endif
203}
204
205void mrdump_read_expdb(void *data, int len, u64 offset_src)
206{
207 dprintf(CRITICAL, "%s: Enter\n", __func__);
208
209 int index = partition_get_index("expdb");
210 part_dev_t *dev = mt_part_get_device();
211 if (index == -1 || dev == NULL) {
212 dprintf(CRITICAL, "%s: no %s partition[%d]\n", __func__, "expdb", index);
213 return;
214 }
215#if defined(MTK_NEW_COMBO_EMMC_SUPPORT) || defined(MTK_TLC_NAND_SUPPORT) || defined(MTK_MLC_NAND_SUPPORT) || defined(MTK_UFS_SUPPORT)
216 int part_id = partition_get_region(index);
217#endif
218 u64 part_size = partition_get_size(index);
219 if (part_size < offset_src) {
220 dprintf(CRITICAL, "%s: partition size(%llx) is less then reserved (%llx)\n", __func__, part_size, offset_src);
221 return;
222 }
223 if ((offset_src + len) > (part_size - MRDUMP_EXPDB_DRAM_KLOG_OFFSET)) {
224 dprintf(CRITICAL, "%s: log size(0x%x) too big.\n", __func__, len);
225 return;
226 }
227 u64 part_offset = partition_get_offset(index) + offset_src;
228
229 dprintf(CRITICAL, "%s: offset %lld size %lld\n", __func__, part_offset, part_size);
230
231#if defined(MTK_EMMC_SUPPORT) || defined(MTK_UFS_SUPPORT)
232#if defined(MTK_NEW_COMBO_EMMC_SUPPORT) || defined(MTK_UFS_SUPPORT)
233 dev->read(dev, part_offset, (uchar *)data, len, part_id);
234#else
235 dev->read(dev, part_offset, (uchar *)data, len);
236#endif
237#else
238 dev->read(dev, part_offset, (uchar *)data, len, part_id);
239#endif
240}
241