blob: 0a6337238de6335869100b266fc3df77150c6bff [file] [log] [blame]
Wyatt Hepler1a960942019-11-26 14:13:38 -08001/*
Armando Montaneza69244e2019-11-15 11:25:10 -08002 * Copyright 2019 The Pigweed Authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
Wyatt Hepler1a960942019-11-26 14:13:38 -08005 * use this file except in compliance with the License. You may obtain a copy of
6 * the License at
Armando Montaneza69244e2019-11-15 11:25:10 -08007 *
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 Hepler1a960942019-11-26 14:13:38 -080013 * License for the specific language governing permissions and limitations under
14 * the License.
Armando Montaneza69244e2019-11-15 11:25:10 -080015 */
16
17HIDDEN(_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 */
24ENTRY(pw_FirmwareInit)
25
26MEMORY
27{
28 /* Internal Flash */
29 FLASH(rx) : ORIGIN = 0x08000000, LENGTH = 512K
30 /* Internal SRAM */
31 RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 192K
32}
33
34SECTIONS
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. */
127PROVIDE (end = _zero_init_ram_end);