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