static const u32 good_magic = 0x4f524243;
static const u8 good_file_magic[] = "LARCHIVE";
+/**
+ * struct cbfs_priv - Private data for this driver
+ *
+ * @initialised: true if this CBFS has been inited
+ * @start: Start position of CBFS in memory, typically memory-mapped SPI flash
+ * @header: Header read from the CBFS, byte-swapped so U-Boot can access it
+ * @file_cache: List of file headers read from CBFS
+ * @result: Success/error result
+ */
struct cbfs_priv {
bool initialized;
+ void *start;
struct cbfs_header header;
struct cbfs_cachenode *file_cache;
enum cbfs_result result;
}
/* Look through a CBFS instance and copy file metadata into regular memory. */
-static int file_cbfs_fill_cache(struct cbfs_priv *priv, void *start, u32 size,
- u32 align)
+static int file_cbfs_fill_cache(struct cbfs_priv *priv, int size, int align)
{
struct cbfs_cachenode *cache_node;
struct cbfs_cachenode *new_node;
struct cbfs_cachenode **cache_tail = &priv->file_cache;
+ void *start;
/* Clear out old information. */
cache_node = priv->file_cache;
}
priv->file_cache = NULL;
+ start = priv->start;
while (size >= align) {
int used;
int ret;
static int file_cbfs_load_header(struct cbfs_priv *priv, ulong end_of_rom)
{
int offset = *(u32 *)(end_of_rom - 3);
+ int ret;
+
+ ret = load_header(priv, end_of_rom + offset + 1);
+ if (ret)
+ return ret;
+ priv->start = (void *)(end_of_rom + 1 - priv->header.rom_size);
- return load_header(priv, end_of_rom + offset + 1);
+ return 0;
}
/**
*/
static int cbfs_load_header_ptr(struct cbfs_priv *priv, ulong base)
{
- return load_header(priv, base + MASTER_HDR_OFFSET);
+ int ret;
+
+ ret = load_header(priv, base + MASTER_HDR_OFFSET);
+ if (ret)
+ return ret;
+ priv->start = (void *)base;
+
+ return 0;
}
static void cbfs_init(struct cbfs_priv *priv, ulong end_of_rom)
{
- void *start_of_rom;
-
if (file_cbfs_load_header(priv, end_of_rom))
return;
- start_of_rom = (void *)(end_of_rom + 1 - priv->header.rom_size);
-
- file_cbfs_fill_cache(priv, start_of_rom, priv->header.rom_size,
- priv->header.align);
+ file_cbfs_fill_cache(priv, priv->header.rom_size, priv->header.align);
if (priv->result == CBFS_SUCCESS)
priv->initialized = true;
}
if (ret)
return ret;
- file_cbfs_fill_cache(priv, (void *)base, priv->header.rom_size,
- priv->header.align);
+ file_cbfs_fill_cache(priv, priv->header.rom_size, priv->header.align);
if (priv->result != CBFS_SUCCESS)
return -EINVAL;
if (file_cbfs_load_header(priv, end_of_rom))
return NULL;
- start = (void *)(end_of_rom + 1 - priv->header.rom_size);
+ start = priv->start;
size = priv->header.rom_size;
align = priv->header.align;