xref: /rk3399_ARM-atf/plat/arm/board/juno/juno_bl1_setup.c (revision 1f37b9442fa47af519eabd2f5b67fdaeb1ddfa64)
1436223deSYatharth Kochar /*
2436223deSYatharth Kochar  * Copyright (c) 2015, 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>
35436223deSYatharth Kochar #include <tbbr_img_def.h>
36436223deSYatharth Kochar #include <v2m_def.h>
37436223deSYatharth Kochar 
38436223deSYatharth Kochar #define RESET_REASON_WDOG_RESET		(0x2)
39436223deSYatharth Kochar 
40436223deSYatharth Kochar /*******************************************************************************
41436223deSYatharth Kochar  * The following function checks if Firmware update is needed,
42436223deSYatharth Kochar  * by checking if TOC in FIP image is valid or watchdog reset happened.
43436223deSYatharth Kochar  ******************************************************************************/
44436223deSYatharth Kochar unsigned int bl1_plat_get_next_image_id(void)
45436223deSYatharth Kochar {
46436223deSYatharth Kochar 	unsigned int *reset_flags_ptr = (unsigned int *)SSC_GPRETN;
47436223deSYatharth Kochar 	unsigned int *nv_flags_ptr = (unsigned int *)
48436223deSYatharth Kochar 			(V2M_SYSREGS_BASE + V2M_SYS_NVFLAGS);
49436223deSYatharth Kochar 	/*
50436223deSYatharth Kochar 	 * Check if TOC is invalid or watchdog reset happened.
51436223deSYatharth Kochar 	 */
52436223deSYatharth Kochar 	if ((arm_io_is_toc_valid() != 1) ||
53436223deSYatharth Kochar 		((*reset_flags_ptr & RESET_REASON_WDOG_RESET) &&
54436223deSYatharth Kochar 		((*nv_flags_ptr == -EAUTH) || (*nv_flags_ptr == -ENOENT))))
55436223deSYatharth Kochar 		return NS_BL1U_IMAGE_ID;
56436223deSYatharth Kochar 
57436223deSYatharth Kochar 	return BL2_IMAGE_ID;
58436223deSYatharth Kochar }
59436223deSYatharth Kochar 
60436223deSYatharth Kochar /*******************************************************************************
61436223deSYatharth Kochar  * On JUNO update the arg2 with address of SCP_BL2U image info.
62436223deSYatharth Kochar  ******************************************************************************/
63436223deSYatharth Kochar void bl1_plat_set_ep_info(unsigned int image_id,
64436223deSYatharth Kochar 		entry_point_info_t *ep_info)
65436223deSYatharth Kochar {
66436223deSYatharth Kochar 	if (image_id == BL2U_IMAGE_ID) {
67436223deSYatharth Kochar 		image_desc_t *image_desc = bl1_plat_get_image_desc(SCP_BL2U_IMAGE_ID);
68436223deSYatharth Kochar 		ep_info->args.arg2 = (unsigned long)&image_desc->image_info;
69436223deSYatharth Kochar 	}
70436223deSYatharth Kochar }
71436223deSYatharth Kochar 
72436223deSYatharth Kochar /*******************************************************************************
73436223deSYatharth Kochar  * On Juno clear SYS_NVFLAGS and wait for watchdog reset.
74436223deSYatharth Kochar  ******************************************************************************/
75*1f37b944SDan Handley __dead2 void bl1_plat_fwu_done(void *client_cookie, void *reserved)
76436223deSYatharth Kochar {
77436223deSYatharth Kochar 	unsigned int *nv_flags_clr = (unsigned int *)
78436223deSYatharth Kochar 			(V2M_SYSREGS_BASE + V2M_SYS_NVFLAGSCLR);
79436223deSYatharth Kochar 	unsigned int *nv_flags_ptr = (unsigned int *)
80436223deSYatharth Kochar 			(V2M_SYSREGS_BASE + V2M_SYS_NVFLAGS);
81436223deSYatharth Kochar 
82436223deSYatharth Kochar 	/* Clear the NV flags register. */
83436223deSYatharth Kochar 	*nv_flags_clr = *nv_flags_ptr;
84436223deSYatharth Kochar 
85436223deSYatharth Kochar 	while (1)
86436223deSYatharth Kochar 		wfi();
87436223deSYatharth Kochar }
88