1 /* SPDX-License-Identifier: GPL-2.0-only */
3 /* This file contains macro definitions for memlayout.ld linker scripts. */
8 #include <arch/memlayout.h>
9 #include <vb2_constants.h>
11 #include "fmap_config.h"
13 /* Macros that the architecture can override. */
14 #ifndef ARCH_POINTER_ALIGN_SIZE
15 #define ARCH_POINTER_ALIGN_SIZE 8
18 #ifndef ARCH_CACHELINE_ALIGN_SIZE
19 #define ARCH_CACHELINE_ALIGN_SIZE 64
22 #define STR(x) XSTR(x)
25 #define ALIGN_COUNTER(align) \
28 #define SET_COUNTER(name, addr) \
29 _ = ASSERT(. <= addr, STR(name overlaps the previous region!)); \
32 #define SYMBOL(name, addr) \
33 SET_COUNTER(name, addr) \
34 _##name = ABSOLUTE(.);
36 #define RECORD_SIZE(name) \
37 _##name##_size = ABSOLUTE(_e##name - _##name);
39 #define REGION(name, addr, size, expected_align) \
41 _ = ASSERT(. == ALIGN(expected_align), \
42 STR(name must be aligned to expected_align!)); \
43 SYMBOL(e##name, addr + size) \
46 #define ALIAS_REGION(name, alias) \
47 _##alias = ABSOLUTE(_##name); \
48 _e##alias = ABSOLUTE(_e##name); \
51 #define REGION_START(name, addr) SYMBOL(name, addr)
53 #define REGION_END(name, addr) \
54 SYMBOL(e##name, addr) \
57 /* Declare according to SRAM/DRAM ranges in SoC hardware-defined address map. */
58 #define SRAM_START(addr) REGION_START(sram, addr)
60 #define SRAM_END(addr) REGION_END(sram, addr)
62 #define DRAM_START(addr) REGION_START(dram, addr)
64 #define TIMESTAMP(addr, size) \
65 REGION(timestamp, addr, size, 8) \
66 _ = ASSERT(size >= 212, "Timestamp region must fit timestamp_cache!");
68 #define PRERAM_CBMEM_CONSOLE(addr, size) \
69 REGION(preram_cbmem_console, addr, size, 4)
71 #define EARLYRAM_STACK(addr, size) \
72 REGION(earlyram_stack, addr, size, ARCH_STACK_ALIGN_SIZE)
74 /* Use either CBFS_CACHE (unified) or both (PRERAM|POSTRAM)_CBFS_CACHE */
75 #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)
80 #define FMAP_CACHE(addr, sz) \
81 REGION(fmap_cache, addr, sz, 4) \
82 _ = ASSERT(sz >= FMAP_SIZE, \
83 STR(FMAP does not fit in FMAP_CACHE! (sz < FMAP_SIZE)));
85 #define CBFS_MCACHE(addr, sz) \
86 REGION(cbfs_mcache, addr, sz, 4)
88 #if ENV_ROMSTAGE_OR_BEFORE
89 #define PRERAM_CBFS_CACHE(addr, size) \
90 REGION(preram_cbfs_cache, addr, size, 4) \
91 ALIAS_REGION(preram_cbfs_cache, cbfs_cache)
92 #define POSTRAM_CBFS_CACHE(addr, size) \
93 REGION(postram_cbfs_cache, addr, size, 4)
95 #define PRERAM_CBFS_CACHE(addr, size) \
96 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)
102 /* Careful: 'INCLUDE <filename>' must always be at the end of the output line */
104 #define DECOMPRESSOR(addr, sz) \
105 SYMBOL(decompressor, addr) \
106 _edecompressor = ABSOLUTE(_decompressor + sz); \
107 RECORD_SIZE(decompressor) \
108 _ = ASSERT(_eprogram - _program <= sz, \
109 STR(decompressor exceeded its allotted size! (sz))); \
110 INCLUDE "decompressor/lib/program.ld"
112 #define OVERLAP_DECOMPRESSOR_ROMSTAGE(addr, sz) DECOMPRESSOR(addr, sz)
113 #define OVERLAP_DECOMPRESSOR_VERSTAGE_ROMSTAGE(addr, sz) \
114 DECOMPRESSOR(addr, sz)
116 #define DECOMPRESSOR(addr, sz) \
117 REGION(decompressor, addr, sz, 1)
119 #define OVERLAP_DECOMPRESSOR_ROMSTAGE(addr, sz) ROMSTAGE(addr, sz)
120 #define OVERLAP_DECOMPRESSOR_VERSTAGE_ROMSTAGE(addr, sz) \
121 OVERLAP_VERSTAGE_ROMSTAGE(addr, sz)
125 #define BOOTBLOCK(addr, sz) \
126 SYMBOL(bootblock, addr) \
127 _ebootblock = ABSOLUTE(_bootblock + sz); \
128 RECORD_SIZE(bootblock) \
129 _ = ASSERT(_eprogram - _program <= sz, \
130 STR(Bootblock exceeded its allotted size! (sz))); \
131 INCLUDE "bootblock/lib/program.ld"
133 #define BOOTBLOCK(addr, sz) \
134 REGION(bootblock, addr, sz, 1)
138 #define ROMSTAGE(addr, sz) \
139 SYMBOL(romstage, addr) \
140 _eromstage = ABSOLUTE(_romstage + sz); \
141 RECORD_SIZE(romstage) \
142 _ = ASSERT(_eprogram - _program <= sz, \
143 STR(Romstage exceeded its allotted size! (sz))); \
144 INCLUDE "romstage/lib/program.ld"
146 #define ROMSTAGE(addr, sz) \
147 REGION(romstage, addr, sz, 1)
151 #define RAMSTAGE(addr, sz) \
152 SYMBOL(ramstage, addr) \
153 _eramstage = ABSOLUTE(_ramstage + sz); \
154 RECORD_SIZE(ramstage) \
155 _ = ASSERT(_eprogram - _program <= sz, \
156 STR(Ramstage exceeded its allotted size! (sz))); \
157 INCLUDE "ramstage/lib/program.ld"
159 #define RAMSTAGE(addr, sz) \
160 REGION(ramstage, addr, sz, 1)
163 /* VBOOT2_WORK must always use VB2_FIRMWARE_WORKBUF_RECOMMENDED_SIZE for its
164 * size argument. The constant is imported via vb2_workbuf_size.h. */
165 #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)));
171 #define TPM_TCPA_LOG(addr, size) \
172 REGION(tpm_tcpa_log, addr, size, 16) \
173 _ = ASSERT(size >= 2K, "tpm tcpa log buffer must be at least 2K!");
175 #if ENV_SEPARATE_VERSTAGE
176 #define VERSTAGE(addr, sz) \
177 SYMBOL(verstage, addr) \
178 _everstage = ABSOLUTE(_verstage + sz); \
179 RECORD_SIZE(verstage) \
180 _ = ASSERT(_eprogram - _program <= sz, \
181 STR(Verstage exceeded its allotted size! (sz))); \
182 INCLUDE "verstage/lib/program.ld"
184 #define OVERLAP_VERSTAGE_ROMSTAGE(addr, size) \
185 _ = ASSERT(CONFIG(VBOOT_RETURN_FROM_VERSTAGE) == 1, \
186 "Must set RETURN_FROM_VERSTAGE to overlap romstage."); \
189 #define VERSTAGE(addr, sz) \
190 REGION(verstage, addr, sz, 1)
192 #define OVERLAP_VERSTAGE_ROMSTAGE(addr, size) ROMSTAGE(addr, size)
196 #define POSTCAR(addr, sz) \
197 SYMBOL(postcar, addr) \
198 _epostcar = ABSOLUTE(_postcar + sz); \
199 RECORD_SIZE(postcar) \
200 _ = ASSERT(_eprogram - _program <= sz, \
201 STR(Aftercar exceeded its allotted size! (sz))); \
202 INCLUDE "postcar/lib/program.ld"
204 #define POSTCAR(addr, sz) \
205 REGION(postcar, addr, sz, 1)
208 #define WATCHDOG_TOMBSTONE(addr, size) \
209 REGION(watchdog_tombstone, addr, size, 4) \
210 _ = ASSERT(size == 4, "watchdog tombstones should be exactly 4 byte!");
212 #endif /* __MEMLAYOUT_H */