Commit 9e7d6631 authored by Sandrine Bailleux's avatar Sandrine Bailleux
Browse files

Refactor load_auth_image_internal().



The pre-processor directives make it hard to read the non-TBB version of
this function. Refactor the code to improve readability. No functional
change introduced.

In particular, introduce a new helper function load_image_flush(),
that simply loads an image and flushes it out to main memory. This is
the only thing load_auth_image_internal() needs to do when TBB is
disabled or when authentication is dynamically disabled.

In other cases, we need to recursively authenticate the parent images up
to the root of trust. To make this clearer, this code gets moved to a
TBB-specific helper function called load_auth_image_recursive().

As a result, load_auth_image_internal() now boils down to calling the
right helper function (depending on TBB enablement and dynamic
authentication status).

Change-Id: I20a39a3b833810b97ecf4219358e7d2cac263890
Signed-off-by: default avatarSandrine Bailleux <sandrine.bailleux@arm.com>
parent 1d2b4161
...@@ -143,26 +143,45 @@ exit: ...@@ -143,26 +143,45 @@ exit:
return io_result; return io_result;
} }
static int load_auth_image_internal(unsigned int image_id, /*
image_info_t *image_data, * Load an image and flush it out to main memory so that it can be executed
int is_parent_image) * later by any CPU, regardless of cache and MMU state.
*/
static int load_image_flush(unsigned int image_id,
image_info_t *image_data)
{ {
int rc; int rc;
rc = load_image(image_id, image_data);
if (rc == 0) {
flush_dcache_range(image_data->image_base,
image_data->image_size);
}
return rc;
}
#if TRUSTED_BOARD_BOOT #if TRUSTED_BOARD_BOOT
if (dyn_is_auth_disabled() == 0) { /*
* This function uses recursion to authenticate the parent images up to the root
* of trust.
*/
static int load_auth_image_recursive(unsigned int image_id,
image_info_t *image_data,
int is_parent_image)
{
int rc;
unsigned int parent_id; unsigned int parent_id;
/* Use recursion to authenticate parent images */ /* Use recursion to authenticate parent images */
rc = auth_mod_get_parent_id(image_id, &parent_id); rc = auth_mod_get_parent_id(image_id, &parent_id);
if (rc == 0) { if (rc == 0) {
rc = load_auth_image_internal(parent_id, image_data, 1); rc = load_auth_image_recursive(parent_id, image_data, 1);
if (rc != 0) { if (rc != 0) {
return rc; return rc;
} }
} }
}
#endif /* TRUSTED_BOARD_BOOT */
/* Load the image */ /* Load the image */
rc = load_image(image_id, image_data); rc = load_image(image_id, image_data);
...@@ -170,8 +189,6 @@ static int load_auth_image_internal(unsigned int image_id, ...@@ -170,8 +189,6 @@ static int load_auth_image_internal(unsigned int image_id,
return rc; return rc;
} }
#if TRUSTED_BOARD_BOOT
if (dyn_is_auth_disabled() == 0) {
/* Authenticate it */ /* Authenticate it */
rc = auth_mod_verify_img(image_id, rc = auth_mod_verify_img(image_id,
(void *)image_data->image_base, (void *)image_data->image_base,
...@@ -184,37 +201,46 @@ static int load_auth_image_internal(unsigned int image_id, ...@@ -184,37 +201,46 @@ static int load_auth_image_internal(unsigned int image_id,
image_data->image_size); image_data->image_size);
return -EAUTH; return -EAUTH;
} }
}
#endif /* TRUSTED_BOARD_BOOT */
/* /*
* Flush the image to main memory so that it can be executed later by * Flush the image to main memory so that it can be executed later by
* any CPU, regardless of cache and MMU state. If TBB is enabled, then * any CPU, regardless of cache and MMU state. This is only needed for
* the file has been successfully loaded and authenticated and flush * child images, not for the parents (certificates).
* only for child images, not for the parents (certificates).
*/ */
if (is_parent_image == 0) { if (is_parent_image == 0) {
flush_dcache_range(image_data->image_base, flush_dcache_range(image_data->image_base,
image_data->image_size); image_data->image_size);
} }
return 0; return 0;
} }
#endif /* TRUSTED_BOARD_BOOT */
static int load_auth_image_internal(unsigned int image_id,
image_info_t *image_data)
{
#if TRUSTED_BOARD_BOOT
if (dyn_is_auth_disabled() == 0) {
return load_auth_image_recursive(image_id, image_data, 0);
}
#endif
return load_image_flush(image_id, image_data);
}
/******************************************************************************* /*******************************************************************************
* Generic function to load and authenticate an image. The image is actually * Generic function to load and authenticate an image. The image is actually
* loaded by calling the 'load_image()' function. Therefore, it returns the * loaded by calling the 'load_image()' function. Therefore, it returns the
* same error codes if the loading operation failed, or -EAUTH if the * same error codes if the loading operation failed, or -EAUTH if the
* authentication failed. In addition, this function uses recursion to * authentication failed. In addition, this function uses recursion to
* authenticate the parent images up to the root of trust. * authenticate the parent images up to the root of trust (if TBB is enabled).
******************************************************************************/ ******************************************************************************/
int load_auth_image(unsigned int image_id, image_info_t *image_data) int load_auth_image(unsigned int image_id, image_info_t *image_data)
{ {
int err; int err;
do { do {
err = load_auth_image_internal(image_id, image_data, 0); err = load_auth_image_internal(image_id, image_data);
} while ((err != 0) && (plat_try_next_boot_source() != 0)); } while ((err != 0) && (plat_try_next_boot_source() != 0));
return err; return err;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment