fsl_romapi.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * Copyright 2017-2020 NXP
  3. * All rights reserved.
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. #include "fsl_romapi.h"
  8. /*******************************************************************************
  9. * Definitions
  10. ******************************************************************************/
  11. /* Component ID definition, used by tools. */
  12. #ifndef FSL_COMPONENT_ID
  13. #define FSL_COMPONENT_ID "driver.romapi"
  14. #endif
  15. /*******************************************************************************
  16. * Prototypes
  17. ******************************************************************************/
  18. /*!
  19. * @brief Interface for the ROM FLEXSPI NOR flash driver.
  20. */
  21. typedef struct
  22. {
  23. uint32_t version;
  24. status_t (*init)(uint32_t instance, flexspi_nor_config_t *config);
  25. status_t (*program)(uint32_t instance, flexspi_nor_config_t *config, uint32_t dst_addr, const uint32_t *src);
  26. uint32_t reserved0;
  27. status_t (*erase)(uint32_t instance, flexspi_nor_config_t *config, uint32_t start, uint32_t lengthInBytes);
  28. uint32_t reserved1;
  29. void (*clear_cache)(uint32_t instance);
  30. status_t (*xfer)(uint32_t instance, flexspi_xfer_t *xfer);
  31. status_t (*update_lut)(uint32_t instance, uint32_t seqIndex, const uint32_t *lutBase, uint32_t seqNumber);
  32. uint32_t reserved2;
  33. } flexspi_nor_driver_interface_t;
  34. /*!
  35. * @brief Root of the bootloader api tree.
  36. *
  37. * An instance of this struct resides in read-only memory in the bootloader. It
  38. * provides a user application access to APIs exported by the bootloader.
  39. *
  40. * @note The order of existing fields must not be changed.
  41. */
  42. typedef struct
  43. {
  44. void (*runBootloader)(void *arg); /*!< Function to start the bootloader executing */
  45. const uint32_t version; /*!< Bootloader version number */
  46. const uint8_t *copyright; /*!< Bootloader Copyright */
  47. const uint32_t reserved0;
  48. flexspi_nor_driver_interface_t *flexSpiNorDriver; /*!< FLEXSPI NOR flash api */
  49. } bootloader_api_entry_t;
  50. /*******************************************************************************
  51. * Variables
  52. ******************************************************************************/
  53. #define g_bootloaderTree ((bootloader_api_entry_t *)*(uint32_t *)0x0020001cU)
  54. #define api_flexspi_nor_erase_sector \
  55. ((status_t(*)(uint32_t instance, flexspi_nor_config_t * config, uint32_t address))0x0021055dU)
  56. #define api_flexspi_nor_erase_block \
  57. ((status_t(*)(uint32_t instance, flexspi_nor_config_t * config, uint32_t address))0x002104a9U)
  58. /*******************************************************************************
  59. * Codes
  60. ******************************************************************************/
  61. /*******************************************************************************
  62. * ROM FLEXSPI NOR driver
  63. ******************************************************************************/
  64. #if defined(FSL_FEATURE_BOOT_ROM_HAS_ROMAPI) && FSL_FEATURE_BOOT_ROM_HAS_ROMAPI
  65. /*!
  66. * @brief Initialize Serial NOR devices via FLEXSPI.
  67. *
  68. * @param instance storage the instance of FLEXSPI.
  69. * @param config A pointer to the storage for the driver runtime state.
  70. */
  71. status_t ROM_FLEXSPI_NorFlash_Init(uint32_t instance, flexspi_nor_config_t *config)
  72. {
  73. return g_bootloaderTree->flexSpiNorDriver->init(instance, config);
  74. }
  75. /*!
  76. * @brief Program data to Serial NOR via FLEXSPI.
  77. *
  78. * @param instance storage the instance of FLEXSPI.
  79. * @param config A pointer to the storage for the driver runtime state.
  80. * @param dstAddr A pointer to the desired flash memory to be programmed.
  81. * @param src A pointer to the source buffer of data that is to be programmed
  82. * into the NOR flash.
  83. */
  84. status_t ROM_FLEXSPI_NorFlash_ProgramPage(uint32_t instance,
  85. flexspi_nor_config_t *config,
  86. uint32_t dstAddr,
  87. const uint32_t *src)
  88. {
  89. return g_bootloaderTree->flexSpiNorDriver->program(instance, config, dstAddr, src);
  90. }
  91. /*!
  92. * @brief Erase Flash Region specified by address and length.
  93. *
  94. * @param instance storage the index of FLEXSPI.
  95. * @param config A pointer to the storage for the driver runtime state.
  96. * @param start The start address of the desired NOR flash memory to be erased.
  97. * @param length The length, given in bytes to be erased.
  98. */
  99. status_t ROM_FLEXSPI_NorFlash_Erase(uint32_t instance, flexspi_nor_config_t *config, uint32_t start, uint32_t length)
  100. {
  101. return g_bootloaderTree->flexSpiNorDriver->erase(instance, config, start, length);
  102. }
  103. #if defined(FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_ERASE_SECTOR) && FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_ERASE_SECTOR
  104. /*!
  105. * @brief Erase one sector specified by address.
  106. *
  107. * @param instance storage the index of FLEXSPI.
  108. * @param config A pointer to the storage for the driver runtime state.
  109. * @param start The start address of the desired NOR flash memory to be erased.
  110. */
  111. status_t ROM_FLEXSPI_NorFlash_EraseSector(uint32_t instance, flexspi_nor_config_t *config, uint32_t start)
  112. {
  113. return api_flexspi_nor_erase_sector(instance, config, start);
  114. }
  115. #endif /* FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_ERASE_SECTOR */
  116. #if defined(FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_ERASE_BLOCK) && FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_ERASE_BLOCK
  117. /*!
  118. * @brief Erase one block specified by address.
  119. *
  120. * @param instance storage the index of FLEXSPI.
  121. * @param config A pointer to the storage for the driver runtime state.
  122. * @param start The start address of the desired NOR flash memory to be erased.
  123. */
  124. status_t ROM_FLEXSPI_NorFlash_EraseBlock(uint32_t instance, flexspi_nor_config_t *config, uint32_t start)
  125. {
  126. return api_flexspi_nor_erase_block(instance, config, start);
  127. }
  128. #endif /* FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_ERASE_BLOCK */
  129. #if defined(FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_CMD_XFER) && FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_CMD_XFER
  130. /*! @brief FLEXSPI command */
  131. status_t ROM_FLEXSPI_NorFlash_CommandXfer(uint32_t instance, flexspi_xfer_t *xfer)
  132. {
  133. return g_bootloaderTree->flexSpiNorDriver->xfer(instance, xfer);
  134. }
  135. #endif /* FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_CMD_XFER */
  136. #if defined(FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_UPDATE_LUT) && FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_UPDATE_LUT
  137. /*! @brief Configure FLEXSPI Lookup table. */
  138. status_t ROM_FLEXSPI_NorFlash_UpdateLut(uint32_t instance,
  139. uint32_t seqIndex,
  140. const uint32_t *lutBase,
  141. uint32_t seqNumber)
  142. {
  143. return g_bootloaderTree->flexSpiNorDriver->update_lut(instance, seqIndex, lutBase, seqNumber);
  144. }
  145. #endif /* FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_UPDATE_LUT */
  146. /*! @brief Software reset for the FLEXSPI logic. */
  147. void ROM_FLEXSPI_NorFlash_ClearCache(uint32_t instance)
  148. {
  149. g_bootloaderTree->flexSpiNorDriver->clear_cache(instance);
  150. }
  151. #endif /* FSL_FEATURE_BOOT_ROM_HAS_ROMAPI */