blob: 40880da29969f910b99b1e084360f7b3b638c15e [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>
Antonio Nino Diaz1b0c6f12019-01-23 21:08:43 +000012#include <drivers/arm/css/css_mhu.h>
Antonio Nino Diazae9654d2019-01-25 14:23:49 +000013#include <drivers/arm/css/css_scpi.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000014#include <plat/common/platform.h>
Antonio Nino Diaza320ecd2019-01-15 14:19:50 +000015#include <platform_def.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000016
Roberto Vargas2b36b152018-02-12 12:36:17 +000017#include "css_scp.h"
Dan Handley9df48042015-03-19 18:58:55 +000018
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000019/* ID of the MHU slot used for the BOM protocol */
20#define BOM_MHU_SLOT_ID 0
Dan Handley9df48042015-03-19 18:58:55 +000021
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000022/* Boot commands sent from AP -> SCP */
23#define BOOT_CMD_INFO 0x00
24#define BOOT_CMD_DATA 0x01
Dan Handley9df48042015-03-19 18:58:55 +000025
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000026/* BOM command header */
Dan Handley9df48042015-03-19 18:58:55 +000027typedef struct {
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000028 uint32_t id : 8;
29 uint32_t reserved : 24;
30} bom_cmd_t;
Dan Handley9df48042015-03-19 18:58:55 +000031
32typedef struct {
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000033 uint32_t image_size;
34 uint32_t checksum;
35} cmd_info_payload_t;
Dan Handley9df48042015-03-19 18:58:55 +000036
37/*
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000038 * Unlike the SCPI protocol, the boot protocol uses the same memory region
Dan Handley9df48042015-03-19 18:58:55 +000039 * for both AP -> SCP and SCP -> AP transfers; define the address of this...
40 */
Vikram Kanigiri72084192016-02-08 16:29:30 +000041#define BOM_SHARED_MEM PLAT_CSS_SCP_COM_SHARED_MEM_BASE
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000042#define BOM_CMD_HEADER ((bom_cmd_t *) BOM_SHARED_MEM)
43#define BOM_CMD_PAYLOAD ((void *) (BOM_SHARED_MEM + sizeof(bom_cmd_t)))
Dan Handley9df48042015-03-19 18:58:55 +000044
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000045typedef struct {
46 /* Offset from the base address of the Trusted RAM */
47 uint32_t offset;
48 uint32_t block_size;
49} cmd_data_payload_t;
Dan Handley9df48042015-03-19 18:58:55 +000050
Soby Mathew2f6cac42017-06-13 18:00:53 +010051/*
Soby Mathewaf14b462018-06-01 16:53:38 +010052 * All CSS platforms load SCP_BL2/SCP_BL2U just below BL2 (this is where BL31
53 * usually resides except when ARM_BL31_IN_DRAM is
54 * set). Ensure that SCP_BL2/SCP_BL2U do not overflow into shared RAM and
55 * the tb_fw_config.
Soby Mathew2f6cac42017-06-13 18:00:53 +010056 */
Soby Mathewaf14b462018-06-01 16:53:38 +010057CASSERT(SCP_BL2_LIMIT <= BL2_BASE, assert_scp_bl2_overwrite_bl2);
58CASSERT(SCP_BL2U_LIMIT <= BL2_BASE, assert_scp_bl2u_overwrite_bl2);
Soby Mathew2f6cac42017-06-13 18:00:53 +010059
Soby Mathewaf14b462018-06-01 16:53:38 +010060CASSERT(SCP_BL2_BASE >= ARM_TB_FW_CONFIG_LIMIT, assert_scp_bl2_overflow);
61CASSERT(SCP_BL2U_BASE >= ARM_TB_FW_CONFIG_LIMIT, assert_scp_bl2u_overflow);
Soby Mathew2f6cac42017-06-13 18:00:53 +010062
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000063static void scp_boot_message_start(void)
64{
65 mhu_secure_message_start(BOM_MHU_SLOT_ID);
Dan Handley9df48042015-03-19 18:58:55 +000066}
67
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000068static void scp_boot_message_send(size_t payload_size)
Dan Handley9df48042015-03-19 18:58:55 +000069{
Juan Castillo2e86cb12016-01-13 15:01:09 +000070 /* Ensure that any write to the BOM payload area is seen by SCP before
71 * we write to the MHU register. If these 2 writes were reordered by
72 * the CPU then SCP would read stale payload data */
73 dmbst();
Dan Handley9df48042015-03-19 18:58:55 +000074
75 /* Send command to SCP */
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000076 mhu_secure_message_send(BOM_MHU_SLOT_ID);
Dan Handley9df48042015-03-19 18:58:55 +000077}
78
79static uint32_t scp_boot_message_wait(size_t size)
80{
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000081 uint32_t mhu_status;
82
83 mhu_status = mhu_secure_message_wait();
84
85 /* Expect an SCP Boot Protocol message, reject any other protocol */
86 if (mhu_status != (1 << BOM_MHU_SLOT_ID)) {
87 ERROR("MHU: Unexpected protocol (MHU status: 0x%x)\n",
88 mhu_status);
89 panic();
90 }
Dan Handley9df48042015-03-19 18:58:55 +000091
Juan Castillo2e86cb12016-01-13 15:01:09 +000092 /* Ensure that any read to the BOM payload area is done after reading
93 * the MHU register. If these 2 reads were reordered then the CPU would
94 * read invalid payload data */
95 dmbld();
Dan Handley9df48042015-03-19 18:58:55 +000096
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000097 return *(uint32_t *) BOM_SHARED_MEM;
Dan Handley9df48042015-03-19 18:58:55 +000098}
99
100static void scp_boot_message_end(void)
101{
Sandrine Bailleux04b66d82015-03-18 14:52:53 +0000102 mhu_secure_message_end(BOM_MHU_SLOT_ID);
Dan Handley9df48042015-03-19 18:58:55 +0000103}
104
Soby Mathew73b7bf92017-05-03 12:58:41 +0100105int css_scp_boot_image_xfer(void *image, unsigned int image_size)
Dan Handley9df48042015-03-19 18:58:55 +0000106{
Sandrine Bailleux04b66d82015-03-18 14:52:53 +0000107 uint32_t response;
108 uint32_t checksum;
109 cmd_info_payload_t *cmd_info_payload;
110 cmd_data_payload_t *cmd_data_payload;
Dan Handley9df48042015-03-19 18:58:55 +0000111
Juan Castilloa72b6472015-12-10 15:49:17 +0000112 assert((uintptr_t) image == SCP_BL2_BASE);
Dan Handley9df48042015-03-19 18:58:55 +0000113
Sandrine Bailleux04b66d82015-03-18 14:52:53 +0000114 if ((image_size == 0) || (image_size % 4 != 0)) {
Juan Castilloa72b6472015-12-10 15:49:17 +0000115 ERROR("Invalid size for the SCP_BL2 image. Must be a multiple of "
Sandrine Bailleux04b66d82015-03-18 14:52:53 +0000116 "4 bytes and not zero (current size = 0x%x)\n",
117 image_size);
118 return -1;
119 }
Dan Handley9df48042015-03-19 18:58:55 +0000120
Sandrine Bailleux04b66d82015-03-18 14:52:53 +0000121 /* Extract the checksum from the image */
122 checksum = *(uint32_t *) image;
123 image = (char *) image + sizeof(checksum);
124 image_size -= sizeof(checksum);
Dan Handley9df48042015-03-19 18:58:55 +0000125
Sandrine Bailleux04b66d82015-03-18 14:52:53 +0000126 mhu_secure_init();
Dan Handley9df48042015-03-19 18:58:55 +0000127
Juan Castilloa72b6472015-12-10 15:49:17 +0000128 VERBOSE("Send info about the SCP_BL2 image to be transferred to SCP\n");
Dan Handley9df48042015-03-19 18:58:55 +0000129
Sandrine Bailleux04b66d82015-03-18 14:52:53 +0000130 /*
131 * Send information about the SCP firmware image about to be transferred
132 * to SCP
133 */
134 scp_boot_message_start();
135
136 BOM_CMD_HEADER->id = BOOT_CMD_INFO;
137 cmd_info_payload = BOM_CMD_PAYLOAD;
138 cmd_info_payload->image_size = image_size;
139 cmd_info_payload->checksum = checksum;
140
141 scp_boot_message_send(sizeof(*cmd_info_payload));
Sandrine Bailleux7da652d2015-04-13 11:47:48 +0100142#if CSS_DETECT_PRE_1_7_0_SCP
143 {
144 const uint32_t deprecated_scp_nack_cmd = 0x404;
145 uint32_t mhu_status;
146
147 VERBOSE("Detecting SCP version incompatibility\n");
148
149 mhu_status = mhu_secure_message_wait();
150 if (mhu_status == deprecated_scp_nack_cmd) {
151 ERROR("Detected an incompatible version of the SCP firmware.\n");
152 ERROR("Only versions from v1.7.0 onwards are supported.\n");
153 ERROR("Please update the SCP firmware.\n");
154 return -1;
155 }
156
157 VERBOSE("SCP version looks OK\n");
158 }
159#endif /* CSS_DETECT_PRE_1_7_0_SCP */
Sandrine Bailleux04b66d82015-03-18 14:52:53 +0000160 response = scp_boot_message_wait(sizeof(response));
161 scp_boot_message_end();
Dan Handley9df48042015-03-19 18:58:55 +0000162
Sandrine Bailleux04b66d82015-03-18 14:52:53 +0000163 if (response != 0) {
164 ERROR("SCP BOOT_CMD_INFO returned error %u\n", response);
165 return -1;
166 }
167
Juan Castilloa72b6472015-12-10 15:49:17 +0000168 VERBOSE("Transferring SCP_BL2 image to SCP\n");
Dan Handley9df48042015-03-19 18:58:55 +0000169
Juan Castilloa72b6472015-12-10 15:49:17 +0000170 /* Transfer SCP_BL2 image to SCP */
Sandrine Bailleux04b66d82015-03-18 14:52:53 +0000171 scp_boot_message_start();
Dan Handley9df48042015-03-19 18:58:55 +0000172
Sandrine Bailleux04b66d82015-03-18 14:52:53 +0000173 BOM_CMD_HEADER->id = BOOT_CMD_DATA;
174 cmd_data_payload = BOM_CMD_PAYLOAD;
Sandrine Bailleux47ea1bc2015-06-09 11:53:33 +0100175 cmd_data_payload->offset = (uintptr_t) image - ARM_TRUSTED_SRAM_BASE;
Sandrine Bailleux04b66d82015-03-18 14:52:53 +0000176 cmd_data_payload->block_size = image_size;
Dan Handley9df48042015-03-19 18:58:55 +0000177
Sandrine Bailleux04b66d82015-03-18 14:52:53 +0000178 scp_boot_message_send(sizeof(*cmd_data_payload));
179 response = scp_boot_message_wait(sizeof(response));
180 scp_boot_message_end();
Dan Handley9df48042015-03-19 18:58:55 +0000181
Sandrine Bailleux04b66d82015-03-18 14:52:53 +0000182 if (response != 0) {
183 ERROR("SCP BOOT_CMD_DATA returned error %u\n", response);
184 return -1;
Dan Handley9df48042015-03-19 18:58:55 +0000185 }
186
Soby Mathew73b7bf92017-05-03 12:58:41 +0100187 return 0;
Dan Handley9df48042015-03-19 18:58:55 +0000188}
Soby Mathew1ced6b82017-06-12 12:37:10 +0100189
190int css_scp_boot_ready(void)
191{
192 VERBOSE("Waiting for SCP to signal it is ready to go on\n");
193
194 /* Wait for SCP to signal it's ready */
195 return scpi_wait_ready();
196}