blob: 33dc08b9ec5274c79e95c0bb00e4142e96bd9335 [file] [log] [blame]
Soby Mathewc2289562018-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 Mathewcab0b5b2018-01-15 14:45:33 +00007#include <arm_dyn_cfg_helpers.h>
Soby Mathewc2289562018-01-15 14:43:42 +00008#include <assert.h>
9#include <debug.h>
10#include <desc_image_load.h>
Soby Mathewda5f2742018-02-21 01:16:39 +000011#include <plat_arm.h>
Soby Mathewc2289562018-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 Mathewcab0b5b2018-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 Mathewc2289562018-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 Mathewda5f2742018-02-21 01:16:39 +000042 if (err != 0) {
Soby Mathewc2289562018-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 Mathewda5f2742018-02-21 01:16:39 +000052 assert(image_desc != NULL);
Soby Mathewc2289562018-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);
Soby Mathew6e79f9f2018-03-26 15:16:46 +010057
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) {
64 WARN("Invalid TB_FW_CONFIG loaded\n");
65 return;
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 Mathewc2289562018-01-15 14:43:42 +000075}
76
Soby Mathewcab0b5b2018-01-15 14:45:33 +000077/*
78 * BL2 utility function to set the address of TB_FW_CONFIG passed from BL1.
79 */
80void arm_bl2_set_tb_cfg_addr(void *dtb)
81{
Soby Mathewda5f2742018-02-21 01:16:39 +000082 assert(dtb != NULL);
Soby Mathewcab0b5b2018-01-15 14:45:33 +000083 tb_fw_cfg_dtb = dtb;
84}
85
86/*
87 * BL2 utility function to initialize dynamic configuration specified by
88 * TB_FW_CONFIG. Return early if TB_FW_CONFIG is not found or HW_CONFIG is
89 * not specified in TB_FW_CONFIG.
90 */
91void arm_bl2_dyn_cfg_init(void)
92{
93 int err = 0;
94 int tb_fw_node;
95 bl_mem_params_node_t *hw_cfg_mem_params = NULL;
96
97 if (tb_fw_cfg_dtb == NULL) {
98 VERBOSE("No TB_FW_CONFIG specified\n");
99 return;
100 }
101
102 err = arm_dyn_tb_fw_cfg_init((void *)tb_fw_cfg_dtb, &tb_fw_node);
103 if (err < 0) {
104 ERROR("Invalid TB_FW_CONFIG passed from BL1\n");
105 panic();
106 }
107
108 /* Get the hw_config load address and size from TB_FW_CONFIG */
109 hw_cfg_mem_params = get_bl_mem_params_node(HW_CONFIG_ID);
110 if (hw_cfg_mem_params == NULL) {
111 VERBOSE("Couldn't find HW_CONFIG in bl_mem_params_node\n");
112 return;
113 }
114
115 err = arm_dyn_get_hwconfig_info((void *)tb_fw_cfg_dtb, tb_fw_node,
116 (uint64_t *) &hw_cfg_mem_params->image_info.image_base,
117 &hw_cfg_mem_params->image_info.image_max_size);
118 if (err < 0) {
119 VERBOSE("Couldn't find HW_CONFIG load info in TB_FW_CONFIG\n");
120 return;
121 }
122
123 /* Remove the IMAGE_ATTRIB_SKIP_LOADING attribute from HW_CONFIG node */
124 hw_cfg_mem_params->image_info.h.attr &= ~IMAGE_ATTRIB_SKIP_LOADING;
Soby Mathew6e79f9f2018-03-26 15:16:46 +0100125
126#if TRUSTED_BOARD_BOOT && defined(DYN_DISABLE_AUTH)
127 uint32_t disable_auth = 0;
128
129 err = arm_dyn_get_disable_auth((void *)tb_fw_cfg_dtb, tb_fw_node,
130 &disable_auth);
131 if (err < 0)
132 return;
133
134 if (disable_auth == 1)
135 dyn_disable_auth();
136#endif
Soby Mathewcab0b5b2018-01-15 14:45:33 +0000137}
138
Soby Mathewc2289562018-01-15 14:43:42 +0000139#endif /* LOAD_IMAGE_V2 */