blob: ec3d22d7d1d6c6b7419d21634a38cb61648becd9 [file] [log] [blame]
Angel Pons32859fc2020-04-02 23:48:27 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Kyösti Mälkkief844012013-06-25 23:17:43 +03002
Kyösti Mälkkie8792be2014-02-26 15:19:04 +02003#ifndef _RULES_H
4#define _RULES_H
5
Jakub Czapiga084ad932021-03-25 13:10:31 +01006#if defined(__TEST__)
7#define ENV_TEST 1
8#else
9#define ENV_TEST 0
10#endif
11
Angel Pons46451972020-06-08 15:52:03 +020012#if defined(__TIMELESS__)
13#define ENV_TIMELESS 1
14#else
15#define ENV_TIMELESS 0
16#endif
17
Kyösti Mälkkie8792be2014-02-26 15:19:04 +020018/* Useful helpers to tell whether the code is executing in bootblock,
19 * romstage, ramstage or SMM.
20 */
21
Julius Werner99f46832018-05-16 14:14:04 -070022#if defined(__DECOMPRESSOR__)
23#define ENV_DECOMPRESSOR 1
24#define ENV_BOOTBLOCK 0
25#define ENV_ROMSTAGE 0
26#define ENV_RAMSTAGE 0
27#define ENV_SMM 0
Julius Werner21a40532020-04-21 16:03:53 -070028#define ENV_SEPARATE_VERSTAGE 0
Julius Werner99f46832018-05-16 14:14:04 -070029#define ENV_RMODULE 0
30#define ENV_POSTCAR 0
31#define ENV_LIBAGESA 0
32#define ENV_STRING "decompressor"
33
34#elif defined(__BOOTBLOCK__)
35#define ENV_DECOMPRESSOR 0
Kyösti Mälkkie8792be2014-02-26 15:19:04 +020036#define ENV_BOOTBLOCK 1
37#define ENV_ROMSTAGE 0
38#define ENV_RAMSTAGE 0
39#define ENV_SMM 0
Julius Werner21a40532020-04-21 16:03:53 -070040#define ENV_SEPARATE_VERSTAGE 0
Aaron Durbindde76292015-09-05 12:59:26 -050041#define ENV_RMODULE 0
Aaron Durbin7f8afe02016-03-18 12:21:23 -050042#define ENV_POSTCAR 0
Kyösti Mälkkia405a582017-03-02 13:01:58 +020043#define ENV_LIBAGESA 0
Ben Gardneraa5f5b12015-11-19 10:48:47 -060044#define ENV_STRING "bootblock"
Kyösti Mälkkie8792be2014-02-26 15:19:04 +020045
Patrick Georgi815f4bf2015-04-28 22:43:31 +020046#elif defined(__ROMSTAGE__)
Julius Werner99f46832018-05-16 14:14:04 -070047#define ENV_DECOMPRESSOR 0
Kyösti Mälkkie8792be2014-02-26 15:19:04 +020048#define ENV_BOOTBLOCK 0
49#define ENV_ROMSTAGE 1
50#define ENV_RAMSTAGE 0
51#define ENV_SMM 0
Julius Werner21a40532020-04-21 16:03:53 -070052#define ENV_SEPARATE_VERSTAGE 0
Aaron Durbindde76292015-09-05 12:59:26 -050053#define ENV_RMODULE 0
Aaron Durbin7f8afe02016-03-18 12:21:23 -050054#define ENV_POSTCAR 0
Kyösti Mälkkia405a582017-03-02 13:01:58 +020055#define ENV_LIBAGESA 0
Ben Gardneraa5f5b12015-11-19 10:48:47 -060056#define ENV_STRING "romstage"
Kyösti Mälkkie8792be2014-02-26 15:19:04 +020057
58#elif defined(__SMM__)
Julius Werner99f46832018-05-16 14:14:04 -070059#define ENV_DECOMPRESSOR 0
Kyösti Mälkkie8792be2014-02-26 15:19:04 +020060#define ENV_BOOTBLOCK 0
61#define ENV_ROMSTAGE 0
62#define ENV_RAMSTAGE 0
63#define ENV_SMM 1
Julius Werner21a40532020-04-21 16:03:53 -070064#define ENV_SEPARATE_VERSTAGE 0
Aaron Durbindde76292015-09-05 12:59:26 -050065#define ENV_RMODULE 0
Aaron Durbin7f8afe02016-03-18 12:21:23 -050066#define ENV_POSTCAR 0
Kyösti Mälkkia405a582017-03-02 13:01:58 +020067#define ENV_LIBAGESA 0
Ben Gardneraa5f5b12015-11-19 10:48:47 -060068#define ENV_STRING "smm"
Patrick Georgicc8171f2015-04-28 22:26:23 +020069
Julius Werner21a40532020-04-21 16:03:53 -070070/*
71 * NOTE: "verstage" code may either run as a separate stage or linked into the
Martin Roth0639bff2020-11-09 13:13:27 -070072 * bootblock/romstage, depending on the setting of the VBOOT_SEPARATE_VERSTAGE
73 * kconfig option. The ENV_SEPARATE_VERSTAGE macro will only return true for
74 * "verstage" code when CONFIG(VBOOT_SEPARATE_VERSTAGE) is true, otherwise that
75 * code will have ENV_BOOTBLOCK or ENV_ROMSTAGE set (depending on the
76 * "VBOOT_STARTS_IN_"... kconfig options).
Julius Werner21a40532020-04-21 16:03:53 -070077 */
Patrick Georgicc8171f2015-04-28 22:26:23 +020078#elif defined(__VERSTAGE__)
Julius Werner99f46832018-05-16 14:14:04 -070079#define ENV_DECOMPRESSOR 0
Patrick Georgicc8171f2015-04-28 22:26:23 +020080#define ENV_BOOTBLOCK 0
81#define ENV_ROMSTAGE 0
82#define ENV_RAMSTAGE 0
83#define ENV_SMM 0
Julius Werner21a40532020-04-21 16:03:53 -070084#define ENV_SEPARATE_VERSTAGE 1
Aaron Durbindde76292015-09-05 12:59:26 -050085#define ENV_RMODULE 0
Aaron Durbin7f8afe02016-03-18 12:21:23 -050086#define ENV_POSTCAR 0
Kyösti Mälkkia405a582017-03-02 13:01:58 +020087#define ENV_LIBAGESA 0
Kangheui Won4b5c8b52020-10-07 14:29:38 +110088#if CONFIG(VBOOT_STARTS_BEFORE_BOOTBLOCK)
89#define ENV_STRING "verstage-before-bootblock"
90#else
Ben Gardneraa5f5b12015-11-19 10:48:47 -060091#define ENV_STRING "verstage"
Kangheui Won4b5c8b52020-10-07 14:29:38 +110092#endif
Furquan Shaikhabde3b52014-08-26 15:39:51 -070093
Aaron Durbincd96c5c2015-09-04 16:28:15 -050094#elif defined(__RAMSTAGE__)
Julius Werner99f46832018-05-16 14:14:04 -070095#define ENV_DECOMPRESSOR 0
Kyösti Mälkkie8792be2014-02-26 15:19:04 +020096#define ENV_BOOTBLOCK 0
97#define ENV_ROMSTAGE 0
98#define ENV_RAMSTAGE 1
99#define ENV_SMM 0
Julius Werner21a40532020-04-21 16:03:53 -0700100#define ENV_SEPARATE_VERSTAGE 0
Aaron Durbindde76292015-09-05 12:59:26 -0500101#define ENV_RMODULE 0
Aaron Durbin7f8afe02016-03-18 12:21:23 -0500102#define ENV_POSTCAR 0
Kyösti Mälkkia405a582017-03-02 13:01:58 +0200103#define ENV_LIBAGESA 0
Ben Gardneraa5f5b12015-11-19 10:48:47 -0600104#define ENV_STRING "ramstage"
Aaron Durbindde76292015-09-05 12:59:26 -0500105
106#elif defined(__RMODULE__)
Julius Werner99f46832018-05-16 14:14:04 -0700107#define ENV_DECOMPRESSOR 0
Aaron Durbindde76292015-09-05 12:59:26 -0500108#define ENV_BOOTBLOCK 0
109#define ENV_ROMSTAGE 0
110#define ENV_RAMSTAGE 0
111#define ENV_SMM 0
Julius Werner21a40532020-04-21 16:03:53 -0700112#define ENV_SEPARATE_VERSTAGE 0
Aaron Durbindde76292015-09-05 12:59:26 -0500113#define ENV_RMODULE 1
Aaron Durbin7f8afe02016-03-18 12:21:23 -0500114#define ENV_POSTCAR 0
Kyösti Mälkkia405a582017-03-02 13:01:58 +0200115#define ENV_LIBAGESA 0
Ben Gardneraa5f5b12015-11-19 10:48:47 -0600116#define ENV_STRING "rmodule"
Aaron Durbincd96c5c2015-09-04 16:28:15 -0500117
Aaron Durbin7f8afe02016-03-18 12:21:23 -0500118#elif defined(__POSTCAR__)
Julius Werner99f46832018-05-16 14:14:04 -0700119#define ENV_DECOMPRESSOR 0
Aaron Durbin7f8afe02016-03-18 12:21:23 -0500120#define ENV_BOOTBLOCK 0
121#define ENV_ROMSTAGE 0
122#define ENV_RAMSTAGE 0
123#define ENV_SMM 0
Julius Werner21a40532020-04-21 16:03:53 -0700124#define ENV_SEPARATE_VERSTAGE 0
Aaron Durbin7f8afe02016-03-18 12:21:23 -0500125#define ENV_RMODULE 0
126#define ENV_POSTCAR 1
Kyösti Mälkkia405a582017-03-02 13:01:58 +0200127#define ENV_LIBAGESA 0
Aaron Durbin7f8afe02016-03-18 12:21:23 -0500128#define ENV_STRING "postcar"
129
Kyösti Mälkkia405a582017-03-02 13:01:58 +0200130#elif defined(__LIBAGESA__)
Julius Werner99f46832018-05-16 14:14:04 -0700131#define ENV_DECOMPRESSOR 0
Kyösti Mälkkia405a582017-03-02 13:01:58 +0200132#define ENV_BOOTBLOCK 0
133#define ENV_ROMSTAGE 0
134#define ENV_RAMSTAGE 0
135#define ENV_SMM 0
Julius Werner21a40532020-04-21 16:03:53 -0700136#define ENV_SEPARATE_VERSTAGE 0
Kyösti Mälkkia405a582017-03-02 13:01:58 +0200137#define ENV_RMODULE 0
138#define ENV_POSTCAR 0
139#define ENV_LIBAGESA 1
140#define ENV_STRING "libagesa"
141
Aaron Durbincd96c5c2015-09-04 16:28:15 -0500142#else
143/*
144 * Default case of nothing set for random blob generation using
Kyösti Mälkkia405a582017-03-02 13:01:58 +0200145 * create_class_compiler that isn't bound to a stage.
Aaron Durbincd96c5c2015-09-04 16:28:15 -0500146 */
Julius Werner99f46832018-05-16 14:14:04 -0700147#define ENV_DECOMPRESSOR 0
Aaron Durbincd96c5c2015-09-04 16:28:15 -0500148#define ENV_BOOTBLOCK 0
149#define ENV_ROMSTAGE 0
150#define ENV_RAMSTAGE 0
151#define ENV_SMM 0
Julius Werner21a40532020-04-21 16:03:53 -0700152#define ENV_SEPARATE_VERSTAGE 0
Aaron Durbindde76292015-09-05 12:59:26 -0500153#define ENV_RMODULE 0
Aaron Durbin7f8afe02016-03-18 12:21:23 -0500154#define ENV_POSTCAR 0
Kyösti Mälkkia405a582017-03-02 13:01:58 +0200155#define ENV_LIBAGESA 0
Ben Gardneraa5f5b12015-11-19 10:48:47 -0600156#define ENV_STRING "UNKNOWN"
Kyösti Mälkkie8792be2014-02-26 15:19:04 +0200157#endif
Kyösti Mälkkief844012013-06-25 23:17:43 +0300158
Julius Wernerd3634c12015-11-13 13:28:41 -0800159/* Define helpers about the current architecture, based on toolchain.inc. */
160
161#if defined(__ARCH_arm__)
162#define ENV_ARM 1
163#define ENV_ARM64 0
164#if __COREBOOT_ARM_ARCH__ == 4
165#define ENV_ARMV4 1
166#define ENV_ARMV7 0
167#elif __COREBOOT_ARM_ARCH__ == 7
168#define ENV_ARMV4 0
169#define ENV_ARMV7 1
Hakim Giydan43e5b572016-09-08 10:13:59 -0700170#if defined(__COREBOOT_ARM_V7_A__)
171#define ENV_ARMV7_A 1
172#define ENV_ARMV7_M 0
173#define ENV_ARMV7_R 0
174#elif defined(__COREBOOT_ARM_V7_M__)
175#define ENV_ARMV7_A 0
176#define ENV_ARMV7_M 1
177#define ENV_ARMV7_R 0
178#elif defined(__COREBOOT_ARM_V7_R__)
179#define ENV_ARMV7_A 0
180#define ENV_ARMV7_M 0
181#define ENV_ARMV7_R 1
182#endif
Julius Wernerd3634c12015-11-13 13:28:41 -0800183#else
184#define ENV_ARMV4 0
185#define ENV_ARMV7 0
186#endif
187#define ENV_ARMV8 0
Julius Wernerd3634c12015-11-13 13:28:41 -0800188#define ENV_RISCV 0
189#define ENV_X86 0
190#define ENV_X86_32 0
191#define ENV_X86_64 0
192
193#elif defined(__ARCH_arm64__)
194#define ENV_ARM 0
195#define ENV_ARM64 1
196#define ENV_ARMV4 0
197#define ENV_ARMV7 0
198#if __COREBOOT_ARM_ARCH__ == 8
199#define ENV_ARMV8 1
200#else
201#define ENV_ARMV8 0
202#endif
Julius Wernerd3634c12015-11-13 13:28:41 -0800203#define ENV_RISCV 0
204#define ENV_X86 0
205#define ENV_X86_32 0
206#define ENV_X86_64 0
207
208#elif defined(__ARCH_riscv__)
209#define ENV_ARM 0
210#define ENV_ARM64 0
211#define ENV_ARMV4 0
212#define ENV_ARMV7 0
213#define ENV_ARMV8 0
Julius Wernerd3634c12015-11-13 13:28:41 -0800214#define ENV_RISCV 1
215#define ENV_X86 0
216#define ENV_X86_32 0
217#define ENV_X86_64 0
218
219#elif defined(__ARCH_x86_32__)
220#define ENV_ARM 0
221#define ENV_ARM64 0
222#define ENV_ARMV4 0
223#define ENV_ARMV7 0
224#define ENV_ARMV8 0
Julius Wernerd3634c12015-11-13 13:28:41 -0800225#define ENV_RISCV 0
226#define ENV_X86 1
227#define ENV_X86_32 1
228#define ENV_X86_64 0
229
230#elif defined(__ARCH_x86_64__)
231#define ENV_ARM 0
232#define ENV_ARM64 0
233#define ENV_ARMV4 0
234#define ENV_ARMV7 0
235#define ENV_ARMV8 0
Julius Wernerd3634c12015-11-13 13:28:41 -0800236#define ENV_RISCV 0
237#define ENV_X86 1
238#define ENV_X86_32 0
239#define ENV_X86_64 1
240
241#else
242#define ENV_ARM 0
243#define ENV_ARM64 0
244#define ENV_ARMV4 0
245#define ENV_ARMV7 0
246#define ENV_ARMV8 0
Julius Wernerd3634c12015-11-13 13:28:41 -0800247#define ENV_RISCV 0
248#define ENV_X86 0
249#define ENV_X86_32 0
250#define ENV_X86_64 0
251
252#endif
253
Subrata Banik63022032019-05-11 20:12:20 +0530254#if CONFIG(RAMPAYLOAD)
255/* ENV_PAYLOAD_LOADER is set to ENV_POSTCAR when CONFIG_RAMPAYLOAD is enabled */
256#define ENV_PAYLOAD_LOADER ENV_POSTCAR
257#else
Ronald G. Minnich42493482019-05-09 17:09:25 +0000258/* ENV_PAYLOAD_LOADER is set when you are in a stage that loads the payload.
259 * For now, that is the ramstage. */
260#define ENV_PAYLOAD_LOADER ENV_RAMSTAGE
Subrata Banik63022032019-05-11 20:12:20 +0530261#endif
Ronald G. Minnich42493482019-05-09 17:09:25 +0000262
Kyösti Mälkki21160a72019-08-17 17:29:36 +0300263#define ENV_ROMSTAGE_OR_BEFORE \
Kyösti Mälkkif704b542019-09-14 14:59:38 +0300264 (ENV_DECOMPRESSOR || ENV_BOOTBLOCK || ENV_ROMSTAGE || \
Martin Rothb9c2ecf2020-06-10 20:35:35 -0600265 (ENV_SEPARATE_VERSTAGE && !CONFIG(VBOOT_STARTS_IN_ROMSTAGE)))
Kyösti Mälkki21160a72019-08-17 17:29:36 +0300266
Kyösti Mälkki7336f972020-06-08 06:05:03 +0300267#if ENV_X86
Kyösti Mälkki21160a72019-08-17 17:29:36 +0300268/* Indicates memory layout is determined with arch/x86/car.ld. */
Martin Roth8418fd42019-04-22 16:26:23 -0600269#define ENV_CACHE_AS_RAM (ENV_ROMSTAGE_OR_BEFORE && !CONFIG(RESET_VECTOR_IN_RAM))
Kyösti Mälkkif2cc52b2019-08-21 07:15:38 +0300270/* No .data sections with execute-in-place from ROM. */
271#define ENV_STAGE_HAS_DATA_SECTION !ENV_CACHE_AS_RAM
Kyösti Mälkkif2cc52b2019-08-21 07:15:38 +0300272#else
273/* Both .data and .bss, sometimes SRAM not DRAM. */
274#define ENV_STAGE_HAS_DATA_SECTION 1
Kyösti Mälkkif2cc52b2019-08-21 07:15:38 +0300275#define ENV_CACHE_AS_RAM 0
276#endif
277
278/* Currently rmodules, ramstage and smm have heap. */
279#define ENV_STAGE_HAS_HEAP_SECTION (ENV_RMODULE || ENV_RAMSTAGE || ENV_SMM)
280
Martin Roth44d53472020-07-23 18:27:58 -0600281/* Set USER_SPACE in the makefile for the rare code that runs in userspace */
282#if defined(__USER_SPACE__)
283#define ENV_USER_SPACE 1
284#else
285#define ENV_USER_SPACE 0
286#endif
287
Martin Roth1594e8f2020-07-15 13:57:54 -0600288/* Define the first stage to run */
289#if CONFIG(VBOOT_STARTS_BEFORE_BOOTBLOCK)
290#define ENV_INITIAL_STAGE ENV_SEPARATE_VERSTAGE
291#else
292#define ENV_INITIAL_STAGE ENV_BOOTBLOCK
293#endif
294
Patrick Rudolpha626d272018-04-18 10:13:32 +0200295/**
296 * For pre-DRAM stages and post-CAR always build with simple device model, ie.
297 * PCI, PNP and CPU functions operate without use of devicetree. The reason
298 * post-CAR utilizes __SIMPLE_DEVICE__ is for simplicity. Currently there's
299 * no known requirement that devicetree would be needed during that stage.
300 *
301 * For ramstage individual source file may define __SIMPLE_DEVICE__
302 * before including any header files to force that particular source
303 * be built with simple device model.
Patrick Rudolpha626d272018-04-18 10:13:32 +0200304 */
305
Kyösti Mälkki21160a72019-08-17 17:29:36 +0300306#if !ENV_RAMSTAGE
Patrick Rudolpha626d272018-04-18 10:13:32 +0200307#define __SIMPLE_DEVICE__
308#endif
309
Kyösti Mälkkie8792be2014-02-26 15:19:04 +0200310#endif /* _RULES_H */