You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

664 rivejä
30 KiB

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