1 /* SPDX-License-Identifier: GPL-2.0-only */
12 #if defined(__TIMELESS__)
13 #define ENV_TIMELESS 1
15 #define ENV_TIMELESS 0
18 /* Useful helpers to tell whether the code is executing in bootblock,
19 * romstage, ramstage or SMM.
22 #if defined(__DECOMPRESSOR__)
23 #define ENV_DECOMPRESSOR 1
24 #define ENV_BOOTBLOCK 0
25 #define ENV_ROMSTAGE 0
26 #define ENV_RAMSTAGE 0
28 #define ENV_SEPARATE_VERSTAGE 0
31 #define ENV_LIBAGESA 0
32 #define ENV_STRING "decompressor"
34 #elif defined(__BOOTBLOCK__)
35 #define ENV_DECOMPRESSOR 0
36 #define ENV_BOOTBLOCK 1
37 #define ENV_ROMSTAGE 0
38 #define ENV_RAMSTAGE 0
40 #define ENV_SEPARATE_VERSTAGE 0
43 #define ENV_LIBAGESA 0
44 #define ENV_STRING "bootblock"
46 #elif defined(__ROMSTAGE__)
47 #define ENV_DECOMPRESSOR 0
48 #define ENV_BOOTBLOCK 0
49 #define ENV_ROMSTAGE 1
50 #define ENV_RAMSTAGE 0
52 #define ENV_SEPARATE_VERSTAGE 0
55 #define ENV_LIBAGESA 0
56 #define ENV_STRING "romstage"
58 #elif defined(__SMM__)
59 #define ENV_DECOMPRESSOR 0
60 #define ENV_BOOTBLOCK 0
61 #define ENV_ROMSTAGE 0
62 #define ENV_RAMSTAGE 0
64 #define ENV_SEPARATE_VERSTAGE 0
67 #define ENV_LIBAGESA 0
68 #define ENV_STRING "smm"
71 * NOTE: "verstage" code may either run as a separate stage or linked into the
72 * 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).
78 #elif defined(__VERSTAGE__)
79 #define ENV_DECOMPRESSOR 0
80 #define ENV_BOOTBLOCK 0
81 #define ENV_ROMSTAGE 0
82 #define ENV_RAMSTAGE 0
84 #define ENV_SEPARATE_VERSTAGE 1
87 #define ENV_LIBAGESA 0
88 #if CONFIG(VBOOT_STARTS_BEFORE_BOOTBLOCK)
89 #define ENV_STRING "verstage-before-bootblock"
91 #define ENV_STRING "verstage"
94 #elif defined(__RAMSTAGE__)
95 #define ENV_DECOMPRESSOR 0
96 #define ENV_BOOTBLOCK 0
97 #define ENV_ROMSTAGE 0
98 #define ENV_RAMSTAGE 1
100 #define ENV_SEPARATE_VERSTAGE 0
101 #define ENV_RMODULE 0
102 #define ENV_POSTCAR 0
103 #define ENV_LIBAGESA 0
104 #define ENV_STRING "ramstage"
106 #elif defined(__RMODULE__)
107 #define ENV_DECOMPRESSOR 0
108 #define ENV_BOOTBLOCK 0
109 #define ENV_ROMSTAGE 0
110 #define ENV_RAMSTAGE 0
112 #define ENV_SEPARATE_VERSTAGE 0
113 #define ENV_RMODULE 1
114 #define ENV_POSTCAR 0
115 #define ENV_LIBAGESA 0
116 #define ENV_STRING "rmodule"
118 #elif defined(__POSTCAR__)
119 #define ENV_DECOMPRESSOR 0
120 #define ENV_BOOTBLOCK 0
121 #define ENV_ROMSTAGE 0
122 #define ENV_RAMSTAGE 0
124 #define ENV_SEPARATE_VERSTAGE 0
125 #define ENV_RMODULE 0
126 #define ENV_POSTCAR 1
127 #define ENV_LIBAGESA 0
128 #define ENV_STRING "postcar"
130 #elif defined(__LIBAGESA__)
131 #define ENV_DECOMPRESSOR 0
132 #define ENV_BOOTBLOCK 0
133 #define ENV_ROMSTAGE 0
134 #define ENV_RAMSTAGE 0
136 #define ENV_SEPARATE_VERSTAGE 0
137 #define ENV_RMODULE 0
138 #define ENV_POSTCAR 0
139 #define ENV_LIBAGESA 1
140 #define ENV_STRING "libagesa"
144 * Default case of nothing set for random blob generation using
145 * create_class_compiler that isn't bound to a stage.
147 #define ENV_DECOMPRESSOR 0
148 #define ENV_BOOTBLOCK 0
149 #define ENV_ROMSTAGE 0
150 #define ENV_RAMSTAGE 0
152 #define ENV_SEPARATE_VERSTAGE 0
153 #define ENV_RMODULE 0
154 #define ENV_POSTCAR 0
155 #define ENV_LIBAGESA 0
156 #define ENV_STRING "UNKNOWN"
159 /* Define helpers about the current architecture, based on toolchain.inc. */
161 #if defined(__ARCH_arm__)
164 #if __COREBOOT_ARM_ARCH__ == 4
167 #define ENV_ARCH "armv4"
168 #elif __COREBOOT_ARM_ARCH__ == 7
171 #define ENV_ARCH "armv7"
172 #if defined(__COREBOOT_ARM_V7_A__)
173 #define ENV_ARMV7_A 1
174 #define ENV_ARMV7_M 0
175 #define ENV_ARMV7_R 0
176 #elif defined(__COREBOOT_ARM_V7_M__)
177 #define ENV_ARMV7_A 0
178 #define ENV_ARMV7_M 1
179 #define ENV_ARMV7_R 0
180 #elif defined(__COREBOOT_ARM_V7_R__)
181 #define ENV_ARMV7_A 0
182 #define ENV_ARMV7_M 0
183 #define ENV_ARMV7_R 1
195 #elif defined(__ARCH_arm64__)
200 #if __COREBOOT_ARM_ARCH__ == 8
209 #define ENV_ARCH "aarch64"
211 #elif defined(__ARCH_riscv__)
221 #define ENV_ARCH "riscv"
223 #elif defined(__ARCH_x86_32__)
233 #define ENV_ARCH "x86_32"
235 #elif defined(__ARCH_x86_64__)
245 #define ENV_ARCH "x86_64"
257 #define ENV_ARCH "unknown"
261 #if CONFIG(RAMPAYLOAD)
262 /* ENV_PAYLOAD_LOADER is set to ENV_POSTCAR when CONFIG_RAMPAYLOAD is enabled */
263 #define ENV_PAYLOAD_LOADER ENV_POSTCAR
265 /* ENV_PAYLOAD_LOADER is set when you are in a stage that loads the payload.
266 * For now, that is the ramstage. */
267 #define ENV_PAYLOAD_LOADER ENV_RAMSTAGE
270 #define ENV_ROMSTAGE_OR_BEFORE \
271 (ENV_DECOMPRESSOR || ENV_BOOTBLOCK || ENV_ROMSTAGE || \
272 (ENV_SEPARATE_VERSTAGE && !CONFIG(VBOOT_STARTS_IN_ROMSTAGE)))
275 /* Indicates memory layout is determined with arch/x86/car.ld. */
276 #define ENV_CACHE_AS_RAM (ENV_ROMSTAGE_OR_BEFORE && !CONFIG(RESET_VECTOR_IN_RAM))
277 /* No .data sections with execute-in-place from ROM. */
278 #define ENV_HAS_DATA_SECTION !ENV_CACHE_AS_RAM
280 /* Both .data and .bss, sometimes SRAM not DRAM. */
281 #define ENV_HAS_DATA_SECTION 1
282 #define ENV_CACHE_AS_RAM 0
285 /* Indicates if the stage uses the _bss region defined in arch/x86/car.ld */
286 #define ENV_SEPARATE_BSS (ENV_CACHE_AS_RAM && (ENV_BOOTBLOCK || !CONFIG(NO_XIP_EARLY_STAGES)))
288 /* Currently rmodules, ramstage and smm have heap. */
289 #define ENV_HAS_HEAP_SECTION (ENV_RMODULE || ENV_RAMSTAGE || ENV_SMM)
291 /* Set USER_SPACE in the makefile for the rare code that runs in userspace */
292 #if defined(__USER_SPACE__)
293 #define ENV_USER_SPACE 1
295 #define ENV_USER_SPACE 0
298 /* Define the first stage to run */
299 #if CONFIG(VBOOT_STARTS_BEFORE_BOOTBLOCK)
300 #define ENV_INITIAL_STAGE ENV_SEPARATE_VERSTAGE
302 #define ENV_INITIAL_STAGE ENV_BOOTBLOCK
305 #define ENV_CREATES_CBMEM ENV_ROMSTAGE
306 #define ENV_HAS_CBMEM (ENV_ROMSTAGE | ENV_POSTCAR | ENV_RAMSTAGE)
307 #define ENV_RAMINIT ENV_ROMSTAGE
310 #define ENV_HAS_SPINLOCKS !ENV_ROMSTAGE_OR_BEFORE
312 #define ENV_HAS_SPINLOCKS 1
314 #define ENV_HAS_SPINLOCKS 0
317 /* When set <arch/smp/spinlock.h> is included for the spinlock implementation. */
318 #define ENV_SUPPORTS_SMP (CONFIG(SMP) && ENV_HAS_SPINLOCKS)
320 #if ENV_X86 && CONFIG(COOP_MULTITASKING) && (ENV_RAMSTAGE || ENV_ROMSTAGE)
321 /* TODO: Enable in all x86 stages */
322 #define ENV_SUPPORTS_COOP 1
324 #define ENV_SUPPORTS_COOP 0
328 * For pre-DRAM stages and post-CAR always build with simple device model, ie.
329 * PCI, PNP and CPU functions operate without use of devicetree. The reason
330 * post-CAR utilizes __SIMPLE_DEVICE__ is for simplicity. Currently there's
331 * no known requirement that devicetree would be needed during that stage.
333 * For ramstage individual source file may define __SIMPLE_DEVICE__
334 * before including any header files to force that particular source
335 * be built with simple device model.
339 #define __SIMPLE_DEVICE__
342 #endif /* _RULES_H */