From 53fb70aa320d4b6217b92d79f08d02321f93f79a Mon Sep 17 00:00:00 2001 From: Marius Brehler Date: Thu, 5 Oct 2023 14:22:26 +0200 Subject: [PATCH 1/4] Update cmsis_device_f4 to v2.6.8 (#287) --- third_party/cmsis_device_f4 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/cmsis_device_f4 b/third_party/cmsis_device_f4 index 6fe2c1f..7ac6909 160000 --- a/third_party/cmsis_device_f4 +++ b/third_party/cmsis_device_f4 @@ -1 +1 @@ -Subproject commit 6fe2c1f498feda34ee422720ff8b3bd1b4656145 +Subproject commit 7ac69098b3e5f9b2d929acd4f087e92a7e59e0e9 From ec52466c5930cade5bf124d36543702614878c04 Mon Sep 17 00:00:00 2001 From: Marius Brehler Date: Wed, 11 Oct 2023 05:32:49 +0200 Subject: [PATCH 2/4] Import files from nrfx repository --- third_party/nrfx-custom/README.md | 13 + .../nrfx-custom/gcc_startup_nrf52840.S | 460 ++++++++++++++++++ third_party/nrfx-custom/nrf52840_xxaa.ld | 15 + third_party/nrfx-custom/nrf_common.ld | 425 ++++++++++++++++ 4 files changed, 913 insertions(+) create mode 100644 third_party/nrfx-custom/README.md create mode 100644 third_party/nrfx-custom/gcc_startup_nrf52840.S create mode 100644 third_party/nrfx-custom/nrf52840_xxaa.ld create mode 100644 third_party/nrfx-custom/nrf_common.ld diff --git a/third_party/nrfx-custom/README.md b/third_party/nrfx-custom/README.md new file mode 100644 index 0000000..6485d4c --- /dev/null +++ b/third_party/nrfx-custom/README.md @@ -0,0 +1,13 @@ + +# nrfx + +This folder contains a subset of files imported from [NordicSemiconductor/nrfx](https://github.com/NordicSemiconductor/nrfx). + +- The [`nrf52840_xxaa.ld`](https://github.com/NordicSemiconductor/nrfx/blob/7ef620bedd3fd41828e0f81523a1d08a986b8a0e/mdk/nrf52840_xxaa.ld) linker script was imported at state NordicSemiconductor/nrfx@7ef620b. + +- The file [`nrf_common.ld`](https://github.com/NordicSemiconductor/nrfx/blob/7ef620bedd3fd41828e0f81523a1d08a986b8a0e/mdk/nrf_common.ld) was imported at state NordicSemiconductor/nrfx@7ef620b. + +- The file [`gcc_startup_nrf52840.S`](https://github.com/NordicSemiconductor/nrfx/blob/7ef620bedd3fd41828e0f81523a1d08a986b8a0e/mdk/gcc_startup_nrf52840.S) was imported at state NordicSemiconductor/nrfx@7ef620b. diff --git a/third_party/nrfx-custom/gcc_startup_nrf52840.S b/third_party/nrfx-custom/gcc_startup_nrf52840.S new file mode 100644 index 0000000..8fa5ea8 --- /dev/null +++ b/third_party/nrfx-custom/gcc_startup_nrf52840.S @@ -0,0 +1,460 @@ +/* + +Copyright (c) 2009-2023 ARM Limited. All rights reserved. + + SPDX-License-Identifier: Apache-2.0 + +Licensed under the Apache License, Version 2.0 (the License); you may +not use this file except in compliance with the License. +You may obtain a copy of the License at + + www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an AS IS BASIS, WITHOUT +WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +NOTICE: This file has been modified by Nordic Semiconductor ASA. + +*/ + + .syntax unified + .arch armv7e-m + +#ifdef __STARTUP_CONFIG +#include "startup_config.h" +#ifndef __STARTUP_CONFIG_STACK_ALIGNEMENT +#define __STARTUP_CONFIG_STACK_ALIGNEMENT 3 +#endif +#endif + + .section .stack +#if defined(__STARTUP_CONFIG) + .align __STARTUP_CONFIG_STACK_ALIGNEMENT + .equ Stack_Size, __STARTUP_CONFIG_STACK_SIZE +#elif defined(__STACK_SIZE) + .align 3 + .equ Stack_Size, __STACK_SIZE +#else + .align 3 + .equ Stack_Size, 16384 +#endif + .globl __StackTop + .globl __StackLimit +__StackLimit: + .space Stack_Size + .size __StackLimit, . - __StackLimit +__StackTop: + .size __StackTop, . - __StackTop + + .section .heap + .align 3 +#if defined(__STARTUP_CONFIG) + .equ Heap_Size, __STARTUP_CONFIG_HEAP_SIZE +#elif defined(__HEAP_SIZE) + .equ Heap_Size, __HEAP_SIZE +#else + .equ Heap_Size, 16384 +#endif + .globl __HeapBase + .globl __HeapLimit +__HeapBase: + .if Heap_Size + .space Heap_Size + .endif + .size __HeapBase, . - __HeapBase +__HeapLimit: + .size __HeapLimit, . - __HeapLimit + + .section .isr_vector, "ax" + .align 2 + .globl __isr_vector +__isr_vector: + .long __StackTop /* Top of Stack */ + .long Reset_Handler + .long NMI_Handler + .long HardFault_Handler + .long MemoryManagement_Handler + .long BusFault_Handler + .long UsageFault_Handler + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long SVC_Handler + .long DebugMon_Handler + .long 0 /*Reserved */ + .long PendSV_Handler + .long SysTick_Handler + + /* External Interrupts */ + .long POWER_CLOCK_IRQHandler + .long RADIO_IRQHandler + .long UARTE0_UART0_IRQHandler + .long SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler + .long SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQHandler + .long NFCT_IRQHandler + .long GPIOTE_IRQHandler + .long SAADC_IRQHandler + .long TIMER0_IRQHandler + .long TIMER1_IRQHandler + .long TIMER2_IRQHandler + .long RTC0_IRQHandler + .long TEMP_IRQHandler + .long RNG_IRQHandler + .long ECB_IRQHandler + .long CCM_AAR_IRQHandler + .long WDT_IRQHandler + .long RTC1_IRQHandler + .long QDEC_IRQHandler + .long COMP_LPCOMP_IRQHandler + .long SWI0_EGU0_IRQHandler + .long SWI1_EGU1_IRQHandler + .long SWI2_EGU2_IRQHandler + .long SWI3_EGU3_IRQHandler + .long SWI4_EGU4_IRQHandler + .long SWI5_EGU5_IRQHandler + .long TIMER3_IRQHandler + .long TIMER4_IRQHandler + .long PWM0_IRQHandler + .long PDM_IRQHandler + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long MWU_IRQHandler + .long PWM1_IRQHandler + .long PWM2_IRQHandler + .long SPIM2_SPIS2_SPI2_IRQHandler + .long RTC2_IRQHandler + .long I2S_IRQHandler + .long FPU_IRQHandler + .long USBD_IRQHandler + .long UARTE1_IRQHandler + .long QSPI_IRQHandler + .long CRYPTOCELL_IRQHandler + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long PWM3_IRQHandler + .long 0 /*Reserved */ + .long SPIM3_IRQHandler + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + .long 0 /*Reserved */ + + .size __isr_vector, . - __isr_vector + +/* Reset Handler */ + + + .text + .thumb + .thumb_func + .align 1 + .globl Reset_Handler + .type Reset_Handler, %function +Reset_Handler: + + +/* Loop to copy data from read only memory to RAM. + * The ranges of copy from/to are specified by following symbols: + * __etext: LMA of start of the section to copy from. Usually end of text + * __data_start: VMA of start of the section to copy to. + * __data_end: VMA of end of the section to copy to. + * + * All addresses must be aligned to 4 bytes boundary. + */ +#ifndef __STARTUP_SKIP_ETEXT + +/* Load .data */ + ldr r1, =__data_start + ldr r2, =__data_end + ldr r3, =__data_load_start + bl copy_region + +/* Load .sdata */ + ldr r1, =__sdata_start + ldr r2, =__sdata_end + ldr r3, =__sdata_load_start + bl copy_region + +/* Load .tdata */ + ldr r1, =__tdata_start + ldr r2, =__tdata_end + ldr r3, =__tdata_load_start + bl copy_region + +/* Load .fast */ + ldr r1, =__fast_start + ldr r2, =__fast_end + ldr r3, =__fast_load_start + bl copy_region + + b copy_etext_done + +/* Method that loads data from nvm to ram */ +copy_region: + subs r2, r2, r1 + ble L_copy_region_done + +L_copy_region: + subs r2, r2, #4 + ldr r0, [r3,r2] + str r0, [r1,r2] + bgt L_copy_region + +L_copy_region_done: + + bx lr + +copy_etext_done: + + +#endif + +/* This part of work usually is done in C library startup code. Otherwise, + * define __STARTUP_CLEAR_BSS to enable it in this startup. This section + * clears the RAM where BSS data is located. + * + * The BSS section is specified by following symbols + * __bss_start__: start of the BSS section. + * __bss_end__: end of the BSS section. + * + * All addresses must be aligned to 4 bytes boundary. + */ +#ifdef __STARTUP_CLEAR_BSS + ldr r1, =__bss_start__ + ldr r2, =__bss_end__ + bl clear_region + + ldr r1, =__tbss_start__ + ldr r2, =__tbss_end__ + bl clear_region + + ldr r1, =__sbss_start__ + ldr r2, =__sbss_end__ + bl clear_region + + b clear_bss_done + +/* Method that clears default-0 registers */ +clear_region: + movs r0, 0 + + subs r2, r2, r1 + ble .L_clear_region_done + +.L_clear_region: + subs r2, r2, #4 + str r0, [r1, r2] + bgt .L_clear_region + +.L_clear_region_done: + + bx lr + +clear_bss_done: + +#endif /* __STARTUP_CLEAR_BSS */ + +/* Execute SystemInit function. */ + bl SystemInit + +/* Call _start function provided by libraries. + * If those libraries are not accessible, define __START as your entry point. + */ +#ifndef __START +#define __START _start +#endif + bl __START + + .pool + .size Reset_Handler,.-Reset_Handler + + .section ".text" + + +/* Dummy Exception Handlers (infinite loops which can be modified) */ + + .weak NMI_Handler + .type NMI_Handler, %function +NMI_Handler: + b . + .size NMI_Handler, . - NMI_Handler + + + .weak HardFault_Handler + .type HardFault_Handler, %function +HardFault_Handler: + b . + .size HardFault_Handler, . - HardFault_Handler + + + .weak MemoryManagement_Handler + .type MemoryManagement_Handler, %function +MemoryManagement_Handler: + b . + .size MemoryManagement_Handler, . - MemoryManagement_Handler + + + .weak BusFault_Handler + .type BusFault_Handler, %function +BusFault_Handler: + b . + .size BusFault_Handler, . - BusFault_Handler + + + .weak UsageFault_Handler + .type UsageFault_Handler, %function +UsageFault_Handler: + b . + .size UsageFault_Handler, . - UsageFault_Handler + + + .weak SVC_Handler + .type SVC_Handler, %function +SVC_Handler: + b . + .size SVC_Handler, . - SVC_Handler + + + .weak DebugMon_Handler + .type DebugMon_Handler, %function +DebugMon_Handler: + b . + .size DebugMon_Handler, . - DebugMon_Handler + + + .weak PendSV_Handler + .type PendSV_Handler, %function +PendSV_Handler: + b . + .size PendSV_Handler, . - PendSV_Handler + + + .weak SysTick_Handler + .type SysTick_Handler, %function +SysTick_Handler: + b . + .size SysTick_Handler, . - SysTick_Handler + + +/* IRQ Handlers */ + + .globl Default_Handler + .type Default_Handler, %function +Default_Handler: + b . + .size Default_Handler, . - Default_Handler + + .macro IRQ handler + .weak \handler + .set \handler, Default_Handler + .endm + + IRQ POWER_CLOCK_IRQHandler + IRQ RADIO_IRQHandler + IRQ UARTE0_UART0_IRQHandler + IRQ SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler + IRQ SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQHandler + IRQ NFCT_IRQHandler + IRQ GPIOTE_IRQHandler + IRQ SAADC_IRQHandler + IRQ TIMER0_IRQHandler + IRQ TIMER1_IRQHandler + IRQ TIMER2_IRQHandler + IRQ RTC0_IRQHandler + IRQ TEMP_IRQHandler + IRQ RNG_IRQHandler + IRQ ECB_IRQHandler + IRQ CCM_AAR_IRQHandler + IRQ WDT_IRQHandler + IRQ RTC1_IRQHandler + IRQ QDEC_IRQHandler + IRQ COMP_LPCOMP_IRQHandler + IRQ SWI0_EGU0_IRQHandler + IRQ SWI1_EGU1_IRQHandler + IRQ SWI2_EGU2_IRQHandler + IRQ SWI3_EGU3_IRQHandler + IRQ SWI4_EGU4_IRQHandler + IRQ SWI5_EGU5_IRQHandler + IRQ TIMER3_IRQHandler + IRQ TIMER4_IRQHandler + IRQ PWM0_IRQHandler + IRQ PDM_IRQHandler + IRQ MWU_IRQHandler + IRQ PWM1_IRQHandler + IRQ PWM2_IRQHandler + IRQ SPIM2_SPIS2_SPI2_IRQHandler + IRQ RTC2_IRQHandler + IRQ I2S_IRQHandler + IRQ FPU_IRQHandler + IRQ USBD_IRQHandler + IRQ UARTE1_IRQHandler + IRQ QSPI_IRQHandler + IRQ CRYPTOCELL_IRQHandler + IRQ PWM3_IRQHandler + IRQ SPIM3_IRQHandler + + .end diff --git a/third_party/nrfx-custom/nrf52840_xxaa.ld b/third_party/nrfx-custom/nrf52840_xxaa.ld new file mode 100644 index 0000000..89fac57 --- /dev/null +++ b/third_party/nrfx-custom/nrf52840_xxaa.ld @@ -0,0 +1,15 @@ +/* Linker script to configure memory regions. */ + +SEARCH_DIR(.) +GROUP(-lgcc -lc -lnosys) + +MEMORY +{ + FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x100000 + EXTFLASH (rx) : ORIGIN = 0x12000000, LENGTH = 0x8000000 + RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x40000 + CODE_RAM (rwx) : ORIGIN = 0x800000, LENGTH = 0x40000 +} + + +INCLUDE "nrf_common.ld" diff --git a/third_party/nrfx-custom/nrf_common.ld b/third_party/nrfx-custom/nrf_common.ld new file mode 100644 index 0000000..65b620e --- /dev/null +++ b/third_party/nrfx-custom/nrf_common.ld @@ -0,0 +1,425 @@ +/* Linker script for Nordic Semiconductor nRF devices + * + * Version: Sourcery G++ 4.5-1 + * Support: https://support.codesourcery.com/GNUToolchain/ + * + * Copyright (c) 2007, 2008, 2009, 2010 CodeSourcery, Inc. + * + * The authors hereby grant permission to use, copy, modify, distribute, + * and license this software and its documentation for any purpose, provided + * that existing copyright notices are retained in all copies and that this + * notice is included verbatim in any distributions. No written agreement, + * license, or royalty fee is required for any of the authorized uses. + * Modifications to this software may be copyrighted by their authors + * and need not follow the licensing terms described here, provided that + * the new terms are clearly indicated on the first page of each file where + * they apply. + */ +OUTPUT_FORMAT ("elf32-littlearm", "elf32-bigarm", "elf32-littlearm") + +/* Linker script to place sections and symbol values. Should be used together + * with other linker script that defines memory regions FLASH and RAM. + * It references following symbols, which must be defined in code: + * Reset_Handler : Entry of reset handler + * + * It defines following symbols, which code can use without definition: + * __init_start + * __init_end + * __text_start + * __CTOR_LIST__ + * __CTOR_END__ + * __DTOR_LIST__ + * __DTOR_END__ + * __exidx_start + * __exidx_end + * __etext + * _etext + * etext + * __data_load_start + * __data_start + * __data_start__ + * __preinit_array_start + * __preinit_array_end + * __data_end + * __data_end__ + * __sdata_start + * __sdata_end + * __fast_start + * __fast_end + * __edata + * _edata + * edata + * __init_array_start + * __init_array_end + * __fini_array_start + * __fini_array_end + * __bss_start__ + * __bss_start + * __bss_end__ + * __bss_end + * __end + * _end + * __end__ + * end + * __HeapBase + * __HeapLimit + * __StackLimit + * __StackTop + * __stack + */ +ENTRY(Reset_Handler) + + +SECTIONS +{ + /* Set the location counter to start of FLASH */ + . = ALIGN(ORIGIN(FLASH), 4); + + .vectors . : { + __vectors_start = .; + /* Vector table */ + KEEP(*(.isr_vector)) + KEEP(*(.vectors)) + } > FLASH + __vectors_size = SIZEOF(.vectors); + __vectors_end = __vectors_start + __vectors_size; + ASSERT(__vectors_start == __vectors_end || (__vectors_end - ORIGIN(FLASH)) <= LENGTH(FLASH) , "error: .vectors is too large to fit in FLASH memory segment") + + + /* .ctors section (global constructor function pointers) */ + . = ALIGN(4); + .ctors . : { + __ctors_start = .; + __CTOR_LIST__ = .; + KEEP (*crtbegin*.o(.ctors)) + KEEP (*(EXCLUDE_FILE (*crtend*.o ) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + __CTOR_END__ = .; + } > FLASH + __ctors_size = SIZEOF(.ctors); + __ctors_end = __ctors_start + __ctors_size; + ASSERT(__ctors_start == __ctors_end || (__ctors_end - ORIGIN(FLASH)) <= LENGTH(FLASH) , "error: .ctors is too large to fit in FLASH memory segment") + + + /* .detors section (global destructor function pointers) */ + . = ALIGN(4); + .dtors . : { + __dtors_start = .; + __DTOR_LIST__ = .; + KEEP (*crtbegin*.o(.dtors)) + KEEP (*(EXCLUDE_FILE (*crtend*.o ) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + __DTOR_END__ = .; + } > FLASH + __dtors_size = SIZEOF(.dtors); + __dtors_end = __dtors_start + __dtors_size; + ASSERT(__dtors_start == __dtors_end || (__dtors_end - ORIGIN(FLASH)) <= LENGTH(FLASH) , "error: .dtors is too large to fit in FLASH memory segment") + + + /* .rodata section */ + . = ALIGN(4); + .rodata . : { + . = ALIGN(4); + __rodata_start = .; + *(.rodata*) + *(.srodata .srodata.*) + } > FLASH + __rodata_size = SIZEOF(.rodata); + __rodata_end = __rodata_start + __rodata_size; + ASSERT(__rodata_start == __rodata_end || (__rodata_end - ORIGIN(FLASH)) <= LENGTH(FLASH) , "error: .rodata is too large to fit in FLASH memory segment") + + + . = ALIGN(4); + .text . : { + __text_start = .; + /* Reset handler for C startup file */ + KEEP(*(.startup)) + *(.startup*) + + /* text: executable instructions of a program. */ + *(.text*) + + /* executable instructions that contribute to the process initialization code */ + . = ALIGN(4); + KEEP(*(.init)) + . = ALIGN(4); + __preinit_array_start = .; + KEEP (*(.preinit_array)) + __preinit_array_end = .; + + . = ALIGN(4); + __init_array_start = .; + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array)) + __init_array_end = .; + + /* executable instructions that contribute to the process termination code */ + KEEP(*(.fini)) + + . = ALIGN(4); + __fini_array_start = .; + KEEP (*(.fini_array)) + KEEP (*(SORT(.fini_array.*))) + __fini_array_end = .; + + /* DWARF-based unwinding - exception handling. C++ stuff (disable with no-asynchronous-unwind-tables)*/ + . = ALIGN(4); + KEEP(*(.eh_frame*)) + + /* section contains a pointer to the .eh_frame section which is */ + /* accessible to the runtime support code of a C++ application */ + . = ALIGN(4); + *(.eh_frame_hdr) + + /* hash tables */ + . = ALIGN(4); + *(.hash) + *(.gnu.hash) + + . = ALIGN(4); + *(.gnu_extab* .gnu.linkonce.extab.*) + + . = ALIGN(4); + __exidx_start = .; + *(.gnu_exidx* .gnu.linkonce.exidx.*) + . = ALIGN(4); + __exidx_end = .; + } > FLASH + __text_size = SIZEOF(.text); + __text_end = __text_start + __text_size; + ASSERT(__text_start == __text_end || (__text_end - ORIGIN(FLASH)) <= LENGTH(FLASH) , "error: .text is too large to fit in FLASH memory segment") + + . = ALIGN(4); + .copy.table . : { + __copy_table_start__ = .; + + LONG (__data_load_start) + LONG (__data_start) + LONG ((__data_end - __data_start) / 4) + + LONG (__sdata_load_start) + LONG (__sdata_start) + LONG ((__sdata_end - __sdata_start) / 4) + + LONG (__tdata_load_start) + LONG (__tdata_start) + LONG ((__tdata_end - __tdata_start) / 4) + + LONG (__fast_load_start) + LONG (__fast_start) + LONG ((__fast_end - __fast_start) / 4) + + /* Add aditional regions here as needed. */ + + __copy_table_end__ = .; + } > FLASH + + . = ALIGN(4); + .zero.table . : { + __zero_table_start__ = .; + + LONG (__bss_start) + LONG ((__bss_end - __bss_start) / 4) + + LONG (__sbss_start) + LONG ((__sbss_end - __sbss_start) / 4) + + LONG (__tbss_start) + LONG ((__tbss_end - __tbss_start) / 4) + + /* Add aditional regions here as needed. */ + + __zero_table_end__ = .; + } > FLASH + + /* End of text */ + . = ALIGN(4); + __etext = .; PROVIDE(etext = .); PROVIDE(_etext = .); + + + /* Define start of all sections that needs to be loaded on boot */ + . = ALIGN(4); + __all_data_load_start = .; + + /* .data section */ + __data_load_start = .; + .data : AT(__data_load_start){ + . = ALIGN(4); + __data_start = .; + __data_start__ = .; + *(vtable) + *(.data* .gnu.linkonce.d.*) + + . = ALIGN(4); + KEEP(*(.jcr*)) + } > RAM + __data_size = SIZEOF(.data); + __data_end = __data_start + __data_size; + __data_end__ = __data_end; + __data_load_end = __data_load_start + __data_size; + ASSERT(__data_load_start == __data_load_end || (__data_load_end - ORIGIN(FLASH)) <= LENGTH(FLASH) , "error: .data is too large to fit in FLASH memory segment") + ASSERT(__data_start == __data_end || (__data_end - ORIGIN(RAM)) <= LENGTH(RAM) , "error: .data is too large to fit in RAM memory segment") + + + /* .sdata section */ + . = ALIGN(4); + __sdata_load_start = ALIGN(__data_load_end, 4); + .sdata . : AT(__sdata_load_start){ + . = ALIGN(4); + __sdata_start = .; + *(.sdata .sdata.* .gnu.linkonce.s.*) + *(.sdata2 .sdata2.* .gnu.linkonce.s2.*) + } > RAM + __sdata_size = SIZEOF(.sdata); + __sdata_end = __sdata_start + __sdata_size; + __sdata_load_end = __sdata_load_start + __sdata_size; + ASSERT(__sdata_load_start == __sdata_load_end || (__sdata_load_end - ORIGIN(FLASH)) <= LENGTH(FLASH) , "error: .sdata is too large to fit in FLASH memory segment") + ASSERT(__sdata_start == __sdata_end || (__sdata_end - ORIGIN(RAM)) <= LENGTH(RAM) , "error: .sdata is too large to fit in RAM memory segment") + + + /* .tdata section */ + . = ALIGN(4); + __tdata_load_start = ALIGN(__sdata_load_end, 4); + .tdata . : AT(__tdata_load_start){ + . = ALIGN(4); + __tdata_start = .; + *(.tdata .tdata.* .gnu.linkonce.td.*) + *(.stdata .stdata.*) + } > RAM + __tdata_size = SIZEOF(.tdata); + __tdata_end = __tdata_start + __tdata_size; + __tdata_load_end = __tdata_load_start + __tdata_size; + ASSERT(__tdata_load_start == __tdata_load_end || (__tdata_load_end - ORIGIN(FLASH)) <= LENGTH(FLASH) , "error: .tdata is too large to fit in FLASH memory segment") + ASSERT(__tdata_start == __tdata_end || (__tdata_end - ORIGIN(RAM)) <= LENGTH(RAM) , "error: .tdata is too large to fit in RAM memory segment") + + + /* .fast section */ + . = ALIGN(4); + __fast_load_start = ALIGN(__tdata_load_end, 4); + .fast . : AT(__fast_load_start){ + . = ALIGN(4); + __fast_start = .; + *(.fast .fast.*) + *(.fastcode .fastcode.*) + *(.fastdata .fastdata.*) + *(.ramcode*) + } > RAM + __fast_size = SIZEOF(.fast); + __fast_end = __fast_start + __fast_size; + __fast_load_end = __fast_load_start + __fast_size; + ASSERT(__fast_load_start == __fast_load_end || (__fast_load_end - ORIGIN(FLASH)) <= LENGTH(FLASH) , "error: .fast is too large to fit in FLASH memory segment") + ASSERT(__fast_start == __fast_end || (__fast_end - ORIGIN(RAM)) <= LENGTH(RAM) , "error: .fast is too large to fit in RAM memory segment") + + /* end of data in RAM */ + . = ALIGN(4); + _edata = .; PROVIDE (edata = .); PROVIDE (__edata = .); + + + /* No-init section. */ + . = ALIGN(4); + .noinit . (NOLOAD): { + __noinit_start = .; PROVIDE(__noinit_start__ = .); + *(.noinit .noinit.*) + *(.no_init .no_init.*) + *(.noninit .noninit.*) + *(.non_init .non_init.*) + . = ALIGN(4); + } > RAM + __noinit_size = SIZEOF(.noinit); + __noinit_end = __noinit_start + __noinit_size; + __noinit_end__ = __noinit_end; + ASSERT(__noinit_start == __noinit_end || (__noinit_end - ORIGIN(RAM)) <= LENGTH(RAM) , "error: .noinit is too large to fit in RAM memory segment") + + + /* .bss section */ + . = ALIGN(4); + .bss . (NOLOAD): { + __bss_start = .; PROVIDE(__bss_start__ = .); + *(.bss* .gnu.linkonce.b.*) + *(.dynbss) + *(COMMON) + . = ALIGN(4); + } > RAM + __bss_size = SIZEOF(.bss); + __bss_end = __bss_start + __bss_size; + __bss_end__ = __bss_end; + ASSERT(__bss_start == __bss_end || (__bss_end - ORIGIN(RAM)) <= LENGTH(RAM) , "error: .bss is too large to fit in RAM memory segment") + + + /* .sbss section */ + . = ALIGN(4); + .sbss . (NOLOAD): { + __sbss_start = .; + __sbss_start__ = __sbss_start; + *(.sbss .sbss.* .gnu.linkonce.sb.*) + *(.sbss2 .sbss2.* .gnu.linkonce.sb2.*) + *(.dynsbss) + . = ALIGN(4); + } > RAM + __sbss_size = SIZEOF(.sbss); + __sbss_end = __sbss_start + __sbss_size; + __sbss_end__ = __sbss_end; + ASSERT(__sbss_start == __sbss_end || (__sbss_end - ORIGIN(RAM)) <= LENGTH(RAM) , "error: .sbss is too large to fit in RAM memory segment") + + + /* .tbss section */ + . = ALIGN(4); + .tbss . (NOLOAD): { + __tbss_start = .; + __tbss_start__ = __tbss_start; + . = ALIGN(4); + *(.tbss .tbss.* .gnu.linkonce.tb.*) + *(.tcommon) + *(.stbss .stbss.*) + . = ALIGN(4); + } > RAM + __tbss_size = SIZEOF(.tbss); + __tbss_end = __tbss_start + __tbss_size; + __tbss_end__ = __tbss_end; + ASSERT(__tbss_start == __tbss_end || (__tbss_end - ORIGIN(RAM)) <= LENGTH(RAM) , "error: .tbss is too large to fit in RAM memory segment") + + . = ALIGN(4); + . = SEGMENT_START("ldata-segment", .); + + . = ALIGN(4); + .heap . (COPY): { + __heap_start = .; + __HeapBase = .; + __heap_base = .; + __end = .; + PROVIDE(end = .); + PROVIDE(_end = .); + PROVIDE(__end__ = .); + KEEP(*(.heap*)) + __HeapLimit = .; + __heap_limit = .; + } > RAM + __heap_end = .; + + /* .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): { + KEEP(*(.stack*)) + } > RAM + + /* Set stack top to end of RAM, and stack limit move down by + * size of stack_dummy section */ + __stack_end = ORIGIN(RAM) + LENGTH(RAM); + + __StackTop = ORIGIN(RAM) + LENGTH(RAM); + __StackLimit = __StackTop - SIZEOF(.stack_dummy); + PROVIDE(__stack = __StackTop); + + /* Check if data + heap + stack exceeds RAM limit */ + ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack") + + /* Check if text sections + data exceeds FLASH limit */ + DataInitFlashUsed = __bss_start - __data_start; + CodeFlashUsed = _etext - ORIGIN(FLASH); + TotalFlashUsed = CodeFlashUsed + DataInitFlashUsed; + ASSERT(TotalFlashUsed <= LENGTH(FLASH), "region FLASH overflowed with .data and user data") +} + From 9382c9ecd59c5988384cac553e4abe0dd73afe61 Mon Sep 17 00:00:00 2001 From: Marius Brehler Date: Wed, 11 Oct 2023 05:45:51 +0200 Subject: [PATCH 3/4] Add LICENSE files and SPDX tags --- LICENSES/BSD-3-Clause.txt | 26 ++++++++++++++++++++++++ LICENSES/LicenseRef-nrf_common.txt | 11 ++++++++++ third_party/nrfx-custom/nrf52840_xxaa.ld | 3 +++ third_party/nrfx-custom/nrf_common.ld | 1 + 4 files changed, 41 insertions(+) create mode 100644 LICENSES/BSD-3-Clause.txt create mode 100644 LICENSES/LicenseRef-nrf_common.txt diff --git a/LICENSES/BSD-3-Clause.txt b/LICENSES/BSD-3-Clause.txt new file mode 100644 index 0000000..a173b10 --- /dev/null +++ b/LICENSES/BSD-3-Clause.txt @@ -0,0 +1,26 @@ +Copyright (c) . + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/LICENSES/LicenseRef-nrf_common.txt b/LICENSES/LicenseRef-nrf_common.txt new file mode 100644 index 0000000..5462a8d --- /dev/null +++ b/LICENSES/LicenseRef-nrf_common.txt @@ -0,0 +1,11 @@ + * Copyright (c) 2007, 2008, 2009, 2010 CodeSourcery, Inc. + * + * The authors hereby grant permission to use, copy, modify, distribute, + * and license this software and its documentation for any purpose, provided + * that existing copyright notices are retained in all copies and that this + * notice is included verbatim in any distributions. No written agreement, + * license, or royalty fee is required for any of the authorized uses. + * Modifications to this software may be copyrighted by their authors + * and need not follow the licensing terms described here, provided that + * the new terms are clearly indicated on the first page of each file where + * they apply. diff --git a/third_party/nrfx-custom/nrf52840_xxaa.ld b/third_party/nrfx-custom/nrf52840_xxaa.ld index 89fac57..cbf7579 100644 --- a/third_party/nrfx-custom/nrf52840_xxaa.ld +++ b/third_party/nrfx-custom/nrf52840_xxaa.ld @@ -1,3 +1,6 @@ +/* SPDX-FileCopyrightText: Nordic Semiconductor ASA + * SPDX-License-Identifier: BSD-3-Clause + */ /* Linker script to configure memory regions. */ SEARCH_DIR(.) diff --git a/third_party/nrfx-custom/nrf_common.ld b/third_party/nrfx-custom/nrf_common.ld index 65b620e..b2daa77 100644 --- a/third_party/nrfx-custom/nrf_common.ld +++ b/third_party/nrfx-custom/nrf_common.ld @@ -4,6 +4,7 @@ * Support: https://support.codesourcery.com/GNUToolchain/ * * Copyright (c) 2007, 2008, 2009, 2010 CodeSourcery, Inc. + * SPDX-License-Identifier: LicenseRef-nrf_common * * The authors hereby grant permission to use, copy, modify, distribute, * and license this software and its documentation for any purpose, provided From 1e52dc22d7e9ef1715083b7cf7280791e8fa7aa4 Mon Sep 17 00:00:00 2001 From: Lucas Camphausen Date: Sat, 14 Oct 2023 07:05:18 +0200 Subject: [PATCH 4/4] Copy .got and .got.plt sections (#291) Change linker script and startup code to also copy the `.got` and `.got.plt` sections. --- .../nrfx-custom/gcc_startup_nrf52840.S | 13 ++++++ third_party/nrfx-custom/nrf_common.ld | 42 +++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/third_party/nrfx-custom/gcc_startup_nrf52840.S b/third_party/nrfx-custom/gcc_startup_nrf52840.S index 8fa5ea8..a42501c 100644 --- a/third_party/nrfx-custom/gcc_startup_nrf52840.S +++ b/third_party/nrfx-custom/gcc_startup_nrf52840.S @@ -1,6 +1,7 @@ /* Copyright (c) 2009-2023 ARM Limited. All rights reserved. +Copyright 2023 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. SPDX-License-Identifier: Apache-2.0 @@ -251,6 +252,18 @@ Reset_Handler: ldr r3, =__fast_load_start bl copy_region +/* Load .got */ + ldr r1, =__got_start + ldr r2, =__got_end + ldr r3, =__got_load_start + bl copy_region + +/* Load .got.plt */ + ldr r1, =__got_plt_start + ldr r2, =__got_plt_end + ldr r3, =__got_plt_load_start + bl copy_region + b copy_etext_done /* Method that loads data from nvm to ram */ diff --git a/third_party/nrfx-custom/nrf_common.ld b/third_party/nrfx-custom/nrf_common.ld index b2daa77..b1d6f88 100644 --- a/third_party/nrfx-custom/nrf_common.ld +++ b/third_party/nrfx-custom/nrf_common.ld @@ -4,6 +4,7 @@ * Support: https://support.codesourcery.com/GNUToolchain/ * * Copyright (c) 2007, 2008, 2009, 2010 CodeSourcery, Inc. + * Copyright 2023 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. * SPDX-License-Identifier: LicenseRef-nrf_common * * The authors hereby grant permission to use, copy, modify, distribute, @@ -47,6 +48,10 @@ OUTPUT_FORMAT ("elf32-littlearm", "elf32-bigarm", "elf32-littlearm") * __sdata_end * __fast_start * __fast_end + * __got_start + * __got_end + * __got_plt_start + * __got_plt_end * __edata * _edata * edata @@ -212,6 +217,14 @@ SECTIONS LONG (__fast_start) LONG ((__fast_end - __fast_start) / 4) + LONG (__got_load_start) + LONG (__got_start) + LONG ((__got_end - __got_start) / 4) + + LONG (__got_plt_load_start) + LONG (__got_plt_start) + LONG ((__got_plt_end - __got_plt_start) / 4) + /* Add aditional regions here as needed. */ __copy_table_end__ = .; @@ -313,6 +326,35 @@ SECTIONS ASSERT(__fast_load_start == __fast_load_end || (__fast_load_end - ORIGIN(FLASH)) <= LENGTH(FLASH) , "error: .fast is too large to fit in FLASH memory segment") ASSERT(__fast_start == __fast_end || (__fast_end - ORIGIN(RAM)) <= LENGTH(RAM) , "error: .fast is too large to fit in RAM memory segment") + + /* .got section */ + . = ALIGN(4); + __got_load_start = ALIGN(__fast_load_end, 4); + .got . : AT(__got_load_start){ + . = ALIGN(4); + __got_start = .; + *(.got) + } > RAM + __got_size = SIZEOF(.got); + __got_end = __got_start + __got_size; + __got_load_end = __got_load_start + __got_size; + ASSERT(__got_load_start == __got_load_end || (__got_load_end - ORIGIN(FLASH)) <= LENGTH(FLASH) , "error: .got is too large to fit in FLASH memory segment") + ASSERT(__got_start == __got_end || (__got_end - ORIGIN(RAM)) <= LENGTH(RAM) , "error: .got is too large to fit in RAM memory segment") + + /* .got.plt section */ + . = ALIGN(4); + __got_plt_load_start = ALIGN(__got_load_end, 4); + .got.plt . : AT(__got_plt_load_start){ + . = ALIGN(4); + __got_plt_start = .; + *(.got.plt) + } > RAM + __got_plt_size = SIZEOF(.got.plt); + __got_plt_end = __got_plt_start + __got_plt_size; + __got_plt_load_end = __got_plt_load_start + __got_plt_size; + ASSERT(__got_plt_load_start == __got_plt_load_end || (__got_plt_load_end - ORIGIN(FLASH)) <= LENGTH(FLASH) , "error: .got.plt is too large to fit in FLASH memory segment") + ASSERT(__got_plt_start == __got_plt_end || (__got_plt_end - ORIGIN(RAM)) <= LENGTH(RAM) , "error: .got.plt is too large to fit in RAM memory segment") + /* end of data in RAM */ . = ALIGN(4); _edata = .; PROVIDE (edata = .); PROVIDE (__edata = .);