2014-02-10 17:04:32 +00:00
|
|
|
/*
|
2018-01-15 14:43:42 +00:00
|
|
|
* Copyright (c) 2014-2018, ARM Limited and Contributors. All rights reserved.
|
2014-02-10 17:04:32 +00:00
|
|
|
*
|
2017-05-03 09:38:09 +01:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
2014-02-10 17:04:32 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
2018-12-14 00:18:21 +00:00
|
|
|
|
|
|
|
#include <common/debug.h>
|
|
|
|
#include <drivers/io/io_driver.h>
|
|
|
|
#include <drivers/io/io_semihosting.h>
|
|
|
|
#include <drivers/io/io_storage.h>
|
|
|
|
#include <lib/semihosting.h>
|
2019-01-25 14:30:04 +00:00
|
|
|
#include <plat/arm/common/plat_arm.h>
|
2018-12-14 00:18:21 +00:00
|
|
|
#include <plat/common/common_def.h>
|
|
|
|
|
2015-04-13 17:36:19 +01:00
|
|
|
/* Semihosting filenames */
|
|
|
|
#define BL2_IMAGE_NAME "bl2.bin"
|
|
|
|
#define BL31_IMAGE_NAME "bl31.bin"
|
|
|
|
#define BL32_IMAGE_NAME "bl32.bin"
|
|
|
|
#define BL33_IMAGE_NAME "bl33.bin"
|
2018-01-15 14:43:42 +00:00
|
|
|
#define TB_FW_CONFIG_NAME "fvp_tb_fw_config.dtb"
|
2018-01-15 14:45:33 +00:00
|
|
|
#define HW_CONFIG_NAME "hw_config.dtb"
|
2015-04-13 17:36:19 +01:00
|
|
|
|
|
|
|
#if TRUSTED_BOARD_BOOT
|
2015-12-03 10:19:21 +00:00
|
|
|
#define TRUSTED_BOOT_FW_CERT_NAME "tb_fw.crt"
|
2015-04-13 17:36:19 +01:00
|
|
|
#define TRUSTED_KEY_CERT_NAME "trusted_key.crt"
|
2015-12-03 10:19:21 +00:00
|
|
|
#define SOC_FW_KEY_CERT_NAME "soc_fw_key.crt"
|
|
|
|
#define TOS_FW_KEY_CERT_NAME "tos_fw_key.crt"
|
|
|
|
#define NT_FW_KEY_CERT_NAME "nt_fw_key.crt"
|
|
|
|
#define SOC_FW_CONTENT_CERT_NAME "soc_fw_content.crt"
|
|
|
|
#define TOS_FW_CONTENT_CERT_NAME "tos_fw_content.crt"
|
|
|
|
#define NT_FW_CONTENT_CERT_NAME "nt_fw_content.crt"
|
2015-04-13 17:36:19 +01:00
|
|
|
#endif /* TRUSTED_BOARD_BOOT */
|
2014-02-10 17:04:32 +00:00
|
|
|
|
|
|
|
/* IO devices */
|
2014-04-23 13:47:06 +01:00
|
|
|
static const io_dev_connector_t *sh_dev_con;
|
|
|
|
static uintptr_t sh_dev_handle;
|
2014-02-14 14:42:48 +00:00
|
|
|
|
2015-04-13 17:36:19 +01:00
|
|
|
static const io_file_spec_t sh_file_spec[] = {
|
|
|
|
[BL2_IMAGE_ID] = {
|
|
|
|
.path = BL2_IMAGE_NAME,
|
|
|
|
.mode = FOPEN_MODE_RB
|
|
|
|
},
|
|
|
|
[BL31_IMAGE_ID] = {
|
|
|
|
.path = BL31_IMAGE_NAME,
|
|
|
|
.mode = FOPEN_MODE_RB
|
|
|
|
},
|
|
|
|
[BL32_IMAGE_ID] = {
|
|
|
|
.path = BL32_IMAGE_NAME,
|
|
|
|
.mode = FOPEN_MODE_RB
|
|
|
|
},
|
|
|
|
[BL33_IMAGE_ID] = {
|
|
|
|
.path = BL33_IMAGE_NAME,
|
|
|
|
.mode = FOPEN_MODE_RB
|
|
|
|
},
|
2018-01-15 14:43:42 +00:00
|
|
|
[TB_FW_CONFIG_ID] = {
|
|
|
|
.path = TB_FW_CONFIG_NAME,
|
2018-01-15 14:45:33 +00:00
|
|
|
.mode = FOPEN_MODE_RB
|
|
|
|
},
|
|
|
|
[HW_CONFIG_ID] = {
|
|
|
|
.path = HW_CONFIG_NAME,
|
2018-01-15 14:43:42 +00:00
|
|
|
.mode = FOPEN_MODE_RB
|
|
|
|
},
|
2015-04-13 17:36:19 +01:00
|
|
|
#if TRUSTED_BOARD_BOOT
|
2015-12-03 10:19:21 +00:00
|
|
|
[TRUSTED_BOOT_FW_CERT_ID] = {
|
|
|
|
.path = TRUSTED_BOOT_FW_CERT_NAME,
|
2015-04-13 17:36:19 +01:00
|
|
|
.mode = FOPEN_MODE_RB
|
|
|
|
},
|
|
|
|
[TRUSTED_KEY_CERT_ID] = {
|
|
|
|
.path = TRUSTED_KEY_CERT_NAME,
|
|
|
|
.mode = FOPEN_MODE_RB
|
|
|
|
},
|
2015-12-03 10:19:21 +00:00
|
|
|
[SOC_FW_KEY_CERT_ID] = {
|
|
|
|
.path = SOC_FW_KEY_CERT_NAME,
|
2015-04-13 17:36:19 +01:00
|
|
|
.mode = FOPEN_MODE_RB
|
|
|
|
},
|
2015-12-03 10:19:21 +00:00
|
|
|
[TRUSTED_OS_FW_KEY_CERT_ID] = {
|
|
|
|
.path = TOS_FW_KEY_CERT_NAME,
|
2015-04-13 17:36:19 +01:00
|
|
|
.mode = FOPEN_MODE_RB
|
|
|
|
},
|
2015-12-03 10:19:21 +00:00
|
|
|
[NON_TRUSTED_FW_KEY_CERT_ID] = {
|
|
|
|
.path = NT_FW_KEY_CERT_NAME,
|
2015-04-13 17:36:19 +01:00
|
|
|
.mode = FOPEN_MODE_RB
|
|
|
|
},
|
2015-12-03 10:19:21 +00:00
|
|
|
[SOC_FW_CONTENT_CERT_ID] = {
|
|
|
|
.path = SOC_FW_CONTENT_CERT_NAME,
|
2015-04-13 17:36:19 +01:00
|
|
|
.mode = FOPEN_MODE_RB
|
|
|
|
},
|
2015-12-03 10:19:21 +00:00
|
|
|
[TRUSTED_OS_FW_CONTENT_CERT_ID] = {
|
|
|
|
.path = TOS_FW_CONTENT_CERT_NAME,
|
2015-04-13 17:36:19 +01:00
|
|
|
.mode = FOPEN_MODE_RB
|
|
|
|
},
|
2015-12-03 10:19:21 +00:00
|
|
|
[NON_TRUSTED_FW_CONTENT_CERT_ID] = {
|
|
|
|
.path = NT_FW_CONTENT_CERT_NAME,
|
2015-04-13 17:36:19 +01:00
|
|
|
.mode = FOPEN_MODE_RB
|
|
|
|
},
|
|
|
|
#endif /* TRUSTED_BOARD_BOOT */
|
|
|
|
};
|
|
|
|
|
2014-02-14 14:42:48 +00:00
|
|
|
|
2014-04-23 13:47:06 +01:00
|
|
|
static int open_semihosting(const uintptr_t spec)
|
2014-02-14 14:42:48 +00:00
|
|
|
{
|
2015-11-02 10:47:01 +00:00
|
|
|
int result;
|
2014-04-23 13:47:06 +01:00
|
|
|
uintptr_t local_image_handle;
|
2014-02-14 14:42:48 +00:00
|
|
|
|
|
|
|
/* See if the file exists on semi-hosting.*/
|
2015-03-19 19:17:53 +00:00
|
|
|
result = io_dev_init(sh_dev_handle, (uintptr_t)NULL);
|
2015-11-02 10:47:01 +00:00
|
|
|
if (result == 0) {
|
2014-02-14 14:42:48 +00:00
|
|
|
result = io_open(sh_dev_handle, spec, &local_image_handle);
|
2015-11-02 10:47:01 +00:00
|
|
|
if (result == 0) {
|
2014-07-29 17:14:00 +01:00
|
|
|
VERBOSE("Using Semi-hosting IO\n");
|
2014-02-14 14:42:48 +00:00
|
|
|
io_close(local_image_handle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-03-19 19:17:53 +00:00
|
|
|
void plat_arm_io_setup(void)
|
2014-02-14 14:42:48 +00:00
|
|
|
{
|
2015-03-19 19:17:53 +00:00
|
|
|
int io_result;
|
2014-02-14 14:42:48 +00:00
|
|
|
|
2015-03-19 19:17:53 +00:00
|
|
|
arm_io_setup();
|
2014-02-14 14:42:48 +00:00
|
|
|
|
2015-03-19 19:17:53 +00:00
|
|
|
/* Register the additional IO devices on this platform */
|
|
|
|
io_result = register_io_dev_sh(&sh_dev_con);
|
2015-11-02 10:47:01 +00:00
|
|
|
assert(io_result == 0);
|
2014-02-10 17:04:32 +00:00
|
|
|
|
2014-02-14 14:42:48 +00:00
|
|
|
/* Open connections to devices and cache the handles */
|
2015-03-19 19:17:53 +00:00
|
|
|
io_result = io_dev_open(sh_dev_con, (uintptr_t)NULL, &sh_dev_handle);
|
2015-11-02 10:47:01 +00:00
|
|
|
assert(io_result == 0);
|
2014-02-14 14:42:48 +00:00
|
|
|
|
2014-02-10 17:04:32 +00:00
|
|
|
/* Ignore improbable errors in release builds */
|
|
|
|
(void)io_result;
|
|
|
|
}
|
|
|
|
|
2015-04-13 17:36:19 +01:00
|
|
|
/*
|
|
|
|
* FVP provides semihosting as an alternative to load images
|
|
|
|
*/
|
|
|
|
int plat_arm_get_alt_image_source(unsigned int image_id, uintptr_t *dev_handle,
|
|
|
|
uintptr_t *image_spec)
|
2014-02-10 17:04:32 +00:00
|
|
|
{
|
2015-04-13 17:36:19 +01:00
|
|
|
int result = open_semihosting((const uintptr_t)&sh_file_spec[image_id]);
|
2015-11-02 10:47:01 +00:00
|
|
|
if (result == 0) {
|
2015-03-19 19:17:53 +00:00
|
|
|
*dev_handle = sh_dev_handle;
|
2015-04-13 17:36:19 +01:00
|
|
|
*image_spec = (uintptr_t)&sh_file_spec[image_id];
|
|
|
|
}
|
2014-02-18 17:40:24 +00:00
|
|
|
|
2014-02-10 17:04:32 +00:00
|
|
|
return result;
|
|
|
|
}
|