1 /* SPDX-License-Identifier: GPL-2.0-only */
5 #include <console/console.h>
9 #include <program_loading.h>
12 #include <stage_cache.h>
15 #include <timestamp.h>
16 #include <security/vboot/vboot_common.h>
18 void run_romstage(void)
20 struct prog romstage
=
21 PROG_INIT(PROG_ROMSTAGE
, CONFIG_CBFS_PREFIX
"/romstage");
25 timestamp_add_now(TS_COPYROM_START
);
27 if (ENV_X86
&& CONFIG(BOOTBLOCK_NORMAL
)) {
28 if (legacy_romstage_select_and_load(&romstage
) != CB_SUCCESS
)
31 if (cbfs_prog_stage_load(&romstage
))
35 timestamp_add_now(TS_COPYROM_END
);
37 console_time_report();
42 if (CONFIG(BOOTBLOCK_CONSOLE
))
43 die_with_post_code(POST_INVALID_ROM
,
44 "Couldn't load romstage.\n");
48 int __weak
prog_locate_hook(struct prog
*prog
) { return 0; }
50 static void run_ramstage_from_resume(struct prog
*ramstage
)
52 /* Load the cached ramstage to runtime location. */
53 stage_cache_load_stage(STAGE_RAMSTAGE
, ramstage
);
55 ramstage
->cbfs_type
= CBFS_TYPE_STAGE
;
56 prog_set_arg(ramstage
, cbmem_top());
58 if (prog_entry(ramstage
) != NULL
) {
59 printk(BIOS_DEBUG
, "Jumping to image.\n");
63 printk(BIOS_ERR
, "ramstage cache invalid.\n");
67 static int load_relocatable_ramstage(struct prog
*ramstage
)
69 struct rmod_stage_load rmod_ram
= {
70 .cbmem_id
= CBMEM_ID_RAMSTAGE
,
74 return rmodule_stage_load(&rmod_ram
);
76 void preload_ramstage(void)
78 if (!CONFIG(CBFS_PRELOAD
))
81 printk(BIOS_DEBUG
, "Preloading ramstage\n");
83 cbfs_preload(CONFIG_CBFS_PREFIX
"/ramstage");
85 void __noreturn
run_ramstage(void)
87 struct prog ramstage
=
88 PROG_INIT(PROG_RAMSTAGE
, CONFIG_CBFS_PREFIX
"/ramstage");
90 /* Call "end of romstage" here if postcar stage doesn't exist */
92 timestamp_add_now(TS_POSTCAR_END
);
94 timestamp_add_now(TS_ROMSTAGE_END
);
97 * Only x86 systems using ramstage stage cache currently take the same
98 * firmware path on resume.
100 if (ENV_X86
&& resume_from_stage_cache())
101 run_ramstage_from_resume(&ramstage
);
105 timestamp_add_now(TS_COPYRAM_START
);
108 if (load_relocatable_ramstage(&ramstage
))
111 if (cbfs_prog_stage_load(&ramstage
))
115 stage_cache_add(STAGE_RAMSTAGE
, &ramstage
);
117 timestamp_add_now(TS_COPYRAM_END
);
119 console_time_report();
121 /* This overrides the arg fetched from the relocatable module */
122 prog_set_arg(&ramstage
, cbmem_top());
127 die_with_post_code(POST_INVALID_ROM
, "Ramstage was not loaded!\n");
130 #if ENV_PAYLOAD_LOADER // gc-sections should take care of this
132 static struct prog global_payload
=
133 PROG_INIT(PROG_PAYLOAD
, CONFIG_CBFS_PREFIX
"/payload");
135 void payload_preload(void)
137 if (!CONFIG(CBFS_PRELOAD
))
140 cbfs_preload(global_payload
.name
);
143 void payload_load(void)
145 struct prog
*payload
= &global_payload
;
148 timestamp_add_now(TS_LOAD_PAYLOAD
);
150 if (prog_locate_hook(payload
))
153 payload
->cbfs_type
= CBFS_TYPE_QUERY
;
154 mapping
= cbfs_type_map(prog_name(payload
), NULL
, &payload
->cbfs_type
);
159 switch (prog_cbfs_type(payload
)) {
160 case CBFS_TYPE_SELF
: /* Simple ELF */
161 selfload_mapped(payload
, mapping
, BM_MEM_RAM
);
163 case CBFS_TYPE_FIT_PAYLOAD
: /* Flattened image tree */
164 if (CONFIG(PAYLOAD_FIT_SUPPORT
)) {
165 fit_payload(payload
, mapping
);
170 die_with_post_code(POST_INVALID_ROM
,
171 "Unsupported payload type %d.\n", payload
->cbfs_type
);
177 if (prog_entry(payload
) == NULL
)
178 die_with_post_code(POST_INVALID_ROM
, "Payload not loaded.\n");
181 void payload_run(void)
183 struct prog
*payload
= &global_payload
;
185 /* Reset to booting from this image as late as possible */
188 printk(BIOS_DEBUG
, "Jumping to boot code at %p(%p)\n",
189 prog_entry(payload
), prog_entry_arg(payload
));
191 post_code(POST_ENTER_ELF_BOOT
);
193 timestamp_add_now(TS_SELFBOOT_JUMP
);
195 /* Before we go off to run the payload, see if
196 * we stayed within our bounds.
198 checkstack(_estack
, 0);