summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/cbfs.c50
-rw-r--r--src/lib/rmodule.c61
2 files changed, 70 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)
diff --git a/src/lib/rmodule.c b/src/lib/rmodule.c
index 462c7d76f2..a3e2184633 100644
--- a/src/lib/rmodule.c
+++ b/src/lib/rmodule.c
@@ -300,3 +300,64 @@ int rmodule_calc_region(unsigned int region_alignment, size_t rmodule_size,
return region_alignment - sizeof(struct rmodule_header);
}
+
+#if CONFIG_DYNAMIC_CBMEM
+#include <cbmem.h>
+#include <cbfs_core.h>
+
+int rmodule_stage_load(struct rmod_stage_load *rsl, struct cbfs_stage *stage)
+{
+ struct rmodule rmod_stage;
+ size_t region_size;
+ char *stage_region;
+ int rmodule_offset;
+ int load_offset;
+ const struct cbmem_entry *cbmem_entry;
+
+ if (stage == NULL || rsl->name == NULL)
+ return -1;
+
+ rmodule_offset =
+ rmodule_calc_region(DYN_CBMEM_ALIGN_SIZE,
+ stage->memlen, &region_size, &load_offset);
+
+ cbmem_entry = cbmem_entry_add(rsl->cbmem_id, region_size);
+
+ if (cbmem_entry == NULL)
+ return -1;
+
+ stage_region = cbmem_entry_start(cbmem_entry);
+
+ printk(BIOS_INFO, "Decompressing stage %s @ 0x%p (%d bytes)\n",
+ rsl->name, &stage_region[rmodule_offset], stage->memlen);
+
+ if (!cbfs_decompress(stage->compression, &stage[1],
+ &stage_region[rmodule_offset], stage->len))
+ return -1;
+
+ if (rmodule_parse(&stage_region[rmodule_offset], &rmod_stage))
+ return -1;
+
+ if (rmodule_load(&stage_region[load_offset], &rmod_stage))
+ return -1;
+
+ rsl->cbmem_entry = cbmem_entry;
+ rsl->entry = rmodule_entry(&rmod_stage);
+
+ return 0;
+}
+
+int rmodule_stage_load_from_cbfs(struct rmod_stage_load *rsl)
+{
+ struct cbfs_stage *stage;
+
+ stage = cbfs_get_file_content(CBFS_DEFAULT_MEDIA,
+ rsl->name, CBFS_TYPE_STAGE, NULL);
+
+ if (stage == NULL)
+ return -1;
+
+ return rmodule_stage_load(rsl, stage);
+}
+
+#endif /* DYNAMIC_CBMEM */