Callisto4Bootloader: drivers/bootloader_common.h Source File

Callisto4Bootloader

bootloader_common.h
Go to the documentation of this file.
1
10 #ifndef __BOOTLOADER_COMMON_H__
11 #define __BOOTLOADER_COMMON_H__
12
13 #include <stdio.h>
14 #include <stdarg.h>
15 #include <stdint.h>
16 #include <stdbool.h>
17 #include "fsl_common.h"
18 #include "bootloader_config.h"
19 #include "target_config.h"
20
22 // Definitions
24
25 #ifndef NULL
26 #define NULL 0
27 #endif
28
29 // The following macros are to be used when trying to save code size for specific peripheral configurations
30 // that will only be using one peripheral instance. most of the peripheral driver code can use multiple instances but by
31 // just using one
32 // we can save space
33 #define USE_ONLY_UART(instance) (defined(BL_FEATURE_UART_OPTIMIZE) && (BL_UART_USED_INSTANCE == instance))
34 #define USE_ONLY_SPI(instance) (defined(BL_FEATURE_SPI_OPTIMIZE) && (BL_SPI_USED_INSTANCE == instance))
35 #define USE_ONLY_I2C(instance) (defined(BL_FEATURE_I2C_OPTIMIZE) && (BL_I2C_USED_INSTANCE == instance))
36
39 #if !defined(MIN)
40 #define MIN(a, b) ((a) < (b) ? (a) : (b))
41 #endif
42
43 #if !defined(MAX)
44 #define MAX(a, b) ((a) > (b) ? (a) : (b))
45 #endif
46
49 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
50
53 #define BSWAP_16(x) (uint16_t)((((x)&0xFF00) >> 0x8) | (((x)&0xFF) << 0x8))
54 #define BSWAP_32(val) \
55 (uint32_t)((BSWAP_16((uint32_t)(val) & (uint32_t)0xFFFF) << 0x10) | (BSWAP_16((uint32_t)((val) >> 0x10))))
56
60 #ifndef ALIGN_DOWN
61 #define ALIGN_DOWN(x, a) ((x) & -(a))
62 #endif
63 #ifndef ALIGN_UP
64 #define ALIGN_UP(x, a) (-(-(x) & -(a)))
65 #endif
66
73 #define FOUR_CHAR_CODE(a, b, c, d) (((d) << 24) | ((c) << 16) | ((b) << 8) | ((a)))
74
75 #if (defined(DEBUG) || defined(_DEBUG)) && !defined(DEBUG_PRINT_DISABLE)
76 static inline void debug_printf(const char *format, ...);
77
81 static inline void debug_printf(const char *format, ...)
82 {
83 va_list args;
84 va_start(args, format);
85 vprintf(format, args);
86 // Temporarily disable MISRA rule 14.2
87 #if defined(__ICCARM__)
88 #pragma diag_suppress = Pm049
89 #endif
90 va_end(args);
91 #if defined(__ICCARM__)
92 #pragma diag_default = Pm049
93 #endif
94 }
95 #else // (DEBUG || _DEBUG) && !DEBUG_PRINT_DISABLE
96 // Empty macro to cause debug_printf() calls to disappear.
97 #define debug_printf(x, ...) \
98 do \
99 { \
100 } while (false)
101 #endif // (DEBUG || _DEBUG) && !DEBUG_PRINT_DISABLE
102
106 typedef void (*pin_irq_callback_t)(uint32_t instance);
107
111 enum _bl_status_groups
112 {
113 kStatusGroup_Bootloader = 100,
114 kStatusGroup_SBLoader = 101,
115 kStatusGroup_MemoryInterface = 102,
116 kStatusGroup_PropertyStore = 103,
117 kStatusGroup_AppCrcCheck = 104,
118 kStatusGroup_Packetizer = 105,
119 kStatusGroup_ReliableUpdate = 106,
120
121 kStatusGroup_SerialNorEeprom = 107,
122 kStatusGroup_FlexSPINAND = 200,
123 kStatusGroup_FLEXSPINOR = 201,
124 kStatusGroup_OCOTP = 202,
125 kStatusGroup_SemcNOR = 211,
126 kStatusGroup_SemcNAND = 212,
127 };
128
132 enum _bl_driver_status_groups
133 {
134 kStatusGroup_QuadSPIDriver = 4,
135 kStatusGroup_OTFADDriver = 5,
136 };
137
138 #if defined(__CC_ARM)
139 #pragma anon_unions
140 #endif
141
145 typedef union StandardVersion
146 {
147 struct
148 {
149 uint8_t bugfix;
150 uint8_t minor;
151 uint8_t major;
152 char name;
153 };
154 uint32_t version;
155
156 #if defined(__cplusplus)
157 StandardVersion()
158 : version(0)
159 {
160 }
161 StandardVersion(uint32_t version)
162 : version(version)
163 {
164 }
165 #endif
166 } standard_version_t;
167
168 // #define MAKE_VERSION(bugfix, minor, major, name) (((name) << 24) | ((major) << 16) | ((minor) << 8 ) | (bugfix))
169
171 typedef enum _bootloader_clock_option
172 {
173 kClockOption_EnterBootloader = 0,
174 kClockOption_ExitBootloader = 1,
175 } bootloader_clock_option_t;
176
178 typedef enum _bootdevice_option
179 {
180 kBootDevice_FlexSpiNOR = 0x01,
181 kBootDevice_FlexSpiNAND = 0x02,
182 kBootDevice_SPIEEPROM = 0x04,
183 kBootDevice_MMC_SD = 0x08,
184 kBootDevice_SemcNOR = 0x10,
185 kBootDevice_SemcNAND = 0x20,
186 } bootdevice_option_t;
187
189 typedef enum _bootmode_option
190 {
191 kBootMode_BootFromFuse,
192 kBootMode_SerialDownloader,
193 kBootMode_InternalBoot
194 } boot_mode_option_t;
195
197 typedef enum _habstatus_option
198 {
199 kHabStatus_Open,
200 kHabStatus_Close,
201 } habstatus_option_t;
203 // Prototypes
205
208
210 void init_hardware(void);
211
213 void deinit_hardware(void);
214
216 void update_available_peripherals(void);
217
219 void check_available_dFlash(void);
220
222 // uint32_t read_autobaud_pin(uint32_t instance);
223
225 void configure_clocks(bootloader_clock_option_t option);
226
228 uint32_t get_available_lirc_clock(void);
229
231 uint32_t get_bus_clock(void);
232
234 uint32_t get_flexcomm_clock(uint32_t instance);
235
237 uint32_t get_system_core_clock(void);
238
240 bool usb_clock_init(void);
241
243 uint32_t get_uart_clock(uint32_t instance);
244
246 bool is_boot_pin_asserted(void);
247
249 void enable_autobaud_pin_irq(uint32_t instance, pin_irq_callback_t func);
250
252 void disable_autobaud_pin_irq(uint32_t instance);
253
255 void Reset_Handler(void);
256
258 void bootloader_watchdog_init(void);
259
261 void bootloader_watchdog_service(void);
262
264 void bootloader_watchdog_deinit(void);
265
267 bool qspi_need_configure(void);
268
270 status_t otfad_init_as_needed(void);
271
273 status_t otfad_bypass_as_needed(void);
274
276 status_t oftfad_resume_as_needed(void);
277
279 bool is_qspi_present(void);
280
282 bool is_otfad_present(void);
283
285 bool is_ltc_present(void);
286
288 status_t get_qspi_otfad_init_status(void);
289
291 void update_qspi_otfad_init_status(status_t initStatus);
292
294 bool is_flexspi_nor_present(void);
295
297 bool is_semc_nor_present(void);
298
300 bool is_secondary_i2c_slave_address_enabled(void);
301
303 bool is_in_execute_only_region(uint32_t start, uint32_t lengthInBytes);
304
306 bool is_second_core_present(void);
307
309 void update_memory_map_lpc_sram(void);
310
312 uint32_t get_primary_boot_device(void);
313
315 habstatus_option_t get_hab_status();
317
318 #endif // __BOOTLOADER_COMMON_H__
319 // EOF
kStatusGroup_SBLoader
SB loader status group number (101).
Definition: bootloader_common.h:114
otfad_bypass_as_needed
status_t otfad_bypass_as_needed(void)
Bypass OTFAD module as needed.
kHabStatus_Open
Definition: bootloader_common.h:199
habstatus_option_t
enum _habstatus_option habstatus_option_t
Hab status option.
standard_version_t
union StandardVersion standard_version_t
Structure of version property.
update_available_peripherals
void update_available_peripherals(void)
Update available peripherals based on specific chips.
StandardVersion::minor
uint8_t minor
minor version [15:8]
Definition: bootloader_common.h:150
get_flexcomm_clock
uint32_t get_flexcomm_clock(uint32_t instance)
Returns the current flexcomm clock frequency in Hertz.
is_otfad_present
bool is_otfad_present(void)
Determine if OTFAD module is present or not.
get_system_core_clock
uint32_t get_system_core_clock(void)
Returns the current core clock frequency in Hertz.
kClockOption_ExitBootloader
Clock option for exiting bootloader.
Definition: bootloader_common.h:174
kStatusGroup_SemcNAND
SEMC NAND status group number.
Definition: bootloader_common.h:126
update_memory_map_lpc_sram
void update_memory_map_lpc_sram(void)
Update LPC SRAM memory map based on Device ID0.
qspi_need_configure
bool qspi_need_configure(void)
Determine if QSPI module to be configured.
kBootMode_BootFromFuse
Definition: bootloader_common.h:191
is_second_core_present
bool is_second_core_present(void)
Check if second core is present.
kBootDevice_SemcNOR
Definition: bootloader_common.h:184
get_bus_clock
uint32_t get_bus_clock(void)
Returns the current bus clock frequency in Hertz.
usb_clock_init
bool usb_clock_init(void)
Configure usb clock.
init_hardware
void init_hardware(void)
Initialize the hardware such as pinmux.
check_available_dFlash
void check_available_dFlash(void)
Update DFlash based on specific chips.
enable_autobaud_pin_irq
void enable_autobaud_pin_irq(uint32_t instance, pin_irq_callback_t func)
Enables the autobaud pin IRQ for the specific instance passed.
boot_mode_option_t
enum _bootmode_option boot_mode_option_t
Boot Mode Option.
_bootdevice_option
_bootdevice_option
Boot device Option.
Definition: bootloader_common.h:178
get_hab_status
habstatus_option_t get_hab_status()
Get the hab status.
kBootDevice_MMC_SD
Definition: bootloader_common.h:183
kHabStatus_Close
Definition: bootloader_common.h:200
kStatusGroup_ReliableUpdate
Reliable Update status groupt number (106).
Definition: bootloader_common.h:119
StandardVersion::version
uint32_t version
combined version numbers
Definition: bootloader_common.h:154
get_available_lirc_clock
uint32_t get_available_lirc_clock(void)
Returns the available lirc clock frequency in Hertz.
kBootDevice_FlexSpiNOR
Definition: bootloader_common.h:180
pin_irq_callback_t
void(* pin_irq_callback_t)(uint32_t instance)
Callback function invoked for a pin change interrupt.
Definition: bootloader_common.h:106
kStatusGroup_Bootloader
Bootloader status group number (100).
Definition: bootloader_common.h:113
is_flexspi_nor_present
bool is_flexspi_nor_present(void)
Determine if FlexSPI NOR module is present or not.
kStatusGroup_FlexSPINAND
FlexSPINAND status group number.
Definition: bootloader_common.h:122
kStatusGroup_SemcNOR
SEMC NOR status group number.
Definition: bootloader_common.h:125
otfad_init_as_needed
status_t otfad_init_as_needed(void)
Initialize QSPI and OTFAD module.
is_in_execute_only_region
bool is_in_execute_only_region(uint32_t start, uint32_t lengthInBytes)
Check if data to be accessed is in execute-only region.
debug_printf
#define debug_printf(x,...)
Definition: bootloader_common.h:97
target_config.h
_habstatus_option
_habstatus_option
Hab status option.
Definition: bootloader_common.h:197
kStatusGroup_SerialNorEeprom
Serial NOR/EEPROM status group number.
Definition: bootloader_common.h:121
kBootMode_SerialDownloader
Definition: bootloader_common.h:192
update_qspi_otfad_init_status
void update_qspi_otfad_init_status(status_t initStatus)
Update status for intializing qspi and otfad modules.
StandardVersion::bugfix
uint8_t bugfix
bugfix version [7:0]
Definition: bootloader_common.h:149
is_semc_nor_present
bool is_semc_nor_present(void)
Determine if SEMC NOR module is present or not.
StandardVersion::major
uint8_t major
major version [23:16]
Definition: bootloader_common.h:151
configure_clocks
void configure_clocks(bootloader_clock_option_t option)
Returns the logic level of the board specific GPIO pin used for autobaud.
is_secondary_i2c_slave_address_enabled
bool is_secondary_i2c_slave_address_enabled(void)
Determine is the Secondary I2C slave address is enabled.
bootloader_config.h
kStatusGroup_QuadSPIDriver
QSPI driver status group number.
Definition: bootloader_common.h:134
get_primary_boot_device
uint32_t get_primary_boot_device(void)
Return Primary boot device type.
bootloader_watchdog_init
void bootloader_watchdog_init(void)
Initialize watchdog.
_bootloader_clock_option
_bootloader_clock_option
Bootloader clock option.
Definition: bootloader_common.h:171
kStatusGroup_OCOTP
OCOTP status group number.
Definition: bootloader_common.h:124
kStatusGroup_PropertyStore
Property store status group number (103).
Definition: bootloader_common.h:116
StandardVersion
Structure of version property.
Definition: bootloader_common.h:145
bootloader_watchdog_service
void bootloader_watchdog_service(void)
Service watchdog.
kStatusGroup_Packetizer
Packetizer status group number (105).
Definition: bootloader_common.h:118
_bootmode_option
_bootmode_option
Boot Mode Option.
Definition: bootloader_common.h:189
bootloader_clock_option_t
enum _bootloader_clock_option bootloader_clock_option_t
Bootloader clock option.
bootdevice_option_t
enum _bootdevice_option bootdevice_option_t
Boot device Option.
kStatusGroup_MemoryInterface
Memory interface status group number (102).
Definition: bootloader_common.h:115
kStatusGroup_AppCrcCheck
Application crc check status group number (104).
Definition: bootloader_common.h:117
kStatusGroup_OTFADDriver
OTFAD driver status group number.
Definition: bootloader_common.h:135
is_qspi_present
bool is_qspi_present(void)
Determine if QSPI memory is present or not.
is_ltc_present
bool is_ltc_present(void)
Determine if LTC module is present or not.
kBootDevice_SemcNAND
Definition: bootloader_common.h:185
disable_autobaud_pin_irq
void disable_autobaud_pin_irq(uint32_t instance)
Disables the autobaud pin IRQ for the instance passed.
kStatusGroup_FLEXSPINOR
FlexSPINOR status group number.
Definition: bootloader_common.h:123
_bl_driver_status_groups
_bl_driver_status_groups
Driver status group numbers.
Definition: bootloader_common.h:132
deinit_hardware
void deinit_hardware(void)
DeInitialize the hardware such as disabling port clock gate.
kBootDevice_SPIEEPROM
Definition: bootloader_common.h:182
is_boot_pin_asserted
bool is_boot_pin_asserted(void)
Returns true if reset BOOTROM mode is selected.
bootloader_watchdog_deinit
void bootloader_watchdog_deinit(void)
De-initialize watchdog.
kBootDevice_FlexSpiNAND
Definition: bootloader_common.h:181
get_uart_clock
uint32_t get_uart_clock(uint32_t instance)
Returns the value in MHz of the UART clock based on the instance.
StandardVersion::name
char name
name [31:24]
Definition: bootloader_common.h:152
kBootMode_InternalBoot
Definition: bootloader_common.h:193
Reset_Handler
void Reset_Handler(void)
Declaration for the reset handler, which is defined in assembler.
_bl_status_groups
_bl_status_groups
Bootloader status group numbers.
Definition: bootloader_common.h:111
oftfad_resume_as_needed
status_t oftfad_resume_as_needed(void)
Resume OTFAD module as needed.
get_qspi_otfad_init_status
status_t get_qspi_otfad_init_status(void)
Return status for intializing qspi and otfad modules.
kClockOption_EnterBootloader
Clock option for entering bootloader.
Definition: bootloader_common.h:173