blob: bd1d6846f08636b52f3ea5efca906c5f6e169740 [file] [log] [blame]
Angel Pons32859fc2020-04-02 23:48:27 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Julius Wernerec5e5e02014-08-20 15:29:56 -07002
3/* This file contains macro definitions for memlayout.ld linker scripts. */
4
5#ifndef __MEMLAYOUT_H
6#define __MEMLAYOUT_H
7
8#include <arch/memlayout.h>
Joel Kitching0097f552019-02-21 12:36:55 +08009#include <vb2_constants.h>
Julius Wernerec5e5e02014-08-20 15:29:56 -070010
Julius Wernercefe89e2019-11-06 19:29:44 -080011#include "fmap_config.h"
12
Aaron Durbin4de29d42015-09-03 22:49:36 -050013/* Macros that the architecture can override. */
14#ifndef ARCH_POINTER_ALIGN_SIZE
15#define ARCH_POINTER_ALIGN_SIZE 8
16#endif
17
18#ifndef ARCH_CACHELINE_ALIGN_SIZE
19#define ARCH_CACHELINE_ALIGN_SIZE 64
20#endif
21
Julius Wernercefe89e2019-11-06 19:29:44 -080022#define STR(x) XSTR(x)
23#define XSTR(x) #x
Julius Wernerec5e5e02014-08-20 15:29:56 -070024
Aaron Durbin4de29d42015-09-03 22:49:36 -050025#define ALIGN_COUNTER(align) \
26 . = ALIGN(align);
27
Julius Wernerec5e5e02014-08-20 15:29:56 -070028#define SET_COUNTER(name, addr) \
29 _ = ASSERT(. <= addr, STR(name overlaps the previous region!)); \
30 . = addr;
31
32#define SYMBOL(name, addr) \
33 SET_COUNTER(name, addr) \
34 _##name = .;
35
36#define REGION(name, addr, size, expected_align) \
37 SYMBOL(name, addr) \
38 _ = ASSERT(. == ALIGN(expected_align), \
39 STR(name must be aligned to expected_align!)); \
40 SYMBOL(e##name, addr + size)
41
Julius Werner757943c2015-12-16 16:07:39 -080042#define ALIAS_REGION(name, alias) \
43 _##alias = _##name; \
44 _e##alias = _e##name;
45
Julius Wernerec5e5e02014-08-20 15:29:56 -070046/* Declare according to SRAM/DRAM ranges in SoC hardware-defined address map. */
47#define SRAM_START(addr) SYMBOL(sram, addr)
48
49#define SRAM_END(addr) SYMBOL(esram, addr)
50
51#define DRAM_START(addr) SYMBOL(dram, addr)
52
Aaron Durbin1936f6c2015-07-03 17:04:21 -050053#define TIMESTAMP(addr, size) \
Julius Werner85b1aad2016-08-19 15:17:42 -070054 REGION(timestamp, addr, size, 8) \
55 _ = ASSERT(size >= 212, "Timestamp region must fit timestamp_cache!");
Aaron Durbin1936f6c2015-07-03 17:04:21 -050056
Julius Wernerec5e5e02014-08-20 15:29:56 -070057#define PRERAM_CBMEM_CONSOLE(addr, size) \
58 REGION(preram_cbmem_console, addr, size, 4)
59
Felix Heldca928c62020-04-04 01:47:37 +020060#define EARLYRAM_STACK(addr, size) \
61 REGION(earlyram_stack, addr, size, ARCH_STACK_ALIGN_SIZE)
62
Julius Wernerec5e5e02014-08-20 15:29:56 -070063/* Use either CBFS_CACHE (unified) or both (PRERAM|POSTRAM)_CBFS_CACHE */
Julius Werner757943c2015-12-16 16:07:39 -080064#define CBFS_CACHE(addr, size) \
65 REGION(cbfs_cache, addr, size, 4) \
66 ALIAS_REGION(cbfs_cache, preram_cbfs_cache) \
67 ALIAS_REGION(cbfs_cache, postram_cbfs_cache)
Julius Wernerec5e5e02014-08-20 15:29:56 -070068
Julius Wernercefe89e2019-11-06 19:29:44 -080069#define FMAP_CACHE(addr, sz) \
70 REGION(fmap_cache, addr, sz, 4) \
Julius Werner8245bd22019-12-04 20:32:15 -080071 _ = ASSERT(sz >= FMAP_SIZE, \
Julius Wernercefe89e2019-11-06 19:29:44 -080072 STR(FMAP does not fit in FMAP_CACHE! (sz < FMAP_SIZE)));
73
Kyösti Mälkkie3acc8f2019-09-13 10:49:20 +030074#if ENV_ROMSTAGE_OR_BEFORE
Julius Werner757943c2015-12-16 16:07:39 -080075 #define PRERAM_CBFS_CACHE(addr, size) \
76 REGION(preram_cbfs_cache, addr, size, 4) \
77 ALIAS_REGION(preram_cbfs_cache, cbfs_cache)
Mary Ruthvenf82e8ab2015-11-13 14:05:27 -080078 #define POSTRAM_CBFS_CACHE(addr, size) \
Mary Ruthvena8aef3a2015-11-24 09:43:27 -080079 REGION(postram_cbfs_cache, addr, size, 4)
Julius Wernerec5e5e02014-08-20 15:29:56 -070080#else
81 #define PRERAM_CBFS_CACHE(addr, size) \
Julius Werner757943c2015-12-16 16:07:39 -080082 REGION(preram_cbfs_cache, addr, size, 4)
83 #define POSTRAM_CBFS_CACHE(addr, size) \
84 REGION(postram_cbfs_cache, addr, size, 4) \
85 ALIAS_REGION(postram_cbfs_cache, cbfs_cache)
Julius Wernerec5e5e02014-08-20 15:29:56 -070086#endif
87
88/* Careful: 'INCLUDE <filename>' must always be at the end of the output line */
Julius Werner99f46832018-05-16 14:14:04 -070089#if ENV_DECOMPRESSOR
90 #define DECOMPRESSOR(addr, sz) \
91 SYMBOL(decompressor, addr) \
92 _edecompressor = _decompressor + sz; \
93 _ = ASSERT(_eprogram - _program <= sz, \
94 STR(decompressor exceeded its allotted size! (sz))); \
95 INCLUDE "decompressor/lib/program.ld"
96
97 #define OVERLAP_DECOMPRESSOR_ROMSTAGE(addr, sz) DECOMPRESSOR(addr, sz)
98 #define OVERLAP_DECOMPRESSOR_VERSTAGE_ROMSTAGE(addr, sz) \
99 DECOMPRESSOR(addr, sz)
100#else
101 #define DECOMPRESSOR(addr, sz) \
102 REGION(decompressor, addr, sz, 1)
103
104 #define OVERLAP_DECOMPRESSOR_ROMSTAGE(addr, sz) ROMSTAGE(addr, sz)
105 #define OVERLAP_DECOMPRESSOR_VERSTAGE_ROMSTAGE(addr, sz) \
106 OVERLAP_VERSTAGE_ROMSTAGE(addr, sz)
107#endif
108
Aaron Durbinb2a62622015-09-04 12:09:49 -0500109#if ENV_BOOTBLOCK
Julius Wernerec5e5e02014-08-20 15:29:56 -0700110 #define BOOTBLOCK(addr, sz) \
Julius Werner862c3852016-02-18 15:46:15 -0800111 SYMBOL(bootblock, addr) \
112 _ebootblock = _bootblock + sz; \
Aaron Durbinb2a62622015-09-04 12:09:49 -0500113 _ = ASSERT(_eprogram - _program <= sz, \
Julius Wernerec5e5e02014-08-20 15:29:56 -0700114 STR(Bootblock exceeded its allotted size! (sz))); \
Nico Huber98fc4262016-01-23 01:24:33 +0100115 INCLUDE "bootblock/lib/program.ld"
Julius Wernerec5e5e02014-08-20 15:29:56 -0700116#else
117 #define BOOTBLOCK(addr, sz) \
Julius Werner862c3852016-02-18 15:46:15 -0800118 REGION(bootblock, addr, sz, 1)
Julius Wernerec5e5e02014-08-20 15:29:56 -0700119#endif
120
Aaron Durbinb2a62622015-09-04 12:09:49 -0500121#if ENV_ROMSTAGE
Julius Wernerec5e5e02014-08-20 15:29:56 -0700122 #define ROMSTAGE(addr, sz) \
Julius Werner862c3852016-02-18 15:46:15 -0800123 SYMBOL(romstage, addr) \
124 _eromstage = _romstage + sz; \
Aaron Durbinb2a62622015-09-04 12:09:49 -0500125 _ = ASSERT(_eprogram - _program <= sz, \
Julius Wernerec5e5e02014-08-20 15:29:56 -0700126 STR(Romstage exceeded its allotted size! (sz))); \
Nico Huber98fc4262016-01-23 01:24:33 +0100127 INCLUDE "romstage/lib/program.ld"
Julius Wernerec5e5e02014-08-20 15:29:56 -0700128#else
129 #define ROMSTAGE(addr, sz) \
Julius Werner862c3852016-02-18 15:46:15 -0800130 REGION(romstage, addr, sz, 1)
Julius Wernerec5e5e02014-08-20 15:29:56 -0700131#endif
132
Aaron Durbin4de29d42015-09-03 22:49:36 -0500133#if ENV_RAMSTAGE
Julius Wernerec5e5e02014-08-20 15:29:56 -0700134 #define RAMSTAGE(addr, sz) \
Julius Werner862c3852016-02-18 15:46:15 -0800135 SYMBOL(ramstage, addr) \
136 _eramstage = _ramstage + sz; \
Aaron Durbin4de29d42015-09-03 22:49:36 -0500137 _ = ASSERT(_eprogram - _program <= sz, \
Julius Wernerec5e5e02014-08-20 15:29:56 -0700138 STR(Ramstage exceeded its allotted size! (sz))); \
Nico Huber98fc4262016-01-23 01:24:33 +0100139 INCLUDE "ramstage/lib/program.ld"
Julius Wernerec5e5e02014-08-20 15:29:56 -0700140#else
141 #define RAMSTAGE(addr, sz) \
Julius Werner862c3852016-02-18 15:46:15 -0800142 REGION(ramstage, addr, sz, 1)
Julius Wernerec5e5e02014-08-20 15:29:56 -0700143#endif
144
Joel Kitching0097f552019-02-21 12:36:55 +0800145/* VBOOT2_WORK must always use VB2_FIRMWARE_WORKBUF_RECOMMENDED_SIZE for its
146 * size argument. The constant is imported via vb2_workbuf_size.h. */
147#define VBOOT2_WORK(addr, sz) \
148 REGION(vboot2_work, addr, sz, 16) \
149 _ = ASSERT(sz == VB2_FIRMWARE_WORKBUF_RECOMMENDED_SIZE, \
150 STR(vboot2 work buffer size must be equivalent to \
151 VB2_FIRMWARE_WORKBUF_RECOMMENDED_SIZE! (sz)));
Aaron Durbine5bad5c2015-09-05 10:27:12 -0500152
Bill XIEc79e96b2019-08-22 20:28:36 +0800153#define TPM_TCPA_LOG(addr, size) \
154 REGION(tpm_tcpa_log, addr, size, 16) \
155 _ = ASSERT(size >= 2K, "tpm tcpa log buffer must be at least 2K!");
Philipp Deppenwiesec9b7d1f2018-11-10 00:35:02 +0100156
Julius Werner21a40532020-04-21 16:03:53 -0700157#if ENV_SEPARATE_VERSTAGE
Aaron Durbine5bad5c2015-09-05 10:27:12 -0500158 #define VERSTAGE(addr, sz) \
Julius Werner862c3852016-02-18 15:46:15 -0800159 SYMBOL(verstage, addr) \
160 _everstage = _verstage + sz; \
Aaron Durbine5bad5c2015-09-05 10:27:12 -0500161 _ = ASSERT(_eprogram - _program <= sz, \
162 STR(Verstage exceeded its allotted size! (sz))); \
Nico Huber98fc4262016-01-23 01:24:33 +0100163 INCLUDE "verstage/lib/program.ld"
Aaron Durbine5bad5c2015-09-05 10:27:12 -0500164
Julius Werner73d042b2017-03-17 16:54:48 -0700165 #define OVERLAP_VERSTAGE_ROMSTAGE(addr, size) \
Julius Wernercd49cce2019-03-05 16:53:33 -0800166 _ = ASSERT(CONFIG(VBOOT_RETURN_FROM_VERSTAGE) == 1, \
Julius Werner73d042b2017-03-17 16:54:48 -0700167 "Must set RETURN_FROM_VERSTAGE to overlap romstage."); \
168 VERSTAGE(addr, size)
Aaron Durbine5bad5c2015-09-05 10:27:12 -0500169#else
170 #define VERSTAGE(addr, sz) \
Julius Werner862c3852016-02-18 15:46:15 -0800171 REGION(verstage, addr, sz, 1)
Aaron Durbine5bad5c2015-09-05 10:27:12 -0500172
173 #define OVERLAP_VERSTAGE_ROMSTAGE(addr, size) ROMSTAGE(addr, size)
174#endif
175
Aaron Durbin7f8afe02016-03-18 12:21:23 -0500176#if ENV_POSTCAR
177 #define POSTCAR(addr, sz) \
178 SYMBOL(postcar, addr) \
179 _epostcar = _postcar + sz; \
180 _ = ASSERT(_eprogram - _program <= sz, \
181 STR(Aftercar exceeded its allotted size! (sz))); \
182 INCLUDE "postcar/lib/program.ld"
183#else
184 #define POSTCAR(addr, sz) \
185 REGION(postcar, addr, sz, 1)
186#endif
187
Aaron Durbine5bad5c2015-09-05 10:27:12 -0500188#define WATCHDOG_TOMBSTONE(addr, size) \
189 REGION(watchdog_tombstone, addr, size, 4) \
190 _ = ASSERT(size == 4, "watchdog tombstones should be exactly 4 byte!");
191
Julius Wernerec5e5e02014-08-20 15:29:56 -0700192#endif /* __MEMLAYOUT_H */