Juan Castillo | b6132f1 | 2015-10-06 14:01:35 +0100 | [diff] [blame] | 1 | /* |
Roberto Vargas | 2ca18d9 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 2 | * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved. |
Juan Castillo | b6132f1 | 2015-10-06 14:01:35 +0100 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Juan Castillo | b6132f1 | 2015-10-06 14:01:35 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
Juan Castillo | b6132f1 | 2015-10-06 14:01:35 +0100 | [diff] [blame] | 7 | #include <errno.h> |
Juan Castillo | b6132f1 | 2015-10-06 14:01:35 +0100 | [diff] [blame] | 8 | #include <stdint.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 9 | |
| 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 Diaz | bd7b740 | 2019-01-25 14:30:04 +0000 | [diff] [blame] | 16 | #include <plat/arm/common/plat_arm.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 17 | #include <plat/common/platform.h> |
| 18 | |
Sathees Balya | 2257607 | 2018-09-03 17:41:13 +0100 | [diff] [blame] | 19 | #pragma weak plat_arm_error_handler |
| 20 | |
Juan Castillo | b6132f1 | 2015-10-06 14:01:35 +0100 | [diff] [blame] | 21 | /* |
Soby Mathew | 9427357 | 2018-03-07 11:32:04 +0000 | [diff] [blame] | 22 | * ARM common implementation for error handler |
Juan Castillo | b6132f1 | 2015-10-06 14:01:35 +0100 | [diff] [blame] | 23 | */ |
Sathees Balya | 2257607 | 2018-09-03 17:41:13 +0100 | [diff] [blame] | 24 | void __dead2 plat_arm_error_handler(int err) |
Juan Castillo | b6132f1 | 2015-10-06 14:01:35 +0100 | [diff] [blame] | 25 | { |
| 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 Diaz | 6971f00 | 2018-11-06 13:14:21 +0000 | [diff] [blame] | 33 | (void)nor_unlock(PLAT_ARM_FIP_BASE); |
Juan Castillo | b6132f1 | 2015-10-06 14:01:35 +0100 | [diff] [blame] | 34 | ret = nor_word_program(PLAT_ARM_FIP_BASE, 0); |
Soby Mathew | 9427357 | 2018-03-07 11:32:04 +0000 | [diff] [blame] | 35 | if (ret != 0) { |
Juan Castillo | b6132f1 | 2015-10-06 14:01:35 +0100 | [diff] [blame] | 36 | ERROR("Cannot erase ToC\n"); |
| 37 | } else { |
| 38 | INFO("Done\n"); |
| 39 | } |
| 40 | break; |
| 41 | default: |
| 42 | /* Unexpected error */ |
| 43 | break; |
| 44 | } |
| 45 | |
Soby Mathew | 9427357 | 2018-03-07 11:32:04 +0000 | [diff] [blame] | 46 | (void)console_flush(); |
| 47 | |
Juan Castillo | b6132f1 | 2015-10-06 14:01:35 +0100 | [diff] [blame] | 48 | /* Loop until the watchdog resets the system */ |
| 49 | for (;;) |
Sandrine Bailleux | 628198b | 2016-08-18 09:24:40 +0100 | [diff] [blame] | 50 | wfi(); |
Juan Castillo | b6132f1 | 2015-10-06 14:01:35 +0100 | [diff] [blame] | 51 | } |
Sathees Balya | 2257607 | 2018-09-03 17:41:13 +0100 | [diff] [blame] | 52 | |
| 53 | void __dead2 plat_error_handler(int err) |
| 54 | { |
| 55 | plat_arm_error_handler(err); |
| 56 | } |