blob: 59c58618152ed668345ccbebce47fbc623d4d9c7 [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>
Juan Castillob6132f12015-10-06 14:01:35 +01008#include <board_arm_def.h>
Soby Mathew94273572018-03-07 11:32:04 +00009#include <console.h>
Juan Castillob6132f12015-10-06 14:01:35 +010010#include <debug.h>
11#include <errno.h>
12#include <norflash.h>
Roberto Vargas2ca18d92018-02-12 12:36:17 +000013#include <platform.h>
Juan Castillob6132f12015-10-06 14:01:35 +010014#include <stdint.h>
15
16/*
Soby Mathew94273572018-03-07 11:32:04 +000017 * ARM common implementation for error handler
Juan Castillob6132f12015-10-06 14:01:35 +010018 */
19void plat_error_handler(int err)
20{
21 int ret;
22
23 switch (err) {
24 case -ENOENT:
25 case -EAUTH:
26 /* Image load or authentication error. Erase the ToC */
27 INFO("Erasing FIP ToC from flash...\n");
28 nor_unlock(PLAT_ARM_FIP_BASE);
29 ret = nor_word_program(PLAT_ARM_FIP_BASE, 0);
Soby Mathew94273572018-03-07 11:32:04 +000030 if (ret != 0) {
Juan Castillob6132f12015-10-06 14:01:35 +010031 ERROR("Cannot erase ToC\n");
32 } else {
33 INFO("Done\n");
34 }
35 break;
36 default:
37 /* Unexpected error */
38 break;
39 }
40
Soby Mathew94273572018-03-07 11:32:04 +000041 (void)console_flush();
42
Juan Castillob6132f12015-10-06 14:01:35 +010043 /* Loop until the watchdog resets the system */
44 for (;;)
Sandrine Bailleux628198b2016-08-18 09:24:40 +010045 wfi();
Juan Castillob6132f12015-10-06 14:01:35 +010046}