Add KBOOT.
This commit is contained in:
278
src/memory/memory.h
Normal file
278
src/memory/memory.h
Normal file
@@ -0,0 +1,278 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
//! @addtogroup memif
|
||||
//! @{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Declarations
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//! @brief Memory interface status codes.
|
||||
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, //!< The memory doesn't support executing in place.
|
||||
kMemoryIsExecutable = true, //!< The memory supports executing in place.
|
||||
};
|
||||
|
||||
//! @brief Interface to memory operations.
|
||||
//!
|
||||
//! This is the main abstract interface to all memory operations.
|
||||
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;
|
||||
|
||||
//! @brief Interface to memory operations for one region of memory.
|
||||
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;
|
||||
|
||||
//! @brief Structure of a memory map entry.
|
||||
typedef struct _memory_map_entry
|
||||
{
|
||||
uint32_t startAddress;
|
||||
uint32_t endAddress;
|
||||
bool isExecutable;
|
||||
const memory_region_interface_t *memoryInterface;
|
||||
} memory_map_entry_t;
|
||||
|
||||
//! @brief Memory Map index constants
|
||||
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 //!< This value is the start address of SRAM_U
|
||||
};
|
||||
|
||||
//! @brief flash memory erase all options.
|
||||
typedef enum _flash_erase_all_option
|
||||
{
|
||||
kFlashEraseAllOption_Blocks = 0,
|
||||
kFlashEraseAllOption_ExecuteOnlySegments = 1
|
||||
} flash_erase_all_option_t;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Externs
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//! @brief Memory map for the system.
|
||||
extern memory_map_entry_t g_memoryMap[];
|
||||
|
||||
//! @name Memory interfaces
|
||||
//@{
|
||||
|
||||
//! @brief Abstract memory interface.
|
||||
//!
|
||||
//! This interface utilizes the memory map to perform different memory operations
|
||||
//! depending on the region of memory being accessed.
|
||||
extern const memory_interface_t g_memoryInterface;
|
||||
|
||||
//! @brief Flash memory interface.
|
||||
extern const memory_region_interface_t g_flashMemoryInterface;
|
||||
|
||||
//! @brief Memory interface for memory with Normal type.
|
||||
//!
|
||||
//! Use of multiword loads and stores is allowed with this memory type.
|
||||
extern const memory_region_interface_t g_normalMemoryInterface;
|
||||
|
||||
#if CPU_IS_ARM_CORTEX_M7
|
||||
//! @brief Memory interface for memory with Normal type.
|
||||
//!
|
||||
//! Use of multiword loads and stores is allowed with this memory type.
|
||||
extern const memory_region_interface_t g_normalDTCMInterface;
|
||||
|
||||
//! @brief Memory interface for memory with Normal type.
|
||||
//!
|
||||
//! Use of multiword loads and stores is allowed with this memory type.
|
||||
extern const memory_region_interface_t g_normalOCRAMInterface;
|
||||
#endif
|
||||
|
||||
//! @brief Memory interface for memory with Device or Strongly-ordered type.
|
||||
//!
|
||||
//! This memory type does not support multiword loads and stores.
|
||||
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
|
||||
|
||||
//! @name Generic memory interface implementation
|
||||
//@{
|
||||
|
||||
//! @brief Initialize memory interface.
|
||||
status_t mem_init(void);
|
||||
|
||||
//! @brief Read memory.
|
||||
status_t mem_read(uint32_t address, uint32_t length, uint8_t *buffer);
|
||||
|
||||
//! @brief Write memory.
|
||||
status_t mem_write(uint32_t address, uint32_t length, const uint8_t *buffer);
|
||||
|
||||
//! @brief Fill memory with a word pattern.
|
||||
status_t mem_fill(uint32_t address, uint32_t length, uint32_t pattern);
|
||||
|
||||
//! @brief Erase memory:
|
||||
status_t mem_erase(uint32_t address, uint32_t length);
|
||||
|
||||
//! @brief Flush meory:
|
||||
status_t mem_flush(void);
|
||||
|
||||
//! @brief Find a map entry that matches address and length.
|
||||
status_t find_map_entry(uint32_t address, uint32_t length, const memory_map_entry_t **map);
|
||||
|
||||
//!@brief Check is the specified memory region is erased.
|
||||
bool mem_is_erased(uint32_t address, uint32_t length);
|
||||
|
||||
//@}
|
||||
|
||||
//! @name Memory utilities
|
||||
//@{
|
||||
|
||||
//! @brief Determine if all or part of block is in a reserved region.
|
||||
bool mem_is_block_reserved(uint32_t address, uint32_t length);
|
||||
|
||||
//@}
|
||||
|
||||
//! @name Flash erase operations
|
||||
//@{
|
||||
|
||||
//! @brief Erase Flash memory.
|
||||
status_t flash_mem_erase(uint32_t address, uint32_t length);
|
||||
|
||||
#if BL_FEATURE_FAC_ERASE
|
||||
//! @brief Erase all Flash memory or all Flash execute-only segments.
|
||||
//!
|
||||
//! It is only valid for non-flash resident bootloader when option is erasing execute-only segments.
|
||||
status_t flash_mem_erase_all(flash_erase_all_option_t eraseOption);
|
||||
#else
|
||||
//! @brief Erase all Flash memory.
|
||||
//!
|
||||
//! If building for flash resident bootloader, we have to decompose the the flash erase all
|
||||
//! operation into two region erases. This allows the user to still do an erase all, but not
|
||||
//! wipe out the bootloader itself.
|
||||
status_t flash_mem_erase_all(void);
|
||||
#endif
|
||||
|
||||
//! @brief Erase all Flash memory (unsecure).
|
||||
status_t flash_mem_erase_all_unsecure(void);
|
||||
|
||||
//@}
|
||||
|
||||
//! @name QSPI erase operation
|
||||
//@{
|
||||
|
||||
//! @brief Erase all QSPI memory
|
||||
status_t qspi_mem_erase_all(void);
|
||||
//@}
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif // __cplusplus
|
||||
|
||||
#if defined(BOOTLOADER_HOST)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Simulator host prototypes
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//! @brief Erase all flash.
|
||||
void host_flash_erase_all(void);
|
||||
|
||||
//! @brief Erase all flash (unsecure).
|
||||
void host_flash_erase_all_unsecure(void);
|
||||
|
||||
//! @brief Erase a region of flash.
|
||||
void host_flash_erase_region(uint32_t address, uint32_t count);
|
||||
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // BOOTLOADER_HOST
|
||||
|
||||
//! @}
|
||||
|
||||
#endif // _memory_h
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// EOF
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
125
src/memory/src/device_memory.c
Normal file
125
src/memory/src/device_memory.c
Normal file
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "device_memory.h"
|
||||
#include "pattern_fill.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Prototypes
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static void device_copy(uint32_t address, uint32_t length, uint32_t buffer);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Variables
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//! @brief Interface to simulator memory operations.
|
||||
const memory_region_interface_t g_deviceMemoryInterface = {.read = &device_mem_read,
|
||||
.write = &device_mem_write,
|
||||
#if !BL_FEATURE_MIN_PROFILE || BL_FEATURE_FILL_MEMORY
|
||||
.fill = &device_mem_fill,
|
||||
#endif // !BL_FEATURE_MIN_PROFILE
|
||||
.flush = NULL,
|
||||
.erase = NULL };
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Code
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//! @brief Device-safe memory copy.
|
||||
//!
|
||||
//! Performs a memory copy using aligned accesses of no more than one word
|
||||
//! at a time.
|
||||
void device_copy(uint32_t address, uint32_t length, uint32_t buffer)
|
||||
{
|
||||
// This loop lets us reuse the byte and halfword copy code.
|
||||
while (length)
|
||||
{
|
||||
// Handle leading/trailing byte.
|
||||
if ((address & 1) || (length == 1))
|
||||
{
|
||||
*(uint8_t *)address = *(const uint8_t *)buffer;
|
||||
++address;
|
||||
++buffer;
|
||||
--length;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Handle leading/trailing halfword.
|
||||
if ((address & 2) || (length < sizeof(uint32_t)))
|
||||
{
|
||||
*(uint16_t *)address = *(const uint16_t *)buffer;
|
||||
address += sizeof(uint16_t);
|
||||
buffer += sizeof(uint16_t);
|
||||
length -= sizeof(uint16_t);
|
||||
}
|
||||
|
||||
// Copy as many whole words as remain.
|
||||
uint32_t words = length >> 2;
|
||||
if (words)
|
||||
{
|
||||
uint32_t wordsLength = words << 2;
|
||||
uint32_t end = address + wordsLength;
|
||||
while (address < end)
|
||||
{
|
||||
*(uint32_t *)address = *(uint32_t *)buffer;
|
||||
address += sizeof(uint32_t);
|
||||
buffer += sizeof(uint32_t);
|
||||
}
|
||||
|
||||
length -= wordsLength;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
status_t device_mem_read(uint32_t address, uint32_t length, uint8_t *buffer)
|
||||
{
|
||||
device_copy((uint32_t)buffer, length, address);
|
||||
return kStatus_Success;
|
||||
}
|
||||
|
||||
status_t device_mem_write(uint32_t address, uint32_t length, const uint8_t *buffer)
|
||||
{
|
||||
device_copy(address, length, (uint32_t)buffer);
|
||||
return kStatus_Success;
|
||||
}
|
||||
|
||||
status_t device_mem_fill(uint32_t address, uint32_t length, uint32_t pattern)
|
||||
{
|
||||
status_t status = kStatus_Success;
|
||||
status = pattern_fill(address, pattern, length, true);
|
||||
return status;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// EOF
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
64
src/memory/src/device_memory.h
Normal file
64
src/memory/src/device_memory.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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(__DEVICE_MEMORY_INTERFACE_H__)
|
||||
#define __DEVICE_MEMORY_INTERFACE_H__
|
||||
|
||||
#include "memory/memory.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Prototypes
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
//! @name Device memory
|
||||
//@{
|
||||
|
||||
//! @brief Read memory.
|
||||
status_t device_mem_read(uint32_t address, uint32_t length, uint8_t *restrict buffer);
|
||||
|
||||
//! @brief Write memory.
|
||||
status_t device_mem_write(uint32_t address, uint32_t length, const uint8_t *restrict buffer);
|
||||
|
||||
//! @brief Fill memory with a word pattern.
|
||||
status_t device_mem_fill(uint32_t address, uint32_t length, uint32_t pattern);
|
||||
|
||||
//@}
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // __DEVICE_MEMORY_INTERFACE_H__
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// EOF
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
778
src/memory/src/flash_memory.c
Normal file
778
src/memory/src/flash_memory.c
Normal file
File diff suppressed because it is too large
Load Diff
81
src/memory/src/flash_memory.h
Normal file
81
src/memory/src/flash_memory.h
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2014, 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(__FLASH_MEMORY_INTERFACE_H__)
|
||||
#define __FLASH_MEMORY_INTERFACE_H__
|
||||
|
||||
#include "memory/memory.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Definitions
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define BL_IS_FLASH_SECTION_PROGRAMMING_ENABLED \
|
||||
(BL_FEATURE_ENABLE_FLASH_PROGRAM_SECTION && FSL_FEATURE_FLASH_HAS_PROGRAM_SECTION_CMD)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Prototypes
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
//! @name Flash memory
|
||||
//! @note Flash read is done through the normal memory interface.
|
||||
//@{
|
||||
|
||||
//! @brief Init Flash memory
|
||||
status_t flash_mem_init(void);
|
||||
|
||||
//! @brief Read memory.
|
||||
status_t flash_mem_read(uint32_t address, uint32_t length, uint8_t *restrict buffer);
|
||||
|
||||
//! @brief Write memory.
|
||||
status_t flash_mem_write(uint32_t address, uint32_t length, const uint8_t *buffer);
|
||||
|
||||
//! @brief Fill memory with a word pattern.
|
||||
status_t flash_mem_fill(uint32_t address, uint32_t length, uint32_t pattern);
|
||||
|
||||
//! @brief Flush final buffer or cached data into FLASH memory.
|
||||
status_t flash_mem_flush(void);
|
||||
|
||||
//! @brief Erase memory.
|
||||
status_t flash_mem_erase(uint32_t address, uint32_t length);
|
||||
|
||||
//@}
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // __FLASH_MEMORY_INTERFACE_H__
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// EOF
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
327
src/memory/src/memory.c
Normal file
327
src/memory/src/memory.c
Normal file
@@ -0,0 +1,327 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "bootloader_common.h"
|
||||
#include "bootloader/bl_context.h"
|
||||
#include "memory/memory.h"
|
||||
#if !defined(BOOTLOADER_HOST)
|
||||
#include "drivers/flash/fsl_flash.h"
|
||||
#include "fsl_device_registers.h"
|
||||
#include "flash_memory.h"
|
||||
#endif // BOOTLOADER_HOST
|
||||
#include "utilities/fsl_assert.h"
|
||||
|
||||
//! @addtogroup memif
|
||||
//! @{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Prototypes
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Forward function declarations.
|
||||
bool mem_is_block_reserved(uint32_t address, uint32_t length);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Variables
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//! @brief This variable is used to do flush operation, it is bind to write operation.
|
||||
static const memory_region_interface_t *s_flushMemoryInterface = NULL;
|
||||
|
||||
//! @brief Interface to generic memory operations.
|
||||
const memory_interface_t g_memoryInterface = {
|
||||
mem_init, mem_read, mem_write,
|
||||
#if !BL_FEATURE_MIN_PROFILE || BL_FEATURE_FILL_MEMORY
|
||||
mem_fill,
|
||||
#else
|
||||
NULL,
|
||||
#endif // !BL_FEATURE_MIN_PROFILE
|
||||
mem_flush, mem_erase,
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Code
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// See memory.h for documentation on this function.
|
||||
status_t mem_read(uint32_t address, uint32_t length, uint8_t *buffer)
|
||||
{
|
||||
if (length == 0)
|
||||
{
|
||||
return kStatus_Success;
|
||||
}
|
||||
|
||||
const memory_map_entry_t *mapEntry;
|
||||
status_t status = find_map_entry(address, length, &mapEntry);
|
||||
if (status == kStatus_Success)
|
||||
{
|
||||
status = mapEntry->memoryInterface->read(address, length, buffer);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
// See memory.h for documentation on this function.
|
||||
status_t mem_write(uint32_t address, uint32_t length, const uint8_t *buffer)
|
||||
{
|
||||
if (length == 0)
|
||||
{
|
||||
return kStatus_Success;
|
||||
}
|
||||
|
||||
if (mem_is_block_reserved(address, length))
|
||||
{
|
||||
return kStatusMemoryRangeInvalid;
|
||||
}
|
||||
|
||||
const memory_map_entry_t *mapEntry;
|
||||
status_t status = find_map_entry(address, length, &mapEntry);
|
||||
if (status == kStatus_Success)
|
||||
{
|
||||
status = mapEntry->memoryInterface->write(address, length, buffer);
|
||||
|
||||
if (status == kStatus_Success)
|
||||
{
|
||||
s_flushMemoryInterface = mapEntry->memoryInterface;
|
||||
}
|
||||
else
|
||||
{
|
||||
s_flushMemoryInterface = NULL;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
status_t mem_erase(uint32_t address, uint32_t length)
|
||||
{
|
||||
status_t status = kStatus_Success;
|
||||
|
||||
#if !defined(BOOTLOADER_HOST)
|
||||
const memory_map_entry_t *mapEntry;
|
||||
status = find_map_entry(address, length, &mapEntry);
|
||||
if (status == kStatus_Success)
|
||||
{
|
||||
// In this case, it means that bootloader tries to erase a range of memory
|
||||
// which doesn't support erase operaton
|
||||
if (mapEntry->memoryInterface->erase == NULL)
|
||||
{
|
||||
return kStatus_FLASH_AddressError;
|
||||
}
|
||||
|
||||
if (mem_is_block_reserved(address, length))
|
||||
{
|
||||
return kStatusMemoryRangeInvalid;
|
||||
}
|
||||
|
||||
status = mapEntry->memoryInterface->erase(address, length);
|
||||
}
|
||||
else if (length == 0)
|
||||
{
|
||||
// if length = 0, return kStatus_Success regardless of memory address
|
||||
return kStatus_Success;
|
||||
}
|
||||
#endif // BOOTLOADER_HOST
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
// See memory.h for documentation on this function.
|
||||
status_t mem_fill(uint32_t address, uint32_t length, uint32_t pattern)
|
||||
{
|
||||
if (length == 0)
|
||||
{
|
||||
return kStatus_Success;
|
||||
}
|
||||
|
||||
if (mem_is_block_reserved(address, length))
|
||||
{
|
||||
return kStatusMemoryRangeInvalid;
|
||||
}
|
||||
|
||||
const memory_map_entry_t *mapEntry;
|
||||
status_t status = find_map_entry(address, length, &mapEntry);
|
||||
if (status == kStatus_Success)
|
||||
{
|
||||
status = mapEntry->memoryInterface->fill(address, length, pattern);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
//! @brief Flush buffered data into target memory
|
||||
//! @note 1. This function should be called immediately after one write-memory command(either
|
||||
//! received in command packet or in sb file), only in this way, given data can be programmed
|
||||
//! at given address as expected.
|
||||
//!
|
||||
//! 2. So far, flush() is only implemented in qspi memory interface, for other memory
|
||||
//! interfaces, it is not available and mem_flush() just returns kStatus_Success if it is
|
||||
//! called.
|
||||
//!
|
||||
//! 3. This function is designed to flush buffered data into target memory, please call it
|
||||
//! only if it is required to do so. For example, write 128 bytes to qspi flash, while the
|
||||
//! page size is 256 bytes, that means data might not be written to qspi memory immediately,
|
||||
//! since the internal buffer of qspi memory interface is not full, if no data are expected
|
||||
//! to write to left area of the same page, this function can be used to force to write
|
||||
//! immediately, otherwise, keep in mind that any calls should be avoided. If users voilate
|
||||
//! this rules, it would make the left area of the same page cannot be programmed.
|
||||
//!
|
||||
//! @return An error code or kStatus_Success
|
||||
status_t mem_flush(void)
|
||||
{
|
||||
status_t status = kStatus_Success;
|
||||
|
||||
#if !defined(BOOTLOADER_HOST)
|
||||
if (s_flushMemoryInterface && s_flushMemoryInterface->flush)
|
||||
{
|
||||
status = s_flushMemoryInterface->flush();
|
||||
s_flushMemoryInterface = NULL; // Clear this variable after performing flush operation
|
||||
}
|
||||
#endif // BOOTLOADER_HOST
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
//! @brief Find a map entry that matches address and length.
|
||||
//!
|
||||
//! @param address Start address for the memory operation.
|
||||
//! @param length Number of bytes on which the operation will act.
|
||||
//! @param map The matching map entry is returned through this pointer if the return status
|
||||
//! is #kStatus_Success.
|
||||
//!
|
||||
//! @retval #kStatus_Success A valid map entry was found and returned through @a map.
|
||||
//! @retval #kStatusMemoryRangeInvalid The requested address range does not match an entry, or
|
||||
//! the length extends past the matching entry's end address.
|
||||
status_t find_map_entry(uint32_t address, uint32_t length, const memory_map_entry_t **map)
|
||||
{
|
||||
status_t status = kStatusMemoryRangeInvalid;
|
||||
|
||||
// Set starting entry.
|
||||
assert(map);
|
||||
if (map)
|
||||
{
|
||||
*map = &g_bootloaderContext.memoryMap[0];
|
||||
}
|
||||
|
||||
// Scan memory map array looking for a match.
|
||||
while ((length > 0) && map && *map)
|
||||
{
|
||||
if (((*map)->startAddress == 0) && ((*map)->endAddress == 0) && ((*map)->memoryInterface == NULL))
|
||||
{
|
||||
break;
|
||||
}
|
||||
// Check if the start address is within this entry's address range.
|
||||
if ((address >= (*map)->startAddress) && (address <= (*map)->endAddress))
|
||||
{
|
||||
// Check that the length fits in this entry's address range.
|
||||
if ((address + length - 1) <= (*map)->endAddress)
|
||||
{
|
||||
status = kStatus_Success;
|
||||
}
|
||||
break;
|
||||
}
|
||||
++(*map);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
// See memory.h for documentation on this function.
|
||||
bool mem_is_block_reserved(uint32_t address, uint32_t length)
|
||||
{
|
||||
uint32_t end = address + length - 1;
|
||||
uint32_t start = 0;
|
||||
for (uint32_t i = 0; i < kProperty_ReservedRegionsCount; ++i)
|
||||
{
|
||||
reserved_region_t *region = &g_bootloaderContext.propertyInterface->store->reservedRegions[i];
|
||||
|
||||
start = (&g_bootloaderContext.memoryMap[i])->startAddress;
|
||||
if ((region->startAddress == start) && (region->endAddress == start))
|
||||
{
|
||||
// Special case, empty region
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((address <= region->endAddress) && (end >= region->startAddress))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// See memory.h for documentation on this function.
|
||||
status_t mem_init(void)
|
||||
{
|
||||
status_t status = kStatus_Success;
|
||||
|
||||
#if !defined(BOOTLOADER_HOST)
|
||||
|
||||
const memory_map_entry_t *map = &g_bootloaderContext.memoryMap[0];
|
||||
|
||||
while (map->memoryInterface)
|
||||
{
|
||||
if (map->memoryInterface->init)
|
||||
{
|
||||
map->memoryInterface->init();
|
||||
}
|
||||
++map;
|
||||
}
|
||||
|
||||
#endif // BOOTLOADER_HOST
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
// See memory.h for documentation on this function.
|
||||
bool mem_is_erased(uint32_t address, uint32_t length)
|
||||
{
|
||||
const uint8_t *start = (const uint8_t *)address;
|
||||
bool isMemoryErased = true;
|
||||
|
||||
while (length)
|
||||
{
|
||||
if (*start != 0xFF)
|
||||
{
|
||||
isMemoryErased = false;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
length--;
|
||||
start++;
|
||||
}
|
||||
}
|
||||
|
||||
return isMemoryErased;
|
||||
}
|
||||
|
||||
//! @}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// EOF
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
129
src/memory/src/normal_memory.c
Normal file
129
src/memory/src/normal_memory.c
Normal file
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "normal_memory.h"
|
||||
#include "pattern_fill.h"
|
||||
#include "sram_init.h"
|
||||
#if !defined(BOOTLOADER_HOST)
|
||||
#include "fsl_device_registers.h"
|
||||
#endif // BOOTLOADER_HOST
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Variables
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//! @brief Interface to simulator memory operations.
|
||||
const memory_region_interface_t g_normalMemoryInterface = {.init = &normal_mem_init,
|
||||
.read = &normal_mem_read,
|
||||
.write = &normal_mem_write,
|
||||
#if !BL_FEATURE_MIN_PROFILE || BL_FEATURE_FILL_MEMORY
|
||||
.fill = &normal_mem_fill,
|
||||
#endif // !BL_FEATURE_MIN_PROFILE
|
||||
.flush = NULL,
|
||||
.erase = NULL };
|
||||
|
||||
#if CPU_IS_ARM_CORTEX_M7
|
||||
//! @brief Interface to simulator memory operations.
|
||||
const memory_region_interface_t g_normalDTCMInterface = {.init = &normal_mem_init,
|
||||
.read = &normal_mem_read,
|
||||
.write = &normal_mem_write,
|
||||
#if !BL_FEATURE_MIN_PROFILE || BL_FEATURE_FILL_MEMORY
|
||||
.fill = &normal_mem_fill,
|
||||
#endif // !BL_FEATURE_MIN_PROFILE
|
||||
.flush = NULL,
|
||||
.erase = NULL };
|
||||
|
||||
//! @brief Interface to simulator memory operations.
|
||||
const memory_region_interface_t g_normalOCRAMInterface = {.init = &normal_mem_init,
|
||||
.read = &normal_mem_read,
|
||||
.write = &normal_mem_write,
|
||||
#if !BL_FEATURE_MIN_PROFILE || BL_FEATURE_FILL_MEMORY
|
||||
.fill = &normal_mem_fill,
|
||||
#endif // !BL_FEATURE_MIN_PROFILE
|
||||
.flush = NULL,
|
||||
.erase = NULL };
|
||||
#endif
|
||||
|
||||
enum
|
||||
{
|
||||
kSRAM_Boundary = 0x20000000u //!< SRAM boundary address
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Code
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//! See normal_memory.h for documentation on this function.
|
||||
status_t normal_mem_init(void)
|
||||
{
|
||||
return sram_init();
|
||||
}
|
||||
|
||||
status_t normal_mem_read(uint32_t address, uint32_t length, uint8_t *buffer)
|
||||
{
|
||||
memcpy((void *)buffer, (void *)address, length);
|
||||
return kStatus_Success;
|
||||
}
|
||||
|
||||
status_t normal_mem_write(uint32_t address, uint32_t length, const uint8_t *buffer)
|
||||
{
|
||||
#if defined(__CORE_CM4_H_GENERIC)
|
||||
// If address is non-longword aligned and the area to be written is across RAM_L and RAM_U,
|
||||
// need to write the RAM_L first and then write RAM_U to avoid unaligned access across RAM boundary
|
||||
if ((address & 0x03) && ((address < kSRAM_Boundary) && ((address + length - 1) >= kSRAM_Boundary)))
|
||||
{
|
||||
uint32_t firstCopyCount = kSRAM_Boundary - address;
|
||||
uint32_t secondCopyCount = length - firstCopyCount;
|
||||
|
||||
memcpy((void *)address, (void *)buffer, firstCopyCount);
|
||||
memcpy((void *)kSRAM_Boundary, (void *)(buffer + firstCopyCount), secondCopyCount);
|
||||
}
|
||||
else
|
||||
#endif // #if defined (__CORE_CM4_H_GENERIC)
|
||||
{
|
||||
memcpy((void *)address, (void *)buffer, length);
|
||||
}
|
||||
return kStatus_Success;
|
||||
}
|
||||
|
||||
status_t normal_mem_fill(uint32_t address, uint32_t length, uint32_t pattern)
|
||||
{
|
||||
status_t status = kStatus_Success;
|
||||
// Allow multiword stores in the pattern fill.
|
||||
#if !BL_FEATURE_MIN_PROFILE || BL_FEATURE_FILL_MEMORY
|
||||
status = pattern_fill(address, pattern, length, true);
|
||||
#endif // !BL_FEATURE_MIN_PROFILE
|
||||
return status;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// EOF
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
67
src/memory/src/normal_memory.h
Normal file
67
src/memory/src/normal_memory.h
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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(__NORMAL_MEMORY_INTERFACE_H__)
|
||||
#define __NORMAL_MEMORY_INTERFACE_H__
|
||||
|
||||
#include "memory/memory.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Prototypes
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
//! @name Normal memory
|
||||
//@{
|
||||
|
||||
//! @brief Init Normal memory
|
||||
status_t normal_mem_init(void);
|
||||
|
||||
//! @brief Read memory.
|
||||
status_t normal_mem_read(uint32_t address, uint32_t length, uint8_t *restrict buffer);
|
||||
|
||||
//! @brief Write memory.
|
||||
status_t normal_mem_write(uint32_t address, uint32_t length, const uint8_t *restrict buffer);
|
||||
|
||||
//! @brief Fill memory with a word pattern.
|
||||
status_t normal_mem_fill(uint32_t address, uint32_t length, uint32_t pattern);
|
||||
|
||||
//@}
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // __NORMAL_MEMORY_INTERFACE_H__
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// EOF
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
59
src/memory/src/pattern_fill.h
Normal file
59
src/memory/src/pattern_fill.h
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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(__PATTERN_FILL_H__)
|
||||
#define __PATTERN_FILL_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "bootloader_common.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Prototypes
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
//! @brief Fill memory with a pattern.
|
||||
//!
|
||||
//! Fills memory with a 32-bit pattern starting at the given address and continuing
|
||||
//! for the specified number of bytes. The start address and length do not have to
|
||||
//! be word aligned or sized.
|
||||
status_t pattern_fill(uint32_t address, uint32_t pattern, uint32_t length, bool allowMultiword);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // __PATTERN_FILL_H__
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// EOF
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
153
src/memory/src/pattern_fill.s
Normal file
153
src/memory/src/pattern_fill.s
Normal file
@@ -0,0 +1,153 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//! \addtogroup rom_loader
|
||||
//! @{
|
||||
//!
|
||||
// Copyright (c) 2006 SigmaTel, Inc.
|
||||
//!
|
||||
//! \file ldr_fill.asm
|
||||
//! \brief Fast ARM assembler implementation of boot fill command.
|
||||
//!
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#include "../../startup/ar_asm_macros.h"
|
||||
|
||||
_CODE_SECTION(.text)
|
||||
|
||||
_THUMB
|
||||
|
||||
|
||||
|
||||
// FUNCTION: int pattern_fill( u32 addr, u32 pattern, u32 byteCount, bool allowMultiword )
|
||||
// Fills memory with 32bit pattern in r1 starting at (any alignment)
|
||||
// address in r0 for a length of r2 bytes.
|
||||
// Inputs:
|
||||
// r0 destination address
|
||||
// r1 32bit fill pattern
|
||||
// r2 number of bytes to fill
|
||||
// r3 pass 1 to use multiword stores
|
||||
//
|
||||
// Outputs:
|
||||
// r0 = 0 SUCCESS
|
||||
// r0 = 1 FAIL
|
||||
//
|
||||
// Registers USED: r0 - r7
|
||||
|
||||
_EXPORT(pattern_fill)
|
||||
|
||||
pattern_fill
|
||||
|
||||
// basic parameter checks
|
||||
|
||||
cmp r2, #0 // anything to do?
|
||||
bne label_pass
|
||||
|
||||
// fail
|
||||
movs r0, #1 // FAIL
|
||||
bx lr
|
||||
|
||||
label_pass
|
||||
// do it to it...
|
||||
|
||||
stmfd sp!, {r4-r7}
|
||||
|
||||
mov r7, r3 // copy allowMultiword param to r7
|
||||
mov r3, r0 // copy destination addres to r3
|
||||
|
||||
movs r4, #3
|
||||
ands r3, r4 // address word aligned?
|
||||
cmp r3, #0
|
||||
beq do_words
|
||||
|
||||
//rsb r3, r3, #4
|
||||
movs r4, #4
|
||||
subs r3, r4, r3
|
||||
|
||||
// if we are here, r3 has count of byte stores we need to do
|
||||
// to get into 32bit alignment....
|
||||
|
||||
do_bytes // store 1 byte at address in r0
|
||||
strb r1, [r0] //, #1
|
||||
adds r0, #1
|
||||
// movs r1, r1 ROR r4
|
||||
movs r4, #8
|
||||
rors r1, r1, r4
|
||||
|
||||
// check if we are done
|
||||
subs r2, r2, #1
|
||||
beq done
|
||||
|
||||
// check for need of another byte store
|
||||
subs r3, r3, #1
|
||||
bne do_bytes
|
||||
|
||||
// at least 4 bytes left?
|
||||
do_words cmp r2, #4
|
||||
blt trailing_bytes
|
||||
beq try_4
|
||||
|
||||
// 5 or more bytes...
|
||||
|
||||
// check if multiword stores are allowed
|
||||
// if not, skip 16-, 12- and 8-byte writes
|
||||
cmp r7, #0
|
||||
beq try_4
|
||||
|
||||
// copy pattern into extra registers
|
||||
mov r4, r1
|
||||
mov r5, r1
|
||||
mov r6, r1
|
||||
|
||||
// store (possibly rotated) 32bits word(s)
|
||||
|
||||
// try for 16 bytes
|
||||
try_16 cmp r2, #16
|
||||
blt try_12
|
||||
stmia r0!, {r1,r4,r5,r6}
|
||||
subs r2, r2, #16
|
||||
b try_16
|
||||
|
||||
// try for 12 bytes
|
||||
try_12 cmp r2, #12
|
||||
blt try_8
|
||||
stmia r0!, {r1,r4,r5}
|
||||
subs r2, r2, #12
|
||||
b try_12
|
||||
|
||||
// try for 8 bytes
|
||||
try_8 cmp r2, #8
|
||||
blt try_4
|
||||
stmia r0!, {r1,r4}
|
||||
subs r2, r2, #8
|
||||
b try_8
|
||||
|
||||
// try for 4 bytes
|
||||
try_4 cmp r2, #4
|
||||
blt trailing_bytes
|
||||
str r1, [r0] //, #4
|
||||
adds r0, #4
|
||||
subs r2, r2, #4
|
||||
b try_4
|
||||
|
||||
trailing_bytes // anything left?
|
||||
cmp r2, #0
|
||||
beq done
|
||||
|
||||
// 1-3 byte stores needed
|
||||
strb r1, [r0] //, #1
|
||||
adds r0, #1
|
||||
// mov r1, r1 ROR #8
|
||||
movs r4, #8
|
||||
rors r1, r1, r4
|
||||
|
||||
// check if we are done
|
||||
subs r2, r2, #1
|
||||
bne trailing_bytes
|
||||
|
||||
done ldmfd sp!, {r4-r7}
|
||||
movs r0, #0 // SUCCESS
|
||||
bx lr
|
||||
|
||||
|
||||
_END
|
||||
|
||||
// eof ldr_fill.arm
|
||||
//! @}
|
||||
156
src/memory/src/pattern_fill_gcc.S
Normal file
156
src/memory/src/pattern_fill_gcc.S
Normal file
@@ -0,0 +1,156 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//! \addtogroup rom_loader
|
||||
//! @{
|
||||
//!
|
||||
// Copyright (c) 2006 SigmaTel, Inc.
|
||||
//!
|
||||
//! \file ldr_fill.asm
|
||||
//! \brief Fast ARM assembler implementation of boot fill command.
|
||||
//!
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
.syntax unified
|
||||
.arch armv6-m
|
||||
|
||||
.section .pattern_fill, "a"
|
||||
.align 2
|
||||
.globl pattern_fill
|
||||
.text
|
||||
.thumb
|
||||
.thumb_func
|
||||
.align 2
|
||||
.type pattern_fill, %function
|
||||
|
||||
// FUNCTION: int pattern_fill( u32 addr, u32 pattern, u32 byteCount, bool allowMultiword )
|
||||
// Fills memory with 32bit pattern in r1 starting at (any alignment)
|
||||
// address in r0 for a length of r2 bytes.
|
||||
// Inputs:
|
||||
// r0 destination address
|
||||
// r1 32bit fill pattern
|
||||
// r2 number of bytes to fill
|
||||
// r3 pass 1 to use multiword stores
|
||||
//
|
||||
// Outputs:
|
||||
// r0 = 0 SUCCESS
|
||||
// r0 = 1 FAIL
|
||||
//
|
||||
// Registers USED: r0 - r7
|
||||
|
||||
pattern_fill:
|
||||
|
||||
// basic parameter checks
|
||||
|
||||
cmp r2, #0 // anything to do?
|
||||
bne _pass
|
||||
|
||||
// fail
|
||||
movs r0, #1 // FAIL
|
||||
bx lr
|
||||
|
||||
_pass:
|
||||
// do it to it...
|
||||
|
||||
push {r4-r7}
|
||||
|
||||
mov r7, r3 // copy allowMultiword param to r7
|
||||
mov r3, r0 // copy destination addres to r3
|
||||
|
||||
movs r4, #3
|
||||
ands r3, r4 // address word aligned?
|
||||
cmp r3, #0
|
||||
beq do_words
|
||||
|
||||
//rsb r3, r3, #4
|
||||
movs r4, #4
|
||||
subs r3, r4, r3
|
||||
|
||||
// if we are here, r3 has count of byte stores we need to do
|
||||
// to get into 32bit alignment....
|
||||
|
||||
do_bytes: // store 1 byte at address in r0
|
||||
strb r1, [r0] //, #1
|
||||
adds r0, #1
|
||||
// movs r1, r1 ROR r4
|
||||
movs r4, #8
|
||||
rors r1, r1, r4
|
||||
|
||||
// check if we are done
|
||||
subs r2, r2, #1
|
||||
beq done
|
||||
|
||||
// check for need of another byte store
|
||||
subs r3, r3, #1
|
||||
bne do_bytes
|
||||
|
||||
// at least 4 bytes left?
|
||||
do_words: cmp r2, #4
|
||||
blt trailing_bytes
|
||||
beq try_4
|
||||
|
||||
// 5 or more bytes...
|
||||
|
||||
// check if multiword stores are allowed
|
||||
// if not, skip 16-, 12- and 8-byte writes
|
||||
cmp r7, #0
|
||||
beq try_4
|
||||
|
||||
// copy pattern into extra registers
|
||||
mov r4, r1
|
||||
mov r5, r1
|
||||
mov r6, r1
|
||||
|
||||
// store (possibly rotated) 32bits word(s)
|
||||
|
||||
// try for 16 bytes
|
||||
try_16: cmp r2, #16
|
||||
blt try_12
|
||||
stmia r0!, {r1,r4,r5,r6}
|
||||
subs r2, r2, #16
|
||||
b try_16
|
||||
|
||||
// try for 12 bytes
|
||||
try_12: cmp r2, #12
|
||||
blt try_8
|
||||
stmia r0!, {r1,r4,r5}
|
||||
subs r2, r2, #12
|
||||
b try_12
|
||||
|
||||
// try for 8 bytes
|
||||
try_8: cmp r2, #8
|
||||
blt try_4
|
||||
stmia r0!, {r1,r4}
|
||||
subs r2, r2, #8
|
||||
b try_8
|
||||
|
||||
// try for 4 bytes
|
||||
try_4: cmp r2, #4
|
||||
blt trailing_bytes
|
||||
str r1, [r0] //, #4
|
||||
adds r0, #4
|
||||
subs r2, r2, #4
|
||||
b try_4
|
||||
|
||||
trailing_bytes: // anything left?
|
||||
cmp r2, #0
|
||||
beq done
|
||||
|
||||
// 1-3 byte stores needed
|
||||
strb r1, [r0] //, #1
|
||||
adds r0, #1
|
||||
// mov r1, r1 ROR #8
|
||||
movs r4, #8
|
||||
rors r1, r1, r4
|
||||
|
||||
// check if we are done
|
||||
subs r2, r2, #1
|
||||
bne trailing_bytes
|
||||
|
||||
done: pop {r4-r7}
|
||||
movs r0, #0 // SUCCESS
|
||||
bx lr
|
||||
|
||||
|
||||
.end
|
||||
|
||||
// eof ldr_fill.arm
|
||||
//! @}
|
||||
613
src/memory/src/qspi_memory.c
Normal file
613
src/memory/src/qspi_memory.c
Normal file
File diff suppressed because it is too large
Load Diff
83
src/memory/src/qspi_memory.h
Normal file
83
src/memory/src/qspi_memory.h
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 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(__QSPI_MEMORY_INTERFACE_H__)
|
||||
#define __QSPI_MEMORY_INTERFACE_H__
|
||||
|
||||
#include "memory/memory.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Prototypes
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
enum
|
||||
{
|
||||
kQspiMemoryId_QuadSpiMemory = 0,
|
||||
kQspiMemoryId_AliasArea = 1,
|
||||
};
|
||||
|
||||
//! @name QSPI memory
|
||||
//! @note QSPI read is done through the normal memory interface.
|
||||
//@{
|
||||
|
||||
//! @brief Initialize QSPI memory
|
||||
status_t qspi_mem_init(uint32_t memoryId);
|
||||
|
||||
//! @brief Read QSPI memory.
|
||||
status_t qspi_mem_read(uint32_t address, uint32_t length, uint8_t *restrict buffer);
|
||||
|
||||
//! @brief Write QSPI Flash memory.
|
||||
status_t qspi_mem_write(uint32_t memoryId, uint32_t address, uint32_t length, const uint8_t *buffer);
|
||||
|
||||
//! @brief Fill QSPI memory with a word pattern.
|
||||
status_t qspi_mem_fill(uint32_t memoryId, uint32_t address, uint32_t length, uint32_t pattern);
|
||||
|
||||
//! @brief Erase QSPI memory
|
||||
status_t qspi_mem_erase(uint32_t memoryId, uint32_t address, uint32_t length);
|
||||
|
||||
//! @brief Erase all QSPI memory
|
||||
status_t qspi_mem_erase_all(void);
|
||||
|
||||
//! @brief Flush cached data into QSPI memory
|
||||
status_t qspi_mem_flush(void);
|
||||
|
||||
//@}
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // __QSPI_MEMORY_INTERFACE_H__
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// EOF
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
96
src/memory/src/sram_init.h
Normal file
96
src/memory/src/sram_init.h
Normal file
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 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 __SRAM_INIT_H__
|
||||
#define __SRAM_INIT_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include "memory/memory.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Declarations
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//! @brief SRAM size-related constants of KL series (CM0+ family)
|
||||
enum _kl_serials_sram_constants
|
||||
{
|
||||
kMaxRamIndex = 7,
|
||||
kMinKlRamSize = (uint32_t)512
|
||||
};
|
||||
|
||||
#if defined(__CORE_CM4_H_GENERIC) || defined(__CORE_CM7_H_GENERIC)
|
||||
//! @brief valid SRAM size index of K series (CM4 family)
|
||||
enum _k_serials_sram_index_constants
|
||||
{
|
||||
kRamSize16kIndex = 3,
|
||||
kRamSize24kIndex = 4,
|
||||
kRamSize32kIndex = 5,
|
||||
kRamSize48kIndex = 6,
|
||||
kRamSize64kIndex = 7,
|
||||
kRamSize96kIndex = 8,
|
||||
kRamSize128kIndex = 9,
|
||||
kRamSize256kIndex = 11
|
||||
};
|
||||
#endif
|
||||
|
||||
#if defined(__CORE_CM0PLUS_H_GENERIC)
|
||||
enum _k_serials_sram_index_constants
|
||||
{
|
||||
kRamSize0p5kIndex = 0,
|
||||
kRamSize1kIndex = 1,
|
||||
kRamSize2kIndex = 2,
|
||||
kRamSize4kIndex = 3,
|
||||
kRamSize8kIndex = 4,
|
||||
kRamSize16kIndex = 5,
|
||||
kRamSize32kIndex = 6,
|
||||
kRamSize64kIndex = 7
|
||||
};
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Prototypes
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
//! @brief Initialize sram interface.
|
||||
status_t sram_init(void);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// EOF
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
113
src/memory/src/sram_init_cm0plus.c
Normal file
113
src/memory/src/sram_init_cm0plus.c
Normal file
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 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.
|
||||
*/
|
||||
|
||||
#include "bootloader_common.h"
|
||||
#include "bootloader/bl_context.h"
|
||||
#include "memory/memory.h"
|
||||
#if !defined(BOOTLOADER_HOST)
|
||||
#include "fsl_device_registers.h"
|
||||
#endif // BOOTLOADER_HOST
|
||||
#include "utilities/fsl_assert.h"
|
||||
#include "sram_init.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Code
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//! @brief Initialize address ranges of SRAM for chips belongs to cm0plus family
|
||||
status_t sram_init(void)
|
||||
{
|
||||
#if defined(__CORE_CM0PLUS_H_GENERIC)
|
||||
|
||||
uint32_t ram_size = 0;
|
||||
|
||||
#if FSL_FEATURE_SIM_OPT_HAS_RAMSIZE
|
||||
uint32_t tmp = (SIM->SOPT1 & SIM_SOPT1_RAMSIZE_MASK) >> SIM_SOPT1_RAMSIZE_SHIFT;
|
||||
switch (tmp)
|
||||
{
|
||||
case 1:
|
||||
ram_size = 8 * 1024;
|
||||
break;
|
||||
case 3:
|
||||
ram_size = 16 * 1024;
|
||||
break;
|
||||
case 4:
|
||||
ram_size = 24 * 1024;
|
||||
break;
|
||||
case 5:
|
||||
ram_size = 32 * 1024;
|
||||
break;
|
||||
case 6:
|
||||
ram_size = 48 * 1024;
|
||||
break;
|
||||
case 7:
|
||||
ram_size = 64 * 1024;
|
||||
break;
|
||||
case 8:
|
||||
ram_size = 96 * 1024;
|
||||
break;
|
||||
case 9:
|
||||
ram_size = 128 * 1024;
|
||||
break;
|
||||
case 11:
|
||||
ram_size = 256 * 1024;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#else
|
||||
uint32_t tmp = (SIM->SDID & SIM_SDID_SRAMSIZE_MASK) >> SIM_SDID_SRAMSIZE_SHIFT;
|
||||
|
||||
if (tmp <= kMaxRamIndex)
|
||||
{
|
||||
ram_size = kMinKlRamSize << tmp;
|
||||
}
|
||||
#endif
|
||||
|
||||
assert(ram_size > 0);
|
||||
|
||||
if (ram_size > 0)
|
||||
{
|
||||
// Update address range of SRAM
|
||||
memory_map_entry_t *map = (memory_map_entry_t *)&g_bootloaderContext.memoryMap[kIndexSRAM];
|
||||
tmp = ram_size / (kSram_LowerPart + kSram_UpperPart);
|
||||
map->startAddress = kSRAMSeparatrix - tmp * kSram_LowerPart; // start of SRAM
|
||||
map->endAddress = kSRAMSeparatrix + tmp * kSram_UpperPart - 1; // end of SRAM
|
||||
}
|
||||
#else
|
||||
#error "This function only applies to cm0plus family"
|
||||
#endif // __CORE_CM0PLUS_H_GENERIC
|
||||
|
||||
return kStatus_Success;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// EOF
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
127
src/memory/src/sram_init_cm4.c
Normal file
127
src/memory/src/sram_init_cm4.c
Normal file
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 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.
|
||||
*/
|
||||
|
||||
#include "bootloader_common.h"
|
||||
#include "bootloader/bl_context.h"
|
||||
#include "memory/memory.h"
|
||||
#if !defined(BOOTLOADER_HOST)
|
||||
#include "fsl_device_registers.h"
|
||||
#endif // BOOTLOADER_HOST
|
||||
#include "sram_init.h"
|
||||
#include "utilities/fsl_assert.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Code
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//! @brief Determine if a number is power of 2.
|
||||
static inline bool is_power_of_2(uint32_t number)
|
||||
{
|
||||
return !(number && (number & (number - 1)));
|
||||
}
|
||||
|
||||
//! @brief Initialize address ranges of SRAM for chips belongs to cm4 family
|
||||
status_t sram_init(void)
|
||||
{
|
||||
#if defined(__CORE_CM4_H_GENERIC)
|
||||
|
||||
uint32_t ram_size = 0;
|
||||
uint32_t tmp;
|
||||
#if defined(FSL_FEATURE_SIM_OPT_HAS_RAMSIZE)
|
||||
tmp = (SIM->SOPT1 & SIM_SOPT1_RAMSIZE_MASK) >> SIM_SOPT1_RAMSIZE_SHIFT;
|
||||
#elif defined(FSL_FEATURE_SIM_SDID_HAS_SRAMSIZE)
|
||||
tmp = (SIM->SDID & SIM_SDID_RAMSIZE) >> SIM_SDID_RAMSIZE_SHIFT;
|
||||
#else
|
||||
#error "No valid RAMSIZE defined!"
|
||||
#endif
|
||||
switch (tmp)
|
||||
{
|
||||
case kRamSize16kIndex:
|
||||
ram_size = 16 * 1024UL;
|
||||
break;
|
||||
case kRamSize24kIndex:
|
||||
ram_size = 24 * 1024UL;
|
||||
break;
|
||||
case kRamSize32kIndex:
|
||||
ram_size = 32 * 1024UL;
|
||||
break;
|
||||
case kRamSize48kIndex:
|
||||
ram_size = 48 * 1024UL;
|
||||
break;
|
||||
case kRamSize64kIndex:
|
||||
ram_size = 64 * 1024UL;
|
||||
break;
|
||||
case kRamSize96kIndex:
|
||||
ram_size = 96 * 1024UL;
|
||||
break;
|
||||
case kRamSize128kIndex:
|
||||
ram_size = 128 * 1024UL;
|
||||
break;
|
||||
case kRamSize256kIndex:
|
||||
ram_size = 256 * 1024UL;
|
||||
break;
|
||||
default:
|
||||
ram_size = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
assert(ram_size > 0);
|
||||
|
||||
uint32_t sram_lower_part = kSram_LowerPart;
|
||||
uint32_t sram_upper_part = kSram_UpperPart;
|
||||
|
||||
if (ram_size)
|
||||
{
|
||||
// For target in which RAM size is not power of 2, for example, 24KB, 48KB, 96KB, 192KB, etc
|
||||
// SRAM_LOWER is 1 / 3 of Total SRAM.
|
||||
if (!is_power_of_2(ram_size))
|
||||
{
|
||||
sram_lower_part = 1;
|
||||
sram_upper_part = 2;
|
||||
}
|
||||
|
||||
// Update address range of SRAM
|
||||
memory_map_entry_t *map = (memory_map_entry_t *)&g_bootloaderContext.memoryMap[kIndexSRAM];
|
||||
|
||||
uint32_t tmp = ram_size / (sram_lower_part + sram_upper_part);
|
||||
|
||||
map->startAddress = kSRAMSeparatrix - tmp * sram_lower_part; // start of SRAM
|
||||
map->endAddress = kSRAMSeparatrix + tmp * sram_upper_part - 1; // end of SRAM
|
||||
}
|
||||
|
||||
#else
|
||||
#error "This function only applies to cm4 family"
|
||||
#endif // __CORE_CM4_H_GENERIC
|
||||
|
||||
return kStatus_Success;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// EOF
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
105
src/memory/src/sram_init_cm7.c
Normal file
105
src/memory/src/sram_init_cm7.c
Normal file
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 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.
|
||||
*/
|
||||
|
||||
#include "bootloader_common.h"
|
||||
#include "bootloader/bl_context.h"
|
||||
#include "memory/memory.h"
|
||||
#if !defined(BOOTLOADER_HOST)
|
||||
#include "fsl_device_registers.h"
|
||||
#endif // BOOTLOADER_HOST
|
||||
#include "sram_init.h"
|
||||
#include "utilities/fsl_assert.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Code
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/*
|
||||
//! @brief Determine if a number is power of 2.
|
||||
static inline bool is_power_of_2(uint32_t number)
|
||||
{
|
||||
return !(number && (number & (number -1)));
|
||||
}
|
||||
*/
|
||||
|
||||
//! @brief Initialize address ranges of SRAM for chips belongs to cm4 family
|
||||
status_t sram_init(void)
|
||||
{
|
||||
memory_map_entry_t *map = NULL;
|
||||
#if defined(__CORE_CM7_H_GENERIC)
|
||||
|
||||
// uint32_t ram_size = 0;
|
||||
uint32_t tmp;
|
||||
#if defined(FSL_FEATURE_SIM_OPT_HAS_RAMSIZE)
|
||||
tmp = (SIM->SOPT1 & SIM_SOPT1_RAMSIZE_MASK) >> SIM_SOPT1_RAMSIZE_SHIFT;
|
||||
#elif defined(FSL_FEATURE_SIM_SDID_HAS_SRAMSIZE)
|
||||
tmp = (SIM->SDID & SIM_SDID_RAMSIZE_MASK) >> SIM_SDID_RAMSIZE_SHIFT;
|
||||
#else
|
||||
#error "No valid RAMSIZE defined!"
|
||||
#endif
|
||||
switch (tmp)
|
||||
{
|
||||
case kRamSize16kIndex:
|
||||
break;
|
||||
case kRamSize24kIndex:
|
||||
break;
|
||||
case kRamSize32kIndex:
|
||||
break;
|
||||
case kRamSize48kIndex:
|
||||
break;
|
||||
case kRamSize64kIndex:
|
||||
break;
|
||||
case kRamSize96kIndex:
|
||||
break;
|
||||
case kRamSize128kIndex:
|
||||
// Update DTCM memory range - 64 KB
|
||||
map = (memory_map_entry_t *)&g_bootloaderContext.memoryMap[kIndexDTCM];
|
||||
map->endAddress = map->startAddress + 1024UL * 64;
|
||||
|
||||
// Update OCRAM memory range - 0 KB
|
||||
map = (memory_map_entry_t *)&g_bootloaderContext.memoryMap[kIndexOCRAM];
|
||||
map->endAddress = map->startAddress;
|
||||
break;
|
||||
case kRamSize256kIndex:
|
||||
// No need to update, defined by default.
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
#else
|
||||
#error "This function only applies to cm7 family"
|
||||
#endif // __CORE_CM7_H_GENERIC
|
||||
|
||||
return kStatus_Success;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// EOF
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Reference in New Issue
Block a user