blob: 3178bc4893490f1321226823434df975fec81c14 [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
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 Durbin1936f6c2015-07-03 17:04:21 -050073#define TIMESTAMP(addr, size) \
74 REGION(timestamp, addr, size, 8)
75
Julius Wernerec5e5e02014-08-20 15:29:56 -070076#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 Ruthvenf82e8ab2015-11-13 14:05:27 -080082#if ENV_ROMSTAGE
83 #define PRERAM_CBFS_CACHE(addr, size) CBFS_CACHE(addr, size)
84 #define POSTRAM_CBFS_CACHE(addr, size) \
Mary Ruthvena8aef3a2015-11-24 09:43:27 -080085 REGION(postram_cbfs_cache, addr, size, 4)
Mary Ruthvenf82e8ab2015-11-13 14:05:27 -080086#elif defined(__PRE_RAM__)
Julius Wernerec5e5e02014-08-20 15:29:56 -070087 #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 Durbinb2a62622015-09-04 12:09:49 -050097#if ENV_BOOTBLOCK
Julius Wernerec5e5e02014-08-20 15:29:56 -070098 #define BOOTBLOCK(addr, sz) \
99 SET_COUNTER(bootblock, addr) \
Aaron Durbinb2a62622015-09-04 12:09:49 -0500100 _ = ASSERT(_eprogram - _program <= sz, \
Julius Wernerec5e5e02014-08-20 15:29:56 -0700101 STR(Bootblock exceeded its allotted size! (sz))); \
Aaron Durbinb2a62622015-09-04 12:09:49 -0500102 INCLUDE "lib/program.bootblock.ld"
Julius Wernerec5e5e02014-08-20 15:29:56 -0700103#else
104 #define BOOTBLOCK(addr, sz) \
105 SET_COUNTER(bootblock, addr) \
106 . += sz;
107#endif
108
Aaron Durbinb2a62622015-09-04 12:09:49 -0500109#if ENV_ROMSTAGE
Julius Wernerec5e5e02014-08-20 15:29:56 -0700110 #define ROMSTAGE(addr, sz) \
111 SET_COUNTER(romstage, addr) \
Aaron Durbinb2a62622015-09-04 12:09:49 -0500112 _ = ASSERT(_eprogram - _program <= sz, \
Julius Wernerec5e5e02014-08-20 15:29:56 -0700113 STR(Romstage exceeded its allotted size! (sz))); \
Aaron Durbinb2a62622015-09-04 12:09:49 -0500114 INCLUDE "lib/program.romstage.ld"
Julius Wernerec5e5e02014-08-20 15:29:56 -0700115#else
116 #define ROMSTAGE(addr, sz) \
117 SET_COUNTER(romstage, addr) \
118 . += sz;
119#endif
120
Aaron Durbin4de29d42015-09-03 22:49:36 -0500121#if ENV_RAMSTAGE
Julius Wernerec5e5e02014-08-20 15:29:56 -0700122 #define RAMSTAGE(addr, sz) \
123 SET_COUNTER(ramstage, addr) \
Aaron Durbin4de29d42015-09-03 22:49:36 -0500124 _ = ASSERT(_eprogram - _program <= sz, \
Julius Wernerec5e5e02014-08-20 15:29:56 -0700125 STR(Ramstage exceeded its allotted size! (sz))); \
Aaron Durbin4de29d42015-09-03 22:49:36 -0500126 INCLUDE "lib/program.ramstage.ld"
Julius Wernerec5e5e02014-08-20 15:29:56 -0700127#else
128 #define RAMSTAGE(addr, sz) \
129 SET_COUNTER(ramstage, addr) \
130 . += sz;
131#endif
132
Aaron Durbine5bad5c2015-09-05 10:27:12 -0500133/* 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 Wernerec5e5e02014-08-20 15:29:56 -0700160#endif /* __MEMLAYOUT_H */