Skip to content

Commit

Permalink
Add SBT vs non-SBT Linkerfile Selection to MAX32672 LP Example (#401)
Browse files Browse the repository at this point in the history
* Clean up script

* Add secure vs non-secure linker selection

* Revert "Clean up script"

This reverts commit fcde559.
  • Loading branch information
Jake-Carter authored Feb 15, 2023
1 parent c8cfd0c commit d998f01
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 4 deletions.
149 changes: 149 additions & 0 deletions Examples/MAX32672/LP/lp-nonsecure.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/*******************************************************************************
* Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2016-05-02 14:15:59 -0700 (Mon, 02 May 2016) $
* $Revision: 22594 $
*
******************************************************************************/

MEMORY {
FLASH (rx) : ORIGIN = 0x10000000, LENGTH = 1024K /* 1024kB "FLASH" */
SRAM (rwx) : ORIGIN = 0x20000000, LENGTH = 32K /* 32kB LP reduced SRAM with ECC */
/* SRAM (rwx) : ORIGIN = 0x20000000, LENGTH = 160K /* 160kB max SRAM with ECC */
/*^ If ECC is enabled, the stack size must be reduced. Otherwise, a
HardFault will occur on startup as the stack is expanded into the
ECC's reserved SRAM space.
*/
/* SRAM (rwx) : ORIGIN = 0x20000000, LENGTH = 200K /* 200kB SRAM, no ECC */
}

SECTIONS {

.text :
{
_text = .;
KEEP(*(.isr_vector))
*(.text*) /* program code */
*(.rodata*) /* read-only data: "const" */

KEEP(*(.init))
KEEP(*(.fini))

/* C++ Exception handling */
KEEP(*(.eh_frame*))
_etext = .;
} > FLASH

/* Binary import */
.bin_storage :
{
FILL(0xFF)
_bin_start_ = .;
KEEP(*(.bin_storage_img))
_bin_end_ = .;
. = ALIGN(4);
} > FLASH

/* it's used for C++ exception handling */
/* we need to keep this to avoid overlapping */
.ARM.exidx :
{
__exidx_start = .;
*(.ARM.exidx*)
__exidx_end = .;
} > FLASH

.data :
{
_data = ALIGN(., 4);
*(.data*) /*read-write initialized data: initialized global variable*/
*(.spix_config*) /* SPIX configuration functions need to be run from SRAM */
*(.flashprog*) /* Flash program */

/* These array sections are used by __libc_init_array to call static C++ constructors */
. = ALIGN(4);
/* preinit data */
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP(*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);

. = ALIGN(4);
/* init data */
PROVIDE_HIDDEN (__init_array_start = .);
KEEP(*(SORT(.init_array.*)))
KEEP(*(.init_array))
PROVIDE_HIDDEN (__init_array_end = .);

. = ALIGN(4);
/* finit data */
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP(*(SORT(.fini_array.*)))
KEEP(*(.fini_array))
PROVIDE_HIDDEN (__fini_array_end = .);

_edata = ALIGN(., 4);
} > SRAM AT>FLASH
__load_data = LOADADDR(.data);

.bss :
{
. = ALIGN(4);
_bss = .;
*(.bss*) /*read-write zero initialized data: uninitialzed global variable*/
*(COMMON)
_ebss = ALIGN(., 4);
} > SRAM

/* Set stack top to end of RAM, and stack limit move down by
* size of stack_dummy section */
__StackTop = ORIGIN(SRAM) + LENGTH(SRAM);
__StackLimit = __StackTop - SIZEOF(.stack_dummy);

/* .stack_dummy section doesn't contains any symbols. It is only
* used for linker to calculate size of stack sections, and assign
* values to stack symbols later */
.stack_dummy (COPY):
{
*(.stack*)
} > SRAM

.heap (COPY):
{
. = ALIGN(4);
*(.heap*)
__HeapLimit = ABSOLUTE(__StackLimit);
} > SRAM

PROVIDE(__stack = __StackTop);

/* Check if data + heap + stack exceeds RAM limit */
ASSERT(__StackLimit >= _ebss, "region RAM overflowed with stack")
}
10 changes: 8 additions & 2 deletions Examples/MAX32672/LP/lp.ld → Examples/MAX32672/LP/lp-sla.ld
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@
MEMORY {
HEADER (rx) : ORIGIN = 0x10000000, LENGTH = 0x200
FLASH (rx) : ORIGIN = 0x10000200, LENGTH = 1024K - 0x200 /* 1024kB "FLASH" */
SRAM (rwx) : ORIGIN = 0x20000000, LENGTH = 32k
SRAM (rwx) : ORIGIN = 0x20000000, LENGTH = 32K /* 32kB LP reduced SRAM with ECC */
/* SRAM (rwx) : ORIGIN = 0x20000000, LENGTH = 160K /* 160kB max SRAM with ECC */
/*^ If ECC is enabled, the stack size must be reduced. Otherwise, a
HardFault will occur on startup as the stack is expanded into the
ECC's reserved SRAM space.
*/
/* SRAM (rwx) : ORIGIN = 0x20000000, LENGTH = 200K /* 200kB SRAM, no ECC */
}

ENTRY(Reset_Handler)
Expand Down Expand Up @@ -159,4 +165,4 @@ SECTIONS {

/* Check if data + heap + stack exceeds RAM limit */
ASSERT(__StackLimit >= _ebss, "region RAM overflowed with stack")
}
}
14 changes: 12 additions & 2 deletions Examples/MAX32672/LP/project.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@
# https://www.analog.com/en/education/education-library/videos/6313214207112.html
SBT=0

# Use the local linker file
LINKERFILE=lp.ld
# This Low-Power example shuts down some SRAM instances.
# To ensure application code does not use the SRAM that will
# be shut down, the available SRAM size is reduced with a
# custom linkerfile. The section below selects the
# appropriate file depending on whether the SBTs are used or not.
ifeq ($(SBT),1)
# This linkerfile contains extra sections for compatibility with the Secure Boot Tools (SBT).
override LINKERFILE = lp-sla.ld
else
# This linkerfile is for use with standard non-secure applications.
override LINKERFILE = lp-nonsecure.ld
endif # SBT

0 comments on commit d998f01

Please sign in to comment.