xref: /rk3399_ARM-atf/plat/arm/board/juno/juno_bl1_setup.c (revision 07570d592ea5b8a0ea22f23d2d502782b9d6c1c5)
1436223deSYatharth Kochar /*
2*07570d59SYatharth Kochar  * Copyright (c) 2015-2016, ARM Limited and Contributors. All rights reserved.
3436223deSYatharth Kochar  *
4436223deSYatharth Kochar  * Redistribution and use in source and binary forms, with or without
5436223deSYatharth Kochar  * modification, are permitted provided that the following conditions are met:
6436223deSYatharth Kochar  *
7436223deSYatharth Kochar  * Redistributions of source code must retain the above copyright notice, this
8436223deSYatharth Kochar  * list of conditions and the following disclaimer.
9436223deSYatharth Kochar  *
10436223deSYatharth Kochar  * Redistributions in binary form must reproduce the above copyright notice,
11436223deSYatharth Kochar  * this list of conditions and the following disclaimer in the documentation
12436223deSYatharth Kochar  * and/or other materials provided with the distribution.
13436223deSYatharth Kochar  *
14436223deSYatharth Kochar  * Neither the name of ARM nor the names of its contributors may be used
15436223deSYatharth Kochar  * to endorse or promote products derived from this software without specific
16436223deSYatharth Kochar  * prior written permission.
17436223deSYatharth Kochar  *
18436223deSYatharth Kochar  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19436223deSYatharth Kochar  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20436223deSYatharth Kochar  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21436223deSYatharth Kochar  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22436223deSYatharth Kochar  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23436223deSYatharth Kochar  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24436223deSYatharth Kochar  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25436223deSYatharth Kochar  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26436223deSYatharth Kochar  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27436223deSYatharth Kochar  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28436223deSYatharth Kochar  * POSSIBILITY OF SUCH DAMAGE.
29436223deSYatharth Kochar  */
30436223deSYatharth Kochar 
31436223deSYatharth Kochar #include <bl_common.h>
32436223deSYatharth Kochar #include <errno.h>
33436223deSYatharth Kochar #include <platform.h>
34436223deSYatharth Kochar #include <plat_arm.h>
35*07570d59SYatharth Kochar #include <sp805.h>
36436223deSYatharth Kochar #include <tbbr_img_def.h>
37436223deSYatharth Kochar #include <v2m_def.h>
38436223deSYatharth Kochar 
39436223deSYatharth Kochar #define RESET_REASON_WDOG_RESET		(0x2)
40436223deSYatharth Kochar 
41*07570d59SYatharth Kochar void juno_reset_to_aarch32_state(void);
42*07570d59SYatharth Kochar 
43*07570d59SYatharth Kochar 
44436223deSYatharth Kochar /*******************************************************************************
45436223deSYatharth Kochar  * The following function checks if Firmware update is needed,
46436223deSYatharth Kochar  * by checking if TOC in FIP image is valid or watchdog reset happened.
47436223deSYatharth Kochar  ******************************************************************************/
48436223deSYatharth Kochar unsigned int bl1_plat_get_next_image_id(void)
49436223deSYatharth Kochar {
50436223deSYatharth Kochar 	unsigned int *reset_flags_ptr = (unsigned int *)SSC_GPRETN;
51436223deSYatharth Kochar 	unsigned int *nv_flags_ptr = (unsigned int *)
52436223deSYatharth Kochar 			(V2M_SYSREGS_BASE + V2M_SYS_NVFLAGS);
53436223deSYatharth Kochar 	/*
54436223deSYatharth Kochar 	 * Check if TOC is invalid or watchdog reset happened.
55436223deSYatharth Kochar 	 */
56436223deSYatharth Kochar 	if ((arm_io_is_toc_valid() != 1) ||
57436223deSYatharth Kochar 		((*reset_flags_ptr & RESET_REASON_WDOG_RESET) &&
58436223deSYatharth Kochar 		((*nv_flags_ptr == -EAUTH) || (*nv_flags_ptr == -ENOENT))))
59436223deSYatharth Kochar 		return NS_BL1U_IMAGE_ID;
60436223deSYatharth Kochar 
61436223deSYatharth Kochar 	return BL2_IMAGE_ID;
62436223deSYatharth Kochar }
63436223deSYatharth Kochar 
64436223deSYatharth Kochar /*******************************************************************************
65436223deSYatharth Kochar  * On JUNO update the arg2 with address of SCP_BL2U image info.
66436223deSYatharth Kochar  ******************************************************************************/
67436223deSYatharth Kochar void bl1_plat_set_ep_info(unsigned int image_id,
68436223deSYatharth Kochar 		entry_point_info_t *ep_info)
69436223deSYatharth Kochar {
70436223deSYatharth Kochar 	if (image_id == BL2U_IMAGE_ID) {
71436223deSYatharth Kochar 		image_desc_t *image_desc = bl1_plat_get_image_desc(SCP_BL2U_IMAGE_ID);
72436223deSYatharth Kochar 		ep_info->args.arg2 = (unsigned long)&image_desc->image_info;
73436223deSYatharth Kochar 	}
74436223deSYatharth Kochar }
75436223deSYatharth Kochar 
76436223deSYatharth Kochar /*******************************************************************************
77436223deSYatharth Kochar  * On Juno clear SYS_NVFLAGS and wait for watchdog reset.
78436223deSYatharth Kochar  ******************************************************************************/
791f37b944SDan Handley __dead2 void bl1_plat_fwu_done(void *client_cookie, void *reserved)
80436223deSYatharth Kochar {
81436223deSYatharth Kochar 	unsigned int *nv_flags_clr = (unsigned int *)
82436223deSYatharth Kochar 			(V2M_SYSREGS_BASE + V2M_SYS_NVFLAGSCLR);
83436223deSYatharth Kochar 	unsigned int *nv_flags_ptr = (unsigned int *)
84436223deSYatharth Kochar 			(V2M_SYSREGS_BASE + V2M_SYS_NVFLAGS);
85436223deSYatharth Kochar 
86436223deSYatharth Kochar 	/* Clear the NV flags register. */
87436223deSYatharth Kochar 	*nv_flags_clr = *nv_flags_ptr;
88436223deSYatharth Kochar 
89436223deSYatharth Kochar 	while (1)
90436223deSYatharth Kochar 		wfi();
91436223deSYatharth Kochar }
92*07570d59SYatharth Kochar 
93*07570d59SYatharth Kochar #if JUNO_AARCH32_EL3_RUNTIME
94*07570d59SYatharth Kochar void bl1_plat_prepare_exit(entry_point_info_t *ep_info)
95*07570d59SYatharth Kochar {
96*07570d59SYatharth Kochar #if !ARM_DISABLE_TRUSTED_WDOG
97*07570d59SYatharth Kochar 	/* Disable watchdog before leaving BL1 */
98*07570d59SYatharth Kochar 	sp805_stop(ARM_SP805_TWDG_BASE);
99*07570d59SYatharth Kochar #endif
100*07570d59SYatharth Kochar 
101*07570d59SYatharth Kochar 	juno_reset_to_aarch32_state();
102*07570d59SYatharth Kochar }
103*07570d59SYatharth Kochar #endif /* JUNO_AARCH32_EL3_RUNTIME */
104