Remove TF-A specific assert and abort
Replace TF-A specific assert and abort handlers by platform_ functions
which should be implemented by the environment.
Signed-off-by: Imre Kis <imre.kis@arm.com>
Change-Id: I613cede8d85919aaaa175ac20d2ed4f4b1abef40
diff --git a/components/common/libc/include/assert.h b/components/common/libc/include/assert.h
index acfd147..6a886db 100644
--- a/components/common/libc/include/assert.h
+++ b/components/common/libc/include/assert.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018-2019, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2018-2024, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -9,26 +9,12 @@
#include <cdefs.h>
-#include <common/debug.h>
+#ifndef NDEBUG
+void __dead2 __assert(const char *file, int line, const char *func, const char *assertion);
-#ifndef PLAT_LOG_LEVEL_ASSERT
-#define PLAT_LOG_LEVEL_ASSERT LOG_LEVEL
-#endif
-
-#if ENABLE_ASSERTIONS
-# if PLAT_LOG_LEVEL_ASSERT >= LOG_LEVEL_INFO
-# define assert(e) ((e) ? (void)0 : __assert(__FILE__, __LINE__))
-# else
-# define assert(e) ((e) ? (void)0 : __assert())
-# endif
+#define assert(e) ((e) ? (void)0 : __assert(__FILE__, __LINE__, __func__, #e))
#else
-#define assert(e) ((void)0)
-#endif /* ENABLE_ASSERTIONS */
-
-#if PLAT_LOG_LEVEL_ASSERT >= LOG_LEVEL_INFO
-void __dead2 __assert(const char *file, unsigned int line);
-#else
-void __dead2 __assert(void);
+#define assert(e) ((void)(e))
#endif
#endif /* ASSERT_H */
diff --git a/components/common/libc/include/libc_platform.h b/components/common/libc/include/libc_platform.h
new file mode 100644
index 0000000..77c5706
--- /dev/null
+++ b/components/common/libc/include/libc_platform.h
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Copyright (c) 2021-2024, Arm Limited and Contributors. All rights reserved.
+ */
+
+#ifndef LIBC_PLATFORM_H_
+#define LIBC_PLATFORM_H_
+
+#include <cdefs.h>
+
+/*
+ * Generic assert fail and abort handler function definitions.
+ * Should be implemented by the environment.
+ */
+void __dead2 platform_assert(const char *file, int line, const char *func,
+ const char *failedexpr);
+
+void __dead2 platform_abort(void);
+
+#endif /* LIBC_PLATFORM_H_ */
diff --git a/components/common/libc/src/abort.c b/components/common/libc/src/abort.c
index ac27f62..c5a7920 100644
--- a/components/common/libc/src/abort.c
+++ b/components/common/libc/src/abort.c
@@ -1,15 +1,13 @@
/*
- * Copyright (c) 2013-2018, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2013-2024, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <stdlib.h>
+#include <cdefs.h>
+#include "libc_platform.h"
-#include <common/debug.h>
-
-void abort(void)
+void __dead2 abort(void)
{
- ERROR("ABORT\n");
- panic();
+ platform_abort();
}
diff --git a/components/common/libc/src/assert.c b/components/common/libc/src/assert.c
index 301d142..f6d33a5 100644
--- a/components/common/libc/src/assert.c
+++ b/components/common/libc/src/assert.c
@@ -1,35 +1,16 @@
/*
- * Copyright (c) 2013-2022, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2013-2024, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <assert.h>
-#include <cdefs.h>
-#include <stdio.h>
-#include <common/debug.h>
-#include <drivers/console.h>
-#include <plat/common/platform.h>
+#ifndef NDEBUG
+#include "libc_platform.h"
-/*
- * Only print the output if PLAT_LOG_LEVEL_ASSERT is higher or equal to
- * LOG_LEVEL_INFO, which is the default value for builds with DEBUG=1.
- */
-
-#if PLAT_LOG_LEVEL_ASSERT >= LOG_LEVEL_INFO
-void __dead2 __assert(const char *file, unsigned int line)
+void __dead2 __assert(const char *file, int line, const char *func, const char *assertion)
{
- printf("ASSERT: %s:%u\n", file, line);
- backtrace("assert");
- console_flush();
- plat_panic_handler();
-}
-#else
-void __dead2 __assert(void)
-{
- backtrace("assert");
- console_flush();
- plat_panic_handler();
+ platform_assert(file, line, func, assertion);
}
#endif