From 4e6e0410732999f5c95bae109ce88bc47bf5de24 Mon Sep 17 00:00:00 2001 From: jake Date: Sun, 10 Nov 2024 12:49:15 -0800 Subject: [PATCH] Added an example linker file for ref Going to use the example linker file for a refernce along with the ld documentation. --- example.ld | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ linker.ld | 21 +++++++++++++----- 2 files changed, 79 insertions(+), 5 deletions(-) create mode 100644 example.ld diff --git a/example.ld b/example.ld new file mode 100644 index 0000000..b8432c6 --- /dev/null +++ b/example.ld @@ -0,0 +1,63 @@ +/* Define the memory regions: Flash and RAM */ +MEMORY +{ + FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 64K + RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 20K +} + +/* Define entry point (usually the reset handler defined in startup code) */ +ENTRY(Reset_Handler) + +/* Define the sections of the program */ +SECTIONS +{ + /* Code section, mapped to Flash memory */ + .text : + { + KEEP(*(.isr_vector)) /* Vector table, which must be at the beginning of Flash */ + *(.text) /* All code goes here */ + *(.rodata) /* Read-only data (e.g., const variables) */ + _etext = .; /* Mark the end of text section */ + } > FLASH + + /* Initialized data section, copied from Flash to RAM at startup */ + .data : + { + _sdata = .; /* Start of data section */ + *(.data) /* Initialized data */ + _edata = .; /* End of data section */ + } > RAM AT > FLASH + + /* Uninitialized data section, placed in RAM but not stored in Flash */ + .bss : + { + _sbss = .; /* Start of BSS */ + *(.bss) /* Uninitialized data */ + *(COMMON) /* Common symbols (zero-initialized) */ + _ebss = .; /* End of BSS */ + } > RAM + + /* Stack section */ + ._stack : + { + . = ALIGN(8); /* Align to 8-byte boundary */ + _estack = .; /* End of stack (top of the stack) */ + . = . + 2048; /* Reserve 2 KB for stack */ + _sstack = .; /* Start of stack */ + } > RAM + + /* Heap section */ + .heap : + { + _sheap = .; /* Start of heap */ + . = . + 2048; /* Reserve 2 KB for heap */ + _eheap = .; /* End of heap */ + } > RAM +} + +/* Provide symbols to be used in the startup code */ +PROVIDE(_stack_start = _sstack); +PROVIDE(_stack_end = _estack); +PROVIDE(_heap_start = _sheap); +PROVIDE(_heap_end = _eheap); + diff --git a/linker.ld b/linker.ld index d87e152..109680f 100644 --- a/linker.ld +++ b/linker.ld @@ -37,11 +37,22 @@ MEMORY floating_point = 0; SECTIONS { - . = 0x10000; - .text : { *(.text) } - . = 0x8000000; - .data : { *(.data) } - .bss : { *(.bss) } + /* Code section, mapped to Flash memory */ + .tect : + { + KEEP(*(.isr_vector)) /* Vector table, which must be at the beginning of Flash*/ + *(.text) /* All code goes here */ + *(.rodata) /* Read-only data (e.g., const vars) */ + _etext = .; /* Mark the end of text section */ + } > FLASH + + /* Initialized data section, copied from Flash to RAM on startup. */ + .data : + { + _sdata = .; /* Start of data section */ + *(.data) /* Initialized data */ + _edata = .; /* End of data section */ + } > RAM AT > FLASH }