Skip to content

Commit a70d30e

Browse files
K64F: Refactor linker script to support memory bank configuration
1 parent df28d42 commit a70d30e

File tree

3 files changed

+76
-66
lines changed

3 files changed

+76
-66
lines changed

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/device/TOOLCHAIN_GCC_ARM/MK64FN1M0xxx12.ld

Lines changed: 59 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,7 @@ ENTRY(Reset_Handler)
5353

5454
__ram_vector_table__ = 1;
5555

56-
#if !defined(MBED_APP_START)
57-
#define MBED_APP_START 0
58-
#elif MBED_APP_START > 0 && MBED_APP_START < 0x410
59-
#error MBED_APP_START too small and will overwrite interrupts and flash config
60-
#endif
6156

62-
#if !defined(MBED_APP_SIZE)
63-
#define MBED_APP_SIZE 0x100000
64-
#endif
6557

6658
#if !defined(MBED_CONF_TARGET_BOOT_STACK_SIZE)
6759
#define MBED_CONF_TARGET_BOOT_STACK_SIZE 0x400
@@ -72,19 +64,32 @@ __stack_size__ = MBED_CONF_TARGET_BOOT_STACK_SIZE;
7264
STACK_SIZE = DEFINED(__stack_size__) ? __stack_size__ : 0x0400;
7365
M_VECTOR_RAM_SIZE = DEFINED(__ram_vector_table__) ? 0x0400 : 0x0;
7466
M_CRASH_DATA_RAM_SIZE = 0x100;
67+
FLASH_VTOR_TABLE_SIZE = 0x400;
68+
FLASH_CONFIG_FIELD_SIZE = 0x10;
69+
70+
/* If we are not configured to execute out of the start of ROM, then a bootloader is
71+
* present. This tells us whether we need to add the Flash Configuration Field at the start of flash. */
72+
#if MBED_CONFIGURED_ROM_BANK_IROM1_START == 0
73+
#define IS_BOOTLOADER_PRESENT 0
74+
#else
75+
#define IS_BOOTLOADER_PRESENT 1
76+
#endif
77+
78+
#if IS_BOOTLOADER_PRESENT && MBED_CONFIGURED_ROM_BANK_IROM1_START < 0x410
79+
#error MBED_CONFIGURED_ROM_BANK_IROM1_START too small and will overwrite interrupts and flash config
80+
#endif
7581

7682
/* Specify the memory areas */
7783
MEMORY
7884
{
79-
#if MBED_APP_START == 0
80-
m_interrupts (RX) : ORIGIN = MBED_APP_START, LENGTH = 0x400
81-
m_flash_config (RX) : ORIGIN = MBED_APP_START + 0x400, LENGTH = 0x10
82-
m_text (RX) : ORIGIN = MBED_APP_START + 0x410, LENGTH = MBED_APP_SIZE - 0x410
83-
#else
84-
m_text (RX) : ORIGIN = MBED_APP_START, LENGTH = MBED_APP_SIZE
85-
#endif
86-
m_data (RW) : ORIGIN = 0x1FFF0000, LENGTH = 0x00010000
87-
m_data_2 (RW) : ORIGIN = 0x20000000, LENGTH = 0x00030000
85+
m_text (RX) : ORIGIN = MBED_CONFIGURED_ROM_BANK_IROM1_START, LENGTH = MBED_CONFIGURED_ROM_BANK_IROM1_SIZE
86+
87+
/*
88+
* Note: while these two SRAMs occupy a contiguous address space, we have to keep them as
89+
* separate memory banks because the MCU doesn't support accesses that bridge the two banks.
90+
*/
91+
m_sram_l (RW) : ORIGIN = MBED_RAM_BANK_SRAM_L_START, LENGTH = MBED_RAM_BANK_SRAM_L_SIZE
92+
m_sram_u (RW) : ORIGIN = MBED_RAM_BANK_SRAM_U_START, LENGTH = MBED_RAM_BANK_SRAM_U_SIZE
8893
}
8994

9095
/* Define output sections */
@@ -97,18 +102,20 @@ SECTIONS
97102
. = ALIGN(8);
98103
KEEP(*(.isr_vector)) /* Startup code */
99104
. = ALIGN(8);
100-
#if MBED_APP_START == 0
101-
} > m_interrupts
105+
} > m_text AT> m_text
102106

103-
.flash_config :
107+
/* FCF to absolute address of 0x400, but only if bootloader is not present. */
108+
#if !IS_BOOTLOADER_PRESENT
109+
.flash_config VTOR_TABLE_SIZE :
104110
{
105-
. = ALIGN(8);
106111
KEEP(*(.FlashConfig)) /* Flash Configuration Field (FCF) */
107-
. = ALIGN(8);
108-
} > m_flash_config
112+
} > m_text AT> m_text
109113
#else
110-
} > m_text
114+
/DISCARD/ : {
115+
*(.FlashConfig)
116+
}
111117
#endif
118+
112119
.text :
113120
{
114121

@@ -204,44 +211,45 @@ SECTIONS
204211
. += M_VECTOR_RAM_SIZE;
205212
. = ALIGN(8);
206213
__interrupts_ram_end__ = .; /* Define a global symbol at data end */
207-
} > m_data
214+
} > m_sram_u
208215

209-
.crash_data_ram :
216+
#if MBED_CONF_PLATFORM_CRASH_CAPTURE_ENABLED
217+
/* Stick the crash data ram at the start of sram_l */
218+
.crash_data_ram : ALIGN(8)
210219
{
211-
. = ALIGN(8);
212220
__CRASH_DATA_RAM__ = .;
213221
__CRASH_DATA_RAM_START__ = .; /* Create a global symbol at data start */
214222
KEEP(*(.keep.crash_data_ram))
215223
*(.m_crash_data_ram) /* This is a user defined section */
216224
. += M_CRASH_DATA_RAM_SIZE;
217225
. = ALIGN(8);
218226
__CRASH_DATA_RAM_END__ = .; /* Define a global symbol at data end */
219-
} > m_data
227+
} > m_sram_u
228+
#endif
220229

221-
.heap_0 :
230+
/* Fill the entire sram_l with the heap 0 section. */
231+
.heap_0 (NOLOAD): ALIGN(8)
222232
{
223-
. = ALIGN(8);
224233
__mbed_sbrk_start_0 = .;
225-
. += (ORIGIN(m_data) + LENGTH(m_data) - .);
234+
. += (ORIGIN(m_sram_l) + LENGTH(m_sram_l) - .);
226235
__mbed_krbs_start_0 = .;
227-
} > m_data
236+
} > m_sram_l
228237

229238
__VECTOR_RAM = DEFINED(__ram_vector_table__) ? __VECTOR_RAM__ : ORIGIN(m_interrupts);
230239
__RAM_VECTOR_TABLE_SIZE_BYTES = DEFINED(__ram_vector_table__) ? (__interrupts_ram_end__ - __interrupts_ram_start__) : 0x0;
231240

232-
.data :
241+
.data : ALIGN(8)
233242
{
234243
PROVIDE(__etext = LOADADDR(.data)); /* Define a global symbol at end of code, */
235244
PROVIDE(__DATA_ROM = LOADADDR(.data)); /* Symbol is used by startup for data initialization. */
236-
. = ALIGN(8);
237245
__DATA_RAM = .;
238246
__data_start__ = .; /* create a global symbol at data start */
239247
*(.data) /* .data sections */
240248
*(.data*) /* .data* sections */
241249
KEEP(*(.jcr*))
242250
. = ALIGN(8);
243251
__data_end__ = .; /* define a global symbol at data end */
244-
} > m_data_2 AT > m_text
252+
} > m_sram_u AT > m_text
245253

246254
__DATA_END = __DATA_ROM + (__data_end__ - __data_start__);
247255
text_end = ORIGIN(m_text) + LENGTH(m_text);
@@ -259,15 +267,14 @@ SECTIONS
259267
KEEP(*(.keep.uninitialized))
260268
. = ALIGN(32);
261269
__uninitialized_end = .;
262-
} > m_data_2
270+
} > m_sram_u
263271

264272
USB_RAM_GAP = DEFINED(__usb_ram_size__) ? __usb_ram_size__ : 0x800;
265273

266274
/* Uninitialized data section */
267-
.bss :
275+
.bss : ALIGN(8)
268276
{
269277
/* This is used by the startup in order to initialize the .bss section */
270-
. = ALIGN(8);
271278
__START_BSS = .;
272279
__bss_start__ = .;
273280
*(.bss)
@@ -279,39 +286,41 @@ SECTIONS
279286
. = ALIGN(8);
280287
__bss_end__ = .;
281288
__END_BSS = .;
282-
} > m_data_2
289+
} > m_sram_u
283290

284-
.heap :
291+
.heap : ALIGN(8)
285292
{
286-
. = ALIGN(8);
287293
__end__ = .;
288294
PROVIDE(end = .);
295+
296+
ASSERT((__end__ - ORIGIN(m_sram_u)) + STACK_SIZE <= LENGTH(m_sram_u), "SRAM_U is not large enough to contain globals and boot stack!");
297+
289298
__mbed_sbrk_start = .;
290299
__HeapBase = .;
291-
. = ORIGIN(m_data_2) + LENGTH(m_data_2) - STACK_SIZE;
300+
. = ORIGIN(m_sram_u) + LENGTH(m_sram_u) - STACK_SIZE;
292301
__mbed_krbs_start = .;
293302
__HeapLimit = .;
294303
__heap_limit = .; /* Add for _sbrk */
295-
} > m_data_2
304+
} > m_sram_u
296305

297-
m_usb_bdt USB_RAM_START (NOLOAD) :
306+
/* USB RAM sections. These live inside a "gap" created in .bss. */
307+
m_usb_bdt USB_RAM_START (OVERLAY) :
298308
{
299309
*(m_usb_bdt)
300310
USB_RAM_BDT_END = .;
301311
}
302312

303-
m_usb_global USB_RAM_BDT_END (NOLOAD) :
313+
m_usb_global USB_RAM_BDT_END (OVERLAY) :
304314
{
305315
*(m_usb_global)
306316
}
307317

308318
/* Initializes stack on the end of block */
309-
__StackTop = ORIGIN(m_data_2) + LENGTH(m_data_2);
319+
__StackTop = ORIGIN(m_sram_u) + LENGTH(m_sram_u);
310320
__StackLimit = __StackTop - STACK_SIZE;
311321
PROVIDE(__stack = __StackTop);
312322

313-
.ARM.attributes 0 : { *(.ARM.attributes) }
314-
315-
ASSERT(__StackLimit >= __HeapLimit, "Region m_data_2 overflowed with stack and heap")
316-
323+
/DISCARD/ : {
324+
*(.ARM.attributes)
325+
}
317326
}

targets/cmsis_mcu_descriptions.json5

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3088,7 +3088,7 @@
30883088
"version": "1.5.0"
30893089
},
30903090
"memories": {
3091-
"IRAM1": {
3091+
"SRAM_U": {
30923092
"access": {
30933093
"execute": false,
30943094
"non_secure": false,
@@ -3099,11 +3099,11 @@
30993099
"write": true
31003100
},
31013101
"default": true,
3102-
"size": 196608,
3103-
"start": 536870912,
3102+
"size": 0x30000,
3103+
"start": 0x20000000,
31043104
"startup": false
31053105
},
3106-
"IRAM2": {
3106+
"SRAM_L": {
31073107
"access": {
31083108
"execute": false,
31093109
"non_secure": false,
@@ -3114,8 +3114,8 @@
31143114
"write": true
31153115
},
31163116
"default": false,
3117-
"size": 65536,
3118-
"start": 536805376,
3117+
"size": 0x10000,
3118+
"start": 0x1FFF0000,
31193119
"startup": false
31203120
},
31213121
"IROM1": {

tools/cmake/mbed_target_functions.cmake

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,17 @@ function(mbed_set_post_build target)
157157
# diagnostic output file for some toolchains.
158158

159159
# copy mapfile .map to .map.old for ram/rom statistics diff in memap.py
160-
if(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${target}${CMAKE_EXECUTABLE_SUFFIX}.map)
161-
add_custom_command(
162-
TARGET
163-
${target}
164-
PRE_BUILD
165-
COMMAND
166-
${CMAKE_COMMAND} -E rename "${CMAKE_CURRENT_BINARY_DIR}/${target}${CMAKE_EXECUTABLE_SUFFIX}.map" "${CMAKE_CURRENT_BINARY_DIR}/${target}${CMAKE_EXECUTABLE_SUFFIX}.map.old"
167-
)
168-
endif()
169-
160+
add_custom_command(
161+
TARGET
162+
${target}
163+
PRE_BUILD
164+
# So that the rename command does not fail on the first build, touch the map file first to create it if it does not exist.
165+
COMMAND
166+
${CMAKE_COMMAND} -E touch "${CMAKE_CURRENT_BINARY_DIR}/${target}${CMAKE_EXECUTABLE_SUFFIX}.map"
167+
COMMAND
168+
${CMAKE_COMMAND} -E rename "${CMAKE_CURRENT_BINARY_DIR}/${target}${CMAKE_EXECUTABLE_SUFFIX}.map" "${CMAKE_CURRENT_BINARY_DIR}/${target}${CMAKE_EXECUTABLE_SUFFIX}.map.old"
169+
)
170+
170171
mbed_configure_memory_map(${target} "${CMAKE_CURRENT_BINARY_DIR}/${target}${CMAKE_EXECUTABLE_SUFFIX}.map")
171172
mbed_validate_application_profile(${target})
172173
mbed_generate_bin_hex(${target})

0 commit comments

Comments
 (0)