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