14f6ad66aSAchin Gupta /* 2*4c0d0390SSoby Mathew * Copyright (c) 2013-2016, ARM Limited and Contributors. All rights reserved. 34f6ad66aSAchin Gupta * 44f6ad66aSAchin Gupta * Redistribution and use in source and binary forms, with or without 54f6ad66aSAchin Gupta * modification, are permitted provided that the following conditions are met: 64f6ad66aSAchin Gupta * 74f6ad66aSAchin Gupta * Redistributions of source code must retain the above copyright notice, this 84f6ad66aSAchin Gupta * list of conditions and the following disclaimer. 94f6ad66aSAchin Gupta * 104f6ad66aSAchin Gupta * Redistributions in binary form must reproduce the above copyright notice, 114f6ad66aSAchin Gupta * this list of conditions and the following disclaimer in the documentation 124f6ad66aSAchin Gupta * and/or other materials provided with the distribution. 134f6ad66aSAchin Gupta * 144f6ad66aSAchin Gupta * Neither the name of ARM nor the names of its contributors may be used 154f6ad66aSAchin Gupta * to endorse or promote products derived from this software without specific 164f6ad66aSAchin Gupta * prior written permission. 174f6ad66aSAchin Gupta * 184f6ad66aSAchin Gupta * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 194f6ad66aSAchin Gupta * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 204f6ad66aSAchin Gupta * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 214f6ad66aSAchin Gupta * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 224f6ad66aSAchin Gupta * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 234f6ad66aSAchin Gupta * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 244f6ad66aSAchin Gupta * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 254f6ad66aSAchin Gupta * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 264f6ad66aSAchin Gupta * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 274f6ad66aSAchin Gupta * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 284f6ad66aSAchin Gupta * POSSIBILITY OF SUCH DAMAGE. 294f6ad66aSAchin Gupta */ 304f6ad66aSAchin Gupta 3197043ac9SDan Handley #include <arch.h> 324f6ad66aSAchin Gupta #include <arch_helpers.h> 3397043ac9SDan Handley #include <assert.h> 341779ba6bSJuan Castillo #include <auth_mod.h> 354f6ad66aSAchin Gupta #include <bl_common.h> 3635e98e55SDan Handley #include <debug.h> 378f55dfb4SSandrine Bailleux #include <errno.h> 3897043ac9SDan Handley #include <io_storage.h> 3997043ac9SDan Handley #include <platform.h> 40fedbc049SJuan Castillo #include <string.h> 413ca9928dSSoby Mathew #include <xlat_tables.h> 424f6ad66aSAchin Gupta 43*4c0d0390SSoby Mathew uintptr_t page_align(uintptr_t value, unsigned dir) 444f6ad66aSAchin Gupta { 454f6ad66aSAchin Gupta /* Round up the limit to the next page boundary */ 46*4c0d0390SSoby Mathew if (value & (PAGE_SIZE - 1)) { 47*4c0d0390SSoby Mathew value &= ~(PAGE_SIZE - 1); 484f6ad66aSAchin Gupta if (dir == UP) 49*4c0d0390SSoby Mathew value += PAGE_SIZE; 504f6ad66aSAchin Gupta } 514f6ad66aSAchin Gupta 524f6ad66aSAchin Gupta return value; 534f6ad66aSAchin Gupta } 544f6ad66aSAchin Gupta 55*4c0d0390SSoby Mathew static inline unsigned int is_page_aligned (uintptr_t addr) { 56*4c0d0390SSoby Mathew return (addr & (PAGE_SIZE - 1)) == 0; 574f6ad66aSAchin Gupta } 584f6ad66aSAchin Gupta 598f55dfb4SSandrine Bailleux /****************************************************************************** 608f55dfb4SSandrine Bailleux * Determine whether the memory region delimited by 'addr' and 'size' is free, 618f55dfb4SSandrine Bailleux * given the extents of free memory. 628f55dfb4SSandrine Bailleux * Return 1 if it is free, 0 otherwise. 638f55dfb4SSandrine Bailleux *****************************************************************************/ 64*4c0d0390SSoby Mathew static int is_mem_free(uintptr_t free_base, size_t free_size, 65*4c0d0390SSoby Mathew uintptr_t addr, size_t size) 664f6ad66aSAchin Gupta { 678f55dfb4SSandrine Bailleux return (addr >= free_base) && (addr + size <= free_base + free_size); 684f6ad66aSAchin Gupta } 694f6ad66aSAchin Gupta 708f55dfb4SSandrine Bailleux /****************************************************************************** 718f55dfb4SSandrine Bailleux * Inside a given memory region, determine whether a sub-region of memory is 728f55dfb4SSandrine Bailleux * closer from the top or the bottom of the encompassing region. Return the 738f55dfb4SSandrine Bailleux * size of the smallest chunk of free memory surrounding the sub-region in 748f55dfb4SSandrine Bailleux * 'small_chunk_size'. 758f55dfb4SSandrine Bailleux *****************************************************************************/ 76*4c0d0390SSoby Mathew static unsigned int choose_mem_pos(uintptr_t mem_start, uintptr_t mem_end, 77*4c0d0390SSoby Mathew uintptr_t submem_start, uintptr_t submem_end, 788f55dfb4SSandrine Bailleux size_t *small_chunk_size) 798f55dfb4SSandrine Bailleux { 808f55dfb4SSandrine Bailleux size_t top_chunk_size, bottom_chunk_size; 814f6ad66aSAchin Gupta 828f55dfb4SSandrine Bailleux assert(mem_start <= submem_start); 838f55dfb4SSandrine Bailleux assert(submem_start <= submem_end); 848f55dfb4SSandrine Bailleux assert(submem_end <= mem_end); 858f55dfb4SSandrine Bailleux assert(small_chunk_size != NULL); 868f55dfb4SSandrine Bailleux 878f55dfb4SSandrine Bailleux top_chunk_size = mem_end - submem_end; 888f55dfb4SSandrine Bailleux bottom_chunk_size = submem_start - mem_start; 898f55dfb4SSandrine Bailleux 908f55dfb4SSandrine Bailleux if (top_chunk_size < bottom_chunk_size) { 918f55dfb4SSandrine Bailleux *small_chunk_size = top_chunk_size; 928f55dfb4SSandrine Bailleux return TOP; 938f55dfb4SSandrine Bailleux } else { 948f55dfb4SSandrine Bailleux *small_chunk_size = bottom_chunk_size; 958f55dfb4SSandrine Bailleux return BOTTOM; 968f55dfb4SSandrine Bailleux } 978f55dfb4SSandrine Bailleux } 988f55dfb4SSandrine Bailleux 998f55dfb4SSandrine Bailleux /****************************************************************************** 1008f55dfb4SSandrine Bailleux * Reserve the memory region delimited by 'addr' and 'size'. The extents of free 1018f55dfb4SSandrine Bailleux * memory are passed in 'free_base' and 'free_size' and they will be updated to 1028f55dfb4SSandrine Bailleux * reflect the memory usage. 1038f55dfb4SSandrine Bailleux * The caller must ensure the memory to reserve is free. 1048f55dfb4SSandrine Bailleux *****************************************************************************/ 105*4c0d0390SSoby Mathew void reserve_mem(uintptr_t *free_base, size_t *free_size, 106*4c0d0390SSoby Mathew uintptr_t addr, size_t size) 1078f55dfb4SSandrine Bailleux { 1088f55dfb4SSandrine Bailleux size_t discard_size; 1098f55dfb4SSandrine Bailleux size_t reserved_size; 1108f55dfb4SSandrine Bailleux unsigned int pos; 1118f55dfb4SSandrine Bailleux 1128f55dfb4SSandrine Bailleux assert(free_base != NULL); 1138f55dfb4SSandrine Bailleux assert(free_size != NULL); 1148f55dfb4SSandrine Bailleux assert(is_mem_free(*free_base, *free_size, addr, size)); 1158f55dfb4SSandrine Bailleux 1168f55dfb4SSandrine Bailleux pos = choose_mem_pos(*free_base, *free_base + *free_size, 1178f55dfb4SSandrine Bailleux addr, addr + size, 1188f55dfb4SSandrine Bailleux &discard_size); 1198f55dfb4SSandrine Bailleux 1208f55dfb4SSandrine Bailleux reserved_size = size + discard_size; 1218f55dfb4SSandrine Bailleux *free_size -= reserved_size; 1228f55dfb4SSandrine Bailleux 1238f55dfb4SSandrine Bailleux if (pos == BOTTOM) 1248f55dfb4SSandrine Bailleux *free_base = addr + size; 1258f55dfb4SSandrine Bailleux 126*4c0d0390SSoby Mathew VERBOSE("Reserved 0x%zx bytes (discarded 0x%zx bytes %s)\n", 1278f55dfb4SSandrine Bailleux reserved_size, discard_size, 1288f55dfb4SSandrine Bailleux pos == TOP ? "above" : "below"); 1294f6ad66aSAchin Gupta } 1304f6ad66aSAchin Gupta 131*4c0d0390SSoby Mathew static void dump_load_info(uintptr_t image_load_addr, 132*4c0d0390SSoby Mathew size_t image_size, 133fb037bfbSDan Handley const meminfo_t *mem_layout) 1344f6ad66aSAchin Gupta { 135*4c0d0390SSoby Mathew INFO("Trying to load image at address %p, size = 0x%zx\n", 136*4c0d0390SSoby Mathew (void *)image_load_addr, image_size); 1376ad2e461SDan Handley INFO("Current memory layout:\n"); 138*4c0d0390SSoby Mathew INFO(" total region = [%p, %p]\n", (void *)mem_layout->total_base, 139*4c0d0390SSoby Mathew (void *)(mem_layout->total_base + mem_layout->total_size)); 140*4c0d0390SSoby Mathew INFO(" free region = [%p, %p]\n", (void *)mem_layout->free_base, 141*4c0d0390SSoby Mathew (void *)(mem_layout->free_base + mem_layout->free_size)); 1424f6ad66aSAchin Gupta } 1434f6ad66aSAchin Gupta 144ee9ad785SRyan Harkin /* Generic function to return the size of an image */ 145*4c0d0390SSoby Mathew size_t image_size(unsigned int image_id) 146ee9ad785SRyan Harkin { 147625de1d4SDan Handley uintptr_t dev_handle; 148625de1d4SDan Handley uintptr_t image_handle; 149625de1d4SDan Handley uintptr_t image_spec; 150ee9ad785SRyan Harkin size_t image_size = 0; 151e098e244SJuan Castillo int io_result; 152ee9ad785SRyan Harkin 153ee9ad785SRyan Harkin /* Obtain a reference to the image by querying the platform layer */ 15416948ae1SJuan Castillo io_result = plat_get_image_source(image_id, &dev_handle, &image_spec); 155e098e244SJuan Castillo if (io_result != 0) { 15616948ae1SJuan Castillo WARN("Failed to obtain reference to image id=%u (%i)\n", 15716948ae1SJuan Castillo image_id, io_result); 158ee9ad785SRyan Harkin return 0; 159ee9ad785SRyan Harkin } 160ee9ad785SRyan Harkin 161ee9ad785SRyan Harkin /* Attempt to access the image */ 162ee9ad785SRyan Harkin io_result = io_open(dev_handle, image_spec, &image_handle); 163e098e244SJuan Castillo if (io_result != 0) { 16416948ae1SJuan Castillo WARN("Failed to access image id=%u (%i)\n", 16516948ae1SJuan Castillo image_id, io_result); 166ee9ad785SRyan Harkin return 0; 167ee9ad785SRyan Harkin } 168ee9ad785SRyan Harkin 169ee9ad785SRyan Harkin /* Find the size of the image */ 170ee9ad785SRyan Harkin io_result = io_size(image_handle, &image_size); 171e098e244SJuan Castillo if ((io_result != 0) || (image_size == 0)) { 17216948ae1SJuan Castillo WARN("Failed to determine the size of the image id=%u (%i)\n", 17316948ae1SJuan Castillo image_id, io_result); 174ee9ad785SRyan Harkin } 175ee9ad785SRyan Harkin io_result = io_close(image_handle); 176ee9ad785SRyan Harkin /* Ignore improbable/unrecoverable error in 'close' */ 177ee9ad785SRyan Harkin 178ee9ad785SRyan Harkin /* TODO: Consider maintaining open device connection from this 179ee9ad785SRyan Harkin * bootloader stage 180ee9ad785SRyan Harkin */ 181ee9ad785SRyan Harkin io_result = io_dev_close(dev_handle); 182ee9ad785SRyan Harkin /* Ignore improbable/unrecoverable error in 'dev_close' */ 183ee9ad785SRyan Harkin 184ee9ad785SRyan Harkin return image_size; 185ee9ad785SRyan Harkin } 1868f55dfb4SSandrine Bailleux 1874f6ad66aSAchin Gupta /******************************************************************************* 188a6b995fbSSandrine Bailleux * Generic function to load an image at a specific address given an image ID and 189a6b995fbSSandrine Bailleux * extents of free memory. 190a6b995fbSSandrine Bailleux * 191a6b995fbSSandrine Bailleux * If the load is successful then the image information is updated. 192a6b995fbSSandrine Bailleux * 193a6b995fbSSandrine Bailleux * If the entry_point_info argument is not NULL then this function also updates: 194a6b995fbSSandrine Bailleux * - the memory layout to mark the memory as reserved; 195a6b995fbSSandrine Bailleux * - the entry point information. 196a6b995fbSSandrine Bailleux * 197a6b995fbSSandrine Bailleux * The caller might pass a NULL pointer for the entry point if they are not 198a6b995fbSSandrine Bailleux * interested in this information. This is typically the case for non-executable 199a6b995fbSSandrine Bailleux * images (e.g. certificates) and executable images that won't ever be executed 200a6b995fbSSandrine Bailleux * on the application processor (e.g. additional microcontroller firmware). 201a6b995fbSSandrine Bailleux * 2028f55dfb4SSandrine Bailleux * Returns 0 on success, a negative error code otherwise. 2034f6ad66aSAchin Gupta ******************************************************************************/ 2044112bfa0SVikram Kanigiri int load_image(meminfo_t *mem_layout, 20516948ae1SJuan Castillo unsigned int image_id, 2061779ba6bSJuan Castillo uintptr_t image_base, 2074112bfa0SVikram Kanigiri image_info_t *image_data, 2084112bfa0SVikram Kanigiri entry_point_info_t *entry_point_info) 2094f6ad66aSAchin Gupta { 210625de1d4SDan Handley uintptr_t dev_handle; 211625de1d4SDan Handley uintptr_t image_handle; 212625de1d4SDan Handley uintptr_t image_spec; 2138f55dfb4SSandrine Bailleux size_t image_size; 2148f55dfb4SSandrine Bailleux size_t bytes_read; 21578460a05SJuan Castillo int io_result; 2164f6ad66aSAchin Gupta 2179d72b4eaSJames Morrissey assert(mem_layout != NULL); 2188f55dfb4SSandrine Bailleux assert(image_data != NULL); 2194112bfa0SVikram Kanigiri assert(image_data->h.version >= VERSION_1); 2209d72b4eaSJames Morrissey 2219d72b4eaSJames Morrissey /* Obtain a reference to the image by querying the platform layer */ 22216948ae1SJuan Castillo io_result = plat_get_image_source(image_id, &dev_handle, &image_spec); 22378460a05SJuan Castillo if (io_result != 0) { 22416948ae1SJuan Castillo WARN("Failed to obtain reference to image id=%u (%i)\n", 22516948ae1SJuan Castillo image_id, io_result); 2264112bfa0SVikram Kanigiri return io_result; 2274f6ad66aSAchin Gupta } 2284f6ad66aSAchin Gupta 2299d72b4eaSJames Morrissey /* Attempt to access the image */ 2309d72b4eaSJames Morrissey io_result = io_open(dev_handle, image_spec, &image_handle); 23178460a05SJuan Castillo if (io_result != 0) { 23216948ae1SJuan Castillo WARN("Failed to access image id=%u (%i)\n", 23316948ae1SJuan Castillo image_id, io_result); 2344112bfa0SVikram Kanigiri return io_result; 2354f6ad66aSAchin Gupta } 2364f6ad66aSAchin Gupta 237f0dd061aSAntonio Nino Diaz INFO("Loading image id=%u at address %p\n", image_id, 238f0dd061aSAntonio Nino Diaz (void *) image_base); 2398f55dfb4SSandrine Bailleux 2409d72b4eaSJames Morrissey /* Find the size of the image */ 2419d72b4eaSJames Morrissey io_result = io_size(image_handle, &image_size); 24278460a05SJuan Castillo if ((io_result != 0) || (image_size == 0)) { 24316948ae1SJuan Castillo WARN("Failed to determine the size of the image id=%u (%i)\n", 24416948ae1SJuan Castillo image_id, io_result); 2454112bfa0SVikram Kanigiri goto exit; 2469d72b4eaSJames Morrissey } 2479d72b4eaSJames Morrissey 2488f55dfb4SSandrine Bailleux /* Check that the memory where the image will be loaded is free */ 2498f55dfb4SSandrine Bailleux if (!is_mem_free(mem_layout->free_base, mem_layout->free_size, 2508f55dfb4SSandrine Bailleux image_base, image_size)) { 251f0dd061aSAntonio Nino Diaz WARN("Failed to reserve memory: %p - %p\n", (void *) image_base, 252f0dd061aSAntonio Nino Diaz (void *) (image_base + image_size)); 2539d72b4eaSJames Morrissey dump_load_info(image_base, image_size, mem_layout); 2544112bfa0SVikram Kanigiri io_result = -ENOMEM; 2554112bfa0SVikram Kanigiri goto exit; 2564f6ad66aSAchin Gupta } 2574f6ad66aSAchin Gupta 2584f6ad66aSAchin Gupta /* We have enough space so load the image now */ 2599d72b4eaSJames Morrissey /* TODO: Consider whether to try to recover/retry a partially successful read */ 260625de1d4SDan Handley io_result = io_read(image_handle, image_base, image_size, &bytes_read); 26178460a05SJuan Castillo if ((io_result != 0) || (bytes_read < image_size)) { 26216948ae1SJuan Castillo WARN("Failed to load image id=%u (%i)\n", image_id, io_result); 2634112bfa0SVikram Kanigiri goto exit; 2644f6ad66aSAchin Gupta } 2654f6ad66aSAchin Gupta 266a6b995fbSSandrine Bailleux image_data->image_base = image_base; 267a6b995fbSSandrine Bailleux image_data->image_size = image_size; 268a6b995fbSSandrine Bailleux 2698f55dfb4SSandrine Bailleux /* 2708f55dfb4SSandrine Bailleux * Update the memory usage info. 2718f55dfb4SSandrine Bailleux * This is done after the actual loading so that it is not updated when 2728f55dfb4SSandrine Bailleux * the load is unsuccessful. 273c5fb47c3SJuan Castillo * If the caller does not provide an entry point, bypass the memory 274c5fb47c3SJuan Castillo * reservation. 2758f55dfb4SSandrine Bailleux */ 276c5fb47c3SJuan Castillo if (entry_point_info != NULL) { 2778f55dfb4SSandrine Bailleux reserve_mem(&mem_layout->free_base, &mem_layout->free_size, 2788f55dfb4SSandrine Bailleux image_base, image_size); 279a6b995fbSSandrine Bailleux entry_point_info->pc = image_base; 280c5fb47c3SJuan Castillo } else { 281f0dd061aSAntonio Nino Diaz INFO("Skip reserving memory: %p - %p\n", (void *) image_base, 282f0dd061aSAntonio Nino Diaz (void *) (image_base + image_size)); 283c5fb47c3SJuan Castillo } 2848f55dfb4SSandrine Bailleux 2854f6ad66aSAchin Gupta /* 2868f55dfb4SSandrine Bailleux * File has been successfully loaded. 287a6b995fbSSandrine Bailleux * Flush the image in Trusted SRAM so that the next exception level can 288a6b995fbSSandrine Bailleux * see it. 2894f6ad66aSAchin Gupta */ 2909d72b4eaSJames Morrissey flush_dcache_range(image_base, image_size); 2914f6ad66aSAchin Gupta 292f0dd061aSAntonio Nino Diaz INFO("Image id=%u loaded: %p - %p\n", image_id, (void *) image_base, 293f0dd061aSAntonio Nino Diaz (void *) (image_base + image_size)); 2949d72b4eaSJames Morrissey 2959d72b4eaSJames Morrissey exit: 2964112bfa0SVikram Kanigiri io_close(image_handle); 2979d72b4eaSJames Morrissey /* Ignore improbable/unrecoverable error in 'close' */ 2989d72b4eaSJames Morrissey 2999d72b4eaSJames Morrissey /* TODO: Consider maintaining open device connection from this bootloader stage */ 3004112bfa0SVikram Kanigiri io_dev_close(dev_handle); 3019d72b4eaSJames Morrissey /* Ignore improbable/unrecoverable error in 'dev_close' */ 3024f6ad66aSAchin Gupta 3034112bfa0SVikram Kanigiri return io_result; 3044f6ad66aSAchin Gupta } 3051779ba6bSJuan Castillo 3061779ba6bSJuan Castillo /******************************************************************************* 3071779ba6bSJuan Castillo * Generic function to load and authenticate an image. The image is actually 3081779ba6bSJuan Castillo * loaded by calling the 'load_image()' function. In addition, this function 3091779ba6bSJuan Castillo * uses recursion to authenticate the parent images up to the root of trust. 3101779ba6bSJuan Castillo ******************************************************************************/ 3111779ba6bSJuan Castillo int load_auth_image(meminfo_t *mem_layout, 3121779ba6bSJuan Castillo unsigned int image_id, 3131779ba6bSJuan Castillo uintptr_t image_base, 3141779ba6bSJuan Castillo image_info_t *image_data, 3151779ba6bSJuan Castillo entry_point_info_t *entry_point_info) 3161779ba6bSJuan Castillo { 3171779ba6bSJuan Castillo int rc; 3181779ba6bSJuan Castillo 3191779ba6bSJuan Castillo #if TRUSTED_BOARD_BOOT 3201779ba6bSJuan Castillo unsigned int parent_id; 3211779ba6bSJuan Castillo 3221779ba6bSJuan Castillo /* Use recursion to authenticate parent images */ 3231779ba6bSJuan Castillo rc = auth_mod_get_parent_id(image_id, &parent_id); 3241779ba6bSJuan Castillo if (rc == 0) { 3251779ba6bSJuan Castillo rc = load_auth_image(mem_layout, parent_id, image_base, 3261779ba6bSJuan Castillo image_data, NULL); 32778460a05SJuan Castillo if (rc != 0) { 3281779ba6bSJuan Castillo return rc; 3291779ba6bSJuan Castillo } 3301779ba6bSJuan Castillo } 3311779ba6bSJuan Castillo #endif /* TRUSTED_BOARD_BOOT */ 3321779ba6bSJuan Castillo 3331779ba6bSJuan Castillo /* Load the image */ 3341779ba6bSJuan Castillo rc = load_image(mem_layout, image_id, image_base, image_data, 3351779ba6bSJuan Castillo entry_point_info); 33678460a05SJuan Castillo if (rc != 0) { 33778460a05SJuan Castillo return rc; 3381779ba6bSJuan Castillo } 3391779ba6bSJuan Castillo 3401779ba6bSJuan Castillo #if TRUSTED_BOARD_BOOT 3411779ba6bSJuan Castillo /* Authenticate it */ 3421779ba6bSJuan Castillo rc = auth_mod_verify_img(image_id, 3431779ba6bSJuan Castillo (void *)image_data->image_base, 3441779ba6bSJuan Castillo image_data->image_size); 3451779ba6bSJuan Castillo if (rc != 0) { 346fedbc049SJuan Castillo memset((void *)image_data->image_base, 0x00, 347fedbc049SJuan Castillo image_data->image_size); 348fedbc049SJuan Castillo flush_dcache_range(image_data->image_base, 349fedbc049SJuan Castillo image_data->image_size); 35078460a05SJuan Castillo return -EAUTH; 3511779ba6bSJuan Castillo } 3521779ba6bSJuan Castillo 3531779ba6bSJuan Castillo /* After working with data, invalidate the data cache */ 3541779ba6bSJuan Castillo inv_dcache_range(image_data->image_base, 3551779ba6bSJuan Castillo (size_t)image_data->image_size); 3561779ba6bSJuan Castillo #endif /* TRUSTED_BOARD_BOOT */ 3571779ba6bSJuan Castillo 35878460a05SJuan Castillo return 0; 3591779ba6bSJuan Castillo } 36068a68c92SSandrine Bailleux 36168a68c92SSandrine Bailleux /******************************************************************************* 36268a68c92SSandrine Bailleux * Print the content of an entry_point_info_t structure. 36368a68c92SSandrine Bailleux ******************************************************************************/ 36468a68c92SSandrine Bailleux void print_entry_point_info(const entry_point_info_t *ep_info) 36568a68c92SSandrine Bailleux { 366*4c0d0390SSoby Mathew INFO("Entry point address = %p\n", (void *)ep_info->pc); 367*4c0d0390SSoby Mathew INFO("SPSR = 0x%x\n", ep_info->spsr); 36868a68c92SSandrine Bailleux 36968a68c92SSandrine Bailleux #define PRINT_IMAGE_ARG(n) \ 37068a68c92SSandrine Bailleux VERBOSE("Argument #" #n " = 0x%llx\n", \ 37168a68c92SSandrine Bailleux (unsigned long long) ep_info->args.arg##n) 37268a68c92SSandrine Bailleux 37368a68c92SSandrine Bailleux PRINT_IMAGE_ARG(0); 37468a68c92SSandrine Bailleux PRINT_IMAGE_ARG(1); 37568a68c92SSandrine Bailleux PRINT_IMAGE_ARG(2); 37668a68c92SSandrine Bailleux PRINT_IMAGE_ARG(3); 37768a68c92SSandrine Bailleux PRINT_IMAGE_ARG(4); 37868a68c92SSandrine Bailleux PRINT_IMAGE_ARG(5); 37968a68c92SSandrine Bailleux PRINT_IMAGE_ARG(6); 38068a68c92SSandrine Bailleux PRINT_IMAGE_ARG(7); 38168a68c92SSandrine Bailleux #undef PRINT_IMAGE_ARG 38268a68c92SSandrine Bailleux } 383