fsl_ftfx_flash.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  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_FLASH_H_
  38. #define _FSL_FTFX_FLASH_H_
  39. #include "fsl_ftfx_controller.h"
  40. /*!
  41. * @addtogroup ftfx_flash_driver
  42. * @{
  43. */
  44. /*******************************************************************************
  45. * Definitions
  46. ******************************************************************************/
  47. #define kStatus_FLASH_Success kStatus_FTFx_Success
  48. #define kFLASH_ApiEraseKey kFTFx_ApiEraseKey
  49. /*!
  50. * @name Flash version
  51. * @{
  52. */
  53. /*! @brief Flash driver version for SDK*/
  54. #define FSL_FLASH_DRIVER_VERSION (MAKE_VERSION(3, 0, 0)) /*!< Version 3.0.0. */
  55. /*! @brief Flash driver version for ROM*/
  56. enum _flash_driver_version_constants
  57. {
  58. kFLASH_DriverVersionName = 'F', /*!< Flash driver version name.*/
  59. kFLASH_DriverVersionMajor = 3, /*!< Major flash driver version.*/
  60. kFLASH_DriverVersionMinor = 0, /*!< Minor flash driver version.*/
  61. kFLASH_DriverVersionBugfix = 0 /*!< Bugfix for flash driver version.*/
  62. };
  63. /*@}*/
  64. /*!
  65. * @brief Enumeration for the three possible flash protection levels.
  66. */
  67. typedef enum _flash_protection_state
  68. {
  69. kFLASH_ProtectionStateUnprotected, /*!< Flash region is not protected.*/
  70. kFLASH_ProtectionStateProtected, /*!< Flash region is protected.*/
  71. kFLASH_ProtectionStateMixed /*!< Flash is mixed with protected and unprotected region.*/
  72. } flash_prot_state_t;
  73. /*!
  74. * @brief Enumeration for the three possible flash execute access levels.
  75. */
  76. typedef enum _flash_execute_only_access_state
  77. {
  78. kFLASH_AccessStateUnLimited, /*!< Flash region is unlimited.*/
  79. kFLASH_AccessStateExecuteOnly, /*!< Flash region is execute only.*/
  80. kFLASH_AccessStateMixed /*!< Flash is mixed with unlimited and execute only region.*/
  81. } flash_xacc_state_t;
  82. /*!
  83. * @brief PFlash protection status
  84. */
  85. typedef union _pflash_protection_status
  86. {
  87. uint32_t protl; /*!< PROT[31:0] .*/
  88. uint32_t proth; /*!< PROT[63:32].*/
  89. uint8_t protsl; /*!< PROTS[7:0] .*/
  90. uint8_t protsh; /*!< PROTS[15:8] .*/
  91. uint8_t reserved[2];
  92. } pflash_prot_status_t;
  93. /*!
  94. * @brief Enumeration for various flash properties.
  95. */
  96. typedef enum _flash_property_tag
  97. {
  98. kFLASH_PropertyPflash0SectorSize = 0x00U, /*!< Pflash sector size property.*/
  99. kFLASH_PropertyPflash0TotalSize = 0x01U, /*!< Pflash total size property.*/
  100. kFLASH_PropertyPflash0BlockSize = 0x02U, /*!< Pflash block size property.*/
  101. kFLASH_PropertyPflash0BlockCount = 0x03U, /*!< Pflash block count property.*/
  102. kFLASH_PropertyPflash0BlockBaseAddr = 0x04U, /*!< Pflash block base address property.*/
  103. kFLASH_PropertyPflash0FacSupport = 0x05U, /*!< Pflash fac support property.*/
  104. kFLASH_PropertyPflash0AccessSegmentSize = 0x06U, /*!< Pflash access segment size property.*/
  105. kFLASH_PropertyPflash0AccessSegmentCount = 0x07U, /*!< Pflash access segment count property.*/
  106. kFLASH_PropertyPflash1SectorSize = 0x10U, /*!< Pflash sector size property.*/
  107. kFLASH_PropertyPflash1TotalSize = 0x11U, /*!< Pflash total size property.*/
  108. kFLASH_PropertyPflash1BlockSize = 0x12U, /*!< Pflash block size property.*/
  109. kFLASH_PropertyPflash1BlockCount = 0x13U, /*!< Pflash block count property.*/
  110. kFLASH_PropertyPflash1BlockBaseAddr = 0x14U, /*!< Pflash block base address property.*/
  111. kFLASH_PropertyPflash1FacSupport = 0x15U, /*!< Pflash fac support property.*/
  112. kFLASH_PropertyPflash1AccessSegmentSize = 0x16U, /*!< Pflash access segment size property.*/
  113. kFLASH_PropertyPflash1AccessSegmentCount = 0x17U, /*!< Pflash access segment count property.*/
  114. kFLASH_PropertyFlexRamBlockBaseAddr = 0x20U, /*!< FlexRam block base address property.*/
  115. kFLASH_PropertyFlexRamTotalSize = 0x21U, /*!< FlexRam total size property.*/
  116. } flash_property_tag_t;
  117. /*! @brief Flash driver state information.
  118. *
  119. * An instance of this structure is allocated by the user of the flash driver and
  120. * passed into each of the driver APIs.
  121. */
  122. typedef struct _flash_config
  123. {
  124. ftfx_config_t ftfxConfig[FTFx_FLASH_COUNT];
  125. } flash_config_t;
  126. /*******************************************************************************
  127. * API
  128. ******************************************************************************/
  129. #if defined(__cplusplus)
  130. extern "C" {
  131. #endif
  132. /*!
  133. * @name Initialization
  134. * @{
  135. */
  136. /*!
  137. * @brief Initializes the global flash properties structure members.
  138. *
  139. * This function checks and initializes the Flash module for the other Flash APIs.
  140. *
  141. * @param config Pointer to the storage for the driver runtime state.
  142. *
  143. * @retval #kStatus_FTFx_Success API was executed successfully.
  144. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  145. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  146. * @retval #kStatus_FTFx_PartitionStatusUpdateFailure Failed to update the partition status.
  147. */
  148. status_t FLASH_Init(flash_config_t *config);
  149. /*@}*/
  150. /*!
  151. * @name Erasing
  152. * @{
  153. */
  154. /*!
  155. * @brief Erases the Dflash sectors encompassed by parameters passed into function.
  156. *
  157. * This function erases the appropriate number of flash sectors based on the
  158. * desired start address and length.
  159. *
  160. * @param config The pointer to the storage for the driver runtime state.
  161. * @param start The start address of the desired flash memory to be erased.
  162. * The start address does not need to be sector-aligned but must be word-aligned.
  163. * @param lengthInBytes The length, given in bytes (not words or long-words)
  164. * to be erased. Must be word-aligned.
  165. * @param key The value used to validate all flash erase APIs.
  166. *
  167. * @retval #kStatus_FTFx_Success API was executed successfully.
  168. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  169. * @retval #kStatus_FTFx_AlignmentError The parameter is not aligned with the specified baseline.
  170. * @retval #kStatus_FTFx_AddressError The address is out of range.
  171. * @retval #kStatus_FTFx_EraseKeyError The API erase key is invalid.
  172. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  173. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  174. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  175. * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
  176. */
  177. status_t FLASH_Erase(flash_config_t *config,
  178. uint32_t start,
  179. uint32_t lengthInBytes,
  180. uint32_t key);
  181. /*!
  182. * @brief Erases entire flexnvm
  183. *
  184. * @param config Pointer to the storage for the driver runtime state.
  185. * @param key A value used to validate all flash erase APIs.
  186. *
  187. * @retval #kStatus_FTFx_Success API was executed successfully.
  188. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  189. * @retval #kStatus_FTFx_EraseKeyError API erase key is invalid.
  190. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  191. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  192. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  193. * @retval #kStatus_FTFx_CommandFailure Run-time error during command execution.
  194. * @retval #kStatus_FTFx_PartitionStatusUpdateFailure Failed to update the partition status.
  195. */
  196. status_t FLASH_EraseAll(flash_config_t *config, uint32_t key);
  197. /*!
  198. * @brief Erases the entire flexnvm, including protected sectors.
  199. *
  200. * @param config Pointer to the storage for the driver runtime state.
  201. * @param key A value used to validate all flash erase APIs.
  202. *
  203. * @retval #kStatus_FTFx_Success API was executed successfully.
  204. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  205. * @retval #kStatus_FTFx_EraseKeyError API erase key is invalid.
  206. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  207. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  208. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  209. * @retval #kStatus_FTFx_CommandFailure Run-time error during command execution.
  210. * @retval #kStatus_FTFx_PartitionStatusUpdateFailure Failed to update the partition status.
  211. */
  212. #if defined(FSL_FEATURE_FLASH_HAS_ERASE_ALL_BLOCKS_UNSECURE_CMD) && FSL_FEATURE_FLASH_HAS_ERASE_ALL_BLOCKS_UNSECURE_CMD
  213. status_t FLASH_EraseAllUnsecure(flash_config_t *config, uint32_t key);
  214. #endif
  215. /*@}*/
  216. /*!
  217. * @name Programming
  218. * @{
  219. */
  220. /*!
  221. * @brief Programs flash with data at locations passed in through parameters.
  222. *
  223. * This function programs the flash memory with the desired data for a given
  224. * flash area as determined by the start address and the length.
  225. *
  226. * @param config A pointer to the storage for the driver runtime state.
  227. * @param start The start address of the desired flash memory to be programmed. Must be
  228. * word-aligned.
  229. * @param src A pointer to the source buffer of data that is to be programmed
  230. * into the flash.
  231. * @param lengthInBytes The length, given in bytes (not words or long-words),
  232. * to be programmed. Must be word-aligned.
  233. *
  234. * @retval #kStatus_FTFx_Success API was executed successfully.
  235. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  236. * @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with the specified baseline.
  237. * @retval #kStatus_FTFx_AddressError Address is out of range.
  238. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  239. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  240. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  241. * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
  242. */
  243. status_t FLASH_Program(flash_config_t *config,
  244. uint32_t start,
  245. uint8_t *src,
  246. uint32_t lengthInBytes);
  247. /*!
  248. * @brief Programs flash with data at locations passed in through parameters via the Program Section command.
  249. *
  250. * This function programs the flash memory with the desired data for a given
  251. * flash area as determined by the start address and length.
  252. *
  253. * @param config A pointer to the storage for the driver runtime state.
  254. * @param start The start address of the desired flash memory to be programmed. Must be
  255. * word-aligned.
  256. * @param src A pointer to the source buffer of data that is to be programmed
  257. * into the flash.
  258. * @param lengthInBytes The length, given in bytes (not words or long-words),
  259. * to be programmed. Must be word-aligned.
  260. *
  261. * @retval #kStatus_FTFx_Success API was executed successfully.
  262. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  263. * @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with specified baseline.
  264. * @retval #kStatus_FTFx_AddressError Address is out of range.
  265. * @retval #kStatus_FTFx_SetFlexramAsRamError Failed to set flexram as RAM.
  266. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  267. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  268. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  269. * @retval #kStatus_FTFx_CommandFailure Run-time error during command execution.
  270. * @retval #kStatus_FTFx_RecoverFlexramAsEepromError Failed to recover FlexRAM as EEPROM.
  271. */
  272. #if defined(FSL_FEATURE_FLASH_HAS_PROGRAM_SECTION_CMD) && FSL_FEATURE_FLASH_HAS_PROGRAM_SECTION_CMD
  273. status_t FLASH_ProgramSection(flash_config_t *config,
  274. uint32_t start,
  275. uint8_t *src,
  276. uint32_t lengthInBytes);
  277. #endif
  278. /*@}*/
  279. /*!
  280. * @name Reading
  281. * @{
  282. */
  283. /*!
  284. * @brief Reads the resource with data at locations passed in through parameters.
  285. *
  286. * This function reads the flash memory with the desired location for a given
  287. * flash area as determined by the start address and length.
  288. *
  289. * @param config A pointer to the storage for the driver runtime state.
  290. * @param start The start address of the desired flash memory to be programmed. Must be
  291. * word-aligned.
  292. * @param dst A pointer to the destination buffer of data that is used to store
  293. * data to be read.
  294. * @param lengthInBytes The length, given in bytes (not words or long-words),
  295. * to be read. Must be word-aligned.
  296. * @param option The resource option which indicates which area should be read back.
  297. *
  298. * @retval #kStatus_FTFx_Success API was executed successfully.
  299. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  300. * @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with the specified baseline.
  301. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  302. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  303. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  304. * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
  305. */
  306. #if defined(FSL_FEATURE_FLASH_HAS_READ_RESOURCE_CMD) && FSL_FEATURE_FLASH_HAS_READ_RESOURCE_CMD
  307. status_t FLASH_ReadResource(flash_config_t *config,
  308. uint32_t start,
  309. uint8_t *dst,
  310. uint32_t lengthInBytes,
  311. ftfx_read_resource_opt_t option);
  312. #endif
  313. /*@}*/
  314. /*!
  315. * @name Verification
  316. * @{
  317. */
  318. /*!
  319. * @brief Verifies an erasure of the desired flash area at a specified margin level.
  320. *
  321. * This function checks the appropriate number of flash sectors based on
  322. * the desired start address and length to check whether the flash is erased
  323. * to the specified read margin level.
  324. *
  325. * @param config A pointer to the storage for the driver runtime state.
  326. * @param start The start address of the desired flash memory to be verified.
  327. * The start address does not need to be sector-aligned but must be word-aligned.
  328. * @param lengthInBytes The length, given in bytes (not words or long-words),
  329. * to be verified. Must be word-aligned.
  330. * @param margin Read margin choice.
  331. *
  332. * @retval #kStatus_FTFx_Success API was executed successfully.
  333. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  334. * @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with specified baseline.
  335. * @retval #kStatus_FTFx_AddressError Address is out of range.
  336. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  337. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  338. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  339. * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
  340. */
  341. status_t FLASH_VerifyErase(flash_config_t *config,
  342. uint32_t start,
  343. uint32_t lengthInBytes,
  344. ftfx_margin_value_t margin);
  345. /*!
  346. * @brief Verifies erasure of the entire flash at a specified margin level.
  347. *
  348. * This function checks whether the flash is erased to the
  349. * specified read margin level.
  350. *
  351. * @param config A pointer to the storage for the driver runtime state.
  352. * @param margin Read margin choice.
  353. *
  354. * @retval #kStatus_FTFx_Success API was executed successfully.
  355. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  356. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  357. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  358. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  359. * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
  360. */
  361. status_t FLASH_VerifyEraseAll(flash_config_t *config, ftfx_margin_value_t margin);
  362. /*!
  363. * @brief Verifies programming of the desired flash area at a specified margin level.
  364. *
  365. * This function verifies the data programed in the flash memory using the
  366. * Flash Program Check Command and compares it to the expected data for a given
  367. * flash area as determined by the start address and length.
  368. *
  369. * @param config A pointer to the storage for the driver runtime state.
  370. * @param start The start address of the desired flash memory to be verified. Must be word-aligned.
  371. * @param lengthInBytes The length, given in bytes (not words or long-words),
  372. * to be verified. Must be word-aligned.
  373. * @param expectedData A pointer to the expected data that is to be
  374. * verified against.
  375. * @param margin Read margin choice.
  376. * @param failedAddress A pointer to the returned failing address.
  377. * @param failedData A pointer to the returned failing data. Some derivatives do
  378. * not include failed data as part of the FCCOBx registers. In this
  379. * case, zeros are returned upon failure.
  380. *
  381. * @retval #kStatus_FTFx_Success API was executed successfully.
  382. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  383. * @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with specified baseline.
  384. * @retval #kStatus_FTFx_AddressError Address is out of range.
  385. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  386. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  387. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  388. * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
  389. */
  390. status_t FLASH_VerifyProgram(flash_config_t *config,
  391. uint32_t start,
  392. uint32_t lengthInBytes,
  393. const uint8_t *expectedData,
  394. ftfx_margin_value_t margin,
  395. uint32_t *failedAddress,
  396. uint32_t *failedData);
  397. /*@}*/
  398. /*!
  399. * @name Security
  400. * @{
  401. */
  402. /*!
  403. * @brief Returns the security state via the pointer passed into the function.
  404. *
  405. * This function retrieves the current flash security status, including the
  406. * security enabling state and the backdoor key enabling state.
  407. *
  408. * @param config A pointer to storage for the driver runtime state.
  409. * @param state A pointer to the value returned for the current security status code:
  410. *
  411. * @retval #kStatus_FTFx_Success API was executed successfully.
  412. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  413. */
  414. status_t FLASH_GetSecurityState(flash_config_t *config, ftfx_security_state_t *state);
  415. /*!
  416. * @brief Allows users to bypass security with a backdoor key.
  417. *
  418. * If the MCU is in secured state, this function unsecures the MCU by
  419. * comparing the provided backdoor key with ones in the flash configuration
  420. * field.
  421. *
  422. * @param config A pointer to the storage for the driver runtime state.
  423. * @param backdoorKey A pointer to the user buffer containing the backdoor key.
  424. *
  425. * @retval #kStatus_FTFx_Success API was executed successfully.
  426. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  427. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  428. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  429. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  430. * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
  431. */
  432. status_t FLASH_SecurityBypass(flash_config_t *config, const uint8_t *backdoorKey);
  433. /*@}*/
  434. /*!
  435. * @name FlexRAM
  436. * @{
  437. */
  438. /*!
  439. * @brief Sets the FlexRAM function command.
  440. *
  441. * @param config A pointer to the storage for the driver runtime state.
  442. * @param option The option used to set the work mode of FlexRAM.
  443. *
  444. * @retval #kStatus_FTFx_Success API was executed successfully.
  445. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  446. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  447. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  448. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  449. * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
  450. */
  451. #if defined(FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD) && FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD
  452. status_t FLASH_SetFlexramFunction(flash_config_t *config, ftfx_flexram_func_opt_t option);
  453. #endif
  454. /*@}*/
  455. /*!
  456. * @name Swap
  457. * @{
  458. */
  459. /*!
  460. * @brief Swaps the lower half flash with the higher half flash.
  461. *
  462. * @param config A pointer to the storage for the driver runtime state.
  463. * @param address Address used to configure the flash swap function
  464. * @param isSetEnable The possible option used to configure the Flash Swap function or check the flash Swap status.
  465. *
  466. * @retval #kStatus_FTFx_Success API was executed successfully.
  467. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  468. * @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with specified baseline.
  469. * @retval #kStatus_FTFx_SwapIndicatorAddressError Swap indicator address is invalid.
  470. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  471. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  472. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  473. * @retval #kStatus_FTFx_CommandFailure Run-time error during command execution.
  474. * @retval #kStatus_FTFx_SwapSystemNotInUninitialized Swap system is not in an uninitialzed state.
  475. */
  476. #if defined(FSL_FEATURE_FLASH_HAS_PFLASH_BLOCK_SWAP) && FSL_FEATURE_FLASH_HAS_PFLASH_BLOCK_SWAP
  477. status_t FLASH_Swap(flash_config_t *config, uint32_t address, bool isSetEnable);
  478. #endif
  479. /*@}*/
  480. /*!
  481. * @name Protection
  482. * @{
  483. */
  484. /*!
  485. * @brief Returns the protection state of the desired flash area via the pointer passed into the function.
  486. *
  487. * This function retrieves the current flash protect status for a given
  488. * flash area as determined by the start address and length.
  489. *
  490. * @param config A pointer to the storage for the driver runtime state.
  491. * @param start The start address of the desired flash memory to be checked. Must be word-aligned.
  492. * @param lengthInBytes The length, given in bytes (not words or long-words)
  493. * to be checked. Must be word-aligned.
  494. * @param protection_state A pointer to the value returned for the current
  495. * protection status code for the desired flash area.
  496. *
  497. * @retval #kStatus_FTFx_Success API was executed successfully.
  498. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  499. * @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with specified baseline.
  500. * @retval #kStatus_FTFx_AddressError The address is out of range.
  501. */
  502. status_t FLASH_IsProtected(flash_config_t *config,
  503. uint32_t start,
  504. uint32_t lengthInBytes,
  505. flash_prot_state_t *protection_state);
  506. /*!
  507. * @brief Returns the access state of the desired flash area via the pointer passed into the function.
  508. *
  509. * This function retrieves the current flash access status for a given
  510. * flash area as determined by the start address and length.
  511. *
  512. * @param config A pointer to the storage for the driver runtime state.
  513. * @param start The start address of the desired flash memory to be checked. Must be word-aligned.
  514. * @param lengthInBytes The length, given in bytes (not words or long-words),
  515. * to be checked. Must be word-aligned.
  516. * @param access_state A pointer to the value returned for the current
  517. * access status code for the desired flash area.
  518. *
  519. * @retval #kStatus_FTFx_Success API was executed successfully.
  520. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  521. * @retval #kStatus_FTFx_AlignmentError The parameter is not aligned to the specified baseline.
  522. * @retval #kStatus_FTFx_AddressError The address is out of range.
  523. */
  524. status_t FLASH_IsExecuteOnly(flash_config_t *config,
  525. uint32_t start,
  526. uint32_t lengthInBytes,
  527. flash_xacc_state_t *access_state);
  528. /*!
  529. * @brief Sets the PFlash Protection to the intended protection status.
  530. *
  531. * @param config A pointer to storage for the driver runtime state.
  532. * @param protectStatus The expected protect status to set to the PFlash protection register. Each bit is
  533. * corresponding to protection of 1/32(64) of the total PFlash. The least significant bit is corresponding to the lowest
  534. * address area of PFlash. The most significant bit is corresponding to the highest address area of PFlash. There are
  535. * two possible cases as shown below:
  536. * 0: this area is protected.
  537. * 1: this area is unprotected.
  538. *
  539. * @retval #kStatus_FTFx_Success API was executed successfully.
  540. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  541. * @retval #kStatus_FTFx_CommandFailure Run-time error during command execution.
  542. */
  543. status_t FLASH_PflashSetProtection(flash_config_t *config, pflash_prot_status_t *protectStatus);
  544. /*!
  545. * @brief Gets the PFlash protection status.
  546. *
  547. * @param config A pointer to the storage for the driver runtime state.
  548. * @param protectStatus Protect status returned by the PFlash IP. Each bit is corresponding to the protection of
  549. * 1/32(64)
  550. * of the
  551. * total PFlash. The least significant bit corresponds to the lowest address area of the PFlash. The most significant
  552. * bit corresponds to the highest address area of PFlash. There are two possible cases as shown below:
  553. * 0: this area is protected.
  554. * 1: this area is unprotected.
  555. *
  556. * @retval #kStatus_FTFx_Success API was executed successfully.
  557. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  558. */
  559. status_t FLASH_PflashGetProtection(flash_config_t *config, pflash_prot_status_t *protectStatus);
  560. /*@}*/
  561. /*!
  562. * @name Properties
  563. * @{
  564. */
  565. /*!
  566. * @brief Returns the desired flash property.
  567. *
  568. * @param config A pointer to the storage for the driver runtime state.
  569. * @param whichProperty The desired property from the list of properties in
  570. * enum flash_property_tag_t
  571. * @param value A pointer to the value returned for the desired flash property.
  572. *
  573. * @retval #kStatus_FTFx_Success API was executed successfully.
  574. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  575. * @retval #kStatus_FTFx_UnknownProperty An unknown property tag.
  576. */
  577. status_t FLASH_GetProperty(flash_config_t *config, flash_property_tag_t whichProperty, uint32_t *value);
  578. /*@}*/
  579. #if defined(__cplusplus)
  580. }
  581. #endif
  582. /*! @}*/
  583. #endif /* _FSL_FTFX_FLASH_H_ */