summaryrefslogtreecommitdiff
path: root/core/cortex-m/ec.lds.S
blob: c8fc6efad7f22cf53ab5a873807d54a567e204c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */
#include "config.h"
#include "rsa.h"

#ifdef RW_B_LDS
#define FW_MEM_OFF_(section) CONFIG_##section##_B_MEM_OFF
#else
#define FW_MEM_OFF_(section) CONFIG_##section##_MEM_OFF
#endif
#define FW_MEM_OFF(section) (FW_MEM_OFF_(section))
#define FW_OFF(section) (CONFIG_PROGRAM_MEMORY_BASE + FW_MEM_OFF(section))

#define FW_SIZE_(section) CONFIG_##section##_SIZE
#define FW_SIZE(section) FW_SIZE_(section)

OUTPUT_FORMAT(BFD_FORMAT, BFD_FORMAT, BFD_FORMAT)
OUTPUT_ARCH(BFD_ARCH)
ENTRY(reset)
MEMORY
{
#if defined(SECTION_IS_RO) && defined(NPCX_RO_HEADER)
    /*
     * Header structure used by npcx booter in RO region.
     * Please notice the location of header must be in front of FW
     * which needs copy. But header itself won't be copied to code ram
     * by booter.
     */
    FLASH_HDR (rx) : ORIGIN = FW_OFF(RO_HDR), LENGTH = FW_SIZE(RO_HDR)
    FLASH (rx) : ORIGIN = FW_OFF(SECTION) + FW_SIZE(RO_HDR), \
                 LENGTH = FW_SIZE(SECTION)
#else
    FLASH (rx) : ORIGIN = FW_OFF(SECTION), LENGTH = FW_SIZE(SECTION)
#endif
#ifdef CONFIG_SHAREDLIB
    SHARED_LIB (rx) : ORIGIN = FW_OFF(SHAREDLIB), LENGTH = FW_SIZE(SHAREDLIB)
#endif

    IRAM (rw)  : ORIGIN = CONFIG_RAM_BASE, LENGTH = CONFIG_RAM_SIZE
#ifdef CONFIG_EXTERNAL_STORAGE
#ifdef CONFIG_REPLACE_LOADER_WITH_BSS_SLOW
   LDR_REGION(rw) : \
        ORIGIN = CONFIG_PROGRAM_MEMORY_BASE + CONFIG_LOADER_MEM_OFF, \
        LENGTH = CONFIG_LOADER_SIZE
#endif /* defined(CONFIG_REPLACE_LOADER_WITH_BSS_SLOW) */
   CDRAM (rx) : \
        ORIGIN = CONFIG_PROGRAM_MEMORY_BASE + FW_MEM_OFF(SECTION), \
        LENGTH = FW_SIZE(SECTION)
#endif /* CONFIG_EXTERNAL_STORAGE */
#ifdef CONFIG_USB_RAM_SIZE
    USB_RAM (rw) : \
        ORIGIN = CONFIG_USB_RAM_BASE, \
        LENGTH = CONFIG_USB_RAM_SIZE * CONFIG_USB_RAM_ACCESS_SIZE / 2
#endif
}
SECTIONS
{
#if defined(SECTION_IS_RO) && defined(NPCX_RO_HEADER)
    .header : {
        KEEP(*(.header))
    } > FLASH_HDR
#endif
#ifdef CONFIG_SHAREDLIB
    .roshared : {
        KEEP(*(.roshared*))
    } > SHARED_LIB
#endif
    .text : {
#if defined(SECTION_IS_RO) && defined(CONFIG_RO_HEAD_ROOM)
	. = . +  CONFIG_RO_HEAD_ROOM;
#endif
#if defined(SECTION_IS_RW) && defined(CONFIG_RW_HEAD_ROOM)
	. = . +  CONFIG_RW_HEAD_ROOM;
#endif
        OUTDIR/core/CORE/init.o (.text.vecttable)
        . = ALIGN(4);
        __version_struct_offset = .;
        KEEP(*(.rodata.ver))

        . = ALIGN(4);
        KEEP(*(.rodata.pstate))

#ifdef SHIFT_CODE_FOR_TEST
        . = ALIGN(256);
#else
        . = ALIGN(4);
#endif
        OUTDIR/core/CORE/init.o (.text)
        *(.text*)
#ifdef CONFIG_EXTERNAL_STORAGE
        __flash_lpfw_start = .;
        /* Entering deep idle FW for better power consumption */
        KEEP(*(.lowpower_ram))
        __flash_lpfw_end = .;
    } > CDRAM AT > FLASH
#else
    } > FLASH
#endif
    . = ALIGN(4);
    .rodata : {
	/* Symbols defined here are declared in link_defs.h */
        __irqprio = .;
        KEEP(*(.rodata.irqprio))
        __irqprio_end = .;

        . = ALIGN(4);
        __cmds = .;
        KEEP(*(SORT(.rodata.cmds*)))
        __cmds_end = .;

        . = ALIGN(4);
        __extension_cmds = .;
        KEEP(*(.rodata.extensioncmds))
	__extension_cmds_end = .;

        . = ALIGN(4);
        __hcmds = .;
        KEEP(*(.rodata.hcmds))
        __hcmds_end = .;

	. = ALIGN(4);
	__mkbp_evt_srcs = .;
	KEEP(*(.rodata.evtsrcs))
	__mkbp_evt_srcs_end = .;

        . = ALIGN(4);
        __hooks_init = .;
        KEEP(*(.rodata.HOOK_INIT))
        __hooks_init_end = .;

        __hooks_pre_freq_change = .;
        KEEP(*(.rodata.HOOK_PRE_FREQ_CHANGE))
        __hooks_pre_freq_change_end = .;

        __hooks_freq_change = .;
        KEEP(*(.rodata.HOOK_FREQ_CHANGE))
        __hooks_freq_change_end = .;

        __hooks_sysjump = .;
        KEEP(*(.rodata.HOOK_SYSJUMP))
        __hooks_sysjump_end = .;

        __hooks_chipset_pre_init = .;
        KEEP(*(.rodata.HOOK_CHIPSET_PRE_INIT))
        __hooks_chipset_pre_init_end = .;

        __hooks_chipset_startup = .;
        KEEP(*(.rodata.HOOK_CHIPSET_STARTUP))
        __hooks_chipset_startup_end = .;

        __hooks_chipset_resume = .;
        KEEP(*(.rodata.HOOK_CHIPSET_RESUME))
        __hooks_chipset_resume_end = .;

        __hooks_chipset_suspend = .;
        KEEP(*(.rodata.HOOK_CHIPSET_SUSPEND))
        __hooks_chipset_suspend_end = .;

        __hooks_chipset_shutdown = .;
        KEEP(*(.rodata.HOOK_CHIPSET_SHUTDOWN))
        __hooks_chipset_shutdown_end = .;

        __hooks_chipset_reset = .;
        KEEP(*(.rodata.HOOK_CHIPSET_RESET))
        __hooks_chipset_reset_end = .;

        __hooks_ac_change = .;
        KEEP(*(.rodata.HOOK_AC_CHANGE))
        __hooks_ac_change_end = .;

        __hooks_lid_change = .;
        KEEP(*(.rodata.HOOK_LID_CHANGE))
        __hooks_lid_change_end = .;

        __hooks_tablet_mode_change = .;
        KEEP(*(.rodata.HOOK_TABLET_MODE_CHANGE))
        __hooks_tablet_mode_change_end = .;

        __hooks_pwrbtn_change = .;
        KEEP(*(.rodata.HOOK_POWER_BUTTON_CHANGE))
        __hooks_pwrbtn_change_end = .;

        __hooks_charge_state_change = .;
        KEEP(*(.rodata.HOOK_CHARGE_STATE_CHANGE))
        __hooks_charge_state_change_end = .;

        __hooks_battery_soc_change = .;
        KEEP(*(.rodata.HOOK_BATTERY_SOC_CHANGE))
        __hooks_battery_soc_change_end = .;

        __hooks_tick = .;
        KEEP(*(.rodata.HOOK_TICK))
        __hooks_tick_end = .;

        __hooks_second = .;
        KEEP(*(.rodata.HOOK_SECOND))
        __hooks_second_end = .;

        __deferred_funcs = .;
        KEEP(*(.rodata.deferred))
        __deferred_funcs_end = .;

        __usb_desc = .;
        KEEP(*(.rodata.usb_desc_conf))
        KEEP(*(SORT(.rodata.usb_desc*)))
        __usb_desc_end = .;
        . = ALIGN(4);
        KEEP(*(.rodata.usb_ep))

        . = ALIGN(4);
        *(.rodata*)

#if defined(SECTION_IS_RO) && defined(CONFIG_FLASH)
        . = ALIGN(64);
        KEEP(*(.google))
#endif
        . = ALIGN(4);
#ifdef CONFIG_EXTERNAL_STORAGE
    } > CDRAM AT > FLASH
#else
    } > FLASH
#endif
    __ro_end = . ;

    __deferred_funcs_count =
		(__deferred_funcs_end - __deferred_funcs) / 4;
    ASSERT(__deferred_funcs_count <= DEFERRABLE_MAX_COUNT,
           "Increase DEFERRABLE_MAX_COUNT")

    .bss : {
	/*
	 * Align to 512 bytes. This is convenient when some memory block
	 * needs big alignment. This is the beginning of the RAM, so there
	 * is usually no penalty on aligning this.
	 */
        . = ALIGN(512);
        __bss_start = .;
	*(.bss.panic_extra)
	*(.bss.big_align)
	/* Stacks must be 64-bit aligned */
        . = ALIGN(8);
        *(.bss.system_stack)
	/* Rest of .bss takes care of its own alignment */
        *(.bss)
#ifdef CONFIG_REPLACE_LOADER_WITH_BSS_SLOW
        . = ALIGN(4);
        __bss_end = .;
#endif /* defined(CONFIG_REPLACE_LOADER_WITH_BSS_SLOW) */
    } > IRAM

    .bss.slow : {
	/* Region of RAM reclaimed from the little firmware(LFW). */
	*(.bss.slow)
#ifdef CONFIG_REPLACE_LOADER_WITH_BSS_SLOW
    } > LDR_REGION
#else
	/*
	 * Not replacing the loader, so .bss.slow is part of .bss.  It needs to
	 * be followed by __bss_end so that .bss.slow will be zeroed by init.
	 */
        . = ALIGN(4);
        __bss_end = .;
    } > IRAM
#endif /* defined(CONFIG_REPLACE_LOADER_WITH_BSS_SLOW) */

#ifdef CONFIG_EXTERNAL_STORAGE
    .data : AT(LOADADDR(.rodata) + SIZEOF(.rodata)) {
#else
    .data : AT(ADDR(.rodata) + SIZEOF(.rodata)) {
#endif
        . = ALIGN(4);
        __data_start = .;
        *(.data.tasks)
        *(.data)
#ifdef CONFIG_MPU
        /* It has to be aligned by 32 bytes to be a valid MPU region. */
        . = ALIGN(32);
        __iram_text_start = .;
#else
        . = ALIGN(4);
#endif
        *(.iram.text)
#ifdef CONFIG_MPU
        . = ALIGN(32);
        __iram_text_end = .;
#else
        . = ALIGN(4);
#endif
        __data_end = .;

	/* Shared memory buffer must be at the end of preallocated RAM, so it
	 * can expand to use all the remaining RAM. */
	__shared_mem_buf = .;

	/* Tag at end of firmware image so that we can find the image size.
	 * This may be overwritten by the shared memory buffer; that's ok
	 * because we only use it to find the image size in flash. */
        . = ALIGN(4);
        BYTE(0x45);
        BYTE(0x4e);
        BYTE(0x44);
        BYTE(0xea);
	/* NOTHING MAY GO AFTER THIS! */
    } > IRAM
#if (defined(CONFIG_VBOOT_HASH) && !defined(CONFIG_MAPPED_STORAGE)) || \
     defined(CONFIG_RWSIG)
    /*
     * Check the shared memory is not too small.
     * The end of memory can have jump data and panic data.
     * Based on calculation, set aside 140 bytes for these.
     * This assert is approximate for RO region but prevents unexpected
     * behavior at run time.
     *
     *                                       CONFIG_RAM_BASE + CONFIG_RAM_SIZE
     * ---+----------------------------------+---------+---------------------+
     *    | shared memory                    |jump data|   panic data        |
     * ---+----------------------------------+---------+---------------------+
     *    __shared_mem_buf                   | jdata(RO) pdata_ptr(if present)
     * ---+-------------------+--------------+---------+---------------------+
     *    __shared_mem_buf    | jdata->total | jdata(RW) pdata_ptr(if present)
     * ---+-------------------+--------------+---------+---------------------+
     *
     * If hash calculation is disable, it is likely the shared memory is not
     * used.
     */
    ASSERT((CONFIG_RAM_BASE + CONFIG_RAM_SIZE - 140) >=
           (__shared_mem_buf + CONFIG_SHARED_MEM_MIN_SIZE),
           "Not enough space for shared memory")
#endif

    /* The linker won't notice if the .data section is too big to fit,
     * apparently because we're sending it into IRAM, not FLASH. The following
     * symbol isn't used by the code, but running "objdump -t *.elf | grep hey"
     * will let us check how much flash space we're actually using. The
     * explicit ASSERT afterwards will cause the linker to abort if we use too
     * much. */
    __hey_flash_used = LOADADDR(.data) + SIZEOF(.data) - FW_OFF(SECTION);
    ASSERT((FW_SIZE(SECTION)
#if defined(CONFIG_RWSIG) && defined(SECTION_IS_RO)
        - CONFIG_RO_PUBKEY_SIZE
#endif
#if defined(CONFIG_RWSIG) && defined(SECTION_IS_RW)
        - CONFIG_RW_SIG_SIZE
#endif
        ) >= (LOADADDR(.data) + SIZEOF(.data) - FW_OFF(SECTION)),
                 "No room left in the flash")

#ifdef CONFIG_USB_RAM_SIZE
    .usb_ram (NOLOAD) : {
        __usb_ram_start = .;
        . = ALIGN(8);
        *(.usb_ram.btable)
        *(.usb_ram.data)
    } > USB_RAM
#endif
#if !(defined(SECTION_IS_RO) && defined(CONFIG_FLASH))
    /DISCARD/ : {
              *(.google)
              }
#endif

    /DISCARD/ : { *(.ARM.*) }
}