mirror of
https://github.com/ARM-software/arm-trusted-firmware.git
synced 2025-04-22 12:34:19 +00:00
bl_common: add image_size()
Fixes ARM-software/tf-issues#42 Some callers of load_image() may need to get the size of the image before/after loading it. Change-Id: I8dc067b69fc711433651a560ba5a8c3519445857 Signed-off-by: Ryan Harkin <ryan.harkin@linaro.org>
This commit is contained in:
parent
48e2ca7967
commit
ee9ad7856c
2 changed files with 45 additions and 0 deletions
|
@ -251,6 +251,50 @@ static void dump_load_info(unsigned long image_load_addr,
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Generic function to return the size of an image */
|
||||||
|
unsigned long image_size(const char *image_name)
|
||||||
|
{
|
||||||
|
io_dev_handle dev_handle;
|
||||||
|
io_handle image_handle;
|
||||||
|
void *image_spec;
|
||||||
|
size_t image_size = 0;
|
||||||
|
int io_result = IO_FAIL;
|
||||||
|
|
||||||
|
assert(image_name != NULL);
|
||||||
|
|
||||||
|
/* Obtain a reference to the image by querying the platform layer */
|
||||||
|
io_result = plat_get_image_source(image_name, &dev_handle, &image_spec);
|
||||||
|
if (io_result != IO_SUCCESS) {
|
||||||
|
WARN("Failed to obtain reference to image '%s' (%i)\n",
|
||||||
|
image_name, io_result);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Attempt to access the image */
|
||||||
|
io_result = io_open(dev_handle, image_spec, &image_handle);
|
||||||
|
if (io_result != IO_SUCCESS) {
|
||||||
|
WARN("Failed to access image '%s' (%i)\n",
|
||||||
|
image_name, io_result);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Find the size of the image */
|
||||||
|
io_result = io_size(image_handle, &image_size);
|
||||||
|
if ((io_result != IO_SUCCESS) || (image_size == 0)) {
|
||||||
|
WARN("Failed to determine the size of the image '%s' file (%i)\n",
|
||||||
|
image_name, io_result);
|
||||||
|
}
|
||||||
|
io_result = io_close(image_handle);
|
||||||
|
/* Ignore improbable/unrecoverable error in 'close' */
|
||||||
|
|
||||||
|
/* TODO: Consider maintaining open device connection from this
|
||||||
|
* bootloader stage
|
||||||
|
*/
|
||||||
|
io_result = io_dev_close(dev_handle);
|
||||||
|
/* Ignore improbable/unrecoverable error in 'dev_close' */
|
||||||
|
|
||||||
|
return image_size;
|
||||||
|
}
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Generic function to load an image into the trusted RAM,
|
* Generic function to load an image into the trusted RAM,
|
||||||
* given a name, extents of free memory & whether the image should be loaded at
|
* given a name, extents of free memory & whether the image should be loaded at
|
||||||
|
|
|
@ -133,6 +133,7 @@ extern void init_bl2_mem_layout(meminfo *,
|
||||||
extern void init_bl31_mem_layout(const meminfo *,
|
extern void init_bl31_mem_layout(const meminfo *,
|
||||||
meminfo *,
|
meminfo *,
|
||||||
unsigned int) __attribute__((weak));
|
unsigned int) __attribute__((weak));
|
||||||
|
extern unsigned long image_size(const char *);
|
||||||
extern unsigned long load_image(meminfo *, const char *, unsigned int, unsigned long);
|
extern unsigned long load_image(meminfo *, const char *, unsigned int, unsigned long);
|
||||||
extern void __dead2 run_image(unsigned long entrypoint,
|
extern void __dead2 run_image(unsigned long entrypoint,
|
||||||
unsigned long spsr,
|
unsigned long spsr,
|
||||||
|
|
Loading…
Add table
Reference in a new issue