Wyatt Hepler | 1a96094 | 2019-11-26 14:13:38 -0800 | [diff] [blame] | 1 | /* |
Armando Montanez | a69244e | 2019-11-15 11:25:10 -0800 | [diff] [blame] | 2 | * Copyright 2019 The Pigweed Authors |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
Wyatt Hepler | 1a96094 | 2019-11-26 14:13:38 -0800 | [diff] [blame] | 5 | * use this file except in compliance with the License. You may obtain a copy of |
| 6 | * the License at |
Armando Montanez | a69244e | 2019-11-15 11:25:10 -0800 | [diff] [blame] | 7 | * |
| 8 | * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
Wyatt Hepler | 1a96094 | 2019-11-26 14:13:38 -0800 | [diff] [blame] | 13 | * License for the specific language governing permissions and limitations under |
| 14 | * the License. |
Armando Montanez | a69244e | 2019-11-15 11:25:10 -0800 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | HIDDEN(_min_stack_size = 1K); |
| 18 | |
| 19 | /* Note: This technically doesn't set the firmware's entry point. Setting the |
| 20 | * firmware entry point is done by setting vector_table[1] in core_init.c. |
| 21 | * However, this DOES tell the compiler how to optimize when --gc-sections |
| 22 | * is enabled. |
| 23 | */ |
| 24 | ENTRY(pw_FirmwareInit) |
| 25 | |
| 26 | MEMORY |
| 27 | { |
| 28 | /* Internal Flash */ |
| 29 | FLASH(rx) : ORIGIN = 0x08000000, LENGTH = 512K |
| 30 | /* Internal SRAM */ |
| 31 | RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 192K |
| 32 | } |
| 33 | |
| 34 | SECTIONS |
| 35 | { |
| 36 | |
| 37 | /* Main executable code. */ |
| 38 | .code : ALIGN(8) |
| 39 | { |
| 40 | /* STM32F4xx expects the vector table to be at the beginning of flash. */ |
| 41 | KEEP(*(.vector_table)) |
| 42 | |
| 43 | . = ALIGN(8); |
| 44 | /* Application code. */ |
| 45 | *(.text) |
| 46 | *(.text*) |
| 47 | KEEP(*(.init)) |
| 48 | KEEP(*(.fini)) |
| 49 | |
| 50 | . = ALIGN(8); |
| 51 | /* Constants.*/ |
| 52 | *(.rodata) |
| 53 | *(.rodata*) |
| 54 | |
| 55 | /* .preinit_array, .init_array, .fini_array are used by libc. |
| 56 | * Each section is a list of function pointers that are called pre-main and |
| 57 | * post-exit for object initialization and tear-down. |
| 58 | * Since the region isn't explicitly referenced, specify KEEP to prevent |
| 59 | * link-time garbage collection. SORT is used for sections that have strict |
| 60 | * init/de-init ordering requirements. */ |
| 61 | . = ALIGN(8); |
| 62 | PROVIDE_HIDDEN (__preinit_array_start = .); |
| 63 | KEEP (*(.preinit_array*)) |
| 64 | PROVIDE_HIDDEN (__preinit_array_end = .); |
| 65 | |
| 66 | PROVIDE_HIDDEN (__init_array_start = .); |
| 67 | KEEP (*(SORT(.init_array.*))) |
| 68 | KEEP (*(.init_array*)) |
| 69 | PROVIDE_HIDDEN (__init_array_end = .); |
| 70 | |
| 71 | PROVIDE_HIDDEN (__fini_array_start = .); |
| 72 | KEEP (*(SORT(.fini_array.*))) |
| 73 | KEEP (*(.fini_array*)) |
| 74 | PROVIDE_HIDDEN (__fini_array_end = .); |
| 75 | } >FLASH |
| 76 | |
| 77 | /* Used by unwind-arm/ */ |
| 78 | .ARM : ALIGN(8) { |
| 79 | __exidx_start = .; |
| 80 | *(.ARM.exidx*) |
| 81 | __exidx_end = .; |
| 82 | } >FLASH |
| 83 | |
| 84 | /* Explicitly initialized global and static data. (.data)*/ |
| 85 | .static_init_ram : ALIGN(8) |
| 86 | { |
| 87 | *(.data) |
| 88 | *(.data*) |
| 89 | . = ALIGN(8); |
| 90 | } >RAM AT> FLASH |
| 91 | |
| 92 | /* Zero initialized global/static data. (.bss) |
| 93 | * This section is zero initialized in pw_FirmwareInit(). */ |
| 94 | .zero_init_ram : ALIGN(8) |
| 95 | { |
| 96 | *(.bss) |
| 97 | *(.bss*) |
| 98 | *(COMMON) |
| 99 | . = ALIGN(8); |
| 100 | } >RAM |
| 101 | |
| 102 | /* Link-time check for stack overlaps. */ |
| 103 | .stack (NOLOAD) : ALIGN(8) |
| 104 | { |
| 105 | HIDDEN(_stack_size = ORIGIN(RAM) + LENGTH(RAM) - .); |
| 106 | ASSERT(_stack_size >= _min_stack_size, "Error: Not enough RAM for stack."); |
| 107 | . = . + _stack_size; |
| 108 | } >RAM |
| 109 | } |
| 110 | |
| 111 | /* Symbols used by core_init.c: */ |
| 112 | /* Top of stack to set stack pointer. */ |
| 113 | _stack_end = ORIGIN(RAM) + LENGTH(RAM); |
| 114 | |
| 115 | /* Start of .static_init_ram in FLASH. */ |
| 116 | _static_init_flash_start = LOADADDR(.static_init_ram); |
| 117 | |
| 118 | /* Region of .static_init_ram in RAM. */ |
| 119 | _static_init_ram_start = ADDR(.static_init_ram); |
| 120 | _static_init_ram_end = _static_init_ram_start + SIZEOF(.static_init_ram); |
| 121 | |
| 122 | /* Region of .zero_init_ram. */ |
| 123 | _zero_init_ram_start = ADDR(.zero_init_ram); |
| 124 | _zero_init_ram_end = _zero_init_ram_start + SIZEOF(.zero_init_ram); |
| 125 | |
| 126 | /* arm-none-eabi expects `end` symbol to point to start of heap for sbrk. */ |
| 127 | PROVIDE (end = _zero_init_ram_end); |