SimpleLink Host Driver  1.0.0.1
 All Data Structures Functions Variables Groups Pages
fs.h
1 /*
2  * fs.h - CC31xx/CC32xx Host Driver Implementation
3  *
4  * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
5  *
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  *
14  * Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in the
16  * documentation and/or other materials provided with the
17  * distribution.
18  *
19  * Neither the name of Texas Instruments Incorporated nor the names of
20  * its contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  *
35 */
36 
37 #ifndef __FS_H__
38 #define __FS_H__
39 
40 /*****************************************************************************/
41 /* Include files */
42 /*****************************************************************************/
43 
44 #include "simplelink.h"
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
57 /*****************************************************************************/
58 /* Macro declarations */
59 /*****************************************************************************/
60 
61 /* FS error codes */
62 #define SL_FS_OK (0)
63 #define SL_FS_ERR_EMPTY_SFLASH (-67)
64 #define SL_FS_ERR_FILE_IS_NOT_SECURE_AND_SIGN (-66)
65 #define SL_FS_ERASING_FLASH (-65)
66 #define SL_FS_FILE_HAS_NOT_BEEN_CLOSE_CORRECTLY (-64)
67 #define SL_FS_WRONG_SIGNATURE (-63)
68 #define SL_FS_WRONG_SIGNATURE_OR_CERTIFIC_NAME_LENGTH (-62)
69 #define SL_FS_NOT_16_ALIGNED (-61)
70 #define SL_FS_CERT_CHAIN_ERROR (-60)
71 #define SL_FS_FILE_NAME_EXIST (-59)
72 #define SL_FS_SECURITY_BUF_ALREADY_ALLOC (-58)
73 #define SL_FS_SECURE_FILE_MUST_BE_COMMIT (-57)
74 #define SL_FS_ERR_INCORRECT_OFFSET_ALIGNMENT (-56)
75 #define SL_FS_ERR_FAILED_READ_NVMEM_HEADER (-55)
76 #define SL_FS_WRONG_FILE_NAME (-54)
77 #define SL_FS_FILE_SYSTEM_IS_LOCKED (-53)
78 #define SL_FS_SECURITY_ALLERT (-52)
79 #define SL_FS_FILE_UNVALID_FILE_SIZE (-51)
80 #define SL_FS_ERR_TOKEN_IS_NOT_VALID (-50)
81 #define SL_FS_NO_DEVICE_IS_LOADED (-49)
82 #define SL_FS_DATA_ADDRESS_SHOUD_BE_IN_DATA_RAM (-48)
83 #define SL_FS_DATA_IS_NOT_ALIGNED (-47)
84 #define SL_FS_ERR_OVERLAP_DETECTION_THRESHHOLD (-46)
85 #define SL_FS_FILE_HAS_RESERVED_NV_INDEX (-45)
86 #define SL_FS_ERR_MAX_FS_FILES_IS_LARGER (-44)
87 #define SL_FS_ERR_MAX_FS_FILES_IS_SMALLER (-43)
88 #define SL_FS_FILE_MAX_SIZE_EXCEEDED (-42)
89 #define SL_FS_INVALID_BUFFER_FOR_READ (-41)
90 #define SL_FS_INVALID_BUFFER_FOR_WRITE (-40)
91 #define SL_FS_ERR_FILE_IMAGE_IS_CORRUPTED (-39)
92 #define SL_FS_ERR_SIZE_OF_FILE_EXT_EXCEEDED (-38)
93 #define SL_FS_WARNING_FILE_NAME_NOT_KEPT (-37)
94 #define SL_FS_ERR_DEVICE_IS_NOT_FORMATTED (-36)
95 #define SL_FS_ERR_FAILED_WRITE_NVMEM_HEADER (-35)
96 #define SL_FS_ERR_NO_AVAILABLE_NV_INDEX (-34)
97 #define SL_FS_ERR_FAILED_TO_ALLOCATE_MEM (-33)
98 #define SL_FS_ERR_FAILED_TO_READ_INTEGRITY_HEADER_2 (-32)
99 #define SL_FS_ERR_FAILED_TO_READ_INTEGRITY_HEADER_1 (-31)
100 #define SL_FS_ERR_NO_AVAILABLE_BLOCKS (-30)
101 #define SL_FS_ERR_FILE_MAX_SIZE_BIGGER_THAN_EXISTING_FILE (-29)
102 #define SL_FS_ERR_FILE_EXISTS_ON_DIFFERENT_DEVICE_ID (-28)
103 #define SL_FS_ERR_INVALID_ACCESS_TYPE (-27)
104 #define SL_FS_ERR_FILE_ALREADY_EXISTS (-26)
105 #define SL_FS_ERR_PROGRAM (-25)
106 #define SL_FS_ERR_NO_ENTRIES_AVAILABLE (-24)
107 #define SL_FS_ERR_FILE_ACCESS_IS_DIFFERENT (-23)
108 #define SL_FS_ERR_BAD_FILE_MODE (-22)
109 #define SL_FS_ERR_FAILED_READ_NVFILE (-21)
110 #define SL_FS_ERR_FAILED_INIT_STORAGE (-20)
111 #define SL_FS_ERR_CONTINUE_WRITE_MUST_BE_MOD_4 (-19)
112 #define SL_FS_ERR_FAILED_LOAD_FILE (-18)
113 #define SL_FS_ERR_INVALID_HANDLE (-17)
114 #define SL_FS_ERR_FAILED_TO_WRITE (-16)
115 #define SL_FS_ERR_OFFSET_OUT_OF_RANGE (-15)
116 #define SL_FS_ERR_ALLOC (-14)
117 #define SL_FS_ERR_READ_DATA_LENGTH (-13)
118 #define SL_FS_ERR_INVALID_FILE_ID (-12)
119 #define SL_FS_ERR_FILE_NOT_EXISTS (-11)
120 #define SL_FS_ERR_EMPTY_ERROR (-10)
121 #define SL_FS_ERR_INVALID_ARGS (-9)
122 #define SL_FS_ERR_FAILED_TO_CREATE_FILE (-8)
123 #define SL_FS_ERR_FS_ALREADY_LOADED (-7)
124 #define SL_FS_ERR_UNKNOWN (-6)
125 #define SL_FS_ERR_FAILED_TO_CREATE_LOCK_OBJ (-5)
126 #define SL_FS_ERR_DEVICE_NOT_LOADED (-4)
127 #define SL_FS_ERR_INVALID_MAGIC_NUM (-3)
128 #define SL_FS_ERR_FAILED_TO_READ (-2)
129 #define SL_FS_ERR_NOT_SUPPORTED (-1)
130 /* end of error codes */
131 
132 #define _FS_MODE_ACCESS_RESERVED_OFFSET (24)
133 #define _FS_MODE_ACCESS_RESERVED_MASK (0xFF)
134 #define _FS_MODE_ACCESS_FLAGS_OFFSET (16)
135 #define _FS_MODE_ACCESS_FLAGS_MASK (0xFF)
136 #define _FS_MODE_ACCESS_OFFSET (12)
137 #define _FS_MODE_ACCESS_MASK (0xF)
138 #define _FS_MODE_OPEN_SIZE_GRAN_OFFSET (8)
139 #define _FS_MODE_OPEN_SIZE_GRAN_MASK (0xF)
140 #define _FS_MODE_OPEN_SIZE_OFFSET (0)
141 #define _FS_MODE_OPEN_SIZE_MASK (0xFF)
142 #define MAX_MODE_SIZE (0xFF)
143 #define _FS_MODE(Access, SizeGran, Size,Flags) (_u32)(((_u32)((Access) & _FS_MODE_ACCESS_MASK)<<_FS_MODE_ACCESS_OFFSET) | \
144  ((_u32)((SizeGran) & _FS_MODE_OPEN_SIZE_GRAN_MASK)<<_FS_MODE_OPEN_SIZE_GRAN_OFFSET) | \
145  ((_u32)((Size) & _FS_MODE_OPEN_SIZE_MASK)<<_FS_MODE_OPEN_SIZE_OFFSET) | \
146  ((_u32)((Flags) & _FS_MODE_ACCESS_FLAGS_MASK)<<_FS_MODE_ACCESS_FLAGS_OFFSET))
147 
148 
149 /* sl_FsOpen options */
150 /* Open for Read */
151 #define FS_MODE_OPEN_READ _FS_MODE(_FS_MODE_OPEN_READ,0,0,0)
152 /* Open for Write (in case file exist) */
153 #define FS_MODE_OPEN_WRITE _FS_MODE(_FS_MODE_OPEN_WRITE,0,0,0)
154 /* Open for Creating a new file */
155 #define FS_MODE_OPEN_CREATE(maxSizeInBytes,accessModeFlags) _sl_GetCreateFsMode(maxSizeInBytes,accessModeFlags)
156 
157 /*****************************************************************************/
158 /* Structure/Enum declarations */
159 /*****************************************************************************/
160 typedef struct
161 {
162  _u16 flags;
163  _u32 FileLen;
164  _u32 AllocatedLen;
165  _u32 Token[4];
167 
168 typedef enum
169 {
170  _FS_MODE_OPEN_READ = 0,
171  _FS_MODE_OPEN_WRITE,
172  _FS_MODE_OPEN_CREATE,
173  _FS_MODE_OPEN_WRITE_CREATE_IF_NOT_EXIST
174 }SlFsFileOpenAccessType_e;
175 
176 typedef enum
177 {
178  _FS_FILE_OPEN_FLAG_COMMIT = 0x1, /* MIRROR - for fail safe */
179  _FS_FILE_OPEN_FLAG_SECURE = 0x2, /* SECURE */
180  _FS_FILE_OPEN_FLAG_NO_SIGNATURE_TEST = 0x4, /* Relevant to secure file only */
181  _FS_FILE_OPEN_FLAG_STATIC = 0x8, /* Relevant to secure file only */
182  _FS_FILE_OPEN_FLAG_VENDOR = 0x10, /* Relevant to secure file only */
183  _FS_FILE_PUBLIC_WRITE= 0x20, /* Relevant to secure file only, the file can be opened for write without Token */
184  _FS_FILE_PUBLIC_READ = 0x40 /* Relevant to secure file only, the file can be opened for read without Token */
185 }SlFileOpenFlags_e;
186 
187 typedef enum
188 {
189  _FS_MODE_SIZE_GRAN_256B = 0, /* MAX_SIZE = 64K */
190  _FS_MODE_SIZE_GRAN_1KB, /* MAX_SIZE = 256K */
191  _FS_MODE_SIZE_GRAN_4KB, /* MAX_SZIE = 1M */
192  _FS_MODE_SIZE_GRAN_16KB, /* MAX_SIZE = 4M */
193  _FS_MODE_SIZE_GRAN_64KB, /* MAX_SIZE = 16M */
194  _FS_MAX_MODE_SIZE_GRAN
195 }_SlFsFileOpenMaxSizeGran_e;
196 
197 /*****************************************************************************/
198 /* Internal Function prototypes */
199 /*****************************************************************************/
200 _u32 _sl_GetCreateFsMode(_u32 maxSizeInBytes,_u32 accessFlags);
201 
202 /*****************************************************************************/
203 /* Function prototypes */
204 /*****************************************************************************/
205 
258 #if _SL_INCLUDE_FUNC(sl_FsOpen)
259 _i32 sl_FsOpen(_u8 *pFileName,_u32 AccessModeAndMaxSize,_u32 *pToken,_i32 *pFileHandle);
260 #endif
261 
281 #if _SL_INCLUDE_FUNC(sl_FsClose)
282 _i16 sl_FsClose(_i32 FileHdl,_u8* pCeritificateFileName,_u8* pSignature,_u32 SignatureLen);
283 #endif
284 
303 #if _SL_INCLUDE_FUNC(sl_FsRead)
304 _i32 sl_FsRead(_i32 FileHdl,_u32 Offset ,_u8* pData,_u32 Len);
305 #endif
306 
325 #if _SL_INCLUDE_FUNC(sl_FsWrite)
326 _i32 sl_FsWrite(_i32 FileHdl,_u32 Offset,_u8* pData,_u32 Len);
327 #endif
328 
346 #if _SL_INCLUDE_FUNC(sl_FsGetInfo)
347 _i16 sl_FsGetInfo(_u8 *pFileName,_u32 Token,SlFsFileInfo_t* pFsFileInfo);
348 #endif
349 
365 #if _SL_INCLUDE_FUNC(sl_FsDel)
366 _i16 sl_FsDel(_u8 *pFileName,_u32 Token);
367 #endif
368 
375 #ifdef __cplusplus
376 }
377 #endif /* __cplusplus */
378 
379 #endif /* __FS_H__ */
380 
Definition: fs.h:160