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) \ |
| 78 | REGION(timestamp, addr, size, 8) |
| 79 | |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 80 | #define PRERAM_CBMEM_CONSOLE(addr, size) \ |
| 81 | REGION(preram_cbmem_console, addr, size, 4) |
| 82 | |
| 83 | /* Use either CBFS_CACHE (unified) or both (PRERAM|POSTRAM)_CBFS_CACHE */ |
Julius Werner | 757943c | 2015-12-16 16:07:39 -0800 | [diff] [blame] | 84 | #define CBFS_CACHE(addr, size) \ |
| 85 | REGION(cbfs_cache, addr, size, 4) \ |
| 86 | ALIAS_REGION(cbfs_cache, preram_cbfs_cache) \ |
| 87 | ALIAS_REGION(cbfs_cache, postram_cbfs_cache) |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 88 | |
Julius Werner | 757943c | 2015-12-16 16:07:39 -0800 | [diff] [blame] | 89 | #if defined(__PRE_RAM__) |
| 90 | #define PRERAM_CBFS_CACHE(addr, size) \ |
| 91 | REGION(preram_cbfs_cache, addr, size, 4) \ |
| 92 | ALIAS_REGION(preram_cbfs_cache, cbfs_cache) |
Mary Ruthven | f82e8ab | 2015-11-13 14:05:27 -0800 | [diff] [blame] | 93 | #define POSTRAM_CBFS_CACHE(addr, size) \ |
Mary Ruthven | a8aef3a | 2015-11-24 09:43:27 -0800 | [diff] [blame] | 94 | REGION(postram_cbfs_cache, addr, size, 4) |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 95 | #else |
| 96 | #define PRERAM_CBFS_CACHE(addr, size) \ |
Julius Werner | 757943c | 2015-12-16 16:07:39 -0800 | [diff] [blame] | 97 | REGION(preram_cbfs_cache, addr, size, 4) |
| 98 | #define POSTRAM_CBFS_CACHE(addr, size) \ |
| 99 | REGION(postram_cbfs_cache, addr, size, 4) \ |
| 100 | ALIAS_REGION(postram_cbfs_cache, cbfs_cache) |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 101 | #endif |
| 102 | |
| 103 | /* 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] | 104 | #if ENV_BOOTBLOCK |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 105 | #define BOOTBLOCK(addr, sz) \ |
Julius Werner | 862c385 | 2016-02-18 15:46:15 -0800 | [diff] [blame] | 106 | SYMBOL(bootblock, addr) \ |
| 107 | _ebootblock = _bootblock + sz; \ |
Aaron Durbin | b2a6262 | 2015-09-04 12:09:49 -0500 | [diff] [blame] | 108 | _ = ASSERT(_eprogram - _program <= sz, \ |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 109 | STR(Bootblock exceeded its allotted size! (sz))); \ |
Nico Huber | 98fc426 | 2016-01-23 01:24:33 +0100 | [diff] [blame] | 110 | INCLUDE "bootblock/lib/program.ld" |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 111 | #else |
| 112 | #define BOOTBLOCK(addr, sz) \ |
Julius Werner | 862c385 | 2016-02-18 15:46:15 -0800 | [diff] [blame] | 113 | REGION(bootblock, addr, sz, 1) |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 114 | #endif |
| 115 | |
Aaron Durbin | b2a6262 | 2015-09-04 12:09:49 -0500 | [diff] [blame] | 116 | #if ENV_ROMSTAGE |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 117 | #define ROMSTAGE(addr, sz) \ |
Julius Werner | 862c385 | 2016-02-18 15:46:15 -0800 | [diff] [blame] | 118 | SYMBOL(romstage, addr) \ |
| 119 | _eromstage = _romstage + sz; \ |
Aaron Durbin | b2a6262 | 2015-09-04 12:09:49 -0500 | [diff] [blame] | 120 | _ = ASSERT(_eprogram - _program <= sz, \ |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 121 | STR(Romstage exceeded its allotted size! (sz))); \ |
Nico Huber | 98fc426 | 2016-01-23 01:24:33 +0100 | [diff] [blame] | 122 | INCLUDE "romstage/lib/program.ld" |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 123 | #else |
| 124 | #define ROMSTAGE(addr, sz) \ |
Julius Werner | 862c385 | 2016-02-18 15:46:15 -0800 | [diff] [blame] | 125 | REGION(romstage, addr, sz, 1) |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 126 | #endif |
| 127 | |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 128 | #if ENV_RAMSTAGE |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 129 | #define RAMSTAGE(addr, sz) \ |
Julius Werner | 862c385 | 2016-02-18 15:46:15 -0800 | [diff] [blame] | 130 | SYMBOL(ramstage, addr) \ |
| 131 | _eramstage = _ramstage + sz; \ |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 132 | _ = ASSERT(_eprogram - _program <= sz, \ |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 133 | STR(Ramstage exceeded its allotted size! (sz))); \ |
Nico Huber | 98fc426 | 2016-01-23 01:24:33 +0100 | [diff] [blame] | 134 | INCLUDE "ramstage/lib/program.ld" |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 135 | #else |
| 136 | #define RAMSTAGE(addr, sz) \ |
Julius Werner | 862c385 | 2016-02-18 15:46:15 -0800 | [diff] [blame] | 137 | REGION(ramstage, addr, sz, 1) |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 138 | #endif |
| 139 | |
Aaron Durbin | e5bad5c | 2015-09-05 10:27:12 -0500 | [diff] [blame] | 140 | /* Careful: required work buffer size depends on RW properties such as key size |
| 141 | * and algorithm -- what works for you might stop working after an update. Do |
| 142 | * NOT lower the asserted minimum without consulting vboot devs (rspangler)! */ |
| 143 | #define VBOOT2_WORK(addr, size) \ |
| 144 | REGION(vboot2_work, addr, size, 16) \ |
| 145 | _ = ASSERT(size >= 12K, "vboot2 work buffer must be at least 12K!"); |
| 146 | |
| 147 | #if ENV_VERSTAGE |
| 148 | #define VERSTAGE(addr, sz) \ |
Julius Werner | 862c385 | 2016-02-18 15:46:15 -0800 | [diff] [blame] | 149 | SYMBOL(verstage, addr) \ |
| 150 | _everstage = _verstage + sz; \ |
Aaron Durbin | e5bad5c | 2015-09-05 10:27:12 -0500 | [diff] [blame] | 151 | _ = ASSERT(_eprogram - _program <= sz, \ |
| 152 | STR(Verstage exceeded its allotted size! (sz))); \ |
Nico Huber | 98fc426 | 2016-01-23 01:24:33 +0100 | [diff] [blame] | 153 | INCLUDE "verstage/lib/program.ld" |
Aaron Durbin | e5bad5c | 2015-09-05 10:27:12 -0500 | [diff] [blame] | 154 | |
| 155 | #define OVERLAP_VERSTAGE_ROMSTAGE(addr, size) VERSTAGE(addr, size) |
| 156 | #else |
| 157 | #define VERSTAGE(addr, sz) \ |
Julius Werner | 862c385 | 2016-02-18 15:46:15 -0800 | [diff] [blame] | 158 | REGION(verstage, addr, sz, 1) |
Aaron Durbin | e5bad5c | 2015-09-05 10:27:12 -0500 | [diff] [blame] | 159 | |
| 160 | #define OVERLAP_VERSTAGE_ROMSTAGE(addr, size) ROMSTAGE(addr, size) |
| 161 | #endif |
| 162 | |
Aaron Durbin | 7f8afe0 | 2016-03-18 12:21:23 -0500 | [diff] [blame^] | 163 | #if ENV_POSTCAR |
| 164 | #define POSTCAR(addr, sz) \ |
| 165 | SYMBOL(postcar, addr) \ |
| 166 | _epostcar = _postcar + sz; \ |
| 167 | _ = ASSERT(_eprogram - _program <= sz, \ |
| 168 | STR(Aftercar exceeded its allotted size! (sz))); \ |
| 169 | INCLUDE "postcar/lib/program.ld" |
| 170 | #else |
| 171 | #define POSTCAR(addr, sz) \ |
| 172 | REGION(postcar, addr, sz, 1) |
| 173 | #endif |
| 174 | |
Aaron Durbin | e5bad5c | 2015-09-05 10:27:12 -0500 | [diff] [blame] | 175 | #define WATCHDOG_TOMBSTONE(addr, size) \ |
| 176 | REGION(watchdog_tombstone, addr, size, 4) \ |
| 177 | _ = ASSERT(size == 4, "watchdog tombstones should be exactly 4 byte!"); |
| 178 | |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 179 | #endif /* __MEMLAYOUT_H */ |