Soby Mathew | 7c6df5b | 2018-01-15 14:43:42 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Soby Mathew | 96a1c6b | 2018-01-15 14:45:33 +0000 | [diff] [blame] | 7 | #include <arm_dyn_cfg_helpers.h> |
Soby Mathew | 7c6df5b | 2018-01-15 14:43:42 +0000 | [diff] [blame] | 8 | #include <assert.h> |
| 9 | #include <debug.h> |
| 10 | #include <desc_image_load.h> |
Soby Mathew | cc36484 | 2018-02-21 01:16:39 +0000 | [diff] [blame] | 11 | #include <plat_arm.h> |
Soby Mathew | 7c6df5b | 2018-01-15 14:43:42 +0000 | [diff] [blame] | 12 | #include <platform.h> |
| 13 | #include <platform_def.h> |
| 14 | #include <string.h> |
| 15 | #include <tbbr_img_def.h> |
| 16 | |
| 17 | #if LOAD_IMAGE_V2 |
| 18 | |
Soby Mathew | 96a1c6b | 2018-01-15 14:45:33 +0000 | [diff] [blame] | 19 | /* Variable to store the address to TB_FW_CONFIG passed from BL1 */ |
| 20 | static void *tb_fw_cfg_dtb; |
| 21 | |
Soby Mathew | 7c6df5b | 2018-01-15 14:43:42 +0000 | [diff] [blame] | 22 | /* |
| 23 | * Helper function to load TB_FW_CONFIG and populate the load information to |
| 24 | * arg0 of BL2 entrypoint info. |
| 25 | */ |
| 26 | void arm_load_tb_fw_config(void) |
| 27 | { |
| 28 | int err; |
| 29 | uintptr_t config_base = 0; |
| 30 | image_desc_t *image_desc; |
| 31 | |
| 32 | image_desc_t arm_tb_fw_info = { |
| 33 | .image_id = TB_FW_CONFIG_ID, |
| 34 | SET_STATIC_PARAM_HEAD(image_info, PARAM_IMAGE_BINARY, |
| 35 | VERSION_2, image_info_t, 0), |
| 36 | .image_info.image_base = ARM_TB_FW_CONFIG_BASE, |
| 37 | .image_info.image_max_size = ARM_TB_FW_CONFIG_LIMIT - ARM_TB_FW_CONFIG_BASE, |
| 38 | }; |
| 39 | |
| 40 | VERBOSE("BL1: Loading TB_FW_CONFIG\n"); |
| 41 | err = load_auth_image(TB_FW_CONFIG_ID, &arm_tb_fw_info.image_info); |
Soby Mathew | cc36484 | 2018-02-21 01:16:39 +0000 | [diff] [blame] | 42 | if (err != 0) { |
Soby Mathew | 7c6df5b | 2018-01-15 14:43:42 +0000 | [diff] [blame] | 43 | /* Return if TB_FW_CONFIG is not loaded */ |
| 44 | VERBOSE("Failed to load TB_FW_CONFIG\n"); |
| 45 | return; |
| 46 | } |
| 47 | |
| 48 | config_base = arm_tb_fw_info.image_info.image_base; |
| 49 | |
| 50 | /* The BL2 ep_info arg0 is modified to point to TB_FW_CONFIG */ |
| 51 | image_desc = bl1_plat_get_image_desc(BL2_IMAGE_ID); |
Soby Mathew | cc36484 | 2018-02-21 01:16:39 +0000 | [diff] [blame] | 52 | assert(image_desc != NULL); |
Soby Mathew | 7c6df5b | 2018-01-15 14:43:42 +0000 | [diff] [blame] | 53 | image_desc->ep_info.args.arg0 = config_base; |
| 54 | |
| 55 | INFO("BL1: TB_FW_CONFIG loaded at address = %p\n", |
| 56 | (void *) config_base); |
Soby Mathew | 45e39e2 | 2018-03-26 15:16:46 +0100 | [diff] [blame] | 57 | |
| 58 | #if TRUSTED_BOARD_BOOT && defined(DYN_DISABLE_AUTH) |
| 59 | int tb_fw_node; |
| 60 | uint32_t disable_auth = 0; |
| 61 | |
| 62 | err = arm_dyn_tb_fw_cfg_init((void *)config_base, &tb_fw_node); |
| 63 | if (err < 0) { |
John Tsichritzis | 116d78a | 2018-06-15 11:43:02 +0100 | [diff] [blame] | 64 | ERROR("Invalid TB_FW_CONFIG loaded\n"); |
| 65 | panic(); |
Soby Mathew | 45e39e2 | 2018-03-26 15:16:46 +0100 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | err = arm_dyn_get_disable_auth((void *)config_base, tb_fw_node, &disable_auth); |
| 69 | if (err < 0) |
| 70 | return; |
| 71 | |
| 72 | if (disable_auth == 1) |
| 73 | dyn_disable_auth(); |
| 74 | #endif |
Soby Mathew | 7c6df5b | 2018-01-15 14:43:42 +0000 | [diff] [blame] | 75 | } |
| 76 | |
Soby Mathew | 96a1c6b | 2018-01-15 14:45:33 +0000 | [diff] [blame] | 77 | /* |
| 78 | * BL2 utility function to set the address of TB_FW_CONFIG passed from BL1. |
| 79 | */ |
| 80 | void arm_bl2_set_tb_cfg_addr(void *dtb) |
| 81 | { |
Soby Mathew | cc36484 | 2018-02-21 01:16:39 +0000 | [diff] [blame] | 82 | assert(dtb != NULL); |
Soby Mathew | 96a1c6b | 2018-01-15 14:45:33 +0000 | [diff] [blame] | 83 | tb_fw_cfg_dtb = dtb; |
| 84 | } |
| 85 | |
| 86 | /* |
| 87 | * BL2 utility function to initialize dynamic configuration specified by |
Soby Mathew | b681484 | 2018-04-04 09:40:32 +0100 | [diff] [blame] | 88 | * TB_FW_CONFIG. Populate the bl_mem_params_node_t of other FW_CONFIGs if |
| 89 | * specified in TB_FW_CONFIG. |
Soby Mathew | 96a1c6b | 2018-01-15 14:45:33 +0000 | [diff] [blame] | 90 | */ |
| 91 | void arm_bl2_dyn_cfg_init(void) |
| 92 | { |
Soby Mathew | b681484 | 2018-04-04 09:40:32 +0100 | [diff] [blame] | 93 | int err = 0, tb_fw_node; |
| 94 | unsigned int i; |
| 95 | bl_mem_params_node_t *cfg_mem_params = NULL; |
| 96 | uint64_t image_base; |
| 97 | uint32_t image_size; |
| 98 | const unsigned int config_ids[] = { |
| 99 | HW_CONFIG_ID, |
| 100 | SOC_FW_CONFIG_ID, |
| 101 | NT_FW_CONFIG_ID, |
| 102 | #ifdef SPD_tspd |
| 103 | /* Currently tos_fw_config is only present for TSP */ |
| 104 | TOS_FW_CONFIG_ID |
| 105 | #endif |
| 106 | }; |
Soby Mathew | 96a1c6b | 2018-01-15 14:45:33 +0000 | [diff] [blame] | 107 | |
| 108 | if (tb_fw_cfg_dtb == NULL) { |
| 109 | VERBOSE("No TB_FW_CONFIG specified\n"); |
| 110 | return; |
| 111 | } |
| 112 | |
John Tsichritzis | 5b8183c | 2018-08-23 09:57:54 +0100 | [diff] [blame] | 113 | err = arm_dyn_tb_fw_cfg_init(tb_fw_cfg_dtb, &tb_fw_node); |
Soby Mathew | 96a1c6b | 2018-01-15 14:45:33 +0000 | [diff] [blame] | 114 | if (err < 0) { |
| 115 | ERROR("Invalid TB_FW_CONFIG passed from BL1\n"); |
| 116 | panic(); |
| 117 | } |
| 118 | |
Soby Mathew | b681484 | 2018-04-04 09:40:32 +0100 | [diff] [blame] | 119 | /* Iterate through all the fw config IDs */ |
| 120 | for (i = 0; i < ARRAY_SIZE(config_ids); i++) { |
| 121 | /* Get the config load address and size from TB_FW_CONFIG */ |
| 122 | cfg_mem_params = get_bl_mem_params_node(config_ids[i]); |
| 123 | if (cfg_mem_params == NULL) { |
| 124 | VERBOSE("Couldn't find HW_CONFIG in bl_mem_params_node\n"); |
| 125 | continue; |
| 126 | } |
Soby Mathew | 96a1c6b | 2018-01-15 14:45:33 +0000 | [diff] [blame] | 127 | |
John Tsichritzis | 5b8183c | 2018-08-23 09:57:54 +0100 | [diff] [blame] | 128 | err = arm_dyn_get_config_load_info(tb_fw_cfg_dtb, tb_fw_node, |
Soby Mathew | b681484 | 2018-04-04 09:40:32 +0100 | [diff] [blame] | 129 | config_ids[i], &image_base, &image_size); |
| 130 | if (err < 0) { |
| 131 | VERBOSE("Couldn't find config_id %d load info in TB_FW_CONFIG\n", |
| 132 | config_ids[i]); |
| 133 | continue; |
| 134 | } |
| 135 | |
| 136 | /* |
| 137 | * Do some runtime checks on the load addresses of soc_fw_config, |
| 138 | * tos_fw_config, nt_fw_config. This is not a comprehensive check |
| 139 | * of all invalid addresses but to prevent trivial porting errors. |
| 140 | */ |
| 141 | if (config_ids[i] != HW_CONFIG_ID) { |
Soby Mathew | 96a1c6b | 2018-01-15 14:45:33 +0000 | [diff] [blame] | 142 | |
Soby Mathew | b681484 | 2018-04-04 09:40:32 +0100 | [diff] [blame] | 143 | if (check_uptr_overflow(image_base, image_size) != 0) |
| 144 | continue; |
| 145 | |
Soby Mathew | af14b46 | 2018-06-01 16:53:38 +0100 | [diff] [blame] | 146 | /* Ensure the configs don't overlap with BL31 */ |
| 147 | if ((image_base > BL31_BASE) || ((image_base + image_size) > BL31_BASE)) |
Soby Mathew | b681484 | 2018-04-04 09:40:32 +0100 | [diff] [blame] | 148 | continue; |
| 149 | |
| 150 | /* Ensure the configs are loaded in a valid address */ |
| 151 | if (image_base < ARM_BL_RAM_BASE) |
| 152 | continue; |
| 153 | #ifdef BL32_BASE |
| 154 | /* |
| 155 | * If BL32 is present, ensure that the configs don't |
| 156 | * overlap with it. |
| 157 | */ |
| 158 | if (image_base >= BL32_BASE && image_base <= BL32_LIMIT) |
| 159 | continue; |
| 160 | #endif |
| 161 | } |
| 162 | |
| 163 | |
| 164 | cfg_mem_params->image_info.image_base = (uintptr_t)image_base; |
| 165 | cfg_mem_params->image_info.image_max_size = image_size; |
| 166 | |
| 167 | /* Remove the IMAGE_ATTRIB_SKIP_LOADING attribute from HW_CONFIG node */ |
| 168 | cfg_mem_params->image_info.h.attr &= ~IMAGE_ATTRIB_SKIP_LOADING; |
| 169 | } |
Soby Mathew | 45e39e2 | 2018-03-26 15:16:46 +0100 | [diff] [blame] | 170 | |
| 171 | #if TRUSTED_BOARD_BOOT && defined(DYN_DISABLE_AUTH) |
| 172 | uint32_t disable_auth = 0; |
| 173 | |
John Tsichritzis | 5b8183c | 2018-08-23 09:57:54 +0100 | [diff] [blame] | 174 | err = arm_dyn_get_disable_auth(tb_fw_cfg_dtb, tb_fw_node, |
Soby Mathew | 45e39e2 | 2018-03-26 15:16:46 +0100 | [diff] [blame] | 175 | &disable_auth); |
| 176 | if (err < 0) |
| 177 | return; |
| 178 | |
| 179 | if (disable_auth == 1) |
| 180 | dyn_disable_auth(); |
| 181 | #endif |
Soby Mathew | 96a1c6b | 2018-01-15 14:45:33 +0000 | [diff] [blame] | 182 | } |
| 183 | |
Soby Mathew | 7c6df5b | 2018-01-15 14:43:42 +0000 | [diff] [blame] | 184 | #endif /* LOAD_IMAGE_V2 */ |