K64F linker script refactor, also fix some misc bugs (#402)

* K64F: Refactor linker script to support memory bank configuration

* Add PHDRS to fix warning

* Fix some bugs

* Fix comment

* Fix space
pull/15531/head
Jamie Smith 2024-12-11 12:18:18 -08:00 committed by GitHub
parent c3f9a8ac07
commit 156cd15c50
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 134 additions and 100 deletions

View File

@ -409,7 +409,7 @@ bool Kinetis_EMAC::link_out(emac_mem_buf_t *buf)
} }
/* Check if a descriptor is available for the transfer (wait 10ms before dropping the buffer) */ /* Check if a descriptor is available for the transfer (wait 10ms before dropping the buffer) */
if (!xTXDCountSem.try_acquire_for(10)) { if (!xTXDCountSem.try_acquire_for(10ms)) {
memory_manager->free(buf); memory_manager->free(buf);
return false; return false;
} }

View File

@ -278,7 +278,7 @@ const char *mbed_trace_exclude_filters_get(void);
* mbed_tracef(TRACE_ACTIVE_LEVEL_DEBUG, "mygr", "Hi There"); * mbed_tracef(TRACE_ACTIVE_LEVEL_DEBUG, "mygr", "Hi There");
* mbed_tracef(TRACE_ACTIVE_LEVEL_DEBUG, "grp2", "This is not printed"); * mbed_tracef(TRACE_ACTIVE_LEVEL_DEBUG, "grp2", "This is not printed");
*/ */
void mbed_trace_include_filters_set(char *filters); void mbed_trace_include_filters_set(char const *filters);
/** get trace include filters /** get trace include filters
*/ */
const char *mbed_trace_include_filters_get(void); const char *mbed_trace_include_filters_get(void);

View File

@ -282,7 +282,7 @@ const char *mbed_trace_include_filters_get(void)
{ {
return m_trace.filters_include; return m_trace.filters_include;
} }
void mbed_trace_include_filters_set(char *filters) void mbed_trace_include_filters_set(char const *filters)
{ {
if (filters) { if (filters) {
(void)strncpy(m_trace.filters_include, filters, m_trace.filters_length); (void)strncpy(m_trace.filters_include, filters, m_trace.filters_length);

View File

@ -26,8 +26,15 @@ namespace mbed {
/** \addtogroup storage-blockdevice */ /** \addtogroup storage-blockdevice */
/** @{*/ /** @{*/
/** Block device for allowing minimal read and program sizes (of 1) for the underlying BD, /**
* using a buffer on the heap. * Block device which allows minimal read and program sizes (of 1) for the underlying BD
* using a buffer on the heap. This essentially "simulates" a byte-programmable device
* like a NOR flash or an EEPROM, using a non-byte-programmable device like an SD card or
* NAND flash.
*
* @note While the read and write size of the buffered block device will always be 1,
* the erase size is the same as the underlying block device. In other words, you
* still must erase in the hardware erase sector size.
*/ */
class BufferedBlockDevice : public BlockDevice { class BufferedBlockDevice : public BlockDevice {
public: public:

View File

@ -53,15 +53,7 @@ ENTRY(Reset_Handler)
__ram_vector_table__ = 1; __ram_vector_table__ = 1;
#if !defined(MBED_APP_START)
#define MBED_APP_START 0
#elif MBED_APP_START > 0 && MBED_APP_START < 0x410
#error MBED_APP_START too small and will overwrite interrupts and flash config
#endif
#if !defined(MBED_APP_SIZE)
#define MBED_APP_SIZE 0x100000
#endif
#if !defined(MBED_CONF_TARGET_BOOT_STACK_SIZE) #if !defined(MBED_CONF_TARGET_BOOT_STACK_SIZE)
#define MBED_CONF_TARGET_BOOT_STACK_SIZE 0x400 #define MBED_CONF_TARGET_BOOT_STACK_SIZE 0x400
@ -72,19 +64,42 @@ __stack_size__ = MBED_CONF_TARGET_BOOT_STACK_SIZE;
STACK_SIZE = DEFINED(__stack_size__) ? __stack_size__ : 0x0400; STACK_SIZE = DEFINED(__stack_size__) ? __stack_size__ : 0x0400;
M_VECTOR_RAM_SIZE = DEFINED(__ram_vector_table__) ? 0x0400 : 0x0; M_VECTOR_RAM_SIZE = DEFINED(__ram_vector_table__) ? 0x0400 : 0x0;
M_CRASH_DATA_RAM_SIZE = 0x100; M_CRASH_DATA_RAM_SIZE = 0x100;
FLASH_VTOR_TABLE_SIZE = 0x400;
FLASH_CONFIG_FIELD_SIZE = 0x10;
/* If we are not configured to execute out of the start of ROM, then a bootloader is
* present. This tells us whether we need to add the Flash Configuration Field at the start of flash. */
#if MBED_CONFIGURED_ROM_BANK_IROM1_START == 0
#define IS_BOOTLOADER_PRESENT 0
#else
#define IS_BOOTLOADER_PRESENT 1
#endif
#if IS_BOOTLOADER_PRESENT && MBED_CONFIGURED_ROM_BANK_IROM1_START < 0x410
#error MBED_CONFIGURED_ROM_BANK_IROM1_START too small and will overwrite interrupts and flash config
#endif
/* Specify the ELF segments (program headers) */
PHDRS
{
text PT_LOAD FLAGS(5); /* read + execute */
ram_vector_table PT_LOAD FLAGS(6); /* read + write */
ram_noinit PT_LOAD FLAGS(6); /* read + write */
ram_init PT_LOAD FLAGS(6); /* read + write */
sram_l PT_LOAD FLAGS(6); /* read + write */
}
/* Specify the memory areas */ /* Specify the memory areas */
MEMORY MEMORY
{ {
#if MBED_APP_START == 0 m_text (RX) : ORIGIN = MBED_CONFIGURED_ROM_BANK_IROM1_START, LENGTH = MBED_CONFIGURED_ROM_BANK_IROM1_SIZE
m_interrupts (RX) : ORIGIN = MBED_APP_START, LENGTH = 0x400
m_flash_config (RX) : ORIGIN = MBED_APP_START + 0x400, LENGTH = 0x10 /*
m_text (RX) : ORIGIN = MBED_APP_START + 0x410, LENGTH = MBED_APP_SIZE - 0x410 * Note: while these two SRAMs occupy a contiguous address space, we have to keep them as
#else * separate memory banks because the MCU doesn't support accesses that bridge the two banks.
m_text (RX) : ORIGIN = MBED_APP_START, LENGTH = MBED_APP_SIZE */
#endif m_sram_l (RW) : ORIGIN = MBED_RAM_BANK_SRAM_L_START, LENGTH = MBED_RAM_BANK_SRAM_L_SIZE
m_data (RW) : ORIGIN = 0x1FFF0000, LENGTH = 0x00010000 m_sram_u (RW) : ORIGIN = MBED_RAM_BANK_SRAM_U_START, LENGTH = MBED_RAM_BANK_SRAM_U_SIZE
m_data_2 (RW) : ORIGIN = 0x20000000, LENGTH = 0x00030000
} }
/* Define output sections */ /* Define output sections */
@ -97,18 +112,20 @@ SECTIONS
. = ALIGN(8); . = ALIGN(8);
KEEP(*(.isr_vector)) /* Startup code */ KEEP(*(.isr_vector)) /* Startup code */
. = ALIGN(8); . = ALIGN(8);
#if MBED_APP_START == 0 } > m_text AT> m_text :text
} > m_interrupts
.flash_config : /* FCF to absolute address of 0x400, but only if bootloader is not present. */
#if !IS_BOOTLOADER_PRESENT
.flash_config FLASH_VTOR_TABLE_SIZE :
{ {
. = ALIGN(8);
KEEP(*(.FlashConfig)) /* Flash Configuration Field (FCF) */ KEEP(*(.FlashConfig)) /* Flash Configuration Field (FCF) */
. = ALIGN(8); } > m_text AT> m_text :text
} > m_flash_config
#else #else
} > m_text /DISCARD/ : {
*(.FlashConfig)
}
#endif #endif
.text : .text :
{ {
@ -123,19 +140,19 @@ SECTIONS
KEEP (*(.init)) KEEP (*(.init))
KEEP (*(.fini)) KEEP (*(.fini))
. = ALIGN(8); . = ALIGN(8);
} > m_text } > m_text AT> m_text :text
.ARM.extab : .ARM.extab :
{ {
*(.ARM.extab* .gnu.linkonce.armextab.*) *(.ARM.extab* .gnu.linkonce.armextab.*)
} > m_text } > m_text AT> m_text :text
.ARM : .ARM :
{ {
__exidx_start = .; __exidx_start = .;
*(.ARM.exidx*) *(.ARM.exidx*)
__exidx_end = .; __exidx_end = .;
} > m_text } > m_text AT> m_text :text
.ctors : .ctors :
{ {
@ -159,7 +176,7 @@ SECTIONS
KEEP (*(SORT(.ctors.*))) KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors)) KEEP (*(.ctors))
__CTOR_END__ = .; __CTOR_END__ = .;
} > m_text } > m_text AT> m_text :text
.dtors : .dtors :
{ {
@ -170,14 +187,14 @@ SECTIONS
KEEP (*(SORT(.dtors.*))) KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors)) KEEP (*(.dtors))
__DTOR_END__ = .; __DTOR_END__ = .;
} > m_text } > m_text AT> m_text :text
.preinit_array : .preinit_array :
{ {
PROVIDE_HIDDEN (__preinit_array_start = .); PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array*)) KEEP (*(.preinit_array*))
PROVIDE_HIDDEN (__preinit_array_end = .); PROVIDE_HIDDEN (__preinit_array_end = .);
} > m_text } > m_text AT> m_text :text
.init_array : .init_array :
{ {
@ -185,7 +202,7 @@ SECTIONS
KEEP (*(SORT(.init_array.*))) KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array*)) KEEP (*(.init_array*))
PROVIDE_HIDDEN (__init_array_end = .); PROVIDE_HIDDEN (__init_array_end = .);
} > m_text } > m_text AT> m_text :text
.fini_array : .fini_array :
{ {
@ -193,7 +210,32 @@ SECTIONS
KEEP (*(SORT(.fini_array.*))) KEEP (*(SORT(.fini_array.*)))
KEEP (*(.fini_array*)) KEEP (*(.fini_array*))
PROVIDE_HIDDEN (__fini_array_end = .); PROVIDE_HIDDEN (__fini_array_end = .);
} > m_text } > m_text AT> m_text :text
#if MBED_CONF_PLATFORM_CRASH_CAPTURE_ENABLED
/* Stick the crash data ram at the start of sram_l */
.crash_data_ram : ALIGN(8)
{
__CRASH_DATA_RAM__ = .;
__CRASH_DATA_RAM_START__ = .; /* Create a global symbol at data start */
KEEP(*(.keep.crash_data_ram))
*(.m_crash_data_ram) /* This is a user defined section */
. += M_CRASH_DATA_RAM_SIZE;
. = ALIGN(8);
__CRASH_DATA_RAM_END__ = .; /* Define a global symbol at data end */
} > m_sram_l :sram_l
#endif
/* Fill the entire sram_l with the heap 0 section. */
.heap_0 (NOLOAD): ALIGN(8)
{
__mbed_sbrk_start_0 = .;
. += (ORIGIN(m_sram_l) + LENGTH(m_sram_l) - .);
__mbed_krbs_start_0 = .;
} > m_sram_l :sram_l
__VECTOR_RAM = DEFINED(__ram_vector_table__) ? __VECTOR_RAM__ : ORIGIN(m_interrupts);
__RAM_VECTOR_TABLE_SIZE_BYTES = DEFINED(__ram_vector_table__) ? (__interrupts_ram_end__ - __interrupts_ram_start__) : 0x0;
.interrupts_ram : .interrupts_ram :
{ {
@ -204,36 +246,12 @@ SECTIONS
. += M_VECTOR_RAM_SIZE; . += M_VECTOR_RAM_SIZE;
. = ALIGN(8); . = ALIGN(8);
__interrupts_ram_end__ = .; /* Define a global symbol at data end */ __interrupts_ram_end__ = .; /* Define a global symbol at data end */
} > m_data } > m_sram_u :ram_vector_table
.crash_data_ram : .data : ALIGN(8)
{
. = ALIGN(8);
__CRASH_DATA_RAM__ = .;
__CRASH_DATA_RAM_START__ = .; /* Create a global symbol at data start */
KEEP(*(.keep.crash_data_ram))
*(.m_crash_data_ram) /* This is a user defined section */
. += M_CRASH_DATA_RAM_SIZE;
. = ALIGN(8);
__CRASH_DATA_RAM_END__ = .; /* Define a global symbol at data end */
} > m_data
.heap_0 :
{
. = ALIGN(8);
__mbed_sbrk_start_0 = .;
. += (ORIGIN(m_data) + LENGTH(m_data) - .);
__mbed_krbs_start_0 = .;
} > m_data
__VECTOR_RAM = DEFINED(__ram_vector_table__) ? __VECTOR_RAM__ : ORIGIN(m_interrupts);
__RAM_VECTOR_TABLE_SIZE_BYTES = DEFINED(__ram_vector_table__) ? (__interrupts_ram_end__ - __interrupts_ram_start__) : 0x0;
.data :
{ {
PROVIDE(__etext = LOADADDR(.data)); /* Define a global symbol at end of code, */ PROVIDE(__etext = LOADADDR(.data)); /* Define a global symbol at end of code, */
PROVIDE(__DATA_ROM = LOADADDR(.data)); /* Symbol is used by startup for data initialization. */ PROVIDE(__DATA_ROM = LOADADDR(.data)); /* Symbol is used by startup for data initialization. */
. = ALIGN(8);
__DATA_RAM = .; __DATA_RAM = .;
__data_start__ = .; /* create a global symbol at data start */ __data_start__ = .; /* create a global symbol at data start */
*(.data) /* .data sections */ *(.data) /* .data sections */
@ -241,7 +259,7 @@ SECTIONS
KEEP(*(.jcr*)) KEEP(*(.jcr*))
. = ALIGN(8); . = ALIGN(8);
__data_end__ = .; /* define a global symbol at data end */ __data_end__ = .; /* define a global symbol at data end */
} > m_data_2 AT > m_text } > m_sram_u AT > m_text :ram_init
__DATA_END = __DATA_ROM + (__data_end__ - __data_start__); __DATA_END = __DATA_ROM + (__data_end__ - __data_start__);
text_end = ORIGIN(m_text) + LENGTH(m_text); text_end = ORIGIN(m_text) + LENGTH(m_text);
@ -259,15 +277,14 @@ SECTIONS
KEEP(*(.keep.uninitialized)) KEEP(*(.keep.uninitialized))
. = ALIGN(32); . = ALIGN(32);
__uninitialized_end = .; __uninitialized_end = .;
} > m_data_2 } > m_sram_u AT> m_sram_u :ram_noinit
USB_RAM_GAP = DEFINED(__usb_ram_size__) ? __usb_ram_size__ : 0x800; USB_RAM_GAP = DEFINED(__usb_ram_size__) ? __usb_ram_size__ : 0x800;
/* Uninitialized data section */ /* Uninitialized data section */
.bss : .bss : ALIGN(8)
{ {
/* This is used by the startup in order to initialize the .bss section */ /* This is used by the startup in order to initialize the .bss section */
. = ALIGN(8);
__START_BSS = .; __START_BSS = .;
__bss_start__ = .; __bss_start__ = .;
*(.bss) *(.bss)
@ -279,39 +296,41 @@ SECTIONS
. = ALIGN(8); . = ALIGN(8);
__bss_end__ = .; __bss_end__ = .;
__END_BSS = .; __END_BSS = .;
} > m_data_2 } > m_sram_u AT> m_sram_u :ram_noinit
.heap : .heap : ALIGN(8)
{ {
. = ALIGN(8);
__end__ = .; __end__ = .;
PROVIDE(end = .); PROVIDE(end = .);
ASSERT((__end__ - ORIGIN(m_sram_u)) + STACK_SIZE <= LENGTH(m_sram_u), "SRAM_U is not large enough to contain globals and boot stack!");
__mbed_sbrk_start = .; __mbed_sbrk_start = .;
__HeapBase = .; __HeapBase = .;
. = ORIGIN(m_data_2) + LENGTH(m_data_2) - STACK_SIZE; . = ORIGIN(m_sram_u) + LENGTH(m_sram_u) - STACK_SIZE;
__mbed_krbs_start = .; __mbed_krbs_start = .;
__HeapLimit = .; __HeapLimit = .;
__heap_limit = .; /* Add for _sbrk */ __heap_limit = .; /* Add for _sbrk */
} > m_data_2 } > m_sram_u AT> m_sram_u :ram_noinit
m_usb_bdt USB_RAM_START (NOLOAD) : /* USB RAM sections. These live inside a "gap" created in .bss. */
m_usb_bdt USB_RAM_START (OVERLAY) :
{ {
*(m_usb_bdt) *(m_usb_bdt)
USB_RAM_BDT_END = .; USB_RAM_BDT_END = .;
} } :ram_noinit
m_usb_global USB_RAM_BDT_END (NOLOAD) : m_usb_global USB_RAM_BDT_END (OVERLAY) :
{ {
*(m_usb_global) *(m_usb_global)
} } :ram_noinit
/* Initializes stack on the end of block */ /* Initializes stack on the end of block */
__StackTop = ORIGIN(m_data_2) + LENGTH(m_data_2); __StackTop = ORIGIN(m_sram_u) + LENGTH(m_sram_u);
__StackLimit = __StackTop - STACK_SIZE; __StackLimit = __StackTop - STACK_SIZE;
PROVIDE(__stack = __StackTop); PROVIDE(__stack = __StackTop);
.ARM.attributes 0 : { *(.ARM.attributes) } /DISCARD/ : {
*(.ARM.attributes)
ASSERT(__StackLimit >= __HeapLimit, "Region m_data_2 overflowed with stack and heap") }
} }

View File

@ -16,6 +16,13 @@ macro(mbed_post_build_nuvoton_tfm_sign_image
function(mbed_post_build_function target) function(mbed_post_build_function target)
find_package(Python3) find_package(Python3)
if("${MBED_OUTPUT_EXT}" STREQUAL "")
# If both bin and hex are being generated, just pick one.
set(EXT hex)
else()
set(EXT ${MBED_OUTPUT_EXT})
endif()
# NOTE: Macro arguments are not variables and cannot pass to if(<condition>). # NOTE: Macro arguments are not variables and cannot pass to if(<condition>).
set(signing_key_1_ ${signing_key_1}) set(signing_key_1_ ${signing_key_1})
if(signing_key_1_) if(signing_key_1_)
@ -30,7 +37,7 @@ macro(mbed_post_build_nuvoton_tfm_sign_image
--tfm-import-path ${tfm_import_path} --tfm-import-path ${tfm_import_path}
--signing_key ${signing_key} --signing_key ${signing_key}
--signing_key_1 ${signing_key_1} --signing_key_1 ${signing_key_1}
--non-secure-binhex $<TARGET_FILE_DIR:${target}>/$<TARGET_FILE_BASE_NAME:${target}>.${MBED_OUTPUT_EXT} --non-secure-binhex $<TARGET_FILE_DIR:${target}>/$<TARGET_FILE_BASE_NAME:${target}>.${EXT}
) )
else() else()
add_custom_command( add_custom_command(
@ -43,7 +50,7 @@ macro(mbed_post_build_nuvoton_tfm_sign_image
tfm_sign_image tfm_sign_image
--tfm-import-path ${tfm_import_path} --tfm-import-path ${tfm_import_path}
--signing_key ${signing_key} --signing_key ${signing_key}
--non-secure-binhex $<TARGET_FILE_DIR:${target}>/$<TARGET_FILE_BASE_NAME:${target}>.${MBED_OUTPUT_EXT} --non-secure-binhex $<TARGET_FILE_DIR:${target}>/$<TARGET_FILE_BASE_NAME:${target}>.${EXT}
) )
endif() endif()
endfunction() endfunction()

View File

@ -3088,7 +3088,7 @@
"version": "1.5.0" "version": "1.5.0"
}, },
"memories": { "memories": {
"IRAM1": { "SRAM_U": {
"access": { "access": {
"execute": false, "execute": false,
"non_secure": false, "non_secure": false,
@ -3099,11 +3099,11 @@
"write": true "write": true
}, },
"default": true, "default": true,
"size": 196608, "size": 0x30000,
"start": 536870912, "start": 0x20000000,
"startup": false "startup": false
}, },
"IRAM2": { "SRAM_L": {
"access": { "access": {
"execute": false, "execute": false,
"non_secure": false, "non_secure": false,
@ -3114,8 +3114,8 @@
"write": true "write": true
}, },
"default": false, "default": false,
"size": 65536, "size": 0x10000,
"start": 536805376, "start": 0x1FFF0000,
"startup": false "startup": false
}, },
"IROM1": { "IROM1": {

View File

@ -77,7 +77,7 @@ foreach(LEGACY_VAR_NAME JLINK_USB_SERIAL_NUMBER LINKSERVER_PROBE_SN MBED_TARGET_
if(NOT "${${LEGACY_VAR_NAME}}" STREQUAL "") if(NOT "${${LEGACY_VAR_NAME}}" STREQUAL "")
message(WARNING "${LEGACY_VAR_NAME} is deprecated, set the MBED_UPLOAD_SERIAL_NUMBER variable instead. MBED_UPLOAD_SERIAL_NUMBER will be set to the value of ${LEGACY_VAR_NAME}.") message(WARNING "${LEGACY_VAR_NAME} is deprecated, set the MBED_UPLOAD_SERIAL_NUMBER variable instead. MBED_UPLOAD_SERIAL_NUMBER will be set to the value of ${LEGACY_VAR_NAME}.")
set(MBED_UPLOAD_SERIAL_NUMBER ${${LEGACY_VAR_NAME}} CACHE STRING "" FORCE) set(MBED_UPLOAD_SERIAL_NUMBER ${${LEGACY_VAR_NAME}} CACHE STRING "" FORCE)
unset(STLINK_PROBE_SN CACHE) unset(${LEGACY_VAR_NAME} CACHE)
endif() endif()
endif() endif()
endforeach() endforeach()

View File

@ -157,16 +157,17 @@ function(mbed_set_post_build target)
# diagnostic output file for some toolchains. # diagnostic output file for some toolchains.
# copy mapfile .map to .map.old for ram/rom statistics diff in memap.py # copy mapfile .map to .map.old for ram/rom statistics diff in memap.py
if(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${target}${CMAKE_EXECUTABLE_SUFFIX}.map) add_custom_command(
add_custom_command( TARGET
TARGET ${target}
${target} PRE_BUILD
PRE_BUILD # 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.
COMMAND COMMAND
${CMAKE_COMMAND} -E rename "${CMAKE_CURRENT_BINARY_DIR}/${target}${CMAKE_EXECUTABLE_SUFFIX}.map" "${CMAKE_CURRENT_BINARY_DIR}/${target}${CMAKE_EXECUTABLE_SUFFIX}.map.old" ${CMAKE_COMMAND} -E touch "${CMAKE_CURRENT_BINARY_DIR}/${target}${CMAKE_EXECUTABLE_SUFFIX}.map"
) COMMAND
endif() ${CMAKE_COMMAND} -E rename "${CMAKE_CURRENT_BINARY_DIR}/${target}${CMAKE_EXECUTABLE_SUFFIX}.map" "${CMAKE_CURRENT_BINARY_DIR}/${target}${CMAKE_EXECUTABLE_SUFFIX}.map.old"
)
mbed_configure_memory_map(${target} "${CMAKE_CURRENT_BINARY_DIR}/${target}${CMAKE_EXECUTABLE_SUFFIX}.map") mbed_configure_memory_map(${target} "${CMAKE_CURRENT_BINARY_DIR}/${target}${CMAKE_EXECUTABLE_SUFFIX}.map")
mbed_validate_application_profile(${target}) mbed_validate_application_profile(${target})
mbed_generate_bin_hex(${target}) mbed_generate_bin_hex(${target})