cbfs: Remove prog_locate() for stages and rmodules

This patch removes the prog_locate() step for stages and rmodules.
Instead, the stage and rmodule loading functions will now perform the
locate step directly together with the actual loading. The long-term
goal of this is to eliminate prog_locate() (and the rdev member in
struct prog that it fills) completely in order to make CBFS verification
code safer and its security guarantees easier to follow. prog_locate()
is the main remaining use case where a raw rdev of CBFS file data
"leaks" out of cbfs.c into other code, and that other code needs to
manually make sure that the contents of the rdev get verified during
loading. By eliminating this step and moving all code that directly
deals with file data into cbfs.c, we can concentrate the code that needs
to worry about file data hashing (and needs access to cbfs_private.h
APIs) into one file, making it easier to keep track of and reason about.

This patch is the first step of this move, later patches will do the
same for SELFs and other program types.

Signed-off-by: Julius Werner <jwerner@chromium.org>
Change-Id: Ia600e55f77c2549a00e2606f09befc1f92594a3a
Reviewed-on: https://review.coreboot.org/c/coreboot/+/49335
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
diff --git a/src/lib/prog_loaders.c b/src/lib/prog_loaders.c
index 4722e54..b31d793 100644
--- a/src/lib/prog_loaders.c
+++ b/src/lib/prog_loaders.c
@@ -45,18 +45,15 @@
 
 	vboot_run_logic();
 
-	if (ENV_X86 && CONFIG(BOOTBLOCK_NORMAL)) {
-		if (legacy_romstage_selector(&romstage))
-			goto fail;
-	} else {
-		if (prog_locate(&romstage))
-			goto fail;
-	}
-
 	timestamp_add_now(TS_START_COPYROM);
 
-	if (cbfs_prog_stage_load(&romstage))
-		goto fail;
+	if (ENV_X86 && CONFIG(BOOTBLOCK_NORMAL)) {
+		if (legacy_romstage_select_and_load(&romstage))
+			goto fail;
+	} else {
+		if (cbfs_prog_stage_load(&romstage))
+			goto fail;
+	}
 
 	timestamp_add_now(TS_END_COPYROM);
 
@@ -78,6 +75,7 @@
 	/* Load the cached ramstage to runtime location. */
 	stage_cache_load_stage(STAGE_RAMSTAGE, ramstage);
 
+	ramstage->cbfs_type = CBFS_TYPE_STAGE;
 	prog_set_arg(ramstage, cbmem_top());
 
 	if (prog_entry(ramstage) != NULL) {
@@ -120,9 +118,6 @@
 
 	vboot_run_logic();
 
-	if (prog_locate(&ramstage))
-		goto fail;
-
 	timestamp_add_now(TS_START_COPYRAM);
 
 	if (ENV_X86) {