1 /*
2  * Copyright 2018-2024 NXP
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #ifndef __EVKMIMXRT1180_FLEXSPI_NOR_CONFIG__
9 #define __EVKMIMXRT1180_FLEXSPI_NOR_CONFIG__
10 
11 #include <stdint.h>
12 #include "board.h"
13 #include "fsl_common.h"
14 
15 /*! @name Driver version */
16 /*@{*/
17 /*! @brief XIP_DEVICE driver version 2.0.4. */
18 #define FSL_XIP_DEVICE_DRIVER_VERSION (MAKE_VERSION(2, 0, 4))
19 /*@}*/
20 
21 /*************************************
22  *  Container
23  *************************************/
24 /* Container header */
25 #define CNT_TAG_HEADER 0x87
26 #define CNT_SIZE       (uint16_t)(sizeof(container))
27 #define CNT_VERSION    0x00
28 #define CNT_NUM_IMG    1
29 #define CNT_FUSE_VER   0
30 #define CNT_SW_VER     0
31 #define CNT_FLAGS      0x00000000 // Container not authenticated
32 
33 #define IMG_FLAGS 0x00000213      // Non-encrypted, SHA512, CM33, Executable
34 
35 #define SGNBK_TAG     0x90
36 #define SGNBK_SIZE    (uint16_t)(sizeof(sign_block))
37 #define SGNBK_VERSION 0x00
38 
39 typedef struct __attribute__((packed)) _cnt_hdr_
40 {
41     uint8_t version;
42     uint16_t length;
43     uint8_t tag;
44 
45     uint32_t flags;
46 
47     uint16_t sw_ver;
48     uint8_t fuse_ver;
49     uint8_t num_images;
50 
51     uint16_t sign_blk_offset;
52     uint16_t reserved1;
53 } cnt_hdr;
54 
55 typedef struct __attribute__((packed)) _img_entry_
56 {
57     uint32_t offset;
58     uint32_t size;
59     uint32_t load_addr;
60     uint32_t reserved1;
61     uint32_t entry;
62     uint32_t reserved2;
63     uint32_t flags;
64     uint32_t metadata;
65     uint8_t hash[64];
66     uint8_t iv[32];
67 } image_entry;
68 
69 typedef struct __attribute__((packed)) _sign_block_
70 {
71     uint8_t version;
72     uint16_t length;
73     uint8_t tag;
74 
75     uint16_t cert_offset;
76     uint16_t srk_offset;
77     uint16_t sign_offset;
78     uint16_t blob_offset;
79     uint32_t reserved1;
80     uint8_t data[0];
81 } sign_block;
82 
83 typedef struct __attribute__((packed)) _container_
84 {
85     cnt_hdr hdr;
86     image_entry array[CNT_NUM_IMG];
87     sign_block sign_block;
88 } container;
89 
90 /* Set resume entry */
91 #if defined(__MCUXPRESSO)
92 extern uint32_t app_image_offset[];
93 extern uint32_t _image_size[];
94 extern uint32_t _image_loadaddr[];
95 extern uint32_t ResetISR[];
96 #define IMAGE_OFFSET        ((uint32_t)app_image_offset)
97 #define IMAGE_SIZE          ((uint32_t)_image_size)
98 #define IMAGE_LOAD_ADDRESS  ((uint32_t)_image_loadaddr)
99 #define IMAGE_ENTRY_ADDRESS ((uint32_t)ResetISR)
100 
101 #elif defined(__ICCARM__)
102 #pragma section = "RO"
103 extern uint32_t __CONTAINER_IMG_OFFSET[];
104 extern uint32_t __CONTAINER_IMG_LOAD_ADDR[];
105 extern uint32_t __CONTAINER_IMG_ENTRY_ADDR[];
106 #define IMAGE_OFFSET        ((uint32_t)__CONTAINER_IMG_OFFSET)
107 #define IMAGE_SIZE          ((uint32_t)__section_size("RO"))
108 #define IMAGE_LOAD_ADDRESS  ((uint32_t)__CONTAINER_IMG_LOAD_ADDR)
109 #define IMAGE_ENTRY_ADDRESS ((uint32_t)__CONTAINER_IMG_ENTRY_ADDR)
110 
111 #elif defined(__CC_ARM) || defined(__ARMCC_VERSION)
112 extern uint32_t Image$$ER_m_container_image_offset$$ZI$$Base[];
113 extern uint32_t Image$$VECTOR_ROM$$Base[];
114 extern uint32_t Load$$LR$$LR_m_text$$Length[];
115 #define IMAGE_OFFSET        ((uint32_t)Image$$ER_m_container_image_offset$$ZI$$Base)
116 #define IMAGE_SIZE          ((uint32_t)Load$$LR$$LR_m_text$$Length)
117 #define IMAGE_LOAD_ADDRESS  ((uint32_t)Image$$VECTOR_ROM$$Base)
118 #define IMAGE_ENTRY_ADDRESS ((uint32_t)Image$$VECTOR_ROM$$Base)
119 
120 #elif defined(__GNUC__)
121 extern uint32_t __CONTAINER_IMG_OFFSET[];
122 extern uint32_t __CONTAINER_IMG_SIZE[];
123 extern uint32_t __VECTOR_TABLE[];
124 #define IMAGE_OFFSET        ((uint32_t)__CONTAINER_IMG_OFFSET)
125 #define IMAGE_SIZE          ((uint32_t)__CONTAINER_IMG_SIZE)
126 #define IMAGE_LOAD_ADDRESS  ((uint32_t)__VECTOR_TABLE)
127 #define IMAGE_ENTRY_ADDRESS ((uint32_t)__VECTOR_TABLE)
128 #endif
129 
130 #if defined(BOARD_FLASH_SIZE)
131 #define FLASH_SIZE BOARD_FLASH_SIZE
132 #else
133 #error "Please define macro BOARD_FLASH_SIZE"
134 #endif
135 
136 #endif /* __EVKMIMXRT1180_FLEXSPI_NOR_CONFIG__ */
137