blob: f3e91e92257ed382f7599d0bf14682c48c2fc41b [file] [log] [blame]
l.yangb8fdece2024-10-10 14:56:17 +08001/**
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
39extern "C" {
40#endif
41
42/*******************************************************************************
43* Extern function declarations *
44*******************************************************************************/
45extern unsigned char *ramdump_phy_to_vir(unsigned long phy, unsigned long size);
46extern int dump_printk_text(char *buffer, unsigned long len);
47
48/*******************************************************************************
49* Extern variable declarations *
50*******************************************************************************/
51extern unsigned int ramdump_compress_flag;
52extern unsigned char *ramdump_log_buf;
53extern 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 */
98typedef 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 */
105typedef 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 */
113typedef 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 */
120typedef 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 */
128typedef 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 ******************************************************************************/
143char *ramdump_log_buf_region = NULL;
144unsigned int ramdump_log_buf_len = 0;
145
146/*******************************************************************************
147 * Global variable definitions *
148 ******************************************************************************/
149unsigned char *ramdump_shared_mem_base = NULL;
150unsigned char *ramdump_export_flag_base = NULL;
151int ramdump_file_num = 0;
152ramdump_file_t ramdump_device_fp = {0};
153ramdump_file_t ramdump_spinand_fp = {0};
154ramdump_file_t *g_ramdump_dev_fp;
155unsigned int ramdump_device_file_cnt = 0;
156unsigned char *ramdump_log_buf = NULL; /* ¸´ÓÃramdump´æ´¢µÄ128KB(Æ«ÒÆ16KB) */
157
158/*******************************************************************************
159 * Inline function implementations *
160 ******************************************************************************/
161static 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*******************************************************************************/
178int 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*******************************************************************************/
209int 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*******************************************************************************/
242void 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*******************************************************************************/
259int 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*******************************************************************************/
289void 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*******************************************************************************/
313int 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*******************************************************************************/
333int 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*******************************************************************************/
372int 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*******************************************************************************/
393int 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
412int 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
467int 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*******************************************************************************/
537int 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*******************************************************************************/
557int 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 ******************************************************************************/
589void 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*******************************************************************************/
605void 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;
l.yangafee7ee2024-10-10 15:01:10 +0800623
624 ramdump_device_write_logbuf();
l.yangb8fdece2024-10-10 14:56:17 +0800625 data_trans_max = RAMDUMP_SHARED_MEM_LEN - roundup(sizeof(ramdump_shmem_t), RAMDUMP_SHMEM_ALIGN_SIZE) - RAMDUMP_COMPRESS_OUT_LEN;
626 cap_to_server_msg.cmd = RAMDUMP_PC_INTERACTIVE_REQ;
627 ramdump_oss_data_trans_write((unsigned char*)(&cap_to_server_msg), sizeof(cap_to_server_msg));
628
629 for(;;)
630 {
631 ramdump_oss_data_trans_read((unsigned char *)req_buf, RAMDUMP_INTERACTIVE_DATA_LEN);
632 switch (*(unsigned int *)req_buf)
633 {
634 case RAMDUMP_TRANS_SERVER_INTERACTIVE_RSP:
635 {
636 ramdump_pc_file_info_rsp cap_to_server_msg ={0};
637 ramdump_trans_server_interactive_req *server_to_cap_msg = (ramdump_trans_server_interactive_req *)req_buf;
638 /* data from server to cap */
639 ramdump_file_num = server_to_cap_msg->file_num;
l.yangafee7ee2024-10-10 15:01:10 +0800640 ramdump_device_fp.file_num += ramdump_file_num;
641 ramdump_spinand_fp.file_num += ramdump_file_num;
l.yangb8fdece2024-10-10 14:56:17 +0800642
643 /* data from cap to server */
644 cap_to_server_msg.cmd = RAMDUMP_PC_FILE_INFO_READ_REQ;
645 cap_to_server_msg.file_id = file_cnt;
646
647 ramdump_oss_data_trans_write(
648 (unsigned char*)(&cap_to_server_msg),
649 sizeof(cap_to_server_msg));
650
651 break;
652 }
653 case RAMDUMP_TRANS_SERVER_FILE_INFO_READ_RSP:
654 {
655 ramdump_pc_trans_data_rsp cap_to_server_msg = {0};
656 ramdump_trans_server_file_info_req *server_to_cap_msg = (ramdump_trans_server_file_info_req *)req_buf;
657 /* data from server to cap */
658 /*device memory file create*/
659 if(ramdump_device_write_file(server_to_cap_msg) == -1){
660 cap_to_server_msg.cmd = RAMDUMP_PC_FILE_TRANS_DONE_REQ;
661 ramdump_device_write_file_head();//±£Ö¤³ö´íǰ¼¸¸öÎļþ¾ùд¶Ô¡£
662 ramdump_printf("ramdump write emmc file error!\n");
663 }
664 file_size = server_to_cap_msg->file_size;
665 file_offset = 0;
666 file_left_size = file_size;
667 /* data from cap to server */
668 cap_to_server_msg.cmd = RAMDUMP_PC_FILE_DATA_TRANS_REQ;
669 cap_to_server_msg.file_id = file_cnt;
670 cap_to_server_msg.offset = file_offset;
671 if (file_size >= data_trans_max)
672 cap_to_server_msg.length = data_trans_max;
673 else
674 cap_to_server_msg.length = file_size;
675 file_trans_size = cap_to_server_msg.length;
676 file_left_size = file_left_size - cap_to_server_msg.length;
677 file_offset = file_offset + cap_to_server_msg.length;
678 printk("device memory trans file:%s !!!\n", server_to_cap_msg->file_name);
679 /* interactive data trans */
680 ramdump_oss_data_trans_write(
681 (unsigned char*)(&cap_to_server_msg),
682 sizeof(cap_to_server_msg));
683
684 break;
685 }
686 case RAMDUMP_TRANS_SERVER_FILE_DATA_TRANS_RSP:
687 {
688 int write_len = 0;
689 ramdump_pc_trans_data_rsp cap_to_server_msg = {0};
690 /* data from server to cap */
691 ramdump_shmem_t *server_to_cap_msg = (ramdump_shmem_t *)ramdump_shared_mem_base;
692 server_to_cap_msg->core_flag = 0;
693 /*data from cap to emmc*/
694
695 write_len = ramdump_device_write_data(server_to_cap_msg, file_left_size, &file_dstlen);
696 if(write_len < 0)
697 {
698 ramdump_printf("ramdump write emmc data error!\n");
699 }
700
701 /*ÅжÏÊ£Óà´óС*/
702 if (file_left_size == 0)
703 {
704 file_cnt++;
705 if (file_cnt == ramdump_file_num)
706 {
707 cap_to_server_msg.cmd = RAMDUMP_PC_FILE_TRANS_DONE_REQ;
708 }
709 else
710 {
711 cap_to_server_msg.cmd = RAMDUMP_PC_FILE_INFO_READ_REQ;
712 cap_to_server_msg.file_id = file_cnt;
713 }
714 ramdump_device_modify_file_size(file_dstlen);
715 file_dstlen = 0;
716 ramdump_device_file_cnt++;
717 }
718 else
719 {
720 /* data from cap to server */
721 if (file_left_size >= data_trans_max)
722 cap_to_server_msg.length = data_trans_max;
723 else
724 cap_to_server_msg.length = file_left_size;
725 cap_to_server_msg.cmd = RAMDUMP_PC_FILE_DATA_TRANS_REQ;
726 cap_to_server_msg.file_id = file_cnt;
727 cap_to_server_msg.offset = file_offset;
728 file_left_size = file_left_size - cap_to_server_msg.length;
729 file_offset= file_offset + cap_to_server_msg.length;
730 }
731
732 ramdump_oss_data_trans_write((unsigned char *)(&cap_to_server_msg), sizeof(cap_to_server_msg));
733 continue;
734 }
735 case RAMDUMP_TRANS_SERVER_FILE_TRANS_DONE_RSP:
736 {
l.yangb8fdece2024-10-10 14:56:17 +0800737 ramdump_device_close();
738 return;
739 }
740 default:
741 {
742 error_cmd = RAMDUMP_INTERACTIVE_CMD_ERROR;
743 ramdump_printf("ramdump trans emmc error:%d!\n", error_cmd);
744 /* interactive data trans */
745 break;
746 }
747 }
748 }
749}
750
751#ifdef __cplusplus
752}
753#endif
754