soc/intel/alderlake: Add ADL-P 4+4 with 28W TDP
[coreboot.git] / src / lib / prog_loaders.c
blob08ba66a0c5f1cb43cf9d71f804b031c837f59873
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <cbfs.h>
4 #include <cbmem.h>
5 #include <console/console.h>
6 #include <fallback.h>
7 #include <halt.h>
8 #include <lib.h>
9 #include <program_loading.h>
10 #include <reset.h>
11 #include <rmodule.h>
12 #include <security/vboot/vboot_common.h>
13 #include <stage_cache.h>
14 #include <symbols.h>
15 #include <timestamp.h>
17 void run_romstage(void)
19 struct prog romstage =
20 PROG_INIT(PROG_ROMSTAGE, CONFIG_CBFS_PREFIX "/romstage");
22 vboot_run_logic();
24 timestamp_add_now(TS_COPYROM_START);
26 if (ENV_X86 && CONFIG(BOOTBLOCK_NORMAL)) {
27 if (legacy_romstage_select_and_load(&romstage) != CB_SUCCESS)
28 goto fail;
29 } else {
30 if (cbfs_prog_stage_load(&romstage))
31 goto fail;
34 timestamp_add_now(TS_COPYROM_END);
36 console_time_report();
38 prog_run(&romstage);
40 fail:
41 if (CONFIG(BOOTBLOCK_CONSOLE))
42 die_with_post_code(POST_INVALID_ROM,
43 "Couldn't load romstage.\n");
44 halt();
47 int __weak prog_locate_hook(struct prog *prog) { return 0; }
49 static void run_ramstage_from_resume(struct prog *ramstage)
51 /* Load the cached ramstage to runtime location. */
52 stage_cache_load_stage(STAGE_RAMSTAGE, ramstage);
54 ramstage->cbfs_type = CBFS_TYPE_STAGE;
55 prog_set_arg(ramstage, cbmem_top());
57 if (prog_entry(ramstage) != NULL) {
58 printk(BIOS_DEBUG, "Jumping to image.\n");
59 prog_run(ramstage);
62 printk(BIOS_ERR, "ramstage cache invalid.\n");
63 board_reset();
66 static int load_relocatable_ramstage(struct prog *ramstage)
68 struct rmod_stage_load rmod_ram = {
69 .cbmem_id = CBMEM_ID_RAMSTAGE,
70 .prog = ramstage,
73 return rmodule_stage_load(&rmod_ram);
75 void preload_ramstage(void)
77 if (!CONFIG(CBFS_PRELOAD))
78 return;
80 printk(BIOS_DEBUG, "Preloading ramstage\n");
82 cbfs_preload(CONFIG_CBFS_PREFIX "/ramstage");
84 void __noreturn run_ramstage(void)
86 struct prog ramstage =
87 PROG_INIT(PROG_RAMSTAGE, CONFIG_CBFS_PREFIX "/ramstage");
89 /* Call "end of romstage" here if postcar stage doesn't exist */
90 if (ENV_POSTCAR)
91 timestamp_add_now(TS_POSTCAR_END);
92 else
93 timestamp_add_now(TS_ROMSTAGE_END);
96 * Only x86 systems using ramstage stage cache currently take the same
97 * firmware path on resume.
99 if (ENV_X86 && resume_from_stage_cache())
100 run_ramstage_from_resume(&ramstage);
102 vboot_run_logic();
104 timestamp_add_now(TS_COPYRAM_START);
106 if (ENV_X86) {
107 if (load_relocatable_ramstage(&ramstage))
108 goto fail;
109 } else {
110 if (cbfs_prog_stage_load(&ramstage))
111 goto fail;
114 stage_cache_add(STAGE_RAMSTAGE, &ramstage);
116 timestamp_add_now(TS_COPYRAM_END);
118 console_time_report();
120 /* This overrides the arg fetched from the relocatable module */
121 prog_set_arg(&ramstage, cbmem_top());
123 prog_run(&ramstage);
125 fail:
126 die_with_post_code(POST_INVALID_ROM, "Ramstage was not loaded!\n");
129 #if ENV_PAYLOAD_LOADER // gc-sections should take care of this
131 static struct prog global_payload =
132 PROG_INIT(PROG_PAYLOAD, CONFIG_CBFS_PREFIX "/payload");
134 void payload_preload(void)
136 if (!CONFIG(CBFS_PRELOAD))
137 return;
139 cbfs_preload(global_payload.name);
142 void payload_load(void)
144 struct prog *payload = &global_payload;
145 void *mapping;
147 timestamp_add_now(TS_LOAD_PAYLOAD);
149 if (prog_locate_hook(payload))
150 goto out;
152 payload->cbfs_type = CBFS_TYPE_QUERY;
153 mapping = cbfs_type_map(prog_name(payload), NULL, &payload->cbfs_type);
155 if (!mapping)
156 goto out;
158 switch (prog_cbfs_type(payload)) {
159 case CBFS_TYPE_SELF: /* Simple ELF */
160 selfload_mapped(payload, mapping, BM_MEM_RAM);
161 break;
162 case CBFS_TYPE_FIT_PAYLOAD: /* Flattened image tree */
163 if (CONFIG(PAYLOAD_FIT_SUPPORT)) {
164 fit_payload(payload, mapping);
165 break;
167 __fallthrough;
168 default:
169 die_with_post_code(POST_INVALID_ROM,
170 "Unsupported payload type %d.\n", payload->cbfs_type);
171 break;
174 cbfs_unmap(mapping);
175 out:
176 if (prog_entry(payload) == NULL)
177 die_with_post_code(POST_INVALID_ROM, "Payload not loaded.\n");
180 void payload_run(void)
182 struct prog *payload = &global_payload;
184 /* Reset to booting from this image as late as possible */
185 boot_successful();
187 printk(BIOS_DEBUG, "Jumping to boot code at %p(%p)\n",
188 prog_entry(payload), prog_entry_arg(payload));
190 post_code(POST_ENTER_ELF_BOOT);
192 timestamp_add_now(TS_SELFBOOT_JUMP);
194 /* Before we go off to run the payload, see if
195 * we stayed within our bounds.
197 checkstack(_estack, 0);
199 prog_run(payload);
202 #endif