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 #include "fsl_efuse.h"
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 /* !@brief EFUSE driver API Interface */
114 typedef struct
115 {
116 standard_version_t version;
117 status_t (*init)(void);
118 status_t (*deinit)(void);
119 status_t (*read)(uint32_t addr, uint32_t *data);
120 status_t (*program)(uint32_t addr, uint32_t data);
121 } efuse_driver_t;
122
123 /*! @}*/
124
125 /*!
126 * @brief Root of the bootloader API tree.
127 *
128 * An instance of this struct resides in read-only memory in the bootloader. It
129 * provides a user application access to APIs exported by the bootloader.
130 *
131 * @note The order of existing fields must not be changed.
132 */
133 typedef struct BootloaderTree
134 {
135 void (*runBootloader)(void *arg); /*!< Function to start the bootloader executing.*/
136 standard_version_t version; /*!< Bootloader version number.*/
137 const char *copyright; /*!< Copyright string.*/
138 const uint32_t reserved0; /*!< reserved*/
139 const flash_driver_interface_t *flashDriver; /*!< Internal Flash driver API.*/
140 const uint32_t reserved1[5]; /*!< reserved*/
141 const uint32_t nbootDriver; /*!< Please refer to "fsl_nboot.h" */
142 const flexspi_nor_flash_driver_t *flexspiNorDriver; /*!< FlexSPI NOR FLASH Driver API.*/
143 const efuse_driver_t *efuseDriver; /*!< eFuse driver API */
144 const uint32_t memoryInterface; /*!< Please refer to "fsl_mem_interface.h" */
145 } bootloader_tree_t;
146
147 /*******************************************************************************
148 * Code
149 ******************************************************************************/
150
151 /********************************************************************************
152 * Internal Flash driver API
153 *******************************************************************************/
154 /*!
155 * @brief Initializes the global flash properties structure members.
156 *
157 * This function checks and initializes the Flash module for the other Flash APIs.
158 */
FLASH_Init(flash_config_t * config)159 status_t FLASH_Init(flash_config_t *config)
160 {
161 assert(BOOTLOADER_API_TREE_POINTER);
162 status_t ret = kStatus_FLASH_Success;
163
164 ret = BOOTLOADER_API_TREE_POINTER->flashDriver->flash_init(config);
165 if (kStatus_FLASH_Success == ret)
166 {
167 /* Call ffr_init is required for A1 */
168 return BOOTLOADER_API_TREE_POINTER->flashDriver->ffr_init(config);
169 }
170 else
171 {
172 return ret;
173 }
174 }
175
176 /*!
177 * @brief Erases the flash sectors encompassed by parameters passed into function.
178 *
179 * This function erases the appropriate number of flash sectors based on the
180 * desired start address and length.
181 */
FLASH_Erase(flash_config_t * config,uint32_t start,uint32_t lengthInBytes,uint32_t key)182 status_t FLASH_Erase(flash_config_t *config, uint32_t start, uint32_t lengthInBytes, uint32_t key)
183 {
184 assert(BOOTLOADER_API_TREE_POINTER);
185 return BOOTLOADER_API_TREE_POINTER->flashDriver->flash_erase(config, start, lengthInBytes, key);
186 }
187
FLASH_EraseNonBlocking(flash_config_t * config,uint32_t start,uint32_t lengthInBytes,uint32_t key)188 status_t FLASH_EraseNonBlocking(flash_config_t *config, uint32_t start, uint32_t lengthInBytes, uint32_t key)
189 {
190 assert(BOOTLOADER_API_TREE_POINTER);
191 return BOOTLOADER_API_TREE_POINTER->flashDriver->flash_erase_non_blocking(config, start, lengthInBytes, key);
192 }
193
194 /*!
195 * @brief Programs flash with data at locations passed in through parameters.
196 *
197 * This function programs the flash memory with the desired data for a given
198 * flash area as determined by the start address and the length.
199 */
FLASH_Program(flash_config_t * config,uint32_t start,uint8_t * src,uint32_t lengthInBytes)200 status_t FLASH_Program(flash_config_t *config, uint32_t start, uint8_t *src, uint32_t lengthInBytes)
201 {
202 assert(BOOTLOADER_API_TREE_POINTER);
203 return BOOTLOADER_API_TREE_POINTER->flashDriver->flash_program(config, start, src, lengthInBytes);
204 }
205
206 /*!
207 * @brief Verifies an erasure of the desired flash area at a specified margin level.
208 *
209 * This function checks the appropriate number of flash sectors based on
210 * the desired start address and length to check whether the flash is erased
211 * to the specified read margin level.
212 */
FLASH_VerifyErase(flash_config_t * config,uint32_t start,uint32_t lengthInBytes)213 status_t FLASH_VerifyErase(flash_config_t *config, uint32_t start, uint32_t lengthInBytes)
214 {
215 assert(BOOTLOADER_API_TREE_POINTER);
216 return BOOTLOADER_API_TREE_POINTER->flashDriver->flash_verify_erase(config, start, lengthInBytes);
217 }
218
219 /*!
220 * @brief Reads flash at locations passed in through parameters.
221 *
222 * This function read the flash memory from a given flash area as determined
223 * by the start address and the length.
224 */
FLASH_Read(flash_config_t * config,uint32_t start,uint8_t * dest,uint32_t lengthInBytes)225 status_t FLASH_Read(flash_config_t *config, uint32_t start, uint8_t *dest, uint32_t lengthInBytes)
226 {
227 assert(BOOTLOADER_API_TREE_POINTER);
228 return BOOTLOADER_API_TREE_POINTER->flashDriver->flash_read(config, start, dest, lengthInBytes);
229 }
230
231 /*!
232 * @brief Verifies programming of the desired flash area at a specified margin level.
233 *
234 * This function verifies the data programed in the flash memory using the
235 * Flash Program Check Command and compares it to the expected data for a given
236 * flash area as determined by the start address and length.
237 */
FLASH_VerifyProgram(flash_config_t * config,uint32_t start,uint32_t lengthInBytes,const uint8_t * expectedData,uint32_t * failedAddress,uint32_t * failedData)238 status_t FLASH_VerifyProgram(flash_config_t *config,
239 uint32_t start,
240 uint32_t lengthInBytes,
241 const uint8_t *expectedData,
242 uint32_t *failedAddress,
243 uint32_t *failedData)
244 {
245 assert(BOOTLOADER_API_TREE_POINTER);
246 return BOOTLOADER_API_TREE_POINTER->flashDriver->flash_verify_program(config, start, lengthInBytes, expectedData,
247 failedAddress, failedData);
248 }
249
250 /*!
251 * @brief Returns the desired flash property.
252 */
FLASH_GetProperty(flash_config_t * config,flash_property_tag_t whichProperty,uint32_t * value)253 status_t FLASH_GetProperty(flash_config_t *config, flash_property_tag_t whichProperty, uint32_t *value)
254 {
255 assert(BOOTLOADER_API_TREE_POINTER);
256 return BOOTLOADER_API_TREE_POINTER->flashDriver->flash_get_property(config, whichProperty, value);
257 }
258
259 #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)260 status_t FLASH_ErasePrologue(flash_config_t *config, uint32_t start, uint32_t lengthInBytes, uint32_t key)
261 {
262 assert(BOOTLOADER_API_TREE_POINTER);
263 return BOOTLOADER_API_TREE_POINTER->flashDriver->flash_erase_with_checker(config, start, lengthInBytes, key);
264 }
265
FLASH_ProgramPrologue(flash_config_t * config,uint32_t start,uint8_t * src,uint32_t lengthInBytes)266 status_t FLASH_ProgramPrologue(flash_config_t *config, uint32_t start, uint8_t *src, uint32_t lengthInBytes)
267 {
268 assert(BOOTLOADER_API_TREE_POINTER);
269 return BOOTLOADER_API_TREE_POINTER->flashDriver->flash_program_with_checker(config, start, src, lengthInBytes);
270 }
271
FLASH_VerifyProgramPrologue(flash_config_t * config,uint32_t start,uint32_t lengthInBytes,const uint8_t * expectedData,uint32_t * failedAddress,uint32_t * failedData)272 status_t FLASH_VerifyProgramPrologue(flash_config_t *config,
273 uint32_t start,
274 uint32_t lengthInBytes,
275 const uint8_t *expectedData,
276 uint32_t *failedAddress,
277 uint32_t *failedData)
278 {
279 assert(BOOTLOADER_API_TREE_POINTER);
280 return BOOTLOADER_API_TREE_POINTER->flashDriver->flash_verify_program_with_checker(
281 config, start, lengthInBytes, expectedData, failedAddress, failedData);
282 }
283
284 #endif // BL_FEATURE_HAS_BUS_CRYPTO_ENGINE
285
286 #if defined(FSL_FEATURE_SYSCON_HAS_FLASH_HIDING) && (FSL_FEATURE_SYSCON_HAS_FLASH_HIDING == 1)
287 /*!
288 * @brief Validates the given address range is loaded in the flash hiding region.
289 */
FLASH_IsFlashAreaReadable(flash_config_t * config,uint32_t startAddress,uint32_t lengthInBytes)290 status_t FLASH_IsFlashAreaReadable(flash_config_t *config, uint32_t startAddress, uint32_t lengthInBytes)
291 {
292 function_command_option_t runCmdFuncOption;
293 runCmdFuncOption.commandAddr = 0x13028c41U; /*!< get the flash erase api location adress in rom */
294 return runCmdFuncOption.isFlashAreaReadable(config, startAddress, lengthInBytes);
295 }
296 #endif
297
298 #if defined(FSL_FEATURE_SYSCON_HAS_CDPA) && (FSL_FEATURE_SYSCON_HAS_CDPA == 1)
299 /*!
300 * @brief Validates the given address range is loaded in the Flash firewall page locked region.
301 */
FLASH_IsFlashAreaModifiable(flash_config_t * config,uint32_t startAddress,uint32_t lengthInBytes)302 status_t FLASH_IsFlashAreaModifiable(flash_config_t *config, uint32_t startAddress, uint32_t lengthInBytes)
303 {
304 function_command_option_t runCmdFuncOption;
305 runCmdFuncOption.commandAddr = 0x13028ca1U; /*!< get the flash erase api location adress in rom */
306 return runCmdFuncOption.isFlashAreaModifiable(config, startAddress, lengthInBytes);
307 }
308 #endif
309
310 /*!
311 * @brief Get flash command execute status.
312 */
FLASH_GetCommandState(flash_config_t * config)313 status_t FLASH_GetCommandState(flash_config_t *config)
314 {
315 assert(BOOTLOADER_API_TREE_POINTER);
316 return BOOTLOADER_API_TREE_POINTER->flashDriver->flash_get_command_state(config);
317 }
318
319 /********************************************************************************
320 * fsl iap ffr CODE
321 *******************************************************************************/
322
323 /*!
324 * @brief Initializes the global FFR properties structure members.
325 */
FFR_Init(flash_config_t * config)326 status_t FFR_Init(flash_config_t *config)
327 {
328 assert(BOOTLOADER_API_TREE_POINTER);
329 return BOOTLOADER_API_TREE_POINTER->flashDriver->ffr_init(config);
330 }
331
332 /*!
333 * @brief Enable firewall for all flash banks.
334 */
FFR_Lock(flash_config_t * config)335 status_t FFR_Lock(flash_config_t *config)
336 {
337 assert(BOOTLOADER_API_TREE_POINTER);
338 return BOOTLOADER_API_TREE_POINTER->flashDriver->ffr_lock(config);
339 }
340
341 /*!
342 * @brief APIs to access CMPA pages;
343 * This routine will erase "customer factory page" and program the page with passed data.
344 */
FFR_CustFactoryPageWrite(flash_config_t * config,uint8_t * page_data,bool seal_part)345 status_t FFR_CustFactoryPageWrite(flash_config_t *config, uint8_t *page_data, bool seal_part)
346 {
347 assert(BOOTLOADER_API_TREE_POINTER);
348 return BOOTLOADER_API_TREE_POINTER->flashDriver->ffr_cust_factory_page_write(config, page_data, seal_part);
349 }
350
351 /*!
352 * @brief See fsl_iap_ffr.h for documentation of this function.
353 */
FFR_GetUUID(flash_config_t * config,uint8_t * uuid)354 status_t FFR_GetUUID(flash_config_t *config, uint8_t *uuid)
355 {
356 assert(BOOTLOADER_API_TREE_POINTER);
357 return BOOTLOADER_API_TREE_POINTER->flashDriver->ffr_get_uuid(config, uuid);
358 }
359
360 /*!
361 * @brief APIs to access CMPA pages
362 * Read data stored in 'Customer Factory CFG Page'.
363 */
FFR_GetCustomerData(flash_config_t * config,uint8_t * pData,uint32_t offset,uint32_t len)364 status_t FFR_GetCustomerData(flash_config_t *config, uint8_t *pData, uint32_t offset, uint32_t len)
365 {
366 assert(BOOTLOADER_API_TREE_POINTER);
367 return BOOTLOADER_API_TREE_POINTER->flashDriver->ffr_get_customer_data(config, pData, offset, len);
368 }
369
370 /*!
371 * @brief This routine writes the 3 pages allocated for Key store data.
372 */
FFR_CustKeystoreWrite(flash_config_t * config,ffr_key_store_t * pKeyStore)373 status_t FFR_CustKeystoreWrite(flash_config_t *config, ffr_key_store_t *pKeyStore)
374 {
375 assert(BOOTLOADER_API_TREE_POINTER);
376 return BOOTLOADER_API_TREE_POINTER->flashDriver->ffr_cust_keystore_write(config, pKeyStore);
377 }
378
379 /*!
380 * @brief APIs to access CFPA pages
381 * This routine will erase CFPA and program the CFPA page with passed data.
382 */
FFR_InfieldPageWrite(flash_config_t * config,uint8_t * page_data,uint32_t valid_len)383 status_t FFR_InfieldPageWrite(flash_config_t *config, uint8_t *page_data, uint32_t valid_len)
384 {
385 assert(BOOTLOADER_API_TREE_POINTER);
386 return BOOTLOADER_API_TREE_POINTER->flashDriver->ffr_infield_page_write(config, page_data, valid_len);
387 }
388
389 /*!
390 * @brief APIs to access CFPA pages
391 * Generic read function, used by customer to read data stored in 'Customer In-field Page'.
392 */
FFR_GetCustomerInfieldData(flash_config_t * config,uint8_t * pData,uint32_t offset,uint32_t len)393 status_t FFR_GetCustomerInfieldData(flash_config_t *config, uint8_t *pData, uint32_t offset, uint32_t len)
394 {
395 assert(BOOTLOADER_API_TREE_POINTER);
396 return BOOTLOADER_API_TREE_POINTER->flashDriver->ffr_get_customer_infield_data(config, pData, offset, len);
397 }
398
399 /*!
400 * @brief Initialize the Security Library for FFR driver
401 */
FFR_SecLibInit(flash_config_t * config,uint32_t * context)402 status_t FFR_SecLibInit(flash_config_t *config, uint32_t *context)
403 {
404 assert(BOOTLOADER_API_TREE_POINTER);
405 return BOOTLOADER_API_TREE_POINTER->flashDriver->ffr_seclib_init(config, context);
406 }
407
408 /*!
409 * @brief The API is used for getting the customer key store data from the customer key store region(0x3e400 - 0x3e600),
410 * and the API should be called after the FLASH_Init and FFR_Init.
411 */
FFR_GetCustKeystoreData(flash_config_t * config,uint8_t * pData,uint32_t offset,uint32_t len)412 status_t FFR_GetCustKeystoreData(flash_config_t *config, uint8_t *pData, uint32_t offset, uint32_t len)
413 {
414 assert(BOOTLOADER_API_TREE_POINTER);
415 return BOOTLOADER_API_TREE_POINTER->flashDriver->flash_get_cust_keystore(config, pData, offset, len);
416 }
417
418 /********************************************************************************
419 * FlexSPI NOR FLASH Driver API
420 *******************************************************************************/
421 /*!
422 * @brief Initialize Serial NOR devices via FLEXSPI.
423 */
FLEXSPI_NorFlash_Init(uint32_t instance,flexspi_nor_config_t * config)424 status_t FLEXSPI_NorFlash_Init(uint32_t instance, flexspi_nor_config_t *config)
425 {
426 assert(BOOTLOADER_API_TREE_POINTER);
427 return BOOTLOADER_API_TREE_POINTER->flexspiNorDriver->init(instance, config);
428 }
429
430 /*!
431 * @brief Program data to Serial NOR via FlexSPI
432 */
FLEXSPI_NorFlash_ProgramPage(uint32_t instance,flexspi_nor_config_t * config,uint32_t dstAddr,const uint32_t * src)433 status_t FLEXSPI_NorFlash_ProgramPage(uint32_t instance,
434 flexspi_nor_config_t *config,
435 uint32_t dstAddr,
436 const uint32_t *src)
437 {
438 assert(BOOTLOADER_API_TREE_POINTER);
439 return BOOTLOADER_API_TREE_POINTER->flexspiNorDriver->page_program(instance, config, dstAddr, src);
440 }
441
442 /*!
443 * @brief Erase all the Serial NOR devices connected on FlexSPI
444 */
FLEXSPI_NorFlash_EraseAll(uint32_t instance,flexspi_nor_config_t * config)445 status_t FLEXSPI_NorFlash_EraseAll(uint32_t instance, flexspi_nor_config_t *config)
446 {
447 assert(BOOTLOADER_API_TREE_POINTER);
448 return BOOTLOADER_API_TREE_POINTER->flexspiNorDriver->erase_all(instance, config);
449 }
450
451 /*!
452 * @brief Erase Flash Region specified by address and length
453 */
FLEXSPI_NorFlash_Erase(uint32_t instance,flexspi_nor_config_t * config,uint32_t start,uint32_t length)454 status_t FLEXSPI_NorFlash_Erase(uint32_t instance, flexspi_nor_config_t *config, uint32_t start, uint32_t length)
455 {
456 assert(BOOTLOADER_API_TREE_POINTER);
457 return BOOTLOADER_API_TREE_POINTER->flexspiNorDriver->erase(instance, config, start, length);
458 }
459
460 /*!
461 * @brief Erase one sector specified by address
462 */
FLEXSPI_NorFlash_EraseSector(uint32_t instance,flexspi_nor_config_t * config,uint32_t address)463 status_t FLEXSPI_NorFlash_EraseSector(uint32_t instance, flexspi_nor_config_t *config, uint32_t address)
464 {
465 assert(BOOTLOADER_API_TREE_POINTER);
466 return BOOTLOADER_API_TREE_POINTER->flexspiNorDriver->erase_sector(instance, config, address);
467 }
468
469 /*!
470 * @brief Erase one block specified by address
471 */
FLEXSPI_NorFlash_EraseBlock(uint32_t instance,flexspi_nor_config_t * config,uint32_t address)472 status_t FLEXSPI_NorFlash_EraseBlock(uint32_t instance, flexspi_nor_config_t *config, uint32_t address)
473 {
474 assert(BOOTLOADER_API_TREE_POINTER);
475 return BOOTLOADER_API_TREE_POINTER->flexspiNorDriver->erase_block(instance, config, address);
476 }
477
478 /*!
479 * @brief Get FlexSPI NOR Configuration Block based on specified option
480 */
FLEXSPI_NorFlash_GetConfig(uint32_t instance,flexspi_nor_config_t * config,serial_nor_config_option_t * option)481 status_t FLEXSPI_NorFlash_GetConfig(uint32_t instance, flexspi_nor_config_t *config, serial_nor_config_option_t *option)
482 {
483 assert(BOOTLOADER_API_TREE_POINTER);
484 return BOOTLOADER_API_TREE_POINTER->flexspiNorDriver->get_config(instance, config, option);
485 }
486
487 /*!
488 * @brief Read data from Serial NOR
489 */
FLEXSPI_NorFlash_Read(uint32_t instance,flexspi_nor_config_t * config,uint32_t * dst,uint32_t start,uint32_t bytes)490 status_t FLEXSPI_NorFlash_Read(
491 uint32_t instance, flexspi_nor_config_t *config, uint32_t *dst, uint32_t start, uint32_t bytes)
492 {
493 assert(BOOTLOADER_API_TREE_POINTER);
494 return BOOTLOADER_API_TREE_POINTER->flexspiNorDriver->read(instance, config, dst, start, bytes);
495 }
496
497 /*!
498 * @brief Perform FlexSPI command
499 */
FLEXSPI_NorFlash_CommandXfer(uint32_t instance,flexspi_xfer_t * xfer)500 status_t FLEXSPI_NorFlash_CommandXfer(uint32_t instance, flexspi_xfer_t *xfer)
501 {
502 assert(BOOTLOADER_API_TREE_POINTER);
503 return BOOTLOADER_API_TREE_POINTER->flexspiNorDriver->xfer(instance, xfer);
504 }
505
506 /*!
507 * @brief Configure FlexSPI Lookup table
508 */
FLEXSPI_NorFlash_UpdateLut(uint32_t instance,uint32_t seqIndex,const uint32_t * lutBase,uint32_t numberOfSeq)509 status_t FLEXSPI_NorFlash_UpdateLut(uint32_t instance, uint32_t seqIndex, const uint32_t *lutBase, uint32_t numberOfSeq)
510 {
511 assert(BOOTLOADER_API_TREE_POINTER);
512 return BOOTLOADER_API_TREE_POINTER->flexspiNorDriver->update_lut(instance, seqIndex, lutBase, numberOfSeq);
513 }
514
515 /*!
516 * @brief Set flexspi clock source
517 */
FLEXSPI_NorFlash_SetClockSource(uint32_t clockSource)518 status_t FLEXSPI_NorFlash_SetClockSource(uint32_t clockSource)
519 {
520 assert(BOOTLOADER_API_TREE_POINTER);
521 return BOOTLOADER_API_TREE_POINTER->flexspiNorDriver->set_clock_source(clockSource);
522 }
523
524 /*!
525 * @brief config flexspi clock
526 */
FLEXSPI_NorFlash_ConfigClock(uint32_t instance,uint32_t freqOption,uint32_t sampleClkMode)527 void FLEXSPI_NorFlash_ConfigClock(uint32_t instance, uint32_t freqOption, uint32_t sampleClkMode)
528 {
529 assert(BOOTLOADER_API_TREE_POINTER);
530 BOOTLOADER_API_TREE_POINTER->flexspiNorDriver->config_clock(instance, freqOption, sampleClkMode);
531 }
532
533 /********************************************************************************
534 * EFUSE driver API
535 *******************************************************************************/
536
537 /*!
538 * @brief Initialize EFUSE controller.
539 */
EFUSE_Init(void)540 status_t EFUSE_Init(void)
541 {
542 assert(BOOTLOADER_API_TREE_POINTER);
543 return BOOTLOADER_API_TREE_POINTER->efuseDriver->init();
544 }
545
546 /*!
547 * @brief De-Initialize EFUSE controller.
548 */
EFUSE_Deinit(void)549 status_t EFUSE_Deinit(void)
550 {
551 assert(BOOTLOADER_API_TREE_POINTER);
552 return BOOTLOADER_API_TREE_POINTER->efuseDriver->deinit();
553 }
554
555 /*!
556 * @brief Read Fuse value from eFuse word.
557 */
EFUSE_Read(uint32_t addr,uint32_t * data)558 status_t EFUSE_Read(uint32_t addr, uint32_t *data)
559 {
560 assert(BOOTLOADER_API_TREE_POINTER);
561 return BOOTLOADER_API_TREE_POINTER->efuseDriver->read(addr, data);
562 }
563
564 /*!
565 * @brief Program value to eFuse block.
566 */
EFUSE_Program(uint32_t addr,uint32_t data)567 status_t EFUSE_Program(uint32_t addr, uint32_t data)
568 {
569 assert(BOOTLOADER_API_TREE_POINTER);
570 return BOOTLOADER_API_TREE_POINTER->efuseDriver->program(addr, data);
571 }
572