blob: 43a1caca75cd1b2d3347e037f0160cd52c778abe [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) \
78 REGION(timestamp, addr, size, 8)
79
Julius Wernerec5e5e02014-08-20 15:29:56 -070080#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 Werner757943c2015-12-16 16:07:39 -080084#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 Wernerec5e5e02014-08-20 15:29:56 -070088
Julius Werner757943c2015-12-16 16:07:39 -080089#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 Ruthvenf82e8ab2015-11-13 14:05:27 -080093 #define POSTRAM_CBFS_CACHE(addr, size) \
Mary Ruthvena8aef3a2015-11-24 09:43:27 -080094 REGION(postram_cbfs_cache, addr, size, 4)
Julius Wernerec5e5e02014-08-20 15:29:56 -070095#else
96 #define PRERAM_CBFS_CACHE(addr, size) \
Julius Werner757943c2015-12-16 16:07:39 -080097 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 Wernerec5e5e02014-08-20 15:29:56 -0700101#endif
102
103/* Careful: 'INCLUDE <filename>' must always be at the end of the output line */
Aaron Durbinb2a62622015-09-04 12:09:49 -0500104#if ENV_BOOTBLOCK
Julius Wernerec5e5e02014-08-20 15:29:56 -0700105 #define BOOTBLOCK(addr, sz) \
Julius Werner862c3852016-02-18 15:46:15 -0800106 SYMBOL(bootblock, addr) \
107 _ebootblock = _bootblock + sz; \
Aaron Durbinb2a62622015-09-04 12:09:49 -0500108 _ = ASSERT(_eprogram - _program <= sz, \
Julius Wernerec5e5e02014-08-20 15:29:56 -0700109 STR(Bootblock exceeded its allotted size! (sz))); \
Nico Huber98fc4262016-01-23 01:24:33 +0100110 INCLUDE "bootblock/lib/program.ld"
Julius Wernerec5e5e02014-08-20 15:29:56 -0700111#else
112 #define BOOTBLOCK(addr, sz) \
Julius Werner862c3852016-02-18 15:46:15 -0800113 REGION(bootblock, addr, sz, 1)
Julius Wernerec5e5e02014-08-20 15:29:56 -0700114#endif
115
Aaron Durbinb2a62622015-09-04 12:09:49 -0500116#if ENV_ROMSTAGE
Julius Wernerec5e5e02014-08-20 15:29:56 -0700117 #define ROMSTAGE(addr, sz) \
Julius Werner862c3852016-02-18 15:46:15 -0800118 SYMBOL(romstage, addr) \
119 _eromstage = _romstage + sz; \
Aaron Durbinb2a62622015-09-04 12:09:49 -0500120 _ = ASSERT(_eprogram - _program <= sz, \
Julius Wernerec5e5e02014-08-20 15:29:56 -0700121 STR(Romstage exceeded its allotted size! (sz))); \
Nico Huber98fc4262016-01-23 01:24:33 +0100122 INCLUDE "romstage/lib/program.ld"
Julius Wernerec5e5e02014-08-20 15:29:56 -0700123#else
124 #define ROMSTAGE(addr, sz) \
Julius Werner862c3852016-02-18 15:46:15 -0800125 REGION(romstage, addr, sz, 1)
Julius Wernerec5e5e02014-08-20 15:29:56 -0700126#endif
127
Aaron Durbin4de29d42015-09-03 22:49:36 -0500128#if ENV_RAMSTAGE
Julius Wernerec5e5e02014-08-20 15:29:56 -0700129 #define RAMSTAGE(addr, sz) \
Julius Werner862c3852016-02-18 15:46:15 -0800130 SYMBOL(ramstage, addr) \
131 _eramstage = _ramstage + sz; \
Aaron Durbin4de29d42015-09-03 22:49:36 -0500132 _ = ASSERT(_eprogram - _program <= sz, \
Julius Wernerec5e5e02014-08-20 15:29:56 -0700133 STR(Ramstage exceeded its allotted size! (sz))); \
Nico Huber98fc4262016-01-23 01:24:33 +0100134 INCLUDE "ramstage/lib/program.ld"
Julius Wernerec5e5e02014-08-20 15:29:56 -0700135#else
136 #define RAMSTAGE(addr, sz) \
Julius Werner862c3852016-02-18 15:46:15 -0800137 REGION(ramstage, addr, sz, 1)
Julius Wernerec5e5e02014-08-20 15:29:56 -0700138#endif
139
Aaron Durbine5bad5c2015-09-05 10:27:12 -0500140/* 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 Werner862c3852016-02-18 15:46:15 -0800149 SYMBOL(verstage, addr) \
150 _everstage = _verstage + sz; \
Aaron Durbine5bad5c2015-09-05 10:27:12 -0500151 _ = ASSERT(_eprogram - _program <= sz, \
152 STR(Verstage exceeded its allotted size! (sz))); \
Nico Huber98fc4262016-01-23 01:24:33 +0100153 INCLUDE "verstage/lib/program.ld"
Aaron Durbine5bad5c2015-09-05 10:27:12 -0500154
155 #define OVERLAP_VERSTAGE_ROMSTAGE(addr, size) VERSTAGE(addr, size)
156#else
157 #define VERSTAGE(addr, sz) \
Julius Werner862c3852016-02-18 15:46:15 -0800158 REGION(verstage, addr, sz, 1)
Aaron Durbine5bad5c2015-09-05 10:27:12 -0500159
160 #define OVERLAP_VERSTAGE_ROMSTAGE(addr, size) ROMSTAGE(addr, size)
161#endif
162
Aaron Durbin7f8afe02016-03-18 12:21:23 -0500163#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 Durbine5bad5c2015-09-05 10:27:12 -0500175#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 Wernerec5e5e02014-08-20 15:29:56 -0700179#endif /* __MEMLAYOUT_H */