Kinetis Bootloader  2.0.0
Common bootloader for Kinetis devices
memory.h
1 /*
2  * Copyright (c) 2013-2016, Freescale Semiconductor, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * o Redistributions of source code must retain the above copyright notice, this list
9  * of conditions and the following disclaimer.
10  *
11  * o Redistributions in binary form must reproduce the above copyright notice, this
12  * list of conditions and the following disclaimer in the documentation and/or
13  * other materials provided with the distribution.
14  *
15  * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16  * contributors may be used to endorse or promote products derived from this
17  * software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef _memory_h
32 #define _memory_h
33 
34 #include <stdint.h>
35 #include "bootloader_common.h"
36 
39 
41 // Declarations
43 
46 {
47  kStatusMemoryRangeInvalid = MAKE_STATUS(kStatusGroup_MemoryInterface, 0),
48  kStatusMemoryReadFailed = MAKE_STATUS(kStatusGroup_MemoryInterface, 1),
49  kStatusMemoryWriteFailed = MAKE_STATUS(kStatusGroup_MemoryInterface, 2),
50  kStatusMemoryCumulativeWrite = MAKE_STATUS(kStatusGroup_MemoryInterface, 3),
51  kStatusMemoryAppOverlapWithExecuteOnlyRegion = MAKE_STATUS(kStatusGroup_MemoryInterface, 4)
52 };
53 
54 // !@brief Executable enum codes
55 enum
56 {
59 };
60 
64 typedef struct _memory_interface
65 {
66  status_t (*init)(void);
67  status_t (*read)(uint32_t address, uint32_t length, uint8_t *buffer);
68  status_t (*write)(uint32_t address, uint32_t length, const uint8_t *buffer);
69  status_t (*fill)(uint32_t address, uint32_t length, uint32_t pattern);
70  status_t (*flush)(void);
71  status_t (*erase)(uint32_t address, uint32_t length);
73 
75 typedef struct _memory_region_interface
76 {
77  status_t (*init)(void);
78  status_t (*read)(uint32_t address, uint32_t length, uint8_t *buffer);
79  status_t (*write)(uint32_t address, uint32_t length, const uint8_t *buffer);
80  status_t (*fill)(uint32_t address, uint32_t length, uint32_t pattern);
81  status_t (*flush)(void);
82  status_t (*erase)(uint32_t address, uint32_t length);
84 
86 typedef struct _memory_map_entry
87 {
88  uint32_t startAddress;
89  uint32_t endAddress;
90  bool isExecutable;
91  const memory_region_interface_t *memoryInterface;
93 
96 {
97  kIndexFlashArray = 0,
98  kIndexSRAM = 1,
99 #if CPU_IS_ARM_CORTEX_M7
100  kIndexDTCM = 2,
101  kIndexOCRAM = 3,
102 #endif // CPU_IS_ARM_CORTEX_M7
103 #if BL_FEATURE_QSPI_MODULE
104  kIndexQspiMemory = 2,
105  kIndexQspiAliasArea = 3,
106 #endif // BL_FEATURE_QSPI_MODULE
107  kSRAMSeparatrix = (uint32_t)0x20000000
108 };
109 
111 typedef enum _flash_erase_all_option
112 {
113  kFlashEraseAllOption_Blocks = 0,
114  kFlashEraseAllOption_ExecuteOnlySegments = 1
116 
118 // Externs
120 
123 
125 
126 
132 
135 
140 
141 #if CPU_IS_ARM_CORTEX_M7
146 
151 #endif
152 
157 
158 #if defined BL_FEATURE_QSPI_MODULE
160 #if BL_FEATURE_QSPI_ALIAS_AREA
162 #endif // BL_FEATURE_QSPI_ALIAS_AREA
163 #endif // BL_FEATURE_QSPI_MODULE
164 
166 
168 // Prototypes
170 
171 #if defined(__cplusplus)
172 extern "C" {
173 #endif // __cplusplus
174 
176 
177 
179 status_t mem_init(void);
180 
182 status_t mem_read(uint32_t address, uint32_t length, uint8_t *buffer);
183 
185 status_t mem_write(uint32_t address, uint32_t length, const uint8_t *buffer);
186 
188 status_t mem_fill(uint32_t address, uint32_t length, uint32_t pattern);
189 
191 status_t mem_erase(uint32_t address, uint32_t length);
192 
194 status_t mem_flush(void);
195 
197 status_t find_map_entry(uint32_t address, uint32_t length, const memory_map_entry_t **map);
198 
200 bool mem_is_erased(uint32_t address, uint32_t length);
201 
203 
205 
206 
208 bool mem_is_block_reserved(uint32_t address, uint32_t length);
209 
211 
213 
214 
216 status_t flash_mem_erase(uint32_t address, uint32_t length);
217 
218 #if BL_FEATURE_FAC_ERASE
223 #else
230 #endif
231 
234 
236 
238 
239 
243 
244 #if defined(__cplusplus)
245 }
246 #endif // __cplusplus
247 
248 #if defined(BOOTLOADER_HOST)
249 
251 // Simulator host prototypes
253 
254 #if __cplusplus
255 extern "C" {
256 #endif
257 
259 void host_flash_erase_all(void);
260 
263 
265 void host_flash_erase_region(uint32_t address, uint32_t count);
266 
267 #if __cplusplus
268 }
269 #endif
270 
271 #endif // BOOTLOADER_HOST
272 
274 
275 #endif // _memory_h
276 // EOF
Memory interface status group number (102).
Definition: bootloader_common.h:145
_memorymap_constants
Memory Map index constants.
Definition: memory.h:95
const memory_region_interface_t g_normalOCRAMInterface
Memory interface for memory with Normal type.
Definition: normal_memory.c:65
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
status_t mem_flush(void)
Flush meory:
Definition: memory.c:194
const memory_region_interface_t g_flashMemoryInterface
Flash memory interface.
Definition: flash_memory.c:84
status_t mem_erase(uint32_t address, uint32_t length)
Erase memory:
Definition: memory.c:121
The memory supports executing in place.
Definition: memory.h:58
Interface to memory operations for one region of memory.
Definition: memory.h:75
const memory_interface_t g_memoryInterface
Abstract memory interface.
Definition: memory.c:59
bool mem_is_erased(uint32_t address, uint32_t length)
Check is the specified memory region is erased.
Definition: memory.c:301
The memory doesn&#39;t support executing in place.
Definition: memory.h:57
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
status_t mem_init(void)
Initialize memory interface.
Definition: memory.c:278
Structure of a memory map entry.
Definition: memory.h:86
status_t mem_read(uint32_t address, uint32_t length, uint8_t *buffer)
Read memory.
Definition: memory.c:74
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
const memory_region_interface_t g_normalMemoryInterface
Memory interface for memory with Normal type.
Definition: normal_memory.c:44
const memory_region_interface_t g_normalDTCMInterface
Memory interface for memory with Normal type.
Definition: normal_memory.c:55
const memory_region_interface_t g_deviceMemoryInterface
Memory interface for memory with Device or Strongly-ordered type.
Definition: device_memory.c:46
void host_flash_erase_all_unsecure(void)
Erase all flash (unsecure).
status_t flash_mem_erase(uint32_t address, uint32_t length)
Erase Flash memory.
Definition: flash_memory.c:509
This value is the start address of SRAM_U.
Definition: memory.h:107
const memory_region_interface_t g_qspiMemoryInterface
Interface to qspi memory operations.
Definition: qspi_memory.c:124
void host_flash_erase_all(void)
Erase all flash.
memory_map_entry_t g_memoryMap[]
Memory map for the system.
status_t qspi_mem_erase_all(void)
Erase all QSPI memory.
Definition: qspi_memory.c:491
status_t mem_fill(uint32_t address, uint32_t length, uint32_t pattern)
Fill memory with a word pattern.
Definition: memory.c:155
status_t flash_mem_erase_all_unsecure(void)
Erase all Flash memory (unsecure).
Definition: flash_memory.c:664
void host_flash_erase_region(uint32_t address, uint32_t count)
Erase a region of flash.
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 memory erase all options.
Definition: memory.h:111
_memory_interface_status
Memory interface status codes.
Definition: memory.h:45
Interface to memory operations.
Definition: memory.h:64
int32_t status_t
Type used for all status and error return values.
Definition: fsl_common.h:121
const memory_region_interface_t g_qspiAliasAreaInterface
Interface to qspi alias area operations.
Definition: qspi_memory.c:137