rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
fsl_ftfx_controller.h
Go to the documentation of this file.
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
38#ifndef _FSL_FTFX_CONTROLLER_H_
39#define _FSL_FTFX_CONTROLLER_H_
40
41#include "fsl_ftfx_features.h"
42#include "fsl_ftfx_utilities.h"
43
44/*******************************************************************************
45 * Definitions
46 ******************************************************************************/
47
48/* Component ID definition, used by tools. */
49#ifndef FSL_COMPONENT_ID
50#define FSL_COMPONENT_ID "platform.drivers.flash"
51#endif
52
53/*!
54 * @name FTFx status
55 * @{
56 */
57/*! @brief FTFx driver status group. */
58#if defined(kStatusGroup_FlashDriver)
59#define kStatusGroupGeneric kStatusGroup_Generic
60#define kStatusGroupFtfxDriver kStatusGroup_FlashDriver
61#elif defined(kStatusGroup_FLASH)
62#define kStatusGroupGeneric kStatusGroup_Generic
63#define kStatusGroupFtfxDriver kStatusGroup_FLASH
64#else
65#define kStatusGroupGeneric 0
66#define kStatusGroupFtfxDriver 1
67#endif
68
69/*!
70 * @brief FTFx driver status codes.
71 */
73{
74 kStatus_FTFx_Success = MAKE_STATUS(kStatusGroupGeneric, 0), /*!< API is executed successfully*/
75 kStatus_FTFx_InvalidArgument = MAKE_STATUS(kStatusGroupGeneric, 4), /*!< Invalid argument*/
76 kStatus_FTFx_SizeError = MAKE_STATUS(kStatusGroupFtfxDriver, 0), /*!< Error size*/
78 MAKE_STATUS(kStatusGroupFtfxDriver, 1), /*!< Parameter is not aligned with the specified baseline*/
79 kStatus_FTFx_AddressError = MAKE_STATUS(kStatusGroupFtfxDriver, 2), /*!< Address is out of range */
81 MAKE_STATUS(kStatusGroupFtfxDriver, 3), /*!< Invalid instruction codes and out-of bound addresses */
83 kStatusGroupFtfxDriver, 4), /*!< The program/erase operation is requested to execute on protected areas */
85 MAKE_STATUS(kStatusGroupFtfxDriver, 5), /*!< Run-time error during command execution. */
86 kStatus_FTFx_UnknownProperty = MAKE_STATUS(kStatusGroupFtfxDriver, 6), /*!< Unknown property.*/
87 kStatus_FTFx_EraseKeyError = MAKE_STATUS(kStatusGroupFtfxDriver, 7), /*!< API erase key is invalid.*/
89 MAKE_STATUS(kStatusGroupFtfxDriver, 8), /*!< The current region is execute-only.*/
91 MAKE_STATUS(kStatusGroupFtfxDriver, 9), /*!< Execute-in-RAM function is not available.*/
93 MAKE_STATUS(kStatusGroupFtfxDriver, 10), /*!< Failed to update partition status.*/
95 MAKE_STATUS(kStatusGroupFtfxDriver, 11), /*!< Failed to set FlexRAM as EEPROM.*/
97 MAKE_STATUS(kStatusGroupFtfxDriver, 12), /*!< Failed to recover FlexRAM as RAM.*/
98 kStatus_FTFx_SetFlexramAsRamError = MAKE_STATUS(kStatusGroupFtfxDriver, 13), /*!< Failed to set FlexRAM as RAM.*/
100 MAKE_STATUS(kStatusGroupFtfxDriver, 14), /*!< Failed to recover FlexRAM as EEPROM.*/
101 kStatus_FTFx_CommandNotSupported = MAKE_STATUS(kStatusGroupFtfxDriver, 15), /*!< Flash API is not supported.*/
103 MAKE_STATUS(kStatusGroupFtfxDriver, 16), /*!< Swap system is not in an uninitialzed state.*/
105 MAKE_STATUS(kStatusGroupFtfxDriver, 17), /*!< The swap indicator address is invalid.*/
106 kStatus_FTFx_ReadOnlyProperty = MAKE_STATUS(kStatusGroupFtfxDriver, 18), /*!< The flash property is read-only.*/
108 MAKE_STATUS(kStatusGroupFtfxDriver, 19), /*!< The flash property value is out of range.*/
110 MAKE_STATUS(kStatusGroupFtfxDriver, 20), /*!< The option of flash prefetch speculation is invalid.*/
111};
112/*@}*/
113
114/*!
115 * @name FTFx API key
116 * @{
117 */
118/*!
119 * @brief Enumeration for FTFx driver API keys.
120 *
121 * @note The resulting value is built with a byte order such that the string
122 * being readable in expected order when viewed in a hex editor, if the value
123 * is treated as a 32-bit little endian value.
124 */
126{
127 kFTFx_ApiEraseKey = FOUR_CHAR_CODE('k', 'f', 'e', 'k') /*!< Key value used to validate all FTFx erase APIs.*/
129/*@}*/
130
131/*!
132 * @brief Enumeration for the FlexRAM load during reset option.
133 */
135{
137 0x00U, /*!< FlexRAM is loaded with valid EEPROM data during reset sequence.*/
138 kFTFx_PartitionFlexramLoadOptNotLoaded = 0x01U /*!< FlexRAM is not loaded during reset sequence.*/
140
141/*!
142 * @brief Enumeration for the two possible options of flash read resource command.
143 */
145{
147 0x00U, /*!< Select code for Program flash 0 IFR, Program flash swap 0 IFR, Data flash 0 IFR */
148 kFTFx_ResourceOptionVersionId = 0x01U /*!< Select code for the version ID*/
150
151/*!
152 * @brief Enumeration for supported FTFx margin levels.
153 */
155{
156 kFTFx_MarginValueNormal, /*!< Use the 'normal' read level for 1s.*/
157 kFTFx_MarginValueUser, /*!< Apply the 'User' margin to the normal read-1 level.*/
158 kFTFx_MarginValueFactory, /*!< Apply the 'Factory' margin to the normal read-1 level.*/
159 kFTFx_MarginValueInvalid /*!< Not real margin level, Used to determine the range of valid margin level. */
161
162/*!
163 * @brief Enumeration for the three possible FTFx security states.
164 */
166{
167 kFTFx_SecurityStateNotSecure = 0xc33cc33cU, /*!< Flash is not secure.*/
168 kFTFx_SecurityStateBackdoorEnabled = 0x5aa55aa5U, /*!< Flash backdoor is enabled.*/
169 kFTFx_SecurityStateBackdoorDisabled = 0x5ac33ca5U /*!< Flash backdoor is disabled.*/
171
172/*!
173 * @brief Enumeration for the two possilbe options of set FlexRAM function command.
174 */
176{
177 kFTFx_FlexramFuncOptAvailableAsRam = 0xFFU, /*!< An option used to make FlexRAM available as RAM */
178 kFTFx_FlexramFuncOptAvailableForEeprom = 0x00U /*!< An option used to make FlexRAM available for EEPROM */
180
181/*!
182 * @brief Enumeration for the possible options of Swap control commands
183 */
185{
186 kFTFx_SwapControlOptionIntializeSystem = 0x01U, /*!< An option used to initialize the Swap system */
187 kFTFx_SwapControlOptionSetInUpdateState = 0x02U, /*!< An option used to set the Swap in an update state */
188 kFTFx_SwapControlOptionSetInCompleteState = 0x04U, /*!< An option used to set the Swap in a complete state */
189 kFTFx_SwapControlOptionReportStatus = 0x08U, /*!< An option used to report the Swap status */
190 kFTFx_SwapControlOptionDisableSystem = 0x10U /*!< An option used to disable the Swap status */
192
193/*!
194 * @brief Enumeration for the possible flash Swap status.
195 */
197{
198 kFTFx_SwapStateUninitialized = 0x00U, /*!< Flash Swap system is in an uninitialized state.*/
199 kFTFx_SwapStateReady = 0x01U, /*!< Flash Swap system is in a ready state.*/
200 kFTFx_SwapStateUpdate = 0x02U, /*!< Flash Swap system is in an update state.*/
201 kFTFx_SwapStateUpdateErased = 0x03U, /*!< Flash Swap system is in an updateErased state.*/
202 kFTFx_SwapStateComplete = 0x04U, /*!< Flash Swap system is in a complete state.*/
203 kFTFx_SwapStateDisabled = 0x05U /*!< Flash Swap system is in a disabled state.*/
205
206/*!
207 * @breif Enumeration for the possible flash Swap block status
208 */
210{
212 0x00U, /*!< Swap block status is that lower half program block at zero.*/
214 0x01U, /*!< Swap block status is that upper half program block at zero.*/
216
217/*!
218 * @brief Flash Swap information
219 */
221{
222 ftfx_swap_state_t flashSwapState; /*!<The current Swap system status.*/
223 ftfx_swap_block_status_t currentSwapBlockStatus; /*!< The current Swap block status.*/
224 ftfx_swap_block_status_t nextSwapBlockStatus; /*!< The next Swap block status.*/
226
227/*!
228 * @brief Enumeration for FTFx memory type.
229 */
235
236/*!
237 * @brief ftfx special memory access information.
238 */
239typedef struct _ftfx_special_mem
240{
241 uint32_t base; /*!< Base address of flash special memory.*/
242 uint32_t size; /*!< size of flash special memory.*/
243 uint32_t count; /*!< flash special memory count.*/
245
246/*!
247 * @brief Flash memory descriptor.
248 */
250{
251 uint8_t type; /*!< Type of flash block.*/
252 uint8_t index; /*!< Index of flash block.*/
253 uint8_t reserved[2];
254 struct {
255 uint32_t isIndBlock:1;
256 uint32_t hasIndPfsizeReg:1;
257 uint32_t hasProtControl:1;
258 uint32_t hasIndProtReg:1;
259 uint32_t hasXaccControl:1;
260 uint32_t hasIndXaccReg:1;
261 uint32_t :18;
262 uint32_t ProtRegBits:8;
264 uint32_t blockBase; /*!< A base address of the flash block */
265 uint32_t totalSize; /*!< The size of the flash block. */
266 uint32_t sectorSize; /*!< The size in bytes of a sector of flash. */
267 uint32_t blockCount; /*!< A number of flash blocks. */
271
272/*!
273 * @brief Active FTFx information for the current operation.
274 */
275typedef struct _ftfx_ops_config
276{
277 uint32_t convertedAddress; /*!< A converted address for the current flash type.*/
278 struct {
279 uint8_t sectorCmd;
280 uint8_t sectionCmd;
281 uint8_t resourceCmd;
282 uint8_t checkCmd;
283 uint8_t swapCtrlCmd;
285 uint8_t reserved[2];
288
289/*!
290 * @brief Flash IFR memory descriptor.
291 */
293{
294 struct {
297 uint32_t :30;
299 struct {
302 uint16_t ifrMemSize;
307 struct {
312
313/*! @brief Flash driver state information.
314 *
315 * An instance of this structure is allocated by the user of the flash driver and
316 * passed into each of the driver APIs.
317 */
318typedef struct _ftfx_config
319{
322 uint32_t flexramBlockBase; /*!< The base address of the FlexRAM/acceleration RAM */
323 uint32_t flexramTotalSize; /*!< The size of the FlexRAM/acceleration RAM */
324 uint16_t eepromTotalSize; /*!< The size of EEPROM area which was partitioned from FlexRAM */
325 uint16_t reserved;
326 uint32_t *runCmdFuncAddr; /*!< An buffer point to the flash execute-in-RAM function. */
329
330/*******************************************************************************
331 * API
332 ******************************************************************************/
333
334#if defined(__cplusplus)
335extern "C" {
336#endif
337
338/*!
339 * @name Initialization
340 * @{
341 */
342
343/*!
344 * @brief Initializes the global flash properties structure members.
345 *
346 * This function checks and initializes the Flash module for the other Flash APIs.
347 *
348 * @param config Pointer to the storage for the driver runtime state.
349 *
350 * @retval #kStatus_FTFx_Success API was executed successfully.
351 * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
352 * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
353 */
355
356/*!
357 * @brief Updates FlexNVM memory partition status according to data flash 0 IFR.
358 *
359 * This function updates FlexNVM memory partition status.
360 *
361 * @param config Pointer to the storage for the driver runtime state.
362 *
363 * @retval #kStatus_FTFx_Success API was executed successfully.
364 * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
365 * @retval #kStatus_FTFx_PartitionStatusUpdateFailure Failed to update the partition status.
366 */
368
369/*@}*/
370
371/*!
372 * @name Erasing
373 * @{
374 */
375
376/*!
377 * @brief Erases the flash sectors encompassed by parameters passed into function.
378 *
379 * This function erases the appropriate number of flash sectors based on the
380 * desired start address and length.
381 *
382 * @param config The pointer to the storage for the driver runtime state.
383 * @param start The start address of the desired flash memory to be erased.
384 * The start address does not need to be sector-aligned but must be word-aligned.
385 * @param lengthInBytes The length, given in bytes (not words or long-words)
386 * to be erased. Must be word-aligned.
387 * @param key The value used to validate all flash erase APIs.
388 *
389 * @retval #kStatus_FTFx_Success API was executed successfully.
390 * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
391 * @retval #kStatus_FTFx_AlignmentError The parameter is not aligned with the specified baseline.
392 * @retval #kStatus_FTFx_AddressError The address is out of range.
393 * @retval #kStatus_FTFx_EraseKeyError The API erase key is invalid.
394 * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
395 * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
396 * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
397 * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
398 */
400 uint32_t start,
401 uint32_t lengthInBytes,
402 uint32_t key);
403
404/*!
405 * @brief Erases entire flash
406 *
407 * @param config Pointer to the storage for the driver runtime state.
408 * @param key A value used to validate all flash erase APIs.
409 *
410 * @retval #kStatus_FTFx_Success API was executed successfully.
411 * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
412 * @retval #kStatus_FTFx_EraseKeyError API erase key is invalid.
413 * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
414 * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
415 * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
416 * @retval #kStatus_FTFx_CommandFailure Run-time error during command execution.
417 * @retval #kStatus_FTFx_PartitionStatusUpdateFailure Failed to update the partition status.
418 */
420
421/*!
422 * @brief Erases the entire flash, including protected sectors.
423 *
424 * @param config Pointer to the storage for the driver runtime state.
425 * @param key A value used to validate all flash erase APIs.
426 *
427 * @retval #kStatus_FTFx_Success API was executed successfully.
428 * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
429 * @retval #kStatus_FTFx_EraseKeyError API erase key is invalid.
430 * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
431 * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
432 * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
433 * @retval #kStatus_FTFx_CommandFailure Run-time error during command execution.
434 * @retval #kStatus_FTFx_PartitionStatusUpdateFailure Failed to update the partition status.
435 */
436#if defined(FSL_FEATURE_FLASH_HAS_ERASE_ALL_BLOCKS_UNSECURE_CMD) && FSL_FEATURE_FLASH_HAS_ERASE_ALL_BLOCKS_UNSECURE_CMD
438#endif
439
440/*!
441 * @brief Erases all program flash execute-only segments defined by the FXACC registers.
442 *
443 * @param config Pointer to the storage for the driver runtime state.
444 * @param key A value used to validate all flash erase APIs.
445 *
446 * @retval #kStatus_FTFx_Success API was executed successfully.
447 * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
448 * @retval #kStatus_FTFx_EraseKeyError API erase key is invalid.
449 * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
450 * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
451 * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
452 * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
453 */
455
456/*@}*/
457
458/*!
459 * @name Programming
460 * @{
461 */
462
463/*!
464 * @brief Programs flash with data at locations passed in through parameters.
465 *
466 * This function programs the flash memory with the desired data for a given
467 * flash area as determined by the start address and the length.
468 *
469 * @param config A pointer to the storage for the driver runtime state.
470 * @param start The start address of the desired flash memory to be programmed. Must be
471 * word-aligned.
472 * @param src A pointer to the source buffer of data that is to be programmed
473 * into the flash.
474 * @param lengthInBytes The length, given in bytes (not words or long-words),
475 * to be programmed. Must be word-aligned.
476 *
477 * @retval #kStatus_FTFx_Success API was executed successfully.
478 * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
479 * @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with the specified baseline.
480 * @retval #kStatus_FTFx_AddressError Address is out of range.
481 * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
482 * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
483 * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
484 * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
485 */
487 uint32_t start,
488 uint8_t *src,
489 uint32_t lengthInBytes);
490
491/*!
492 * @brief Programs Program Once Field through parameters.
493 *
494 * This function programs the Program Once Field with the desired data for a given
495 * flash area as determined by the index and length.
496 *
497 * @param config A pointer to the storage for the driver runtime state.
498 * @param index The index indicating which area of the Program Once Field to be programmed.
499 * @param src A pointer to the source buffer of data that is to be programmed
500 * into the Program Once Field.
501 * @param lengthInBytes The length, given in bytes (not words or long-words),
502 * to be programmed. Must be word-aligned.
503 *
504 * @retval #kStatus_FTFx_Success API was executed successfully.
505 * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
506 * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
507 * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
508 * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
509 * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
510 */
511status_t FTFx_CMD_ProgramOnce(ftfx_config_t *config, uint32_t index, uint8_t *src, uint32_t lengthInBytes);
512
513/*!
514 * @brief Programs flash with data at locations passed in through parameters via the Program Section command.
515 *
516 * This function programs the flash memory with the desired data for a given
517 * flash area as determined by the start address and length.
518 *
519 * @param config A pointer to the storage for the driver runtime state.
520 * @param start The start address of the desired flash memory to be programmed. Must be
521 * word-aligned.
522 * @param src A pointer to the source buffer of data that is to be programmed
523 * into the flash.
524 * @param lengthInBytes The length, given in bytes (not words or long-words),
525 * to be programmed. Must be word-aligned.
526 *
527 * @retval #kStatus_FTFx_Success API was executed successfully.
528 * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
529 * @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with specified baseline.
530 * @retval #kStatus_FTFx_AddressError Address is out of range.
531 * @retval #kStatus_FTFx_SetFlexramAsRamError Failed to set flexram as RAM.
532 * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
533 * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
534 * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
535 * @retval #kStatus_FTFx_CommandFailure Run-time error during command execution.
536 * @retval #kStatus_FTFx_RecoverFlexramAsEepromError Failed to recover FlexRAM as EEPROM.
537 */
538#if defined(FSL_FEATURE_FLASH_HAS_PROGRAM_SECTION_CMD) && FSL_FEATURE_FLASH_HAS_PROGRAM_SECTION_CMD
540 uint32_t start,
541 uint8_t *src,
542 uint32_t lengthInBytes);
543#endif
544
545/*!
546 * @brief Prepares the FlexNVM block for use as data flash, EEPROM backup, or a combination of both and initializes the
547 * FlexRAM.
548 *
549 * @param config Pointer to storage for the driver runtime state.
550 * @param option The option used to set FlexRAM load behavior during reset.
551 * @param eepromDataSizeCode Determines the amount of FlexRAM used in each of the available EEPROM subsystems.
552 * @param flexnvmPartitionCode Specifies how to split the FlexNVM block between data flash memory and EEPROM backup
553 * memory supporting EEPROM functions.
554 *
555 * @retval #kStatus_FTFx_Success API was executed successfully.
556 * @retval #kStatus_FTFx_InvalidArgument Invalid argument is provided.
557 * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
558 * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
559 * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
560 * @retval #kStatus_FTFx_CommandFailure Run-time error during command execution.
561 */
562#if defined(FSL_FEATURE_FLASH_HAS_PROGRAM_PARTITION_CMD) && FSL_FEATURE_FLASH_HAS_PROGRAM_PARTITION_CMD
565 uint32_t eepromDataSizeCode,
566 uint32_t flexnvmPartitionCode);
567#endif
568
569/*@}*/
570
571/*!
572 * @name Reading
573 * @{
574 */
575
576/*!
577 * @brief Reads the Program Once Field through parameters.
578 *
579 * This function reads the read once feild with given index and length.
580 *
581 * @param config A pointer to the storage for the driver runtime state.
582 * @param index The index indicating the area of program once field to be read.
583 * @param dst A pointer to the destination buffer of data that is used to store
584 * data to be read.
585 * @param lengthInBytes The length, given in bytes (not words or long-words),
586 * to be programmed. Must be word-aligned.
587 *
588 * @retval #kStatus_FTFx_Success API was executed successfully.
589 * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
590 * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
591 * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
592 * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
593 * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
594 */
595status_t FTFx_CMD_ReadOnce(ftfx_config_t *config, uint32_t index, uint8_t *dst, uint32_t lengthInBytes);
596
597/*!
598 * @brief Reads the resource with data at locations passed in through parameters.
599 *
600 * This function reads the flash memory with the desired location for a given
601 * flash area as determined by the start address and length.
602 *
603 * @param config A pointer to the storage for the driver runtime state.
604 * @param start The start address of the desired flash memory to be programmed. Must be
605 * word-aligned.
606 * @param dst A pointer to the destination buffer of data that is used to store
607 * data to be read.
608 * @param lengthInBytes The length, given in bytes (not words or long-words),
609 * to be read. Must be word-aligned.
610 * @param option The resource option which indicates which area should be read back.
611 *
612 * @retval #kStatus_FTFx_Success API was executed successfully.
613 * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
614 * @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with the specified baseline.
615 * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
616 * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
617 * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
618 * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
619 */
620#if defined(FSL_FEATURE_FLASH_HAS_READ_RESOURCE_CMD) && FSL_FEATURE_FLASH_HAS_READ_RESOURCE_CMD
622 uint32_t start,
623 uint8_t *dst,
624 uint32_t lengthInBytes,
626#endif
627
628/*@}*/
629
630/*!
631 * @name Verification
632 * @{
633 */
634
635/*!
636 * @brief Verifies an erasure of the desired flash area at a specified margin level.
637 *
638 * This function checks the appropriate number of flash sectors based on
639 * the desired start address and length to check whether the flash is erased
640 * to the specified read margin level.
641 *
642 * @param config A pointer to the storage for the driver runtime state.
643 * @param start The start address of the desired flash memory to be verified.
644 * The start address does not need to be sector-aligned but must be word-aligned.
645 * @param lengthInBytes The length, given in bytes (not words or long-words),
646 * to be verified. Must be word-aligned.
647 * @param margin Read margin choice.
648 *
649 * @retval #kStatus_FTFx_Success API was executed successfully.
650 * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
651 * @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with specified baseline.
652 * @retval #kStatus_FTFx_AddressError Address is out of range.
653 * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
654 * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
655 * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
656 * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
657 */
659 uint32_t start,
660 uint32_t lengthInBytes,
661 ftfx_margin_value_t margin);
662
663/*!
664 * @brief Verifies erasure of the entire flash at a specified margin level.
665 *
666 * This function checks whether the flash is erased to the
667 * specified read margin level.
668 *
669 * @param config A pointer to the storage for the driver runtime state.
670 * @param margin Read margin choice.
671 *
672 * @retval #kStatus_FTFx_Success API was executed successfully.
673 * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
674 * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
675 * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
676 * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
677 * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
678 */
680
681/*!
682 * @brief Verifies whether the program flash execute-only segments have been erased to
683 * the specified read margin level.
684 *
685 * @param config A pointer to the storage for the driver runtime state.
686 * @param margin Read margin choice.
687 *
688 * @retval #kStatus_FTFx_Success API was executed successfully.
689 * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
690 * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
691 * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
692 * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
693 * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
694 */
696
697/*!
698 * @brief Verifies programming of the desired flash area at a specified margin level.
699 *
700 * This function verifies the data programed in the flash memory using the
701 * Flash Program Check Command and compares it to the expected data for a given
702 * flash area as determined by the start address and length.
703 *
704 * @param config A pointer to the storage for the driver runtime state.
705 * @param start The start address of the desired flash memory to be verified. Must be word-aligned.
706 * @param lengthInBytes The length, given in bytes (not words or long-words),
707 * to be verified. Must be word-aligned.
708 * @param expectedData A pointer to the expected data that is to be
709 * verified against.
710 * @param margin Read margin choice.
711 * @param failedAddress A pointer to the returned failing address.
712 * @param failedData A pointer to the returned failing data. Some derivatives do
713 * not include failed data as part of the FCCOBx registers. In this
714 * case, zeros are returned upon failure.
715 *
716 * @retval #kStatus_FTFx_Success API was executed successfully.
717 * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
718 * @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with specified baseline.
719 * @retval #kStatus_FTFx_AddressError Address is out of range.
720 * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
721 * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
722 * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
723 * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
724 */
726 uint32_t start,
727 uint32_t lengthInBytes,
728 const uint8_t *expectedData,
729 ftfx_margin_value_t margin,
730 uint32_t *failedAddress,
731 uint32_t *failedData);
732
733/*@}*/
734
735/*!
736 * @name Security
737 * @{
738 */
739
740/*!
741 * @brief Returns the security state via the pointer passed into the function.
742 *
743 * This function retrieves the current flash security status, including the
744 * security enabling state and the backdoor key enabling state.
745 *
746 * @param config A pointer to storage for the driver runtime state.
747 * @param state A pointer to the value returned for the current security status code:
748 *
749 * @retval #kStatus_FTFx_Success API was executed successfully.
750 * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
751 */
753
754/*!
755 * @brief Allows users to bypass security with a backdoor key.
756 *
757 * If the MCU is in secured state, this function unsecures the MCU by
758 * comparing the provided backdoor key with ones in the flash configuration
759 * field.
760 *
761 * @param config A pointer to the storage for the driver runtime state.
762 * @param backdoorKey A pointer to the user buffer containing the backdoor key.
763 *
764 * @retval #kStatus_FTFx_Success API was executed successfully.
765 * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
766 * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
767 * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
768 * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
769 * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
770 */
771status_t FTFx_CMD_SecurityBypass(ftfx_config_t *config, const uint8_t *backdoorKey);
772
773/*@}*/
774
775/*!
776 * @name FlexRAM
777 * @{
778 */
779
780/*!
781 * @brief Sets the FlexRAM function command.
782 *
783 * @param config A pointer to the storage for the driver runtime state.
784 * @param option The option used to set the work mode of FlexRAM.
785 *
786 * @retval #kStatus_FTFx_Success API was executed successfully.
787 * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
788 * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
789 * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
790 * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
791 * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
792 */
793#if defined(FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD) && FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD
795#endif
796
797/*@}*/
798
799/*!
800 * @name Swap
801 * @{
802 */
803
804/*!
805 * @brief Configures the Swap function or checks the swap state of the Flash module.
806 *
807 * @param config A pointer to the storage for the driver runtime state.
808 * @param address Address used to configure the flash Swap function.
809 * @param option The possible option used to configure Flash Swap function or check the flash Swap status
810 * @param returnInfo A pointer to the data which is used to return the information of flash Swap.
811 *
812 * @retval #kStatus_FTFx_Success API was executed successfully.
813 * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
814 * @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with specified baseline.
815 * @retval #kStatus_FTFx_SwapIndicatorAddressError Swap indicator address is invalid.
816 * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
817 * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
818 * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
819 * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
820 */
821#if defined(FSL_FEATURE_FLASH_HAS_SWAP_CONTROL_CMD) && FSL_FEATURE_FLASH_HAS_SWAP_CONTROL_CMD
823 uint32_t address,
825 ftfx_swap_state_config_t *returnInfo);
826#endif
827
828/*@}*/
829
830#if defined(__cplusplus)
831}
832#endif
833
834
835#endif /* _FSL_FTFX_CONTROLLER_H_ */
836
static constexpr persistent_config_s * config
status_t FTFx_CMD_SwapControl(ftfx_config_t *config, uint32_t address, ftfx_swap_control_opt_t option, ftfx_swap_state_config_t *returnInfo)
Configures the Swap function or checks the swap state of the Flash module.
enum _ftfx_read_resource_opt ftfx_read_resource_opt_t
Enumeration for the two possible options of flash read resource command.
_ftfx_security_state
Enumeration for the three possible FTFx security states.
@ kFTFx_SecurityStateBackdoorEnabled
@ kFTFx_SecurityStateNotSecure
@ kFTFx_SecurityStateBackdoorDisabled
enum _ftfx_swap_control_option ftfx_swap_control_opt_t
Enumeration for the possible options of Swap control commands.
struct _ftfx_ops_config ftfx_ops_config_t
Active FTFx information for the current operation.
status_t FTFx_CMD_Program(ftfx_config_t *config, uint32_t start, uint8_t *src, uint32_t lengthInBytes)
Programs flash with data at locations passed in through parameters.
_ftfx_swap_control_option
Enumeration for the possible options of Swap control commands.
@ kFTFx_SwapControlOptionReportStatus
@ kFTFx_SwapControlOptionSetInCompleteState
@ kFTFx_SwapControlOptionDisableSystem
@ kFTFx_SwapControlOptionSetInUpdateState
@ kFTFx_SwapControlOptionIntializeSystem
status_t FTFx_REG_GetSecurityState(ftfx_config_t *config, ftfx_security_state_t *state)
Returns the security state via the pointer passed into the function.
status_t FTFx_CMD_ProgramSection(ftfx_config_t *config, uint32_t start, uint8_t *src, uint32_t lengthInBytes)
Programs flash with data at locations passed in through parameters via the Program Section command.
struct _ftfx_swap_state_config ftfx_swap_state_config_t
Flash Swap information.
status_t FTFx_CMD_VerifyProgram(ftfx_config_t *config, uint32_t start, uint32_t lengthInBytes, const uint8_t *expectedData, ftfx_margin_value_t margin, uint32_t *failedAddress, uint32_t *failedData)
Verifies programming of the desired flash area at a specified margin level.
status_t FTFx_API_UpdateFlexnvmPartitionStatus(ftfx_config_t *config)
Updates FlexNVM memory partition status according to data flash 0 IFR.
status_t FTFx_CMD_ProgramOnce(ftfx_config_t *config, uint32_t index, uint8_t *src, uint32_t lengthInBytes)
Programs Program Once Field through parameters.
status_t FTFx_API_Init(ftfx_config_t *config)
Initializes the global flash properties structure members.
_ftfx_status
FTFx driver status codes.
@ kStatus_FTFx_AlignmentError
@ kStatus_FTFx_SetFlexramAsRamError
@ kStatus_FTFx_RegionExecuteOnly
@ kStatus_FTFx_SizeError
@ kStatus_FTFx_CommandFailure
@ kStatus_FTFx_UnknownProperty
@ kStatus_FTFx_RecoverFlexramAsRamError
@ kStatus_FTFx_EraseKeyError
@ kStatus_FTFx_RecoverFlexramAsEepromError
@ kStatus_FTFx_Success
@ kStatus_FTFx_InvalidArgument
@ kStatus_FTFx_AddressError
@ kStatus_FTFx_ReadOnlyProperty
@ kStatus_FTFx_ExecuteInRamFunctionNotReady
@ kStatus_FTFx_SwapSystemNotInUninitialized
@ kStatus_FTFx_InvalidPropertyValue
@ kStatus_FTFx_InvalidSpeculationOption
@ kStatus_FTFx_PartitionStatusUpdateFailure
@ kStatus_FTFx_CommandNotSupported
@ kStatus_FTFx_SwapIndicatorAddressError
@ kStatus_FTFx_ProtectionViolation
@ kStatus_FTFx_AccessError
@ kStatus_FTFx_SetFlexramAsEepromError
struct _ftfx_special_mem ftfx_spec_mem_t
ftfx special memory access information.
enum _ftfx_swap_block_status ftfx_swap_block_status_t
_ftfx_partition_flexram_load_option
Enumeration for the FlexRAM load during reset option.
@ kFTFx_PartitionFlexramLoadOptNotLoaded
@ kFTFx_PartitionFlexramLoadOptLoadedWithValidEepromData
status_t FTFx_CMD_EraseAll(ftfx_config_t *config, uint32_t key)
Erases entire flash.
status_t FTFx_CMD_EraseAllUnsecure(ftfx_config_t *config, uint32_t key)
Erases the entire flash, including protected sectors.
enum _ftfx_margin_value ftfx_margin_value_t
Enumeration for supported FTFx margin levels.
_ftfx_flexram_function_option
Enumeration for the two possilbe options of set FlexRAM function command.
@ kFTFx_FlexramFuncOptAvailableForEeprom
@ kFTFx_FlexramFuncOptAvailableAsRam
status_t FTFx_CMD_VerifyEraseAllExecuteOnlySegments(ftfx_config_t *config, ftfx_margin_value_t margin)
Verifies whether the program flash execute-only segments have been erased to the specified read margi...
status_t FTFx_CMD_VerifyEraseAll(ftfx_config_t *config, ftfx_margin_value_t margin)
Verifies erasure of the entire flash at a specified margin level.
status_t FTFx_CMD_ReadResource(ftfx_config_t *config, uint32_t start, uint8_t *dst, uint32_t lengthInBytes, ftfx_read_resource_opt_t option)
Reads the resource with data at locations passed in through parameters.
status_t FTFx_CMD_Erase(ftfx_config_t *config, uint32_t start, uint32_t lengthInBytes, uint32_t key)
Erases the flash sectors encompassed by parameters passed into function.
enum _ftfx_swap_state ftfx_swap_state_t
Enumeration for the possible flash Swap status.
enum _ftfx_flexram_function_option ftfx_flexram_func_opt_t
Enumeration for the two possilbe options of set FlexRAM function command.
status_t FTFx_CMD_SecurityBypass(ftfx_config_t *config, const uint8_t *backdoorKey)
Allows users to bypass security with a backdoor key.
struct _ftfx_config ftfx_config_t
Flash driver state information.
_ftfx_driver_api_keys
Enumeration for FTFx driver API keys.
@ kFTFx_ApiEraseKey
status_t FTFx_CMD_VerifyErase(ftfx_config_t *config, uint32_t start, uint32_t lengthInBytes, ftfx_margin_value_t margin)
Verifies an erasure of the desired flash area at a specified margin level.
_ftfx_memory_type
Enumeration for FTFx memory type.
@ kFTFx_MemTypeFlexnvm
@ kFTFx_MemTypePflash
status_t FTFx_CMD_SetFlexramFunction(ftfx_config_t *config, ftfx_flexram_func_opt_t option)
Sets the FlexRAM function command.
struct _ftfx_mem_descriptor ftfx_mem_desc_t
Flash memory descriptor.
_ftfx_swap_state
Enumeration for the possible flash Swap status.
@ kFTFx_SwapStateReady
@ kFTFx_SwapStateUninitialized
@ kFTFx_SwapStateUpdate
@ kFTFx_SwapStateComplete
@ kFTFx_SwapStateDisabled
@ kFTFx_SwapStateUpdateErased
enum _ftfx_security_state ftfx_security_state_t
Enumeration for the three possible FTFx security states.
status_t FTFx_CMD_ProgramPartition(ftfx_config_t *config, ftfx_partition_flexram_load_opt_t option, uint32_t eepromDataSizeCode, uint32_t flexnvmPartitionCode)
Prepares the FlexNVM block for use as data flash, EEPROM backup, or a combination of both and initial...
_ftfx_swap_block_status
@ kFTFx_SwapBlockStatusUpperHalfProgramBlocksAtZero
@ kFTFx_SwapBlockStatusLowerHalfProgramBlocksAtZero
_ftfx_read_resource_opt
Enumeration for the two possible options of flash read resource command.
@ kFTFx_ResourceOptionVersionId
@ kFTFx_ResourceOptionFlashIfr
_ftfx_margin_value
Enumeration for supported FTFx margin levels.
@ kFTFx_MarginValueNormal
@ kFTFx_MarginValueInvalid
@ kFTFx_MarginValueFactory
@ kFTFx_MarginValueUser
struct _ftfx_ifr_descriptor ftfx_ifr_desc_t
Flash IFR memory descriptor.
enum _ftfx_partition_flexram_load_option ftfx_partition_flexram_load_opt_t
Enumeration for the FlexRAM load during reset option.
status_t FTFx_CMD_ReadOnce(ftfx_config_t *config, uint32_t index, uint8_t *dst, uint32_t lengthInBytes)
Reads the Program Once Field through parameters.
status_t FTFx_CMD_EraseAllExecuteOnlySegments(ftfx_config_t *config, uint32_t key)
Erases all program flash execute-only segments defined by the FXACC registers.
int32_t status_t
Type used for all status and error return values.
Definition fsl_common.h:169
state("state", SensorCategory.SENSOR_INPUTS, FieldType.INT8, 1871, 1.0, -1.0, -1.0, "")
Flash driver state information.
ftfx_ifr_desc_t ifrDesc
ftfx_ops_config_t opsConfig
uint32_t * runCmdFuncAddr
ftfx_mem_desc_t flashDesc
Flash IFR memory descriptor.
struct _ftfx_ifr_descriptor::@3 resRange
struct _ftfx_ifr_descriptor::@4 idxInfo
struct _ftfx_ifr_descriptor::@2 feature
Flash memory descriptor.
ftfx_spec_mem_t accessSegmentMem
ftfx_spec_mem_t protectRegionMem
struct _ftfx_mem_descriptor::@0 feature
Active FTFx information for the current operation.
struct _ftfx_ops_config::@1 addrAligment
ftfx special memory access information.
Flash Swap information.
ftfx_swap_block_status_t nextSwapBlockStatus
ftfx_swap_state_t flashSwapState
ftfx_swap_block_status_t currentSwapBlockStatus