17b56928aSSoby Mathew /* 27b56928aSSoby Mathew * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved. 37b56928aSSoby Mathew * 47b56928aSSoby Mathew * SPDX-License-Identifier: BSD-3-Clause 57b56928aSSoby Mathew */ 67b56928aSSoby Mathew 77b56928aSSoby Mathew #include <errno.h> 87b56928aSSoby Mathew #include <stdint.h> 9*09d40e0eSAntonio Nino Diaz 10*09d40e0eSAntonio Nino Diaz #include <platform_def.h> 11*09d40e0eSAntonio Nino Diaz 12*09d40e0eSAntonio Nino Diaz #include <arch_helpers.h> 13*09d40e0eSAntonio Nino Diaz #include <common/debug.h> 14*09d40e0eSAntonio Nino Diaz #include <drivers/cfi/v2m_flash.h> 15*09d40e0eSAntonio Nino Diaz #include <drivers/console.h> 16*09d40e0eSAntonio Nino Diaz #include <plat/common/platform.h> 17*09d40e0eSAntonio Nino Diaz 18*09d40e0eSAntonio Nino Diaz #include <plat_arm.h> 197b56928aSSoby Mathew 204da6f6cdSSathees Balya #pragma weak plat_arm_error_handler 214da6f6cdSSathees Balya 227b56928aSSoby Mathew /* 237b56928aSSoby Mathew * ARM common implementation for error handler 247b56928aSSoby Mathew */ 254da6f6cdSSathees Balya void __dead2 plat_arm_error_handler(int err) 267b56928aSSoby Mathew { 277b56928aSSoby Mathew int ret; 287b56928aSSoby Mathew 297b56928aSSoby Mathew switch (err) { 307b56928aSSoby Mathew case -ENOENT: 317b56928aSSoby Mathew case -EAUTH: 327b56928aSSoby Mathew /* Image load or authentication error. Erase the ToC */ 337b56928aSSoby Mathew INFO("Erasing FIP ToC from flash...\n"); 34583e0791SAntonio Nino Diaz (void)nor_unlock(PLAT_ARM_FIP_BASE); 357b56928aSSoby Mathew ret = nor_word_program(PLAT_ARM_FIP_BASE, 0); 367b56928aSSoby Mathew if (ret != 0) { 377b56928aSSoby Mathew ERROR("Cannot erase ToC\n"); 387b56928aSSoby Mathew } else { 397b56928aSSoby Mathew INFO("Done\n"); 407b56928aSSoby Mathew } 417b56928aSSoby Mathew break; 427b56928aSSoby Mathew default: 437b56928aSSoby Mathew /* Unexpected error */ 447b56928aSSoby Mathew break; 457b56928aSSoby Mathew } 467b56928aSSoby Mathew 477b56928aSSoby Mathew (void)console_flush(); 487b56928aSSoby Mathew 497b56928aSSoby Mathew /* Loop until the watchdog resets the system */ 507b56928aSSoby Mathew for (;;) 517b56928aSSoby Mathew wfi(); 527b56928aSSoby Mathew } 534da6f6cdSSathees Balya 544da6f6cdSSathees Balya void __dead2 plat_error_handler(int err) 554da6f6cdSSathees Balya { 564da6f6cdSSathees Balya plat_arm_error_handler(err); 574da6f6cdSSathees Balya } 58