blob: 02f995f7f83626f3f4d40a174748894629c5da46 [file] [log] [blame]
Soby Mathew7c6df5b2018-01-15 14:43:42 +00001/*
2 * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Soby Mathew96a1c6b2018-01-15 14:45:33 +00007#include <arm_dyn_cfg_helpers.h>
Soby Mathew7c6df5b2018-01-15 14:43:42 +00008#include <assert.h>
9#include <debug.h>
10#include <desc_image_load.h>
Soby Mathewcc364842018-02-21 01:16:39 +000011#include <plat_arm.h>
Soby Mathew7c6df5b2018-01-15 14:43:42 +000012#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 Mathew96a1c6b2018-01-15 14:45:33 +000019/* Variable to store the address to TB_FW_CONFIG passed from BL1 */
20static void *tb_fw_cfg_dtb;
21
Soby Mathew7c6df5b2018-01-15 14:43:42 +000022/*
23 * Helper function to load TB_FW_CONFIG and populate the load information to
24 * arg0 of BL2 entrypoint info.
25 */
26void 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 Mathewcc364842018-02-21 01:16:39 +000042 if (err != 0) {
Soby Mathew7c6df5b2018-01-15 14:43:42 +000043 /* 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 Mathewcc364842018-02-21 01:16:39 +000052 assert(image_desc != NULL);
Soby Mathew7c6df5b2018-01-15 14:43:42 +000053 image_desc->ep_info.args.arg0 = config_base;
54
55 INFO("BL1: TB_FW_CONFIG loaded at address = %p\n",
56 (void *) config_base);
57}
58
Soby Mathew96a1c6b2018-01-15 14:45:33 +000059/*
60 * BL2 utility function to set the address of TB_FW_CONFIG passed from BL1.
61 */
62void arm_bl2_set_tb_cfg_addr(void *dtb)
63{
Soby Mathewcc364842018-02-21 01:16:39 +000064 assert(dtb != NULL);
Soby Mathew96a1c6b2018-01-15 14:45:33 +000065 tb_fw_cfg_dtb = dtb;
66}
67
68/*
69 * BL2 utility function to initialize dynamic configuration specified by
70 * TB_FW_CONFIG. Return early if TB_FW_CONFIG is not found or HW_CONFIG is
71 * not specified in TB_FW_CONFIG.
72 */
73void arm_bl2_dyn_cfg_init(void)
74{
75 int err = 0;
76 int tb_fw_node;
77 bl_mem_params_node_t *hw_cfg_mem_params = NULL;
78
79 if (tb_fw_cfg_dtb == NULL) {
80 VERBOSE("No TB_FW_CONFIG specified\n");
81 return;
82 }
83
84 err = arm_dyn_tb_fw_cfg_init((void *)tb_fw_cfg_dtb, &tb_fw_node);
85 if (err < 0) {
86 ERROR("Invalid TB_FW_CONFIG passed from BL1\n");
87 panic();
88 }
89
90 /* Get the hw_config load address and size from TB_FW_CONFIG */
91 hw_cfg_mem_params = get_bl_mem_params_node(HW_CONFIG_ID);
92 if (hw_cfg_mem_params == NULL) {
93 VERBOSE("Couldn't find HW_CONFIG in bl_mem_params_node\n");
94 return;
95 }
96
97 err = arm_dyn_get_hwconfig_info((void *)tb_fw_cfg_dtb, tb_fw_node,
98 (uint64_t *) &hw_cfg_mem_params->image_info.image_base,
99 &hw_cfg_mem_params->image_info.image_max_size);
100 if (err < 0) {
101 VERBOSE("Couldn't find HW_CONFIG load info in TB_FW_CONFIG\n");
102 return;
103 }
104
105 /* Remove the IMAGE_ATTRIB_SKIP_LOADING attribute from HW_CONFIG node */
106 hw_cfg_mem_params->image_info.h.attr &= ~IMAGE_ATTRIB_SKIP_LOADING;
107}
108
Soby Mathew7c6df5b2018-01-15 14:43:42 +0000109#endif /* LOAD_IMAGE_V2 */