blob: 74121b4877be8c507d7d898b7c8925adc78fa7a3 [file] [log] [blame]
Dan Handleyb4315302015-03-19 18:58:55 +00001/*
Manish V Badarkhe04e06972020-05-31 10:17:59 +01002 * Copyright (c) 2014-2020, ARM Limited and Contributors. All rights reserved.
Dan Handleyb4315302015-03-19 18:58:55 +00003 *
dp-arm82cb2c12017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Dan Handleyb4315302015-03-19 18:58:55 +00005 */
6
Sandrine Bailleuxe234ba02015-03-18 14:52:53 +00007#include <assert.h>
Sandrine Bailleuxe234ba02015-03-18 14:52:53 +00008#include <stdint.h>
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +00009
10#include <arch_helpers.h>
11#include <common/debug.h>
Antonio Nino Diazc4113962019-01-23 21:08:43 +000012#include <drivers/arm/css/css_mhu.h>
Antonio Nino Diaz2d4135e2019-01-23 18:55:03 +000013#include <drivers/arm/css/css_scp.h>
Antonio Nino Diaz0387aa42019-01-25 14:23:49 +000014#include <drivers/arm/css/css_scpi.h>
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +000015#include <plat/common/platform.h>
Antonio Nino Diaz234bc7f2019-01-15 14:19:50 +000016#include <platform_def.h>
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +000017
Sandrine Bailleuxe234ba02015-03-18 14:52:53 +000018/* ID of the MHU slot used for the BOM protocol */
19#define BOM_MHU_SLOT_ID 0
20
Dan Handleyb4315302015-03-19 18:58:55 +000021/* Boot commands sent from AP -> SCP */
Sandrine Bailleuxe234ba02015-03-18 14:52:53 +000022#define BOOT_CMD_INFO 0x00
23#define BOOT_CMD_DATA 0x01
24
25/* BOM command header */
26typedef struct {
27 uint32_t id : 8;
28 uint32_t reserved : 24;
29} bom_cmd_t;
Dan Handleyb4315302015-03-19 18:58:55 +000030
31typedef struct {
32 uint32_t image_size;
Sandrine Bailleuxe234ba02015-03-18 14:52:53 +000033 uint32_t checksum;
34} cmd_info_payload_t;
Dan Handleyb4315302015-03-19 18:58:55 +000035
36/*
Sandrine Bailleuxe234ba02015-03-18 14:52:53 +000037 * Unlike the SCPI protocol, the boot protocol uses the same memory region
Dan Handleyb4315302015-03-19 18:58:55 +000038 * for both AP -> SCP and SCP -> AP transfers; define the address of this...
39 */
Vikram Kanigiri8e083ec2016-02-08 16:29:30 +000040#define BOM_SHARED_MEM PLAT_CSS_SCP_COM_SHARED_MEM_BASE
Sandrine Bailleuxe234ba02015-03-18 14:52:53 +000041#define BOM_CMD_HEADER ((bom_cmd_t *) BOM_SHARED_MEM)
42#define BOM_CMD_PAYLOAD ((void *) (BOM_SHARED_MEM + sizeof(bom_cmd_t)))
Dan Handleyb4315302015-03-19 18:58:55 +000043
Sandrine Bailleuxe234ba02015-03-18 14:52:53 +000044typedef struct {
45 /* Offset from the base address of the Trusted RAM */
46 uint32_t offset;
47 uint32_t block_size;
48} cmd_data_payload_t;
49
Soby Mathew1ea63d72017-06-13 18:00:53 +010050/*
Soby Mathewc099cd32018-06-01 16:53:38 +010051 * All CSS platforms load SCP_BL2/SCP_BL2U just below BL2 (this is where BL31
52 * usually resides except when ARM_BL31_IN_DRAM is
53 * set). Ensure that SCP_BL2/SCP_BL2U do not overflow into shared RAM and
Manish V Badarkhe04e06972020-05-31 10:17:59 +010054 * the fw_config.
Soby Mathew1ea63d72017-06-13 18:00:53 +010055 */
Soby Mathewc099cd32018-06-01 16:53:38 +010056CASSERT(SCP_BL2_LIMIT <= BL2_BASE, assert_scp_bl2_overwrite_bl2);
57CASSERT(SCP_BL2U_LIMIT <= BL2_BASE, assert_scp_bl2u_overwrite_bl2);
Soby Mathew1ea63d72017-06-13 18:00:53 +010058
Manish V Badarkhe04e06972020-05-31 10:17:59 +010059CASSERT(SCP_BL2_BASE >= ARM_FW_CONFIG_LIMIT, assert_scp_bl2_overflow);
60CASSERT(SCP_BL2U_BASE >= ARM_FW_CONFIG_LIMIT, assert_scp_bl2u_overflow);
Soby Mathew1ea63d72017-06-13 18:00:53 +010061
Sandrine Bailleuxe234ba02015-03-18 14:52:53 +000062static void scp_boot_message_start(void)
Dan Handleyb4315302015-03-19 18:58:55 +000063{
Sandrine Bailleuxe234ba02015-03-18 14:52:53 +000064 mhu_secure_message_start(BOM_MHU_SLOT_ID);
Dan Handleyb4315302015-03-19 18:58:55 +000065}
66
Sandrine Bailleuxe234ba02015-03-18 14:52:53 +000067static void scp_boot_message_send(size_t payload_size)
Dan Handleyb4315302015-03-19 18:58:55 +000068{
Juan Castillo74eb26e2016-01-13 15:01:09 +000069 /* Ensure that any write to the BOM payload area is seen by SCP before
70 * we write to the MHU register. If these 2 writes were reordered by
71 * the CPU then SCP would read stale payload data */
72 dmbst();
Dan Handleyb4315302015-03-19 18:58:55 +000073
74 /* Send command to SCP */
Sandrine Bailleuxe234ba02015-03-18 14:52:53 +000075 mhu_secure_message_send(BOM_MHU_SLOT_ID);
Dan Handleyb4315302015-03-19 18:58:55 +000076}
77
78static uint32_t scp_boot_message_wait(size_t size)
79{
Sandrine Bailleuxe234ba02015-03-18 14:52:53 +000080 uint32_t mhu_status;
81
82 mhu_status = mhu_secure_message_wait();
83
84 /* Expect an SCP Boot Protocol message, reject any other protocol */
85 if (mhu_status != (1 << BOM_MHU_SLOT_ID)) {
86 ERROR("MHU: Unexpected protocol (MHU status: 0x%x)\n",
87 mhu_status);
88 panic();
89 }
Dan Handleyb4315302015-03-19 18:58:55 +000090
Juan Castillo74eb26e2016-01-13 15:01:09 +000091 /* Ensure that any read to the BOM payload area is done after reading
92 * the MHU register. If these 2 reads were reordered then the CPU would
93 * read invalid payload data */
94 dmbld();
Dan Handleyb4315302015-03-19 18:58:55 +000095
Sandrine Bailleuxe234ba02015-03-18 14:52:53 +000096 return *(uint32_t *) BOM_SHARED_MEM;
Dan Handleyb4315302015-03-19 18:58:55 +000097}
98
99static void scp_boot_message_end(void)
100{
Sandrine Bailleuxe234ba02015-03-18 14:52:53 +0000101 mhu_secure_message_end(BOM_MHU_SLOT_ID);
Dan Handleyb4315302015-03-19 18:58:55 +0000102}
103
Soby Mathew74d44a42017-05-03 12:58:41 +0100104int css_scp_boot_image_xfer(void *image, unsigned int image_size)
Dan Handleyb4315302015-03-19 18:58:55 +0000105{
Dan Handleyb4315302015-03-19 18:58:55 +0000106 uint32_t response;
Sandrine Bailleuxe234ba02015-03-18 14:52:53 +0000107 uint32_t checksum;
108 cmd_info_payload_t *cmd_info_payload;
109 cmd_data_payload_t *cmd_data_payload;
110
Juan Castillof59821d2015-12-10 15:49:17 +0000111 assert((uintptr_t) image == SCP_BL2_BASE);
Sandrine Bailleuxe234ba02015-03-18 14:52:53 +0000112
113 if ((image_size == 0) || (image_size % 4 != 0)) {
Juan Castillof59821d2015-12-10 15:49:17 +0000114 ERROR("Invalid size for the SCP_BL2 image. Must be a multiple of "
Sandrine Bailleuxe234ba02015-03-18 14:52:53 +0000115 "4 bytes and not zero (current size = 0x%x)\n",
116 image_size);
117 return -1;
118 }
119
120 /* Extract the checksum from the image */
121 checksum = *(uint32_t *) image;
122 image = (char *) image + sizeof(checksum);
123 image_size -= sizeof(checksum);
Dan Handleyb4315302015-03-19 18:58:55 +0000124
125 mhu_secure_init();
126
Juan Castillof59821d2015-12-10 15:49:17 +0000127 VERBOSE("Send info about the SCP_BL2 image to be transferred to SCP\n");
Dan Handleyb4315302015-03-19 18:58:55 +0000128
Sandrine Bailleuxe234ba02015-03-18 14:52:53 +0000129 /*
130 * Send information about the SCP firmware image about to be transferred
131 * to SCP
132 */
133 scp_boot_message_start();
Dan Handleyb4315302015-03-19 18:58:55 +0000134
Sandrine Bailleuxe234ba02015-03-18 14:52:53 +0000135 BOM_CMD_HEADER->id = BOOT_CMD_INFO;
136 cmd_info_payload = BOM_CMD_PAYLOAD;
137 cmd_info_payload->image_size = image_size;
138 cmd_info_payload->checksum = checksum;
Dan Handleyb4315302015-03-19 18:58:55 +0000139
Sandrine Bailleuxe234ba02015-03-18 14:52:53 +0000140 scp_boot_message_send(sizeof(*cmd_info_payload));
Sandrine Bailleux556b9662015-04-13 11:47:48 +0100141#if CSS_DETECT_PRE_1_7_0_SCP
142 {
143 const uint32_t deprecated_scp_nack_cmd = 0x404;
144 uint32_t mhu_status;
145
146 VERBOSE("Detecting SCP version incompatibility\n");
147
148 mhu_status = mhu_secure_message_wait();
149 if (mhu_status == deprecated_scp_nack_cmd) {
150 ERROR("Detected an incompatible version of the SCP firmware.\n");
151 ERROR("Only versions from v1.7.0 onwards are supported.\n");
152 ERROR("Please update the SCP firmware.\n");
153 return -1;
154 }
155
156 VERBOSE("SCP version looks OK\n");
157 }
158#endif /* CSS_DETECT_PRE_1_7_0_SCP */
Sandrine Bailleuxe234ba02015-03-18 14:52:53 +0000159 response = scp_boot_message_wait(sizeof(response));
160 scp_boot_message_end();
Dan Handleyb4315302015-03-19 18:58:55 +0000161
Sandrine Bailleuxe234ba02015-03-18 14:52:53 +0000162 if (response != 0) {
163 ERROR("SCP BOOT_CMD_INFO returned error %u\n", response);
164 return -1;
Dan Handleyb4315302015-03-19 18:58:55 +0000165 }
166
Juan Castillof59821d2015-12-10 15:49:17 +0000167 VERBOSE("Transferring SCP_BL2 image to SCP\n");
Sandrine Bailleuxe234ba02015-03-18 14:52:53 +0000168
Juan Castillof59821d2015-12-10 15:49:17 +0000169 /* Transfer SCP_BL2 image to SCP */
Sandrine Bailleuxe234ba02015-03-18 14:52:53 +0000170 scp_boot_message_start();
171
172 BOM_CMD_HEADER->id = BOOT_CMD_DATA;
173 cmd_data_payload = BOM_CMD_PAYLOAD;
Sandrine Bailleuxfe556122015-06-09 11:53:33 +0100174 cmd_data_payload->offset = (uintptr_t) image - ARM_TRUSTED_SRAM_BASE;
Sandrine Bailleuxe234ba02015-03-18 14:52:53 +0000175 cmd_data_payload->block_size = image_size;
176
177 scp_boot_message_send(sizeof(*cmd_data_payload));
178 response = scp_boot_message_wait(sizeof(response));
179 scp_boot_message_end();
180
181 if (response != 0) {
182 ERROR("SCP BOOT_CMD_DATA returned error %u\n", response);
183 return -1;
184 }
185
Soby Mathew74d44a42017-05-03 12:58:41 +0100186 return 0;
Dan Handleyb4315302015-03-19 18:58:55 +0000187}
Soby Mathew18e279e2017-06-12 12:37:10 +0100188
189int css_scp_boot_ready(void)
190{
191 VERBOSE("Waiting for SCP to signal it is ready to go on\n");
192
193 /* Wait for SCP to signal it's ready */
194 return scpi_wait_ready();
195}