blob: 519d44d7d16bbe28927dffa632037fb814096788 [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>
Roberto Vargas2ca18d92018-02-12 12:36:17 +000011#include <platform.h>
Sughosh Ganu5c06ff12018-03-10 19:12:28 +053012#include <platform_def.h>
Juan Castillob6132f12015-10-06 14:01:35 +010013#include <stdint.h>
Antonio Nino Diazd7da2f82018-10-10 11:14:44 +010014#include <v2m_flash.h>
Juan Castillob6132f12015-10-06 14:01:35 +010015
Sathees Balya22576072018-09-03 17:41:13 +010016#pragma weak plat_arm_error_handler
17
Juan Castillob6132f12015-10-06 14:01:35 +010018/*
Soby Mathew94273572018-03-07 11:32:04 +000019 * ARM common implementation for error handler
Juan Castillob6132f12015-10-06 14:01:35 +010020 */
Sathees Balya22576072018-09-03 17:41:13 +010021void __dead2 plat_arm_error_handler(int err)
Juan Castillob6132f12015-10-06 14:01:35 +010022{
23 int ret;
24
25 switch (err) {
26 case -ENOENT:
27 case -EAUTH:
28 /* Image load or authentication error. Erase the ToC */
29 INFO("Erasing FIP ToC from flash...\n");
30 nor_unlock(PLAT_ARM_FIP_BASE);
31 ret = nor_word_program(PLAT_ARM_FIP_BASE, 0);
Soby Mathew94273572018-03-07 11:32:04 +000032 if (ret != 0) {
Juan Castillob6132f12015-10-06 14:01:35 +010033 ERROR("Cannot erase ToC\n");
34 } else {
35 INFO("Done\n");
36 }
37 break;
38 default:
39 /* Unexpected error */
40 break;
41 }
42
Soby Mathew94273572018-03-07 11:32:04 +000043 (void)console_flush();
44
Juan Castillob6132f12015-10-06 14:01:35 +010045 /* Loop until the watchdog resets the system */
46 for (;;)
Sandrine Bailleux628198b2016-08-18 09:24:40 +010047 wfi();
Juan Castillob6132f12015-10-06 14:01:35 +010048}
Sathees Balya22576072018-09-03 17:41:13 +010049
50void __dead2 plat_error_handler(int err)
51{
52 plat_arm_error_handler(err);
53}