blob: 2bc948d6825772b925f1f9ab22f9813f4693986b [file] [log] [blame]
Yatharth Kochar736a3bf2015-10-11 14:14:55 +01001/*
Tamas Banb87db072023-05-08 13:48:51 +02002 * Copyright (c) 2015-2024, Arm Limited and Contributors. All rights reserved.
Yatharth Kochar736a3bf2015-10-11 14:14:55 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Yatharth Kochar736a3bf2015-10-11 14:14:55 +01005 */
6
Yatharth Kochar736a3bf2015-10-11 14:14:55 +01007#include <errno.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00008
9#include <common/bl_common.h>
10#include <common/debug.h>
11#include <common/tbbr/tbbr_img_def.h>
Antonio Nino Diaz09d58762019-01-23 19:06:55 +000012#include <drivers/arm/css/sds.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000013#include <drivers/arm/sp805.h>
Antonio Nino Diazbd7b7402019-01-25 14:30:04 +000014#include <plat/arm/common/plat_arm.h>
Aditya Angadi20b48412019-04-16 11:29:14 +053015#include <plat/arm/common/arm_def.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000016#include <plat/common/platform.h>
Antonio Nino Diaza320ecd2019-01-15 14:19:50 +000017#include <platform_def.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000018
Yatharth Kocharede39cb2016-11-14 12:01:04 +000019void juno_reset_to_aarch32_state(void);
20
Sathees Balya22576072018-09-03 17:41:13 +010021static int is_watchdog_reset(void)
22{
23#if !CSS_USE_SCMI_SDS_DRIVER
24 #define RESET_REASON_WDOG_RESET (0x2)
25 const uint32_t *reset_flags_ptr = (const uint32_t *)SSC_GPRETN;
26
27 if ((*reset_flags_ptr & RESET_REASON_WDOG_RESET) != 0)
28 return 1;
29
30 return 0;
31#else
32 int ret;
33 uint32_t scp_reset_synd_flags;
34
Tamas Banb87db072023-05-08 13:48:51 +020035 ret = sds_init(SDS_SCP_AP_REGION_ID);
Sathees Balya22576072018-09-03 17:41:13 +010036 if (ret != SDS_OK) {
37 ERROR("SCP SDS initialization failed\n");
38 panic();
39 }
40
Tamas Banb87db072023-05-08 13:48:51 +020041 ret = sds_struct_read(SDS_SCP_AP_REGION_ID,
42 SDS_RESET_SYNDROME_STRUCT_ID,
Sathees Balya22576072018-09-03 17:41:13 +010043 SDS_RESET_SYNDROME_OFFSET,
44 &scp_reset_synd_flags,
45 SDS_RESET_SYNDROME_SIZE,
46 SDS_ACCESS_MODE_NON_CACHED);
47 if (ret != SDS_OK) {
48 ERROR("Getting reset reason from SDS failed\n");
49 panic();
50 }
51
52 /* Check if the WATCHDOG_RESET_BIT is set in the reset syndrome */
53 if (scp_reset_synd_flags & SDS_RESET_SYNDROME_AP_WD_RESET_BIT)
54 return 1;
55
56 return 0;
57#endif
58}
59
60/*******************************************************************************
61 * The following function checks if Firmware update is needed,
62 * by checking if TOC in FIP image is valid or watchdog reset happened.
63 ******************************************************************************/
Louis Mayencourt70d7c092020-01-29 11:42:31 +000064bool plat_arm_bl1_fwu_needed(void)
Sathees Balya22576072018-09-03 17:41:13 +010065{
Manish V Badarkhe79f4ee02021-06-16 19:59:41 +010066 int32_t nv_flags = (int32_t)mmio_read_32(V2M_SYS_NVFLAGS_ADDR);
Sathees Balya22576072018-09-03 17:41:13 +010067
68 /* Check if TOC is invalid or watchdog reset happened. */
Manish V Badarkhe79f4ee02021-06-16 19:59:41 +010069 return (!arm_io_is_toc_valid() || (((nv_flags == -EAUTH) ||
70 (nv_flags == -ENOENT)) && is_watchdog_reset()));
Sathees Balya22576072018-09-03 17:41:13 +010071}
72
Yatharth Kochar736a3bf2015-10-11 14:14:55 +010073/*******************************************************************************
74 * On JUNO update the arg2 with address of SCP_BL2U image info.
75 ******************************************************************************/
76void bl1_plat_set_ep_info(unsigned int image_id,
77 entry_point_info_t *ep_info)
78{
79 if (image_id == BL2U_IMAGE_ID) {
80 image_desc_t *image_desc = bl1_plat_get_image_desc(SCP_BL2U_IMAGE_ID);
81 ep_info->args.arg2 = (unsigned long)&image_desc->image_info;
82 }
83}
84
85/*******************************************************************************
86 * On Juno clear SYS_NVFLAGS and wait for watchdog reset.
87 ******************************************************************************/
Dan Handley89f8f332015-12-15 14:28:24 +000088__dead2 void bl1_plat_fwu_done(void *client_cookie, void *reserved)
Yatharth Kochar736a3bf2015-10-11 14:14:55 +010089{
Manish V Badarkhe79f4ee02021-06-16 19:59:41 +010090 uint32_t nv_flags = mmio_read_32(V2M_SYS_NVFLAGS_ADDR);
Yatharth Kochar736a3bf2015-10-11 14:14:55 +010091
92 /* Clear the NV flags register. */
Manish V Badarkhe79f4ee02021-06-16 19:59:41 +010093 mmio_write_32((V2M_SYSREGS_BASE + V2M_SYS_NVFLAGSCLR),
94 nv_flags);
Yatharth Kochar736a3bf2015-10-11 14:14:55 +010095
Ambroise Vincentfa42c9e2019-07-04 14:58:45 +010096 /* Setup the watchdog to reset the system as soon as possible */
97 sp805_refresh(ARM_SP805_TWDG_BASE, 1U);
98
Jimmy Brisson471550a2020-08-06 10:50:15 -050099 while (true)
Yatharth Kochar736a3bf2015-10-11 14:14:55 +0100100 wfi();
101}
Yatharth Kocharede39cb2016-11-14 12:01:04 +0000102
103#if JUNO_AARCH32_EL3_RUNTIME
104void bl1_plat_prepare_exit(entry_point_info_t *ep_info)
105{
106#if !ARM_DISABLE_TRUSTED_WDOG
107 /* Disable watchdog before leaving BL1 */
108 sp805_stop(ARM_SP805_TWDG_BASE);
109#endif
110
111 juno_reset_to_aarch32_state();
112}
113#endif /* JUNO_AARCH32_EL3_RUNTIME */
Aditya Angadi20b48412019-04-16 11:29:14 +0530114
115void plat_arm_secure_wdt_start(void)
116{
117 sp805_start(ARM_SP805_TWDG_BASE, ARM_TWDG_LOAD_VAL);
118}
119
120void plat_arm_secure_wdt_stop(void)
121{
122 sp805_stop(ARM_SP805_TWDG_BASE);
123}