Angel Pons | 32859fc | 2020-04-02 23:48:27 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 2 | |
| 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 Kitching | 0097f55 | 2019-02-21 12:36:55 +0800 | [diff] [blame] | 9 | #include <vb2_constants.h> |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 10 | |
Julius Werner | cefe89e | 2019-11-06 19:29:44 -0800 | [diff] [blame] | 11 | #include "fmap_config.h" |
| 12 | |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 13 | /* 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 Werner | cefe89e | 2019-11-06 19:29:44 -0800 | [diff] [blame] | 22 | #define STR(x) XSTR(x) |
| 23 | #define XSTR(x) #x |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 24 | |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 25 | #define ALIGN_COUNTER(align) \ |
| 26 | . = ALIGN(align); |
| 27 | |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 28 | #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 Werner | 757943c | 2015-12-16 16:07:39 -0800 | [diff] [blame] | 42 | #define ALIAS_REGION(name, alias) \ |
| 43 | _##alias = _##name; \ |
| 44 | _e##alias = _e##name; |
| 45 | |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 46 | /* 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 Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 53 | #define TIMESTAMP(addr, size) \ |
Julius Werner | 85b1aad | 2016-08-19 15:17:42 -0700 | [diff] [blame] | 54 | REGION(timestamp, addr, size, 8) \ |
| 55 | _ = ASSERT(size >= 212, "Timestamp region must fit timestamp_cache!"); |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 56 | |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 57 | #define PRERAM_CBMEM_CONSOLE(addr, size) \ |
| 58 | REGION(preram_cbmem_console, addr, size, 4) |
| 59 | |
Felix Held | ca928c6 | 2020-04-04 01:47:37 +0200 | [diff] [blame] | 60 | #define EARLYRAM_STACK(addr, size) \ |
| 61 | REGION(earlyram_stack, addr, size, ARCH_STACK_ALIGN_SIZE) |
| 62 | |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 63 | /* Use either CBFS_CACHE (unified) or both (PRERAM|POSTRAM)_CBFS_CACHE */ |
Julius Werner | 757943c | 2015-12-16 16:07:39 -0800 | [diff] [blame] | 64 | #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 Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 68 | |
Julius Werner | cefe89e | 2019-11-06 19:29:44 -0800 | [diff] [blame] | 69 | #define FMAP_CACHE(addr, sz) \ |
| 70 | REGION(fmap_cache, addr, sz, 4) \ |
Julius Werner | 8245bd2 | 2019-12-04 20:32:15 -0800 | [diff] [blame] | 71 | _ = ASSERT(sz >= FMAP_SIZE, \ |
Julius Werner | cefe89e | 2019-11-06 19:29:44 -0800 | [diff] [blame] | 72 | STR(FMAP does not fit in FMAP_CACHE! (sz < FMAP_SIZE))); |
| 73 | |
Julius Werner | 1e37c9c | 2019-12-11 17:09:39 -0800 | [diff] [blame] | 74 | #define CBFS_MCACHE(addr, sz) \ |
| 75 | REGION(cbfs_mcache, addr, sz, 4) |
| 76 | |
Kyösti Mälkki | e3acc8f | 2019-09-13 10:49:20 +0300 | [diff] [blame] | 77 | #if ENV_ROMSTAGE_OR_BEFORE |
Julius Werner | 757943c | 2015-12-16 16:07:39 -0800 | [diff] [blame] | 78 | #define PRERAM_CBFS_CACHE(addr, size) \ |
| 79 | REGION(preram_cbfs_cache, addr, size, 4) \ |
| 80 | ALIAS_REGION(preram_cbfs_cache, cbfs_cache) |
Mary Ruthven | f82e8ab | 2015-11-13 14:05:27 -0800 | [diff] [blame] | 81 | #define POSTRAM_CBFS_CACHE(addr, size) \ |
Mary Ruthven | a8aef3a | 2015-11-24 09:43:27 -0800 | [diff] [blame] | 82 | REGION(postram_cbfs_cache, addr, size, 4) |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 83 | #else |
| 84 | #define PRERAM_CBFS_CACHE(addr, size) \ |
Julius Werner | 757943c | 2015-12-16 16:07:39 -0800 | [diff] [blame] | 85 | REGION(preram_cbfs_cache, addr, size, 4) |
| 86 | #define POSTRAM_CBFS_CACHE(addr, size) \ |
| 87 | REGION(postram_cbfs_cache, addr, size, 4) \ |
| 88 | ALIAS_REGION(postram_cbfs_cache, cbfs_cache) |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 89 | #endif |
| 90 | |
| 91 | /* Careful: 'INCLUDE <filename>' must always be at the end of the output line */ |
Julius Werner | 99f4683 | 2018-05-16 14:14:04 -0700 | [diff] [blame] | 92 | #if ENV_DECOMPRESSOR |
| 93 | #define DECOMPRESSOR(addr, sz) \ |
| 94 | SYMBOL(decompressor, addr) \ |
| 95 | _edecompressor = _decompressor + sz; \ |
| 96 | _ = ASSERT(_eprogram - _program <= sz, \ |
| 97 | STR(decompressor exceeded its allotted size! (sz))); \ |
| 98 | INCLUDE "decompressor/lib/program.ld" |
| 99 | |
| 100 | #define OVERLAP_DECOMPRESSOR_ROMSTAGE(addr, sz) DECOMPRESSOR(addr, sz) |
| 101 | #define OVERLAP_DECOMPRESSOR_VERSTAGE_ROMSTAGE(addr, sz) \ |
| 102 | DECOMPRESSOR(addr, sz) |
| 103 | #else |
| 104 | #define DECOMPRESSOR(addr, sz) \ |
| 105 | REGION(decompressor, addr, sz, 1) |
| 106 | |
| 107 | #define OVERLAP_DECOMPRESSOR_ROMSTAGE(addr, sz) ROMSTAGE(addr, sz) |
| 108 | #define OVERLAP_DECOMPRESSOR_VERSTAGE_ROMSTAGE(addr, sz) \ |
| 109 | OVERLAP_VERSTAGE_ROMSTAGE(addr, sz) |
| 110 | #endif |
| 111 | |
Aaron Durbin | b2a6262 | 2015-09-04 12:09:49 -0500 | [diff] [blame] | 112 | #if ENV_BOOTBLOCK |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 113 | #define BOOTBLOCK(addr, sz) \ |
Julius Werner | 862c385 | 2016-02-18 15:46:15 -0800 | [diff] [blame] | 114 | SYMBOL(bootblock, addr) \ |
| 115 | _ebootblock = _bootblock + sz; \ |
Aaron Durbin | b2a6262 | 2015-09-04 12:09:49 -0500 | [diff] [blame] | 116 | _ = ASSERT(_eprogram - _program <= sz, \ |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 117 | STR(Bootblock exceeded its allotted size! (sz))); \ |
Nico Huber | 98fc426 | 2016-01-23 01:24:33 +0100 | [diff] [blame] | 118 | INCLUDE "bootblock/lib/program.ld" |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 119 | #else |
| 120 | #define BOOTBLOCK(addr, sz) \ |
Julius Werner | 862c385 | 2016-02-18 15:46:15 -0800 | [diff] [blame] | 121 | REGION(bootblock, addr, sz, 1) |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 122 | #endif |
| 123 | |
Aaron Durbin | b2a6262 | 2015-09-04 12:09:49 -0500 | [diff] [blame] | 124 | #if ENV_ROMSTAGE |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 125 | #define ROMSTAGE(addr, sz) \ |
Julius Werner | 862c385 | 2016-02-18 15:46:15 -0800 | [diff] [blame] | 126 | SYMBOL(romstage, addr) \ |
| 127 | _eromstage = _romstage + sz; \ |
Aaron Durbin | b2a6262 | 2015-09-04 12:09:49 -0500 | [diff] [blame] | 128 | _ = ASSERT(_eprogram - _program <= sz, \ |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 129 | STR(Romstage exceeded its allotted size! (sz))); \ |
Nico Huber | 98fc426 | 2016-01-23 01:24:33 +0100 | [diff] [blame] | 130 | INCLUDE "romstage/lib/program.ld" |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 131 | #else |
| 132 | #define ROMSTAGE(addr, sz) \ |
Julius Werner | 862c385 | 2016-02-18 15:46:15 -0800 | [diff] [blame] | 133 | REGION(romstage, addr, sz, 1) |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 134 | #endif |
| 135 | |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 136 | #if ENV_RAMSTAGE |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 137 | #define RAMSTAGE(addr, sz) \ |
Julius Werner | 862c385 | 2016-02-18 15:46:15 -0800 | [diff] [blame] | 138 | SYMBOL(ramstage, addr) \ |
| 139 | _eramstage = _ramstage + sz; \ |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 140 | _ = ASSERT(_eprogram - _program <= sz, \ |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 141 | STR(Ramstage exceeded its allotted size! (sz))); \ |
Nico Huber | 98fc426 | 2016-01-23 01:24:33 +0100 | [diff] [blame] | 142 | INCLUDE "ramstage/lib/program.ld" |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 143 | #else |
| 144 | #define RAMSTAGE(addr, sz) \ |
Julius Werner | 862c385 | 2016-02-18 15:46:15 -0800 | [diff] [blame] | 145 | REGION(ramstage, addr, sz, 1) |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 146 | #endif |
| 147 | |
Joel Kitching | 0097f55 | 2019-02-21 12:36:55 +0800 | [diff] [blame] | 148 | /* VBOOT2_WORK must always use VB2_FIRMWARE_WORKBUF_RECOMMENDED_SIZE for its |
| 149 | * size argument. The constant is imported via vb2_workbuf_size.h. */ |
| 150 | #define VBOOT2_WORK(addr, sz) \ |
| 151 | REGION(vboot2_work, addr, sz, 16) \ |
| 152 | _ = ASSERT(sz == VB2_FIRMWARE_WORKBUF_RECOMMENDED_SIZE, \ |
| 153 | STR(vboot2 work buffer size must be equivalent to \ |
| 154 | VB2_FIRMWARE_WORKBUF_RECOMMENDED_SIZE! (sz))); |
Aaron Durbin | e5bad5c | 2015-09-05 10:27:12 -0500 | [diff] [blame] | 155 | |
Bill XIE | c79e96b | 2019-08-22 20:28:36 +0800 | [diff] [blame] | 156 | #define TPM_TCPA_LOG(addr, size) \ |
| 157 | REGION(tpm_tcpa_log, addr, size, 16) \ |
| 158 | _ = ASSERT(size >= 2K, "tpm tcpa log buffer must be at least 2K!"); |
Philipp Deppenwiese | c9b7d1f | 2018-11-10 00:35:02 +0100 | [diff] [blame] | 159 | |
Julius Werner | 21a4053 | 2020-04-21 16:03:53 -0700 | [diff] [blame] | 160 | #if ENV_SEPARATE_VERSTAGE |
Aaron Durbin | e5bad5c | 2015-09-05 10:27:12 -0500 | [diff] [blame] | 161 | #define VERSTAGE(addr, sz) \ |
Julius Werner | 862c385 | 2016-02-18 15:46:15 -0800 | [diff] [blame] | 162 | SYMBOL(verstage, addr) \ |
| 163 | _everstage = _verstage + sz; \ |
Aaron Durbin | e5bad5c | 2015-09-05 10:27:12 -0500 | [diff] [blame] | 164 | _ = ASSERT(_eprogram - _program <= sz, \ |
| 165 | STR(Verstage exceeded its allotted size! (sz))); \ |
Nico Huber | 98fc426 | 2016-01-23 01:24:33 +0100 | [diff] [blame] | 166 | INCLUDE "verstage/lib/program.ld" |
Aaron Durbin | e5bad5c | 2015-09-05 10:27:12 -0500 | [diff] [blame] | 167 | |
Julius Werner | 73d042b | 2017-03-17 16:54:48 -0700 | [diff] [blame] | 168 | #define OVERLAP_VERSTAGE_ROMSTAGE(addr, size) \ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 169 | _ = ASSERT(CONFIG(VBOOT_RETURN_FROM_VERSTAGE) == 1, \ |
Julius Werner | 73d042b | 2017-03-17 16:54:48 -0700 | [diff] [blame] | 170 | "Must set RETURN_FROM_VERSTAGE to overlap romstage."); \ |
| 171 | VERSTAGE(addr, size) |
Aaron Durbin | e5bad5c | 2015-09-05 10:27:12 -0500 | [diff] [blame] | 172 | #else |
| 173 | #define VERSTAGE(addr, sz) \ |
Julius Werner | 862c385 | 2016-02-18 15:46:15 -0800 | [diff] [blame] | 174 | REGION(verstage, addr, sz, 1) |
Aaron Durbin | e5bad5c | 2015-09-05 10:27:12 -0500 | [diff] [blame] | 175 | |
| 176 | #define OVERLAP_VERSTAGE_ROMSTAGE(addr, size) ROMSTAGE(addr, size) |
| 177 | #endif |
| 178 | |
Aaron Durbin | 7f8afe0 | 2016-03-18 12:21:23 -0500 | [diff] [blame] | 179 | #if ENV_POSTCAR |
| 180 | #define POSTCAR(addr, sz) \ |
| 181 | SYMBOL(postcar, addr) \ |
| 182 | _epostcar = _postcar + sz; \ |
| 183 | _ = ASSERT(_eprogram - _program <= sz, \ |
| 184 | STR(Aftercar exceeded its allotted size! (sz))); \ |
| 185 | INCLUDE "postcar/lib/program.ld" |
| 186 | #else |
| 187 | #define POSTCAR(addr, sz) \ |
| 188 | REGION(postcar, addr, sz, 1) |
| 189 | #endif |
| 190 | |
Aaron Durbin | e5bad5c | 2015-09-05 10:27:12 -0500 | [diff] [blame] | 191 | #define WATCHDOG_TOMBSTONE(addr, size) \ |
| 192 | REGION(watchdog_tombstone, addr, size, 4) \ |
| 193 | _ = ASSERT(size == 4, "watchdog tombstones should be exactly 4 byte!"); |
| 194 | |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 195 | #endif /* __MEMLAYOUT_H */ |