blob: 27c9e1d50fb6b8e08aadcb81e090974dd3449062 [file] [log] [blame]
Dan Handley9df48042015-03-19 18:58:55 +00001/*
Roberto Vargas2b36b152018-02-12 12:36:17 +00002 * Copyright (c) 2014-2018, ARM Limited and Contributors. All rights reserved.
Dan Handley9df48042015-03-19 18:58:55 +00003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Dan Handley9df48042015-03-19 18:58:55 +00005 */
6
Sandrine Bailleux04b66d82015-03-18 14:52:53 +00007#include <assert.h>
Sandrine Bailleux04b66d82015-03-18 14:52:53 +00008#include <stdint.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00009
10#include <arch_helpers.h>
11#include <common/debug.h>
12#include <plat/common/platform.h>
13
14#include <css_def.h>
15
Samarth Parikh59cfa132017-11-23 14:23:21 +053016#include "../mhu/css_mhu.h"
Soby Mathew1ced6b82017-06-12 12:37:10 +010017#include "../scpi/css_scpi.h"
Roberto Vargas2b36b152018-02-12 12:36:17 +000018#include "css_scp.h"
Dan Handley9df48042015-03-19 18:58:55 +000019
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000020/* ID of the MHU slot used for the BOM protocol */
21#define BOM_MHU_SLOT_ID 0
Dan Handley9df48042015-03-19 18:58:55 +000022
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000023/* Boot commands sent from AP -> SCP */
24#define BOOT_CMD_INFO 0x00
25#define BOOT_CMD_DATA 0x01
Dan Handley9df48042015-03-19 18:58:55 +000026
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000027/* BOM command header */
Dan Handley9df48042015-03-19 18:58:55 +000028typedef struct {
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000029 uint32_t id : 8;
30 uint32_t reserved : 24;
31} bom_cmd_t;
Dan Handley9df48042015-03-19 18:58:55 +000032
33typedef struct {
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000034 uint32_t image_size;
35 uint32_t checksum;
36} cmd_info_payload_t;
Dan Handley9df48042015-03-19 18:58:55 +000037
38/*
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000039 * Unlike the SCPI protocol, the boot protocol uses the same memory region
Dan Handley9df48042015-03-19 18:58:55 +000040 * for both AP -> SCP and SCP -> AP transfers; define the address of this...
41 */
Vikram Kanigiri72084192016-02-08 16:29:30 +000042#define BOM_SHARED_MEM PLAT_CSS_SCP_COM_SHARED_MEM_BASE
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000043#define BOM_CMD_HEADER ((bom_cmd_t *) BOM_SHARED_MEM)
44#define BOM_CMD_PAYLOAD ((void *) (BOM_SHARED_MEM + sizeof(bom_cmd_t)))
Dan Handley9df48042015-03-19 18:58:55 +000045
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000046typedef struct {
47 /* Offset from the base address of the Trusted RAM */
48 uint32_t offset;
49 uint32_t block_size;
50} cmd_data_payload_t;
Dan Handley9df48042015-03-19 18:58:55 +000051
Soby Mathew2f6cac42017-06-13 18:00:53 +010052/*
Soby Mathewaf14b462018-06-01 16:53:38 +010053 * All CSS platforms load SCP_BL2/SCP_BL2U just below BL2 (this is where BL31
54 * usually resides except when ARM_BL31_IN_DRAM is
55 * set). Ensure that SCP_BL2/SCP_BL2U do not overflow into shared RAM and
56 * the tb_fw_config.
Soby Mathew2f6cac42017-06-13 18:00:53 +010057 */
Soby Mathewaf14b462018-06-01 16:53:38 +010058CASSERT(SCP_BL2_LIMIT <= BL2_BASE, assert_scp_bl2_overwrite_bl2);
59CASSERT(SCP_BL2U_LIMIT <= BL2_BASE, assert_scp_bl2u_overwrite_bl2);
Soby Mathew2f6cac42017-06-13 18:00:53 +010060
Soby Mathewaf14b462018-06-01 16:53:38 +010061CASSERT(SCP_BL2_BASE >= ARM_TB_FW_CONFIG_LIMIT, assert_scp_bl2_overflow);
62CASSERT(SCP_BL2U_BASE >= ARM_TB_FW_CONFIG_LIMIT, assert_scp_bl2u_overflow);
Soby Mathew2f6cac42017-06-13 18:00:53 +010063
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000064static void scp_boot_message_start(void)
65{
66 mhu_secure_message_start(BOM_MHU_SLOT_ID);
Dan Handley9df48042015-03-19 18:58:55 +000067}
68
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000069static void scp_boot_message_send(size_t payload_size)
Dan Handley9df48042015-03-19 18:58:55 +000070{
Juan Castillo2e86cb12016-01-13 15:01:09 +000071 /* Ensure that any write to the BOM payload area is seen by SCP before
72 * we write to the MHU register. If these 2 writes were reordered by
73 * the CPU then SCP would read stale payload data */
74 dmbst();
Dan Handley9df48042015-03-19 18:58:55 +000075
76 /* Send command to SCP */
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000077 mhu_secure_message_send(BOM_MHU_SLOT_ID);
Dan Handley9df48042015-03-19 18:58:55 +000078}
79
80static uint32_t scp_boot_message_wait(size_t size)
81{
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000082 uint32_t mhu_status;
83
84 mhu_status = mhu_secure_message_wait();
85
86 /* Expect an SCP Boot Protocol message, reject any other protocol */
87 if (mhu_status != (1 << BOM_MHU_SLOT_ID)) {
88 ERROR("MHU: Unexpected protocol (MHU status: 0x%x)\n",
89 mhu_status);
90 panic();
91 }
Dan Handley9df48042015-03-19 18:58:55 +000092
Juan Castillo2e86cb12016-01-13 15:01:09 +000093 /* Ensure that any read to the BOM payload area is done after reading
94 * the MHU register. If these 2 reads were reordered then the CPU would
95 * read invalid payload data */
96 dmbld();
Dan Handley9df48042015-03-19 18:58:55 +000097
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000098 return *(uint32_t *) BOM_SHARED_MEM;
Dan Handley9df48042015-03-19 18:58:55 +000099}
100
101static void scp_boot_message_end(void)
102{
Sandrine Bailleux04b66d82015-03-18 14:52:53 +0000103 mhu_secure_message_end(BOM_MHU_SLOT_ID);
Dan Handley9df48042015-03-19 18:58:55 +0000104}
105
Soby Mathew73b7bf92017-05-03 12:58:41 +0100106int css_scp_boot_image_xfer(void *image, unsigned int image_size)
Dan Handley9df48042015-03-19 18:58:55 +0000107{
Sandrine Bailleux04b66d82015-03-18 14:52:53 +0000108 uint32_t response;
109 uint32_t checksum;
110 cmd_info_payload_t *cmd_info_payload;
111 cmd_data_payload_t *cmd_data_payload;
Dan Handley9df48042015-03-19 18:58:55 +0000112
Juan Castilloa72b6472015-12-10 15:49:17 +0000113 assert((uintptr_t) image == SCP_BL2_BASE);
Dan Handley9df48042015-03-19 18:58:55 +0000114
Sandrine Bailleux04b66d82015-03-18 14:52:53 +0000115 if ((image_size == 0) || (image_size % 4 != 0)) {
Juan Castilloa72b6472015-12-10 15:49:17 +0000116 ERROR("Invalid size for the SCP_BL2 image. Must be a multiple of "
Sandrine Bailleux04b66d82015-03-18 14:52:53 +0000117 "4 bytes and not zero (current size = 0x%x)\n",
118 image_size);
119 return -1;
120 }
Dan Handley9df48042015-03-19 18:58:55 +0000121
Sandrine Bailleux04b66d82015-03-18 14:52:53 +0000122 /* Extract the checksum from the image */
123 checksum = *(uint32_t *) image;
124 image = (char *) image + sizeof(checksum);
125 image_size -= sizeof(checksum);
Dan Handley9df48042015-03-19 18:58:55 +0000126
Sandrine Bailleux04b66d82015-03-18 14:52:53 +0000127 mhu_secure_init();
Dan Handley9df48042015-03-19 18:58:55 +0000128
Juan Castilloa72b6472015-12-10 15:49:17 +0000129 VERBOSE("Send info about the SCP_BL2 image to be transferred to SCP\n");
Dan Handley9df48042015-03-19 18:58:55 +0000130
Sandrine Bailleux04b66d82015-03-18 14:52:53 +0000131 /*
132 * Send information about the SCP firmware image about to be transferred
133 * to SCP
134 */
135 scp_boot_message_start();
136
137 BOM_CMD_HEADER->id = BOOT_CMD_INFO;
138 cmd_info_payload = BOM_CMD_PAYLOAD;
139 cmd_info_payload->image_size = image_size;
140 cmd_info_payload->checksum = checksum;
141
142 scp_boot_message_send(sizeof(*cmd_info_payload));
Sandrine Bailleux7da652d2015-04-13 11:47:48 +0100143#if CSS_DETECT_PRE_1_7_0_SCP
144 {
145 const uint32_t deprecated_scp_nack_cmd = 0x404;
146 uint32_t mhu_status;
147
148 VERBOSE("Detecting SCP version incompatibility\n");
149
150 mhu_status = mhu_secure_message_wait();
151 if (mhu_status == deprecated_scp_nack_cmd) {
152 ERROR("Detected an incompatible version of the SCP firmware.\n");
153 ERROR("Only versions from v1.7.0 onwards are supported.\n");
154 ERROR("Please update the SCP firmware.\n");
155 return -1;
156 }
157
158 VERBOSE("SCP version looks OK\n");
159 }
160#endif /* CSS_DETECT_PRE_1_7_0_SCP */
Sandrine Bailleux04b66d82015-03-18 14:52:53 +0000161 response = scp_boot_message_wait(sizeof(response));
162 scp_boot_message_end();
Dan Handley9df48042015-03-19 18:58:55 +0000163
Sandrine Bailleux04b66d82015-03-18 14:52:53 +0000164 if (response != 0) {
165 ERROR("SCP BOOT_CMD_INFO returned error %u\n", response);
166 return -1;
167 }
168
Juan Castilloa72b6472015-12-10 15:49:17 +0000169 VERBOSE("Transferring SCP_BL2 image to SCP\n");
Dan Handley9df48042015-03-19 18:58:55 +0000170
Juan Castilloa72b6472015-12-10 15:49:17 +0000171 /* Transfer SCP_BL2 image to SCP */
Sandrine Bailleux04b66d82015-03-18 14:52:53 +0000172 scp_boot_message_start();
Dan Handley9df48042015-03-19 18:58:55 +0000173
Sandrine Bailleux04b66d82015-03-18 14:52:53 +0000174 BOM_CMD_HEADER->id = BOOT_CMD_DATA;
175 cmd_data_payload = BOM_CMD_PAYLOAD;
Sandrine Bailleux47ea1bc2015-06-09 11:53:33 +0100176 cmd_data_payload->offset = (uintptr_t) image - ARM_TRUSTED_SRAM_BASE;
Sandrine Bailleux04b66d82015-03-18 14:52:53 +0000177 cmd_data_payload->block_size = image_size;
Dan Handley9df48042015-03-19 18:58:55 +0000178
Sandrine Bailleux04b66d82015-03-18 14:52:53 +0000179 scp_boot_message_send(sizeof(*cmd_data_payload));
180 response = scp_boot_message_wait(sizeof(response));
181 scp_boot_message_end();
Dan Handley9df48042015-03-19 18:58:55 +0000182
Sandrine Bailleux04b66d82015-03-18 14:52:53 +0000183 if (response != 0) {
184 ERROR("SCP BOOT_CMD_DATA returned error %u\n", response);
185 return -1;
Dan Handley9df48042015-03-19 18:58:55 +0000186 }
187
Soby Mathew73b7bf92017-05-03 12:58:41 +0100188 return 0;
Dan Handley9df48042015-03-19 18:58:55 +0000189}
Soby Mathew1ced6b82017-06-12 12:37:10 +0100190
191int css_scp_boot_ready(void)
192{
193 VERBOSE("Waiting for SCP to signal it is ready to go on\n");
194
195 /* Wait for SCP to signal it's ready */
196 return scpi_wait_ready();
197}