blob: e77f5dc5c8c43a1dd4faa689068e6492c0d3bcee [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>
Antonio Nino Diazbd7b7402019-01-25 14:30:04 +000016#include <plat/arm/common/plat_arm.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000017#include <plat/common/platform.h>
18
Sathees Balya22576072018-09-03 17:41:13 +010019#pragma weak plat_arm_error_handler
20
Juan Castillob6132f12015-10-06 14:01:35 +010021/*
Soby Mathew94273572018-03-07 11:32:04 +000022 * ARM common implementation for error handler
Juan Castillob6132f12015-10-06 14:01:35 +010023 */
Sathees Balya22576072018-09-03 17:41:13 +010024void __dead2 plat_arm_error_handler(int err)
Juan Castillob6132f12015-10-06 14:01:35 +010025{
26 int ret;
27
28 switch (err) {
29 case -ENOENT:
30 case -EAUTH:
31 /* Image load or authentication error. Erase the ToC */
32 INFO("Erasing FIP ToC from flash...\n");
Antonio Nino Diaz6971f002018-11-06 13:14:21 +000033 (void)nor_unlock(PLAT_ARM_FIP_BASE);
Juan Castillob6132f12015-10-06 14:01:35 +010034 ret = nor_word_program(PLAT_ARM_FIP_BASE, 0);
Soby Mathew94273572018-03-07 11:32:04 +000035 if (ret != 0) {
Juan Castillob6132f12015-10-06 14:01:35 +010036 ERROR("Cannot erase ToC\n");
37 } else {
38 INFO("Done\n");
39 }
40 break;
41 default:
42 /* Unexpected error */
43 break;
44 }
45
Soby Mathew94273572018-03-07 11:32:04 +000046 (void)console_flush();
47
Juan Castillob6132f12015-10-06 14:01:35 +010048 /* Loop until the watchdog resets the system */
49 for (;;)
Sandrine Bailleux628198b2016-08-18 09:24:40 +010050 wfi();
Juan Castillob6132f12015-10-06 14:01:35 +010051}
Sathees Balya22576072018-09-03 17:41:13 +010052
53void __dead2 plat_error_handler(int err)
54{
55 plat_arm_error_handler(err);
56}