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> |
| 11 | #include <platform.h> |
| 12 | #include <platform_def.h> |
| 13 | #include <string.h> |
| 14 | #include <tbbr_img_def.h> |
| 15 | |
| 16 | #if LOAD_IMAGE_V2 |
| 17 | |
Soby Mathew | 96a1c6b | 2018-01-15 14:45:33 +0000 | [diff] [blame^] | 18 | /* Variable to store the address to TB_FW_CONFIG passed from BL1 */ |
| 19 | static void *tb_fw_cfg_dtb; |
| 20 | |
Soby Mathew | 7c6df5b | 2018-01-15 14:43:42 +0000 | [diff] [blame] | 21 | /* |
| 22 | * Helper function to load TB_FW_CONFIG and populate the load information to |
| 23 | * arg0 of BL2 entrypoint info. |
| 24 | */ |
| 25 | void arm_load_tb_fw_config(void) |
| 26 | { |
| 27 | int err; |
| 28 | uintptr_t config_base = 0; |
| 29 | image_desc_t *image_desc; |
| 30 | |
| 31 | image_desc_t arm_tb_fw_info = { |
| 32 | .image_id = TB_FW_CONFIG_ID, |
| 33 | SET_STATIC_PARAM_HEAD(image_info, PARAM_IMAGE_BINARY, |
| 34 | VERSION_2, image_info_t, 0), |
| 35 | .image_info.image_base = ARM_TB_FW_CONFIG_BASE, |
| 36 | .image_info.image_max_size = ARM_TB_FW_CONFIG_LIMIT - ARM_TB_FW_CONFIG_BASE, |
| 37 | }; |
| 38 | |
| 39 | VERBOSE("BL1: Loading TB_FW_CONFIG\n"); |
| 40 | err = load_auth_image(TB_FW_CONFIG_ID, &arm_tb_fw_info.image_info); |
| 41 | if (err) { |
| 42 | /* Return if TB_FW_CONFIG is not loaded */ |
| 43 | VERBOSE("Failed to load TB_FW_CONFIG\n"); |
| 44 | return; |
| 45 | } |
| 46 | |
| 47 | config_base = arm_tb_fw_info.image_info.image_base; |
| 48 | |
| 49 | /* The BL2 ep_info arg0 is modified to point to TB_FW_CONFIG */ |
| 50 | image_desc = bl1_plat_get_image_desc(BL2_IMAGE_ID); |
| 51 | assert(image_desc); |
| 52 | image_desc->ep_info.args.arg0 = config_base; |
| 53 | |
| 54 | INFO("BL1: TB_FW_CONFIG loaded at address = %p\n", |
| 55 | (void *) config_base); |
| 56 | } |
| 57 | |
Soby Mathew | 96a1c6b | 2018-01-15 14:45:33 +0000 | [diff] [blame^] | 58 | /* |
| 59 | * BL2 utility function to set the address of TB_FW_CONFIG passed from BL1. |
| 60 | */ |
| 61 | void arm_bl2_set_tb_cfg_addr(void *dtb) |
| 62 | { |
| 63 | assert(dtb); |
| 64 | tb_fw_cfg_dtb = dtb; |
| 65 | } |
| 66 | |
| 67 | /* |
| 68 | * BL2 utility function to initialize dynamic configuration specified by |
| 69 | * TB_FW_CONFIG. Return early if TB_FW_CONFIG is not found or HW_CONFIG is |
| 70 | * not specified in TB_FW_CONFIG. |
| 71 | */ |
| 72 | void arm_bl2_dyn_cfg_init(void) |
| 73 | { |
| 74 | int err = 0; |
| 75 | int tb_fw_node; |
| 76 | bl_mem_params_node_t *hw_cfg_mem_params = NULL; |
| 77 | |
| 78 | if (tb_fw_cfg_dtb == NULL) { |
| 79 | VERBOSE("No TB_FW_CONFIG specified\n"); |
| 80 | return; |
| 81 | } |
| 82 | |
| 83 | err = arm_dyn_tb_fw_cfg_init((void *)tb_fw_cfg_dtb, &tb_fw_node); |
| 84 | if (err < 0) { |
| 85 | ERROR("Invalid TB_FW_CONFIG passed from BL1\n"); |
| 86 | panic(); |
| 87 | } |
| 88 | |
| 89 | /* Get the hw_config load address and size from TB_FW_CONFIG */ |
| 90 | hw_cfg_mem_params = get_bl_mem_params_node(HW_CONFIG_ID); |
| 91 | if (hw_cfg_mem_params == NULL) { |
| 92 | VERBOSE("Couldn't find HW_CONFIG in bl_mem_params_node\n"); |
| 93 | return; |
| 94 | } |
| 95 | |
| 96 | err = arm_dyn_get_hwconfig_info((void *)tb_fw_cfg_dtb, tb_fw_node, |
| 97 | (uint64_t *) &hw_cfg_mem_params->image_info.image_base, |
| 98 | &hw_cfg_mem_params->image_info.image_max_size); |
| 99 | if (err < 0) { |
| 100 | VERBOSE("Couldn't find HW_CONFIG load info in TB_FW_CONFIG\n"); |
| 101 | return; |
| 102 | } |
| 103 | |
| 104 | /* Remove the IMAGE_ATTRIB_SKIP_LOADING attribute from HW_CONFIG node */ |
| 105 | hw_cfg_mem_params->image_info.h.attr &= ~IMAGE_ATTRIB_SKIP_LOADING; |
| 106 | } |
| 107 | |
Soby Mathew | 7c6df5b | 2018-01-15 14:43:42 +0000 | [diff] [blame] | 108 | #endif /* LOAD_IMAGE_V2 */ |