blob: 0d84ec1481ca46913f8677b5e1a51228e13053cb [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) \
Julius Werner84446e62021-02-12 17:37:27 -080034 _##name = ABSOLUTE(.);
Julius Wernerec5e5e02014-08-20 15:29:56 -070035
Julius Werner82d16b12020-12-30 15:51:10 -080036#define RECORD_SIZE(name) \
37 _##name##_size = ABSOLUTE(_e##name - _##name);
38
Julius Wernerec5e5e02014-08-20 15:29:56 -070039#define REGION(name, addr, size, expected_align) \
40 SYMBOL(name, addr) \
41 _ = ASSERT(. == ALIGN(expected_align), \
42 STR(name must be aligned to expected_align!)); \
Julius Werner82d16b12020-12-30 15:51:10 -080043 SYMBOL(e##name, addr + size) \
44 RECORD_SIZE(name)
Julius Wernerec5e5e02014-08-20 15:29:56 -070045
Julius Werner757943c2015-12-16 16:07:39 -080046#define ALIAS_REGION(name, alias) \
Julius Werner84446e62021-02-12 17:37:27 -080047 _##alias = ABSOLUTE(_##name); \
48 _e##alias = ABSOLUTE(_e##name); \
Julius Werner82d16b12020-12-30 15:51:10 -080049 RECORD_SIZE(alias)
50
51#define REGION_START(name, addr) SYMBOL(name, addr)
52
53#define REGION_END(name, addr) \
54 SYMBOL(e##name, addr) \
55 RECORD_SIZE(name)
Julius Werner757943c2015-12-16 16:07:39 -080056
Julius Wernerec5e5e02014-08-20 15:29:56 -070057/* Declare according to SRAM/DRAM ranges in SoC hardware-defined address map. */
Julius Werner82d16b12020-12-30 15:51:10 -080058#define SRAM_START(addr) REGION_START(sram, addr)
Julius Wernerec5e5e02014-08-20 15:29:56 -070059
Julius Werner82d16b12020-12-30 15:51:10 -080060#define SRAM_END(addr) REGION_END(sram, addr)
Julius Wernerec5e5e02014-08-20 15:29:56 -070061
Julius Werner82d16b12020-12-30 15:51:10 -080062#define DRAM_START(addr) REGION_START(dram, addr)
Julius Wernerec5e5e02014-08-20 15:29:56 -070063
Aaron Durbin1936f6c2015-07-03 17:04:21 -050064#define TIMESTAMP(addr, size) \
Julius Werner85b1aad2016-08-19 15:17:42 -070065 REGION(timestamp, addr, size, 8) \
66 _ = ASSERT(size >= 212, "Timestamp region must fit timestamp_cache!");
Aaron Durbin1936f6c2015-07-03 17:04:21 -050067
Julius Wernerec5e5e02014-08-20 15:29:56 -070068#define PRERAM_CBMEM_CONSOLE(addr, size) \
69 REGION(preram_cbmem_console, addr, size, 4)
70
Felix Heldca928c62020-04-04 01:47:37 +020071#define EARLYRAM_STACK(addr, size) \
72 REGION(earlyram_stack, addr, size, ARCH_STACK_ALIGN_SIZE)
73
Julius Wernerec5e5e02014-08-20 15:29:56 -070074/* Use either CBFS_CACHE (unified) or both (PRERAM|POSTRAM)_CBFS_CACHE */
Julius Werner757943c2015-12-16 16:07:39 -080075#define CBFS_CACHE(addr, size) \
76 REGION(cbfs_cache, addr, size, 4) \
77 ALIAS_REGION(cbfs_cache, preram_cbfs_cache) \
78 ALIAS_REGION(cbfs_cache, postram_cbfs_cache)
Julius Wernerec5e5e02014-08-20 15:29:56 -070079
Julius Wernercefe89e2019-11-06 19:29:44 -080080#define FMAP_CACHE(addr, sz) \
81 REGION(fmap_cache, addr, sz, 4) \
Julius Werner8245bd22019-12-04 20:32:15 -080082 _ = ASSERT(sz >= FMAP_SIZE, \
Julius Wernercefe89e2019-11-06 19:29:44 -080083 STR(FMAP does not fit in FMAP_CACHE! (sz < FMAP_SIZE)));
84
Julius Werner1e37c9c2019-12-11 17:09:39 -080085#define CBFS_MCACHE(addr, sz) \
86 REGION(cbfs_mcache, addr, sz, 4)
87
Kyösti Mälkkie3acc8f2019-09-13 10:49:20 +030088#if ENV_ROMSTAGE_OR_BEFORE
Julius Werner757943c2015-12-16 16:07:39 -080089 #define PRERAM_CBFS_CACHE(addr, size) \
90 REGION(preram_cbfs_cache, addr, size, 4) \
91 ALIAS_REGION(preram_cbfs_cache, cbfs_cache)
Mary Ruthvenf82e8ab2015-11-13 14:05:27 -080092 #define POSTRAM_CBFS_CACHE(addr, size) \
Mary Ruthvena8aef3a2015-11-24 09:43:27 -080093 REGION(postram_cbfs_cache, addr, size, 4)
Julius Wernerec5e5e02014-08-20 15:29:56 -070094#else
95 #define PRERAM_CBFS_CACHE(addr, size) \
Julius Werner757943c2015-12-16 16:07:39 -080096 REGION(preram_cbfs_cache, addr, size, 4)
97 #define POSTRAM_CBFS_CACHE(addr, size) \
98 REGION(postram_cbfs_cache, addr, size, 4) \
99 ALIAS_REGION(postram_cbfs_cache, cbfs_cache)
Julius Wernerec5e5e02014-08-20 15:29:56 -0700100#endif
101
102/* Careful: 'INCLUDE <filename>' must always be at the end of the output line */
Julius Werner99f46832018-05-16 14:14:04 -0700103#if ENV_DECOMPRESSOR
104 #define DECOMPRESSOR(addr, sz) \
105 SYMBOL(decompressor, addr) \
Julius Werner84446e62021-02-12 17:37:27 -0800106 _edecompressor = ABSOLUTE(_decompressor + sz); \
Julius Werner82d16b12020-12-30 15:51:10 -0800107 RECORD_SIZE(decompressor) \
Julius Werner99f46832018-05-16 14:14:04 -0700108 _ = ASSERT(_eprogram - _program <= sz, \
109 STR(decompressor exceeded its allotted size! (sz))); \
110 INCLUDE "decompressor/lib/program.ld"
111
112 #define OVERLAP_DECOMPRESSOR_ROMSTAGE(addr, sz) DECOMPRESSOR(addr, sz)
113 #define OVERLAP_DECOMPRESSOR_VERSTAGE_ROMSTAGE(addr, sz) \
114 DECOMPRESSOR(addr, sz)
115#else
116 #define DECOMPRESSOR(addr, sz) \
117 REGION(decompressor, addr, sz, 1)
118
119 #define OVERLAP_DECOMPRESSOR_ROMSTAGE(addr, sz) ROMSTAGE(addr, sz)
120 #define OVERLAP_DECOMPRESSOR_VERSTAGE_ROMSTAGE(addr, sz) \
121 OVERLAP_VERSTAGE_ROMSTAGE(addr, sz)
122#endif
123
Aaron Durbinb2a62622015-09-04 12:09:49 -0500124#if ENV_BOOTBLOCK
Julius Wernerec5e5e02014-08-20 15:29:56 -0700125 #define BOOTBLOCK(addr, sz) \
Julius Werner862c3852016-02-18 15:46:15 -0800126 SYMBOL(bootblock, addr) \
Julius Werner84446e62021-02-12 17:37:27 -0800127 _ebootblock = ABSOLUTE(_bootblock + sz); \
Julius Werner82d16b12020-12-30 15:51:10 -0800128 RECORD_SIZE(bootblock) \
Aaron Durbinb2a62622015-09-04 12:09:49 -0500129 _ = ASSERT(_eprogram - _program <= sz, \
Julius Wernerec5e5e02014-08-20 15:29:56 -0700130 STR(Bootblock exceeded its allotted size! (sz))); \
Nico Huber98fc4262016-01-23 01:24:33 +0100131 INCLUDE "bootblock/lib/program.ld"
Julius Wernerec5e5e02014-08-20 15:29:56 -0700132#else
133 #define BOOTBLOCK(addr, sz) \
Julius Werner862c3852016-02-18 15:46:15 -0800134 REGION(bootblock, addr, sz, 1)
Julius Wernerec5e5e02014-08-20 15:29:56 -0700135#endif
136
Aaron Durbinb2a62622015-09-04 12:09:49 -0500137#if ENV_ROMSTAGE
Julius Wernerec5e5e02014-08-20 15:29:56 -0700138 #define ROMSTAGE(addr, sz) \
Julius Werner862c3852016-02-18 15:46:15 -0800139 SYMBOL(romstage, addr) \
Julius Werner84446e62021-02-12 17:37:27 -0800140 _eromstage = ABSOLUTE(_romstage + sz); \
Julius Werner82d16b12020-12-30 15:51:10 -0800141 RECORD_SIZE(romstage) \
Aaron Durbinb2a62622015-09-04 12:09:49 -0500142 _ = ASSERT(_eprogram - _program <= sz, \
Julius Wernerec5e5e02014-08-20 15:29:56 -0700143 STR(Romstage exceeded its allotted size! (sz))); \
Nico Huber98fc4262016-01-23 01:24:33 +0100144 INCLUDE "romstage/lib/program.ld"
Julius Wernerec5e5e02014-08-20 15:29:56 -0700145#else
146 #define ROMSTAGE(addr, sz) \
Julius Werner862c3852016-02-18 15:46:15 -0800147 REGION(romstage, addr, sz, 1)
Julius Wernerec5e5e02014-08-20 15:29:56 -0700148#endif
149
Aaron Durbin4de29d42015-09-03 22:49:36 -0500150#if ENV_RAMSTAGE
Julius Wernerec5e5e02014-08-20 15:29:56 -0700151 #define RAMSTAGE(addr, sz) \
Julius Werner862c3852016-02-18 15:46:15 -0800152 SYMBOL(ramstage, addr) \
Julius Werner84446e62021-02-12 17:37:27 -0800153 _eramstage = ABSOLUTE(_ramstage + sz); \
Julius Werner82d16b12020-12-30 15:51:10 -0800154 RECORD_SIZE(ramstage) \
Aaron Durbin4de29d42015-09-03 22:49:36 -0500155 _ = ASSERT(_eprogram - _program <= sz, \
Julius Wernerec5e5e02014-08-20 15:29:56 -0700156 STR(Ramstage exceeded its allotted size! (sz))); \
Nico Huber98fc4262016-01-23 01:24:33 +0100157 INCLUDE "ramstage/lib/program.ld"
Julius Wernerec5e5e02014-08-20 15:29:56 -0700158#else
159 #define RAMSTAGE(addr, sz) \
Julius Werner862c3852016-02-18 15:46:15 -0800160 REGION(ramstage, addr, sz, 1)
Julius Wernerec5e5e02014-08-20 15:29:56 -0700161#endif
162
Joel Kitching0097f552019-02-21 12:36:55 +0800163/* VBOOT2_WORK must always use VB2_FIRMWARE_WORKBUF_RECOMMENDED_SIZE for its
Felix Held1840f932022-11-18 23:26:38 +0100164 * size argument. The constant is imported via 2constants.h. */
Joel Kitching0097f552019-02-21 12:36:55 +0800165#define VBOOT2_WORK(addr, sz) \
166 REGION(vboot2_work, addr, sz, 16) \
167 _ = ASSERT(sz == VB2_FIRMWARE_WORKBUF_RECOMMENDED_SIZE, \
168 STR(vboot2 work buffer size must be equivalent to \
169 VB2_FIRMWARE_WORKBUF_RECOMMENDED_SIZE! (sz)));
Aaron Durbine5bad5c2015-09-05 10:27:12 -0500170
Sergii Dmytruk2710df72022-11-10 00:40:51 +0200171#define TPM_LOG(addr, size) \
172 REGION(tpm_log, addr, size, 16) \
173 _ = ASSERT(size >= 2K, "tpm log buffer must be at least 2K!");
Philipp Deppenwiesec9b7d1f2018-11-10 00:35:02 +0100174
Julius Werner21a40532020-04-21 16:03:53 -0700175#if ENV_SEPARATE_VERSTAGE
Aaron Durbine5bad5c2015-09-05 10:27:12 -0500176 #define VERSTAGE(addr, sz) \
Julius Werner862c3852016-02-18 15:46:15 -0800177 SYMBOL(verstage, addr) \
Julius Werner84446e62021-02-12 17:37:27 -0800178 _everstage = ABSOLUTE(_verstage + sz); \
Julius Werner82d16b12020-12-30 15:51:10 -0800179 RECORD_SIZE(verstage) \
Aaron Durbine5bad5c2015-09-05 10:27:12 -0500180 _ = ASSERT(_eprogram - _program <= sz, \
181 STR(Verstage exceeded its allotted size! (sz))); \
Nico Huber98fc4262016-01-23 01:24:33 +0100182 INCLUDE "verstage/lib/program.ld"
Aaron Durbine5bad5c2015-09-05 10:27:12 -0500183
Julius Werner73d042b2017-03-17 16:54:48 -0700184 #define OVERLAP_VERSTAGE_ROMSTAGE(addr, size) \
Julius Wernercd49cce2019-03-05 16:53:33 -0800185 _ = ASSERT(CONFIG(VBOOT_RETURN_FROM_VERSTAGE) == 1, \
Julius Werner73d042b2017-03-17 16:54:48 -0700186 "Must set RETURN_FROM_VERSTAGE to overlap romstage."); \
187 VERSTAGE(addr, size)
Aaron Durbine5bad5c2015-09-05 10:27:12 -0500188#else
189 #define VERSTAGE(addr, sz) \
Julius Werner862c3852016-02-18 15:46:15 -0800190 REGION(verstage, addr, sz, 1)
Aaron Durbine5bad5c2015-09-05 10:27:12 -0500191
192 #define OVERLAP_VERSTAGE_ROMSTAGE(addr, size) ROMSTAGE(addr, size)
193#endif
194
Aaron Durbin7f8afe02016-03-18 12:21:23 -0500195#if ENV_POSTCAR
196 #define POSTCAR(addr, sz) \
197 SYMBOL(postcar, addr) \
Julius Werner84446e62021-02-12 17:37:27 -0800198 _epostcar = ABSOLUTE(_postcar + sz); \
Julius Werner82d16b12020-12-30 15:51:10 -0800199 RECORD_SIZE(postcar) \
Aaron Durbin7f8afe02016-03-18 12:21:23 -0500200 _ = ASSERT(_eprogram - _program <= sz, \
201 STR(Aftercar exceeded its allotted size! (sz))); \
202 INCLUDE "postcar/lib/program.ld"
203#else
204 #define POSTCAR(addr, sz) \
205 REGION(postcar, addr, sz, 1)
206#endif
207
Aaron Durbine5bad5c2015-09-05 10:27:12 -0500208#define WATCHDOG_TOMBSTONE(addr, size) \
209 REGION(watchdog_tombstone, addr, size, 4) \
210 _ = ASSERT(size == 4, "watchdog tombstones should be exactly 4 byte!");
211
Julius Wernerec5e5e02014-08-20 15:29:56 -0700212#endif /* __MEMLAYOUT_H */