aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Harkin <ryan.harkin@linaro.org>2014-02-04 11:43:57 +0000
committerRyan Harkin <ryan.harkin@linaro.org>2014-02-25 17:39:23 +0000
commit99182aa3860b84ecd49f7351dacca93864b1f05d (patch)
treeaf6ef4541bbe0c18944306f58ebfec9c68e7f9d1
parentd59a6c6dbd1fe809d2788447a44cc82341005a8f (diff)
bl_common: add image_size()ryan-issue-42
Fixes issue #42: https://github.com/ARM-software/tf-issues/issues/42 Some callers of load_image() may need to get the size of the image before/after loading it. Signed-off-by: Ryan Harkin <ryan.harkin@linaro.org>
-rw-r--r--common/bl_common.c48
-rw-r--r--include/bl_common.h1
2 files changed, 49 insertions, 0 deletions
diff --git a/common/bl_common.c b/common/bl_common.c
index 9afae95..fcafaa6 100644
--- a/common/bl_common.c
+++ b/common/bl_common.c
@@ -251,6 +251,54 @@ static void dump_load_info(unsigned long image_load_addr,
#endif
}
+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;
+
+ /* TODO: Rework all error reports in this function to use the new error macros */
+ if (image_name == NULL) {
+ printf("ERROR: Invalid argument(s) (image:'%s')\r\n",
+ image_name);
+ return 0;
+ }
+
+ /* 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) {
+ printf("ERROR: Failed to obtain reference to image '%s' (%i)\r\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) {
+ printf("ERROR: Failed to access image '%s' (%i)\r\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) ) {
+ /* TODO: Rework all error reports in this section to use the new error macros */
+ printf("ERROR: Failed to determine the size of the image '%s' file (%i)\r\n",
+ image_name, io_result);
+ return 0;
+ }
+
+ io_result = io_close(image_handle);
+
+ /* TODO: Consider issuing warning for failure to close IO */
+ /* TODO: Consider maintaining open device connection from this bootloader stage */
+ io_result = io_dev_close(dev_handle);
+
+ return image_size;
+}
/*******************************************************************************
* Generic function to load an image into the trusted RAM,
* given a name, extents of free memory & whether the image should be loaded at
diff --git a/include/bl_common.h b/include/bl_common.h
index aad3d22..81c6b41 100644
--- a/include/bl_common.h
+++ b/include/bl_common.h
@@ -133,6 +133,7 @@ extern void init_bl2_mem_layout(meminfo *,
extern void init_bl31_mem_layout(const meminfo *,
meminfo *,
unsigned int) __attribute__((weak));
+extern unsigned long image_size(const char *);
extern unsigned long load_image(meminfo *, const char *, unsigned int, unsigned long);
extern void __dead2 run_image(unsigned long entrypoint,
unsigned long spsr,