fsl_flexspi_nor_boot.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * Copyright 2019-2021 NXP
  3. * All rights reserved.
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. #ifndef __FLEXSPI_NOR_BOOT_H__
  8. #define __FLEXSPI_NOR_BOOT_H__
  9. #include <stdint.h>
  10. #include "board.h"
  11. #include "fsl_common.h"
  12. /*! @name Driver version */
  13. /*@{*/
  14. /*! @brief XIP_DEVICE driver version 2.0.4. */
  15. #define FSL_XIP_DEVICE_DRIVER_VERSION (MAKE_VERSION(2, 0, 4))
  16. /*@}*/
  17. /*************************************
  18. * IVT Data
  19. *************************************/
  20. typedef struct _ivt_
  21. {
  22. /** @ref hdr with tag #HAB_TAG_IVT, length and HAB version fields
  23. * (see @ref data)
  24. */
  25. uint32_t hdr;
  26. /** Absolute address of the first instruction to execute from the
  27. * image
  28. */
  29. uint32_t entry;
  30. /** Reserved in this version of HAB: should be NULL. */
  31. uint32_t reserved1;
  32. /** Absolute address of the image DCD: may be NULL. */
  33. uint32_t dcd;
  34. /** Absolute address of the Boot Data: may be NULL, but not interpreted
  35. * any further by HAB
  36. */
  37. uint32_t boot_data;
  38. /** Absolute address of the IVT.*/
  39. uint32_t self;
  40. /** Absolute address of the image CSF.*/
  41. uint32_t csf;
  42. /** Reserved in this version of HAB: should be zero. */
  43. uint32_t reserved2;
  44. } ivt;
  45. #define IVT_MAJOR_VERSION 0x4
  46. #define IVT_MAJOR_VERSION_SHIFT 0x4
  47. #define IVT_MAJOR_VERSION_MASK 0xF
  48. #define IVT_MINOR_VERSION 0x1
  49. #define IVT_MINOR_VERSION_SHIFT 0x0
  50. #define IVT_MINOR_VERSION_MASK 0xF
  51. #define IVT_VERSION(major, minor) \
  52. ((((major)&IVT_MAJOR_VERSION_MASK) << IVT_MAJOR_VERSION_SHIFT) | \
  53. (((minor)&IVT_MINOR_VERSION_MASK) << IVT_MINOR_VERSION_SHIFT))
  54. /* IVT header */
  55. #define IVT_TAG_HEADER 0xD1 /**< Image Vector Table */
  56. #define IVT_SIZE 0x2000
  57. #define IVT_PAR IVT_VERSION(IVT_MAJOR_VERSION, IVT_MINOR_VERSION)
  58. #define IVT_HEADER (IVT_TAG_HEADER | (IVT_SIZE << 8) | (IVT_PAR << 24))
  59. /* Set resume entry */
  60. #if defined(__CC_ARM) || defined(__ARMCC_VERSION)
  61. extern uint32_t Reset_Handler[];
  62. #define IMAGE_ENTRY_ADDRESS ((uint32_t)Reset_Handler)
  63. #define BOOT_IMAGE_BASE ((uint32_t)FLASH_BASE)
  64. #define BOOT_IMAGE_SIZE ((uint32_t)FLASH_SIZE)
  65. #define BOOT_DATA_ADDRESS &boot_data
  66. #define IVT_ADDRESS &image_vector_table
  67. #define DCD_DATA_ADDRESS dcd_data
  68. #elif defined(__MCUXPRESSO)
  69. extern uint32_t ResetISR[];
  70. extern uint32_t __boot_hdr_start__[];
  71. extern uint32_t __boot_hdr_ivt_loadaddr__[];
  72. extern uint32_t __boot_hdr_boot_data_loadaddr__[];
  73. extern uint32_t __boot_hdr_dcd_loadaddr__[];
  74. extern uint32_t _boot_loadaddr[];
  75. extern uint32_t _boot_size[];
  76. #define IMAGE_ENTRY_ADDRESS ((uint32_t)ResetISR)
  77. #define BOOT_IMAGE_BASE ((uint32_t)_boot_loadaddr)
  78. #define BOOT_IMAGE_SIZE ((uint32_t)_boot_size)
  79. #define BOOT_DATA_ADDRESS ((uint32_t)__boot_hdr_boot_data_loadaddr__)
  80. #define IVT_ADDRESS ((uint32_t)__boot_hdr_ivt_loadaddr__)
  81. #define DCD_DATA_ADDRESS ((uint32_t)__boot_hdr_dcd_loadaddr__)
  82. #elif defined(__ICCARM__)
  83. extern uint32_t Reset_Handler[];
  84. #define IMAGE_ENTRY_ADDRESS ((uint32_t)Reset_Handler)
  85. #define BOOT_IMAGE_BASE ((uint32_t)FLASH_BASE)
  86. #define BOOT_IMAGE_SIZE ((uint32_t)FLASH_SIZE)
  87. #define BOOT_DATA_ADDRESS &boot_data
  88. #define IVT_ADDRESS &image_vector_table
  89. #define DCD_DATA_ADDRESS dcd_data
  90. #elif defined(__GNUC__)
  91. extern uint32_t Reset_Handler[];
  92. #define IMAGE_ENTRY_ADDRESS ((uint32_t)Reset_Handler)
  93. #define BOOT_IMAGE_BASE ((uint32_t)FLASH_BASE)
  94. #define BOOT_IMAGE_SIZE ((uint32_t)FLASH_SIZE)
  95. #define BOOT_DATA_ADDRESS &boot_data
  96. #define IVT_ADDRESS &image_vector_table
  97. #define DCD_DATA_ADDRESS dcd_data
  98. #endif
  99. #if defined(XIP_BOOT_HEADER_ENABLE) && (XIP_BOOT_HEADER_ENABLE == 1)
  100. #if defined(XIP_BOOT_HEADER_DCD_ENABLE) && (1 == XIP_BOOT_HEADER_DCD_ENABLE)
  101. #define DCD_ADDRESS DCD_DATA_ADDRESS
  102. #else
  103. #define DCD_ADDRESS 0
  104. #endif
  105. #endif
  106. #define CSF_ADDRESS 0
  107. #define IVT_RSVD (uint32_t)(0x00000000)
  108. /*************************************
  109. * Boot Data
  110. *************************************/
  111. typedef struct _boot_data_
  112. {
  113. uint32_t start; /* boot start location */
  114. uint32_t size; /* size */
  115. uint32_t plugin; /* plugin flag - 1 if downloaded application is plugin */
  116. uint32_t placeholder; /* placehoder to make even 0x10 size */
  117. } BOOT_DATA_T;
  118. #if __CORTEX_M == 7
  119. #define FLASH_BASE FlexSPI1_AMBA_BASE
  120. #elif __CORTEX_M == 4
  121. #define FLASH_BASE FlexSPI1_ALIAS_BASE
  122. #endif
  123. #if defined(BOARD_FLASH_SIZE)
  124. #define FLASH_SIZE BOARD_FLASH_SIZE
  125. #else
  126. #error "Please define macro BOARD_FLASH_SIZE"
  127. #endif
  128. #define PLUGIN_FLAG (uint32_t)0
  129. /* External Variables */
  130. const BOOT_DATA_T boot_data;
  131. #if defined(XIP_BOOT_HEADER_DCD_ENABLE) && (1 == XIP_BOOT_HEADER_DCD_ENABLE)
  132. extern const uint8_t dcd_data[];
  133. #endif
  134. #endif /* __FLEXSPI_NOR_BOOT_H__ */