blob: af277eaf204083bc4ab2659e6aff83d8b0fb58e3 [file] [log] [blame]
Angel Pons32859fc2020-04-02 23:48:27 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Julius Wernerec5e5e02014-08-20 15:29:56 -07003
4/* This file contains macro definitions for memlayout.ld linker scripts. */
5
6#ifndef __MEMLAYOUT_H
7#define __MEMLAYOUT_H
8
9#include <arch/memlayout.h>
Joel Kitching0097f552019-02-21 12:36:55 +080010#include <vb2_constants.h>
Julius Wernerec5e5e02014-08-20 15:29:56 -070011
Julius Wernercefe89e2019-11-06 19:29:44 -080012#include "fmap_config.h"
13
Aaron Durbin4de29d42015-09-03 22:49:36 -050014/* Macros that the architecture can override. */
15#ifndef ARCH_POINTER_ALIGN_SIZE
16#define ARCH_POINTER_ALIGN_SIZE 8
17#endif
18
19#ifndef ARCH_CACHELINE_ALIGN_SIZE
20#define ARCH_CACHELINE_ALIGN_SIZE 64
21#endif
22
Julius Wernercefe89e2019-11-06 19:29:44 -080023#define STR(x) XSTR(x)
24#define XSTR(x) #x
Julius Wernerec5e5e02014-08-20 15:29:56 -070025
Aaron Durbin4de29d42015-09-03 22:49:36 -050026#define ALIGN_COUNTER(align) \
27 . = ALIGN(align);
28
Julius Wernerec5e5e02014-08-20 15:29:56 -070029#define SET_COUNTER(name, addr) \
30 _ = ASSERT(. <= addr, STR(name overlaps the previous region!)); \
31 . = addr;
32
33#define SYMBOL(name, addr) \
34 SET_COUNTER(name, addr) \
35 _##name = .;
36
37#define REGION(name, addr, size, expected_align) \
38 SYMBOL(name, addr) \
39 _ = ASSERT(. == ALIGN(expected_align), \
40 STR(name must be aligned to expected_align!)); \
41 SYMBOL(e##name, addr + size)
42
Julius Werner757943c2015-12-16 16:07:39 -080043#define ALIAS_REGION(name, alias) \
44 _##alias = _##name; \
45 _e##alias = _e##name;
46
Julius Wernerec5e5e02014-08-20 15:29:56 -070047/* Declare according to SRAM/DRAM ranges in SoC hardware-defined address map. */
48#define SRAM_START(addr) SYMBOL(sram, addr)
49
50#define SRAM_END(addr) SYMBOL(esram, addr)
51
52#define DRAM_START(addr) SYMBOL(dram, addr)
53
Aaron Durbin1936f6c2015-07-03 17:04:21 -050054#define TIMESTAMP(addr, size) \
Julius Werner85b1aad2016-08-19 15:17:42 -070055 REGION(timestamp, addr, size, 8) \
56 _ = ASSERT(size >= 212, "Timestamp region must fit timestamp_cache!");
Aaron Durbin1936f6c2015-07-03 17:04:21 -050057
Julius Wernerec5e5e02014-08-20 15:29:56 -070058#define PRERAM_CBMEM_CONSOLE(addr, size) \
59 REGION(preram_cbmem_console, addr, size, 4)
60
Felix Heldca928c62020-04-04 01:47:37 +020061#define EARLYRAM_STACK(addr, size) \
62 REGION(earlyram_stack, addr, size, ARCH_STACK_ALIGN_SIZE)
63
Julius Wernerec5e5e02014-08-20 15:29:56 -070064/* Use either CBFS_CACHE (unified) or both (PRERAM|POSTRAM)_CBFS_CACHE */
Julius Werner757943c2015-12-16 16:07:39 -080065#define CBFS_CACHE(addr, size) \
66 REGION(cbfs_cache, addr, size, 4) \
67 ALIAS_REGION(cbfs_cache, preram_cbfs_cache) \
68 ALIAS_REGION(cbfs_cache, postram_cbfs_cache)
Julius Wernerec5e5e02014-08-20 15:29:56 -070069
Julius Wernercefe89e2019-11-06 19:29:44 -080070#define FMAP_CACHE(addr, sz) \
71 REGION(fmap_cache, addr, sz, 4) \
Julius Werner8245bd22019-12-04 20:32:15 -080072 _ = ASSERT(sz >= FMAP_SIZE, \
Julius Wernercefe89e2019-11-06 19:29:44 -080073 STR(FMAP does not fit in FMAP_CACHE! (sz < FMAP_SIZE)));
74
Kyösti Mälkkie3acc8f2019-09-13 10:49:20 +030075#if ENV_ROMSTAGE_OR_BEFORE
Julius Werner757943c2015-12-16 16:07:39 -080076 #define PRERAM_CBFS_CACHE(addr, size) \
77 REGION(preram_cbfs_cache, addr, size, 4) \
78 ALIAS_REGION(preram_cbfs_cache, cbfs_cache)
Mary Ruthvenf82e8ab2015-11-13 14:05:27 -080079 #define POSTRAM_CBFS_CACHE(addr, size) \
Mary Ruthvena8aef3a2015-11-24 09:43:27 -080080 REGION(postram_cbfs_cache, addr, size, 4)
Julius Wernerec5e5e02014-08-20 15:29:56 -070081#else
82 #define PRERAM_CBFS_CACHE(addr, size) \
Julius Werner757943c2015-12-16 16:07:39 -080083 REGION(preram_cbfs_cache, addr, size, 4)
84 #define POSTRAM_CBFS_CACHE(addr, size) \
85 REGION(postram_cbfs_cache, addr, size, 4) \
86 ALIAS_REGION(postram_cbfs_cache, cbfs_cache)
Julius Wernerec5e5e02014-08-20 15:29:56 -070087#endif
88
89/* Careful: 'INCLUDE <filename>' must always be at the end of the output line */
Julius Werner99f46832018-05-16 14:14:04 -070090#if ENV_DECOMPRESSOR
91 #define DECOMPRESSOR(addr, sz) \
92 SYMBOL(decompressor, addr) \
93 _edecompressor = _decompressor + sz; \
94 _ = ASSERT(_eprogram - _program <= sz, \
95 STR(decompressor exceeded its allotted size! (sz))); \
96 INCLUDE "decompressor/lib/program.ld"
97
98 #define OVERLAP_DECOMPRESSOR_ROMSTAGE(addr, sz) DECOMPRESSOR(addr, sz)
99 #define OVERLAP_DECOMPRESSOR_VERSTAGE_ROMSTAGE(addr, sz) \
100 DECOMPRESSOR(addr, sz)
101#else
102 #define DECOMPRESSOR(addr, sz) \
103 REGION(decompressor, addr, sz, 1)
104
105 #define OVERLAP_DECOMPRESSOR_ROMSTAGE(addr, sz) ROMSTAGE(addr, sz)
106 #define OVERLAP_DECOMPRESSOR_VERSTAGE_ROMSTAGE(addr, sz) \
107 OVERLAP_VERSTAGE_ROMSTAGE(addr, sz)
108#endif
109
Aaron Durbinb2a62622015-09-04 12:09:49 -0500110#if ENV_BOOTBLOCK
Julius Wernerec5e5e02014-08-20 15:29:56 -0700111 #define BOOTBLOCK(addr, sz) \
Julius Werner862c3852016-02-18 15:46:15 -0800112 SYMBOL(bootblock, addr) \
113 _ebootblock = _bootblock + sz; \
Aaron Durbinb2a62622015-09-04 12:09:49 -0500114 _ = ASSERT(_eprogram - _program <= sz, \
Julius Wernerec5e5e02014-08-20 15:29:56 -0700115 STR(Bootblock exceeded its allotted size! (sz))); \
Nico Huber98fc4262016-01-23 01:24:33 +0100116 INCLUDE "bootblock/lib/program.ld"
Julius Wernerec5e5e02014-08-20 15:29:56 -0700117#else
118 #define BOOTBLOCK(addr, sz) \
Julius Werner862c3852016-02-18 15:46:15 -0800119 REGION(bootblock, addr, sz, 1)
Julius Wernerec5e5e02014-08-20 15:29:56 -0700120#endif
121
Aaron Durbinb2a62622015-09-04 12:09:49 -0500122#if ENV_ROMSTAGE
Julius Wernerec5e5e02014-08-20 15:29:56 -0700123 #define ROMSTAGE(addr, sz) \
Julius Werner862c3852016-02-18 15:46:15 -0800124 SYMBOL(romstage, addr) \
125 _eromstage = _romstage + sz; \
Aaron Durbinb2a62622015-09-04 12:09:49 -0500126 _ = ASSERT(_eprogram - _program <= sz, \
Julius Wernerec5e5e02014-08-20 15:29:56 -0700127 STR(Romstage exceeded its allotted size! (sz))); \
Nico Huber98fc4262016-01-23 01:24:33 +0100128 INCLUDE "romstage/lib/program.ld"
Julius Wernerec5e5e02014-08-20 15:29:56 -0700129#else
130 #define ROMSTAGE(addr, sz) \
Julius Werner862c3852016-02-18 15:46:15 -0800131 REGION(romstage, addr, sz, 1)
Julius Wernerec5e5e02014-08-20 15:29:56 -0700132#endif
133
Aaron Durbin4de29d42015-09-03 22:49:36 -0500134#if ENV_RAMSTAGE
Julius Wernerec5e5e02014-08-20 15:29:56 -0700135 #define RAMSTAGE(addr, sz) \
Julius Werner862c3852016-02-18 15:46:15 -0800136 SYMBOL(ramstage, addr) \
137 _eramstage = _ramstage + sz; \
Aaron Durbin4de29d42015-09-03 22:49:36 -0500138 _ = ASSERT(_eprogram - _program <= sz, \
Julius Wernerec5e5e02014-08-20 15:29:56 -0700139 STR(Ramstage exceeded its allotted size! (sz))); \
Nico Huber98fc4262016-01-23 01:24:33 +0100140 INCLUDE "ramstage/lib/program.ld"
Julius Wernerec5e5e02014-08-20 15:29:56 -0700141#else
142 #define RAMSTAGE(addr, sz) \
Julius Werner862c3852016-02-18 15:46:15 -0800143 REGION(ramstage, addr, sz, 1)
Julius Wernerec5e5e02014-08-20 15:29:56 -0700144#endif
145
Joel Kitching0097f552019-02-21 12:36:55 +0800146/* VBOOT2_WORK must always use VB2_FIRMWARE_WORKBUF_RECOMMENDED_SIZE for its
147 * size argument. The constant is imported via vb2_workbuf_size.h. */
148#define VBOOT2_WORK(addr, sz) \
149 REGION(vboot2_work, addr, sz, 16) \
150 _ = ASSERT(sz == VB2_FIRMWARE_WORKBUF_RECOMMENDED_SIZE, \
151 STR(vboot2 work buffer size must be equivalent to \
152 VB2_FIRMWARE_WORKBUF_RECOMMENDED_SIZE! (sz)));
Aaron Durbine5bad5c2015-09-05 10:27:12 -0500153
Bill XIEc79e96b2019-08-22 20:28:36 +0800154#define TPM_TCPA_LOG(addr, size) \
155 REGION(tpm_tcpa_log, addr, size, 16) \
156 _ = ASSERT(size >= 2K, "tpm tcpa log buffer must be at least 2K!");
Philipp Deppenwiesec9b7d1f2018-11-10 00:35:02 +0100157
Julius Werner21a40532020-04-21 16:03:53 -0700158#if ENV_SEPARATE_VERSTAGE
Aaron Durbine5bad5c2015-09-05 10:27:12 -0500159 #define VERSTAGE(addr, sz) \
Julius Werner862c3852016-02-18 15:46:15 -0800160 SYMBOL(verstage, addr) \
161 _everstage = _verstage + sz; \
Aaron Durbine5bad5c2015-09-05 10:27:12 -0500162 _ = ASSERT(_eprogram - _program <= sz, \
163 STR(Verstage exceeded its allotted size! (sz))); \
Nico Huber98fc4262016-01-23 01:24:33 +0100164 INCLUDE "verstage/lib/program.ld"
Aaron Durbine5bad5c2015-09-05 10:27:12 -0500165
Julius Werner73d042b2017-03-17 16:54:48 -0700166 #define OVERLAP_VERSTAGE_ROMSTAGE(addr, size) \
Julius Wernercd49cce2019-03-05 16:53:33 -0800167 _ = ASSERT(CONFIG(VBOOT_RETURN_FROM_VERSTAGE) == 1, \
Julius Werner73d042b2017-03-17 16:54:48 -0700168 "Must set RETURN_FROM_VERSTAGE to overlap romstage."); \
169 VERSTAGE(addr, size)
Aaron Durbine5bad5c2015-09-05 10:27:12 -0500170#else
171 #define VERSTAGE(addr, sz) \
Julius Werner862c3852016-02-18 15:46:15 -0800172 REGION(verstage, addr, sz, 1)
Aaron Durbine5bad5c2015-09-05 10:27:12 -0500173
174 #define OVERLAP_VERSTAGE_ROMSTAGE(addr, size) ROMSTAGE(addr, size)
175#endif
176
Aaron Durbin7f8afe02016-03-18 12:21:23 -0500177#if ENV_POSTCAR
178 #define POSTCAR(addr, sz) \
179 SYMBOL(postcar, addr) \
180 _epostcar = _postcar + sz; \
181 _ = ASSERT(_eprogram - _program <= sz, \
182 STR(Aftercar exceeded its allotted size! (sz))); \
183 INCLUDE "postcar/lib/program.ld"
184#else
185 #define POSTCAR(addr, sz) \
186 REGION(postcar, addr, sz, 1)
187#endif
188
Aaron Durbine5bad5c2015-09-05 10:27:12 -0500189#define WATCHDOG_TOMBSTONE(addr, size) \
190 REGION(watchdog_tombstone, addr, size, 4) \
191 _ = ASSERT(size == 4, "watchdog tombstones should be exactly 4 byte!");
192
Julius Wernerec5e5e02014-08-20 15:29:56 -0700193#endif /* __MEMLAYOUT_H */