bl_context.h
/*
* Copyright (c) 2013, 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.
*/
#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"
#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)
// Definitions
#if !defined(BOOTLOADER_HOST)
typedef struct FlashDriverInterface
{
standard_version_t version;
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;
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)
typedef struct _bootloaderContext
{
const memory_interface_t *memoryInterface;
const memory_map_entry_t *memoryMap;
const property_interface_t *propertyInterface;
const command_interface_t *commandInterface;
const flash_driver_interface_t *flashDriverInterface;
const peripheral_descriptor_t *allPeripherals;
const aes_driver_interface_t *aesInterface;
const peripheral_descriptor_t *activePeripheral;
flash_config_t flashState;
} 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__
// EOF
bootloader_context_t::aesInterface
const aes_driver_interface_t * aesInterface
Interface to the AES driver.
Definition: bl_context.h:127
bootloader_context_t::flashState
flash_config_t flashState
Flash driver instance.
Definition: bl_context.h:133
flash_callback_t
void(* flash_callback_t)(void)
callback type used for pflash block
Definition: src/drivers/flash/fsl_flash.h:421
bootloader_context_t::commandInterface
const command_interface_t * commandInterface
Interface to command processor operations.
Definition: bl_context.h:124
flash_driver_interface_t::version
standard_version_t version
flash driver API version number.
Definition: bl_context.h:59
g_bootloaderContext
bootloader_context_t g_bootloaderContext
Bootloader global context data.
Definition: bl_context.c:40
flash_read_resource_option_t
flash_read_resource_option_t
Enumeration for the two possible options of flash read resource command.
Definition: src/drivers/flash/fsl_flash.h:273
bootloader_context_t::memoryInterface
const memory_interface_t * memoryInterface
Abstract interface to memory operations.
Definition: bl_context.h:121
flash_driver_interface_t
Interface for the flash driver.
Definition: bl_context.h:57
memory_map_entry_t
Structure of a memory map entry.
Definition: memory.h:86
bootloader_context_t
Structure of bootloader global context.
Definition: bl_context.h:117
aes_init
void aes_init(uint32_t *key)
An initialization function for the decryption peripheral Warning: The key must be word aligned...
Definition: aes_security.c:79
aes_driver_interface_t
Interface for AES 128 functions.
Definition: bl_context.h:100
bootloader_context_t::allPeripherals
const peripheral_descriptor_t * allPeripherals
Array of all peripherals.
Definition: bl_context.h:126
property_interface_t
Interface to property operations.
Definition: property.h:321
flash_flexram_function_option_t
flash_flexram_function_option_t
Enumeration for the two possilbe options of set flexram function command.
Definition: src/drivers/flash/fsl_flash.h:317
flash_property_tag_t
flash_property_tag_t
Enumeration for various flash properties.
Definition: src/drivers/flash/fsl_flash.h:231
standard_version_t
Structure of version property.
Definition: bootloader_common.h:168
bootloader_context_t::activePeripheral
const peripheral_descriptor_t * activePeripheral
The currently active peripheral.
Definition: bl_context.h:132
bootloader_context_t::flashDriverInterface
const flash_driver_interface_t * flashDriverInterface
Flash driver interface.
Definition: bl_context.h:125
aes_decrypt
void aes_decrypt(uint32_t *in, uint32_t *key, uint32_t *out)
Decrypts a 16 byte block of data in and out may use the same address so decrypting in place is suppor...
Definition: aes_security.c:138
flash_security_state_t
flash_security_state_t
Enumeration for the three possible flash security states.
Definition: src/drivers/flash/fsl_flash.h:201
flash_margin_value_t
flash_margin_value_t
Enumeration for supported flash margin levels.
Definition: src/drivers/flash/fsl_flash.h:190
flash_config_t
Flash driver state information.
Definition: src/drivers/flash/fsl_flash.h:443
aes_encrypt
void aes_encrypt(uint32_t *in, uint32_t *key, uint32_t *out)
Encrypts a 16 byte block of data in and out may use the same address so encrypting in place is suppor...
Definition: aes_security.c:113
flash_execute_only_access_state_t
flash_execute_only_access_state_t
Enumeration for the three possible flash execute access levels.
Definition: src/drivers/flash/fsl_flash.h:221
g_flashDriverInterface
const flash_driver_interface_t g_flashDriverInterface
Function table for flash driver.
Definition: bl_tree_root.c:46
memory_interface_t
Interface to memory operations.
Definition: memory.h:64
bootloader_context_t::propertyInterface
const property_interface_t * propertyInterface
Interface to property store.
Definition: bl_context.h:123
status_t
int32_t status_t
Type used for all status and error return values.
Definition: fsl_common.h:121
bootloader_context_t::memoryMap
const memory_map_entry_t * memoryMap
Memory map used by abstract memory interface.
Definition: bl_context.h:122
command_interface_t
Interface to command processor operations.
Definition: bl_command.h:95