summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Durbin <adurbin@chromium.org>2015-03-24 15:50:45 -0500
committerAaron Durbin <adurbin@google.com>2015-03-24 22:48:51 +0100
commit12d45b2f8a6c10d68ab940c24b7f68d5a6fbb378 (patch)
tree093f3bd7bdff2657d1811dc5aed904943880c8d2
parentd0f9f74223715aaebe897a6f773d3383d548fd12 (diff)
downloadcoreboot-12d45b2f8a6c10d68ab940c24b7f68d5a6fbb378.tar.xz
cbfs: expose init_backing_media()
I broke cbfs loading with commit 358901. As multiple functions are being reused one needs to ensure there is always a cbfs media object allocated on the stack and initialized. Ya for no common writable globals. TEST=Ran qemu-armv7. CBFS loading works again. Change-Id: Ibd047af7dcd8575e6203651471079fc2042da282 Signed-off-by: Aaron Durbin <adurbin@chromium.org> Reviewed-on: http://review.coreboot.org/8973 Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net> Reviewed-by: Duncan Laurie <dlaurie@google.com> Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org> Tested-by: Aaron Durbin <adurbin@google.com> Tested-by: build bot (Jenkins) Tested-by: Raptor Engineering Automated Test Stand <noreply@raptorengineeringinc.com>
-rw-r--r--src/include/cbfs.h1
-rw-r--r--src/lib/cbfs.c8
-rw-r--r--src/lib/cbfs_core.c8
3 files changed, 13 insertions, 4 deletions
diff --git a/src/include/cbfs.h b/src/include/cbfs.h
index 9aa2c969ba..2db3c94f90 100644
--- a/src/include/cbfs.h
+++ b/src/include/cbfs.h
@@ -52,6 +52,7 @@
#include <cbfs_core.h>
+int init_backing_media(struct cbfs_media **media, struct cbfs_media *backing);
void *cbfs_load_optionrom(struct cbfs_media *media, uint16_t vendor,
uint16_t device, void * dest);
void *cbfs_load_stage(struct cbfs_media *media, const char *name);
diff --git a/src/lib/cbfs.c b/src/lib/cbfs.c
index 54d159fc86..977141236c 100644
--- a/src/lib/cbfs.c
+++ b/src/lib/cbfs.c
@@ -76,6 +76,10 @@ void *cbfs_load_optionrom(struct cbfs_media *media, uint16_t vendor,
void *cbfs_load_stage_by_offset(struct cbfs_media *media, ssize_t offset)
{
struct cbfs_stage stage;
+ struct cbfs_media backing_store;
+
+ if (init_backing_media(&media, &backing_store))
+ return (void *)-1;
if (cbfs_read(media, &stage, offset, sizeof(stage)) != sizeof(stage)) {
ERROR("ERROR: failed to read stage header\n");
@@ -116,6 +120,10 @@ void *cbfs_load_stage(struct cbfs_media *media, const char *name)
{
struct cbfs_file file;
ssize_t offset;
+ struct cbfs_media backing_store;
+
+ if (init_backing_media(&media, &backing_store))
+ return (void *)-1;
offset = cbfs_locate_file(media, &file, name);
if (offset < 0 || file.type != CBFS_TYPE_STAGE)
diff --git a/src/lib/cbfs_core.c b/src/lib/cbfs_core.c
index c28a8658d0..acd434fb48 100644
--- a/src/lib/cbfs_core.c
+++ b/src/lib/cbfs_core.c
@@ -94,7 +94,7 @@ const struct cbfs_header *cbfs_get_header(struct cbfs_media *media)
}
-static int init_media(struct cbfs_media **media, struct cbfs_media *backing)
+int init_backing_media(struct cbfs_media **media, struct cbfs_media *backing)
{
if (*media == CBFS_DEFAULT_MEDIA) {
*media = backing;
@@ -115,7 +115,7 @@ ssize_t cbfs_locate_file(struct cbfs_media *media, struct cbfs_file *file,
const struct cbfs_header *header;
struct cbfs_media default_media;
- if (init_media(&media, &default_media))
+ if (init_backing_media(&media, &default_media))
return -1;
if (CBFS_HEADER_INVALID_ADDRESS == (header = cbfs_get_header(media)))
@@ -200,7 +200,7 @@ size_t cbfs_read(struct cbfs_media *media, void *dest, size_t offset,
struct cbfs_media default_media;
size_t nread;
- if (init_media(&media, &default_media))
+ if (init_backing_media(&media, &default_media))
return 0;
media->open(media);
@@ -216,7 +216,7 @@ struct cbfs_file *cbfs_get_file(struct cbfs_media *media, const char *name)
struct cbfs_file file, *file_ptr;
ssize_t offset;
- if (init_media(&media, &default_media))
+ if (init_backing_media(&media, &default_media))
return NULL;
offset = cbfs_locate_file(media, &file, name);