memory.h
/*
* Copyright (c) 2013-2016, 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 _memory_h
#define _memory_h
#include <stdint.h>
#include "bootloader_common.h"
// Declarations
enum _memory_interface_status
{
kStatusMemoryRangeInvalid = MAKE_STATUS(kStatusGroup_MemoryInterface, 0),
kStatusMemoryReadFailed = MAKE_STATUS(kStatusGroup_MemoryInterface, 1),
kStatusMemoryWriteFailed = MAKE_STATUS(kStatusGroup_MemoryInterface, 2),
kStatusMemoryCumulativeWrite = MAKE_STATUS(kStatusGroup_MemoryInterface, 3),
kStatusMemoryAppOverlapWithExecuteOnlyRegion = MAKE_STATUS(kStatusGroup_MemoryInterface, 4)
};
// !@brief Executable enum codes
enum
{
kMemoryNotExecutable = false,
kMemoryIsExecutable = true,
};
typedef struct _memory_interface
{
status_t (*init)(void);
status_t (*read)(uint32_t address, uint32_t length, uint8_t *buffer);
status_t (*write)(uint32_t address, uint32_t length, const uint8_t *buffer);
status_t (*fill)(uint32_t address, uint32_t length, uint32_t pattern);
status_t (*flush)(void);
status_t (*erase)(uint32_t address, uint32_t length);
} memory_interface_t;
typedef struct _memory_region_interface
{
status_t (*init)(void);
status_t (*read)(uint32_t address, uint32_t length, uint8_t *buffer);
status_t (*write)(uint32_t address, uint32_t length, const uint8_t *buffer);
status_t (*fill)(uint32_t address, uint32_t length, uint32_t pattern);
status_t (*flush)(void);
status_t (*erase)(uint32_t address, uint32_t length);
} memory_region_interface_t;
typedef struct _memory_map_entry
{
uint32_t startAddress;
uint32_t endAddress;
bool isExecutable;
const memory_region_interface_t *memoryInterface;
} memory_map_entry_t;
enum _memorymap_constants
{
kIndexFlashArray = 0,
kIndexSRAM = 1,
#if CPU_IS_ARM_CORTEX_M7
kIndexDTCM = 2,
kIndexOCRAM = 3,
#endif // CPU_IS_ARM_CORTEX_M7
#if BL_FEATURE_QSPI_MODULE
kIndexQspiMemory = 2,
kIndexQspiAliasArea = 3,
#endif // BL_FEATURE_QSPI_MODULE
kSRAMSeparatrix = (uint32_t)0x20000000
};
typedef enum _flash_erase_all_option
{
kFlashEraseAllOption_Blocks = 0,
kFlashEraseAllOption_ExecuteOnlySegments = 1
} flash_erase_all_option_t;
// Externs
extern memory_map_entry_t g_memoryMap[];
extern const memory_interface_t g_memoryInterface;
extern const memory_region_interface_t g_flashMemoryInterface;
extern const memory_region_interface_t g_normalMemoryInterface;
#if CPU_IS_ARM_CORTEX_M7
extern const memory_region_interface_t g_normalDTCMInterface;
extern const memory_region_interface_t g_normalOCRAMInterface;
#endif
extern const memory_region_interface_t g_deviceMemoryInterface;
#if defined BL_FEATURE_QSPI_MODULE
extern const memory_region_interface_t g_qspiMemoryInterface;
#if BL_FEATURE_QSPI_ALIAS_AREA
extern const memory_region_interface_t g_qspiAliasAreaInterface;
#endif // BL_FEATURE_QSPI_ALIAS_AREA
#endif // BL_FEATURE_QSPI_MODULE
// Prototypes
#if defined(__cplusplus)
extern "C" {
#endif // __cplusplus
status_t mem_init(void);
status_t mem_read(uint32_t address, uint32_t length, uint8_t *buffer);
status_t mem_write(uint32_t address, uint32_t length, const uint8_t *buffer);
status_t mem_fill(uint32_t address, uint32_t length, uint32_t pattern);
status_t mem_erase(uint32_t address, uint32_t length);
status_t mem_flush(void);
status_t find_map_entry(uint32_t address, uint32_t length, const memory_map_entry_t **map);
bool mem_is_erased(uint32_t address, uint32_t length);
bool mem_is_block_reserved(uint32_t address, uint32_t length);
status_t flash_mem_erase(uint32_t address, uint32_t length);
#if BL_FEATURE_FAC_ERASE
status_t flash_mem_erase_all(flash_erase_all_option_t eraseOption);
#else
status_t flash_mem_erase_all(void);
#endif
status_t flash_mem_erase_all_unsecure(void);
status_t qspi_mem_erase_all(void);
#if defined(__cplusplus)
}
#endif // __cplusplus
#if defined(BOOTLOADER_HOST)
// Simulator host prototypes
#if __cplusplus
extern "C" {
#endif
void host_flash_erase_all(void);
void host_flash_erase_all_unsecure(void);
void host_flash_erase_region(uint32_t address, uint32_t count);
#if __cplusplus
}
#endif
#endif // BOOTLOADER_HOST
#endif // _memory_h
// EOF
kStatusGroup_MemoryInterface
Memory interface status group number (102).
Definition: bootloader_common.h:145
_memorymap_constants
_memorymap_constants
Memory Map index constants.
Definition: memory.h:95
g_normalOCRAMInterface
const memory_region_interface_t g_normalOCRAMInterface
Memory interface for memory with Normal type.
Definition: normal_memory.c:65
mem_is_block_reserved
bool mem_is_block_reserved(uint32_t address, uint32_t length)
Determine if all or part of block is in a reserved region.
Definition: memory.c:254
mem_flush
status_t mem_flush(void)
Flush meory:
Definition: memory.c:194
g_flashMemoryInterface
const memory_region_interface_t g_flashMemoryInterface
Flash memory interface.
Definition: flash_memory.c:84
mem_erase
status_t mem_erase(uint32_t address, uint32_t length)
Erase memory:
Definition: memory.c:121
kMemoryIsExecutable
The memory supports executing in place.
Definition: memory.h:58
memory_region_interface_t
Interface to memory operations for one region of memory.
Definition: memory.h:75
g_memoryInterface
const memory_interface_t g_memoryInterface
Abstract memory interface.
Definition: memory.c:59
mem_is_erased
bool mem_is_erased(uint32_t address, uint32_t length)
Check is the specified memory region is erased.
Definition: memory.c:301
kMemoryNotExecutable
The memory doesn&#39;t support executing in place.
Definition: memory.h:57
find_map_entry
status_t find_map_entry(uint32_t address, uint32_t length, const memory_map_entry_t **map)
Find a map entry that matches address and length.
Definition: memory.c:219
mem_init
status_t mem_init(void)
Initialize memory interface.
Definition: memory.c:278
memory_map_entry_t
Structure of a memory map entry.
Definition: memory.h:86
mem_read
status_t mem_read(uint32_t address, uint32_t length, uint8_t *buffer)
Read memory.
Definition: memory.c:74
flash_mem_erase_all
status_t flash_mem_erase_all(flash_erase_all_option_t eraseOption)
Erase all Flash memory or all Flash execute-only segments.
Definition: flash_memory.c:539
g_normalMemoryInterface
const memory_region_interface_t g_normalMemoryInterface
Memory interface for memory with Normal type.
Definition: normal_memory.c:44
g_normalDTCMInterface
const memory_region_interface_t g_normalDTCMInterface
Memory interface for memory with Normal type.
Definition: normal_memory.c:55
g_deviceMemoryInterface
const memory_region_interface_t g_deviceMemoryInterface
Memory interface for memory with Device or Strongly-ordered type.
Definition: device_memory.c:46
host_flash_erase_all_unsecure
void host_flash_erase_all_unsecure(void)
Erase all flash (unsecure).
flash_mem_erase
status_t flash_mem_erase(uint32_t address, uint32_t length)
Erase Flash memory.
Definition: flash_memory.c:509
kSRAMSeparatrix
This value is the start address of SRAM_U.
Definition: memory.h:107
g_qspiMemoryInterface
const memory_region_interface_t g_qspiMemoryInterface
Interface to qspi memory operations.
Definition: qspi_memory.c:124
host_flash_erase_all
void host_flash_erase_all(void)
Erase all flash.
g_memoryMap
memory_map_entry_t g_memoryMap[]
Memory map for the system.
qspi_mem_erase_all
status_t qspi_mem_erase_all(void)
Erase all QSPI memory.
Definition: qspi_memory.c:491
mem_fill
status_t mem_fill(uint32_t address, uint32_t length, uint32_t pattern)
Fill memory with a word pattern.
Definition: memory.c:155
flash_mem_erase_all_unsecure
status_t flash_mem_erase_all_unsecure(void)
Erase all Flash memory (unsecure).
Definition: flash_memory.c:664
host_flash_erase_region
void host_flash_erase_region(uint32_t address, uint32_t count)
Erase a region of flash.
mem_write
status_t mem_write(uint32_t address, uint32_t length, const uint8_t *buffer)
Write memory.
Definition: memory.c:91
flash_erase_all_option_t
flash_erase_all_option_t
flash memory erase all options.
Definition: memory.h:111
_memory_interface_status
_memory_interface_status
Memory interface status codes.
Definition: memory.h:45
memory_interface_t
Interface to memory operations.
Definition: memory.h:64
status_t
int32_t status_t
Type used for all status and error return values.
Definition: fsl_common.h:121
g_qspiAliasAreaInterface
const memory_region_interface_t g_qspiAliasAreaInterface
Interface to qspi alias area operations.
Definition: qspi_memory.c:137