blob: 5268510dbd0708c316f83260ede9b26471963821 [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
7#include <arch_helpers.h>
Sandrine Bailleux04b66d82015-03-18 14:52:53 +00008#include <assert.h>
Dan Handley9df48042015-03-19 18:58:55 +00009#include <css_def.h>
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000010#include <debug.h>
Dan Handley9df48042015-03-19 18:58:55 +000011#include <platform.h>
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000012#include <stdint.h>
Samarth Parikh59cfa132017-11-23 14:23:21 +053013#include "../mhu/css_mhu.h"
Soby Mathew1ced6b82017-06-12 12:37:10 +010014#include "../scpi/css_scpi.h"
Roberto Vargas2b36b152018-02-12 12:36:17 +000015#include "css_scp.h"
Dan Handley9df48042015-03-19 18:58:55 +000016
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000017/* ID of the MHU slot used for the BOM protocol */
18#define BOM_MHU_SLOT_ID 0
Dan Handley9df48042015-03-19 18:58:55 +000019
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000020/* Boot commands sent from AP -> SCP */
21#define BOOT_CMD_INFO 0x00
22#define BOOT_CMD_DATA 0x01
Dan Handley9df48042015-03-19 18:58:55 +000023
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000024/* BOM command header */
Dan Handley9df48042015-03-19 18:58:55 +000025typedef struct {
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000026 uint32_t id : 8;
27 uint32_t reserved : 24;
28} bom_cmd_t;
Dan Handley9df48042015-03-19 18:58:55 +000029
30typedef struct {
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000031 uint32_t image_size;
32 uint32_t checksum;
33} cmd_info_payload_t;
Dan Handley9df48042015-03-19 18:58:55 +000034
35/*
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000036 * Unlike the SCPI protocol, the boot protocol uses the same memory region
Dan Handley9df48042015-03-19 18:58:55 +000037 * for both AP -> SCP and SCP -> AP transfers; define the address of this...
38 */
Vikram Kanigiri72084192016-02-08 16:29:30 +000039#define BOM_SHARED_MEM PLAT_CSS_SCP_COM_SHARED_MEM_BASE
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000040#define BOM_CMD_HEADER ((bom_cmd_t *) BOM_SHARED_MEM)
41#define BOM_CMD_PAYLOAD ((void *) (BOM_SHARED_MEM + sizeof(bom_cmd_t)))
Dan Handley9df48042015-03-19 18:58:55 +000042
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000043typedef struct {
44 /* Offset from the base address of the Trusted RAM */
45 uint32_t offset;
46 uint32_t block_size;
47} cmd_data_payload_t;
Dan Handley9df48042015-03-19 18:58:55 +000048
Soby Mathew2f6cac42017-06-13 18:00:53 +010049/*
Soby Mathewaf14b462018-06-01 16:53:38 +010050 * All CSS platforms load SCP_BL2/SCP_BL2U just below BL2 (this is where BL31
51 * usually resides except when ARM_BL31_IN_DRAM is
52 * set). Ensure that SCP_BL2/SCP_BL2U do not overflow into shared RAM and
53 * the tb_fw_config.
Soby Mathew2f6cac42017-06-13 18:00:53 +010054 */
Soby Mathewaf14b462018-06-01 16:53:38 +010055CASSERT(SCP_BL2_LIMIT <= BL2_BASE, assert_scp_bl2_overwrite_bl2);
56CASSERT(SCP_BL2U_LIMIT <= BL2_BASE, assert_scp_bl2u_overwrite_bl2);
Soby Mathew2f6cac42017-06-13 18:00:53 +010057
Soby Mathewaf14b462018-06-01 16:53:38 +010058CASSERT(SCP_BL2_BASE >= ARM_TB_FW_CONFIG_LIMIT, assert_scp_bl2_overflow);
59CASSERT(SCP_BL2U_BASE >= ARM_TB_FW_CONFIG_LIMIT, assert_scp_bl2u_overflow);
Soby Mathew2f6cac42017-06-13 18:00:53 +010060
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000061static void scp_boot_message_start(void)
62{
63 mhu_secure_message_start(BOM_MHU_SLOT_ID);
Dan Handley9df48042015-03-19 18:58:55 +000064}
65
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000066static void scp_boot_message_send(size_t payload_size)
Dan Handley9df48042015-03-19 18:58:55 +000067{
Juan Castillo2e86cb12016-01-13 15:01:09 +000068 /* Ensure that any write to the BOM payload area is seen by SCP before
69 * we write to the MHU register. If these 2 writes were reordered by
70 * the CPU then SCP would read stale payload data */
71 dmbst();
Dan Handley9df48042015-03-19 18:58:55 +000072
73 /* Send command to SCP */
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000074 mhu_secure_message_send(BOM_MHU_SLOT_ID);
Dan Handley9df48042015-03-19 18:58:55 +000075}
76
77static uint32_t scp_boot_message_wait(size_t size)
78{
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000079 uint32_t mhu_status;
80
81 mhu_status = mhu_secure_message_wait();
82
83 /* Expect an SCP Boot Protocol message, reject any other protocol */
84 if (mhu_status != (1 << BOM_MHU_SLOT_ID)) {
85 ERROR("MHU: Unexpected protocol (MHU status: 0x%x)\n",
86 mhu_status);
87 panic();
88 }
Dan Handley9df48042015-03-19 18:58:55 +000089
Juan Castillo2e86cb12016-01-13 15:01:09 +000090 /* Ensure that any read to the BOM payload area is done after reading
91 * the MHU register. If these 2 reads were reordered then the CPU would
92 * read invalid payload data */
93 dmbld();
Dan Handley9df48042015-03-19 18:58:55 +000094
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000095 return *(uint32_t *) BOM_SHARED_MEM;
Dan Handley9df48042015-03-19 18:58:55 +000096}
97
98static void scp_boot_message_end(void)
99{
Sandrine Bailleux04b66d82015-03-18 14:52:53 +0000100 mhu_secure_message_end(BOM_MHU_SLOT_ID);
Dan Handley9df48042015-03-19 18:58:55 +0000101}
102
Soby Mathew73b7bf92017-05-03 12:58:41 +0100103int css_scp_boot_image_xfer(void *image, unsigned int image_size)
Dan Handley9df48042015-03-19 18:58:55 +0000104{
Sandrine Bailleux04b66d82015-03-18 14:52:53 +0000105 uint32_t response;
106 uint32_t checksum;
107 cmd_info_payload_t *cmd_info_payload;
108 cmd_data_payload_t *cmd_data_payload;
Dan Handley9df48042015-03-19 18:58:55 +0000109
Juan Castilloa72b6472015-12-10 15:49:17 +0000110 assert((uintptr_t) image == SCP_BL2_BASE);
Dan Handley9df48042015-03-19 18:58:55 +0000111
Sandrine Bailleux04b66d82015-03-18 14:52:53 +0000112 if ((image_size == 0) || (image_size % 4 != 0)) {
Juan Castilloa72b6472015-12-10 15:49:17 +0000113 ERROR("Invalid size for the SCP_BL2 image. Must be a multiple of "
Sandrine Bailleux04b66d82015-03-18 14:52:53 +0000114 "4 bytes and not zero (current size = 0x%x)\n",
115 image_size);
116 return -1;
117 }
Dan Handley9df48042015-03-19 18:58:55 +0000118
Sandrine Bailleux04b66d82015-03-18 14:52:53 +0000119 /* Extract the checksum from the image */
120 checksum = *(uint32_t *) image;
121 image = (char *) image + sizeof(checksum);
122 image_size -= sizeof(checksum);
Dan Handley9df48042015-03-19 18:58:55 +0000123
Sandrine Bailleux04b66d82015-03-18 14:52:53 +0000124 mhu_secure_init();
Dan Handley9df48042015-03-19 18:58:55 +0000125
Juan Castilloa72b6472015-12-10 15:49:17 +0000126 VERBOSE("Send info about the SCP_BL2 image to be transferred to SCP\n");
Dan Handley9df48042015-03-19 18:58:55 +0000127
Sandrine Bailleux04b66d82015-03-18 14:52:53 +0000128 /*
129 * Send information about the SCP firmware image about to be transferred
130 * to SCP
131 */
132 scp_boot_message_start();
133
134 BOM_CMD_HEADER->id = BOOT_CMD_INFO;
135 cmd_info_payload = BOM_CMD_PAYLOAD;
136 cmd_info_payload->image_size = image_size;
137 cmd_info_payload->checksum = checksum;
138
139 scp_boot_message_send(sizeof(*cmd_info_payload));
Sandrine Bailleux7da652d2015-04-13 11:47:48 +0100140#if CSS_DETECT_PRE_1_7_0_SCP
141 {
142 const uint32_t deprecated_scp_nack_cmd = 0x404;
143 uint32_t mhu_status;
144
145 VERBOSE("Detecting SCP version incompatibility\n");
146
147 mhu_status = mhu_secure_message_wait();
148 if (mhu_status == deprecated_scp_nack_cmd) {
149 ERROR("Detected an incompatible version of the SCP firmware.\n");
150 ERROR("Only versions from v1.7.0 onwards are supported.\n");
151 ERROR("Please update the SCP firmware.\n");
152 return -1;
153 }
154
155 VERBOSE("SCP version looks OK\n");
156 }
157#endif /* CSS_DETECT_PRE_1_7_0_SCP */
Sandrine Bailleux04b66d82015-03-18 14:52:53 +0000158 response = scp_boot_message_wait(sizeof(response));
159 scp_boot_message_end();
Dan Handley9df48042015-03-19 18:58:55 +0000160
Sandrine Bailleux04b66d82015-03-18 14:52:53 +0000161 if (response != 0) {
162 ERROR("SCP BOOT_CMD_INFO returned error %u\n", response);
163 return -1;
164 }
165
Juan Castilloa72b6472015-12-10 15:49:17 +0000166 VERBOSE("Transferring SCP_BL2 image to SCP\n");
Dan Handley9df48042015-03-19 18:58:55 +0000167
Juan Castilloa72b6472015-12-10 15:49:17 +0000168 /* Transfer SCP_BL2 image to SCP */
Sandrine Bailleux04b66d82015-03-18 14:52:53 +0000169 scp_boot_message_start();
Dan Handley9df48042015-03-19 18:58:55 +0000170
Sandrine Bailleux04b66d82015-03-18 14:52:53 +0000171 BOM_CMD_HEADER->id = BOOT_CMD_DATA;
172 cmd_data_payload = BOM_CMD_PAYLOAD;
Sandrine Bailleux47ea1bc2015-06-09 11:53:33 +0100173 cmd_data_payload->offset = (uintptr_t) image - ARM_TRUSTED_SRAM_BASE;
Sandrine Bailleux04b66d82015-03-18 14:52:53 +0000174 cmd_data_payload->block_size = image_size;
Dan Handley9df48042015-03-19 18:58:55 +0000175
Sandrine Bailleux04b66d82015-03-18 14:52:53 +0000176 scp_boot_message_send(sizeof(*cmd_data_payload));
177 response = scp_boot_message_wait(sizeof(response));
178 scp_boot_message_end();
Dan Handley9df48042015-03-19 18:58:55 +0000179
Sandrine Bailleux04b66d82015-03-18 14:52:53 +0000180 if (response != 0) {
181 ERROR("SCP BOOT_CMD_DATA returned error %u\n", response);
182 return -1;
Dan Handley9df48042015-03-19 18:58:55 +0000183 }
184
Soby Mathew73b7bf92017-05-03 12:58:41 +0100185 return 0;
Dan Handley9df48042015-03-19 18:58:55 +0000186}
Soby Mathew1ced6b82017-06-12 12:37:10 +0100187
188int css_scp_boot_ready(void)
189{
190 VERBOSE("Waiting for SCP to signal it is ready to go on\n");
191
192 /* Wait for SCP to signal it's ready */
193 return scpi_wait_ready();
194}