xref: /rk3399_ARM-atf/plat/arm/common/arm_err.c (revision bd9344f670a46125cdd8949ded75be124f34d587)
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 <errno.h>
87b56928aSSoby Mathew #include <stdint.h>
909d40e0eSAntonio Nino Diaz 
1009d40e0eSAntonio Nino Diaz #include <platform_def.h>
1109d40e0eSAntonio Nino Diaz 
1209d40e0eSAntonio Nino Diaz #include <arch_helpers.h>
1309d40e0eSAntonio Nino Diaz #include <common/debug.h>
1409d40e0eSAntonio Nino Diaz #include <drivers/cfi/v2m_flash.h>
1509d40e0eSAntonio Nino Diaz #include <drivers/console.h>
16*bd9344f6SAntonio Nino Diaz #include <plat/arm/common/plat_arm.h>
1709d40e0eSAntonio Nino Diaz #include <plat/common/platform.h>
1809d40e0eSAntonio Nino Diaz 
194da6f6cdSSathees Balya #pragma weak plat_arm_error_handler
204da6f6cdSSathees Balya 
217b56928aSSoby Mathew /*
227b56928aSSoby Mathew  * ARM common implementation for error handler
237b56928aSSoby Mathew  */
244da6f6cdSSathees Balya void __dead2 plat_arm_error_handler(int err)
257b56928aSSoby Mathew {
267b56928aSSoby Mathew 	int ret;
277b56928aSSoby Mathew 
287b56928aSSoby Mathew 	switch (err) {
297b56928aSSoby Mathew 	case -ENOENT:
307b56928aSSoby Mathew 	case -EAUTH:
317b56928aSSoby Mathew 		/* Image load or authentication error. Erase the ToC */
327b56928aSSoby Mathew 		INFO("Erasing FIP ToC from flash...\n");
33583e0791SAntonio Nino Diaz 		(void)nor_unlock(PLAT_ARM_FIP_BASE);
347b56928aSSoby Mathew 		ret = nor_word_program(PLAT_ARM_FIP_BASE, 0);
357b56928aSSoby Mathew 		if (ret != 0) {
367b56928aSSoby Mathew 			ERROR("Cannot erase ToC\n");
377b56928aSSoby Mathew 		} else {
387b56928aSSoby Mathew 			INFO("Done\n");
397b56928aSSoby Mathew 		}
407b56928aSSoby Mathew 		break;
417b56928aSSoby Mathew 	default:
427b56928aSSoby Mathew 		/* Unexpected error */
437b56928aSSoby Mathew 		break;
447b56928aSSoby Mathew 	}
457b56928aSSoby Mathew 
467b56928aSSoby Mathew 	(void)console_flush();
477b56928aSSoby Mathew 
487b56928aSSoby Mathew 	/* Loop until the watchdog resets the system */
497b56928aSSoby Mathew 	for (;;)
507b56928aSSoby Mathew 		wfi();
517b56928aSSoby Mathew }
524da6f6cdSSathees Balya 
534da6f6cdSSathees Balya void __dead2 plat_error_handler(int err)
544da6f6cdSSathees Balya {
554da6f6cdSSathees Balya 	plat_arm_error_handler(err);
564da6f6cdSSathees Balya }
57