summaryrefslogtreecommitdiff
path: root/src/lib/cbfs.c
diff options
context:
space:
mode:
authorAaron Durbin <adurbin@chromium.org>2013-10-24 10:14:06 -0500
committerAaron Durbin <adurbin@google.com>2014-01-28 22:29:42 +0100
commitf545abfd22a594ecb9c0678efa5278bb38a37a70 (patch)
tree60c77bc89c52293a316acc2fba2da3897ebeaea2 /src/lib/cbfs.c
parent16000c883ee121b82b943c613ab1ae6a5ed7e01c (diff)
rmodule: consolidate rmodule stage loading
There are 3 places rmodule stages are loaded in the existing code: cbfs and 2 in vboot_wrapper. Much of the code is the same except for a few different cbmem entry ids. Instead provide a common implementation in the rmodule library itself. A structure named rmod_stage_load is introduced to manage the inputs and outputs from the new API. BUG=chrome-os-partner:22866 BRANCH=None TEST=Built and booted successfully. Change-Id: I146055005557e04164e95de4aae8a2bde8713131 Signed-off-by: Aaron Durbin <adurbin@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/174425 Reviewed-by: Duncan Laurie <dlaurie@chromium.org> Reviewed-on: http://review.coreboot.org/4897 Reviewed-by: Alexandru Gagniuc <mr.nuke.me@gmail.com> Tested-by: build bot (Jenkins) Reviewed-by: Aaron Durbin <adurbin@google.com>
Diffstat (limited to 'src/lib/cbfs.c')
-rw-r--r--src/lib/cbfs.c50
1 files changed, 9 insertions, 41 deletions
diff --git a/src/lib/cbfs.c b/src/lib/cbfs.c
index e38f856de7..d101f452ec 100644
--- a/src/lib/cbfs.c
+++ b/src/lib/cbfs.c
@@ -177,51 +177,19 @@ load_cached_ramstage(struct romstage_handoff *handoff,
static void *load_stage_from_cbfs(struct cbfs_media *media, const char *name,
struct romstage_handoff *handoff)
{
- struct cbfs_stage *stage;
- struct rmodule ramstage;
- void *entry_point;
- size_t region_size;
- char *ramstage_region;
- int rmodule_offset;
- int load_offset;
- const struct cbmem_entry *ramstage_entry;
-
- stage = (struct cbfs_stage *)
- cbfs_get_file_content(media, name, CBFS_TYPE_STAGE, NULL);
+ struct rmod_stage_load rmod_ram = {
+ .cbmem_id = CBMEM_ID_RAMSTAGE,
+ .name = name,
+ };
- if (stage == NULL)
- return (void *) -1;
-
- rmodule_offset =
- rmodule_calc_region(DYN_CBMEM_ALIGN_SIZE,
- stage->memlen, &region_size, &load_offset);
-
- ramstage_entry = cbmem_entry_add(CBMEM_ID_RAMSTAGE, region_size);
-
- if (ramstage_entry == NULL)
+ if (rmodule_stage_load_from_cbfs(&rmod_ram)) {
+ printk(BIOS_DEBUG, "Could not load ramstage.\n");
return (void *) -1;
+ }
- ramstage_region = cbmem_entry_start(ramstage_entry);
-
- LOG("Decompressing stage %s @ 0x%p (%d bytes)\n",
- name, &ramstage_region[rmodule_offset], stage->memlen);
-
- if (!cbfs_decompress(stage->compression, &stage[1],
- &ramstage_region[rmodule_offset], stage->len))
- return (void *) -1;
-
- if (rmodule_parse(&ramstage_region[rmodule_offset], &ramstage))
- return (void *) -1;
-
- /* The ramstage is responsible for clearing its own bss. */
- if (rmodule_load(&ramstage_region[load_offset], &ramstage))
- return (void *) -1;
-
- entry_point = rmodule_entry(&ramstage);
-
- cache_loaded_ramstage(handoff, ramstage_entry, entry_point);
+ cache_loaded_ramstage(handoff, rmod_ram.cbmem_entry, rmod_ram.entry);
- return entry_point;
+ return rmod_ram.entry;
}
void * cbfs_load_stage(struct cbfs_media *media, const char *name)