Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 1 | /* |
Soby Mathew | 566034f | 2018-02-08 17:45:12 +0000 | [diff] [blame] | 2 | * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved. |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 3 | * |
dp-arm | 82cb2c1 | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 7 | #include <arch_helpers.h> |
Isla Mitchell | 2a4b4b7 | 2017-07-11 14:54:08 +0100 | [diff] [blame] | 8 | #include <assert.h> |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 9 | #include <auth_mod.h> |
| 10 | #include <bl1.h> |
| 11 | #include <bl_common.h> |
| 12 | #include <context.h> |
| 13 | #include <context_mgmt.h> |
| 14 | #include <debug.h> |
| 15 | #include <errno.h> |
| 16 | #include <platform.h> |
| 17 | #include <platform_def.h> |
Antonio Nino Diaz | 085e80e | 2018-03-21 10:49:27 +0000 | [diff] [blame] | 18 | #include <smccc_helpers.h> |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 19 | #include <string.h> |
Sandrine Bailleux | 949a52d | 2016-11-11 16:44:37 +0000 | [diff] [blame] | 20 | #include <utils.h> |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 21 | #include "bl1_private.h" |
| 22 | |
| 23 | /* |
| 24 | * Function declarations. |
| 25 | */ |
| 26 | static int bl1_fwu_image_copy(unsigned int image_id, |
Roberto Vargas | 735181b | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 27 | uintptr_t image_src, |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 28 | unsigned int block_size, |
| 29 | unsigned int image_size, |
| 30 | unsigned int flags); |
| 31 | static int bl1_fwu_image_auth(unsigned int image_id, |
Roberto Vargas | 735181b | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 32 | uintptr_t image_src, |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 33 | unsigned int image_size, |
| 34 | unsigned int flags); |
| 35 | static int bl1_fwu_image_execute(unsigned int image_id, |
| 36 | void **handle, |
| 37 | unsigned int flags); |
Dan Handley | 28955d5 | 2015-12-15 10:52:33 +0000 | [diff] [blame] | 38 | static register_t bl1_fwu_image_resume(register_t image_param, |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 39 | void **handle, |
| 40 | unsigned int flags); |
| 41 | static int bl1_fwu_sec_image_done(void **handle, |
| 42 | unsigned int flags); |
Antonio Nino Diaz | 9d6fc3c | 2017-05-12 16:51:59 +0100 | [diff] [blame] | 43 | static int bl1_fwu_image_reset(unsigned int image_id, |
| 44 | unsigned int flags); |
Dan Handley | 1f37b94 | 2015-12-15 14:28:24 +0000 | [diff] [blame] | 45 | __dead2 static void bl1_fwu_done(void *client_cookie, void *reserved); |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 46 | |
| 47 | /* |
| 48 | * This keeps track of last executed secure image id. |
| 49 | */ |
| 50 | static unsigned int sec_exec_image_id = INVALID_IMAGE_ID; |
| 51 | |
Antonio Nino Diaz | 9d6fc3c | 2017-05-12 16:51:59 +0100 | [diff] [blame] | 52 | /* Authentication status of each image. */ |
Roberto Vargas | 735181b | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 53 | extern unsigned int auth_img_flags[MAX_NUMBER_IDS]; |
Antonio Nino Diaz | 9d6fc3c | 2017-05-12 16:51:59 +0100 | [diff] [blame] | 54 | |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 55 | /******************************************************************************* |
| 56 | * Top level handler for servicing FWU SMCs. |
| 57 | ******************************************************************************/ |
| 58 | register_t bl1_fwu_smc_handler(unsigned int smc_fid, |
| 59 | register_t x1, |
| 60 | register_t x2, |
| 61 | register_t x3, |
| 62 | register_t x4, |
| 63 | void *cookie, |
| 64 | void *handle, |
| 65 | unsigned int flags) |
| 66 | { |
| 67 | |
| 68 | switch (smc_fid) { |
| 69 | case FWU_SMC_IMAGE_COPY: |
| 70 | SMC_RET1(handle, bl1_fwu_image_copy(x1, x2, x3, x4, flags)); |
| 71 | |
| 72 | case FWU_SMC_IMAGE_AUTH: |
| 73 | SMC_RET1(handle, bl1_fwu_image_auth(x1, x2, x3, flags)); |
| 74 | |
| 75 | case FWU_SMC_IMAGE_EXECUTE: |
| 76 | SMC_RET1(handle, bl1_fwu_image_execute(x1, &handle, flags)); |
| 77 | |
| 78 | case FWU_SMC_IMAGE_RESUME: |
Dan Handley | 28955d5 | 2015-12-15 10:52:33 +0000 | [diff] [blame] | 79 | SMC_RET1(handle, bl1_fwu_image_resume(x1, &handle, flags)); |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 80 | |
| 81 | case FWU_SMC_SEC_IMAGE_DONE: |
| 82 | SMC_RET1(handle, bl1_fwu_sec_image_done(&handle, flags)); |
| 83 | |
Antonio Nino Diaz | 9d6fc3c | 2017-05-12 16:51:59 +0100 | [diff] [blame] | 84 | case FWU_SMC_IMAGE_RESET: |
| 85 | SMC_RET1(handle, bl1_fwu_image_reset(x1, flags)); |
| 86 | |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 87 | case FWU_SMC_UPDATE_DONE: |
Dan Handley | 1f37b94 | 2015-12-15 14:28:24 +0000 | [diff] [blame] | 88 | bl1_fwu_done((void *)x1, NULL); |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 89 | /* We should never return from bl1_fwu_done() */ |
Jonathan Wright | c9662db | 2018-03-13 13:54:03 +0000 | [diff] [blame] | 90 | break; |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 91 | |
| 92 | default: |
| 93 | assert(0); |
| 94 | break; |
| 95 | } |
| 96 | |
Antonio Nino Diaz | 7a317a7 | 2017-04-04 17:08:32 +0100 | [diff] [blame] | 97 | SMC_RET1(handle, SMC_UNK); |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | /******************************************************************************* |
Antonio Nino Diaz | 128daee | 2017-06-01 13:40:17 +0100 | [diff] [blame] | 101 | * Utility functions to keep track of the images that are loaded at any time. |
| 102 | ******************************************************************************/ |
| 103 | |
| 104 | #ifdef PLAT_FWU_MAX_SIMULTANEOUS_IMAGES |
| 105 | #define FWU_MAX_SIMULTANEOUS_IMAGES PLAT_FWU_MAX_SIMULTANEOUS_IMAGES |
| 106 | #else |
| 107 | #define FWU_MAX_SIMULTANEOUS_IMAGES 10 |
| 108 | #endif |
| 109 | |
| 110 | static int bl1_fwu_loaded_ids[FWU_MAX_SIMULTANEOUS_IMAGES] = { |
| 111 | [0 ... FWU_MAX_SIMULTANEOUS_IMAGES-1] = INVALID_IMAGE_ID |
| 112 | }; |
| 113 | |
| 114 | /* |
| 115 | * Adds an image_id to the bl1_fwu_loaded_ids array. |
| 116 | * Returns 0 on success, 1 on error. |
| 117 | */ |
| 118 | static int bl1_fwu_add_loaded_id(int image_id) |
| 119 | { |
| 120 | int i; |
| 121 | |
| 122 | /* Check if the ID is already in the list */ |
| 123 | for (i = 0; i < FWU_MAX_SIMULTANEOUS_IMAGES; i++) { |
| 124 | if (bl1_fwu_loaded_ids[i] == image_id) |
| 125 | return 0; |
| 126 | } |
| 127 | |
| 128 | /* Find an empty slot */ |
| 129 | for (i = 0; i < FWU_MAX_SIMULTANEOUS_IMAGES; i++) { |
| 130 | if (bl1_fwu_loaded_ids[i] == INVALID_IMAGE_ID) { |
| 131 | bl1_fwu_loaded_ids[i] = image_id; |
| 132 | return 0; |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | return 1; |
| 137 | } |
| 138 | |
| 139 | /* |
| 140 | * Removes an image_id from the bl1_fwu_loaded_ids array. |
| 141 | * Returns 0 on success, 1 on error. |
| 142 | */ |
| 143 | static int bl1_fwu_remove_loaded_id(int image_id) |
| 144 | { |
| 145 | int i; |
| 146 | |
| 147 | /* Find the ID */ |
| 148 | for (i = 0; i < FWU_MAX_SIMULTANEOUS_IMAGES; i++) { |
| 149 | if (bl1_fwu_loaded_ids[i] == image_id) { |
| 150 | bl1_fwu_loaded_ids[i] = INVALID_IMAGE_ID; |
| 151 | return 0; |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | return 1; |
| 156 | } |
| 157 | |
| 158 | /******************************************************************************* |
| 159 | * This function checks if the specified image overlaps another image already |
| 160 | * loaded. It returns 0 if there is no overlap, a negative error code otherwise. |
| 161 | ******************************************************************************/ |
| 162 | static int bl1_fwu_image_check_overlaps(int image_id) |
| 163 | { |
| 164 | const image_desc_t *image_desc, *checked_image_desc; |
| 165 | const image_info_t *info, *checked_info; |
| 166 | |
| 167 | uintptr_t image_base, image_end; |
| 168 | uintptr_t checked_image_base, checked_image_end; |
| 169 | |
| 170 | checked_image_desc = bl1_plat_get_image_desc(image_id); |
| 171 | checked_info = &checked_image_desc->image_info; |
| 172 | |
| 173 | /* Image being checked mustn't be empty. */ |
| 174 | assert(checked_info->image_size != 0); |
| 175 | |
| 176 | checked_image_base = checked_info->image_base; |
| 177 | checked_image_end = checked_image_base + checked_info->image_size - 1; |
Soby Mathew | ee05ae1 | 2017-06-15 16:11:48 +0100 | [diff] [blame] | 178 | /* No need to check for overflows, it's done in bl1_fwu_image_copy(). */ |
Antonio Nino Diaz | 128daee | 2017-06-01 13:40:17 +0100 | [diff] [blame] | 179 | |
| 180 | for (int i = 0; i < FWU_MAX_SIMULTANEOUS_IMAGES; i++) { |
| 181 | |
Soby Mathew | ee05ae1 | 2017-06-15 16:11:48 +0100 | [diff] [blame] | 182 | /* Skip INVALID_IMAGE_IDs and don't check image against itself */ |
| 183 | if ((bl1_fwu_loaded_ids[i] == INVALID_IMAGE_ID) || |
| 184 | (bl1_fwu_loaded_ids[i] == image_id)) |
Antonio Nino Diaz | 128daee | 2017-06-01 13:40:17 +0100 | [diff] [blame] | 185 | continue; |
| 186 | |
| 187 | image_desc = bl1_plat_get_image_desc(bl1_fwu_loaded_ids[i]); |
| 188 | |
| 189 | /* Only check images that are loaded or being loaded. */ |
Soby Mathew | ee05ae1 | 2017-06-15 16:11:48 +0100 | [diff] [blame] | 190 | assert (image_desc && image_desc->state != IMAGE_STATE_RESET); |
Antonio Nino Diaz | 128daee | 2017-06-01 13:40:17 +0100 | [diff] [blame] | 191 | |
| 192 | info = &image_desc->image_info; |
| 193 | |
| 194 | /* There cannot be overlaps with an empty image. */ |
| 195 | if (info->image_size == 0) |
| 196 | continue; |
| 197 | |
| 198 | image_base = info->image_base; |
| 199 | image_end = image_base + info->image_size - 1; |
| 200 | /* |
| 201 | * Overflows cannot happen. It is checked in |
| 202 | * bl1_fwu_image_copy() when the image goes from RESET to |
| 203 | * COPYING or COPIED. |
| 204 | */ |
| 205 | assert (image_end > image_base); |
| 206 | |
| 207 | /* Check if there are overlaps. */ |
| 208 | if (!(image_end < checked_image_base || |
| 209 | checked_image_end < image_base)) { |
| 210 | VERBOSE("Image with ID %d overlaps existing image with ID %d", |
| 211 | checked_image_desc->image_id, image_desc->image_id); |
| 212 | return -EPERM; |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | return 0; |
| 217 | } |
| 218 | |
| 219 | /******************************************************************************* |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 220 | * This function is responsible for copying secure images in AP Secure RAM. |
| 221 | ******************************************************************************/ |
| 222 | static int bl1_fwu_image_copy(unsigned int image_id, |
| 223 | uintptr_t image_src, |
| 224 | unsigned int block_size, |
| 225 | unsigned int image_size, |
| 226 | unsigned int flags) |
| 227 | { |
Sandrine Bailleux | 9f1489e | 2016-11-11 15:56:20 +0000 | [diff] [blame] | 228 | uintptr_t dest_addr; |
Sandrine Bailleux | b38a9e5 | 2016-11-14 14:56:51 +0000 | [diff] [blame] | 229 | unsigned int remaining; |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 230 | |
| 231 | /* Get the image descriptor. */ |
| 232 | image_desc_t *image_desc = bl1_plat_get_image_desc(image_id); |
Sandrine Bailleux | 9f1489e | 2016-11-11 15:56:20 +0000 | [diff] [blame] | 233 | if (!image_desc) { |
| 234 | WARN("BL1-FWU: Invalid image ID %u\n", image_id); |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 235 | return -EPERM; |
| 236 | } |
| 237 | |
Sandrine Bailleux | 9f1489e | 2016-11-11 15:56:20 +0000 | [diff] [blame] | 238 | /* |
| 239 | * The request must originate from a non-secure caller and target a |
| 240 | * secure image. Any other scenario is invalid. |
| 241 | */ |
| 242 | if (GET_SECURITY_STATE(flags) == SECURE) { |
| 243 | WARN("BL1-FWU: Copy not allowed from secure world.\n"); |
| 244 | return -EPERM; |
| 245 | } |
| 246 | if (GET_SECURITY_STATE(image_desc->ep_info.h.attr) == NON_SECURE) { |
| 247 | WARN("BL1-FWU: Copy not allowed for non-secure images.\n"); |
| 248 | return -EPERM; |
| 249 | } |
| 250 | |
| 251 | /* Check whether the FWU state machine is in the correct state. */ |
| 252 | if ((image_desc->state != IMAGE_STATE_RESET) && |
| 253 | (image_desc->state != IMAGE_STATE_COPYING)) { |
| 254 | WARN("BL1-FWU: Copy not allowed at this point of the FWU" |
| 255 | " process.\n"); |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 256 | return -EPERM; |
| 257 | } |
| 258 | |
Sandrine Bailleux | 949a52d | 2016-11-11 16:44:37 +0000 | [diff] [blame] | 259 | if ((!image_src) || (!block_size) || |
| 260 | check_uptr_overflow(image_src, block_size - 1)) { |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 261 | WARN("BL1-FWU: Copy not allowed due to invalid image source" |
| 262 | " or block size\n"); |
| 263 | return -ENOMEM; |
| 264 | } |
| 265 | |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 266 | if (image_desc->state == IMAGE_STATE_COPYING) { |
Sandrine Bailleux | 1bfb706 | 2016-11-14 14:58:05 +0000 | [diff] [blame] | 267 | /* |
| 268 | * There must have been at least 1 copy operation for this image |
| 269 | * previously. |
| 270 | */ |
| 271 | assert(image_desc->copied_size != 0); |
| 272 | /* |
| 273 | * The image size must have been recorded in the 1st copy |
| 274 | * operation. |
| 275 | */ |
Sandrine Bailleux | 9f1489e | 2016-11-11 15:56:20 +0000 | [diff] [blame] | 276 | image_size = image_desc->image_info.image_size; |
Sandrine Bailleux | 1bfb706 | 2016-11-14 14:58:05 +0000 | [diff] [blame] | 277 | assert(image_size != 0); |
| 278 | assert(image_desc->copied_size < image_size); |
| 279 | |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 280 | INFO("BL1-FWU: Continuing image copy in blocks\n"); |
Sandrine Bailleux | 9f1489e | 2016-11-11 15:56:20 +0000 | [diff] [blame] | 281 | } else { /* image_desc->state == IMAGE_STATE_RESET */ |
| 282 | INFO("BL1-FWU: Initial call to copy an image\n"); |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 283 | |
Sandrine Bailleux | 9f1489e | 2016-11-11 15:56:20 +0000 | [diff] [blame] | 284 | /* |
| 285 | * image_size is relevant only for the 1st copy request, it is |
| 286 | * then ignored for subsequent calls for this image. |
| 287 | */ |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 288 | if (!image_size) { |
Sandrine Bailleux | 9f1489e | 2016-11-11 15:56:20 +0000 | [diff] [blame] | 289 | WARN("BL1-FWU: Copy not allowed due to invalid image" |
| 290 | " size\n"); |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 291 | return -ENOMEM; |
| 292 | } |
| 293 | |
Yatharth Kochar | 53d703a | 2016-11-11 13:57:50 +0000 | [diff] [blame] | 294 | #if LOAD_IMAGE_V2 |
| 295 | /* Check that the image size to load is within limit */ |
| 296 | if (image_size > image_desc->image_info.image_max_size) { |
| 297 | WARN("BL1-FWU: Image size out of bounds\n"); |
| 298 | return -ENOMEM; |
| 299 | } |
| 300 | #else |
Sandrine Bailleux | 949a52d | 2016-11-11 16:44:37 +0000 | [diff] [blame] | 301 | /* |
| 302 | * Check the image will fit into the free trusted RAM after BL1 |
| 303 | * load. |
| 304 | */ |
Sandrine Bailleux | 9f1489e | 2016-11-11 15:56:20 +0000 | [diff] [blame] | 305 | const meminfo_t *mem_layout = bl1_plat_sec_mem_layout(); |
Sandrine Bailleux | 949a52d | 2016-11-11 16:44:37 +0000 | [diff] [blame] | 306 | if (!is_mem_free(mem_layout->free_base, mem_layout->free_size, |
| 307 | image_desc->image_info.image_base, |
| 308 | image_size)) { |
Sandrine Bailleux | 9f1489e | 2016-11-11 15:56:20 +0000 | [diff] [blame] | 309 | WARN("BL1-FWU: Copy not allowed due to insufficient" |
| 310 | " resources.\n"); |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 311 | return -ENOMEM; |
| 312 | } |
Yatharth Kochar | 53d703a | 2016-11-11 13:57:50 +0000 | [diff] [blame] | 313 | #endif |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 314 | |
Sandrine Bailleux | 9f1489e | 2016-11-11 15:56:20 +0000 | [diff] [blame] | 315 | /* Save the given image size. */ |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 316 | image_desc->image_info.image_size = image_size; |
| 317 | |
Antonio Nino Diaz | 128daee | 2017-06-01 13:40:17 +0100 | [diff] [blame] | 318 | /* Make sure the image doesn't overlap other images. */ |
| 319 | if (bl1_fwu_image_check_overlaps(image_id)) { |
| 320 | image_desc->image_info.image_size = 0; |
| 321 | WARN("BL1-FWU: This image overlaps another one\n"); |
| 322 | return -EPERM; |
| 323 | } |
| 324 | |
Sandrine Bailleux | b38a9e5 | 2016-11-14 14:56:51 +0000 | [diff] [blame] | 325 | /* |
| 326 | * copied_size must be explicitly initialized here because the |
| 327 | * FWU code doesn't necessarily do it when it resets the state |
| 328 | * machine. |
| 329 | */ |
| 330 | image_desc->copied_size = 0; |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 331 | } |
| 332 | |
Sandrine Bailleux | b38a9e5 | 2016-11-14 14:56:51 +0000 | [diff] [blame] | 333 | /* |
| 334 | * If the given block size is more than the total image size |
| 335 | * then clip the former to the latter. |
| 336 | */ |
| 337 | remaining = image_size - image_desc->copied_size; |
| 338 | if (block_size > remaining) { |
| 339 | WARN("BL1-FWU: Block size is too big, clipping it.\n"); |
| 340 | block_size = remaining; |
| 341 | } |
| 342 | |
| 343 | /* Make sure the source image is mapped in memory. */ |
| 344 | if (bl1_plat_mem_check(image_src, block_size, flags)) { |
| 345 | WARN("BL1-FWU: Source image is not mapped.\n"); |
| 346 | return -ENOMEM; |
| 347 | } |
| 348 | |
Antonio Nino Diaz | 128daee | 2017-06-01 13:40:17 +0100 | [diff] [blame] | 349 | if (bl1_fwu_add_loaded_id(image_id)) { |
| 350 | WARN("BL1-FWU: Too many images loaded at the same time.\n"); |
| 351 | return -ENOMEM; |
| 352 | } |
| 353 | |
Soby Mathew | 566034f | 2018-02-08 17:45:12 +0000 | [diff] [blame] | 354 | /* Allow the platform to handle pre-image load before copying */ |
| 355 | if (image_desc->state == IMAGE_STATE_RESET) { |
| 356 | if (bl1_plat_handle_pre_image_load(image_id) != 0) { |
| 357 | ERROR("BL1-FWU: Failure in pre-image load of image id %d\n", |
| 358 | image_id); |
| 359 | return -EPERM; |
| 360 | } |
| 361 | } |
| 362 | |
Sandrine Bailleux | b38a9e5 | 2016-11-14 14:56:51 +0000 | [diff] [blame] | 363 | /* Everything looks sane. Go ahead and copy the block of data. */ |
| 364 | dest_addr = image_desc->image_info.image_base + image_desc->copied_size; |
| 365 | memcpy((void *) dest_addr, (const void *) image_src, block_size); |
| 366 | flush_dcache_range(dest_addr, block_size); |
| 367 | |
| 368 | image_desc->copied_size += block_size; |
| 369 | image_desc->state = (block_size == remaining) ? |
| 370 | IMAGE_STATE_COPIED : IMAGE_STATE_COPYING; |
| 371 | |
| 372 | INFO("BL1-FWU: Copy operation successful.\n"); |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 373 | return 0; |
| 374 | } |
| 375 | |
| 376 | /******************************************************************************* |
| 377 | * This function is responsible for authenticating Normal/Secure images. |
| 378 | ******************************************************************************/ |
| 379 | static int bl1_fwu_image_auth(unsigned int image_id, |
| 380 | uintptr_t image_src, |
| 381 | unsigned int image_size, |
| 382 | unsigned int flags) |
| 383 | { |
| 384 | int result; |
| 385 | uintptr_t base_addr; |
| 386 | unsigned int total_size; |
| 387 | |
| 388 | /* Get the image descriptor. */ |
| 389 | image_desc_t *image_desc = bl1_plat_get_image_desc(image_id); |
| 390 | if (!image_desc) |
| 391 | return -EPERM; |
| 392 | |
Yatharth Kochar | 843ddee | 2016-02-01 11:04:46 +0000 | [diff] [blame] | 393 | if (GET_SECURITY_STATE(flags) == SECURE) { |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 394 | if (image_desc->state != IMAGE_STATE_RESET) { |
| 395 | WARN("BL1-FWU: Authentication from secure world " |
| 396 | "while in invalid state\n"); |
| 397 | return -EPERM; |
| 398 | } |
| 399 | } else { |
Yatharth Kochar | 843ddee | 2016-02-01 11:04:46 +0000 | [diff] [blame] | 400 | if (GET_SECURITY_STATE(image_desc->ep_info.h.attr) == SECURE) { |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 401 | if (image_desc->state != IMAGE_STATE_COPIED) { |
| 402 | WARN("BL1-FWU: Authentication of secure image " |
| 403 | "from non-secure world while not in copied state\n"); |
| 404 | return -EPERM; |
| 405 | } |
| 406 | } else { |
| 407 | if (image_desc->state != IMAGE_STATE_RESET) { |
| 408 | WARN("BL1-FWU: Authentication of non-secure image " |
| 409 | "from non-secure world while in invalid state\n"); |
| 410 | return -EPERM; |
| 411 | } |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | if (image_desc->state == IMAGE_STATE_COPIED) { |
| 416 | /* |
| 417 | * Image is in COPIED state. |
| 418 | * Use the stored address and size. |
| 419 | */ |
| 420 | base_addr = image_desc->image_info.image_base; |
| 421 | total_size = image_desc->image_info.image_size; |
| 422 | } else { |
Sandrine Bailleux | 949a52d | 2016-11-11 16:44:37 +0000 | [diff] [blame] | 423 | if ((!image_src) || (!image_size) || |
| 424 | check_uptr_overflow(image_src, image_size - 1)) { |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 425 | WARN("BL1-FWU: Auth not allowed due to invalid" |
| 426 | " image source/size\n"); |
| 427 | return -ENOMEM; |
| 428 | } |
| 429 | |
| 430 | /* |
| 431 | * Image is in RESET state. |
| 432 | * Check the parameters and authenticate the source image in place. |
| 433 | */ |
Dan Handley | 03131c8 | 2015-12-14 16:26:43 +0000 | [diff] [blame] | 434 | if (bl1_plat_mem_check(image_src, image_size, \ |
| 435 | image_desc->ep_info.h.attr)) { |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 436 | WARN("BL1-FWU: Authentication arguments source/size not mapped\n"); |
| 437 | return -ENOMEM; |
| 438 | } |
| 439 | |
Antonio Nino Diaz | 128daee | 2017-06-01 13:40:17 +0100 | [diff] [blame] | 440 | if (bl1_fwu_add_loaded_id(image_id)) { |
| 441 | WARN("BL1-FWU: Too many images loaded at the same time.\n"); |
| 442 | return -ENOMEM; |
| 443 | } |
| 444 | |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 445 | base_addr = image_src; |
| 446 | total_size = image_size; |
| 447 | |
| 448 | /* Update the image size in the descriptor. */ |
| 449 | image_desc->image_info.image_size = total_size; |
| 450 | } |
| 451 | |
| 452 | /* |
| 453 | * Authenticate the image. |
| 454 | */ |
| 455 | INFO("BL1-FWU: Authenticating image_id:%d\n", image_id); |
| 456 | result = auth_mod_verify_img(image_id, (void *)base_addr, total_size); |
| 457 | if (result != 0) { |
| 458 | WARN("BL1-FWU: Authentication Failed err=%d\n", result); |
| 459 | |
| 460 | /* |
| 461 | * Authentication has failed. |
| 462 | * Clear the memory if the image was copied. |
| 463 | * This is to prevent an attack where this contains |
| 464 | * some malicious code that can somehow be executed later. |
| 465 | */ |
| 466 | if (image_desc->state == IMAGE_STATE_COPIED) { |
| 467 | /* Clear the memory.*/ |
Douglas Raillard | 308d359 | 2016-12-02 13:51:54 +0000 | [diff] [blame] | 468 | zero_normalmem((void *)base_addr, total_size); |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 469 | flush_dcache_range(base_addr, total_size); |
| 470 | |
| 471 | /* Indicate that image can be copied again*/ |
| 472 | image_desc->state = IMAGE_STATE_RESET; |
| 473 | } |
Antonio Nino Diaz | 128daee | 2017-06-01 13:40:17 +0100 | [diff] [blame] | 474 | |
| 475 | /* |
| 476 | * Even if this fails it's ok because the ID isn't in the array. |
| 477 | * The image cannot be in RESET state here, it is checked at the |
| 478 | * beginning of the function. |
| 479 | */ |
| 480 | bl1_fwu_remove_loaded_id(image_id); |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 481 | return -EAUTH; |
| 482 | } |
| 483 | |
| 484 | /* Indicate that image is in authenticated state. */ |
| 485 | image_desc->state = IMAGE_STATE_AUTHENTICATED; |
| 486 | |
Soby Mathew | 566034f | 2018-02-08 17:45:12 +0000 | [diff] [blame] | 487 | /* Allow the platform to handle post-image load */ |
| 488 | result = bl1_plat_handle_post_image_load(image_id); |
| 489 | if (result != 0) { |
| 490 | ERROR("BL1-FWU: Failure %d in post-image load of image id %d\n", |
| 491 | result, image_id); |
| 492 | /* |
| 493 | * Panic here as the platform handling of post-image load is |
| 494 | * not correct. |
| 495 | */ |
| 496 | plat_error_handler(result); |
| 497 | } |
| 498 | |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 499 | /* |
| 500 | * Flush image_info to memory so that other |
| 501 | * secure world images can see changes. |
| 502 | */ |
| 503 | flush_dcache_range((unsigned long)&image_desc->image_info, |
| 504 | sizeof(image_info_t)); |
| 505 | |
| 506 | INFO("BL1-FWU: Authentication was successful\n"); |
| 507 | |
| 508 | return 0; |
| 509 | } |
| 510 | |
| 511 | /******************************************************************************* |
| 512 | * This function is responsible for executing Secure images. |
| 513 | ******************************************************************************/ |
| 514 | static int bl1_fwu_image_execute(unsigned int image_id, |
| 515 | void **handle, |
| 516 | unsigned int flags) |
| 517 | { |
| 518 | /* Get the image descriptor. */ |
| 519 | image_desc_t *image_desc = bl1_plat_get_image_desc(image_id); |
| 520 | |
| 521 | /* |
| 522 | * Execution is NOT allowed if: |
Dan Handley | 28955d5 | 2015-12-15 10:52:33 +0000 | [diff] [blame] | 523 | * image_id is invalid OR |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 524 | * Caller is from Secure world OR |
| 525 | * Image is Non-Secure OR |
| 526 | * Image is Non-Executable OR |
| 527 | * Image is NOT in AUTHENTICATED state. |
| 528 | */ |
| 529 | if ((!image_desc) || |
Yatharth Kochar | 843ddee | 2016-02-01 11:04:46 +0000 | [diff] [blame] | 530 | (GET_SECURITY_STATE(flags) == SECURE) || |
| 531 | (GET_SECURITY_STATE(image_desc->ep_info.h.attr) == NON_SECURE) || |
| 532 | (EP_GET_EXE(image_desc->ep_info.h.attr) == NON_EXECUTABLE) || |
| 533 | (image_desc->state != IMAGE_STATE_AUTHENTICATED)) { |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 534 | WARN("BL1-FWU: Execution not allowed due to invalid state/args\n"); |
| 535 | return -EPERM; |
| 536 | } |
| 537 | |
| 538 | INFO("BL1-FWU: Executing Secure image\n"); |
| 539 | |
dp-arm | a440900 | 2017-02-15 11:07:55 +0000 | [diff] [blame] | 540 | #ifdef AARCH64 |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 541 | /* Save NS-EL1 system registers. */ |
| 542 | cm_el1_sysregs_context_save(NON_SECURE); |
dp-arm | a440900 | 2017-02-15 11:07:55 +0000 | [diff] [blame] | 543 | #endif |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 544 | |
| 545 | /* Prepare the image for execution. */ |
| 546 | bl1_prepare_next_image(image_id); |
| 547 | |
| 548 | /* Update the secure image id. */ |
| 549 | sec_exec_image_id = image_id; |
| 550 | |
dp-arm | a440900 | 2017-02-15 11:07:55 +0000 | [diff] [blame] | 551 | #ifdef AARCH64 |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 552 | *handle = cm_get_context(SECURE); |
dp-arm | a440900 | 2017-02-15 11:07:55 +0000 | [diff] [blame] | 553 | #else |
| 554 | *handle = smc_get_ctx(SECURE); |
| 555 | #endif |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 556 | return 0; |
| 557 | } |
| 558 | |
| 559 | /******************************************************************************* |
Dan Handley | 28955d5 | 2015-12-15 10:52:33 +0000 | [diff] [blame] | 560 | * This function is responsible for resuming execution in the other security |
| 561 | * world |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 562 | ******************************************************************************/ |
Dan Handley | 28955d5 | 2015-12-15 10:52:33 +0000 | [diff] [blame] | 563 | static register_t bl1_fwu_image_resume(register_t image_param, |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 564 | void **handle, |
| 565 | unsigned int flags) |
| 566 | { |
| 567 | image_desc_t *image_desc; |
| 568 | unsigned int resume_sec_state; |
Yatharth Kochar | 843ddee | 2016-02-01 11:04:46 +0000 | [diff] [blame] | 569 | unsigned int caller_sec_state = GET_SECURITY_STATE(flags); |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 570 | |
Dan Handley | 28955d5 | 2015-12-15 10:52:33 +0000 | [diff] [blame] | 571 | /* Get the image descriptor for last executed secure image id. */ |
| 572 | image_desc = bl1_plat_get_image_desc(sec_exec_image_id); |
| 573 | if (caller_sec_state == NON_SECURE) { |
| 574 | if (!image_desc) { |
| 575 | WARN("BL1-FWU: Resume not allowed due to no available" |
| 576 | "secure image\n"); |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 577 | return -EPERM; |
| 578 | } |
Dan Handley | 28955d5 | 2015-12-15 10:52:33 +0000 | [diff] [blame] | 579 | } else { |
| 580 | /* image_desc must be valid for secure world callers */ |
| 581 | assert(image_desc); |
| 582 | } |
| 583 | |
Yatharth Kochar | 843ddee | 2016-02-01 11:04:46 +0000 | [diff] [blame] | 584 | assert(GET_SECURITY_STATE(image_desc->ep_info.h.attr) == SECURE); |
| 585 | assert(EP_GET_EXE(image_desc->ep_info.h.attr) == EXECUTABLE); |
Dan Handley | 28955d5 | 2015-12-15 10:52:33 +0000 | [diff] [blame] | 586 | |
| 587 | if (caller_sec_state == SECURE) { |
| 588 | assert(image_desc->state == IMAGE_STATE_EXECUTED); |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 589 | |
| 590 | /* Update the flags. */ |
| 591 | image_desc->state = IMAGE_STATE_INTERRUPTED; |
| 592 | resume_sec_state = NON_SECURE; |
| 593 | } else { |
Dan Handley | 28955d5 | 2015-12-15 10:52:33 +0000 | [diff] [blame] | 594 | assert(image_desc->state == IMAGE_STATE_INTERRUPTED); |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 595 | |
| 596 | /* Update the flags. */ |
| 597 | image_desc->state = IMAGE_STATE_EXECUTED; |
| 598 | resume_sec_state = SECURE; |
| 599 | } |
| 600 | |
dp-arm | a440900 | 2017-02-15 11:07:55 +0000 | [diff] [blame] | 601 | INFO("BL1-FWU: Resuming %s world context\n", |
| 602 | (resume_sec_state == SECURE) ? "secure" : "normal"); |
| 603 | |
| 604 | #ifdef AARCH64 |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 605 | /* Save the EL1 system registers of calling world. */ |
Dan Handley | 28955d5 | 2015-12-15 10:52:33 +0000 | [diff] [blame] | 606 | cm_el1_sysregs_context_save(caller_sec_state); |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 607 | |
| 608 | /* Restore the EL1 system registers of resuming world. */ |
| 609 | cm_el1_sysregs_context_restore(resume_sec_state); |
| 610 | |
| 611 | /* Update the next context. */ |
| 612 | cm_set_next_eret_context(resume_sec_state); |
| 613 | |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 614 | *handle = cm_get_context(resume_sec_state); |
dp-arm | a440900 | 2017-02-15 11:07:55 +0000 | [diff] [blame] | 615 | #else |
| 616 | /* Update the next context. */ |
| 617 | cm_set_next_context(cm_get_context(resume_sec_state)); |
| 618 | |
| 619 | /* Prepare the smc context for the next BL image. */ |
| 620 | smc_set_next_ctx(resume_sec_state); |
| 621 | |
| 622 | *handle = smc_get_ctx(resume_sec_state); |
| 623 | #endif |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 624 | return image_param; |
| 625 | } |
| 626 | |
| 627 | /******************************************************************************* |
| 628 | * This function is responsible for resuming normal world context. |
| 629 | ******************************************************************************/ |
| 630 | static int bl1_fwu_sec_image_done(void **handle, unsigned int flags) |
| 631 | { |
Dan Handley | 28955d5 | 2015-12-15 10:52:33 +0000 | [diff] [blame] | 632 | image_desc_t *image_desc; |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 633 | |
Dan Handley | 28955d5 | 2015-12-15 10:52:33 +0000 | [diff] [blame] | 634 | /* Make sure caller is from the secure world */ |
Yatharth Kochar | 843ddee | 2016-02-01 11:04:46 +0000 | [diff] [blame] | 635 | if (GET_SECURITY_STATE(flags) == NON_SECURE) { |
Dan Handley | 28955d5 | 2015-12-15 10:52:33 +0000 | [diff] [blame] | 636 | WARN("BL1-FWU: Image done not allowed from normal world\n"); |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 637 | return -EPERM; |
| 638 | } |
| 639 | |
Dan Handley | 28955d5 | 2015-12-15 10:52:33 +0000 | [diff] [blame] | 640 | /* Get the image descriptor for last executed secure image id */ |
| 641 | image_desc = bl1_plat_get_image_desc(sec_exec_image_id); |
| 642 | |
| 643 | /* image_desc must correspond to a valid secure executing image */ |
| 644 | assert(image_desc); |
Yatharth Kochar | 843ddee | 2016-02-01 11:04:46 +0000 | [diff] [blame] | 645 | assert(GET_SECURITY_STATE(image_desc->ep_info.h.attr) == SECURE); |
| 646 | assert(EP_GET_EXE(image_desc->ep_info.h.attr) == EXECUTABLE); |
Dan Handley | 28955d5 | 2015-12-15 10:52:33 +0000 | [diff] [blame] | 647 | assert(image_desc->state == IMAGE_STATE_EXECUTED); |
| 648 | |
Antonio Nino Diaz | 128daee | 2017-06-01 13:40:17 +0100 | [diff] [blame] | 649 | #if ENABLE_ASSERTIONS |
| 650 | int rc = bl1_fwu_remove_loaded_id(sec_exec_image_id); |
| 651 | assert(rc == 0); |
| 652 | #else |
| 653 | bl1_fwu_remove_loaded_id(sec_exec_image_id); |
| 654 | #endif |
| 655 | |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 656 | /* Update the flags. */ |
| 657 | image_desc->state = IMAGE_STATE_RESET; |
| 658 | sec_exec_image_id = INVALID_IMAGE_ID; |
| 659 | |
dp-arm | a440900 | 2017-02-15 11:07:55 +0000 | [diff] [blame] | 660 | INFO("BL1-FWU: Resuming Normal world context\n"); |
| 661 | #ifdef AARCH64 |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 662 | /* |
| 663 | * Secure world is done so no need to save the context. |
| 664 | * Just restore the Non-Secure context. |
| 665 | */ |
| 666 | cm_el1_sysregs_context_restore(NON_SECURE); |
| 667 | |
| 668 | /* Update the next context. */ |
| 669 | cm_set_next_eret_context(NON_SECURE); |
| 670 | |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 671 | *handle = cm_get_context(NON_SECURE); |
dp-arm | a440900 | 2017-02-15 11:07:55 +0000 | [diff] [blame] | 672 | #else |
| 673 | /* Update the next context. */ |
| 674 | cm_set_next_context(cm_get_context(NON_SECURE)); |
| 675 | |
| 676 | /* Prepare the smc context for the next BL image. */ |
| 677 | smc_set_next_ctx(NON_SECURE); |
| 678 | |
| 679 | *handle = smc_get_ctx(NON_SECURE); |
| 680 | #endif |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 681 | return 0; |
| 682 | } |
| 683 | |
| 684 | /******************************************************************************* |
| 685 | * This function provides the opportunity for users to perform any |
| 686 | * platform specific handling after the Firmware update is done. |
| 687 | ******************************************************************************/ |
Dan Handley | 1f37b94 | 2015-12-15 14:28:24 +0000 | [diff] [blame] | 688 | __dead2 static void bl1_fwu_done(void *client_cookie, void *reserved) |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 689 | { |
| 690 | NOTICE("BL1-FWU: *******FWU Process Completed*******\n"); |
| 691 | |
| 692 | /* |
| 693 | * Call platform done function. |
| 694 | */ |
Dan Handley | 1f37b94 | 2015-12-15 14:28:24 +0000 | [diff] [blame] | 695 | bl1_plat_fwu_done(client_cookie, reserved); |
Yatharth Kochar | 48bfb88 | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 696 | assert(0); |
| 697 | } |
Antonio Nino Diaz | 9d6fc3c | 2017-05-12 16:51:59 +0100 | [diff] [blame] | 698 | |
| 699 | /******************************************************************************* |
| 700 | * This function resets an image to IMAGE_STATE_RESET. It fails if the image is |
| 701 | * being executed. |
| 702 | ******************************************************************************/ |
| 703 | static int bl1_fwu_image_reset(unsigned int image_id, unsigned int flags) |
| 704 | { |
| 705 | image_desc_t *image_desc = bl1_plat_get_image_desc(image_id); |
| 706 | |
| 707 | if ((!image_desc) || (GET_SECURITY_STATE(flags) == SECURE)) { |
| 708 | WARN("BL1-FWU: Reset not allowed due to invalid args\n"); |
| 709 | return -EPERM; |
| 710 | } |
| 711 | |
| 712 | switch (image_desc->state) { |
| 713 | |
| 714 | case IMAGE_STATE_RESET: |
| 715 | /* Nothing to do. */ |
| 716 | break; |
| 717 | |
| 718 | case IMAGE_STATE_INTERRUPTED: |
| 719 | case IMAGE_STATE_AUTHENTICATED: |
| 720 | case IMAGE_STATE_COPIED: |
| 721 | case IMAGE_STATE_COPYING: |
| 722 | |
| 723 | if (bl1_fwu_remove_loaded_id(image_id)) { |
| 724 | WARN("BL1-FWU: Image reset couldn't find the image ID\n"); |
| 725 | return -EPERM; |
| 726 | } |
| 727 | |
Soby Mathew | ee05ae1 | 2017-06-15 16:11:48 +0100 | [diff] [blame] | 728 | if (image_desc->copied_size) { |
| 729 | /* Clear the memory if the image is copied */ |
| 730 | assert(GET_SECURITY_STATE(image_desc->ep_info.h.attr) == SECURE); |
| 731 | |
| 732 | zero_normalmem((void *)image_desc->image_info.image_base, |
| 733 | image_desc->copied_size); |
| 734 | flush_dcache_range(image_desc->image_info.image_base, |
| 735 | image_desc->copied_size); |
| 736 | } |
Antonio Nino Diaz | 9d6fc3c | 2017-05-12 16:51:59 +0100 | [diff] [blame] | 737 | |
| 738 | /* Reset status variables */ |
| 739 | image_desc->copied_size = 0; |
| 740 | image_desc->image_info.image_size = 0; |
| 741 | image_desc->state = IMAGE_STATE_RESET; |
| 742 | |
| 743 | /* Clear authentication state */ |
| 744 | auth_img_flags[image_id] = 0; |
| 745 | |
| 746 | break; |
| 747 | |
| 748 | case IMAGE_STATE_EXECUTED: |
| 749 | default: |
| 750 | assert(0); |
Jonathan Wright | c9662db | 2018-03-13 13:54:03 +0000 | [diff] [blame] | 751 | break; |
Antonio Nino Diaz | 9d6fc3c | 2017-05-12 16:51:59 +0100 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | return 0; |
| 755 | } |