xf.li | ed996a2 | 2025-03-13 23:49:05 -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 "ramdump_emmc.h" |
| 30 | #include "ram_config.h" |
| 31 | #include "ramdump_compress.h" |
| 32 | #include <linux/lzo.h> |
| 33 | |
| 34 | #ifdef __cplusplus |
| 35 | extern "C" { |
| 36 | #endif |
| 37 | |
| 38 | /******************************************************************************* |
| 39 | * Extern function declarations * |
| 40 | *******************************************************************************/ |
| 41 | |
| 42 | /******************************************************************************* |
| 43 | * Extern variable declarations * |
| 44 | *******************************************************************************/ |
| 45 | extern unsigned char *ramdump_shared_mem_base; |
| 46 | extern unsigned char *ramdump_emmc_flag_base; |
| 47 | extern unsigned int ramdump_compress_flag; |
| 48 | |
| 49 | /******************************************************************************* |
| 50 | * Macro definitions * |
| 51 | ******************************************************************************/ |
| 52 | #define RAMDUMP_DELAY_MS_COUNT (2500) |
| 53 | |
| 54 | /******************************************************************************* |
| 55 | * Type definitions * |
| 56 | ******************************************************************************/ |
| 57 | |
| 58 | /******************************************************************************* |
| 59 | * Local function declarations * |
| 60 | ******************************************************************************/ |
| 61 | |
| 62 | /******************************************************************************* |
| 63 | * Local variable definitions * |
| 64 | ******************************************************************************/ |
| 65 | |
| 66 | /******************************************************************************* |
| 67 | * Global variable definitions * |
| 68 | ******************************************************************************/ |
| 69 | unsigned int ramdump_emmc_size = 0; |
| 70 | volatile unsigned int ramdump_emmc_offset = 0; |
| 71 | extern unsigned int ramdump_device_file_cnt; |
| 72 | |
| 73 | /******************************************************************************* |
| 74 | * Inline function implementations * |
| 75 | ******************************************************************************/ |
| 76 | static inline void ramdump_wait_delay( unsigned long ms) |
| 77 | { |
| 78 | volatile int j = 0; |
| 79 | for (j = 0; j < 10000; j++); |
| 80 | } |
| 81 | |
| 82 | /******************************************************************************* |
| 83 | * Local function implementations * |
| 84 | ******************************************************************************/ |
| 85 | int ramdump_emmc_init(ramdump_file_t *fp) |
| 86 | { |
| 87 | fp->magic = 0x2A2A2A2A; |
| 88 | ramdump_emmc_offset = roundup(sizeof(ramdump_file_t), RAMDUMP_EMMC_ALIGN_SIZE); |
| 89 | |
| 90 | if(RAMDUMP_TRANS_EMMC_LEN > ramdump_emmc_offset) |
| 91 | { |
| 92 | ramdump_emmc_size = RAMDUMP_TRANS_EMMC_LEN - ramdump_emmc_offset; |
| 93 | } |
| 94 | else |
| 95 | { |
| 96 | printk("[ramdump] emmc start addr is %ld, emmc size= %ld, error: size smaller than ramdump file header, return!\n", sysctl_ramdump_emmc_start_addr, sysctl_ramdump_emmc_size); |
| 97 | return -1; |
| 98 | } |
| 99 | |
| 100 | if(mmc_ramdump_init()){ |
| 101 | ramdump_printf("EMMC init failed! No ramdump data trans to emmc!\n"); |
| 102 | return -1; |
| 103 | } |
| 104 | return 0; |
| 105 | } |
| 106 | |
| 107 | int ramdump_emmc_write_file(char *file_name, unsigned int file_size, ramdump_file_t *fp) |
| 108 | { |
| 109 | if (ramdump_device_file_cnt >= RAMDUMP_FILE_NUM_MAX) |
| 110 | return -1; |
| 111 | if (ramdump_emmc_offset >= RAMDUMP_TRANS_EMMC_LEN) |
| 112 | return -1; |
| 113 | |
| 114 | fp->file_fp[ramdump_device_file_cnt].magic = 0x3A3A3A3A; |
| 115 | strncpy(fp->file_fp[ramdump_device_file_cnt].file_name, file_name, RAMDUMP_RAMCONF_FILENAME_MAXLEN - 1); |
| 116 | fp->file_fp[ramdump_device_file_cnt].offset = ramdump_emmc_offset; |
| 117 | fp->file_fp[ramdump_device_file_cnt].size = file_size; |
| 118 | return 0; |
| 119 | } |
| 120 | |
| 121 | int ramdump_emmc_write_file_head(ramdump_file_t *fp) |
| 122 | { |
| 123 | int ret = -1; |
| 124 | mmc_bwrite(RAMDUMP_EMMC_ADDR, roundup(sizeof(ramdump_file_t), RAMDUMP_EMMC_ALIGN_SIZE), fp); |
| 125 | return ret; |
| 126 | } |
| 127 | |
| 128 | int ramdump_emmc_write_data(ramdump_shmem_t *msg, ramdump_file_t *fp, unsigned int size) |
| 129 | { |
| 130 | int ret = 0; |
| 131 | unsigned int buffer = RAMDUMP_EMMC_ADDR + ramdump_emmc_offset; |
| 132 | |
| 133 | if (ramdump_device_file_cnt >= RAMDUMP_FILE_NUM_MAX) |
| 134 | return -1; |
| 135 | |
| 136 | while(1){ |
| 137 | if ((msg->core_flag == 1) && (msg->rw_flag == 2)){ |
| 138 | if(msg->size >= (ramdump_emmc_size - fp->file_fp[ramdump_device_file_cnt].offset)) |
| 139 | return -1; |
| 140 | ret = mmc_bwrite(buffer, msg->size, msg->buf); |
| 141 | ramdump_emmc_offset = ramdump_emmc_offset + roundup(msg->size, RAMDUMP_EMMC_ALIGN_SIZE); |
| 142 | msg->core_flag = 1; |
| 143 | msg->rw_flag = 1; |
| 144 | ret = msg->size; |
| 145 | break; |
| 146 | } |
| 147 | else |
| 148 | ramdump_wait_delay(0); |
| 149 | } |
| 150 | return ret; |
| 151 | } |
| 152 | |
| 153 | int ramdump_emmc_read(char *buffer, ramdump_shmem_t *msg, unsigned int size) |
| 154 | { |
| 155 | int ret = 0; |
| 156 | |
| 157 | return ret; |
| 158 | } |
| 159 | |
| 160 | void ramdump_emmc_close(ramdump_file_t *fp) |
| 161 | { |
| 162 | fp->file_size = ramdump_emmc_offset; |
| 163 | ramdump_emmc_write_file_head(fp); |
| 164 | ramdump_printf("ramdump trans emmc finished!\n"); |
| 165 | } |
| 166 | |
| 167 | #ifdef __cplusplus |
| 168 | } |
| 169 | #endif |
| 170 | |