blob: aa65f4f338f9b2cb2b47725e1a1a463dc63cd085 [file] [log] [blame]
Juan Castillob6132f12015-10-06 14:01:35 +01001/*
Roberto Vargas2ca18d92018-02-12 12:36:17 +00002 * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
Juan Castillob6132f12015-10-06 14:01:35 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Juan Castillob6132f12015-10-06 14:01:35 +01005 */
6
Sandrine Bailleux628198b2016-08-18 09:24:40 +01007#include <arch_helpers.h>
Soby Mathew94273572018-03-07 11:32:04 +00008#include <console.h>
Juan Castillob6132f12015-10-06 14:01:35 +01009#include <debug.h>
10#include <errno.h>
Antonio Nino Diaz6971f002018-11-06 13:14:21 +000011#include <plat_arm.h>
Roberto Vargas2ca18d92018-02-12 12:36:17 +000012#include <platform.h>
Sughosh Ganu5c06ff12018-03-10 19:12:28 +053013#include <platform_def.h>
Juan Castillob6132f12015-10-06 14:01:35 +010014#include <stdint.h>
Antonio Nino Diazd7da2f82018-10-10 11:14:44 +010015#include <v2m_flash.h>
Juan Castillob6132f12015-10-06 14:01:35 +010016
Sathees Balya22576072018-09-03 17:41:13 +010017#pragma weak plat_arm_error_handler
18
Juan Castillob6132f12015-10-06 14:01:35 +010019/*
Soby Mathew94273572018-03-07 11:32:04 +000020 * ARM common implementation for error handler
Juan Castillob6132f12015-10-06 14:01:35 +010021 */
Sathees Balya22576072018-09-03 17:41:13 +010022void __dead2 plat_arm_error_handler(int err)
Juan Castillob6132f12015-10-06 14:01:35 +010023{
24 int ret;
25
26 switch (err) {
27 case -ENOENT:
28 case -EAUTH:
29 /* Image load or authentication error. Erase the ToC */
30 INFO("Erasing FIP ToC from flash...\n");
Antonio Nino Diaz6971f002018-11-06 13:14:21 +000031 (void)nor_unlock(PLAT_ARM_FIP_BASE);
Juan Castillob6132f12015-10-06 14:01:35 +010032 ret = nor_word_program(PLAT_ARM_FIP_BASE, 0);
Soby Mathew94273572018-03-07 11:32:04 +000033 if (ret != 0) {
Juan Castillob6132f12015-10-06 14:01:35 +010034 ERROR("Cannot erase ToC\n");
35 } else {
36 INFO("Done\n");
37 }
38 break;
39 default:
40 /* Unexpected error */
41 break;
42 }
43
Soby Mathew94273572018-03-07 11:32:04 +000044 (void)console_flush();
45
Juan Castillob6132f12015-10-06 14:01:35 +010046 /* Loop until the watchdog resets the system */
47 for (;;)
Sandrine Bailleux628198b2016-08-18 09:24:40 +010048 wfi();
Juan Castillob6132f12015-10-06 14:01:35 +010049}
Sathees Balya22576072018-09-03 17:41:13 +010050
51void __dead2 plat_error_handler(int err)
52{
53 plat_arm_error_handler(err);
54}