1 /*
2  * Copyright 2021 NXP
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  *
7  */
8 
9 #include "fsl_flash.h"
10 #include "fsl_flash_ffr.h"
11 #include "fsl_flexspi_nor_flash.h"
12 
13 /*! @brief Component ID definition, used by tools. */
14 #ifndef FSL_COMPONENT_ID
15 #define FSL_COMPONENT_ID "platform.drivers.niobe4analog_iap"
16 #endif
17 
18 #define BOOTLOADER_API_TREE_POINTER ((bootloader_tree_t *)0x1302FC00U)
19 
20 /*!
21  * @name flash, ffr, flexspi nor flash Structure
22  * @{
23  */
24 
25 typedef union functionCommandOption
26 {
27     uint32_t commandAddr;
28     status_t (*isFlashAreaReadable)(flash_config_t *config, uint32_t startAddress, uint32_t lengthInBytes);
29     status_t (*isFlashAreaModifiable)(flash_config_t *config, uint32_t startAddress, uint32_t lengthInBytes);
30 } function_command_option_t;
31 
32 /*!
33  * @brief Structure of version property.
34  *
35  * @ingroup bl_core
36  */
37 typedef union StandardVersion
38 {
39     struct
40     {
41         uint8_t bugfix; /*!< bugfix version [7:0] */
42         uint8_t minor;  /*!< minor version [15:8] */
43         uint8_t major;  /*!< major version [23:16] */
44         char name;      /*!< name [31:24] */
45     };
46     uint32_t version;   /*!< combined version numbers */
47 } standard_version_t;
48 
49 /*! @brief Interface for the flash driver.*/
50 typedef struct FlashDriverInterface
51 {
52     standard_version_t version; /*!< flash driver API version number. */
53     /* Flash driver */
54     status_t (*flash_init)(flash_config_t *config);
55     status_t (*flash_erase)(flash_config_t *config, uint32_t start, uint32_t lengthInBytes, uint32_t key);
56     status_t (*flash_program)(flash_config_t *config, uint32_t start, uint8_t *src, uint32_t lengthInBytes);
57     status_t (*flash_verify_erase)(flash_config_t *config, uint32_t start, uint32_t lengthInBytes);
58     status_t (*flash_verify_program)(flash_config_t *config,
59                                      uint32_t start,
60                                      uint32_t lengthInBytes,
61                                      const uint8_t *expectedData,
62                                      uint32_t *failedAddress,
63                                      uint32_t *failedData);
64     status_t (*flash_get_property)(flash_config_t *config, flash_property_tag_t whichProperty, uint32_t *value);
65 
66     status_t (*flash_erase_with_checker)(flash_config_t *config, uint32_t start, uint32_t lengthInBytes, uint32_t key);
67     status_t (*flash_program_with_checker)(flash_config_t *config,
68                                            uint32_t start,
69                                            uint8_t *src,
70                                            uint32_t lengthInBytes);
71     status_t (*flash_verify_program_with_checker)(flash_config_t *config,
72                                                   uint32_t start,
73                                                   uint32_t lengthInBytes,
74                                                   const uint8_t *expectedData,
75                                                   uint32_t *failedAddress,
76                                                   uint32_t *failedData);
77     /*!< Flash FFR driver */
78     status_t (*ffr_init)(flash_config_t *config);
79     status_t (*ffr_lock)(flash_config_t *config);
80     status_t (*ffr_cust_factory_page_write)(flash_config_t *config, uint8_t *page_data, bool seal_part);
81     status_t (*ffr_get_uuid)(flash_config_t *config, uint8_t *uuid);
82     status_t (*ffr_get_customer_data)(flash_config_t *config, uint8_t *pData, uint32_t offset, uint32_t len);
83     status_t (*ffr_cust_keystore_write)(flash_config_t *config, ffr_key_store_t *pKeyStore);
84     status_t reserved0;
85     status_t reserved1;
86     status_t (*ffr_infield_page_write)(flash_config_t *config, uint8_t *page_data, uint32_t valid_len);
87     status_t (*ffr_get_customer_infield_data)(flash_config_t *config, uint8_t *pData, uint32_t offset, uint32_t len);
88     status_t (*flash_read)(flash_config_t *config, uint32_t start, uint8_t *dest, uint32_t lengthInBytes);
89     status_t (*ffr_seclib_init)(flash_config_t *config, uint32_t *context);
90     status_t (*flash_get_cust_keystore)(flash_config_t *config, uint8_t *pData, uint32_t offset, uint32_t len);
91     status_t (*flash_erase_non_blocking)(flash_config_t *config, uint32_t start, uint32_t lengthInBytes, uint32_t key);
92     status_t (*flash_get_command_state)(flash_config_t *config);
93 } flash_driver_interface_t;
94 
95 /*! @brief FLEXSPI Flash driver API Interface */
96 typedef struct
97 {
98     uint32_t version;
99     status_t (*init)(uint32_t instance, flexspi_nor_config_t *config);
100     status_t (*page_program)(uint32_t instance, flexspi_nor_config_t *config, uint32_t dstAddr, const uint32_t *src);
101     status_t (*erase_all)(uint32_t instance, flexspi_nor_config_t *config);
102     status_t (*erase)(uint32_t instance, flexspi_nor_config_t *config, uint32_t start, uint32_t length);
103     status_t (*erase_sector)(uint32_t instance, flexspi_nor_config_t *config, uint32_t address);
104     status_t (*erase_block)(uint32_t instance, flexspi_nor_config_t *config, uint32_t address);
105     status_t (*get_config)(uint32_t instance, flexspi_nor_config_t *config, serial_nor_config_option_t *option);
106     status_t (*read)(uint32_t instance, flexspi_nor_config_t *config, uint32_t *dst, uint32_t start, uint32_t bytes);
107     status_t (*xfer)(uint32_t instance, flexspi_xfer_t *xfer);
108     status_t (*update_lut)(uint32_t instance, uint32_t seqIndex, const uint32_t *lutBase, uint32_t numberOfSeq);
109     status_t (*set_clock_source)(uint32_t clockSrc);
110     void (*config_clock)(uint32_t instance, uint32_t freqOption, uint32_t sampleClkMode);
111 } flexspi_nor_flash_driver_t;
112 
113 /*! @}*/
114 
115 /*!
116  * @brief Root of the bootloader API tree.
117  *
118  * An instance of this struct resides in read-only memory in the bootloader. It
119  * provides a user application access to APIs exported by the bootloader.
120  *
121  * @note The order of existing fields must not be changed.
122  */
123 typedef struct BootloaderTree
124 {
125     void (*runBootloader)(void *arg);            /*!< Function to start the bootloader executing.*/
126     standard_version_t version;                  /*!< Bootloader version number.*/
127     const char *copyright;                       /*!< Copyright string.*/
128     const uint32_t reserved0;                    /*!< reserved*/
129     const flash_driver_interface_t *flashDriver; /*!< Internal Flash driver API.*/
130     const uint32_t reserved1[5];                  /*!< reserved*/
131     const uint32_t nbootDriver;                   /*!< Please refer to "fsl_nboot.h" */
132     const flexspi_nor_flash_driver_t *flexspiNorDriver; /*!< FlexSPI NOR FLASH Driver API.*/
133     const uint32_t reserved2;                        /*!< reserved*/
134     const uint32_t memoryInterface;                   /*!< Please refer to "fsl_mem_interface.h" */
135 } bootloader_tree_t;
136 
137 /*******************************************************************************
138  * Code
139  ******************************************************************************/
140 
141 /********************************************************************************
142  * Internal Flash driver API
143  *******************************************************************************/
144 /*!
145  * @brief Initializes the global flash properties structure members.
146  *
147  * This function checks and initializes the Flash module for the other Flash APIs.
148  */
FLASH_Init(flash_config_t * config)149 status_t FLASH_Init(flash_config_t *config)
150 {
151     assert(BOOTLOADER_API_TREE_POINTER);
152     return BOOTLOADER_API_TREE_POINTER->flashDriver->flash_init(config);
153 }
154 
155 /*!
156  * @brief Erases the flash sectors encompassed by parameters passed into function.
157  *
158  * This function erases the appropriate number of flash sectors based on the
159  * desired start address and length.
160  */
FLASH_Erase(flash_config_t * config,uint32_t start,uint32_t lengthInBytes,uint32_t key)161 status_t FLASH_Erase(flash_config_t *config, uint32_t start, uint32_t lengthInBytes, uint32_t key)
162 {
163     assert(BOOTLOADER_API_TREE_POINTER);
164     return BOOTLOADER_API_TREE_POINTER->flashDriver->flash_erase(config, start, lengthInBytes, key);
165 }
166 
FLASH_EraseNonBlocking(flash_config_t * config,uint32_t start,uint32_t lengthInBytes,uint32_t key)167 status_t FLASH_EraseNonBlocking(flash_config_t *config, uint32_t start, uint32_t lengthInBytes, uint32_t key)
168 {
169     assert(BOOTLOADER_API_TREE_POINTER);
170     return BOOTLOADER_API_TREE_POINTER->flashDriver->flash_erase_non_blocking(config, start, lengthInBytes, key);
171 
172 }
173 
174 /*!
175  * @brief Programs flash with data at locations passed in through parameters.
176  *
177  * This function programs the flash memory with the desired data for a given
178  * flash area as determined by the start address and the length.
179  */
FLASH_Program(flash_config_t * config,uint32_t start,uint8_t * src,uint32_t lengthInBytes)180 status_t FLASH_Program(flash_config_t *config, uint32_t start, uint8_t *src, uint32_t lengthInBytes)
181 {
182     assert(BOOTLOADER_API_TREE_POINTER);
183     return BOOTLOADER_API_TREE_POINTER->flashDriver->flash_program(config, start, src, lengthInBytes);
184 }
185 
186 /*!
187  * @brief Verifies an erasure of the desired flash area at a specified margin level.
188  *
189  * This function checks the appropriate number of flash sectors based on
190  * the desired start address and length to check whether the flash is erased
191  * to the specified read margin level.
192  */
FLASH_VerifyErase(flash_config_t * config,uint32_t start,uint32_t lengthInBytes)193 status_t FLASH_VerifyErase(flash_config_t *config, uint32_t start, uint32_t lengthInBytes)
194 {
195     assert(BOOTLOADER_API_TREE_POINTER);
196     return BOOTLOADER_API_TREE_POINTER->flashDriver->flash_verify_erase(config, start, lengthInBytes);
197 }
198 
199 /*!
200  * @brief Reads flash at locations passed in through parameters.
201  *
202  * This function read the flash memory from a given flash area as determined
203  * by the start address and the length.
204  */
FLASH_Read(flash_config_t * config,uint32_t start,uint8_t * dest,uint32_t lengthInBytes)205 status_t FLASH_Read(flash_config_t *config, uint32_t start, uint8_t *dest, uint32_t lengthInBytes)
206 {
207     assert(BOOTLOADER_API_TREE_POINTER);
208     return BOOTLOADER_API_TREE_POINTER->flashDriver->flash_read(config, start, dest, lengthInBytes);
209 }
210 
211 /*!
212  * @brief Verifies programming of the desired flash area at a specified margin level.
213  *
214  * This function verifies the data programed in the flash memory using the
215  * Flash Program Check Command and compares it to the expected data for a given
216  * flash area as determined by the start address and length.
217  */
FLASH_VerifyProgram(flash_config_t * config,uint32_t start,uint32_t lengthInBytes,const uint8_t * expectedData,uint32_t * failedAddress,uint32_t * failedData)218 status_t FLASH_VerifyProgram(flash_config_t *config,
219                              uint32_t start,
220                              uint32_t lengthInBytes,
221                              const uint8_t *expectedData,
222                              uint32_t *failedAddress,
223                              uint32_t *failedData)
224 {
225     assert(BOOTLOADER_API_TREE_POINTER);
226     return BOOTLOADER_API_TREE_POINTER->flashDriver->flash_verify_program(config, start, lengthInBytes, expectedData,
227                                                                           failedAddress, failedData);
228 }
229 
230 /*!
231  * @brief Returns the desired flash property.
232  */
FLASH_GetProperty(flash_config_t * config,flash_property_tag_t whichProperty,uint32_t * value)233 status_t FLASH_GetProperty(flash_config_t *config, flash_property_tag_t whichProperty, uint32_t *value)
234 {
235     assert(BOOTLOADER_API_TREE_POINTER);
236     return BOOTLOADER_API_TREE_POINTER->flashDriver->flash_get_property(config, whichProperty, value);
237 }
238 
239 #if defined(BL_FEATURE_HAS_BUS_CRYPTO_ENGINE) && BL_FEATURE_HAS_BUS_CRYPTO_ENGINE
FLASH_ErasePrologue(flash_config_t * config,uint32_t start,uint32_t lengthInBytes,uint32_t key)240 status_t FLASH_ErasePrologue(flash_config_t *config, uint32_t start, uint32_t lengthInBytes, uint32_t key)
241 {
242     assert(BOOTLOADER_API_TREE_POINTER);
243     return BOOTLOADER_API_TREE_POINTER->flashDriver->flash_erase_with_checker(config, start, lengthInBytes, key);
244 }
245 
FLASH_ProgramPrologue(flash_config_t * config,uint32_t start,uint8_t * src,uint32_t lengthInBytes)246 status_t FLASH_ProgramPrologue(flash_config_t *config, uint32_t start, uint8_t *src, uint32_t lengthInBytes)
247 {
248     assert(BOOTLOADER_API_TREE_POINTER);
249     return BOOTLOADER_API_TREE_POINTER->flashDriver->flash_program_with_checker(config, start, src, lengthInBytes);
250 }
251 
FLASH_VerifyProgramPrologue(flash_config_t * config,uint32_t start,uint32_t lengthInBytes,const uint8_t * expectedData,uint32_t * failedAddress,uint32_t * failedData)252 status_t FLASH_VerifyProgramPrologue(flash_config_t *config,
253                                      uint32_t start,
254                                      uint32_t lengthInBytes,
255                                      const uint8_t *expectedData,
256                                      uint32_t *failedAddress,
257                                      uint32_t *failedData)
258 {
259     assert(BOOTLOADER_API_TREE_POINTER);
260     return BOOTLOADER_API_TREE_POINTER->flashDriver->flash_verify_program_with_checker(
261         config, start, lengthInBytes, expectedData, failedAddress, failedData);
262 }
263 
264 #endif // BL_FEATURE_HAS_BUS_CRYPTO_ENGINE
265 
266 #if defined(FSL_FEATURE_SYSCON_HAS_FLASH_HIDING) && (FSL_FEATURE_SYSCON_HAS_FLASH_HIDING == 1)
267 /*!
268  * @brief Validates the given address range is loaded in the flash hiding region.
269  */
FLASH_IsFlashAreaReadable(flash_config_t * config,uint32_t startAddress,uint32_t lengthInBytes)270 status_t FLASH_IsFlashAreaReadable(flash_config_t *config, uint32_t startAddress, uint32_t lengthInBytes)
271 {
272     function_command_option_t runCmdFuncOption;
273     runCmdFuncOption.commandAddr = 0x13028c41U; /*!< get the flash erase api location adress in rom */
274     return runCmdFuncOption.isFlashAreaReadable(config, startAddress, lengthInBytes);
275 }
276 #endif
277 
278 #if defined(FSL_FEATURE_SYSCON_HAS_CDPA) && (FSL_FEATURE_SYSCON_HAS_CDPA == 1)
279 /*!
280  * @brief Validates the given address range is loaded in the Flash firewall page locked region.
281  */
FLASH_IsFlashAreaModifiable(flash_config_t * config,uint32_t startAddress,uint32_t lengthInBytes)282 status_t FLASH_IsFlashAreaModifiable(flash_config_t *config, uint32_t startAddress, uint32_t lengthInBytes)
283 {
284     function_command_option_t runCmdFuncOption;
285     runCmdFuncOption.commandAddr = 0x13028ca1U; /*!< get the flash erase api location adress in rom */
286     return runCmdFuncOption.isFlashAreaModifiable(config, startAddress, lengthInBytes);
287 }
288 #endif
289 
290 /*!
291  * @brief Get flash command execute status.
292  */
FLASH_GetCommandState(flash_config_t * config)293 status_t FLASH_GetCommandState(flash_config_t *config)
294 {
295     assert(BOOTLOADER_API_TREE_POINTER);
296     return BOOTLOADER_API_TREE_POINTER->flashDriver->flash_get_command_state(config);
297 }
298 
299 /********************************************************************************
300  * fsl iap ffr CODE
301  *******************************************************************************/
302 
303 /*!
304  * @brief Initializes the global FFR properties structure members.
305  */
FFR_Init(flash_config_t * config)306 status_t FFR_Init(flash_config_t *config)
307 {
308     assert(BOOTLOADER_API_TREE_POINTER);
309     return BOOTLOADER_API_TREE_POINTER->flashDriver->ffr_init(config);
310 }
311 
312 /*!
313  * @brief Enable firewall for all flash banks.
314  */
FFR_Lock(flash_config_t * config)315 status_t FFR_Lock(flash_config_t *config)
316 {
317     assert(BOOTLOADER_API_TREE_POINTER);
318     return BOOTLOADER_API_TREE_POINTER->flashDriver->ffr_lock(config);
319 }
320 
321 /*!
322  * @brief APIs to access CMPA pages;
323  * This routine will erase "customer factory page" and program the page with passed data.
324  */
FFR_CustFactoryPageWrite(flash_config_t * config,uint8_t * page_data,bool seal_part)325 status_t FFR_CustFactoryPageWrite(flash_config_t *config, uint8_t *page_data, bool seal_part)
326 {
327     assert(BOOTLOADER_API_TREE_POINTER);
328     return BOOTLOADER_API_TREE_POINTER->flashDriver->ffr_cust_factory_page_write(config, page_data, seal_part);
329 }
330 
331 /*!
332  * @brief See fsl_iap_ffr.h for documentation of this function.
333  */
FFR_GetUUID(flash_config_t * config,uint8_t * uuid)334 status_t FFR_GetUUID(flash_config_t *config, uint8_t *uuid)
335 {
336     assert(BOOTLOADER_API_TREE_POINTER);
337     return BOOTLOADER_API_TREE_POINTER->flashDriver->ffr_get_uuid(config, uuid);
338 }
339 
340 /*!
341  * @brief APIs to access CMPA pages
342  * Read data stored in 'Customer Factory CFG Page'.
343  */
FFR_GetCustomerData(flash_config_t * config,uint8_t * pData,uint32_t offset,uint32_t len)344 status_t FFR_GetCustomerData(flash_config_t *config, uint8_t *pData, uint32_t offset, uint32_t len)
345 {
346     assert(BOOTLOADER_API_TREE_POINTER);
347     return BOOTLOADER_API_TREE_POINTER->flashDriver->ffr_get_customer_data(config, pData, offset, len);
348 }
349 
350 /*!
351  * @brief This routine writes the 3 pages allocated for Key store data.
352  */
FFR_CustKeystoreWrite(flash_config_t * config,ffr_key_store_t * pKeyStore)353 status_t FFR_CustKeystoreWrite(flash_config_t *config, ffr_key_store_t *pKeyStore)
354 {
355     assert(BOOTLOADER_API_TREE_POINTER);
356     return BOOTLOADER_API_TREE_POINTER->flashDriver->ffr_cust_keystore_write(config, pKeyStore);
357 }
358 
359 /*!
360  * @brief APIs to access CFPA pages
361  * This routine will erase CFPA and program the CFPA page with passed data.
362  */
FFR_InfieldPageWrite(flash_config_t * config,uint8_t * page_data,uint32_t valid_len)363 status_t FFR_InfieldPageWrite(flash_config_t *config, uint8_t *page_data, uint32_t valid_len)
364 {
365     assert(BOOTLOADER_API_TREE_POINTER);
366     return BOOTLOADER_API_TREE_POINTER->flashDriver->ffr_infield_page_write(config, page_data, valid_len);
367 }
368 
369 /*!
370  * @brief APIs to access CFPA pages
371  * Generic read function, used by customer to read data stored in 'Customer In-field Page'.
372  */
FFR_GetCustomerInfieldData(flash_config_t * config,uint8_t * pData,uint32_t offset,uint32_t len)373 status_t FFR_GetCustomerInfieldData(flash_config_t *config, uint8_t *pData, uint32_t offset, uint32_t len)
374 {
375     assert(BOOTLOADER_API_TREE_POINTER);
376     return BOOTLOADER_API_TREE_POINTER->flashDriver->ffr_get_customer_infield_data(config, pData, offset, len);
377 }
378 
379 /*!
380  * @brief Initialize the Security Library for FFR driver
381  */
FFR_SecLibInit(flash_config_t * config,uint32_t * context)382 status_t FFR_SecLibInit(flash_config_t *config, uint32_t *context)
383 {
384     assert(BOOTLOADER_API_TREE_POINTER);
385     return BOOTLOADER_API_TREE_POINTER->flashDriver->ffr_seclib_init(config, context);
386 }
387 
388 /*!
389  * @brief The API is used for getting the customer key store data from the customer key store region(0x3e400 �C 0x3e600),
390  * and the API should be called after the FLASH_Init and FFR_Init.
391  */
FFR_GetCustKeystoreData(flash_config_t * config,uint8_t * pData,uint32_t offset,uint32_t len)392 status_t FFR_GetCustKeystoreData(flash_config_t *config, uint8_t *pData, uint32_t offset, uint32_t len)
393 {
394     assert(BOOTLOADER_API_TREE_POINTER);
395     return BOOTLOADER_API_TREE_POINTER->flashDriver->flash_get_cust_keystore(config, pData, offset, len);
396 }
397 
398 /********************************************************************************
399  * FlexSPI NOR FLASH Driver API
400  *******************************************************************************/
401 /*!
402  * @brief Initialize Serial NOR devices via FLEXSPI.
403  */
FLEXSPI_NorFlash_Init(uint32_t instance,flexspi_nor_config_t * config)404 status_t FLEXSPI_NorFlash_Init(uint32_t instance, flexspi_nor_config_t *config)
405 {
406     assert(BOOTLOADER_API_TREE_POINTER);
407     return BOOTLOADER_API_TREE_POINTER->flexspiNorDriver->init(instance, config);
408 }
409 
410 /*!
411  * @brief Program data to Serial NOR via FlexSPI
412  */
FLEXSPI_NorFlash_ProgramPage(uint32_t instance,flexspi_nor_config_t * config,uint32_t dstAddr,const uint32_t * src)413 status_t FLEXSPI_NorFlash_ProgramPage(uint32_t instance,
414                                       flexspi_nor_config_t *config,
415                                       uint32_t dstAddr,
416                                       const uint32_t *src)
417 {
418     assert(BOOTLOADER_API_TREE_POINTER);
419     return BOOTLOADER_API_TREE_POINTER->flexspiNorDriver->page_program(instance, config, dstAddr, src);
420 }
421 
422 /*!
423  * @brief Erase all the Serial NOR devices connected on FlexSPI
424  */
FLEXSPI_NorFlash_EraseAll(uint32_t instance,flexspi_nor_config_t * config)425 status_t FLEXSPI_NorFlash_EraseAll(uint32_t instance, flexspi_nor_config_t *config)
426 {
427     assert(BOOTLOADER_API_TREE_POINTER);
428     return BOOTLOADER_API_TREE_POINTER->flexspiNorDriver->erase_all(instance, config);
429 }
430 
431 /*!
432  * @brief Erase Flash Region specified by address and length
433  */
FLEXSPI_NorFlash_Erase(uint32_t instance,flexspi_nor_config_t * config,uint32_t start,uint32_t length)434 status_t FLEXSPI_NorFlash_Erase(uint32_t instance, flexspi_nor_config_t *config, uint32_t start, uint32_t length)
435 {
436     assert(BOOTLOADER_API_TREE_POINTER);
437     return BOOTLOADER_API_TREE_POINTER->flexspiNorDriver->erase(instance, config, start, length);
438 }
439 
440 /*!
441  * @brief Erase one sector specified by address
442  */
FLEXSPI_NorFlash_EraseSector(uint32_t instance,flexspi_nor_config_t * config,uint32_t address)443 status_t FLEXSPI_NorFlash_EraseSector(uint32_t instance, flexspi_nor_config_t *config, uint32_t address)
444 {
445     assert(BOOTLOADER_API_TREE_POINTER);
446     return BOOTLOADER_API_TREE_POINTER->flexspiNorDriver->erase_sector(instance, config, address);
447 }
448 
449 /*!
450  * @brief Erase one block specified by address
451  */
FLEXSPI_NorFlash_EraseBlock(uint32_t instance,flexspi_nor_config_t * config,uint32_t address)452 status_t FLEXSPI_NorFlash_EraseBlock(uint32_t instance, flexspi_nor_config_t *config, uint32_t address)
453 {
454     assert(BOOTLOADER_API_TREE_POINTER);
455     return BOOTLOADER_API_TREE_POINTER->flexspiNorDriver->erase_block(instance, config, address);
456 }
457 
458 /*!
459  * @brief Get FlexSPI NOR Configuration Block based on specified option
460  */
FLEXSPI_NorFlash_GetConfig(uint32_t instance,flexspi_nor_config_t * config,serial_nor_config_option_t * option)461 status_t FLEXSPI_NorFlash_GetConfig(uint32_t instance, flexspi_nor_config_t *config, serial_nor_config_option_t *option)
462 {
463     assert(BOOTLOADER_API_TREE_POINTER);
464     return BOOTLOADER_API_TREE_POINTER->flexspiNorDriver->get_config(instance, config, option);
465 }
466 
467 /*!
468  * @brief Read data from Serial NOR
469  */
FLEXSPI_NorFlash_Read(uint32_t instance,flexspi_nor_config_t * config,uint32_t * dst,uint32_t start,uint32_t bytes)470 status_t FLEXSPI_NorFlash_Read(
471     uint32_t instance, flexspi_nor_config_t *config, uint32_t *dst, uint32_t start, uint32_t bytes)
472 {
473     assert(BOOTLOADER_API_TREE_POINTER);
474     return BOOTLOADER_API_TREE_POINTER->flexspiNorDriver->read(instance, config, dst, start, bytes);
475 }
476 
477 /*!
478  * @brief Perform FlexSPI command
479  */
FLEXSPI_NorFlash_CommandXfer(uint32_t instance,flexspi_xfer_t * xfer)480 status_t FLEXSPI_NorFlash_CommandXfer(uint32_t instance, flexspi_xfer_t *xfer)
481 {
482     assert(BOOTLOADER_API_TREE_POINTER);
483     return BOOTLOADER_API_TREE_POINTER->flexspiNorDriver->xfer(instance, xfer);
484 }
485 
486 /*!
487  * @brief Configure FlexSPI Lookup table
488  */
FLEXSPI_NorFlash_UpdateLut(uint32_t instance,uint32_t seqIndex,const uint32_t * lutBase,uint32_t numberOfSeq)489 status_t FLEXSPI_NorFlash_UpdateLut(uint32_t instance, uint32_t seqIndex, const uint32_t *lutBase, uint32_t numberOfSeq)
490 {
491     assert(BOOTLOADER_API_TREE_POINTER);
492     return BOOTLOADER_API_TREE_POINTER->flexspiNorDriver->update_lut(instance, seqIndex, lutBase, numberOfSeq);
493 }
494 
495 /*!
496  * @brief Set flexspi clock source
497  */
FLEXSPI_NorFlash_SetClockSource(uint32_t clockSource)498 status_t FLEXSPI_NorFlash_SetClockSource(uint32_t clockSource)
499 {
500     assert(BOOTLOADER_API_TREE_POINTER);
501     return BOOTLOADER_API_TREE_POINTER->flexspiNorDriver->set_clock_source(clockSource);
502 }
503 
504 /*!
505  * @brief config flexspi clock
506  */
FLEXSPI_NorFlash_ConfigClock(uint32_t instance,uint32_t freqOption,uint32_t sampleClkMode)507 void FLEXSPI_NorFlash_ConfigClock(uint32_t instance, uint32_t freqOption, uint32_t sampleClkMode)
508 {
509     assert(BOOTLOADER_API_TREE_POINTER);
510     BOOTLOADER_API_TREE_POINTER->flexspiNorDriver->config_clock(instance, freqOption, sampleClkMode);
511 }
512