diff options
author | Aaron Durbin <adurbin@chromium.org> | 2013-10-24 10:14:06 -0500 |
---|---|---|
committer | Aaron Durbin <adurbin@google.com> | 2014-01-28 22:29:42 +0100 |
commit | f545abfd22a594ecb9c0678efa5278bb38a37a70 (patch) | |
tree | 60c77bc89c52293a316acc2fba2da3897ebeaea2 /src/lib/rmodule.c | |
parent | 16000c883ee121b82b943c613ab1ae6a5ed7e01c (diff) | |
download | coreboot-f545abfd22a594ecb9c0678efa5278bb38a37a70.tar.xz |
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/rmodule.c')
-rw-r--r-- | src/lib/rmodule.c | 61 |
1 files changed, 61 insertions, 0 deletions
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, ®ion_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 */ |