spl: Create a function to init spl_load_info

Rather than having every caller set this up individually, create a
common init function. This allows new fields to be added without the
risk of them being left uninited.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Michael Trimarchi <michael@amarulasolutions.com>
This commit is contained in:
Simon Glass 2024-08-22 07:55:02 -06:00 committed by Tom Rini
parent 50a1ed4335
commit 3fd11278ff
18 changed files with 57 additions and 76 deletions

View file

@ -282,28 +282,32 @@ static inline void *spl_image_fdt_addr(struct spl_image_info *info)
#endif
}
struct spl_load_info;
/**
* spl_load_reader() - Read from device
*
* @load: Information about the load state
* @offset: Offset to read from in bytes. This must be a multiple of
* @load->bl_len.
* @count: Number of bytes to read. This must be a multiple of
* @load->bl_len.
* @buf: Buffer to read into
* @return number of bytes read, 0 on error
*/
typedef ulong (*spl_load_reader)(struct spl_load_info *load, ulong sector,
ulong count, void *buf);
/**
* Information required to load data from a device
*
* @read: Function to call to read from the device
* @priv: Private data for the device
* @bl_len: Block length for reading in bytes
* @read: Function to call to read from the device
*/
struct spl_load_info {
spl_load_reader read;
void *priv;
/**
* read() - Read from device
*
* @load: Information about the load state
* @offset: Offset to read from in bytes. This must be a multiple of
* @load->bl_len.
* @count: Number of bytes to read. This must be a multiple of
* @load->bl_len.
* @buf: Buffer to read into
* @return number of bytes read, 0 on error
*/
ulong (*read)(struct spl_load_info *load, ulong sector, ulong count,
void *buf);
#if IS_ENABLED(CONFIG_SPL_LOAD_BLOCK)
int bl_len;
#endif
@ -328,6 +332,18 @@ static inline void spl_set_bl_len(struct spl_load_info *info, int bl_len)
#endif
}
/**
* spl_load_init() - Set up a new spl_load_info structure
*/
static inline void spl_load_init(struct spl_load_info *load,
spl_load_reader h_read, void *priv,
uint bl_len)
{
load->read = h_read;
load->priv = priv;
spl_set_bl_len(load, bl_len);
}
/*
* We need to know the position of U-Boot in memory so we can jump to it. We
* allow any U-Boot binary to be used (u-boot.bin, u-boot-nodtb.bin,