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 | |
| 66 | /* Declare according to SRAM/DRAM ranges in SoC hardware-defined address map. */ |
| 67 | #define SRAM_START(addr) SYMBOL(sram, addr) |
| 68 | |
| 69 | #define SRAM_END(addr) SYMBOL(esram, addr) |
| 70 | |
| 71 | #define DRAM_START(addr) SYMBOL(dram, addr) |
| 72 | |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 73 | #define TIMESTAMP(addr, size) \ |
| 74 | REGION(timestamp, addr, size, 8) |
| 75 | |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 76 | #define PRERAM_CBMEM_CONSOLE(addr, size) \ |
| 77 | REGION(preram_cbmem_console, addr, size, 4) |
| 78 | |
| 79 | /* Use either CBFS_CACHE (unified) or both (PRERAM|POSTRAM)_CBFS_CACHE */ |
| 80 | #define CBFS_CACHE(addr, size) REGION(cbfs_cache, addr, size, 4) |
| 81 | |
Mary Ruthven | f82e8ab | 2015-11-13 14:05:27 -0800 | [diff] [blame] | 82 | #if ENV_ROMSTAGE |
| 83 | #define PRERAM_CBFS_CACHE(addr, size) CBFS_CACHE(addr, size) |
| 84 | #define POSTRAM_CBFS_CACHE(addr, size) \ |
| 85 | REGION(dram_cbfs_cache, addr, size, 4) |
| 86 | #elif defined(__PRE_RAM__) |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 87 | #define PRERAM_CBFS_CACHE(addr, size) CBFS_CACHE(addr, size) |
| 88 | #define POSTRAM_CBFS_CACHE(addr, size) \ |
| 89 | REGION(unused_cbfs_cache, addr, size, 4) |
| 90 | #else |
| 91 | #define PRERAM_CBFS_CACHE(addr, size) \ |
| 92 | REGION(unused_cbfs_cache, addr, size, 4) |
| 93 | #define POSTRAM_CBFS_CACHE(addr, size) CBFS_CACHE(addr, size) |
| 94 | #endif |
| 95 | |
| 96 | /* 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] | 97 | #if ENV_BOOTBLOCK |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 98 | #define BOOTBLOCK(addr, sz) \ |
| 99 | SET_COUNTER(bootblock, addr) \ |
Aaron Durbin | b2a6262 | 2015-09-04 12:09:49 -0500 | [diff] [blame] | 100 | _ = ASSERT(_eprogram - _program <= sz, \ |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 101 | STR(Bootblock exceeded its allotted size! (sz))); \ |
Aaron Durbin | b2a6262 | 2015-09-04 12:09:49 -0500 | [diff] [blame] | 102 | INCLUDE "lib/program.bootblock.ld" |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 103 | #else |
| 104 | #define BOOTBLOCK(addr, sz) \ |
| 105 | SET_COUNTER(bootblock, addr) \ |
| 106 | . += sz; |
| 107 | #endif |
| 108 | |
Aaron Durbin | b2a6262 | 2015-09-04 12:09:49 -0500 | [diff] [blame] | 109 | #if ENV_ROMSTAGE |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 110 | #define ROMSTAGE(addr, sz) \ |
| 111 | SET_COUNTER(romstage, addr) \ |
Aaron Durbin | b2a6262 | 2015-09-04 12:09:49 -0500 | [diff] [blame] | 112 | _ = ASSERT(_eprogram - _program <= sz, \ |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 113 | STR(Romstage exceeded its allotted size! (sz))); \ |
Aaron Durbin | b2a6262 | 2015-09-04 12:09:49 -0500 | [diff] [blame] | 114 | INCLUDE "lib/program.romstage.ld" |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 115 | #else |
| 116 | #define ROMSTAGE(addr, sz) \ |
| 117 | SET_COUNTER(romstage, addr) \ |
| 118 | . += sz; |
| 119 | #endif |
| 120 | |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 121 | #if ENV_RAMSTAGE |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 122 | #define RAMSTAGE(addr, sz) \ |
| 123 | SET_COUNTER(ramstage, addr) \ |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 124 | _ = ASSERT(_eprogram - _program <= sz, \ |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 125 | STR(Ramstage exceeded its allotted size! (sz))); \ |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 126 | INCLUDE "lib/program.ramstage.ld" |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 127 | #else |
| 128 | #define RAMSTAGE(addr, sz) \ |
| 129 | SET_COUNTER(ramstage, addr) \ |
| 130 | . += sz; |
| 131 | #endif |
| 132 | |
Aaron Durbin | e5bad5c | 2015-09-05 10:27:12 -0500 | [diff] [blame] | 133 | /* Careful: required work buffer size depends on RW properties such as key size |
| 134 | * and algorithm -- what works for you might stop working after an update. Do |
| 135 | * NOT lower the asserted minimum without consulting vboot devs (rspangler)! */ |
| 136 | #define VBOOT2_WORK(addr, size) \ |
| 137 | REGION(vboot2_work, addr, size, 16) \ |
| 138 | _ = ASSERT(size >= 12K, "vboot2 work buffer must be at least 12K!"); |
| 139 | |
| 140 | #if ENV_VERSTAGE |
| 141 | #define VERSTAGE(addr, sz) \ |
| 142 | SET_COUNTER(verstage, addr) \ |
| 143 | _ = ASSERT(_eprogram - _program <= sz, \ |
| 144 | STR(Verstage exceeded its allotted size! (sz))); \ |
| 145 | INCLUDE "lib/program.verstage.ld" |
| 146 | |
| 147 | #define OVERLAP_VERSTAGE_ROMSTAGE(addr, size) VERSTAGE(addr, size) |
| 148 | #else |
| 149 | #define VERSTAGE(addr, sz) \ |
| 150 | SET_COUNTER(verstage, addr) \ |
| 151 | . += sz; |
| 152 | |
| 153 | #define OVERLAP_VERSTAGE_ROMSTAGE(addr, size) ROMSTAGE(addr, size) |
| 154 | #endif |
| 155 | |
| 156 | #define WATCHDOG_TOMBSTONE(addr, size) \ |
| 157 | REGION(watchdog_tombstone, addr, size, 4) \ |
| 158 | _ = ASSERT(size == 4, "watchdog tombstones should be exactly 4 byte!"); |
| 159 | |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 160 | #endif /* __MEMLAYOUT_H */ |