xref: /rk3399_ARM-atf/plat/arm/common/arm_err.c (revision 46b69e3de1b7817f4d8ed46fe1975f4bf630f0ec)
17b56928aSSoby Mathew /*
27b56928aSSoby Mathew  * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
37b56928aSSoby Mathew  *
47b56928aSSoby Mathew  * SPDX-License-Identifier: BSD-3-Clause
57b56928aSSoby Mathew  */
67b56928aSSoby Mathew 
77b56928aSSoby Mathew #include <arch_helpers.h>
87b56928aSSoby Mathew #include <console.h>
97b56928aSSoby Mathew #include <debug.h>
107b56928aSSoby Mathew #include <errno.h>
117b56928aSSoby Mathew #include <norflash.h>
127b56928aSSoby Mathew #include <platform.h>
13*46b69e3dSSughosh Ganu #include <platform_def.h>
147b56928aSSoby Mathew #include <stdint.h>
157b56928aSSoby Mathew 
167b56928aSSoby Mathew /*
177b56928aSSoby Mathew  * ARM common implementation for error handler
187b56928aSSoby Mathew  */
197b56928aSSoby Mathew void plat_error_handler(int err)
207b56928aSSoby Mathew {
217b56928aSSoby Mathew 	int ret;
227b56928aSSoby Mathew 
237b56928aSSoby Mathew 	switch (err) {
247b56928aSSoby Mathew 	case -ENOENT:
257b56928aSSoby Mathew 	case -EAUTH:
267b56928aSSoby Mathew 		/* Image load or authentication error. Erase the ToC */
277b56928aSSoby Mathew 		INFO("Erasing FIP ToC from flash...\n");
287b56928aSSoby Mathew 		nor_unlock(PLAT_ARM_FIP_BASE);
297b56928aSSoby Mathew 		ret = nor_word_program(PLAT_ARM_FIP_BASE, 0);
307b56928aSSoby Mathew 		if (ret != 0) {
317b56928aSSoby Mathew 			ERROR("Cannot erase ToC\n");
327b56928aSSoby Mathew 		} else {
337b56928aSSoby Mathew 			INFO("Done\n");
347b56928aSSoby Mathew 		}
357b56928aSSoby Mathew 		break;
367b56928aSSoby Mathew 	default:
377b56928aSSoby Mathew 		/* Unexpected error */
387b56928aSSoby Mathew 		break;
397b56928aSSoby Mathew 	}
407b56928aSSoby Mathew 
417b56928aSSoby Mathew 	(void)console_flush();
427b56928aSSoby Mathew 
437b56928aSSoby Mathew 	/* Loop until the watchdog resets the system */
447b56928aSSoby Mathew 	for (;;)
457b56928aSSoby Mathew 		wfi();
467b56928aSSoby Mathew }
47