blob: 09be615eff9cb32fced55d0197d23012a6069d3e [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.
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 Georgib890a122015-03-26 15:17:45 +010017 * Foundation, Inc.
Julius Wernerec5e5e02014-08-20 15:29:56 -070018 */
19
20/* This file contains macro definitions for memlayout.ld linker scripts. */
21
22#ifndef __MEMLAYOUT_H
23#define __MEMLAYOUT_H
24
Aaron Durbin4de29d42015-09-03 22:49:36 -050025#include <rules.h>
Julius Wernerec5e5e02014-08-20 15:29:56 -070026#include <arch/memlayout.h>
27
Aaron Durbin4de29d42015-09-03 22:49:36 -050028/* 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
Aaron Durbindde76292015-09-05 12:59:26 -050046/* Default is that currently ramstage, smm, and rmodules have a heap. */
Aaron Durbin4de29d42015-09-03 22:49:36 -050047#ifndef ARCH_STAGE_HAS_HEAP_SECTION
Aaron Durbindde76292015-09-05 12:59:26 -050048#define ARCH_STAGE_HAS_HEAP_SECTION (ENV_RAMSTAGE || ENV_SMM || ENV_RMODULE)
Aaron Durbin4de29d42015-09-03 22:49:36 -050049#endif
50
Julius Wernerec5e5e02014-08-20 15:29:56 -070051#define STR(x) #x
52
Aaron Durbin4de29d42015-09-03 22:49:36 -050053#define ALIGN_COUNTER(align) \
54 . = ALIGN(align);
55
Julius Wernerec5e5e02014-08-20 15:29:56 -070056#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 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 */
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 Durbin4de29d42015-09-03 22:49:36 -050088#if defined(__PRE_RAM__) && !ENV_ROMSTAGE
Julius Wernerec5e5e02014-08-20 15:29:56 -070089 #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 Durbinb2a62622015-09-04 12:09:49 -050099#if ENV_BOOTBLOCK
Julius Wernerec5e5e02014-08-20 15:29:56 -0700100 #define BOOTBLOCK(addr, sz) \
101 SET_COUNTER(bootblock, addr) \
Aaron Durbinb2a62622015-09-04 12:09:49 -0500102 _ = ASSERT(_eprogram - _program <= sz, \
Julius Wernerec5e5e02014-08-20 15:29:56 -0700103 STR(Bootblock exceeded its allotted size! (sz))); \
Aaron Durbinb2a62622015-09-04 12:09:49 -0500104 INCLUDE "lib/program.bootblock.ld"
Julius Wernerec5e5e02014-08-20 15:29:56 -0700105#else
106 #define BOOTBLOCK(addr, sz) \
107 SET_COUNTER(bootblock, addr) \
108 . += sz;
109#endif
110
Aaron Durbinb2a62622015-09-04 12:09:49 -0500111#if ENV_ROMSTAGE
Julius Wernerec5e5e02014-08-20 15:29:56 -0700112 #define ROMSTAGE(addr, sz) \
113 SET_COUNTER(romstage, addr) \
Aaron Durbinb2a62622015-09-04 12:09:49 -0500114 _ = ASSERT(_eprogram - _program <= sz, \
Julius Wernerec5e5e02014-08-20 15:29:56 -0700115 STR(Romstage exceeded its allotted size! (sz))); \
Aaron Durbinb2a62622015-09-04 12:09:49 -0500116 INCLUDE "lib/program.romstage.ld"
Julius Wernerec5e5e02014-08-20 15:29:56 -0700117#else
118 #define ROMSTAGE(addr, sz) \
119 SET_COUNTER(romstage, addr) \
120 . += sz;
121#endif
122
Aaron Durbin4de29d42015-09-03 22:49:36 -0500123#if ENV_RAMSTAGE
Julius Wernerec5e5e02014-08-20 15:29:56 -0700124 #define RAMSTAGE(addr, sz) \
125 SET_COUNTER(ramstage, addr) \
Aaron Durbin4de29d42015-09-03 22:49:36 -0500126 _ = ASSERT(_eprogram - _program <= sz, \
Julius Wernerec5e5e02014-08-20 15:29:56 -0700127 STR(Ramstage exceeded its allotted size! (sz))); \
Aaron Durbin4de29d42015-09-03 22:49:36 -0500128 INCLUDE "lib/program.ramstage.ld"
Julius Wernerec5e5e02014-08-20 15:29:56 -0700129#else
130 #define RAMSTAGE(addr, sz) \
131 SET_COUNTER(ramstage, addr) \
132 . += sz;
133#endif
134
Aaron Durbine5bad5c2015-09-05 10:27:12 -0500135/* 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 Wernerec5e5e02014-08-20 15:29:56 -0700162#endif /* __MEMLAYOUT_H */