bootloader_common.h
/*
* Copyright (c) 2013-2015, Freescale Semiconductor, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* o Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
*
* o Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __BOOTLOADER_COMMON_H__
#define __BOOTLOADER_COMMON_H__
#include <stdio.h>
#include <stdarg.h>
#include <stdint.h>
#if !defined(WIN32)
#include <stdbool.h>
#endif
#include "bootloader_common.h"
#include "fsl_common.h"
#if defined(BOOTLOADER_HOST)
#include "blfwk/bootloader_config.h"
#elif defined(BUSPAL)
#include "../src/buspal_config.h"
#else
#include "bootloader_config.h"
#include "target_config.h"
#endif
// Definitions
#ifndef NULL
#define NULL 0
#endif
// The following macros are to be used when trying to save code size for specific peripheral configurations
// that will only be using one peripheral instance. most of the peripheral driver code can use multiple instances but by
// just using one
// we can save space
#define USE_ONLY_UART(instance) (defined(BL_FEATURE_UART_OPTIMIZE) && (BL_UART_USED_INSTANCE == instance))
#define USE_ONLY_SPI(instance) (defined(BL_FEATURE_SPI_OPTIMIZE) && (BL_SPI_USED_INSTANCE == instance))
#define USE_ONLY_I2C(instance) (defined(BL_FEATURE_I2C_OPTIMIZE) && (BL_I2C_USED_INSTANCE == instance))
#if !defined(MIN)
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif
#if !defined(MAX)
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#endif
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#define BSWAP_16(x) (uint16_t)((((x)&0xFF00) >> 0x8) | (((x)&0xFF) << 0x8))
#define BSWAP_32(val) \
(uint32_t)((BSWAP_16((uint32_t)(val) & (uint32_t)0xFFFF) << 0x10) | (BSWAP_16((uint32_t)((val) >> 0x10))))
#ifndef ALIGN_DOWN
#define ALIGN_DOWN(x, a) ((x) & -(a))
#endif
#ifndef ALIGN_UP
#define ALIGN_UP(x, a) (-(-(x) & -(a)))
#endif
#define FOUR_CHAR_CODE(a, b, c, d) (((d) << 24) | ((c) << 16) | ((b) << 8) | ((a)))
#if (defined(DEBUG) || defined(_DEBUG)) && !defined(DEBUG_PRINT_DISABLE)
static inline void debug_printf(const char *format, ...);
static inline void debug_printf(const char *format, ...)
{
va_list args;
va_start(args, format);
vprintf(format, args);
// Temporarily disable MISRA rule 14.2
#if defined(__ICCARM__)
#pragma diag_suppress = Pm049
#endif
va_end(args);
#if defined(__ICCARM__)
#pragma diag_default = Pm049
#endif
}
#else // (DEBUG || _DEBUG) && !DEBUG_PRINT_DISABLE
// Empty macro to cause debug_printf() calls to disappear.
#define debug_printf(x, ...) \
do \
{ \
} while (false)
#endif // (DEBUG || _DEBUG) && !DEBUG_PRINT_DISABLE
typedef void (*pin_irq_callback_t)(uint32_t instance);
enum _bl_status_groups
{
kStatusGroup_Bootloader = kStatusGroup_ApplicationRangeStart,
kStatusGroup_SBLoader,
kStatusGroup_MemoryInterface,
kStatusGroup_PropertyStore,
kStatusGroup_AppCrcCheck,
kStatusGroup_Packetizer,
kStatusGroup_ReliableUpdate
};
enum _bl_driver_status_groups
{
kStatusGroup_QuadSPIDriver = 4,
kStatusGroup_OTFADDriver = 5,
};
#if defined(__CC_ARM)
#pragma anon_unions
#endif
typedef union StandardVersion
{
struct
{
uint8_t bugfix;
uint8_t minor;
uint8_t major;
char name;
};
uint32_t version;
#if defined(__cplusplus)
StandardVersion()
: version(0)
{
}
StandardVersion(uint32_t version)
: version(version)
{
}
#endif
} standard_version_t;
// #define MAKE_VERSION(bugfix, minor, major, name) (((name) << 24) | ((major) << 16) | ((minor) << 8 ) | (bugfix))
enum _external_mem_identifiers
{
kExternalMemId_QuadSPI0 = 1,
};
typedef enum _bootloader_clock_option
{
kClockOption_EnterBootloader = 0,
kClockOption_ExitBootloader = 1,
} bootloader_clock_option_t;
// Prototypes
void init_hardware(void);
void deinit_hardware(void);
void update_available_peripherals(void);
// uint32_t read_autobaud_pin(uint32_t instance);
void configure_clocks(bootloader_clock_option_t option);
uint32_t get_available_lirc_clock(void);
uint32_t get_bus_clock(void);
uint32_t get_system_core_clock(void);
bool usb_clock_init(void);
uint32_t get_uart_clock(uint32_t instance);
bool is_boot_pin_asserted(void);
void enable_autobaud_pin_irq(uint32_t instance, pin_irq_callback_t func);
void disable_autobaud_pin_irq(uint32_t instance);
void Reset_Handler(void);
void bootloader_watchdog_init(void);
void bootloader_watchdog_service(void);
void bootloader_watchdog_deinit(void);
bool qspi_need_configure(void);
status_t otfad_init_as_needed(void);
bool is_qspi_present(void);
bool is_otfad_present(void);
bool is_ltc_present(void);
status_t get_qspi_otfad_init_status(void);
void update_qspi_otfad_init_status(status_t initStatus);
bool is_secondary_i2c_slave_address_enabled(void);
bool is_in_execute_only_region(uint32_t start, uint32_t lengthInBytes);
bool is_second_core_present(void);
#endif // __BOOTLOADER_COMMON_H__
// EOF
get_qspi_otfad_init_status
status_t get_qspi_otfad_init_status(void)
Return status for intializing qspi and otfad modules.
Definition: bl_misc.c:236
kStatusGroup_MemoryInterface
Memory interface status group number (102).
Definition: bootloader_common.h:145
standard_version_t::version
uint32_t version
combined version numbers
Definition: bootloader_common.h:177
kStatusGroup_ApplicationRangeStart
Definition: fsl_common.h:105
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.
Definition: bl_misc.c:249
get_available_lirc_clock
uint32_t get_available_lirc_clock(void)
Returns the available lirc clock frequency in Hertz.
bootloader_watchdog_init
void bootloader_watchdog_init(void)
Initialize watchdog.
Reset_Handler
void Reset_Handler(void)
Declaration for the reset handler, which is defined in assembler.
get_bus_clock
uint32_t get_bus_clock(void)
Returns the current bus clock frequency in Hertz.
Definition: MK65F18/src/bus_pal_hardware.c:858
usb_clock_init
bool usb_clock_init(void)
Configure usb clock.
Definition: MK65F18/src/bus_pal_hardware.c:285
kStatusGroup_Bootloader
Bootloader status group number (100).
Definition: bootloader_common.h:143
configure_clocks
void configure_clocks(bootloader_clock_option_t option)
Returns the logic level of the board specific GPIO pin used for autobaud.
disable_autobaud_pin_irq
void disable_autobaud_pin_irq(uint32_t instance)
Disables the autobaud pin IRQ for the instance passed.
_bl_status_groups
_bl_status_groups
Bootloader status group numbers.
Definition: bootloader_common.h:141
get_system_core_clock
uint32_t get_system_core_clock(void)
Returns the current core clock frequency in Hertz.
init_hardware
void init_hardware(void)
Initialize the hardware such as pinmux.
Definition: hardware_init_MK80F25615.c:49
_bl_driver_status_groups
_bl_driver_status_groups
Driver status group numbers.
Definition: bootloader_common.h:155
kStatusGroup_QuadSPIDriver
QSPI driver status group number.
Definition: bootloader_common.h:157
kStatusGroup_PropertyStore
Property store status group number (103).
Definition: bootloader_common.h:146
pin_irq_callback_t
void(* pin_irq_callback_t)(uint32_t instance)
Callback function invoked for a pin change interrupt.
Definition: bootloader_common.h:136
kStatusGroup_SBLoader
SB loader status group number (101).
Definition: bootloader_common.h:144
_external_mem_identifiers
_external_mem_identifiers
External memory identifiers.
Definition: bootloader_common.h:196
get_uart_clock
uint32_t get_uart_clock(uint32_t instance)
Returns the value in MHz of the UART clock based on the instance.
Definition: host_hardware.c:303
qspi_need_configure
bool qspi_need_configure(void)
Determine if QSPI module to be configured.
Definition: bl_misc.c:97
is_second_core_present
bool is_second_core_present(void)
Check if second core is present.
otfad_init_as_needed
status_t otfad_init_as_needed(void)
Initialize QSPI and OTFAD module.
Definition: bl_misc.c:108
standard_version_t
Structure of version property.
Definition: bootloader_common.h:168
update_available_peripherals
void update_available_peripherals(void)
Update available peripherals based on specific chips.
bootloader_watchdog_service
void bootloader_watchdog_service(void)
Service watchdog.
bootloader_watchdog_deinit
void bootloader_watchdog_deinit(void)
De-initialize watchdog.
kStatusGroup_AppCrcCheck
Application crc check status group number (104).
Definition: bootloader_common.h:147
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.
is_qspi_present
bool is_qspi_present(void)
Determine if QSPI memory is present or not.
Definition: bl_misc.c:152
kStatusGroup_OTFADDriver
OTFAD driver status group number.
Definition: bootloader_common.h:158
is_ltc_present
bool is_ltc_present(void)
Determine if LTC module is present or not.
Definition: bl_misc.c:175
is_boot_pin_asserted
bool is_boot_pin_asserted(void)
Returns true if reset BOOTROM mode is selected.
deinit_hardware
void deinit_hardware(void)
DeInitialize the hardware such as disabling port clock gate.
is_otfad_present
bool is_otfad_present(void)
Determine if OTFAD module is present or not.
Definition: bl_misc.c:162
kStatusGroup_Packetizer
Packetizer status group number (105).
Definition: bootloader_common.h:148
status_t
int32_t status_t
Type used for all status and error return values.
Definition: fsl_common.h:121
kStatusGroup_ReliableUpdate
Reliable Update status groupt number (106).
Definition: bootloader_common.h:149
update_qspi_otfad_init_status
void update_qspi_otfad_init_status(status_t initStatus)
Update status for intializing qspi and otfad modules
Definition: bl_misc.c:242
is_secondary_i2c_slave_address_enabled
bool is_secondary_i2c_slave_address_enabled(void)
Determine is the Secondary I2C slave address is enabled.