1 /*
2  * Copyright 2022 NXP
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 #include "fsl_romapi_otp.h"
8 #include "fsl_romapi_nboot.h"
9 #include "fsl_romapi_flexspi.h"
10 #include "fsl_romapi_iap.h"
11 #include "fsl_romapi.h"
12 
13 /*******************************************************************************
14  * Definitions
15  ******************************************************************************/
16 /* Component ID definition, used by tools. */
17 #ifndef FSL_COMPONENT_ID
18 #define FSL_COMPONENT_ID "platform.drivers.romapi"
19 #endif
20 
21 //! @brief Boot mode can be selected by user application
22 //! @note  For master boot, valid boot insterfaces for user application are USART I2C SPI USB-HID USB-DFU SD MMC
23 //!        For ISP boot, valid boot interfaces for user application are USART I2C SPI
24 enum
25 {
26     kUserAppBootMode_MasterBoot = 0u,
27     kUserAppBootMode_IspBoot    = 1u,
28 };
29 
30 //! @brief Boot interface can be selected by user application
31 //! @note  For USB-HID QSPI USB-DFU SD MMC, these interfaces are invalid for ISP boot
32 enum
33 {
34     kUserAppBootPeripheral_UART    = 0u,
35     kUserAppBootPeripheral_I2C     = 1u,
36     kUserAppBootPeripheral_SPI     = 2u,
37     kUserAppBootPeripheral_USB_HID = 3u,
38     kUserAppBootPeripheral_FLEXSPI = 4u,
39     kUserAppBootPeripheral_DFU     = 5u
40 };
41 
42 //! @brief Root of the bootloader API tree.
43 //!
44 //! An instance of this struct resides in read-only memory in the bootloader. It
45 //! provides a user application access to APIs exported by the bootloader.
46 //!
47 //! @note The order of existing fields must not be changed.
48 //!
49 //! @ingroup context
50 typedef struct BootloaderTree
51 {
52     void (*runBootloader)(void *arg); //!< Function to start the bootloader executing.
53     standard_version_t version;       //!< Bootloader version number.
54     const char *copyright;            //!< Copyright string.
55     const uint32_t UNUSED;
56     const nboot_interface_t *nbootDriver;               //!< Image authentication API.
57     const flexspi_nor_flash_driver_t *flexspiNorDriver; //!< FlexSPI NOR FLASH Driver API.
58     const ocotp_driver_t *otpDriver;                    //!< OTP driver API.
59     const uint32_t *iapApiDriver;                       //!< IAP driver API.
60 } bootloader_tree_t;
61 
62 #define ROM_API_TREE ((bootloader_tree_t *)ROM_API_TREE_ADDR)
63 
bootloader_user_entry(void * arg)64 void bootloader_user_entry(void *arg)
65 {
66     assert(ROM_API_TREE);
67     ROM_API_TREE->runBootloader(arg);
68 }
69 
bootloader_version(void)70 uint32_t bootloader_version(void)
71 {
72     assert(ROM_API_TREE);
73     return (ROM_API_TREE->version.version);
74 }
75 
bootloader_copyright(void)76 const char *bootloader_copyright(void)
77 {
78     assert(ROM_API_TREE);
79     return (ROM_API_TREE->copyright);
80 }
81