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. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
Patrick Georgi | b890a12 | 2015-03-26 15:17:45 +0100 | [diff] [blame] | 17 | * Foundation, Inc. |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | /* This file contains macro definitions for memlayout.ld linker scripts. */ |
| 21 | |
| 22 | #ifndef __MEMLAYOUT_H |
| 23 | #define __MEMLAYOUT_H |
| 24 | |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 25 | #include <rules.h> |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 26 | #include <arch/memlayout.h> |
| 27 | |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 28 | /* Macros that the architecture can override. */ |
| 29 | #ifndef ARCH_POINTER_ALIGN_SIZE |
| 30 | #define ARCH_POINTER_ALIGN_SIZE 8 |
| 31 | #endif |
| 32 | |
| 33 | #ifndef ARCH_CACHELINE_ALIGN_SIZE |
| 34 | #define ARCH_CACHELINE_ALIGN_SIZE 64 |
| 35 | #endif |
| 36 | |
| 37 | /* Default to data as well as bss. */ |
| 38 | #ifndef ARCH_STAGE_HAS_DATA_SECTION |
| 39 | #define ARCH_STAGE_HAS_DATA_SECTION 1 |
| 40 | #endif |
| 41 | |
| 42 | #ifndef ARCH_STAGE_HAS_BSS_SECTION |
| 43 | #define ARCH_STAGE_HAS_BSS_SECTION 1 |
| 44 | #endif |
| 45 | |
| 46 | /* Default is that currently ramstage and smm only has a heap. */ |
| 47 | #ifndef ARCH_STAGE_HAS_HEAP_SECTION |
| 48 | #define ARCH_STAGE_HAS_HEAP_SECTION (ENV_RAMSTAGE || ENV_SMM) |
| 49 | #endif |
| 50 | |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 51 | #define STR(x) #x |
| 52 | |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 53 | #define ALIGN_COUNTER(align) \ |
| 54 | . = ALIGN(align); |
| 55 | |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 56 | #define SET_COUNTER(name, addr) \ |
| 57 | _ = ASSERT(. <= addr, STR(name overlaps the previous region!)); \ |
| 58 | . = addr; |
| 59 | |
| 60 | #define SYMBOL(name, addr) \ |
| 61 | SET_COUNTER(name, addr) \ |
| 62 | _##name = .; |
| 63 | |
| 64 | #define REGION(name, addr, size, expected_align) \ |
| 65 | SYMBOL(name, addr) \ |
| 66 | _ = ASSERT(. == ALIGN(expected_align), \ |
| 67 | STR(name must be aligned to expected_align!)); \ |
| 68 | SYMBOL(e##name, addr + size) |
| 69 | |
| 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 */ |
| 84 | #define CBFS_CACHE(addr, size) REGION(cbfs_cache, addr, size, 4) |
| 85 | |
| 86 | /* TODO: This only works if you never access CBFS in romstage before RAM is up! |
| 87 | * If you need to change that assumption, you have some work ahead of you... */ |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 88 | #if defined(__PRE_RAM__) && !ENV_ROMSTAGE |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 89 | #define PRERAM_CBFS_CACHE(addr, size) CBFS_CACHE(addr, size) |
| 90 | #define POSTRAM_CBFS_CACHE(addr, size) \ |
| 91 | REGION(unused_cbfs_cache, addr, size, 4) |
| 92 | #else |
| 93 | #define PRERAM_CBFS_CACHE(addr, size) \ |
| 94 | REGION(unused_cbfs_cache, addr, size, 4) |
| 95 | #define POSTRAM_CBFS_CACHE(addr, size) CBFS_CACHE(addr, size) |
| 96 | #endif |
| 97 | |
| 98 | /* 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] | 99 | #if ENV_BOOTBLOCK |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 100 | #define BOOTBLOCK(addr, sz) \ |
| 101 | SET_COUNTER(bootblock, addr) \ |
Aaron Durbin | b2a6262 | 2015-09-04 12:09:49 -0500 | [diff] [blame] | 102 | _ = ASSERT(_eprogram - _program <= sz, \ |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 103 | STR(Bootblock exceeded its allotted size! (sz))); \ |
Aaron Durbin | b2a6262 | 2015-09-04 12:09:49 -0500 | [diff] [blame] | 104 | INCLUDE "lib/program.bootblock.ld" |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 105 | #else |
| 106 | #define BOOTBLOCK(addr, sz) \ |
| 107 | SET_COUNTER(bootblock, addr) \ |
| 108 | . += sz; |
| 109 | #endif |
| 110 | |
Aaron Durbin | b2a6262 | 2015-09-04 12:09:49 -0500 | [diff] [blame] | 111 | #if ENV_ROMSTAGE |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 112 | #define ROMSTAGE(addr, sz) \ |
| 113 | SET_COUNTER(romstage, addr) \ |
Aaron Durbin | b2a6262 | 2015-09-04 12:09:49 -0500 | [diff] [blame] | 114 | _ = ASSERT(_eprogram - _program <= sz, \ |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 115 | STR(Romstage exceeded its allotted size! (sz))); \ |
Aaron Durbin | b2a6262 | 2015-09-04 12:09:49 -0500 | [diff] [blame] | 116 | INCLUDE "lib/program.romstage.ld" |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 117 | #else |
| 118 | #define ROMSTAGE(addr, sz) \ |
| 119 | SET_COUNTER(romstage, addr) \ |
| 120 | . += sz; |
| 121 | #endif |
| 122 | |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 123 | #if ENV_RAMSTAGE |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 124 | #define RAMSTAGE(addr, sz) \ |
| 125 | SET_COUNTER(ramstage, addr) \ |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 126 | _ = ASSERT(_eprogram - _program <= sz, \ |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 127 | STR(Ramstage exceeded its allotted size! (sz))); \ |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 128 | INCLUDE "lib/program.ramstage.ld" |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 129 | #else |
| 130 | #define RAMSTAGE(addr, sz) \ |
| 131 | SET_COUNTER(ramstage, addr) \ |
| 132 | . += sz; |
| 133 | #endif |
| 134 | |
Aaron Durbin | e5bad5c | 2015-09-05 10:27:12 -0500 | [diff] [blame^] | 135 | /* Careful: required work buffer size depends on RW properties such as key size |
| 136 | * and algorithm -- what works for you might stop working after an update. Do |
| 137 | * NOT lower the asserted minimum without consulting vboot devs (rspangler)! */ |
| 138 | #define VBOOT2_WORK(addr, size) \ |
| 139 | REGION(vboot2_work, addr, size, 16) \ |
| 140 | _ = ASSERT(size >= 12K, "vboot2 work buffer must be at least 12K!"); |
| 141 | |
| 142 | #if ENV_VERSTAGE |
| 143 | #define VERSTAGE(addr, sz) \ |
| 144 | SET_COUNTER(verstage, addr) \ |
| 145 | _ = ASSERT(_eprogram - _program <= sz, \ |
| 146 | STR(Verstage exceeded its allotted size! (sz))); \ |
| 147 | INCLUDE "lib/program.verstage.ld" |
| 148 | |
| 149 | #define OVERLAP_VERSTAGE_ROMSTAGE(addr, size) VERSTAGE(addr, size) |
| 150 | #else |
| 151 | #define VERSTAGE(addr, sz) \ |
| 152 | SET_COUNTER(verstage, addr) \ |
| 153 | . += sz; |
| 154 | |
| 155 | #define OVERLAP_VERSTAGE_ROMSTAGE(addr, size) ROMSTAGE(addr, size) |
| 156 | #endif |
| 157 | |
| 158 | #define WATCHDOG_TOMBSTONE(addr, size) \ |
| 159 | REGION(watchdog_tombstone, addr, size, 4) \ |
| 160 | _ = ASSERT(size == 4, "watchdog tombstones should be exactly 4 byte!"); |
| 161 | |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 162 | #endif /* __MEMLAYOUT_H */ |