blob: 8650d48a7d7e43e99c76bf9b15e807984e0eae3f [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
Juan Castillob6132f12015-10-06 14:01:35 +01007#include <errno.h>
Juan Castillob6132f12015-10-06 14:01:35 +01008#include <stdint.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00009
10#include <platform_def.h>
11
12#include <arch_helpers.h>
13#include <common/debug.h>
14#include <drivers/cfi/v2m_flash.h>
15#include <drivers/console.h>
16#include <plat/common/platform.h>
17
18#include <plat_arm.h>
Juan Castillob6132f12015-10-06 14:01:35 +010019
Sathees Balya22576072018-09-03 17:41:13 +010020#pragma weak plat_arm_error_handler
21
Juan Castillob6132f12015-10-06 14:01:35 +010022/*
Soby Mathew94273572018-03-07 11:32:04 +000023 * ARM common implementation for error handler
Juan Castillob6132f12015-10-06 14:01:35 +010024 */
Sathees Balya22576072018-09-03 17:41:13 +010025void __dead2 plat_arm_error_handler(int err)
Juan Castillob6132f12015-10-06 14:01:35 +010026{
27 int ret;
28
29 switch (err) {
30 case -ENOENT:
31 case -EAUTH:
32 /* Image load or authentication error. Erase the ToC */
33 INFO("Erasing FIP ToC from flash...\n");
Antonio Nino Diaz6971f002018-11-06 13:14:21 +000034 (void)nor_unlock(PLAT_ARM_FIP_BASE);
Juan Castillob6132f12015-10-06 14:01:35 +010035 ret = nor_word_program(PLAT_ARM_FIP_BASE, 0);
Soby Mathew94273572018-03-07 11:32:04 +000036 if (ret != 0) {
Juan Castillob6132f12015-10-06 14:01:35 +010037 ERROR("Cannot erase ToC\n");
38 } else {
39 INFO("Done\n");
40 }
41 break;
42 default:
43 /* Unexpected error */
44 break;
45 }
46
Soby Mathew94273572018-03-07 11:32:04 +000047 (void)console_flush();
48
Juan Castillob6132f12015-10-06 14:01:35 +010049 /* Loop until the watchdog resets the system */
50 for (;;)
Sandrine Bailleux628198b2016-08-18 09:24:40 +010051 wfi();
Juan Castillob6132f12015-10-06 14:01:35 +010052}
Sathees Balya22576072018-09-03 17:41:13 +010053
54void __dead2 plat_error_handler(int err)
55{
56 plat_arm_error_handler(err);
57}