xf.li | 3dd5374 | 2024-09-27 00:06:23 -0700 | [diff] [blame] | 1 | /** |
| 2 | * @file oss_ramdump_osa.c |
| 3 | * @brief Implementation of Ramdump os adapt |
| 4 | * |
| 5 | * Copyright (C) 2017 Sanechips Technology Co., Ltd. |
| 6 | * @author Qing Wang <wang.qing@sanechips.com.cn> |
| 7 | * @ingroup si_ap_oss_ramdump_id |
| 8 | * |
| 9 | * SPDX-License-Identifier: Apache-2.0 |
| 10 | * |
| 11 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 12 | * not use this file except in compliance with the License. |
| 13 | * You may obtain a copy of the License at |
| 14 | * |
| 15 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 16 | * |
| 17 | * Unless required by applicable law or agreed to in writing, software |
| 18 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 19 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 20 | * See the License for the specific language governing permissions and |
| 21 | * limitations under the License. |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | /******************************************************************************* |
| 26 | * Include header files * |
| 27 | ******************************************************************************/ |
| 28 | #include "ramdump.h" |
| 29 | #include <linux/lzo.h> |
| 30 | #include "ramdump_compress.h" |
| 31 | #ifdef CONFIG_RAMDUMP_EMMC |
| 32 | #include "ramdump_emmc.h" |
| 33 | #endif |
| 34 | #ifdef CONFIG_MTD_SPI_NAND |
| 35 | #include "ramdump_spinand.h" |
| 36 | #endif |
| 37 | |
| 38 | #ifdef __cplusplus |
| 39 | extern "C" { |
| 40 | #endif |
| 41 | |
| 42 | /******************************************************************************* |
| 43 | * Extern function declarations * |
| 44 | *******************************************************************************/ |
| 45 | extern unsigned char *ramdump_phy_to_vir(unsigned long phy, unsigned long size); |
| 46 | extern int dump_printk_text(char *buffer, unsigned long len); |
| 47 | |
| 48 | /******************************************************************************* |
| 49 | * Extern variable declarations * |
| 50 | *******************************************************************************/ |
| 51 | extern unsigned int ramdump_compress_flag; |
| 52 | extern unsigned char *ramdump_log_buf; |
| 53 | extern unsigned int ramdump_export_mode; |
| 54 | |
| 55 | /******************************************************************************* |
| 56 | * Macro definitions * |
| 57 | ******************************************************************************/ |
| 58 | /*Ö¸ÁîÖ¡³¤¶È */ |
| 59 | #define RAMDUMP_INTERACTIVE_DATA_LEN 40 |
| 60 | #define RAMDUMP_INTERACTIVE_ARRAY_LEN 10 |
| 61 | |
| 62 | /* ramdump ºÍ ¹²ÏíÄÚ´æ½»»¥ÃüÁîÔ¼¶¨ */ |
| 63 | /*ͬ²½ÇëÇó*/ |
| 64 | #define RAMDUMP_PC_INTERACTIVE_REQ 1 |
| 65 | /*ͬ²½ÇëÇóÓ¦´ð,´«ÊäramdumpµÄÎļþÊýÄ¿*/ |
| 66 | #define RAMDUMP_TRANS_SERVER_INTERACTIVE_RSP 2 |
| 67 | /*ÇëÇó´«µÝÖ¸¶¨Îļþ±àºÅµÄÎļþÐÅÏ¢*/ |
| 68 | #define RAMDUMP_PC_FILE_INFO_READ_REQ 3 |
| 69 | /*ÇëÇó´«µÝÖ¸¶¨Îļþ±àºÅµÄÎļþÐÅÏ¢µÄÓ¦´ð£¬´«ÊäÎļþÃû¼°´óС*/ |
| 70 | #define RAMDUMP_TRANS_SERVER_FILE_INFO_READ_RSP 4 |
| 71 | /*ÇëÇó¶Áȡָ¶¨Îļþ±àºÅµÄÎļþÄÚÈÝ*/ |
| 72 | #define RAMDUMP_PC_FILE_DATA_TRANS_REQ 5 |
| 73 | /*ÇëÇó¶Áȡָ¶¨Îļþ±àºÅµÄÎļþÄÚÈݵÄÓ¦´ð£¬´«ÊäÎļþÄÚÈÝ*/ |
| 74 | #define RAMDUMP_TRANS_SERVER_FILE_DATA_TRANS_RSP 6 |
| 75 | /*´«Êä½áÊø*/ |
| 76 | #define RAMDUMP_PC_FILE_TRANS_DONE_REQ 7 |
| 77 | /*´«Êä½áÊøÓ¦´ð*/ |
| 78 | #define RAMDUMP_TRANS_SERVER_FILE_TRANS_DONE_RSP 8 |
| 79 | |
| 80 | /* ´íÎóÀàÐÍ */ |
| 81 | /*Ö¸Áî´íÎó*/ |
| 82 | #define RAMDUMP_INTERACTIVE_CMD_ERROR 9 |
| 83 | /*ÇëÇó´«µÝÖ¸¶¨Îļþ±àºÅ´í*/ |
| 84 | #define RAMDUMP_FILE_NUMBER_ERROR 10 |
| 85 | /*ÇëÇó´«µÝÖ¸¶¨ÎļþλÖôóС´í*/ |
| 86 | #define RAMDUMP_FILE_SIZE_ERROR 11 |
| 87 | |
| 88 | #define RAMDUMP_DELAY_MS_COUNT (2500) |
| 89 | |
| 90 | /******************************************************************************* |
| 91 | * Type definitions * |
| 92 | ******************************************************************************/ |
| 93 | /* |
| 94 | * struct TRANS WITH AP |
| 95 | */ |
| 96 | |
| 97 | /* trans_server rsp pc, interactive msg struct */ |
| 98 | typedef struct |
| 99 | { |
| 100 | unsigned int cmd; |
| 101 | unsigned int file_num; |
| 102 | } ramdump_trans_server_interactive_req; |
| 103 | |
| 104 | /* trans_server rsp pc, file info msg struct */ |
| 105 | typedef struct |
| 106 | { |
| 107 | unsigned int cmd; |
| 108 | char file_name[RAMDUMP_RAMCONF_FILENAME_MAXLEN]; |
| 109 | unsigned int file_size; |
| 110 | } ramdump_trans_server_file_info_req; |
| 111 | |
| 112 | /* pc req trans_server, file info msg struct */ |
| 113 | typedef struct |
| 114 | { |
| 115 | unsigned int cmd; |
| 116 | unsigned int file_id; |
| 117 | } ramdump_pc_file_info_rsp; |
| 118 | |
| 119 | /* trans_server rsp pc, trans data msg struct */ |
| 120 | typedef struct |
| 121 | { |
| 122 | unsigned int cmd; |
| 123 | unsigned int buf_addr; |
| 124 | unsigned int buf_left_size; |
| 125 | } ramdump_trans_server_data_trans_req; |
| 126 | |
| 127 | /* pc req trans_server, trans data msg struct */ |
| 128 | typedef struct |
| 129 | { |
| 130 | unsigned int cmd; |
| 131 | unsigned int file_id; /* Îļþ±àºÅ */ |
| 132 | unsigned int offset; /* offsetΪÊý¾ÝÆ«ÒÆ */ |
| 133 | unsigned int length; /* lengthΪÊý¾Ý³¤¶È */ |
| 134 | } ramdump_pc_trans_data_rsp; |
| 135 | |
| 136 | /******************************************************************************* |
| 137 | * Local function declarations * |
| 138 | ******************************************************************************/ |
| 139 | |
| 140 | /******************************************************************************* |
| 141 | * Local variable definitions * |
| 142 | ******************************************************************************/ |
| 143 | char *ramdump_log_buf_region = NULL; |
| 144 | unsigned int ramdump_log_buf_len = 0; |
| 145 | |
| 146 | /******************************************************************************* |
| 147 | * Global variable definitions * |
| 148 | ******************************************************************************/ |
| 149 | unsigned char *ramdump_shared_mem_base = NULL; |
| 150 | unsigned char *ramdump_export_flag_base = NULL; |
| 151 | int ramdump_file_num = 0; |
| 152 | ramdump_file_t ramdump_device_fp = {0}; |
| 153 | ramdump_file_t ramdump_spinand_fp = {0}; |
| 154 | ramdump_file_t *g_ramdump_dev_fp; |
| 155 | unsigned int ramdump_device_file_cnt = 0; |
| 156 | unsigned char *ramdump_log_buf = NULL; /* ¸´ÓÃramdump´æ´¢µÄ128KB(Æ«ÒÆ16KB) */ |
| 157 | |
| 158 | /******************************************************************************* |
| 159 | * Inline function implementations * |
| 160 | ******************************************************************************/ |
| 161 | static inline void ramdump_wait_delay( unsigned long ms) |
| 162 | { |
| 163 | volatile int j = 0; |
| 164 | for (j = 0; j < 10000; j++); |
| 165 | } |
| 166 | /******************************************************************************* |
| 167 | * extern function implementations * |
| 168 | ******************************************************************************/ |
| 169 | |
| 170 | /******************************************************************************* |
| 171 | * ¹¦ÄÜÃèÊö: ramdump_oss_data_trans_write |
| 172 | * ²ÎÊý˵Ã÷: |
| 173 | * (´«Èë²ÎÊý) void |
| 174 | * (´«³ö²ÎÊý) void |
| 175 | * ·µ »Ø Öµ: void |
| 176 | * ÆäËü˵Ã÷: This function is used for ramdump to trans dump data to PC |
| 177 | *******************************************************************************/ |
| 178 | int ramdump_oss_data_trans_write(unsigned char *buffer, unsigned int size) |
| 179 | { |
| 180 | int ret; |
| 181 | ramdump_shmem_t *msg = (ramdump_shmem_t *)ramdump_shared_mem_base; |
| 182 | |
| 183 | if (size > (RAMDUMP_SHARED_MEM_LEN- roundup(sizeof(ramdump_shmem_t), RAMDUMP_SHMEM_ALIGN_SIZE))); |
| 184 | ret = -1; |
| 185 | |
| 186 | while(1){ |
| 187 | if ((msg->core_flag == 1) && (msg->rw_flag == 1)){ |
| 188 | memcpy(msg->buf, buffer, size); |
| 189 | msg->size = size; |
| 190 | msg->core_flag = 0; |
| 191 | msg->rw_flag = 2; |
| 192 | ret = size; |
| 193 | break; |
| 194 | } |
| 195 | else |
| 196 | ramdump_wait_delay(0); |
| 197 | } |
| 198 | return ret; |
| 199 | } |
| 200 | |
| 201 | /******************************************************************************* |
| 202 | * ¹¦ÄÜÃèÊö: ramdump_oss_data_trans_read |
| 203 | * ²ÎÊý˵Ã÷: |
| 204 | * (´«Èë²ÎÊý) void |
| 205 | * (´«³ö²ÎÊý) void |
| 206 | * ·µ »Ø Öµ: void |
| 207 | * ÆäËü˵Ã÷: This function is used for ramdump to trans dump data to PC |
| 208 | *******************************************************************************/ |
| 209 | int ramdump_oss_data_trans_read(unsigned char *buffer, unsigned int size) |
| 210 | { |
| 211 | int ret; |
| 212 | ramdump_shmem_t *msg = (ramdump_shmem_t *)ramdump_shared_mem_base; |
| 213 | |
| 214 | if (size > (RAMDUMP_SHARED_MEM_LEN - roundup(sizeof(ramdump_shmem_t), RAMDUMP_SHMEM_ALIGN_SIZE))) |
| 215 | ret = -1; |
| 216 | |
| 217 | while(1){ |
| 218 | if ((msg->core_flag == 1) && (msg->rw_flag == 2)){ |
| 219 | if (size < msg->size) |
| 220 | return -1; |
| 221 | memcpy(buffer, msg->buf, msg->size); |
| 222 | msg->size = size; |
| 223 | msg->core_flag = 1; |
| 224 | msg->rw_flag = 1; |
| 225 | ret = size; |
| 226 | break; |
| 227 | } |
| 228 | else |
| 229 | ramdump_wait_delay(0); |
| 230 | } |
| 231 | return ret; |
| 232 | } |
| 233 | |
| 234 | /******************************************************************************* |
| 235 | * ¹¦ÄÜÃèÊö: ramdump_oss_data_trans_init |
| 236 | * ²ÎÊý˵Ã÷: |
| 237 | * (´«Èë²ÎÊý) void |
| 238 | * (´«³ö²ÎÊý) void |
| 239 | * ·µ »Ø Öµ: void |
| 240 | * ÆäËü˵Ã÷: This function is used for map ramdump_shared_mem_base |
| 241 | *******************************************************************************/ |
| 242 | void ramdump_oss_data_trans_init(void) |
| 243 | { |
| 244 | ramdump_shmem_t *msg = (ramdump_shmem_t *)ramdump_shared_mem_base; |
| 245 | |
| 246 | memset(msg, 0, sizeof(ramdump_shmem_t)); |
| 247 | msg->core_flag = 1; |
| 248 | msg->rw_flag = 1; |
| 249 | } |
| 250 | |
| 251 | /******************************************************************************* |
| 252 | * ¹¦ÄÜÃèÊö: ramdump_device_init |
| 253 | * ²ÎÊý˵Ã÷: |
| 254 | * (´«Èë²ÎÊý) void |
| 255 | * (´«³ö²ÎÊý) void |
| 256 | * ·µ »Ø Öµ: void |
| 257 | * ÆäËü˵Ã÷: This function is used for init fp head |
| 258 | *******************************************************************************/ |
| 259 | int ramdump_device_init(void) |
| 260 | { |
| 261 | int ret = 0; |
| 262 | |
| 263 | ramdump_lzo_init(); |
| 264 | if(ramdump_export_mode == RAMDUMP_MODE_EMMC) |
| 265 | { |
| 266 | #ifdef CONFIG_RAMDUMP_EMMC |
| 267 | ret = ramdump_emmc_init(&ramdump_device_fp); |
| 268 | #endif |
| 269 | g_ramdump_dev_fp = &ramdump_device_fp; |
| 270 | } |
| 271 | else if(ramdump_export_mode == RAMDUMP_MODE_SPINAND) |
| 272 | { |
| 273 | #ifdef CONFIG_MTD_SPI_NAND |
| 274 | ret = ramdump_spinand_init(&ramdump_spinand_fp); |
| 275 | #endif |
| 276 | g_ramdump_dev_fp = &ramdump_spinand_fp; |
| 277 | } |
| 278 | return ret; |
| 279 | } |
| 280 | |
| 281 | /******************************************************************************* |
| 282 | * ¹¦ÄÜÃèÊö: ramdump_device_close |
| 283 | * ²ÎÊý˵Ã÷: |
| 284 | * (´«Èë²ÎÊý) void |
| 285 | * (´«³ö²ÎÊý) void |
| 286 | * ·µ »Ø Öµ: void |
| 287 | * ÆäËü˵Ã÷: This function is used for print close msg |
| 288 | *******************************************************************************/ |
| 289 | void ramdump_device_close(void) |
| 290 | { |
| 291 | if(ramdump_export_mode == RAMDUMP_MODE_EMMC) |
| 292 | { |
| 293 | #ifdef CONFIG_RAMDUMP_EMMC |
| 294 | ramdump_emmc_close(&ramdump_device_fp); |
| 295 | #endif |
| 296 | } |
| 297 | else if (ramdump_export_mode == RAMDUMP_MODE_SPINAND) |
| 298 | { |
| 299 | #ifdef CONFIG_MTD_SPI_NAND |
| 300 | ramdump_spinand_close(&ramdump_spinand_fp); |
| 301 | #endif |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | /******************************************************************************* |
| 306 | * ¹¦ÄÜÃèÊö: ramdump_fill_header |
| 307 | * ²ÎÊý˵Ã÷: |
| 308 | * (´«Èë²ÎÊý) |
| 309 | * (´«³ö²ÎÊý) void |
| 310 | * ·µ »Ø Öµ: void |
| 311 | * ÆäËü˵Ã÷: This function is used for ramdump file header |
| 312 | *******************************************************************************/ |
| 313 | int ramdump_fill_header(char *file_name, unsigned int file_size, ramdump_file_t *fp, unsigned int offset) |
| 314 | { |
| 315 | if (ramdump_device_file_cnt >= RAMDUMP_FILE_NUM_MAX) |
| 316 | return -1; |
| 317 | |
| 318 | fp->file_fp[ramdump_device_file_cnt].magic = 0x3A3A3A3A; |
| 319 | strncpy(fp->file_fp[ramdump_device_file_cnt].file_name, file_name, RAMDUMP_RAMCONF_FILENAME_MAXLEN - 1); |
| 320 | fp->file_fp[ramdump_device_file_cnt].offset = offset; |
| 321 | fp->file_fp[ramdump_device_file_cnt].size = file_size; |
| 322 | return 0; |
| 323 | } |
| 324 | |
| 325 | /******************************************************************************* |
| 326 | * ¹¦ÄÜÃèÊö: ramdump_device_write_file |
| 327 | * ²ÎÊý˵Ã÷: |
| 328 | * (´«Èë²ÎÊý) void |
| 329 | * (´«³ö²ÎÊý) void |
| 330 | * ·µ »Ø Öµ: void |
| 331 | * ÆäËü˵Ã÷: This function is used for write file infomation |
| 332 | *******************************************************************************/ |
| 333 | int ramdump_device_write_file(ramdump_trans_server_file_info_req *server_to_cap) |
| 334 | { |
| 335 | int ret = -1; |
| 336 | |
| 337 | if(ramdump_export_mode == RAMDUMP_MODE_EMMC) |
| 338 | { |
| 339 | #ifdef CONFIG_RAMDUMP_EMMC |
| 340 | if (ramdump_emmc_offset >= RAMDUMP_TRANS_EMMC_LEN) |
| 341 | return -1; |
| 342 | |
| 343 | ret = ramdump_fill_header(server_to_cap->file_name, |
| 344 | server_to_cap->file_size, |
| 345 | &ramdump_device_fp, |
| 346 | ramdump_emmc_offset); |
| 347 | #endif |
| 348 | } |
| 349 | else if(ramdump_export_mode == RAMDUMP_MODE_SPINAND) |
| 350 | { |
| 351 | #ifdef CONFIG_MTD_SPI_NAND |
| 352 | if (ramdump_spinand_offset >= RAMDUMP_SPINAND_LEN) |
| 353 | return -1; |
| 354 | |
| 355 | ret = ramdump_fill_header(server_to_cap->file_name, |
| 356 | server_to_cap->file_size, |
| 357 | &ramdump_spinand_fp, |
| 358 | ramdump_spinand_offset); |
| 359 | #endif |
| 360 | } |
| 361 | return ret; |
| 362 | } |
| 363 | |
| 364 | /******************************************************************************* |
| 365 | * ¹¦ÄÜÃèÊö: ramdump_device_write_file |
| 366 | * ²ÎÊý˵Ã÷: |
| 367 | * (´«Èë²ÎÊý) fp£º Îļþ¾ä±ú |
| 368 | * (´«³ö²ÎÊý) file_size Îļþ´óС |
| 369 | * ·µ »Ø Öµ: ³É¹¦·µ»Ø0£¬Ê§°Ü·µ»Ø-1 |
| 370 | * ÆäËü˵Ã÷: This function is used for write file infomation |
| 371 | *******************************************************************************/ |
| 372 | int ramdump_device_modify_file_size(ssize_t file_size) |
| 373 | { |
| 374 | int ret = -1; |
| 375 | ramdump_file_t *fp = g_ramdump_dev_fp; |
| 376 | |
| 377 | if(fp) |
| 378 | { |
| 379 | fp->file_fp[ramdump_device_file_cnt].size = file_size; |
| 380 | return 0; |
| 381 | } |
| 382 | return ret; |
| 383 | } |
| 384 | |
| 385 | /******************************************************************************* |
| 386 | * ¹¦ÄÜÃèÊö: ramdump_device_write_file_head |
| 387 | * ²ÎÊý˵Ã÷: |
| 388 | * (´«Èë²ÎÊý) void |
| 389 | * (´«³ö²ÎÊý) void |
| 390 | * ·µ »Ø Öµ: void |
| 391 | * ÆäËü˵Ã÷: This function is used for write file head |
| 392 | *******************************************************************************/ |
| 393 | int ramdump_device_write_file_head(void) |
| 394 | { |
| 395 | int ret = -1; |
| 396 | |
| 397 | if(ramdump_export_mode == RAMDUMP_MODE_EMMC) |
| 398 | { |
| 399 | #ifdef CONFIG_RAMDUMP_EMMC |
| 400 | ret = ramdump_emmc_write_file_head(&ramdump_device_fp); |
| 401 | #endif |
| 402 | } |
| 403 | else if(ramdump_export_mode == RAMDUMP_MODE_SPINAND) |
| 404 | { |
| 405 | #ifdef CONFIG_MTD_SPI_NAND |
| 406 | ret = ramdump_spinand_write_file_head(&ramdump_spinand_fp); |
| 407 | #endif |
| 408 | } |
| 409 | return ret; |
| 410 | } |
| 411 | |
| 412 | int ramdump_do_write_log_txt(ramdump_file_t *fp) |
| 413 | { |
| 414 | int ret = -1; |
| 415 | size_t dst_len = 0; |
| 416 | size_t send_len = 0; |
| 417 | ramdump_shmem_t *msg = (ramdump_shmem_t *)ramdump_shared_mem_base; |
| 418 | char *buf = NULL; |
| 419 | |
| 420 | memset(ramdump_log_buf, 0, RAMDUMP_LOG_BUF); |
| 421 | ret = dump_printk_text(ramdump_log_buf, RAMDUMP_LOG_BUF); |
| 422 | if(ret < 0){ |
| 423 | printk("ramdump printk log buf failed!!\n"); |
| 424 | return ret; |
| 425 | } |
| 426 | if (ramdump_compress_flag == 1){ |
| 427 | ret = ramdump_lzo_compress(ramdump_log_buf, RAMDUMP_LOG_BUF, msg->buf, &dst_len); |
| 428 | buf = msg->buf; |
| 429 | } |
| 430 | if (ret != LZO_E_OK){ |
| 431 | dst_len = RAMDUMP_LOG_BUF; |
| 432 | buf = ramdump_log_buf; |
| 433 | } |
| 434 | fp->file_num += 1; |
| 435 | fp->file_fp[ramdump_device_file_cnt].magic = 0x3A3A3A3A; |
| 436 | strncpy(fp->file_fp[ramdump_device_file_cnt].file_name, "cap_log_buf.txt", RAMDUMP_RAMCONF_FILENAME_MAXLEN - 1); |
| 437 | |
| 438 | if (fp == &ramdump_device_fp) |
| 439 | { |
| 440 | #ifdef CONFIG_RAMDUMP_EMMC |
| 441 | fp->file_fp[ramdump_device_file_cnt].size = roundup(dst_len, RAMDUMP_EMMC_ALIGN_SIZE); |
| 442 | fp->file_fp[ramdump_device_file_cnt].offset = ramdump_emmc_offset; |
| 443 | ret = mmc_bwrite(RAMDUMP_EMMC_ADDR + ramdump_emmc_offset, dst_len, buf); |
| 444 | ramdump_emmc_write_file_head(fp); |
| 445 | ramdump_emmc_offset = ramdump_emmc_offset + roundup(dst_len, RAMDUMP_EMMC_ALIGN_SIZE); |
| 446 | #endif |
| 447 | } |
| 448 | else if (fp == &ramdump_spinand_fp) |
| 449 | { |
| 450 | #ifdef CONFIG_MTD_SPI_NAND |
| 451 | send_len = roundup(dst_len, RAMDUMP_FLASH_ALIGN_SIZE); |
| 452 | fp->file_fp[ramdump_device_file_cnt].size = send_len; |
| 453 | fp->file_fp[ramdump_device_file_cnt].offset = ramdump_spinand_offset; |
| 454 | ret = write_data(RAMDUMP_SPINAND_ADDR + ramdump_spinand_offset, send_len, buf); |
| 455 | ramdump_spinand_offset = ramdump_spinand_offset + send_len; |
| 456 | #endif |
| 457 | } |
| 458 | else |
| 459 | { |
| 460 | printk("ramdump_do_write_logbuf error fp!\n"); |
| 461 | return -1; |
| 462 | } |
| 463 | ramdump_device_file_cnt += 1; |
| 464 | return ret; |
| 465 | } |
| 466 | |
| 467 | int ramdump_do_write_logbuf(ramdump_file_t *fp) |
| 468 | { |
| 469 | char *buf = NULL; |
| 470 | int ret = -1; |
| 471 | size_t dst_len = 0; |
| 472 | size_t send_len = 0; |
| 473 | ramdump_shmem_t *msg = (ramdump_shmem_t *)ramdump_shared_mem_base; |
| 474 | |
| 475 | if(!fp) |
| 476 | { |
| 477 | printk("ramdump_do_write_logbuf error: fp is Null\n"); |
| 478 | return -1; |
| 479 | } |
| 480 | |
| 481 | ramdump_log_buf_region = log_buf_addr_get(); |
| 482 | ramdump_log_buf_len = log_buf_len_get(); |
| 483 | |
| 484 | if (ramdump_compress_flag == 1){ |
| 485 | ret = ramdump_lzo_compress(ramdump_log_buf_region, ramdump_log_buf_len, msg->buf, &dst_len); |
| 486 | buf = msg->buf; |
| 487 | } |
| 488 | if (ret != LZO_E_OK){ |
| 489 | dst_len = ramdump_log_buf_len; |
| 490 | buf = ramdump_log_buf_region; |
| 491 | } |
| 492 | |
| 493 | fp->file_num += 1; |
| 494 | fp->file_fp[ramdump_device_file_cnt].magic = 0x3A3A3A3A; |
| 495 | strncpy(fp->file_fp[ramdump_device_file_cnt].file_name, "cap_log_buf.bin", RAMDUMP_RAMCONF_FILENAME_MAXLEN - 1); |
| 496 | |
| 497 | if (fp == &ramdump_device_fp) |
| 498 | { |
| 499 | #ifdef CONFIG_RAMDUMP_EMMC |
| 500 | fp->file_fp[ramdump_device_file_cnt].size = roundup(dst_len, RAMDUMP_EMMC_ALIGN_SIZE); |
| 501 | ret = mmc_bwrite(RAMDUMP_EMMC_ADDR + ramdump_emmc_offset, dst_len, buf); |
| 502 | fp->file_fp[ramdump_device_file_cnt].offset = ramdump_emmc_offset; |
| 503 | ramdump_emmc_write_file_head(fp); |
| 504 | ramdump_emmc_offset = ramdump_emmc_offset + roundup(dst_len, RAMDUMP_EMMC_ALIGN_SIZE); |
| 505 | #endif |
| 506 | } |
| 507 | else if (fp == &ramdump_spinand_fp) |
| 508 | { |
| 509 | #ifdef CONFIG_MTD_SPI_NAND |
| 510 | send_len = roundup(dst_len, RAMDUMP_FLASH_ALIGN_SIZE); |
| 511 | fp->file_fp[ramdump_device_file_cnt].size = send_len; |
| 512 | fp->file_fp[ramdump_device_file_cnt].offset = ramdump_spinand_offset; |
| 513 | ret = write_data(RAMDUMP_SPINAND_ADDR + ramdump_spinand_offset, send_len, buf); |
| 514 | ramdump_spinand_offset = ramdump_spinand_offset + send_len; |
| 515 | #endif |
| 516 | } |
| 517 | else |
| 518 | { |
| 519 | printk("ramdump_do_write_logbuf error fp!\n"); |
| 520 | return -1; |
| 521 | } |
| 522 | |
| 523 | ramdump_device_file_cnt += 1; |
| 524 | ramdump_do_write_log_txt(fp); |
| 525 | |
| 526 | return ret; |
| 527 | } |
| 528 | |
| 529 | /******************************************************************************* |
| 530 | * ¹¦ÄÜÃèÊö: ramdump_device_write_logbuf |
| 531 | * ²ÎÊý˵Ã÷: |
| 532 | * (´«Èë²ÎÊý) void |
| 533 | * (´«³ö²ÎÊý) void |
| 534 | * ·µ »Ø Öµ: void |
| 535 | * ÆäËü˵Ã÷: This function is used for write cap logbuf |
| 536 | *******************************************************************************/ |
| 537 | int ramdump_device_write_logbuf(void) |
| 538 | { |
| 539 | int ret = -1; |
| 540 | |
| 541 | ret = ramdump_do_write_logbuf(g_ramdump_dev_fp); |
| 542 | if (ret < 0) |
| 543 | ramdump_printf("device memory trans file:cap_log_buf error!!!\n"); |
| 544 | else |
| 545 | ramdump_printf("device memory trans file:cap_log_buf success!!!\n"); |
| 546 | return ret; |
| 547 | } |
| 548 | |
| 549 | /******************************************************************************* |
| 550 | * ¹¦ÄÜÃèÊö: ramdump_device_write_data |
| 551 | * ²ÎÊý˵Ã÷: |
| 552 | * (´«Èë²ÎÊý) void |
| 553 | * (´«³ö²ÎÊý) void |
| 554 | * ·µ »Ø Öµ: void |
| 555 | * ÆäËü˵Ã÷: This function is used for write data |
| 556 | *******************************************************************************/ |
| 557 | int ramdump_device_write_data(ramdump_shmem_t *msg, unsigned int size, ssize_t *dstlen) |
| 558 | { |
| 559 | int ret = 0; |
| 560 | |
| 561 | if(ramdump_export_mode == RAMDUMP_MODE_EMMC) |
| 562 | { |
| 563 | #ifdef CONFIG_RAMDUMP_EMMC |
| 564 | ret = ramdump_emmc_write_data(msg, &ramdump_device_fp, size); |
| 565 | if(ret < 0) |
| 566 | *dstlen = 0; |
| 567 | else |
| 568 | *dstlen += roundup(ret, RAMDUMP_EMMC_ALIGN_SIZE); |
| 569 | #endif |
| 570 | } |
| 571 | else if(ramdump_export_mode == RAMDUMP_MODE_SPINAND) |
| 572 | { |
| 573 | #ifdef CONFIG_MTD_SPI_NAND |
| 574 | ret = ramdump_spinand_write_data(msg, &ramdump_spinand_fp, size); |
| 575 | if(ret < 0) |
| 576 | *dstlen = 0; |
| 577 | else |
| 578 | *dstlen += ret; |
| 579 | #endif |
| 580 | } |
| 581 | else |
| 582 | return 0; |
| 583 | return ret; |
| 584 | } |
| 585 | |
| 586 | /******************************************************************************* |
| 587 | * Global function implementations * |
| 588 | ******************************************************************************/ |
| 589 | void ramdump_shared_mem_init(void) |
| 590 | { |
| 591 | ramdump_shared_mem_base = ramdump_phy_to_vir((unsigned long)RAMDUMP_SHARED_MEM_BASE, (unsigned long)RAMDUMP_MEM_LEN); |
| 592 | ramdump_export_flag_base = ramdump_phy_to_vir((unsigned long)IRAM_BASE_ADDR_RAMDUMP_MODE, sizeof(unsigned long)); |
| 593 | ramdump_log_buf = ramdump_shared_mem_base + 0x4000; |
| 594 | ramdump_flash_alloc_transbuf(); |
| 595 | } |
| 596 | |
| 597 | /******************************************************************************* |
| 598 | * ¹¦ÄÜÃèÊö: ramdump_data_transfer_to_device |
| 599 | * ²ÎÊý˵Ã÷: |
| 600 | * (´«Èë²ÎÊý) void |
| 601 | * (´«³ö²ÎÊý) void |
| 602 | * ·µ »Ø Öµ: void |
| 603 | * ÆäËü˵Ã÷: This function is used for ramdump to trans dump data to ap |
| 604 | *******************************************************************************/ |
| 605 | void ramdump_data_transfer_to_device(void) |
| 606 | { |
| 607 | int data_trans_max; |
| 608 | int file_cnt = 0; |
| 609 | int file_size = 0; |
| 610 | int file_offset = 0; |
| 611 | int file_left_size = 0; |
| 612 | int file_trans_size = 0; |
| 613 | int error_cmd = 0; |
| 614 | int ret = 0; |
| 615 | ssize_t file_dstlen = 0; |
| 616 | |
| 617 | unsigned int req_buf[RAMDUMP_INTERACTIVE_ARRAY_LEN] = {0}; |
| 618 | ramdump_trans_server_interactive_req cap_to_server_msg = {0}; |
| 619 | |
| 620 | /* interactive begin */ |
| 621 | if(ramdump_device_init() < 0) |
| 622 | return; |
| 623 | data_trans_max = RAMDUMP_SHARED_MEM_LEN - roundup(sizeof(ramdump_shmem_t), RAMDUMP_SHMEM_ALIGN_SIZE) - RAMDUMP_COMPRESS_OUT_LEN; |
| 624 | cap_to_server_msg.cmd = RAMDUMP_PC_INTERACTIVE_REQ; |
| 625 | ramdump_oss_data_trans_write((unsigned char*)(&cap_to_server_msg), sizeof(cap_to_server_msg)); |
| 626 | |
| 627 | for(;;) |
| 628 | { |
| 629 | ramdump_oss_data_trans_read((unsigned char *)req_buf, RAMDUMP_INTERACTIVE_DATA_LEN); |
| 630 | switch (*(unsigned int *)req_buf) |
| 631 | { |
| 632 | case RAMDUMP_TRANS_SERVER_INTERACTIVE_RSP: |
| 633 | { |
| 634 | ramdump_pc_file_info_rsp cap_to_server_msg ={0}; |
| 635 | ramdump_trans_server_interactive_req *server_to_cap_msg = (ramdump_trans_server_interactive_req *)req_buf; |
| 636 | /* data from server to cap */ |
| 637 | ramdump_file_num = server_to_cap_msg->file_num; |
xf.li | a06dd22 | 2024-10-14 09:07:20 +0000 | [diff] [blame^] | 638 | ramdump_device_fp.file_num = ramdump_file_num; |
| 639 | ramdump_spinand_fp.file_num = ramdump_file_num; |
xf.li | 3dd5374 | 2024-09-27 00:06:23 -0700 | [diff] [blame] | 640 | |
| 641 | /* data from cap to server */ |
| 642 | cap_to_server_msg.cmd = RAMDUMP_PC_FILE_INFO_READ_REQ; |
| 643 | cap_to_server_msg.file_id = file_cnt; |
| 644 | |
| 645 | ramdump_oss_data_trans_write( |
| 646 | (unsigned char*)(&cap_to_server_msg), |
| 647 | sizeof(cap_to_server_msg)); |
| 648 | |
| 649 | break; |
| 650 | } |
| 651 | case RAMDUMP_TRANS_SERVER_FILE_INFO_READ_RSP: |
| 652 | { |
| 653 | ramdump_pc_trans_data_rsp cap_to_server_msg = {0}; |
| 654 | ramdump_trans_server_file_info_req *server_to_cap_msg = (ramdump_trans_server_file_info_req *)req_buf; |
| 655 | /* data from server to cap */ |
| 656 | /*device memory file create*/ |
| 657 | if(ramdump_device_write_file(server_to_cap_msg) == -1){ |
| 658 | cap_to_server_msg.cmd = RAMDUMP_PC_FILE_TRANS_DONE_REQ; |
| 659 | ramdump_device_write_file_head();//±£Ö¤³ö´íǰ¼¸¸öÎļþ¾ùд¶Ô¡£ |
| 660 | ramdump_printf("ramdump write emmc file error!\n"); |
| 661 | } |
| 662 | file_size = server_to_cap_msg->file_size; |
| 663 | file_offset = 0; |
| 664 | file_left_size = file_size; |
| 665 | /* data from cap to server */ |
| 666 | cap_to_server_msg.cmd = RAMDUMP_PC_FILE_DATA_TRANS_REQ; |
| 667 | cap_to_server_msg.file_id = file_cnt; |
| 668 | cap_to_server_msg.offset = file_offset; |
| 669 | if (file_size >= data_trans_max) |
| 670 | cap_to_server_msg.length = data_trans_max; |
| 671 | else |
| 672 | cap_to_server_msg.length = file_size; |
| 673 | file_trans_size = cap_to_server_msg.length; |
| 674 | file_left_size = file_left_size - cap_to_server_msg.length; |
| 675 | file_offset = file_offset + cap_to_server_msg.length; |
| 676 | printk("device memory trans file:%s !!!\n", server_to_cap_msg->file_name); |
| 677 | /* interactive data trans */ |
| 678 | ramdump_oss_data_trans_write( |
| 679 | (unsigned char*)(&cap_to_server_msg), |
| 680 | sizeof(cap_to_server_msg)); |
| 681 | |
| 682 | break; |
| 683 | } |
| 684 | case RAMDUMP_TRANS_SERVER_FILE_DATA_TRANS_RSP: |
| 685 | { |
| 686 | int write_len = 0; |
| 687 | ramdump_pc_trans_data_rsp cap_to_server_msg = {0}; |
| 688 | /* data from server to cap */ |
| 689 | ramdump_shmem_t *server_to_cap_msg = (ramdump_shmem_t *)ramdump_shared_mem_base; |
| 690 | server_to_cap_msg->core_flag = 0; |
| 691 | /*data from cap to emmc*/ |
| 692 | |
| 693 | write_len = ramdump_device_write_data(server_to_cap_msg, file_left_size, &file_dstlen); |
| 694 | if(write_len < 0) |
| 695 | { |
| 696 | ramdump_printf("ramdump write emmc data error!\n"); |
| 697 | } |
| 698 | |
| 699 | /*ÅжÏÊ£Óà´óС*/ |
| 700 | if (file_left_size == 0) |
| 701 | { |
| 702 | file_cnt++; |
| 703 | if (file_cnt == ramdump_file_num) |
| 704 | { |
| 705 | cap_to_server_msg.cmd = RAMDUMP_PC_FILE_TRANS_DONE_REQ; |
| 706 | } |
| 707 | else |
| 708 | { |
| 709 | cap_to_server_msg.cmd = RAMDUMP_PC_FILE_INFO_READ_REQ; |
| 710 | cap_to_server_msg.file_id = file_cnt; |
| 711 | } |
| 712 | ramdump_device_modify_file_size(file_dstlen); |
| 713 | file_dstlen = 0; |
| 714 | ramdump_device_file_cnt++; |
| 715 | } |
| 716 | else |
| 717 | { |
| 718 | /* data from cap to server */ |
| 719 | if (file_left_size >= data_trans_max) |
| 720 | cap_to_server_msg.length = data_trans_max; |
| 721 | else |
| 722 | cap_to_server_msg.length = file_left_size; |
| 723 | cap_to_server_msg.cmd = RAMDUMP_PC_FILE_DATA_TRANS_REQ; |
| 724 | cap_to_server_msg.file_id = file_cnt; |
| 725 | cap_to_server_msg.offset = file_offset; |
| 726 | file_left_size = file_left_size - cap_to_server_msg.length; |
| 727 | file_offset= file_offset + cap_to_server_msg.length; |
| 728 | } |
| 729 | |
| 730 | ramdump_oss_data_trans_write((unsigned char *)(&cap_to_server_msg), sizeof(cap_to_server_msg)); |
| 731 | continue; |
| 732 | } |
| 733 | case RAMDUMP_TRANS_SERVER_FILE_TRANS_DONE_RSP: |
| 734 | { |
xf.li | a06dd22 | 2024-10-14 09:07:20 +0000 | [diff] [blame^] | 735 | ramdump_device_write_logbuf(); |
xf.li | 3dd5374 | 2024-09-27 00:06:23 -0700 | [diff] [blame] | 736 | ramdump_device_close(); |
| 737 | return; |
| 738 | } |
| 739 | default: |
| 740 | { |
| 741 | error_cmd = RAMDUMP_INTERACTIVE_CMD_ERROR; |
| 742 | ramdump_printf("ramdump trans emmc error:%d!\n", error_cmd); |
| 743 | /* interactive data trans */ |
| 744 | break; |
| 745 | } |
| 746 | } |
| 747 | } |
| 748 | } |
| 749 | |
| 750 | #ifdef __cplusplus |
| 751 | } |
| 752 | #endif |
| 753 | |