137b70031SAmbroise Vincent /* 2e6937287SZelalem * Copyright (c) 2019-2020, Arm Limited. All rights reserved. 337b70031SAmbroise Vincent * 437b70031SAmbroise Vincent * SPDX-License-Identifier: BSD-3-Clause 537b70031SAmbroise Vincent */ 637b70031SAmbroise Vincent 737b70031SAmbroise Vincent #include <errno.h> 837b70031SAmbroise Vincent 937b70031SAmbroise Vincent #include <common/debug.h> 1037b70031SAmbroise Vincent #include <drivers/arm/sp805.h> 1137b70031SAmbroise Vincent #include <drivers/cfi/v2m_flash.h> 1237b70031SAmbroise Vincent #include <plat/arm/common/plat_arm.h> 1337b70031SAmbroise Vincent #include <platform_def.h> 1437b70031SAmbroise Vincent 1537b70031SAmbroise Vincent /* 1637b70031SAmbroise Vincent * FVP error handler 1737b70031SAmbroise Vincent */ 1837b70031SAmbroise Vincent __dead2 void plat_arm_error_handler(int err) 1937b70031SAmbroise Vincent { 2037b70031SAmbroise Vincent int ret; 2137b70031SAmbroise Vincent 2237b70031SAmbroise Vincent switch (err) { 2337b70031SAmbroise Vincent case -ENOENT: 2437b70031SAmbroise Vincent case -EAUTH: 2537b70031SAmbroise Vincent /* Image load or authentication error. Erase the ToC */ 2637b70031SAmbroise Vincent INFO("Erasing FIP ToC from flash...\n"); 2737b70031SAmbroise Vincent (void)nor_unlock(PLAT_ARM_FIP_BASE); 2837b70031SAmbroise Vincent ret = nor_word_program(PLAT_ARM_FIP_BASE, 0); 2937b70031SAmbroise Vincent if (ret != 0) { 3037b70031SAmbroise Vincent ERROR("Cannot erase ToC\n"); 3137b70031SAmbroise Vincent } else { 3237b70031SAmbroise Vincent INFO("Done\n"); 3337b70031SAmbroise Vincent } 3437b70031SAmbroise Vincent break; 3537b70031SAmbroise Vincent default: 3637b70031SAmbroise Vincent /* Unexpected error */ 3737b70031SAmbroise Vincent break; 3837b70031SAmbroise Vincent } 3937b70031SAmbroise Vincent 40*831b0e98SJimmy Brisson console_flush(); 4137b70031SAmbroise Vincent 4237b70031SAmbroise Vincent /* Setup the watchdog to reset the system as soon as possible */ 4337b70031SAmbroise Vincent sp805_refresh(ARM_SP805_TWDG_BASE, 1U); 4437b70031SAmbroise Vincent 4537b70031SAmbroise Vincent for (;;) 4637b70031SAmbroise Vincent wfi(); 4737b70031SAmbroise Vincent } 48