1 /*
2  * Copyright 2016-2019, 2021,2024 NXP
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  *
7  */
8 #ifndef __API_TREE_ROOT_H__
9 #define __API_TREE_ROOT_H__
10 
11 #include "fsl_loader_utils.h"
12 #include "nboot_rom_api_table.h"
13 
14 ////////////////////////////////////////////////////////////////////////////////
15 // Definitions
16 ////////////////////////////////////////////////////////////////////////////////
17 // Load and set user appplication boot options stored in specific register
18 #define LOAD_USER_APP_BOOT_OPTIONS()        (SYSCON_USER_APP_BOOT_OPTIONS)
19 #define CLEAR_USER_APP_BOOT_OPTIONS()       (SYSCON_USER_APP_BOOT_OPTIONS = 0u)
20 #define SET_USER_APP_BOOT_OPTIONS(value)    (SYSCON_USER_APP_BOOT_OPTIONS = value)
21 
22 //! @brief Boot parameters of the user application
23 //!  WORD    OFFSET      FIELD                              DESCRIPTION
24 //!          [31:24]     TAG                                Must be '0xEB'
25 //!          [23:20]     Boot mode                          0:Master boot mode; 1: ISP boot
26 //!          [19:16]     Boot interface                     0:USART 1:I2C 2:SPI 3:USB HID 4:QSPI 5:USB DFU
27 //!          [15:12]     Boot instance(Channel)             0 or 1; For SD or MMC,this is to select the instance
28 //!                                                         For FLEXSPI boot, this select the Channel A or Channel B
29 //!          [11:08]     Redundant boot image index         Redundant boot image index for FlexSPI NOR flash
30 //!          [07:00]     Reserved
31 //!
32 //!  TAG[31:24]	    BOOT MODE[23:20]    INTERFACE[19:16]    INSTANCE[15:12]     RBII    Reserved[07:00]     COMBINATION     BOOT ACTION
33 //!  0xEB  	        0                   0	                X	                X       X	                0xEB00XXXX	    MASTR BOOT: USART
34 //!	                0	                1	                X	                X       X	                0xEB01XXXX	    MASTR BOOT: I2C
35 //!	                0	                2	                X	                X       X	                0xEB02XXXX	    MASTR BOOT: SPI
36 //!	                0	                3	                X	                X       X	                0xEB03XXXX	    MASTR BOOT: USB HID
37 //!	                0	                4	                X	                0       X	                0xEB0400XX	    MASTR BOOT: FlexSPI Channel A:boot image index 0
38 //!	                0	                4	                X	                1       X	                0xEB0401XX	    MASTR BOOT: FlexSPI Channel A:boot image index 1
39 //!	                0                   4	                X	                0       X	                0xEB0410XX	    MASTR BOOT: FlexSPI Channel B:boot image index 0
40 //!	                0	                4	                X	                1       X	                0xEB0411XX	    MASTR BOOT: FlexSPI Channel B:boot image index 1
41 //!	                0	                5	                X	                X       X	                0xEB05XXXX	    MASTR BOOT: USB DFU
42 //!	                1	                0	                X	                X       X	                0xEB10XXXX	    ISP BOOT: USART
43 //!	                1	                1	                X	                X       X	                0xEB11XXXX	    ISP BOOT: I2C
44 //!	                1	                2	                X	                X       X	                0xEB12XXXX	    ISP BOOT: SPI
45 //!
46 
47 typedef struct _fsl_user_app_boot_invoke_option
48 {
49     union
50     {
51         struct
52         {
53             uint32_t reserved           : 8;
54             uint32_t boot_image_index   : 4;
55             uint32_t instance           : 4;
56             uint32_t boot_interface     : 4;
57             uint32_t mode               : 4;
58             uint32_t tag                : 8;
59         } B;
60         uint32_t U;
61     } option;
62 } fsl_user_app_boot_invoke_option_t;
63 
64 //! @brief Boot interface can be selected by user application
65 //! @note  For USB-HID QSPI USB-DFU SD MMC, these interfaces are invalid for ISP boot
66 enum
67 {
68     kUserAppBootPeripheral_UART     = 0u,
69     kUserAppBootPeripheral_I2C      = 1u,
70     kUserAppBootPeripheral_SPI      = 2u,
71     kUserAppBootPeripheral_USB_HID  = 3u,
72     kUserAppBootPeripheral_FLEXSPI  = 4u,
73     kUserAppBootPeripheral_DFU      = 5u
74 };
75 
76 //! @brief Boot mode can be selected by user application
77 //! @note  For master boot, valid boot insterfaces for user application are USART I2C SPI USB-HID USB-DFU SD MMC
78 //!        For ISP boot, valid boot interfaces for user application are USART I2C SPI
79 enum
80 {
81     kUserAppBootMode_MasterBoot = 0,
82     kUserAppBootMode_IspBoot    = 1,
83 };
84 
85 
86 //!@brief OTP driver API Interface for A0
87 typedef struct
88 {
89     uint32_t version;
90     status_t (*init)(uint32_t src_clk_freq);
91     status_t (*deinit)(void);
92     status_t (*fuse_read)(uint32_t addr, uint32_t *data);
93     status_t (*fuse_program)(uint32_t addr, uint32_t data, bool lock);
94     status_t (*reload)(void);
95     status_t (*crc_check)(uint32_t start_addr, uint32_t end_addr, uint32_t crc_addr);
96     status_t (*crc_calc)(uint32_t *src, uint32_t numberOfWords, uint32_t *crcChecksum);
97     status_t (*crc_check_sw)(uint32_t *src, uint32_t numberOfWords, uint32_t crc_fuse_idx);
98 } ocotp_driver_v0_t;
99 
100 //!@brief OTP driver API Interface for A1/A2
101 typedef struct
102 {
103     uint32_t version;
104     status_t (*init)(uint32_t src_clk_freq);
105     status_t (*deinit)(void);
106     status_t (*fuse_read)(uint32_t addr, uint32_t *data, uint32_t argChk);
107     status_t (*fuse_program)(uint32_t addr, uint32_t data, bool lock);
108     status_t (*reload)(void);
109     status_t (*crc_check)(uint32_t start_addr, uint32_t end_addr, uint32_t crc_addr);
110     status_t (*crc_calc)(uint32_t *src, uint32_t numberOfWords, uint32_t *crcChecksum);
111     status_t (*crc_check_sw)(uint32_t *src, uint32_t numberOfWords, uint32_t crc_fuse_idx);
112 } ocotp_driver_v1_t;
113 
114 //! @brief Root of the bootloader API tree for A0.
115 //!
116 //! An instance of this struct resides in read-only memory in the bootloader. It
117 //! provides a user application access to APIs exported by the bootloader.
118 //!
119 //! @note The order of existing fields must not be changed.
120 //!
121 //! @ingroup context
122 typedef struct BootloaderTree_v0
123 {
124     void (*runBootloader)(void *arg);                               //!< Function to start the bootloader executing.
125     fsl_standard_version_t                      version;                //!< Bootloader version number.
126     const char                              *copyright;             //!< Copyright string.
127     const uint32_t                          reservedBootloader2;
128     const nboot_interface_v0_t              *nbootDriver;           //!< Image authentication API.
129     const uint32_t                          reservedBootloader3;
130     const ocotp_driver_v0_t                 *otpDriver;             //!< OTP driver API.
131     const fsl_iap_api_interface_t               *iapApiDriver;
132 } bootloader_tree_v0_t;
133 
134 //! @brief Root of the bootloader API tree for A1/A2.
135 //!
136 //! An instance of this struct resides in read-only memory in the bootloader. It
137 //! provides a user application access to APIs exported by the bootloader.
138 //!
139 //! @note The order of existing fields must not be changed.
140 //!
141 //! @ingroup context
142 typedef struct BootloaderTree_v1
143 {
144     void (*runBootloader)(void *arg);                               //!< Function to start the bootloader executing.
145     fsl_standard_version_t                      version;                //!< Bootloader version number.
146     const char                              *copyright;             //!< Copyright string.
147     const uint32_t                          reservedBootloader2;
148     const nboot_interface_v1_t              *nbootDriver;           //!< Image authentication API.
149     const uint32_t                          reservedBootloader3;
150     const ocotp_driver_v1_t                 *otpDriver;             //!< OTP driver API.
151     const fsl_iap_api_interface_t               *iapApiDriver;
152 } bootloader_tree_v1_t;
153 
154 #if defined(__cplusplus)
155 extern "C" {
156 #endif
157 
158 #if defined(__cplusplus)
159 }
160 #endif
161 
162 #endif // __API_TREE_ROOT_H__
163 
164 ////////////////////////////////////////////////////////////////////////////////
165 // EOF
166 ////////////////////////////////////////////////////////////////////////////////
167