aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Narkevitch <ainh@cypress.com>2019-10-10 12:32:12 -0700
committerDavid Hu <david.hu@arm.com>2019-10-17 03:57:38 +0000
commite0e4d3b7791777ce3e504712d26c8a6206ea7adb (patch)
tree107edd8b8656c3d2e0327b40a82d36ece7b2a7fc
parent36405e3fb8eac747d1fe20b534774f47ef9dced4 (diff)
downloadtrusted-firmware-m-e0e4d3b7791777ce3e504712d26c8a6206ea7adb.tar.gz
plat: Debug Access Port (DAP) driver (psoc64)
As specified by the default security policy, CM4 core debug port is disabled during the boot, but allowed to be enabled later after CM4 is up. Add an API to control DAP and enable CM4 debugging. Signed-off-by: Andrei Narkevitch <ainh@cypress.com> Change-Id: Ica84ab545f04191c03e49dcc31eba61346737415
-rw-r--r--platform/ext/psoc64.cmake1
-rw-r--r--platform/ext/target/psoc64/driver_dap.c77
-rw-r--r--platform/ext/target/psoc64/driver_dap.h47
-rw-r--r--platform/ext/target/psoc64/spm_hal.c11
4 files changed, 136 insertions, 0 deletions
diff --git a/platform/ext/psoc64.cmake b/platform/ext/psoc64.cmake
index 7491e00332..9f438408f3 100644
--- a/platform/ext/psoc64.cmake
+++ b/platform/ext/psoc64.cmake
@@ -227,6 +227,7 @@ if (NOT DEFINED BUILD_CMSIS_DRIVERS)
elseif(BUILD_CMSIS_DRIVERS)
list(APPEND ALL_SRC_C "${PLATFORM_DIR}/target/psoc64/driver_smpu.c")
list(APPEND ALL_SRC_C "${PLATFORM_DIR}/target/psoc64/driver_ppu.c")
+ list(APPEND ALL_SRC_C "${PLATFORM_DIR}/target/psoc64/driver_dap.c")
list(APPEND ALL_SRC_C "${PLATFORM_DIR}/target/psoc64/CMSIS_Driver/Driver_USART.c")
embedded_include_directories(PATH "${PLATFORM_DIR}/target/psoc64/CMSIS_Driver" ABSOLUTE)
embedded_include_directories(PATH "${PLATFORM_DIR}/driver" ABSOLUTE)
diff --git a/platform/ext/target/psoc64/driver_dap.c b/platform/ext/target/psoc64/driver_dap.c
new file mode 100644
index 0000000000..4a85356ff1
--- /dev/null
+++ b/platform/ext/target/psoc64/driver_dap.c
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2019, Cypress Semiconductor Corporation. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <stdio.h>
+
+#include "driver_dap.h"
+
+#include "cycfg.h"
+#include "cy_device.h"
+#include "cy_device_headers.h"
+#include "cy_ipc_drv.h"
+#include "cy_prot.h"
+#include "cy_sysint.h"
+#include "driver_dap.h"
+#include "pc_config.h"
+
+
+int cy_access_port_control(cy_ap_name_t ap, cy_ap_control_t en)
+{
+ int rc = -1;
+ volatile uint32_t syscallCmd = 0;
+ uint32_t timeout = 0;
+
+ syscallCmd |= DAPCONTROL_SYSCALL_OPCODE;
+ syscallCmd |= (uint8_t)en << 16;
+ syscallCmd |= (uint8_t)ap << 8;
+ syscallCmd |= 1;
+
+ IPC->STRUCT[CY_IPC_CHAN_SYSCALL].DATA = syscallCmd;
+
+ while(((IPC->STRUCT[CY_IPC_CHAN_SYSCALL].ACQUIRE &
+ IPC_STRUCT_ACQUIRE_SUCCESS_Msk) == 0) &&
+ (timeout < SYSCALL_TIMEOUT))
+ {
+ ++timeout;
+ }
+
+ if(timeout < SYSCALL_TIMEOUT)
+ {
+ timeout = 0;
+
+ IPC->STRUCT[CY_IPC_CHAN_SYSCALL].NOTIFY = 1;
+
+ while(((IPC->STRUCT[CY_IPC_CHAN_SYSCALL].LOCK_STATUS &
+ IPC_STRUCT_ACQUIRE_SUCCESS_Msk) != 0) &&
+ (timeout < SYSCALL_TIMEOUT))
+ {
+ ++timeout;
+ }
+
+ if(timeout < SYSCALL_TIMEOUT)
+ {
+ syscallCmd = IPC->STRUCT[CY_IPC_CHAN_SYSCALL].DATA;
+ if(CY_FB_SYSCALL_SUCCESS != syscallCmd)
+ {
+ rc = syscallCmd;
+ }
+ else
+ {
+ rc = 0;
+ }
+ }
+ }
+ return rc;
+} \ No newline at end of file
diff --git a/platform/ext/target/psoc64/driver_dap.h b/platform/ext/target/psoc64/driver_dap.h
new file mode 100644
index 0000000000..72bec39e96
--- /dev/null
+++ b/platform/ext/target/psoc64/driver_dap.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2019, Cypress Semiconductor Corporation. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __DRIVER_DAP_H__
+#define __DRIVER_DAP_H__
+
+/* DAPControl SysCall opcode */
+#define DAPCONTROL_SYSCALL_OPCODE (0x3AUL << 24UL)
+
+/* PSA crypto SysCall return codes */
+#define CY_FB_SYSCALL_SUCCESS (0xA0000000UL)
+
+/* SysCall timeout value */
+#define SYSCALL_TIMEOUT (15000UL)
+
+/* DAPControl SysCall parameter: access port state */
+typedef enum
+{
+ CY_AP_DIS = 0,
+ CY_AP_EN = 1
+}cy_ap_control_t;
+
+/* DAPControl SysCall parameter: access port name */
+typedef enum
+{
+ CY_CM0_AP = 0,
+ CY_CM4_AP = 1,
+ CY_SYS_AP = 2
+}cy_ap_name_t;
+
+/* API functions */
+int cy_access_port_control(cy_ap_name_t ap, cy_ap_control_t en);
+
+#endif /* __DRIVER_DAP_H__ */
diff --git a/platform/ext/target/psoc64/spm_hal.c b/platform/ext/target/psoc64/spm_hal.c
index a2968bdcaa..b5046212e6 100644
--- a/platform/ext/target/psoc64/spm_hal.c
+++ b/platform/ext/target/psoc64/spm_hal.c
@@ -27,6 +27,7 @@
#include "cy_prot.h"
#include "cy_sysint.h"
#include "pc_config.h"
+#include "driver_dap.h"
/* Get address of memory regions to configure MPU */
extern const struct memory_region_limits memory_regions;
@@ -219,6 +220,16 @@ void tfm_spm_hal_boot_ns_cpu(uintptr_t start_addr)
{
printf("Starting Cortex-M4 at 0x%x\r\n", start_addr);
Cy_SysEnableCM4(start_addr);
+
+ if (cy_access_port_control(CY_CM4_AP, CY_AP_EN) == 0) {
+ /* The delay is required after Access port was enabled for
+ * debugger/programmer to connect and set TEST BIT */
+ Cy_SysLib_Delay(100);
+ }
+ else {
+ printf("Could not enable CY_CM4_AP DAP control\n");
+ }
+
}
void tfm_spm_hal_wait_for_ns_cpu_ready(void)