Fix assert abstraction in sim

Assertions that are expected to fail under sim test, are now marked as such
using the macro ASSERT which allows to programmatically switch between normal
assert() behavior and captured assertion.

Assertion changes were moved to more appropriate owners and code duplication
was removed.

Signed-off-by: Fabio Utzig <utzig@apache.org>
diff --git a/boot/bootutil/src/bootutil_misc.c b/boot/bootutil/src/bootutil_misc.c
index 7229a5d..0ec8605 100644
--- a/boot/bootutil/src/bootutil_misc.c
+++ b/boot/bootutil/src/bootutil_misc.c
@@ -34,12 +34,6 @@
 #define BOOT_LOG_LEVEL BOOT_LOG_LEVEL_INFO
 #include "bootutil/bootutil_log.h"
 
-#ifdef __BOOTSIM__
-#undef assert
-void sim_assert(int, const char *test, const char *, unsigned int, const char *);
-#define assert(x) sim_assert((x), #x, __FILE__, __LINE__, __func__)
-#endif
-
 int boot_current_slot;
 
 const uint32_t boot_img_magic[] = {
diff --git a/boot/bootutil/src/bootutil_priv.h b/boot/bootutil/src/bootutil_priv.h
index 08e8c83..1fd0403 100644
--- a/boot/bootutil/src/bootutil_priv.h
+++ b/boot/bootutil/src/bootutil_priv.h
@@ -28,6 +28,12 @@
 extern "C" {
 #endif
 
+#ifdef __BOOTSIM__
+#include "bootsim.h"
+#else
+#define ASSERT assert
+#endif
+
 struct flash_area;
 
 #define BOOT_EFLASH     1
diff --git a/boot/bootutil/src/loader.c b/boot/bootutil/src/loader.c
index fbbc805..75494f6 100644
--- a/boot/bootutil/src/loader.c
+++ b/boot/bootutil/src/loader.c
@@ -41,12 +41,6 @@
 #include "mcuboot_config/mcuboot_config.h"
 #endif
 
-#ifdef __BOOTSIM__
-#undef assert
-void sim_assert(int, const char *test, const char *, unsigned int, const char *);
-#define assert(x) sim_assert((x), #x, __FILE__, __LINE__, __func__)
-#endif
-
 static struct boot_loader_state boot_data;
 
 #ifdef MCUBOOT_VALIDATE_SLOT0
@@ -58,7 +52,7 @@
         }                                    \
     } while (0)
 #else
-#define BOOT_STATUS_ASSERT(x) assert(x)
+#define BOOT_STATUS_ASSERT(x) ASSERT(x)
 #endif
 
 struct boot_status_table {
@@ -1429,7 +1423,7 @@
 
 #ifdef MCUBOOT_VALIDATE_SLOT0
     rc = boot_validate_slot(0);
-    assert(rc == 0);
+    ASSERT(rc == 0);
     if (rc != 0) {
         rc = BOOT_EBADIMAGE;
         goto out;