summaryrefslogtreecommitdiff
path: root/src/lib/cbfs_spi.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/cbfs_spi.c')
-rw-r--r--src/lib/cbfs_spi.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/src/lib/cbfs_spi.c b/src/lib/cbfs_spi.c
index 447153295f..2b3728efaa 100644
--- a/src/lib/cbfs_spi.c
+++ b/src/lib/cbfs_spi.c
@@ -70,26 +70,30 @@ static void *cbfs_media_unmap(struct cbfs_media *media,
return cbfs_simple_buffer_unmap(&context->buffer, address);
}
-int init_default_cbfs_media(struct cbfs_media *media)
+static int init_cbfs_media_context(void)
{
- if (spi_context.buffer.buffer)
- return 0; /* It has been already initialized. */
+ if (!spi_context.spi_flash_info) {
- spi_context.spi_flash_info = spi_flash_probe
- (CONFIG_BOOT_MEDIA_SPI_BUS, 0);
- if (!spi_context.spi_flash_info)
- return -1;
+ spi_context.spi_flash_info = spi_flash_probe
+ (CONFIG_BOOT_MEDIA_SPI_BUS, 0);
- spi_context.buffer.buffer = (void *)CONFIG_CBFS_CACHE_ADDRESS;
- spi_context.buffer.size = CONFIG_CBFS_CACHE_SIZE;
+ if (!spi_context.spi_flash_info)
+ return -1;
- media->context = &spi_context;
+ spi_context.buffer.buffer = (void *)CONFIG_CBFS_CACHE_ADDRESS;
+ spi_context.buffer.size = CONFIG_CBFS_CACHE_SIZE;
+ }
+ return 0;
+}
+int init_default_cbfs_media(struct cbfs_media *media)
+{
+ media->context = &spi_context;
media->open = cbfs_media_open;
media->close = cbfs_media_close;
media->read = cbfs_media_read;
media->map = cbfs_media_map;
media->unmap = cbfs_media_unmap;
- return 0;
+ return init_cbfs_media_context();
}