fsl_ftfx_controller.h 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836
  1. /*
  2. * The Clear BSD License
  3. * Copyright 2013-2016 Freescale Semiconductor, Inc.
  4. * Copyright 2016-2018 NXP
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted (subject to the limitations in the
  9. * disclaimer below) provided that the following conditions 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 distribution.
  17. *
  18. * * Neither the name of the copyright holder nor the names of its
  19. * contributors may be used to endorse or promote products derived from
  20. * this software without specific prior written permission.
  21. *
  22. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
  23. * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
  24. * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
  25. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  26. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  28. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  29. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  30. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  31. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  32. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  33. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  34. * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. *
  36. */
  37. #ifndef _FSL_FTFX_CONTROLLER_H_
  38. #define _FSL_FTFX_CONTROLLER_H_
  39. #include "fsl_ftfx_features.h"
  40. #include "fsl_ftfx_utilities.h"
  41. /*******************************************************************************
  42. * Definitions
  43. ******************************************************************************/
  44. /* Component ID definition, used by tools. */
  45. #ifndef FSL_COMPONENT_ID
  46. #define FSL_COMPONENT_ID "platform.drivers.flash"
  47. #endif
  48. /*!
  49. * @name FTFx status
  50. * @{
  51. */
  52. /*! @brief FTFx driver status group. */
  53. #if defined(kStatusGroup_FlashDriver)
  54. #define kStatusGroupGeneric kStatusGroup_Generic
  55. #define kStatusGroupFtfxDriver kStatusGroup_FlashDriver
  56. #elif defined(kStatusGroup_FLASH)
  57. #define kStatusGroupGeneric kStatusGroup_Generic
  58. #define kStatusGroupFtfxDriver kStatusGroup_FLASH
  59. #else
  60. #define kStatusGroupGeneric 0
  61. #define kStatusGroupFtfxDriver 1
  62. #endif
  63. /*!
  64. * @brief FTFx driver status codes.
  65. */
  66. enum _ftfx_status
  67. {
  68. kStatus_FTFx_Success = MAKE_STATUS(kStatusGroupGeneric, 0), /*!< API is executed successfully*/
  69. kStatus_FTFx_InvalidArgument = MAKE_STATUS(kStatusGroupGeneric, 4), /*!< Invalid argument*/
  70. kStatus_FTFx_SizeError = MAKE_STATUS(kStatusGroupFtfxDriver, 0), /*!< Error size*/
  71. kStatus_FTFx_AlignmentError =
  72. MAKE_STATUS(kStatusGroupFtfxDriver, 1), /*!< Parameter is not aligned with the specified baseline*/
  73. kStatus_FTFx_AddressError = MAKE_STATUS(kStatusGroupFtfxDriver, 2), /*!< Address is out of range */
  74. kStatus_FTFx_AccessError =
  75. MAKE_STATUS(kStatusGroupFtfxDriver, 3), /*!< Invalid instruction codes and out-of bound addresses */
  76. kStatus_FTFx_ProtectionViolation = MAKE_STATUS(
  77. kStatusGroupFtfxDriver, 4), /*!< The program/erase operation is requested to execute on protected areas */
  78. kStatus_FTFx_CommandFailure =
  79. MAKE_STATUS(kStatusGroupFtfxDriver, 5), /*!< Run-time error during command execution. */
  80. kStatus_FTFx_UnknownProperty = MAKE_STATUS(kStatusGroupFtfxDriver, 6), /*!< Unknown property.*/
  81. kStatus_FTFx_EraseKeyError = MAKE_STATUS(kStatusGroupFtfxDriver, 7), /*!< API erase key is invalid.*/
  82. kStatus_FTFx_RegionExecuteOnly =
  83. MAKE_STATUS(kStatusGroupFtfxDriver, 8), /*!< The current region is execute-only.*/
  84. kStatus_FTFx_ExecuteInRamFunctionNotReady =
  85. MAKE_STATUS(kStatusGroupFtfxDriver, 9), /*!< Execute-in-RAM function is not available.*/
  86. kStatus_FTFx_PartitionStatusUpdateFailure =
  87. MAKE_STATUS(kStatusGroupFtfxDriver, 10), /*!< Failed to update partition status.*/
  88. kStatus_FTFx_SetFlexramAsEepromError =
  89. MAKE_STATUS(kStatusGroupFtfxDriver, 11), /*!< Failed to set FlexRAM as EEPROM.*/
  90. kStatus_FTFx_RecoverFlexramAsRamError =
  91. MAKE_STATUS(kStatusGroupFtfxDriver, 12), /*!< Failed to recover FlexRAM as RAM.*/
  92. kStatus_FTFx_SetFlexramAsRamError = MAKE_STATUS(kStatusGroupFtfxDriver, 13), /*!< Failed to set FlexRAM as RAM.*/
  93. kStatus_FTFx_RecoverFlexramAsEepromError =
  94. MAKE_STATUS(kStatusGroupFtfxDriver, 14), /*!< Failed to recover FlexRAM as EEPROM.*/
  95. kStatus_FTFx_CommandNotSupported = MAKE_STATUS(kStatusGroupFtfxDriver, 15), /*!< Flash API is not supported.*/
  96. kStatus_FTFx_SwapSystemNotInUninitialized =
  97. MAKE_STATUS(kStatusGroupFtfxDriver, 16), /*!< Swap system is not in an uninitialzed state.*/
  98. kStatus_FTFx_SwapIndicatorAddressError =
  99. MAKE_STATUS(kStatusGroupFtfxDriver, 17), /*!< The swap indicator address is invalid.*/
  100. kStatus_FTFx_ReadOnlyProperty = MAKE_STATUS(kStatusGroupFtfxDriver, 18), /*!< The flash property is read-only.*/
  101. kStatus_FTFx_InvalidPropertyValue =
  102. MAKE_STATUS(kStatusGroupFtfxDriver, 19), /*!< The flash property value is out of range.*/
  103. kStatus_FTFx_InvalidSpeculationOption =
  104. MAKE_STATUS(kStatusGroupFtfxDriver, 20), /*!< The option of flash prefetch speculation is invalid.*/
  105. };
  106. /*@}*/
  107. /*!
  108. * @name FTFx API key
  109. * @{
  110. */
  111. /*!
  112. * @brief Enumeration for FTFx driver API keys.
  113. *
  114. * @note The resulting value is built with a byte order such that the string
  115. * being readable in expected order when viewed in a hex editor, if the value
  116. * is treated as a 32-bit little endian value.
  117. */
  118. enum _ftfx_driver_api_keys
  119. {
  120. kFTFx_ApiEraseKey = FOUR_CHAR_CODE('k', 'f', 'e', 'k') /*!< Key value used to validate all FTFx erase APIs.*/
  121. };
  122. /*@}*/
  123. /*!
  124. * @brief Enumeration for the FlexRAM load during reset option.
  125. */
  126. typedef enum _ftfx_partition_flexram_load_option
  127. {
  128. kFTFx_PartitionFlexramLoadOptLoadedWithValidEepromData =
  129. 0x00U, /*!< FlexRAM is loaded with valid EEPROM data during reset sequence.*/
  130. kFTFx_PartitionFlexramLoadOptNotLoaded = 0x01U /*!< FlexRAM is not loaded during reset sequence.*/
  131. } ftfx_partition_flexram_load_opt_t;
  132. /*!
  133. * @brief Enumeration for the two possible options of flash read resource command.
  134. */
  135. typedef enum _ftfx_read_resource_opt
  136. {
  137. kFTFx_ResourceOptionFlashIfr =
  138. 0x00U, /*!< Select code for Program flash 0 IFR, Program flash swap 0 IFR, Data flash 0 IFR */
  139. kFTFx_ResourceOptionVersionId = 0x01U /*!< Select code for the version ID*/
  140. } ftfx_read_resource_opt_t;
  141. /*!
  142. * @brief Enumeration for supported FTFx margin levels.
  143. */
  144. typedef enum _ftfx_margin_value
  145. {
  146. kFTFx_MarginValueNormal, /*!< Use the 'normal' read level for 1s.*/
  147. kFTFx_MarginValueUser, /*!< Apply the 'User' margin to the normal read-1 level.*/
  148. kFTFx_MarginValueFactory, /*!< Apply the 'Factory' margin to the normal read-1 level.*/
  149. kFTFx_MarginValueInvalid /*!< Not real margin level, Used to determine the range of valid margin level. */
  150. } ftfx_margin_value_t;
  151. /*!
  152. * @brief Enumeration for the three possible FTFx security states.
  153. */
  154. typedef enum _ftfx_security_state
  155. {
  156. kFTFx_SecurityStateNotSecure = 0xc33cc33cU, /*!< Flash is not secure.*/
  157. kFTFx_SecurityStateBackdoorEnabled = 0x5aa55aa5U, /*!< Flash backdoor is enabled.*/
  158. kFTFx_SecurityStateBackdoorDisabled = 0x5ac33ca5U /*!< Flash backdoor is disabled.*/
  159. } ftfx_security_state_t;
  160. /*!
  161. * @brief Enumeration for the two possilbe options of set FlexRAM function command.
  162. */
  163. typedef enum _ftfx_flexram_function_option
  164. {
  165. kFTFx_FlexramFuncOptAvailableAsRam = 0xFFU, /*!< An option used to make FlexRAM available as RAM */
  166. kFTFx_FlexramFuncOptAvailableForEeprom = 0x00U /*!< An option used to make FlexRAM available for EEPROM */
  167. } ftfx_flexram_func_opt_t;
  168. /*!
  169. * @brief Enumeration for the possible options of Swap control commands
  170. */
  171. typedef enum _ftfx_swap_control_option
  172. {
  173. kFTFx_SwapControlOptionIntializeSystem = 0x01U, /*!< An option used to initialize the Swap system */
  174. kFTFx_SwapControlOptionSetInUpdateState = 0x02U, /*!< An option used to set the Swap in an update state */
  175. kFTFx_SwapControlOptionSetInCompleteState = 0x04U, /*!< An option used to set the Swap in a complete state */
  176. kFTFx_SwapControlOptionReportStatus = 0x08U, /*!< An option used to report the Swap status */
  177. kFTFx_SwapControlOptionDisableSystem = 0x10U /*!< An option used to disable the Swap status */
  178. } ftfx_swap_control_opt_t;
  179. /*!
  180. * @brief Enumeration for the possible flash Swap status.
  181. */
  182. typedef enum _ftfx_swap_state
  183. {
  184. kFTFx_SwapStateUninitialized = 0x00U, /*!< Flash Swap system is in an uninitialized state.*/
  185. kFTFx_SwapStateReady = 0x01U, /*!< Flash Swap system is in a ready state.*/
  186. kFTFx_SwapStateUpdate = 0x02U, /*!< Flash Swap system is in an update state.*/
  187. kFTFx_SwapStateUpdateErased = 0x03U, /*!< Flash Swap system is in an updateErased state.*/
  188. kFTFx_SwapStateComplete = 0x04U, /*!< Flash Swap system is in a complete state.*/
  189. kFTFx_SwapStateDisabled = 0x05U /*!< Flash Swap system is in a disabled state.*/
  190. } ftfx_swap_state_t;
  191. /*!
  192. * @breif Enumeration for the possible flash Swap block status
  193. */
  194. typedef enum _ftfx_swap_block_status
  195. {
  196. kFTFx_SwapBlockStatusLowerHalfProgramBlocksAtZero =
  197. 0x00U, /*!< Swap block status is that lower half program block at zero.*/
  198. kFTFx_SwapBlockStatusUpperHalfProgramBlocksAtZero =
  199. 0x01U, /*!< Swap block status is that upper half program block at zero.*/
  200. } ftfx_swap_block_status_t;
  201. /*!
  202. * @brief Flash Swap information
  203. */
  204. typedef struct _ftfx_swap_state_config
  205. {
  206. ftfx_swap_state_t flashSwapState; /*!<The current Swap system status.*/
  207. ftfx_swap_block_status_t currentSwapBlockStatus; /*!< The current Swap block status.*/
  208. ftfx_swap_block_status_t nextSwapBlockStatus; /*!< The next Swap block status.*/
  209. } ftfx_swap_state_config_t;
  210. /*!
  211. * @brief Enumeration for FTFx memory type.
  212. */
  213. enum _ftfx_memory_type
  214. {
  215. kFTFx_MemTypePflash = 0x00U,
  216. kFTFx_MemTypeFlexnvm = 0x01U
  217. } ;
  218. /*!
  219. * @brief ftfx special memory access information.
  220. */
  221. typedef struct _ftfx_special_mem
  222. {
  223. uint32_t base; /*!< Base address of flash special memory.*/
  224. uint32_t size; /*!< size of flash special memory.*/
  225. uint32_t count; /*!< flash special memory count.*/
  226. } ftfx_spec_mem_t;
  227. /*!
  228. * @brief Flash memory descriptor.
  229. */
  230. typedef struct _ftfx_mem_descriptor
  231. {
  232. uint8_t type; /*!< Type of flash block.*/
  233. uint8_t index; /*!< Index of flash block.*/
  234. uint8_t reserved[2];
  235. struct {
  236. uint32_t isIndBlock:1;
  237. uint32_t hasIndPfsizeReg:1;
  238. uint32_t hasProtControl:1;
  239. uint32_t hasIndProtReg:1;
  240. uint32_t hasXaccControl:1;
  241. uint32_t hasIndXaccReg:1;
  242. uint32_t :18;
  243. uint32_t ProtRegBits:8;
  244. } feature;
  245. uint32_t blockBase; /*!< A base address of the flash block */
  246. uint32_t totalSize; /*!< The size of the flash block. */
  247. uint32_t sectorSize; /*!< The size in bytes of a sector of flash. */
  248. uint32_t blockCount; /*!< A number of flash blocks. */
  249. ftfx_spec_mem_t accessSegmentMem;
  250. ftfx_spec_mem_t protectRegionMem;
  251. } ftfx_mem_desc_t;
  252. /*!
  253. * @brief Active FTFx information for the current operation.
  254. */
  255. typedef struct _ftfx_ops_config
  256. {
  257. uint32_t convertedAddress; /*!< A converted address for the current flash type.*/
  258. struct {
  259. uint8_t sectorCmd;
  260. uint8_t sectionCmd;
  261. uint8_t resourceCmd;
  262. uint8_t checkCmd;
  263. uint8_t swapCtrlCmd;
  264. uint8_t blockWriteUnitSize;
  265. uint8_t reserved[2];
  266. } addrAligment;
  267. } ftfx_ops_config_t;
  268. /*!
  269. * @brief Flash IFR memory descriptor.
  270. */
  271. typedef struct _ftfx_ifr_descriptor
  272. {
  273. struct {
  274. uint32_t has4ByteIdxSupport:1;
  275. uint32_t has8ByteIdxSupport:1;
  276. uint32_t :30;
  277. } feature;
  278. struct {
  279. uint8_t versionIdStart;
  280. uint8_t versionIdSize;
  281. uint16_t ifrMemSize;
  282. uint32_t pflashIfrStart;
  283. uint32_t dflashIfrStart;
  284. uint32_t pflashSwapIfrStart;
  285. } resRange;
  286. struct {
  287. uint16_t mix8byteIdxStart;
  288. uint16_t mix8byteIdxEnd;
  289. } idxInfo;
  290. } ftfx_ifr_desc_t;
  291. /*! @brief Flash driver state information.
  292. *
  293. * An instance of this structure is allocated by the user of the flash driver and
  294. * passed into each of the driver APIs.
  295. */
  296. typedef struct _ftfx_config
  297. {
  298. ftfx_mem_desc_t flashDesc;
  299. ftfx_ops_config_t opsConfig;
  300. uint32_t flexramBlockBase; /*!< The base address of the FlexRAM/acceleration RAM */
  301. uint32_t flexramTotalSize; /*!< The size of the FlexRAM/acceleration RAM */
  302. uint16_t eepromTotalSize; /*!< The size of EEPROM area which was partitioned from FlexRAM */
  303. uint16_t reserved;
  304. uint32_t *runCmdFuncAddr; /*!< An buffer point to the flash execute-in-RAM function. */
  305. ftfx_ifr_desc_t ifrDesc;
  306. } ftfx_config_t;
  307. /*******************************************************************************
  308. * API
  309. ******************************************************************************/
  310. #if defined(__cplusplus)
  311. extern "C" {
  312. #endif
  313. /*!
  314. * @name Initialization
  315. * @{
  316. */
  317. /*!
  318. * @brief Initializes the global flash properties structure members.
  319. *
  320. * This function checks and initializes the Flash module for the other Flash APIs.
  321. *
  322. * @param config Pointer to the storage for the driver runtime state.
  323. *
  324. * @retval #kStatus_FTFx_Success API was executed successfully.
  325. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  326. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  327. */
  328. status_t FTFx_API_Init(ftfx_config_t *config);
  329. /*!
  330. * @brief Updates FlexNVM memory partition status according to data flash 0 IFR.
  331. *
  332. * This function updates FlexNVM memory partition status.
  333. *
  334. * @param config Pointer to the storage for the driver runtime state.
  335. *
  336. * @retval #kStatus_FTFx_Success API was executed successfully.
  337. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  338. * @retval #kStatus_FTFx_PartitionStatusUpdateFailure Failed to update the partition status.
  339. */
  340. status_t FTFx_API_UpdateFlexnvmPartitionStatus(ftfx_config_t *config);
  341. /*@}*/
  342. /*!
  343. * @name Erasing
  344. * @{
  345. */
  346. /*!
  347. * @brief Erases the flash sectors encompassed by parameters passed into function.
  348. *
  349. * This function erases the appropriate number of flash sectors based on the
  350. * desired start address and length.
  351. *
  352. * @param config The pointer to the storage for the driver runtime state.
  353. * @param start The start address of the desired flash memory to be erased.
  354. * The start address does not need to be sector-aligned but must be word-aligned.
  355. * @param lengthInBytes The length, given in bytes (not words or long-words)
  356. * to be erased. Must be word-aligned.
  357. * @param key The value used to validate all flash erase APIs.
  358. *
  359. * @retval #kStatus_FTFx_Success API was executed successfully.
  360. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  361. * @retval #kStatus_FTFx_AlignmentError The parameter is not aligned with the specified baseline.
  362. * @retval #kStatus_FTFx_AddressError The address is out of range.
  363. * @retval #kStatus_FTFx_EraseKeyError The API erase key is invalid.
  364. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  365. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  366. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  367. * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
  368. */
  369. status_t FTFx_CMD_Erase(ftfx_config_t *config,
  370. uint32_t start,
  371. uint32_t lengthInBytes,
  372. uint32_t key);
  373. /*!
  374. * @brief Erases entire flash
  375. *
  376. * @param config Pointer to the storage for the driver runtime state.
  377. * @param key A value used to validate all flash erase APIs.
  378. *
  379. * @retval #kStatus_FTFx_Success API was executed successfully.
  380. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  381. * @retval #kStatus_FTFx_EraseKeyError API erase key is invalid.
  382. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  383. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  384. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  385. * @retval #kStatus_FTFx_CommandFailure Run-time error during command execution.
  386. * @retval #kStatus_FTFx_PartitionStatusUpdateFailure Failed to update the partition status.
  387. */
  388. status_t FTFx_CMD_EraseAll(ftfx_config_t *config, uint32_t key);
  389. /*!
  390. * @brief Erases the entire flash, including protected sectors.
  391. *
  392. * @param config Pointer to the storage for the driver runtime state.
  393. * @param key A value used to validate all flash erase APIs.
  394. *
  395. * @retval #kStatus_FTFx_Success API was executed successfully.
  396. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  397. * @retval #kStatus_FTFx_EraseKeyError API erase key is invalid.
  398. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  399. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  400. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  401. * @retval #kStatus_FTFx_CommandFailure Run-time error during command execution.
  402. * @retval #kStatus_FTFx_PartitionStatusUpdateFailure Failed to update the partition status.
  403. */
  404. #if defined(FSL_FEATURE_FLASH_HAS_ERASE_ALL_BLOCKS_UNSECURE_CMD) && FSL_FEATURE_FLASH_HAS_ERASE_ALL_BLOCKS_UNSECURE_CMD
  405. status_t FTFx_CMD_EraseAllUnsecure(ftfx_config_t *config, uint32_t key);
  406. #endif
  407. /*!
  408. * @brief Erases all program flash execute-only segments defined by the FXACC registers.
  409. *
  410. * @param config Pointer to the storage for the driver runtime state.
  411. * @param key A value used to validate all flash erase APIs.
  412. *
  413. * @retval #kStatus_FTFx_Success API was executed successfully.
  414. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  415. * @retval #kStatus_FTFx_EraseKeyError API erase key is invalid.
  416. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  417. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  418. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  419. * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
  420. */
  421. status_t FTFx_CMD_EraseAllExecuteOnlySegments(ftfx_config_t *config, uint32_t key);
  422. /*@}*/
  423. /*!
  424. * @name Programming
  425. * @{
  426. */
  427. /*!
  428. * @brief Programs flash with data at locations passed in through parameters.
  429. *
  430. * This function programs the flash memory with the desired data for a given
  431. * flash area as determined by the start address and the length.
  432. *
  433. * @param config A pointer to the storage for the driver runtime state.
  434. * @param start The start address of the desired flash memory to be programmed. Must be
  435. * word-aligned.
  436. * @param src A pointer to the source buffer of data that is to be programmed
  437. * into the flash.
  438. * @param lengthInBytes The length, given in bytes (not words or long-words),
  439. * to be programmed. Must be word-aligned.
  440. *
  441. * @retval #kStatus_FTFx_Success API was executed successfully.
  442. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  443. * @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with the specified baseline.
  444. * @retval #kStatus_FTFx_AddressError Address is out of range.
  445. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  446. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  447. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  448. * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
  449. */
  450. status_t FTFx_CMD_Program(ftfx_config_t *config,
  451. uint32_t start,
  452. uint8_t *src,
  453. uint32_t lengthInBytes);
  454. /*!
  455. * @brief Programs Program Once Field through parameters.
  456. *
  457. * This function programs the Program Once Field with the desired data for a given
  458. * flash area as determined by the index and length.
  459. *
  460. * @param config A pointer to the storage for the driver runtime state.
  461. * @param index The index indicating which area of the Program Once Field to be programmed.
  462. * @param src A pointer to the source buffer of data that is to be programmed
  463. * into the Program Once Field.
  464. * @param lengthInBytes The length, given in bytes (not words or long-words),
  465. * to be programmed. Must be word-aligned.
  466. *
  467. * @retval #kStatus_FTFx_Success API was executed successfully.
  468. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  469. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  470. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  471. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  472. * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
  473. */
  474. status_t FTFx_CMD_ProgramOnce(ftfx_config_t *config, uint32_t index, uint8_t *src, uint32_t lengthInBytes);
  475. /*!
  476. * @brief Programs flash with data at locations passed in through parameters via the Program Section command.
  477. *
  478. * This function programs the flash memory with the desired data for a given
  479. * flash area as determined by the start address and length.
  480. *
  481. * @param config A pointer to the storage for the driver runtime state.
  482. * @param start The start address of the desired flash memory to be programmed. Must be
  483. * word-aligned.
  484. * @param src A pointer to the source buffer of data that is to be programmed
  485. * into the flash.
  486. * @param lengthInBytes The length, given in bytes (not words or long-words),
  487. * to be programmed. Must be word-aligned.
  488. *
  489. * @retval #kStatus_FTFx_Success API was executed successfully.
  490. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  491. * @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with specified baseline.
  492. * @retval #kStatus_FTFx_AddressError Address is out of range.
  493. * @retval #kStatus_FTFx_SetFlexramAsRamError Failed to set flexram as RAM.
  494. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  495. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  496. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  497. * @retval #kStatus_FTFx_CommandFailure Run-time error during command execution.
  498. * @retval #kStatus_FTFx_RecoverFlexramAsEepromError Failed to recover FlexRAM as EEPROM.
  499. */
  500. #if defined(FSL_FEATURE_FLASH_HAS_PROGRAM_SECTION_CMD) && FSL_FEATURE_FLASH_HAS_PROGRAM_SECTION_CMD
  501. status_t FTFx_CMD_ProgramSection(ftfx_config_t *config,
  502. uint32_t start,
  503. uint8_t *src,
  504. uint32_t lengthInBytes);
  505. #endif
  506. /*!
  507. * @brief Prepares the FlexNVM block for use as data flash, EEPROM backup, or a combination of both and initializes the
  508. * FlexRAM.
  509. *
  510. * @param config Pointer to storage for the driver runtime state.
  511. * @param option The option used to set FlexRAM load behavior during reset.
  512. * @param eepromDataSizeCode Determines the amount of FlexRAM used in each of the available EEPROM subsystems.
  513. * @param flexnvmPartitionCode Specifies how to split the FlexNVM block between data flash memory and EEPROM backup
  514. * memory supporting EEPROM functions.
  515. *
  516. * @retval #kStatus_FTFx_Success API was executed successfully.
  517. * @retval #kStatus_FTFx_InvalidArgument Invalid argument is provided.
  518. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  519. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  520. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  521. * @retval #kStatus_FTFx_CommandFailure Run-time error during command execution.
  522. */
  523. #if defined(FSL_FEATURE_FLASH_HAS_PROGRAM_PARTITION_CMD) && FSL_FEATURE_FLASH_HAS_PROGRAM_PARTITION_CMD
  524. status_t FTFx_CMD_ProgramPartition(ftfx_config_t *config,
  525. ftfx_partition_flexram_load_opt_t option,
  526. uint32_t eepromDataSizeCode,
  527. uint32_t flexnvmPartitionCode);
  528. #endif
  529. /*@}*/
  530. /*!
  531. * @name Reading
  532. * @{
  533. */
  534. /*!
  535. * @brief Reads the Program Once Field through parameters.
  536. *
  537. * This function reads the read once feild with given index and length.
  538. *
  539. * @param config A pointer to the storage for the driver runtime state.
  540. * @param index The index indicating the area of program once field to be read.
  541. * @param dst A pointer to the destination buffer of data that is used to store
  542. * data to be read.
  543. * @param lengthInBytes The length, given in bytes (not words or long-words),
  544. * to be programmed. Must be word-aligned.
  545. *
  546. * @retval #kStatus_FTFx_Success API was executed successfully.
  547. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  548. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  549. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  550. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  551. * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
  552. */
  553. status_t FTFx_CMD_ReadOnce(ftfx_config_t *config, uint32_t index, uint8_t *dst, uint32_t lengthInBytes);
  554. /*!
  555. * @brief Reads the resource with data at locations passed in through parameters.
  556. *
  557. * This function reads the flash memory with the desired location for a given
  558. * flash area as determined by the start address and length.
  559. *
  560. * @param config A pointer to the storage for the driver runtime state.
  561. * @param start The start address of the desired flash memory to be programmed. Must be
  562. * word-aligned.
  563. * @param dst A pointer to the destination buffer of data that is used to store
  564. * data to be read.
  565. * @param lengthInBytes The length, given in bytes (not words or long-words),
  566. * to be read. Must be word-aligned.
  567. * @param option The resource option which indicates which area should be read back.
  568. *
  569. * @retval #kStatus_FTFx_Success API was executed successfully.
  570. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  571. * @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with the specified baseline.
  572. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  573. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  574. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  575. * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
  576. */
  577. #if defined(FSL_FEATURE_FLASH_HAS_READ_RESOURCE_CMD) && FSL_FEATURE_FLASH_HAS_READ_RESOURCE_CMD
  578. status_t FTFx_CMD_ReadResource(ftfx_config_t *config,
  579. uint32_t start,
  580. uint8_t *dst,
  581. uint32_t lengthInBytes,
  582. ftfx_read_resource_opt_t option);
  583. #endif
  584. /*@}*/
  585. /*!
  586. * @name Verification
  587. * @{
  588. */
  589. /*!
  590. * @brief Verifies an erasure of the desired flash area at a specified margin level.
  591. *
  592. * This function checks the appropriate number of flash sectors based on
  593. * the desired start address and length to check whether the flash is erased
  594. * to the specified read margin level.
  595. *
  596. * @param config A pointer to the storage for the driver runtime state.
  597. * @param start The start address of the desired flash memory to be verified.
  598. * The start address does not need to be sector-aligned but must be word-aligned.
  599. * @param lengthInBytes The length, given in bytes (not words or long-words),
  600. * to be verified. Must be word-aligned.
  601. * @param margin Read margin choice.
  602. *
  603. * @retval #kStatus_FTFx_Success API was executed successfully.
  604. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  605. * @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with specified baseline.
  606. * @retval #kStatus_FTFx_AddressError Address is out of range.
  607. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  608. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  609. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  610. * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
  611. */
  612. status_t FTFx_CMD_VerifyErase(ftfx_config_t *config,
  613. uint32_t start,
  614. uint32_t lengthInBytes,
  615. ftfx_margin_value_t margin);
  616. /*!
  617. * @brief Verifies erasure of the entire flash at a specified margin level.
  618. *
  619. * This function checks whether the flash is erased to the
  620. * specified read margin level.
  621. *
  622. * @param config A pointer to the storage for the driver runtime state.
  623. * @param margin Read margin choice.
  624. *
  625. * @retval #kStatus_FTFx_Success API was executed successfully.
  626. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  627. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  628. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  629. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  630. * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
  631. */
  632. status_t FTFx_CMD_VerifyEraseAll(ftfx_config_t *config, ftfx_margin_value_t margin);
  633. /*!
  634. * @brief Verifies whether the program flash execute-only segments have been erased to
  635. * the specified read margin level.
  636. *
  637. * @param config A pointer to the storage for the driver runtime state.
  638. * @param margin Read margin choice.
  639. *
  640. * @retval #kStatus_FTFx_Success API was executed successfully.
  641. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  642. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  643. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  644. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  645. * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
  646. */
  647. status_t FTFx_CMD_VerifyEraseAllExecuteOnlySegments(ftfx_config_t *config, ftfx_margin_value_t margin);
  648. /*!
  649. * @brief Verifies programming of the desired flash area at a specified margin level.
  650. *
  651. * This function verifies the data programed in the flash memory using the
  652. * Flash Program Check Command and compares it to the expected data for a given
  653. * flash area as determined by the start address and length.
  654. *
  655. * @param config A pointer to the storage for the driver runtime state.
  656. * @param start The start address of the desired flash memory to be verified. Must be word-aligned.
  657. * @param lengthInBytes The length, given in bytes (not words or long-words),
  658. * to be verified. Must be word-aligned.
  659. * @param expectedData A pointer to the expected data that is to be
  660. * verified against.
  661. * @param margin Read margin choice.
  662. * @param failedAddress A pointer to the returned failing address.
  663. * @param failedData A pointer to the returned failing data. Some derivatives do
  664. * not include failed data as part of the FCCOBx registers. In this
  665. * case, zeros are returned upon failure.
  666. *
  667. * @retval #kStatus_FTFx_Success API was executed successfully.
  668. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  669. * @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with specified baseline.
  670. * @retval #kStatus_FTFx_AddressError Address is out of range.
  671. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  672. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  673. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  674. * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
  675. */
  676. status_t FTFx_CMD_VerifyProgram(ftfx_config_t *config,
  677. uint32_t start,
  678. uint32_t lengthInBytes,
  679. const uint8_t *expectedData,
  680. ftfx_margin_value_t margin,
  681. uint32_t *failedAddress,
  682. uint32_t *failedData);
  683. /*@}*/
  684. /*!
  685. * @name Security
  686. * @{
  687. */
  688. /*!
  689. * @brief Returns the security state via the pointer passed into the function.
  690. *
  691. * This function retrieves the current flash security status, including the
  692. * security enabling state and the backdoor key enabling state.
  693. *
  694. * @param config A pointer to storage for the driver runtime state.
  695. * @param state A pointer to the value returned for the current security status code:
  696. *
  697. * @retval #kStatus_FTFx_Success API was executed successfully.
  698. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  699. */
  700. status_t FTFx_REG_GetSecurityState(ftfx_config_t *config, ftfx_security_state_t *state);
  701. /*!
  702. * @brief Allows users to bypass security with a backdoor key.
  703. *
  704. * If the MCU is in secured state, this function unsecures the MCU by
  705. * comparing the provided backdoor key with ones in the flash configuration
  706. * field.
  707. *
  708. * @param config A pointer to the storage for the driver runtime state.
  709. * @param backdoorKey A pointer to the user buffer containing the backdoor key.
  710. *
  711. * @retval #kStatus_FTFx_Success API was executed successfully.
  712. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  713. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  714. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  715. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  716. * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
  717. */
  718. status_t FTFx_CMD_SecurityBypass(ftfx_config_t *config, const uint8_t *backdoorKey);
  719. /*@}*/
  720. /*!
  721. * @name FlexRAM
  722. * @{
  723. */
  724. /*!
  725. * @brief Sets the FlexRAM function command.
  726. *
  727. * @param config A pointer to the storage for the driver runtime state.
  728. * @param option The option used to set the work mode of FlexRAM.
  729. *
  730. * @retval #kStatus_FTFx_Success API was executed successfully.
  731. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  732. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  733. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  734. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  735. * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
  736. */
  737. #if defined(FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD) && FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD
  738. status_t FTFx_CMD_SetFlexramFunction(ftfx_config_t *config, ftfx_flexram_func_opt_t option);
  739. #endif
  740. /*@}*/
  741. /*!
  742. * @name Swap
  743. * @{
  744. */
  745. /*!
  746. * @brief Configures the Swap function or checks the swap state of the Flash module.
  747. *
  748. * @param config A pointer to the storage for the driver runtime state.
  749. * @param address Address used to configure the flash Swap function.
  750. * @param option The possible option used to configure Flash Swap function or check the flash Swap status
  751. * @param returnInfo A pointer to the data which is used to return the information of flash Swap.
  752. *
  753. * @retval #kStatus_FTFx_Success API was executed successfully.
  754. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  755. * @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with specified baseline.
  756. * @retval #kStatus_FTFx_SwapIndicatorAddressError Swap indicator address is invalid.
  757. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  758. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  759. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  760. * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
  761. */
  762. #if defined(FSL_FEATURE_FLASH_HAS_SWAP_CONTROL_CMD) && FSL_FEATURE_FLASH_HAS_SWAP_CONTROL_CMD
  763. status_t FTFx_CMD_SwapControl(ftfx_config_t *config,
  764. uint32_t address,
  765. ftfx_swap_control_opt_t option,
  766. ftfx_swap_state_config_t *returnInfo);
  767. #endif
  768. /*@}*/
  769. #if defined(__cplusplus)
  770. }
  771. #endif
  772. #endif /* _FSL_FTFX_CONTROLLER_H_ */