Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright 2014 Google Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | /* This file contains macro definitions for memlayout.ld linker scripts. */ |
| 17 | |
| 18 | #ifndef __MEMLAYOUT_H |
| 19 | #define __MEMLAYOUT_H |
| 20 | |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 21 | #include <rules.h> |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 22 | #include <arch/memlayout.h> |
| 23 | |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 24 | /* Macros that the architecture can override. */ |
| 25 | #ifndef ARCH_POINTER_ALIGN_SIZE |
| 26 | #define ARCH_POINTER_ALIGN_SIZE 8 |
| 27 | #endif |
| 28 | |
| 29 | #ifndef ARCH_CACHELINE_ALIGN_SIZE |
| 30 | #define ARCH_CACHELINE_ALIGN_SIZE 64 |
| 31 | #endif |
| 32 | |
| 33 | /* Default to data as well as bss. */ |
| 34 | #ifndef ARCH_STAGE_HAS_DATA_SECTION |
| 35 | #define ARCH_STAGE_HAS_DATA_SECTION 1 |
| 36 | #endif |
| 37 | |
| 38 | #ifndef ARCH_STAGE_HAS_BSS_SECTION |
| 39 | #define ARCH_STAGE_HAS_BSS_SECTION 1 |
| 40 | #endif |
| 41 | |
Aaron Durbin | dde7629 | 2015-09-05 12:59:26 -0500 | [diff] [blame] | 42 | /* Default is that currently ramstage, smm, and rmodules have a heap. */ |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 43 | #ifndef ARCH_STAGE_HAS_HEAP_SECTION |
Aaron Durbin | dde7629 | 2015-09-05 12:59:26 -0500 | [diff] [blame] | 44 | #define ARCH_STAGE_HAS_HEAP_SECTION (ENV_RAMSTAGE || ENV_SMM || ENV_RMODULE) |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 45 | #endif |
| 46 | |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 47 | #define STR(x) #x |
| 48 | |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 49 | #define ALIGN_COUNTER(align) \ |
| 50 | . = ALIGN(align); |
| 51 | |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 52 | #define SET_COUNTER(name, addr) \ |
| 53 | _ = ASSERT(. <= addr, STR(name overlaps the previous region!)); \ |
| 54 | . = addr; |
| 55 | |
| 56 | #define SYMBOL(name, addr) \ |
| 57 | SET_COUNTER(name, addr) \ |
| 58 | _##name = .; |
| 59 | |
| 60 | #define REGION(name, addr, size, expected_align) \ |
| 61 | SYMBOL(name, addr) \ |
| 62 | _ = ASSERT(. == ALIGN(expected_align), \ |
| 63 | STR(name must be aligned to expected_align!)); \ |
| 64 | SYMBOL(e##name, addr + size) |
| 65 | |
Julius Werner | 757943c | 2015-12-16 16:07:39 -0800 | [diff] [blame] | 66 | #define ALIAS_REGION(name, alias) \ |
| 67 | _##alias = _##name; \ |
| 68 | _e##alias = _e##name; |
| 69 | |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 70 | /* Declare according to SRAM/DRAM ranges in SoC hardware-defined address map. */ |
| 71 | #define SRAM_START(addr) SYMBOL(sram, addr) |
| 72 | |
| 73 | #define SRAM_END(addr) SYMBOL(esram, addr) |
| 74 | |
| 75 | #define DRAM_START(addr) SYMBOL(dram, addr) |
| 76 | |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 77 | #define TIMESTAMP(addr, size) \ |
Julius Werner | 85b1aad | 2016-08-19 15:17:42 -0700 | [diff] [blame^] | 78 | REGION(timestamp, addr, size, 8) \ |
| 79 | _ = ASSERT(size >= 212, "Timestamp region must fit timestamp_cache!"); |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 80 | |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 81 | #define PRERAM_CBMEM_CONSOLE(addr, size) \ |
| 82 | REGION(preram_cbmem_console, addr, size, 4) |
| 83 | |
| 84 | /* Use either CBFS_CACHE (unified) or both (PRERAM|POSTRAM)_CBFS_CACHE */ |
Julius Werner | 757943c | 2015-12-16 16:07:39 -0800 | [diff] [blame] | 85 | #define CBFS_CACHE(addr, size) \ |
| 86 | REGION(cbfs_cache, addr, size, 4) \ |
| 87 | ALIAS_REGION(cbfs_cache, preram_cbfs_cache) \ |
| 88 | ALIAS_REGION(cbfs_cache, postram_cbfs_cache) |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 89 | |
Julius Werner | 757943c | 2015-12-16 16:07:39 -0800 | [diff] [blame] | 90 | #if defined(__PRE_RAM__) |
| 91 | #define PRERAM_CBFS_CACHE(addr, size) \ |
| 92 | REGION(preram_cbfs_cache, addr, size, 4) \ |
| 93 | ALIAS_REGION(preram_cbfs_cache, cbfs_cache) |
Mary Ruthven | f82e8ab | 2015-11-13 14:05:27 -0800 | [diff] [blame] | 94 | #define POSTRAM_CBFS_CACHE(addr, size) \ |
Mary Ruthven | a8aef3a | 2015-11-24 09:43:27 -0800 | [diff] [blame] | 95 | REGION(postram_cbfs_cache, addr, size, 4) |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 96 | #else |
| 97 | #define PRERAM_CBFS_CACHE(addr, size) \ |
Julius Werner | 757943c | 2015-12-16 16:07:39 -0800 | [diff] [blame] | 98 | REGION(preram_cbfs_cache, addr, size, 4) |
| 99 | #define POSTRAM_CBFS_CACHE(addr, size) \ |
| 100 | REGION(postram_cbfs_cache, addr, size, 4) \ |
| 101 | ALIAS_REGION(postram_cbfs_cache, cbfs_cache) |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 102 | #endif |
| 103 | |
| 104 | /* Careful: 'INCLUDE <filename>' must always be at the end of the output line */ |
Aaron Durbin | b2a6262 | 2015-09-04 12:09:49 -0500 | [diff] [blame] | 105 | #if ENV_BOOTBLOCK |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 106 | #define BOOTBLOCK(addr, sz) \ |
Julius Werner | 862c385 | 2016-02-18 15:46:15 -0800 | [diff] [blame] | 107 | SYMBOL(bootblock, addr) \ |
| 108 | _ebootblock = _bootblock + sz; \ |
Aaron Durbin | b2a6262 | 2015-09-04 12:09:49 -0500 | [diff] [blame] | 109 | _ = ASSERT(_eprogram - _program <= sz, \ |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 110 | STR(Bootblock exceeded its allotted size! (sz))); \ |
Nico Huber | 98fc426 | 2016-01-23 01:24:33 +0100 | [diff] [blame] | 111 | INCLUDE "bootblock/lib/program.ld" |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 112 | #else |
| 113 | #define BOOTBLOCK(addr, sz) \ |
Julius Werner | 862c385 | 2016-02-18 15:46:15 -0800 | [diff] [blame] | 114 | REGION(bootblock, addr, sz, 1) |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 115 | #endif |
| 116 | |
Aaron Durbin | b2a6262 | 2015-09-04 12:09:49 -0500 | [diff] [blame] | 117 | #if ENV_ROMSTAGE |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 118 | #define ROMSTAGE(addr, sz) \ |
Julius Werner | 862c385 | 2016-02-18 15:46:15 -0800 | [diff] [blame] | 119 | SYMBOL(romstage, addr) \ |
| 120 | _eromstage = _romstage + sz; \ |
Aaron Durbin | b2a6262 | 2015-09-04 12:09:49 -0500 | [diff] [blame] | 121 | _ = ASSERT(_eprogram - _program <= sz, \ |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 122 | STR(Romstage exceeded its allotted size! (sz))); \ |
Nico Huber | 98fc426 | 2016-01-23 01:24:33 +0100 | [diff] [blame] | 123 | INCLUDE "romstage/lib/program.ld" |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 124 | #else |
| 125 | #define ROMSTAGE(addr, sz) \ |
Julius Werner | 862c385 | 2016-02-18 15:46:15 -0800 | [diff] [blame] | 126 | REGION(romstage, addr, sz, 1) |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 127 | #endif |
| 128 | |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 129 | #if ENV_RAMSTAGE |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 130 | #define RAMSTAGE(addr, sz) \ |
Julius Werner | 862c385 | 2016-02-18 15:46:15 -0800 | [diff] [blame] | 131 | SYMBOL(ramstage, addr) \ |
| 132 | _eramstage = _ramstage + sz; \ |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 133 | _ = ASSERT(_eprogram - _program <= sz, \ |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 134 | STR(Ramstage exceeded its allotted size! (sz))); \ |
Nico Huber | 98fc426 | 2016-01-23 01:24:33 +0100 | [diff] [blame] | 135 | INCLUDE "ramstage/lib/program.ld" |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 136 | #else |
| 137 | #define RAMSTAGE(addr, sz) \ |
Julius Werner | 862c385 | 2016-02-18 15:46:15 -0800 | [diff] [blame] | 138 | REGION(ramstage, addr, sz, 1) |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 139 | #endif |
| 140 | |
Aaron Durbin | e5bad5c | 2015-09-05 10:27:12 -0500 | [diff] [blame] | 141 | /* Careful: required work buffer size depends on RW properties such as key size |
| 142 | * and algorithm -- what works for you might stop working after an update. Do |
| 143 | * NOT lower the asserted minimum without consulting vboot devs (rspangler)! */ |
| 144 | #define VBOOT2_WORK(addr, size) \ |
| 145 | REGION(vboot2_work, addr, size, 16) \ |
| 146 | _ = ASSERT(size >= 12K, "vboot2 work buffer must be at least 12K!"); |
| 147 | |
| 148 | #if ENV_VERSTAGE |
| 149 | #define VERSTAGE(addr, sz) \ |
Julius Werner | 862c385 | 2016-02-18 15:46:15 -0800 | [diff] [blame] | 150 | SYMBOL(verstage, addr) \ |
| 151 | _everstage = _verstage + sz; \ |
Aaron Durbin | e5bad5c | 2015-09-05 10:27:12 -0500 | [diff] [blame] | 152 | _ = ASSERT(_eprogram - _program <= sz, \ |
| 153 | STR(Verstage exceeded its allotted size! (sz))); \ |
Nico Huber | 98fc426 | 2016-01-23 01:24:33 +0100 | [diff] [blame] | 154 | INCLUDE "verstage/lib/program.ld" |
Aaron Durbin | e5bad5c | 2015-09-05 10:27:12 -0500 | [diff] [blame] | 155 | |
| 156 | #define OVERLAP_VERSTAGE_ROMSTAGE(addr, size) VERSTAGE(addr, size) |
| 157 | #else |
| 158 | #define VERSTAGE(addr, sz) \ |
Julius Werner | 862c385 | 2016-02-18 15:46:15 -0800 | [diff] [blame] | 159 | REGION(verstage, addr, sz, 1) |
Aaron Durbin | e5bad5c | 2015-09-05 10:27:12 -0500 | [diff] [blame] | 160 | |
| 161 | #define OVERLAP_VERSTAGE_ROMSTAGE(addr, size) ROMSTAGE(addr, size) |
| 162 | #endif |
| 163 | |
Aaron Durbin | 7f8afe0 | 2016-03-18 12:21:23 -0500 | [diff] [blame] | 164 | #if ENV_POSTCAR |
| 165 | #define POSTCAR(addr, sz) \ |
| 166 | SYMBOL(postcar, addr) \ |
| 167 | _epostcar = _postcar + sz; \ |
| 168 | _ = ASSERT(_eprogram - _program <= sz, \ |
| 169 | STR(Aftercar exceeded its allotted size! (sz))); \ |
| 170 | INCLUDE "postcar/lib/program.ld" |
| 171 | #else |
| 172 | #define POSTCAR(addr, sz) \ |
| 173 | REGION(postcar, addr, sz, 1) |
| 174 | #endif |
| 175 | |
Aaron Durbin | e5bad5c | 2015-09-05 10:27:12 -0500 | [diff] [blame] | 176 | #define WATCHDOG_TOMBSTONE(addr, size) \ |
| 177 | REGION(watchdog_tombstone, addr, size, 4) \ |
| 178 | _ = ASSERT(size == 4, "watchdog tombstones should be exactly 4 byte!"); |
| 179 | |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 180 | #endif /* __MEMLAYOUT_H */ |