1436223deSYatharth Kochar /* 207570d59SYatharth Kochar * Copyright (c) 2015-2016, ARM Limited and Contributors. All rights reserved. 3436223deSYatharth Kochar * 482cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause 5436223deSYatharth Kochar */ 6436223deSYatharth Kochar 7436223deSYatharth Kochar #include <bl_common.h> 8436223deSYatharth Kochar #include <errno.h> 9436223deSYatharth Kochar #include <plat_arm.h> 10*4adb10c1SIsla Mitchell #include <platform.h> 1107570d59SYatharth Kochar #include <sp805.h> 12436223deSYatharth Kochar #include <tbbr_img_def.h> 13436223deSYatharth Kochar #include <v2m_def.h> 14436223deSYatharth Kochar 15436223deSYatharth Kochar #define RESET_REASON_WDOG_RESET (0x2) 16436223deSYatharth Kochar 1707570d59SYatharth Kochar void juno_reset_to_aarch32_state(void); 1807570d59SYatharth Kochar 1907570d59SYatharth Kochar 20436223deSYatharth Kochar /******************************************************************************* 21436223deSYatharth Kochar * The following function checks if Firmware update is needed, 22436223deSYatharth Kochar * by checking if TOC in FIP image is valid or watchdog reset happened. 23436223deSYatharth Kochar ******************************************************************************/ 24436223deSYatharth Kochar unsigned int bl1_plat_get_next_image_id(void) 25436223deSYatharth Kochar { 26436223deSYatharth Kochar unsigned int *reset_flags_ptr = (unsigned int *)SSC_GPRETN; 27436223deSYatharth Kochar unsigned int *nv_flags_ptr = (unsigned int *) 28436223deSYatharth Kochar (V2M_SYSREGS_BASE + V2M_SYS_NVFLAGS); 29436223deSYatharth Kochar /* 30436223deSYatharth Kochar * Check if TOC is invalid or watchdog reset happened. 31436223deSYatharth Kochar */ 32436223deSYatharth Kochar if ((arm_io_is_toc_valid() != 1) || 33436223deSYatharth Kochar ((*reset_flags_ptr & RESET_REASON_WDOG_RESET) && 34436223deSYatharth Kochar ((*nv_flags_ptr == -EAUTH) || (*nv_flags_ptr == -ENOENT)))) 35436223deSYatharth Kochar return NS_BL1U_IMAGE_ID; 36436223deSYatharth Kochar 37436223deSYatharth Kochar return BL2_IMAGE_ID; 38436223deSYatharth Kochar } 39436223deSYatharth Kochar 40436223deSYatharth Kochar /******************************************************************************* 41436223deSYatharth Kochar * On JUNO update the arg2 with address of SCP_BL2U image info. 42436223deSYatharth Kochar ******************************************************************************/ 43436223deSYatharth Kochar void bl1_plat_set_ep_info(unsigned int image_id, 44436223deSYatharth Kochar entry_point_info_t *ep_info) 45436223deSYatharth Kochar { 46436223deSYatharth Kochar if (image_id == BL2U_IMAGE_ID) { 47436223deSYatharth Kochar image_desc_t *image_desc = bl1_plat_get_image_desc(SCP_BL2U_IMAGE_ID); 48436223deSYatharth Kochar ep_info->args.arg2 = (unsigned long)&image_desc->image_info; 49436223deSYatharth Kochar } 50436223deSYatharth Kochar } 51436223deSYatharth Kochar 52436223deSYatharth Kochar /******************************************************************************* 53436223deSYatharth Kochar * On Juno clear SYS_NVFLAGS and wait for watchdog reset. 54436223deSYatharth Kochar ******************************************************************************/ 551f37b944SDan Handley __dead2 void bl1_plat_fwu_done(void *client_cookie, void *reserved) 56436223deSYatharth Kochar { 57436223deSYatharth Kochar unsigned int *nv_flags_clr = (unsigned int *) 58436223deSYatharth Kochar (V2M_SYSREGS_BASE + V2M_SYS_NVFLAGSCLR); 59436223deSYatharth Kochar unsigned int *nv_flags_ptr = (unsigned int *) 60436223deSYatharth Kochar (V2M_SYSREGS_BASE + V2M_SYS_NVFLAGS); 61436223deSYatharth Kochar 62436223deSYatharth Kochar /* Clear the NV flags register. */ 63436223deSYatharth Kochar *nv_flags_clr = *nv_flags_ptr; 64436223deSYatharth Kochar 65436223deSYatharth Kochar while (1) 66436223deSYatharth Kochar wfi(); 67436223deSYatharth Kochar } 6807570d59SYatharth Kochar 6907570d59SYatharth Kochar #if JUNO_AARCH32_EL3_RUNTIME 7007570d59SYatharth Kochar void bl1_plat_prepare_exit(entry_point_info_t *ep_info) 7107570d59SYatharth Kochar { 7207570d59SYatharth Kochar #if !ARM_DISABLE_TRUSTED_WDOG 7307570d59SYatharth Kochar /* Disable watchdog before leaving BL1 */ 7407570d59SYatharth Kochar sp805_stop(ARM_SP805_TWDG_BASE); 7507570d59SYatharth Kochar #endif 7607570d59SYatharth Kochar 7707570d59SYatharth Kochar juno_reset_to_aarch32_state(); 7807570d59SYatharth Kochar } 7907570d59SYatharth Kochar #endif /* JUNO_AARCH32_EL3_RUNTIME */ 80