41 #include "simplelink.h"
65 #define SL_FS_ERR_EMPTY_SFLASH (-67)
66 #define SL_FS_ERR_FILE_IS_NOT_SECURE_AND_SIGN (-66)
67 #define SL_FS_ERASING_FLASH (-65)
68 #define SL_FS_FILE_HAS_NOT_BEEN_CLOSE_CORRECTLY (-64)
69 #define SL_FS_WRONG_SIGNATURE (-63)
70 #define SL_FS_WRONG_SIGNATURE_OR_CERTIFIC_NAME_LENGTH (-62)
71 #define SL_FS_NOT_16_ALIGNED (-61)
72 #define SL_FS_CERT_CHAIN_ERROR (-60)
73 #define SL_FS_FILE_NAME_EXIST (-59)
74 #define SL_FS_SECURITY_BUF_ALREADY_ALLOC (-58)
75 #define SL_FS_SECURE_FILE_MUST_BE_COMMIT (-57)
76 #define SL_FS_ERR_INCORRECT_OFFSET_ALIGNMENT (-56)
77 #define SL_FS_ERR_FAILED_READ_NVMEM_HEADER (-55)
78 #define SL_FS_WRONG_FILE_NAME (-54)
79 #define SL_FS_FILE_SYSTEM_IS_LOCKED (-53)
80 #define SL_FS_SECURITY_ALLERT (-52)
81 #define SL_FS_FILE_UNVALID_FILE_SIZE (-51)
82 #define SL_FS_ERR_TOKEN_IS_NOT_VALID (-50)
83 #define SL_FS_NO_DEVICE_IS_LOADED (-49)
84 #define SL_FS_DATA_ADDRESS_SHOUD_BE_IN_DATA_RAM (-48)
85 #define SL_FS_DATA_IS_NOT_ALIGNED (-47)
86 #define SL_FS_ERR_OVERLAP_DETECTION_THRESHHOLD (-46)
87 #define SL_FS_FILE_HAS_RESERVED_NV_INDEX (-45)
88 #define SL_FS_ERR_MAX_FS_FILES_IS_LARGER (-44)
89 #define SL_FS_ERR_MAX_FS_FILES_IS_SMALLER (-43)
90 #define SL_FS_FILE_MAX_SIZE_EXCEEDED (-42)
91 #define SL_FS_INVALID_BUFFER_FOR_READ (-41)
92 #define SL_FS_INVALID_BUFFER_FOR_WRITE (-40)
93 #define SL_FS_ERR_FILE_IMAGE_IS_CORRUPTED (-39)
94 #define SL_FS_ERR_SIZE_OF_FILE_EXT_EXCEEDED (-38)
95 #define SL_FS_WARNING_FILE_NAME_NOT_KEPT (-37)
96 #define SL_FS_ERR_DEVICE_IS_NOT_FORMATTED (-36)
97 #define SL_FS_ERR_FAILED_WRITE_NVMEM_HEADER (-35)
98 #define SL_FS_ERR_NO_AVAILABLE_NV_INDEX (-34)
99 #define SL_FS_ERR_FAILED_TO_ALLOCATE_MEM (-33)
100 #define SL_FS_ERR_FAILED_TO_READ_INTEGRITY_HEADER_2 (-32)
101 #define SL_FS_ERR_FAILED_TO_READ_INTEGRITY_HEADER_1 (-31)
102 #define SL_FS_ERR_NO_AVAILABLE_BLOCKS (-30)
103 #define SL_FS_ERR_FILE_MAX_SIZE_BIGGER_THAN_EXISTING_FILE (-29)
104 #define SL_FS_ERR_FILE_EXISTS_ON_DIFFERENT_DEVICE_ID (-28)
105 #define SL_FS_ERR_INVALID_ACCESS_TYPE (-27)
106 #define SL_FS_ERR_FILE_ALREADY_EXISTS (-26)
107 #define SL_FS_ERR_PROGRAM (-25)
108 #define SL_FS_ERR_NO_ENTRIES_AVAILABLE (-24)
109 #define SL_FS_ERR_FILE_ACCESS_IS_DIFFERENT (-23)
110 #define SL_FS_ERR_BAD_FILE_MODE (-22)
111 #define SL_FS_ERR_FAILED_READ_NVFILE (-21)
112 #define SL_FS_ERR_FAILED_INIT_STORAGE (-20)
113 #define SL_FS_ERR_CONTINUE_WRITE_MUST_BE_MOD_4 (-19)
114 #define SL_FS_ERR_FAILED_LOAD_FILE (-18)
115 #define SL_FS_ERR_INVALID_HANDLE (-17)
116 #define SL_FS_ERR_FAILED_TO_WRITE (-16)
117 #define SL_FS_ERR_OFFSET_OUT_OF_RANGE (-15)
118 #define SL_FS_ERR_ALLOC (-14)
119 #define SL_FS_ERR_READ_DATA_LENGTH (-13)
120 #define SL_FS_ERR_INVALID_FILE_ID (-12)
121 #define SL_FS_ERR_FILE_NOT_EXISTS (-11)
122 #define SL_FS_ERR_EMPTY_ERROR (-10)
123 #define SL_FS_ERR_INVALID_ARGS (-9)
124 #define SL_FS_ERR_FAILED_TO_CREATE_FILE (-8)
125 #define SL_FS_ERR_FS_ALREADY_LOADED (-7)
126 #define SL_FS_ERR_UNKNOWN (-6)
127 #define SL_FS_ERR_FAILED_TO_CREATE_LOCK_OBJ (-5)
128 #define SL_FS_ERR_DEVICE_NOT_LOADED (-4)
129 #define SL_FS_ERR_INVALID_MAGIC_NUM (-3)
130 #define SL_FS_ERR_FAILED_TO_READ (-2)
131 #define SL_FS_ERR_NOT_SUPPORTED (-1)
134 #define _FS_MODE_ACCESS_RESERVED_OFFSET (24)
135 #define _FS_MODE_ACCESS_RESERVED_MASK (0xFF)
136 #define _FS_MODE_ACCESS_FLAGS_OFFSET (16)
137 #define _FS_MODE_ACCESS_FLAGS_MASK (0xFF)
138 #define _FS_MODE_ACCESS_OFFSET (12)
139 #define _FS_MODE_ACCESS_MASK (0xF)
140 #define _FS_MODE_OPEN_SIZE_GRAN_OFFSET (8)
141 #define _FS_MODE_OPEN_SIZE_GRAN_MASK (0xF)
142 #define _FS_MODE_OPEN_SIZE_OFFSET (0)
143 #define _FS_MODE_OPEN_SIZE_MASK (0xFF)
144 #define MAX_MODE_SIZE (0xFF)
145 #define _FS_MODE(Access, SizeGran, Size,Flags) (_u32)(((_u32)((Access) & _FS_MODE_ACCESS_MASK)<<_FS_MODE_ACCESS_OFFSET) | \
146 ((_u32)((SizeGran) & _FS_MODE_OPEN_SIZE_GRAN_MASK)<<_FS_MODE_OPEN_SIZE_GRAN_OFFSET) | \
147 ((_u32)((Size) & _FS_MODE_OPEN_SIZE_MASK)<<_FS_MODE_OPEN_SIZE_OFFSET) | \
148 ((_u32)((Flags) & _FS_MODE_ACCESS_FLAGS_MASK)<<_FS_MODE_ACCESS_FLAGS_OFFSET))
153 #define FS_MODE_OPEN_READ _FS_MODE(_FS_MODE_OPEN_READ,0,0,0)
155 #define FS_MODE_OPEN_WRITE _FS_MODE(_FS_MODE_OPEN_WRITE,0,0,0)
157 #define FS_MODE_OPEN_CREATE(maxSizeInBytes,accessModeFlags) _sl_GetCreateFsMode(maxSizeInBytes,accessModeFlags)
172 _FS_MODE_OPEN_READ = 0,
174 _FS_MODE_OPEN_CREATE,
175 _FS_MODE_OPEN_WRITE_CREATE_IF_NOT_EXIST
176 }SlFsFileOpenAccessType_e;
180 _FS_FILE_OPEN_FLAG_COMMIT = 0x1,
181 _FS_FILE_OPEN_FLAG_SECURE = 0x2,
182 _FS_FILE_OPEN_FLAG_NO_SIGNATURE_TEST = 0x4,
183 _FS_FILE_OPEN_FLAG_STATIC = 0x8,
184 _FS_FILE_OPEN_FLAG_VENDOR = 0x10,
185 _FS_FILE_PUBLIC_WRITE= 0x20,
186 _FS_FILE_PUBLIC_READ = 0x40
191 _FS_MODE_SIZE_GRAN_256B = 0,
192 _FS_MODE_SIZE_GRAN_1KB,
193 _FS_MODE_SIZE_GRAN_4KB,
194 _FS_MODE_SIZE_GRAN_16KB,
195 _FS_MODE_SIZE_GRAN_64KB,
196 _FS_MAX_MODE_SIZE_GRAN
197 }_SlFsFileOpenMaxSizeGran_e;
202 _u32 _sl_GetCreateFsMode(_u32 maxSizeInBytes,_u32 accessFlags);
260 #if _SL_INCLUDE_FUNC(sl_FsOpen)
261 _i32
sl_FsOpen(
const _u8 *pFileName,
const _u32 AccessModeAndMaxSize,_u32 *pToken,_i32 *pFileHandle);
283 #if _SL_INCLUDE_FUNC(sl_FsClose)
284 _i16
sl_FsClose(
const _i32 FileHdl,
const _u8* pCeritificateFileName,
const _u8* pSignature,
const _u32 SignatureLen);
305 #if _SL_INCLUDE_FUNC(sl_FsRead)
306 _i32
sl_FsRead(
const _i32 FileHdl,_u32 Offset ,_u8* pData,_u32 Len);
327 #if _SL_INCLUDE_FUNC(sl_FsWrite)
328 _i32
sl_FsWrite(
const _i32 FileHdl,_u32 Offset,_u8* pData,_u32 Len);
348 #if _SL_INCLUDE_FUNC(sl_FsGetInfo)
367 #if _SL_INCLUDE_FUNC(sl_FsDel)
368 _i16
sl_FsDel(
const _u8 *pFileName,
const _u32 Token);
_i16 sl_FsGetInfo(const _u8 *pFileName, const _u32 Token, SlFsFileInfo_t *pFsFileInfo)
get info on a file
_i16 sl_FsClose(const _i32 FileHdl, const _u8 *pCeritificateFileName, const _u8 *pSignature, const _u32 SignatureLen)
close file in storage device
_i32 sl_FsOpen(const _u8 *pFileName, const _u32 AccessModeAndMaxSize, _u32 *pToken, _i32 *pFileHandle)
open file for read or write from/to storage device
_i16 sl_FsDel(const _u8 *pFileName, const _u32 Token)
Delete specific file from a storage or all files from a storage (format)
_i32 sl_FsWrite(const _i32 FileHdl, _u32 Offset, _u8 *pData, _u32 Len)
write block of data to a file in storage device
_i32 sl_FsRead(const _i32 FileHdl, _u32 Offset, _u8 *pData, _u32 Len)
Read block of data from a file in storage device.