Add BusPal to the right firmware.
This commit is contained in:
119
right/src/buspal/bootloader/bl_context.h
Normal file
119
right/src/buspal/bootloader/bl_context.h
Normal file
@@ -0,0 +1,119 @@
|
||||
#if !defined(__CONTEXT_H__)
|
||||
#define __CONTEXT_H__
|
||||
|
||||
#include "bootloader_common.h"
|
||||
#include "bootloader/bl_peripheral.h"
|
||||
#include "memory/memory.h"
|
||||
#include "packet/command_packet.h"
|
||||
//#include "bootloader/bl_command.h"
|
||||
#include "property/property.h"
|
||||
#include "command.h"
|
||||
|
||||
#if !defined(BOOTLOADER_HOST)
|
||||
#include "flash/fsl_flash.h"
|
||||
#if BL_FEATURE_ENCRYPTION
|
||||
#include "security/aes_security.h"
|
||||
#endif // #if BL_FEATURE_ENCRYPTION
|
||||
#endif // #if !defined(BOOTLOADER_HOST)
|
||||
|
||||
//! @addtogroup context
|
||||
//! @{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Definitions
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(BOOTLOADER_HOST)
|
||||
|
||||
//! @brief Interface for the flash driver.
|
||||
typedef struct FlashDriverInterface
|
||||
{
|
||||
standard_version_t version; //!< flash driver API version number.
|
||||
status_t (*flash_init)(flash_config_t *config);
|
||||
status_t (*flash_erase_all)(flash_config_t *config, uint32_t key);
|
||||
status_t (*flash_erase_all_unsecure)(flash_config_t *config, uint32_t key);
|
||||
status_t (*flash_erase)(flash_config_t *config, uint32_t start, uint32_t lengthInBytes, uint32_t key);
|
||||
status_t (*flash_program)(flash_config_t *config, uint32_t start, uint32_t *src, uint32_t lengthInBytes);
|
||||
status_t (*flash_get_security_state)(flash_config_t *config, flash_security_state_t *state);
|
||||
status_t (*flash_security_bypass)(flash_config_t *config, const uint8_t *backdoorKey);
|
||||
status_t (*flash_verify_erase_all)(flash_config_t *config, flash_margin_value_t margin);
|
||||
status_t (*flash_verify_erase)(flash_config_t *config,
|
||||
uint32_t start,
|
||||
uint32_t lengthInBytes,
|
||||
flash_margin_value_t margin);
|
||||
status_t (*flash_verify_program)(flash_config_t *config,
|
||||
uint32_t start,
|
||||
uint32_t lengthInBytes,
|
||||
const uint32_t *expectedData,
|
||||
flash_margin_value_t margin,
|
||||
uint32_t *failedAddress,
|
||||
uint32_t *failedData);
|
||||
status_t (*flash_get_property)(flash_config_t *config, flash_property_tag_t whichProperty, uint32_t *value);
|
||||
status_t (*flash_register_callback)(flash_config_t *config, flash_callback_t callback);
|
||||
status_t (*flash_program_once)(flash_config_t *config, uint32_t index, uint32_t *src, uint32_t lengthInBytes);
|
||||
status_t (*flash_read_once)(flash_config_t *config, uint32_t index, uint32_t *dst, uint32_t lengthInBytes);
|
||||
status_t (*flash_read_resource)(flash_config_t *config,
|
||||
uint32_t start,
|
||||
uint32_t *dst,
|
||||
uint32_t lengthInBytes,
|
||||
flash_read_resource_option_t option);
|
||||
status_t (*flash_prepare_execute_in_ram_functions)(flash_config_t *config);
|
||||
status_t (*flash_is_execute_only)(flash_config_t *config,
|
||||
uint32_t start,
|
||||
uint32_t lengthInBytes,
|
||||
flash_execute_only_access_state_t *access_state);
|
||||
status_t (*flash_erase_all_execute_only_segments)(flash_config_t *config, uint32_t key);
|
||||
status_t (*flash_verify_erase_all_execute_only_segments)(flash_config_t *config, flash_margin_value_t margin);
|
||||
status_t (*flash_set_flexram_function)(flash_config_t *config, flash_flexram_function_option_t option);
|
||||
status_t (*flash_program_section)(flash_config_t *config, uint32_t start, uint32_t *src, uint32_t lengthInBytes);
|
||||
} flash_driver_interface_t;
|
||||
|
||||
//! @brief Interface for AES 128 functions
|
||||
typedef struct AesDriverInterface
|
||||
{
|
||||
void (*aes_init)(uint32_t *key);
|
||||
void (*aes_encrypt)(uint32_t *in, uint32_t *key, uint32_t *out);
|
||||
void (*aes_decrypt)(uint32_t *in, uint32_t *key, uint32_t *out);
|
||||
} aes_driver_interface_t;
|
||||
|
||||
#else // #if !defined(BOOTLOADER_HOST)
|
||||
|
||||
// Provide stub definitions for flash driver types for the host.
|
||||
typedef uint32_t flash_driver_interface_t;
|
||||
typedef uint32_t flash_config_t;
|
||||
typedef uint32_t aes_driver_interface_t;
|
||||
|
||||
#endif // #if !defined(BOOTLOADER_HOST)
|
||||
|
||||
//! @brief Structure of bootloader global context.
|
||||
typedef struct _bootloaderContext
|
||||
{
|
||||
//! @name API tree
|
||||
//@{
|
||||
const memory_interface_t *memoryInterface; //!< Abstract interface to memory operations.
|
||||
const memory_map_entry_t *memoryMap; //!< Memory map used by abstract memory interface.
|
||||
const property_interface_t *propertyInterface; //!< Interface to property store.
|
||||
const command_interface_t *commandInterface; //!< Interface to command processor operations.
|
||||
const flash_driver_interface_t *flashDriverInterface; //!< Flash driver interface.
|
||||
const peripheral_descriptor_t *allPeripherals; //!< Array of all peripherals.
|
||||
const aes_driver_interface_t *aesInterface; //!< Interface to the AES driver
|
||||
//@}
|
||||
|
||||
//! @name Runtime state
|
||||
//@{
|
||||
const peripheral_descriptor_t *activePeripheral; //!< The currently active peripheral.
|
||||
flash_config_t flashState; //!< Flash driver instance.
|
||||
//@}
|
||||
} bootloader_context_t;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Externs
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
extern bootloader_context_t g_bootloaderContext;
|
||||
extern const flash_driver_interface_t g_flashDriverInterface;
|
||||
extern const aes_driver_interface_t g_aesInterface;
|
||||
|
||||
//! @}
|
||||
|
||||
#endif // __CONTEXT_H__
|
||||
126
right/src/buspal/bootloader/bl_peripheral.h
Normal file
126
right/src/buspal/bootloader/bl_peripheral.h
Normal file
@@ -0,0 +1,126 @@
|
||||
#ifndef _peripheral_h
|
||||
#define _peripheral_h
|
||||
|
||||
#include <stdint.h>
|
||||
#include "bootloader_common.h"
|
||||
|
||||
//! @addtogroup peripheral
|
||||
//! @{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Declarations
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//! @brief Peripheral type bit mask definitions.
|
||||
//!
|
||||
//! These bit mask constants serve multiple purposes. They are each a unique value that identifies
|
||||
//! a peripheral type. They are also the mask for the bits used in the bootloader configuration
|
||||
//! flash region to list available peripherals and control which peripherals are enabled.
|
||||
enum _peripheral_types
|
||||
{
|
||||
kPeripheralType_UART = (1 << 0),
|
||||
kPeripheralType_I2CSlave = (1 << 1),
|
||||
kPeripheralType_SPISlave = (1 << 2),
|
||||
kPeripheralType_CAN = (1 << 3),
|
||||
kPeripheralType_USB_HID = (1 << 4),
|
||||
kPeripheralType_USB_CDC = (1 << 5),
|
||||
kPeripheralType_USB_DFU = (1 << 6),
|
||||
kPeripheralType_USB_MSC = (1 << 7)
|
||||
};
|
||||
|
||||
//! @brief Pinmux types.
|
||||
typedef enum _pinmux_types
|
||||
{
|
||||
kPinmuxType_Default = 0,
|
||||
kPinmuxType_GPIO = 1,
|
||||
kPinmuxType_Peripheral = 2
|
||||
} pinmux_type_t;
|
||||
|
||||
// Forward declaration.
|
||||
typedef struct PeripheralDescriptor peripheral_descriptor_t;
|
||||
|
||||
typedef void (*serial_byte_receive_func_t)(uint8_t);
|
||||
|
||||
//! @brief Peripheral control interface.
|
||||
typedef struct _peripheral_control_interface
|
||||
{
|
||||
bool (*pollForActivity)(const peripheral_descriptor_t *self);
|
||||
status_t (*init)(const peripheral_descriptor_t *self, serial_byte_receive_func_t function);
|
||||
void (*shutdown)(const peripheral_descriptor_t *self);
|
||||
void (*pump)(const peripheral_descriptor_t *self);
|
||||
} peripheral_control_interface_t;
|
||||
|
||||
//! @brief Peripheral abstract byte interface.
|
||||
typedef struct _peripheral_byte_inteface
|
||||
{
|
||||
status_t (*init)(const peripheral_descriptor_t *self);
|
||||
#ifdef BOOTLOADER_HOST
|
||||
status_t (*read)(const peripheral_descriptor_t *self, uint8_t *buffer, uint32_t requestedBytes);
|
||||
#endif // #ifdef BOOTLOADER_HOST
|
||||
status_t (*write)(const peripheral_descriptor_t *self, const uint8_t *buffer, uint32_t byteCount);
|
||||
} peripheral_byte_inteface_t;
|
||||
|
||||
//! @brief Packet types.
|
||||
typedef enum _packet_type
|
||||
{
|
||||
kPacketType_Command, //!< Send or expect a command packet
|
||||
kPacketType_Data //!< Send or expect a data packet
|
||||
} packet_type_t;
|
||||
|
||||
//! @brief Peripheral Packet Interface.
|
||||
typedef struct _peripheral_packet_interface
|
||||
{
|
||||
status_t (*init)(const peripheral_descriptor_t *self);
|
||||
status_t (*readPacket)(const peripheral_descriptor_t *self,
|
||||
uint8_t **packet,
|
||||
uint32_t *packetLength,
|
||||
packet_type_t packetType);
|
||||
status_t (*writePacket)(const peripheral_descriptor_t *self,
|
||||
const uint8_t *packet,
|
||||
uint32_t byteCount,
|
||||
packet_type_t packetType);
|
||||
void (*abortDataPhase)(const peripheral_descriptor_t *self);
|
||||
status_t (*finalize)(const peripheral_descriptor_t *self);
|
||||
uint32_t (*getMaxPacketSize)(const peripheral_descriptor_t *self);
|
||||
void (*byteReceivedCallback)(uint8_t byte);
|
||||
} peripheral_packet_interface_t;
|
||||
|
||||
//! @brief Peripheral descriptor.
|
||||
//!
|
||||
//! Instances of this struct describe a particular instance of a peripheral that is
|
||||
//! available for bootloading.
|
||||
struct PeripheralDescriptor
|
||||
{
|
||||
//! @brief Bit mask identifying the peripheral type.
|
||||
//!
|
||||
//! See #_peripheral_types for a list of valid bits.
|
||||
uint32_t typeMask;
|
||||
|
||||
//! @brief The instance number of the peripheral.
|
||||
uint32_t instance;
|
||||
|
||||
//! @brief Configure pinmux setting for the peripheral.
|
||||
void (*pinmuxConfig)(uint32_t instance, pinmux_type_t pinmux);
|
||||
|
||||
//! @brief Control interface for the peripheral.
|
||||
const peripheral_control_interface_t *controlInterface;
|
||||
|
||||
//! @brief Byte-level interface for the peripheral.
|
||||
//!
|
||||
//! May be NULL since not all periperhals support this interface.
|
||||
const peripheral_byte_inteface_t *byteInterface;
|
||||
|
||||
//! @brief Packet level interface for the peripheral.
|
||||
const peripheral_packet_interface_t *packetInterface;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Externs
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//! @brief Array of all peripherals available in this device.
|
||||
extern const peripheral_descriptor_t g_peripherals[];
|
||||
|
||||
//! @}
|
||||
|
||||
#endif // _peripheral_h
|
||||
70
right/src/buspal/bootloader/bootloader.h
Normal file
70
right/src/buspal/bootloader/bootloader.h
Normal file
@@ -0,0 +1,70 @@
|
||||
#if !defined(__BOOTLOADER_H__)
|
||||
#define __BOOTLOADER_H__
|
||||
|
||||
#include "bootloader_common.h"
|
||||
#include "bootloader/bl_peripheral.h"
|
||||
//#include "bootloader/bl_command.h"
|
||||
#include "bootloader/bl_context.h"
|
||||
//#include "bootloader/bl_version.h"
|
||||
//#include "bootloader/bl_user_entry.h"
|
||||
//#include "bootloader/bl_peripheral_interface.h"
|
||||
//#include "bootloader/bl_shutdown_cleanup.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Definitions
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//! @brief Bootloader status codes.
|
||||
//! @ingroup bl_core
|
||||
enum _bootloader_status
|
||||
{
|
||||
kStatus_UnknownCommand = MAKE_STATUS(kStatusGroup_Bootloader, 0),
|
||||
kStatus_SecurityViolation = MAKE_STATUS(kStatusGroup_Bootloader, 1),
|
||||
kStatus_AbortDataPhase = MAKE_STATUS(kStatusGroup_Bootloader, 2),
|
||||
kStatus_Ping = MAKE_STATUS(kStatusGroup_Bootloader, 3),
|
||||
kStatus_NoResponse = MAKE_STATUS(kStatusGroup_Bootloader, 4),
|
||||
kStatus_NoResponseExpected = MAKE_STATUS(kStatusGroup_Bootloader, 5)
|
||||
};
|
||||
|
||||
//! @brief Root of the bootloader API tree.
|
||||
//!
|
||||
//! An instance of this struct resides in read-only memory in the bootloader. It
|
||||
//! provides a user application access to APIs exported by the bootloader.
|
||||
//!
|
||||
//! @note The order of existing fields must not be changed.
|
||||
//!
|
||||
//! @ingroup context
|
||||
#if 1 // Moved into each SOC based header file in future !!!!!!!!!!!!!
|
||||
typedef struct BootloaderTree
|
||||
{
|
||||
void (*runBootloader)(void *arg); //!< Function to start the bootloader executing.
|
||||
standard_version_t version; //!< Bootloader version number.
|
||||
const char *copyright; //!< Copyright string.
|
||||
const bootloader_context_t *runtimeContext; //!< Pointer to the bootloader's runtime context.
|
||||
const flash_driver_interface_t *flashDriver; //!< Flash driver API.
|
||||
const aes_driver_interface_t *aesDriver; //!< AES driver API.
|
||||
} bootloader_tree_t;
|
||||
#endif
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Prototypes
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @brief Verify that a given address is ok to jump to.
|
||||
*
|
||||
* @param applicationAddress The entry point address to validate.
|
||||
* @return Boolean indicating whether the address is valid.
|
||||
*
|
||||
* @ingroup bl_core
|
||||
*/
|
||||
bool is_valid_application_location(uint32_t applicationAddress);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __BOOTLOADER_H__
|
||||
Reference in New Issue
Block a user