1 /* SPDX-License-Identifier: GPL-2.0-only */
5 #include <console/console.h>
9 #include <program_loading.h>
12 #include <security/vboot/vboot_common.h>
13 #include <stage_cache.h>
15 #include <timestamp.h>
17 void run_romstage(void)
19 struct prog romstage
=
20 PROG_INIT(PROG_ROMSTAGE
, CONFIG_CBFS_PREFIX
"/romstage");
24 timestamp_add_now(TS_COPYROM_START
);
26 if (ENV_X86
&& CONFIG(BOOTBLOCK_NORMAL
)) {
27 if (legacy_romstage_select_and_load(&romstage
) != CB_SUCCESS
)
30 if (cbfs_prog_stage_load(&romstage
))
34 timestamp_add_now(TS_COPYROM_END
);
36 console_time_report();
41 if (CONFIG(BOOTBLOCK_CONSOLE
))
42 die_with_post_code(POST_INVALID_ROM
,
43 "Couldn't load romstage.\n");
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");
62 printk(BIOS_ERR
, "ramstage cache invalid.\n");
66 static int load_relocatable_ramstage(struct prog
*ramstage
)
68 struct rmod_stage_load rmod_ram
= {
69 .cbmem_id
= CBMEM_ID_RAMSTAGE
,
73 return rmodule_stage_load(&rmod_ram
);
75 void preload_ramstage(void)
77 if (!CONFIG(CBFS_PRELOAD
))
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 */
91 timestamp_add_now(TS_POSTCAR_END
);
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
);
104 timestamp_add_now(TS_COPYRAM_START
);
107 if (load_relocatable_ramstage(&ramstage
))
110 if (cbfs_prog_stage_load(&ramstage
))
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());
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
))
139 cbfs_preload(global_payload
.name
);
142 void payload_load(void)
144 struct prog
*payload
= &global_payload
;
147 timestamp_add_now(TS_LOAD_PAYLOAD
);
149 if (prog_locate_hook(payload
))
152 payload
->cbfs_type
= CBFS_TYPE_QUERY
;
153 mapping
= cbfs_type_map(prog_name(payload
), NULL
, &payload
->cbfs_type
);
158 switch (prog_cbfs_type(payload
)) {
159 case CBFS_TYPE_SELF
: /* Simple ELF */
160 selfload_mapped(payload
, mapping
, BM_MEM_RAM
);
162 case CBFS_TYPE_FIT_PAYLOAD
: /* Flattened image tree */
163 if (CONFIG(PAYLOAD_FIT_SUPPORT
)) {
164 fit_payload(payload
, mapping
);
169 die_with_post_code(POST_INVALID_ROM
,
170 "Unsupported payload type %d.\n", payload
->cbfs_type
);
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 */
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);