Vastly simplify bl_context.h and bootloader.h
This commit is contained in:
@@ -1,118 +1,12 @@
|
|||||||
#if !defined(__CONTEXT_H__)
|
#ifndef __CONTEXT_H__
|
||||||
#define __CONTEXT_H__
|
#define __CONTEXT_H__
|
||||||
|
|
||||||
#include "bootloader_common.h"
|
|
||||||
#include "bootloader/bl_peripheral.h"
|
|
||||||
#include "memory.h"
|
|
||||||
#include "packet/command_packet.h"
|
|
||||||
#include "property.h"
|
|
||||||
#include "command.h"
|
#include "command.h"
|
||||||
|
|
||||||
#if !defined(BOOTLOADER_HOST)
|
typedef struct _bootloaderContext {
|
||||||
#include "flash/fsl_flash.h"
|
const peripheral_descriptor_t *activePeripheral;
|
||||||
#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;
|
} bootloader_context_t;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Externs
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
extern bootloader_context_t g_bootloaderContext;
|
extern bootloader_context_t g_bootloaderContext;
|
||||||
extern const flash_driver_interface_t g_flashDriverInterface;
|
|
||||||
extern const aes_driver_interface_t g_aesInterface;
|
|
||||||
|
|
||||||
//! @}
|
#endif
|
||||||
|
|
||||||
#endif // __CONTEXT_H__
|
|
||||||
|
|||||||
@@ -1,65 +1,13 @@
|
|||||||
#if !defined(__BOOTLOADER_H__)
|
#ifndef __BOOTLOADER_H__
|
||||||
#define __BOOTLOADER_H__
|
#define __BOOTLOADER_H__
|
||||||
|
|
||||||
#include "bootloader_common.h"
|
enum _bootloader_status {
|
||||||
#include "bootloader/bl_peripheral.h"
|
|
||||||
#include "bootloader/bl_context.h"
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Definitions
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
//! @brief Bootloader status codes.
|
|
||||||
//! @ingroup bl_core
|
|
||||||
enum _bootloader_status
|
|
||||||
{
|
|
||||||
kStatus_UnknownCommand = MAKE_STATUS(kStatusGroup_Bootloader, 0),
|
kStatus_UnknownCommand = MAKE_STATUS(kStatusGroup_Bootloader, 0),
|
||||||
kStatus_SecurityViolation = MAKE_STATUS(kStatusGroup_Bootloader, 1),
|
kStatus_SecurityViolation = MAKE_STATUS(kStatusGroup_Bootloader, 1),
|
||||||
kStatus_AbortDataPhase = MAKE_STATUS(kStatusGroup_Bootloader, 2),
|
kStatus_AbortDataPhase = MAKE_STATUS(kStatusGroup_Bootloader, 2),
|
||||||
kStatus_Ping = MAKE_STATUS(kStatusGroup_Bootloader, 3),
|
kStatus_Ping = MAKE_STATUS(kStatusGroup_Bootloader, 3),
|
||||||
kStatus_NoResponse = MAKE_STATUS(kStatusGroup_Bootloader, 4),
|
kStatus_NoResponse = MAKE_STATUS(kStatusGroup_Bootloader, 4),
|
||||||
kStatus_NoResponseExpected = MAKE_STATUS(kStatusGroup_Bootloader, 5)
|
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
|
#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