From cec7c838233d9da81ecec3c7c441c1198a013b2b Mon Sep 17 00:00:00 2001 From: Lin Gao Date: Tue, 18 Jun 2019 17:21:52 -0500 Subject: [PATCH] fix IAR linker script to conditionally include signature --- .../device/TOOLCHAIN_ARM_STD/CC3220SF.sct | 2 +- .../device/TOOLCHAIN_GCC_ARM/gcc_arm.ld | 2 +- .../device/TOOLCHAIN_IAR/CC3220SF.icf | 93 ++++++++++++++----- ...{startup_CC3220SF.s => startup_CC3220SF.S} | 0 4 files changed, 74 insertions(+), 23 deletions(-) rename targets/TARGET_TI/TARGET_CC32XX/TARGET_CC3220SF/device/TOOLCHAIN_IAR/{startup_CC3220SF.s => startup_CC3220SF.S} (100%) diff --git a/targets/TARGET_TI/TARGET_CC32XX/TARGET_CC3220SF/device/TOOLCHAIN_ARM_STD/CC3220SF.sct b/targets/TARGET_TI/TARGET_CC32XX/TARGET_CC3220SF/device/TOOLCHAIN_ARM_STD/CC3220SF.sct index 9cd7136927b3..f015722ed098 100644 --- a/targets/TARGET_TI/TARGET_CC32XX/TARGET_CC3220SF/device/TOOLCHAIN_ARM_STD/CC3220SF.sct +++ b/targets/TARGET_TI/TARGET_CC32XX/TARGET_CC3220SF/device/TOOLCHAIN_ARM_STD/CC3220SF.sct @@ -42,7 +42,7 @@ #if defined(MBED_APP_SIZE) #define ROM_EXEC_SIZE MBED_APP_SIZE #else - #define ROM_EXEC_SIZE (ROM_SIZE- (MBED_APP_START - ROM_START) + #define ROM_EXEC_SIZE (ROM_SIZE- (MBED_APP_START - ROM_START)) #endif #endif #else diff --git a/targets/TARGET_TI/TARGET_CC32XX/TARGET_CC3220SF/device/TOOLCHAIN_GCC_ARM/gcc_arm.ld b/targets/TARGET_TI/TARGET_CC32XX/TARGET_CC3220SF/device/TOOLCHAIN_GCC_ARM/gcc_arm.ld index 39708c391ecc..25fa6835c358 100644 --- a/targets/TARGET_TI/TARGET_CC32XX/TARGET_CC3220SF/device/TOOLCHAIN_GCC_ARM/gcc_arm.ld +++ b/targets/TARGET_TI/TARGET_CC32XX/TARGET_CC3220SF/device/TOOLCHAIN_GCC_ARM/gcc_arm.ld @@ -35,7 +35,7 @@ #if defined(MBED_APP_SIZE) #define ROM_EXEC_SIZE MBED_APP_SIZE #else - #define ROM_EXEC_SIZE (ROM_SIZE- (MBED_APP_START - ROM_START) + #define ROM_EXEC_SIZE (ROM_SIZE- (MBED_APP_START - ROM_START)) #endif #endif #else diff --git a/targets/TARGET_TI/TARGET_CC32XX/TARGET_CC3220SF/device/TOOLCHAIN_IAR/CC3220SF.icf b/targets/TARGET_TI/TARGET_CC32XX/TARGET_CC3220SF/device/TOOLCHAIN_IAR/CC3220SF.icf index eb8f70518062..24760ca2876b 100644 --- a/targets/TARGET_TI/TARGET_CC32XX/TARGET_CC3220SF/device/TOOLCHAIN_IAR/CC3220SF.icf +++ b/targets/TARGET_TI/TARGET_CC32XX/TARGET_CC3220SF/device/TOOLCHAIN_IAR/CC3220SF.icf @@ -7,43 +7,94 @@ define symbol FLASH_HDR_SIZE = 0x800; define symbol RAM_START = 0x20000000; define symbol RAM_SIZE = 0x40000; define symbol VECTORS = 195; /* This value must match NVIC_NUM_VECTORS */ -define symbol HEAP_SIZE = 0xA000; /* Common - Do not change */ -if (!isdefinedsymbol(MBED_APP_START)) { - define symbol MBED_APP_START = (ROM_START + FLASH_HDR_SIZE); +if (isdefinedsymbol(MBED_APP_START)) { + /* + * There're two cases if MBED_APP_START is defined. + * Case 1: MBED_APP_START is defined as ROM_START, this happens when restrict_size is turned on, most likely for bootloader build. + * In this build, include FLASH_HDR region. + */ + if (MBED_APP_START == ROM_START) { + define symbol FLASH_HDR_INCLUDED = 1; + if (isdefinedsymbol(MBED_APP_SIZE)) { + define symbol ROM_EXEC_START = (ROM_START + FLASH_HDR_SIZE); + define symbol ROM_EXEC_SIZE = (MBED_APP_SIZE - FLASH_HDR_SIZE); + } + } + else { + /* + * Case 2: MBED_APP_START is defined as a value greater than ROM_START, this is most likely a build other than the bootloader. E.g., the MCC build. + * In this build, exclude FLASH_HDR region. This workarounds an issue in managed boodloader MCC build where the jump address and stack pointer point to the cookie area + */ + define symbol FLASH_HDR_INCLUDED = 0; + define symbol ROM_EXEC_START = MBED_APP_START; + if (isdefinedsymbol(MBED_APP_SIZE)) { + define symbol ROM_EXEC_SIZE= MBED_APP_SIZE; + } + else { + define symbol ROM_EXEC_SIZE = (ROM_SIZE- (MBED_APP_START - ROM_START)); + } + } } - -if (!isdefinedsymbol(MBED_APP_SIZE)) { - define symbol MBED_APP_SIZE = (ROM_SIZE - FLASH_HDR_SIZE); +else { + /* + * MBED_APP_START is not defined. This is most likely a bootloader build, or other apps that do not require boodloader. + * In this build, include FLASH_HDR region + */ + define symbol FLASH_HDR_INCLUDED = 1; + define symbol ROM_EXEC_START = (ROM_START + FLASH_HDR_SIZE); + if (isdefinedsymbol (MBED_APP_SIZE)) { + define symbol ROM_EXEC_SIZE = (MBED_APP_SIZE - FLASH_HDR_SIZE); + } + else { + define symbol ROM_EXEC_SIZE = (ROM_SIZE - FLASH_HDR_SIZE); + } } + /* Round up VECTORS_SIZE to 8 bytes */ define symbol VECTORS_SIZE = ((VECTORS * 4) + 7) & ~7; -define symbol RAM_REGION_START = RAM_START + VECTORS_SIZE; -define symbol RAM_REGION_SIZE = RAM_SIZE - VECTORS_SIZE; -define symbol ISR_STACK_SIZE = 0x400; + +/* boot stack size*/ +if (!isdefinedsymbol(MBED_BOOT_STACK_SIZE)) { + define symbol MBED_BOOT_STACK_SIZE = 0x400; +} +/* Place the boot stack at the top of the RAM */ +define symbol CSTACK_START = (RAM_START + RAM_SIZE - MBED_BOOT_STACK_SIZE); +define symbol CSTACK_SIZE = MBED_BOOT_STACK_SIZE; + +/* The rest of RAM */ +define symbol RAM_REGION_START = (RAM_START + VECTORS_SIZE); +define symbol RAM_REGION_SIZE = (RAM_SIZE - VECTORS_SIZE - MBED_BOOT_STACK_SIZE); define memory mem with size = 4G; +/* ROM regions */ define region FLASH_HDR_region = mem:[from FLASH_HDR_START size FLASH_HDR_SIZE]; -define region FLASH_region = mem:[from MBED_APP_START size MBED_APP_SIZE]; -define region RAM_region = mem:[from RAM_REGION_START size RAM_REGION_SIZE]; +define region FLASH_region = mem:[from ROM_EXEC_START size ROM_EXEC_SIZE]; -// -// Keep the debug header -// -keep {section .dbghdr}; -place at start of FLASH_HDR_region { readonly section .dbghdr }; +/* RAM regions */ +define region RAM_region = mem:[from RAM_REGION_START size RAM_REGION_SIZE]; +define region CSTACK_region = mem:[from CSTACK_START size CSTACK_SIZE]; -define block CSTACK with alignment = 8, size = ISR_STACK_SIZE { }; -define block HEAP with alignment = 8, size = HEAP_SIZE { }; +if (FLASH_HDR_INCLUDED == 1) { + keep {section .dbghdr}; + place in FLASH_HDR_region { readonly section .dbghdr }; +} initialize by copy { readwrite }; do not initialize { section .noinit }; -place at address mem: MBED_APP_START { readonly section .intvec }; +place at address mem: ROM_EXEC_START { readonly section .intvec }; place in FLASH_region { readonly }; -place in RAM_region { readwrite, - block CSTACK, block HEAP }; + +define symbol __size_cstack__ = MBED_BOOT_STACK_SIZE; +define block CSTACK with alignment = 8, size = __size_cstack__ { }; +place in CSTACK_region { block CSTACK }; + +define symbol __size_heap__ = 0x10000; +define block HEAP with expanding size, alignment = 8, minimum size = __size_heap__ { }; +place in RAM_region { block HEAP, readwrite, zeroinit }; + diff --git a/targets/TARGET_TI/TARGET_CC32XX/TARGET_CC3220SF/device/TOOLCHAIN_IAR/startup_CC3220SF.s b/targets/TARGET_TI/TARGET_CC32XX/TARGET_CC3220SF/device/TOOLCHAIN_IAR/startup_CC3220SF.S similarity index 100% rename from targets/TARGET_TI/TARGET_CC32XX/TARGET_CC3220SF/device/TOOLCHAIN_IAR/startup_CC3220SF.s rename to targets/TARGET_TI/TARGET_CC32XX/TARGET_CC3220SF/device/TOOLCHAIN_IAR/startup_CC3220SF.S