2 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 * @brief This file provides API for get nor flash information
22 #ifndef ROM_ACCESS_LIBRARY_LIBRARY_INCLUDE_SYSTEM_SERVICE_NOR_BACKUP_H_
23 #define ROM_ACCESS_LIBRARY_LIBRARY_INCLUDE_SYSTEM_SERVICE_NOR_BACKUP_H_
25 /** @addtogroup BaseSystem
28 /** @addtogroup system_service
32 /** @addtogroup rom_access_library
33 * @ingroup system_service
36 #if defined(__cplusplus)
41 * \~english Common return value: Normal return value of API
43 #define RET_DEV_NORMAL 0
46 * \~english Common return value: Parameter error return value of API
48 #define RET_DEV_ERR_PARAM 3
51 * \~english Common return value: Error of getting device info
53 #define RET_DEV_ERROR 4
56 * \~english Read API return value: Internal error
58 #define RET_DEV_RD_ERR_OTHER 1
61 * \~english Read API return value: Acquire buffer error(malloc)
63 #define RET_DEV_RD_ERR 2
66 * \~english Read API return value: error type 1
68 #define RET_DEV_RD_ERR_1 -1
71 * \~english Read API return value: error type 2
73 #define RET_DEV_RD_ERR_2 -2
76 * \~english Read API return value: error type 3
78 #define RET_DEV_RD_ERR_3 -3
81 * \~english Read API return value: error type 4
83 #define RET_DEV_RD_ERR_4 -4
86 * \~english Write API return value: Other error
88 #define RET_DEV_WT_ERR_OTHER 1
91 * \~english Write API return value: Internal error
93 #define RET_DEV_WT_ERR 2
95 /**\ingroup mtdn_backup_Read
96 * \~english @par Brief
97 * Read data from norflash device.
98 * \~english @param [in] path_name
99 * const char* - Device path to read(such as "/dev/mtd1ro")
100 * \~english @param [in] i_id
101 * int - Main block ID(0, 2, 4, ...)
102 * \~english @param [in] i_offset
104 * \~english @param [in] i_size
105 * int - Data size to read
106 * \~english @param [in] p_buff
107 * Void* - Buffer for storing read data
108 * \~english @retval RET_DEV_NORMAL OK
109 * \~english @retval RET_DEV_ERROR Get device error
110 * \~english @retval RET_DEV_ERR_PARAM Parameter error
111 * \~english @retval RET_DEV_RD_ERR_OTHER Internal error
112 * \~english @retval RET_DEV_RD_ERR Acquire buffer error(malloc)
113 * \~english @retval RET_DEV_RD_ERR_1 Error type 1
114 * \~english @retval RET_DEV_RD_ERR_2 Error type 2
115 * \~english @retval RET_DEV_RD_ERR_3 Error type 3
116 * \~english @retval RET_DEV_RD_ERR_4 Error type 4
117 * \~english @par Preconditions
118 * - There is no preconditions for this API.
119 * \~english @par Change of internal state
120 * - Change of internal state according to the API does not occur.
121 * \~english @par Conditions of processing failure
122 * - Parameter path_name is NULL. [RET_DEV_ERR_PARAM]
123 * - Parameter p_buff is NULL. [RET_DEV_ERR_PARAM]
124 * - Value of parameter i_id is less than 0. [RET_DEV_ERR_PARAM]
125 * - Value of parameter i_offset is less than 0 or value of parameter i_size
126 * is not greater than 0. [RET_DEV_ERR_PARAM]
127 * - Device specified by path_name is invalid. [RET_DEV_ERR_PARAM]
128 * - Sum value of i_offset and i_size is greater than block size - 16byte.
129 * [RET_DEV_ERR_PARAM]
130 * - Failed to get device info. [RET_DEV_ERROR]
131 * - Failed to acquire the send/receive buffer(malloc). [RET_DEV_RD_ERR]
132 * - Internal IO error(open, read, close, ioctl, lseek, other error).
133 * [RET_DEV_RD_ERR_OTHER]
134 * - Check text error of main block and backup block. [RET_DEV_RD_ERR_1]
135 * - Check text error of main block and checksum error of backup block.
137 * - Checksum error of main block and check text error of backup block.
139 * - Checksum error of main block and backup block. [RET_DEV_RD_ERR_4]
140 * \~english @par Detail
141 * - This API gets data from main or backup block according to specified\n
142 * norflash device pathname and main block ID.
144 * - When this API is executed, read data from main block first. If failed to\n
145 * read main block, return RET_DEV_RD_ERR_OTHER. If read main block success,\n
146 * but check main block data error, turn to read data from backup block which\n
147 * block ID is i_id + 1.
148 * \~english @par Classification
150 * \~english @par Type
152 * \~english @see mtdn_backup_Write
154 int mtdn_backup_Read(const char * path_name, int i_id, int i_offset, int i_size, void *p_buff);
156 /**\ingroup mtdn_backup_Write
157 * \~english @par Brief
158 * Write data to norflash device.
159 * \~english @param [in] path_name
160 * const char* - Device path to write(such as "/dev/mtd")
161 * \~english @param [in] i_id
162 * int - Main block ID(0, 2, 4, ...)
163 * \~english @param [in] i_offset
165 * \~english @param [in] i_size
166 * int - Data size to write
167 * \~english @param [in] p_buff
168 * Void* - Buffer for storing written data
169 * \~english @retval RET_DEV_NORMAL OK
170 * \~english @retval RET_DEV_ERROR Get device error
171 * \~english @retval RET_DEV_ERR_PARAM Parameter error
172 * \~english @retval RET_DEV_WT_ERR_OTHER Other error
173 * \~english @retval RET_DEV_WT_ERR Internal error
174 * \~english @par Preconditions
175 * - There is no preconditions for this API.
176 * \~english @par Change of internal state
177 * - Change of internal state according to the API does not occur.
178 * \~english @par Conditions of processing failure
179 * - Parameter path_name is NULL. [RET_DEV_ERR_PARAM]
180 * - Parameter p_buff is NULL. [RET_DEV_ERR_PARAM]
181 * - Value of parameter i_id is less than 0. [RET_DEV_ERR_PARAM]
182 * - Value of parameter i_offset is less than 0 or value of parameter i_size
183 * is not greater than 0. [RET_DEV_ERR_PARAM]
184 * - Device specified by path_name is invalid. [RET_DEV_ERR_PARAM]
185 * - Sum value of i_offset and i_size is greater than block size - 16byte.
186 * [RET_DEV_ERR_PARAM]
187 * - Failed to get device info. [RET_DEV_ERROR]
188 * - Internal processing error(Other error). [RET_DEV_WT_ERR_OTHER]
189 * - Internal IO error(open, write, close, ioctl, malloc, lseek).
191 * \~english @par Detail
192 * - This API writes data to main and backup blocks according to specified\n
193 * norflash device pathname and main block ID.
195 * - When this API is executed, p_buff data will be write to main and backup\n
196 * blocks. If failed to write any block, return RET_DEV_WT_ERR.
197 * \~english @par Classification
199 * \~english @par Type
201 * \~english @see mtdn_backup_Read
203 int mtdn_backup_Write(const char * path_name, int i_id, int i_offset, int i_size, void *p_buff);
205 #if defined(__cplusplus)
207 #endif // __cplusplus
209 /** @}*/ // end of rom_access_library
210 /** @}*/ // end of system_service
211 /** @}*/ // end of BaseSystem
212 #endif // ROM_ACCESS_LIBRARY_LIBRARY_INCLUDE_SYSTEM_SERVICE_NOR_BACKUP_H_