blob: a68b21f4d69409c2e6020a38889e43f3b71ed120 [file] [log] [blame]
Julius Wernerec5e5e02014-08-20 15:29:56 -07001/*
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 Wernerec5e5e02014-08-20 15:29:56 -070014 */
15
16/* This file contains macro definitions for memlayout.ld linker scripts. */
17
18#ifndef __MEMLAYOUT_H
19#define __MEMLAYOUT_H
20
Aaron Durbin4de29d42015-09-03 22:49:36 -050021#include <rules.h>
Julius Wernerec5e5e02014-08-20 15:29:56 -070022#include <arch/memlayout.h>
23
Aaron Durbin4de29d42015-09-03 22:49:36 -050024/* 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 Durbindde76292015-09-05 12:59:26 -050042/* Default is that currently ramstage, smm, and rmodules have a heap. */
Aaron Durbin4de29d42015-09-03 22:49:36 -050043#ifndef ARCH_STAGE_HAS_HEAP_SECTION
Aaron Durbindde76292015-09-05 12:59:26 -050044#define ARCH_STAGE_HAS_HEAP_SECTION (ENV_RAMSTAGE || ENV_SMM || ENV_RMODULE)
Aaron Durbin4de29d42015-09-03 22:49:36 -050045#endif
46
Julius Wernerec5e5e02014-08-20 15:29:56 -070047#define STR(x) #x
48
Aaron Durbin4de29d42015-09-03 22:49:36 -050049#define ALIGN_COUNTER(align) \
50 . = ALIGN(align);
51
Julius Wernerec5e5e02014-08-20 15:29:56 -070052#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 Werner757943c2015-12-16 16:07:39 -080066#define ALIAS_REGION(name, alias) \
67 _##alias = _##name; \
68 _e##alias = _e##name;
69
Julius Wernerec5e5e02014-08-20 15:29:56 -070070/* 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 Durbin1936f6c2015-07-03 17:04:21 -050077#define TIMESTAMP(addr, size) \
Julius Werner85b1aad2016-08-19 15:17:42 -070078 REGION(timestamp, addr, size, 8) \
79 _ = ASSERT(size >= 212, "Timestamp region must fit timestamp_cache!");
Aaron Durbin1936f6c2015-07-03 17:04:21 -050080
Julius Wernerec5e5e02014-08-20 15:29:56 -070081#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 Werner757943c2015-12-16 16:07:39 -080085#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 Wernerec5e5e02014-08-20 15:29:56 -070089
Julius Werner757943c2015-12-16 16:07:39 -080090#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 Ruthvenf82e8ab2015-11-13 14:05:27 -080094 #define POSTRAM_CBFS_CACHE(addr, size) \
Mary Ruthvena8aef3a2015-11-24 09:43:27 -080095 REGION(postram_cbfs_cache, addr, size, 4)
Julius Wernerec5e5e02014-08-20 15:29:56 -070096#else
97 #define PRERAM_CBFS_CACHE(addr, size) \
Julius Werner757943c2015-12-16 16:07:39 -080098 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 Wernerec5e5e02014-08-20 15:29:56 -0700102#endif
103
104/* Careful: 'INCLUDE <filename>' must always be at the end of the output line */
Aaron Durbinb2a62622015-09-04 12:09:49 -0500105#if ENV_BOOTBLOCK
Julius Wernerec5e5e02014-08-20 15:29:56 -0700106 #define BOOTBLOCK(addr, sz) \
Julius Werner862c3852016-02-18 15:46:15 -0800107 SYMBOL(bootblock, addr) \
108 _ebootblock = _bootblock + sz; \
Aaron Durbinb2a62622015-09-04 12:09:49 -0500109 _ = ASSERT(_eprogram - _program <= sz, \
Julius Wernerec5e5e02014-08-20 15:29:56 -0700110 STR(Bootblock exceeded its allotted size! (sz))); \
Nico Huber98fc4262016-01-23 01:24:33 +0100111 INCLUDE "bootblock/lib/program.ld"
Julius Wernerec5e5e02014-08-20 15:29:56 -0700112#else
113 #define BOOTBLOCK(addr, sz) \
Julius Werner862c3852016-02-18 15:46:15 -0800114 REGION(bootblock, addr, sz, 1)
Julius Wernerec5e5e02014-08-20 15:29:56 -0700115#endif
116
Aaron Durbinb2a62622015-09-04 12:09:49 -0500117#if ENV_ROMSTAGE
Julius Wernerec5e5e02014-08-20 15:29:56 -0700118 #define ROMSTAGE(addr, sz) \
Julius Werner862c3852016-02-18 15:46:15 -0800119 SYMBOL(romstage, addr) \
120 _eromstage = _romstage + sz; \
Aaron Durbinb2a62622015-09-04 12:09:49 -0500121 _ = ASSERT(_eprogram - _program <= sz, \
Julius Wernerec5e5e02014-08-20 15:29:56 -0700122 STR(Romstage exceeded its allotted size! (sz))); \
Nico Huber98fc4262016-01-23 01:24:33 +0100123 INCLUDE "romstage/lib/program.ld"
Julius Wernerec5e5e02014-08-20 15:29:56 -0700124#else
125 #define ROMSTAGE(addr, sz) \
Julius Werner862c3852016-02-18 15:46:15 -0800126 REGION(romstage, addr, sz, 1)
Julius Wernerec5e5e02014-08-20 15:29:56 -0700127#endif
128
Aaron Durbin4de29d42015-09-03 22:49:36 -0500129#if ENV_RAMSTAGE
Julius Wernerec5e5e02014-08-20 15:29:56 -0700130 #define RAMSTAGE(addr, sz) \
Julius Werner862c3852016-02-18 15:46:15 -0800131 SYMBOL(ramstage, addr) \
132 _eramstage = _ramstage + sz; \
Aaron Durbin4de29d42015-09-03 22:49:36 -0500133 _ = ASSERT(_eprogram - _program <= sz, \
Julius Wernerec5e5e02014-08-20 15:29:56 -0700134 STR(Ramstage exceeded its allotted size! (sz))); \
Nico Huber98fc4262016-01-23 01:24:33 +0100135 INCLUDE "ramstage/lib/program.ld"
Julius Wernerec5e5e02014-08-20 15:29:56 -0700136#else
137 #define RAMSTAGE(addr, sz) \
Julius Werner862c3852016-02-18 15:46:15 -0800138 REGION(ramstage, addr, sz, 1)
Julius Wernerec5e5e02014-08-20 15:29:56 -0700139#endif
140
Aaron Durbine5bad5c2015-09-05 10:27:12 -0500141/* 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 Werner862c3852016-02-18 15:46:15 -0800150 SYMBOL(verstage, addr) \
151 _everstage = _verstage + sz; \
Aaron Durbine5bad5c2015-09-05 10:27:12 -0500152 _ = ASSERT(_eprogram - _program <= sz, \
153 STR(Verstage exceeded its allotted size! (sz))); \
Nico Huber98fc4262016-01-23 01:24:33 +0100154 INCLUDE "verstage/lib/program.ld"
Aaron Durbine5bad5c2015-09-05 10:27:12 -0500155
156 #define OVERLAP_VERSTAGE_ROMSTAGE(addr, size) VERSTAGE(addr, size)
157#else
158 #define VERSTAGE(addr, sz) \
Julius Werner862c3852016-02-18 15:46:15 -0800159 REGION(verstage, addr, sz, 1)
Aaron Durbine5bad5c2015-09-05 10:27:12 -0500160
161 #define OVERLAP_VERSTAGE_ROMSTAGE(addr, size) ROMSTAGE(addr, size)
162#endif
163
Aaron Durbin7f8afe02016-03-18 12:21:23 -0500164#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 Durbine5bad5c2015-09-05 10:27:12 -0500176#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 Wernerec5e5e02014-08-20 15:29:56 -0700180#endif /* __MEMLAYOUT_H */