xref: /rk3399_ARM-atf/plat/arm/board/fvp/fvp_io_storage.c (revision c948f77136c42a92d0bb660543a3600c36dcf7f1)
1 /*
2  * Copyright (c) 2014-2018, ARM Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include <assert.h>
8 
9 #include <common/debug.h>
10 #include <drivers/io/io_driver.h>
11 #include <drivers/io/io_semihosting.h>
12 #include <drivers/io/io_storage.h>
13 #include <lib/semihosting.h>
14 #include <plat/common/common_def.h>
15 
16 #include <plat_arm.h>
17 
18 /* Semihosting filenames */
19 #define BL2_IMAGE_NAME			"bl2.bin"
20 #define BL31_IMAGE_NAME			"bl31.bin"
21 #define BL32_IMAGE_NAME			"bl32.bin"
22 #define BL33_IMAGE_NAME			"bl33.bin"
23 #define TB_FW_CONFIG_NAME		"fvp_tb_fw_config.dtb"
24 #define HW_CONFIG_NAME			"hw_config.dtb"
25 
26 #if TRUSTED_BOARD_BOOT
27 #define TRUSTED_BOOT_FW_CERT_NAME	"tb_fw.crt"
28 #define TRUSTED_KEY_CERT_NAME		"trusted_key.crt"
29 #define SOC_FW_KEY_CERT_NAME		"soc_fw_key.crt"
30 #define TOS_FW_KEY_CERT_NAME		"tos_fw_key.crt"
31 #define NT_FW_KEY_CERT_NAME		"nt_fw_key.crt"
32 #define SOC_FW_CONTENT_CERT_NAME	"soc_fw_content.crt"
33 #define TOS_FW_CONTENT_CERT_NAME	"tos_fw_content.crt"
34 #define NT_FW_CONTENT_CERT_NAME		"nt_fw_content.crt"
35 #endif /* TRUSTED_BOARD_BOOT */
36 
37 /* IO devices */
38 static const io_dev_connector_t *sh_dev_con;
39 static uintptr_t sh_dev_handle;
40 
41 static const io_file_spec_t sh_file_spec[] = {
42 	[BL2_IMAGE_ID] = {
43 		.path = BL2_IMAGE_NAME,
44 		.mode = FOPEN_MODE_RB
45 	},
46 	[BL31_IMAGE_ID] = {
47 		.path = BL31_IMAGE_NAME,
48 		.mode = FOPEN_MODE_RB
49 	},
50 	[BL32_IMAGE_ID] = {
51 		.path = BL32_IMAGE_NAME,
52 		.mode = FOPEN_MODE_RB
53 	},
54 	[BL33_IMAGE_ID] = {
55 		.path = BL33_IMAGE_NAME,
56 		.mode = FOPEN_MODE_RB
57 	},
58 	[TB_FW_CONFIG_ID] = {
59 		.path = TB_FW_CONFIG_NAME,
60 		.mode = FOPEN_MODE_RB
61 	},
62 	[HW_CONFIG_ID] = {
63 		.path = HW_CONFIG_NAME,
64 		.mode = FOPEN_MODE_RB
65 	},
66 #if TRUSTED_BOARD_BOOT
67 	[TRUSTED_BOOT_FW_CERT_ID] = {
68 		.path = TRUSTED_BOOT_FW_CERT_NAME,
69 		.mode = FOPEN_MODE_RB
70 	},
71 	[TRUSTED_KEY_CERT_ID] = {
72 		.path = TRUSTED_KEY_CERT_NAME,
73 		.mode = FOPEN_MODE_RB
74 	},
75 	[SOC_FW_KEY_CERT_ID] = {
76 		.path = SOC_FW_KEY_CERT_NAME,
77 		.mode = FOPEN_MODE_RB
78 	},
79 	[TRUSTED_OS_FW_KEY_CERT_ID] = {
80 		.path = TOS_FW_KEY_CERT_NAME,
81 		.mode = FOPEN_MODE_RB
82 	},
83 	[NON_TRUSTED_FW_KEY_CERT_ID] = {
84 		.path = NT_FW_KEY_CERT_NAME,
85 		.mode = FOPEN_MODE_RB
86 	},
87 	[SOC_FW_CONTENT_CERT_ID] = {
88 		.path = SOC_FW_CONTENT_CERT_NAME,
89 		.mode = FOPEN_MODE_RB
90 	},
91 	[TRUSTED_OS_FW_CONTENT_CERT_ID] = {
92 		.path = TOS_FW_CONTENT_CERT_NAME,
93 		.mode = FOPEN_MODE_RB
94 	},
95 	[NON_TRUSTED_FW_CONTENT_CERT_ID] = {
96 		.path = NT_FW_CONTENT_CERT_NAME,
97 		.mode = FOPEN_MODE_RB
98 	},
99 #endif /* TRUSTED_BOARD_BOOT */
100 };
101 
102 
103 static int open_semihosting(const uintptr_t spec)
104 {
105 	int result;
106 	uintptr_t local_image_handle;
107 
108 	/* See if the file exists on semi-hosting.*/
109 	result = io_dev_init(sh_dev_handle, (uintptr_t)NULL);
110 	if (result == 0) {
111 		result = io_open(sh_dev_handle, spec, &local_image_handle);
112 		if (result == 0) {
113 			VERBOSE("Using Semi-hosting IO\n");
114 			io_close(local_image_handle);
115 		}
116 	}
117 	return result;
118 }
119 
120 void plat_arm_io_setup(void)
121 {
122 	int io_result;
123 
124 	arm_io_setup();
125 
126 	/* Register the additional IO devices on this platform */
127 	io_result = register_io_dev_sh(&sh_dev_con);
128 	assert(io_result == 0);
129 
130 	/* Open connections to devices and cache the handles */
131 	io_result = io_dev_open(sh_dev_con, (uintptr_t)NULL, &sh_dev_handle);
132 	assert(io_result == 0);
133 
134 	/* Ignore improbable errors in release builds */
135 	(void)io_result;
136 }
137 
138 /*
139  * FVP provides semihosting as an alternative to load images
140  */
141 int plat_arm_get_alt_image_source(unsigned int image_id, uintptr_t *dev_handle,
142 				  uintptr_t *image_spec)
143 {
144 	int result = open_semihosting((const uintptr_t)&sh_file_spec[image_id]);
145 	if (result == 0) {
146 		*dev_handle = sh_dev_handle;
147 		*image_spec = (uintptr_t)&sh_file_spec[image_id];
148 	}
149 
150 	return result;
151 }
152