boot/espressif: Update main.c to call init and loader functions

Add ESP specific loader code to load host application

Signed-off-by: Shubham Kulkarni <shubham.kulkarni@espressif.com>
diff --git a/boot/espressif/main.c b/boot/espressif/main.c
index 9b98fbf..c5bb3e0 100644
--- a/boot/espressif/main.c
+++ b/boot/espressif/main.c
@@ -5,14 +5,35 @@
  */
 
 #include <bootutil/bootutil.h>
+#include <bootutil/image.h>
+
+#include <mcuboot_config/mcuboot_logging.h>
+
+#include <bootloader_init.h>
+#include <esp_loader.h>
+
+void do_boot(struct boot_rsp *rsp)
+{
+    MCUBOOT_LOG_INF("br_image_off = 0x%x", rsp->br_image_off);
+    MCUBOOT_LOG_INF("ih_hdr_size = 0x%x", rsp->br_hdr->ih_hdr_size);
+    int slot = (rsp->br_image_off == CONFIG_ESP_APPLICATION_PRIMARY_START_ADDRESS) ? 0 : 1;
+    esp_app_image_load(slot, rsp->br_hdr->ih_hdr_size);
+}
 
 int main()
 {
+    bootloader_init();
     struct boot_rsp rsp;
-    int rv = boot_go(&rsp);
+#ifdef MCUBOOT_VER
+    MCUBOOT_LOG_INF("*** Booting MCUBoot build %s  ***", MCUBOOT_VER);
+#endif
 
-    if (rv == 0) {
-        //    
+    fih_int fih_rc = FIH_FAILURE;
+    FIH_CALL(boot_go, fih_rc, &rsp);
+    if (fih_not_eq(fih_rc, FIH_SUCCESS)) {
+        MCUBOOT_LOG_ERR("Unable to find bootable image");
+        FIH_PANIC;
     }
+    do_boot(&rsp);
     while(1);
 }