@@ -12,4 +12,9 @@ config SYS_SOC
config SYS_CONFIG_NAME
default "bcm_ns3"
+config CHIMP_OPTEE
+ bool "Enable secure ChiMP firmware loading"
+ depends on OPTEE
+ default y
+
endif
@@ -3,3 +3,4 @@
# Copyright 2020 Broadcom.
obj-y := ns3.o
+obj-$(CONFIG_CHIMP_OPTEE) += chimp_optee.o
new file mode 100644
@@ -0,0 +1,154 @@
+// SPDX-License-Identifier: BSD-2-Clause
+/*
+ * Copyright 2020 Broadcom.
+ */
+
+#include <brcm/chimp.h>
+#include <common.h>
+#include <tee.h>
+
+#define CHMIP_BOOT_UUID { 0x6272636D, 0x2019, 0x0716, \
+ { 0x42, 0x43, 0x4D, 0x5F, 0x53, 0x43, 0x48, 0x49 } }
+
+enum {
+ TEE_CHIMP_FASTBOOT = 0,
+ TEE_CHIMP_HEALTH_STATUS,
+ TEE_CHIMP_HANDSHAKE_STATUS,
+} tee_chmip_cmd;
+
+struct bcm_chimp_data {
+ struct udevice *tee;
+ u32 session;
+} chimp_data;
+
+static int get_open_session(struct bcm_chimp_data *b_data)
+{
+ struct udevice *tee = NULL;
+
+ while (!b_data->tee) {
+ const struct tee_optee_ta_uuid uuid = CHMIP_BOOT_UUID;
+ struct tee_open_session_arg arg;
+ int rc;
+
+ tee = tee_find_device(tee, NULL, NULL, NULL);
+ if (!tee)
+ return -ENODEV;
+
+ memset(&arg, 0, sizeof(arg));
+ tee_optee_ta_uuid_to_octets(arg.uuid, &uuid);
+ rc = tee_open_session(tee, &arg, 0, NULL);
+ if (!rc) {
+ b_data->tee = tee;
+ b_data->session = arg.session;
+ }
+ }
+
+ return 0;
+}
+
+int chimp_handshake_status_optee(u32 timeout, u32 *hs)
+{
+ struct tee_invoke_arg arg;
+ struct tee_param param[1];
+ int ret;
+
+ if (get_open_session(&chimp_data))
+ return BCM_CHIMP_FAILURE;
+
+ memset(&arg, 0, sizeof(arg));
+ arg.func = TEE_CHIMP_HANDSHAKE_STATUS;
+ arg.session = chimp_data.session;
+
+ param[0].attr = TEE_PARAM_ATTR_TYPE_VALUE_INOUT;
+ param[0].u.value.a = timeout;
+
+ if (tee_invoke_func(chimp_data.tee, &arg,
+ ARRAY_SIZE(param), param)) {
+ printf("Handshake status command failed\n");
+ ret = BCM_CHIMP_FAILURE;
+ goto out;
+ }
+ switch (arg.ret) {
+ case TEE_SUCCESS:
+ *hs = param[0].u.value.a;
+ ret = BCM_CHIMP_SUCCESS;
+ break;
+ default:
+ ret = BCM_CHIMP_FAILURE;
+ break;
+ }
+out:
+ tee_close_session(chimp_data.tee, chimp_data.session);
+ chimp_data.tee = NULL;
+
+ return ret;
+}
+
+int chimp_health_status_optee(u32 *health)
+{
+ struct tee_invoke_arg arg;
+ struct tee_param param[1];
+ int ret;
+
+ if (get_open_session(&chimp_data))
+ return BCM_CHIMP_FAILURE;
+
+ memset(&arg, 0, sizeof(arg));
+ arg.func = TEE_CHIMP_HEALTH_STATUS;
+ arg.session = chimp_data.session;
+
+ param[0].attr = TEE_PARAM_ATTR_TYPE_VALUE_OUTPUT;
+
+ if (tee_invoke_func(chimp_data.tee, &arg,
+ ARRAY_SIZE(param), param)) {
+ printf("Helath status command failed\n");
+ ret = BCM_CHIMP_FAILURE;
+ goto out;
+ }
+ switch (arg.ret) {
+ case TEE_SUCCESS:
+ *health = param[0].u.value.a;
+ ret = BCM_CHIMP_SUCCESS;
+ break;
+ default:
+ ret = BCM_CHIMP_FAILURE;
+ break;
+ }
+out:
+ tee_close_session(chimp_data.tee, chimp_data.session);
+ chimp_data.tee = NULL;
+
+ return ret;
+}
+
+int chimp_fastboot_optee(void)
+{
+ struct tee_invoke_arg arg;
+ int ret;
+
+ if (get_open_session(&chimp_data))
+ return BCM_CHIMP_FAILURE;
+
+ memset(&arg, 0, sizeof(arg));
+ arg.func = TEE_CHIMP_FASTBOOT;
+ arg.session = chimp_data.session;
+
+ if (tee_invoke_func(chimp_data.tee, &arg, 0, NULL)) {
+ printf("Chimp boot_fail\n");
+ ret = BCM_CHIMP_FAILURE;
+ goto out;
+ }
+ switch (arg.ret) {
+ case TEE_SUCCESS:
+ ret = BCM_CHIMP_SUCCESS;
+ break;
+ default:
+ ret = BCM_CHIMP_FAILURE;
+ break;
+ }
+out:
+ tee_close_session(chimp_data.tee, chimp_data.session);
+ chimp_data.tee = NULL;
+
+ return ret;
+}
new file mode 100644
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright 2020 Broadcom.
+ *
+ */
+
+#ifndef __CHIMP_H__
+#define __CHIMP_H__
+
+#include <common.h>
+#include <linux/compiler.h>
+
+#define BCM_CHIMP_SUCCESS 0
+#define BCM_CHIMP_FAILURE (!BCM_CHIMP_SUCCESS)
+
+#ifdef CONFIG_CHIMP_OPTEE
+int chimp_fastboot_optee(void);
+int chimp_health_status_optee(u32 *status);
+int chimp_handshake_status_optee(u32 timeout, u32 *hstatus);
+#else
+static inline int chimp_handshake_status_optee(u32 timeout, u32 *status)
+{
+ printf("ChiMP handshake status fail (OPTEE not enabled)\n");
+ return BCM_CHIMP_FAILURE;
+}
+
+static inline int chimp_health_status_optee(u32 *status)
+{
+ printf("ChiMP health status fail (OPTEE not enabled)\n");
+ return BCM_CHIMP_FAILURE;
+}
+
+static inline int chimp_fastboot_optee(void)
+{
+ printf("ChiMP secure boot fail (OPTEE not enabled)\n");
+ return BCM_CHIMP_FAILURE;
+}
+#endif
+
+#endif