1 /*
2  * Copyright 2022 NXP
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #ifndef _FSL_ROMAPI_H_
9 #define _FSL_ROMAPI_H_
10 /*******************************************************************************
11  * Definitions
12  ******************************************************************************/
13 #include <stdint.h>
14 #include <fsl_device_registers.h>
15 
16 /*******************************************************************************
17  * Definitions
18  ******************************************************************************/
19 
20 /*! @name Driver version */
21 /*@{*/
22 /*! @brief ROMAPI driver version 2.0.0. */
23 #define FSL_ROMAPI_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
24 /*@}*/
25 
26 #define ROM_API_TREE_ADDR_A0           0x13024100U
27 #define ROM_API_TREE_ADDR_A1           0x13030000U
28 
get_romapi_addr(void)29 static inline uint32_t get_romapi_addr(void) {
30     uint32_t chip_rev_nr = SOCCTRL->CHIP_INFO & 0x0fu;
31     return (chip_rev_nr == 0u) ? ROM_API_TREE_ADDR_A0 : ROM_API_TREE_ADDR_A1;
32 }
33 
34 #define ROM_API_TREE_ADDR  (get_romapi_addr())
35 
36 
37 // FOR A0. This needs to be adjusted for A1
38 //! @brief Boot parameters of the user application
39 //!  WORD    OFFSET      FIELD                              DESCRIPTION
40 //!          [31:24]     TAG                                Must be '0xEB'
41 //!          [23:20]     Boot mode                          0:Master boot mode; 1: ISP boot
42 //!          [19:16]     Boot interface                     0:USART 1:I2C 2:SPI 3:USB HID 4:QSPI 5:USB DFU
43 //!          [15:12]     Boot instance(Channel)             0 or 1; For SD or MMC,this is to select the instance
44 //!                                                         For FLEXSPI boot, this select the Channel A or Channel B
45 //!          [11:08]     Redundant boot image index         Redundant boot image index for FlexSPI NOR flash
46 //!          [07:00]     Reserved
47 //!
48 //!  TAG[31:24]	    BOOT MODE[23:20]    INTERFACE[19:16]    INSTANCE[15:12]     RBII    Reserved[07:00]     COMBINATION     BOOT ACTION
49 //!  0xEB  	        0                   0	                X	                X       X	                0xEB00XXXX	    MASTR BOOT: USART
50 //!	                0	                1	                X	                X       X	                0xEB01XXXX	    MASTR BOOT: I2C
51 //!	                0	                2	                X	                X       X	                0xEB02XXXX	    MASTR BOOT: SPI
52 //!	                0	                3	                X	                X       X	                0xEB03XXXX	    MASTR BOOT: USB HID
53 //!	                0	                4	                X	                0       X	                0xEB0400XX	    MASTR BOOT: FlexSPI Channel A:boot image index 0
54 //!	                0	                4	                X	                1       X	                0xEB0401XX	    MASTR BOOT: FlexSPI Channel A:boot image index 1
55 //!	                0                   4	                X	                0       X	                0xEB0410XX	    MASTR BOOT: FlexSPI Channel B:boot image index 0
56 //!	                0	                4	                X	                1       X	                0xEB0411XX	    MASTR BOOT: FlexSPI Channel B:boot image index 1
57 //!	                0	                5	                X	                X       X	                0xEB05XXXX	    MASTR BOOT: USB DFU
58 //!	                1	                0	                X	                X       X	                0xEB10XXXX	    ISP BOOT: USART
59 //!	                1	                1	                X	                X       X	                0xEB11XXXX	    ISP BOOT: I2C
60 //!	                1	                2	                X	                X       X	                0xEB12XXXX	    ISP BOOT: SPI
61 //!
62 
63 typedef struct _user_app_boot_invoke_option
64 {
65     union
66     {
67         struct
68         {
69             uint32_t reserved           : 8;
70             uint32_t boot_image_index   : 4;
71             uint32_t instance           : 4;
72             uint32_t boot_interface     : 4;
73             uint32_t mode               : 4;
74             uint32_t tag                : 8;
75         } B;
76         uint32_t U;
77     } option;
78 } user_app_boot_invoke_option_t;
79 
80 /*!
81  * @brief Run the Bootloader API  to force into the ISP mode base on the user arg
82  *
83  * @param arg Indicates API prototype fields definition. Refer to the above user_app_boot_invoke_option_t structure
84  */
85 void bootloader_user_entry(void *arg);
86 
87 /*!
88  * @brief Get Bootloader version
89  *
90  * @retval Bootloader version.
91  */
92 uint32_t bootloader_version(void);
93 
94 /*!
95  * @brief Get Bootloader Copyright
96  *
97  * @retval Pointer to Bootloader copyright header
98  */
99 const char * bootloader_copyright(void);
100 
101 #endif /* _FSL_ROMAPI_H_ */
102