espressif: remove IDF git submodule and add its reference by param

Remove the ESP-IDF from git submodules to avoid potential
duplicated repo clones on the user system. IDF HAL code is still
a dependency for Espressif port, therefore now the HAL code
reference needs to be passed by parameter when building.

The Espressif port was also updated to work with last v5.1 IDF
code.

Signed-off-by: Almir Okato <almir.okato@espressif.com>
diff --git a/boot/espressif/hal/include/bootloader_wdt.h b/boot/espressif/hal/include/bootloader_wdt.h
index 1295cf3..e5ac551 100644
--- a/boot/espressif/hal/include/bootloader_wdt.h
+++ b/boot/espressif/hal/include/bootloader_wdt.h
@@ -6,4 +6,3 @@
 #pragma once
 
 void bootloader_wdt_feed(void);
-void bootloader_config_wdt(void);
diff --git a/boot/espressif/hal/include/esp32/esp32.cmake b/boot/espressif/hal/include/esp32/esp32.cmake
index 7d3776e..6e72ced 100644
--- a/boot/espressif/hal/include/esp32/esp32.cmake
+++ b/boot/espressif/hal/include/esp32/esp32.cmake
@@ -2,21 +2,31 @@
 #
 # SPDX-License-Identifier: Apache-2.0
 
-list(APPEND include_dirs
-    ${esp_idf_dir}/components/${MCUBOOT_TARGET}/include
-    )
-
 list(APPEND hal_srcs
-    ${esp_idf_dir}/components/efuse/src/esp_efuse_api_key_esp32.c
+    ${esp_hal_dir}/components/esp_hw_support/port/${MCUBOOT_TARGET}/rtc_init.c
+    ${esp_hal_dir}/components/efuse/src/efuse_controller/keys/without_key_purposes/three_key_blocks/esp_efuse_api_key.c
     )
 
 if (DEFINED CONFIG_ESP_MULTI_PROCESSOR_BOOT)
     list(APPEND hal_srcs
         ${src_dir}/${MCUBOOT_TARGET}/app_cpu_start.c
+        ${esp_hal_dir}/components/esp_hw_support/cpu.c
+        )
+endif()
+
+if (DEFINED CONFIG_ESP_CONSOLE_UART_CUSTOM)
+    list(APPEND hal_srcs
+        ${src_dir}/${MCUBOOT_TARGET}/console_uart_custom.c
         )
 endif()
 
 list(APPEND LINKER_SCRIPTS
-    -T${esp_idf_dir}/components/esp_rom/${MCUBOOT_TARGET}/ld/${MCUBOOT_TARGET}.rom.newlib-funcs.ld
-    -T${esp_idf_dir}/components/esp_rom/${MCUBOOT_TARGET}/ld/${MCUBOOT_TARGET}.rom.eco3.ld
+    -T${esp_hal_dir}/components/esp_rom/${MCUBOOT_TARGET}/ld/${MCUBOOT_TARGET}.rom.newlib-funcs.ld
+    -T${esp_hal_dir}/components/esp_rom/${MCUBOOT_TARGET}/ld/${MCUBOOT_TARGET}.rom.eco3.ld
     )
+
+set_source_files_properties(
+    ${esp_hal_dir}/components/bootloader_support/src/esp32/bootloader_esp32.c
+    ${esp_hal_dir}/components/bootloader_support/bootloader_flash/src/bootloader_flash.c
+    PROPERTIES COMPILE_FLAGS
+    "-Wno-unused-variable -Wno-unused-but-set-variable")
diff --git a/boot/espressif/hal/include/esp32/sdkconfig.h b/boot/espressif/hal/include/esp32/sdkconfig.h
index 6e76b63..7431e9b 100644
--- a/boot/espressif/hal/include/esp32/sdkconfig.h
+++ b/boot/espressif/hal/include/esp32/sdkconfig.h
@@ -8,9 +8,17 @@
 #define CONFIG_IDF_FIRMWARE_CHIP_ID 0x0000
 #define CONFIG_IDF_TARGET_ESP32 1
 #define CONFIG_ESP32_REV_MIN_3 1
+#define CONFIG_ESP32_REV_MIN_FULL 300
+#define CONFIG_ESP_REV_MIN_FULL CONFIG_ESP32_REV_MIN_FULL
 #define CONFIG_ESP32_REV_MIN 3
+#define CONFIG_ESP32_REV_MAX_FULL 399
+#define CONFIG_ESP_REV_MAX_FULL CONFIG_ESP32_REV_MAX_FULL
 #define CONFIG_SPI_FLASH_ROM_DRIVER_PATCH 1
+#define CONFIG_MMU_PAGE_SIZE 0x10000
 #define CONFIG_ESP32_XTAL_FREQ 40
+#define CONFIG_XTAL_FREQ 40
+#define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_160 1
+#define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ 160
 #define CONFIG_MCUBOOT 1
 #define NDEBUG 1
 #define CONFIG_BOOTLOADER_WDT_TIME_MS 9000
@@ -20,3 +28,4 @@
 #define CONFIG_EFUSE_VIRTUAL_OFFSET 0x250000
 #define CONFIG_EFUSE_VIRTUAL_SIZE 0x2000
 #define CONFIG_EFUSE_MAX_BLK_LEN 192
+#define CONFIG_BOOTLOADER_FLASH_XMC_SUPPORT 1
diff --git a/boot/espressif/hal/include/esp32c3/esp32c3.cmake b/boot/espressif/hal/include/esp32c3/esp32c3.cmake
index 5d37192..3d4525a 100644
--- a/boot/espressif/hal/include/esp32c3/esp32c3.cmake
+++ b/boot/espressif/hal/include/esp32c3/esp32c3.cmake
@@ -3,17 +3,18 @@
 # SPDX-License-Identifier: Apache-2.0
 
 list(APPEND hal_srcs
-    ${esp_idf_dir}/components/bootloader_support/src/flash_qio_mode.c
-    ${esp_idf_dir}/components/esp_hw_support/port/${MCUBOOT_TARGET}/cpu_util_esp32c3.c
-    ${esp_idf_dir}/components/efuse/src/esp_efuse_api_key_esp32xx.c
+    ${esp_hal_dir}/components/esp_hw_support/port/${MCUBOOT_TARGET}/rtc_init.c
+    ${esp_hal_dir}/components/hal/cache_hal.c
+    ${esp_hal_dir}/components/efuse/src/efuse_controller/keys/with_key_purposes/esp_efuse_api_key.c
 )
 
+if (DEFINED CONFIG_ESP_CONSOLE_UART_CUSTOM)
+    list(APPEND hal_srcs
+        ${src_dir}/${MCUBOOT_TARGET}/console_uart_custom.c
+        )
+endif()
+
 list(APPEND LINKER_SCRIPTS
-    -T${esp_idf_dir}/components/esp_rom/${MCUBOOT_TARGET}/ld/${MCUBOOT_TARGET}.rom.newlib.ld
-    -T${esp_idf_dir}/components/esp_rom/${MCUBOOT_TARGET}/ld/${MCUBOOT_TARGET}.rom.eco3.ld
+    -T${esp_hal_dir}/components/esp_rom/${MCUBOOT_TARGET}/ld/${MCUBOOT_TARGET}.rom.newlib.ld
+    -T${esp_hal_dir}/components/esp_rom/${MCUBOOT_TARGET}/ld/${MCUBOOT_TARGET}.rom.eco3.ld
 )
-
-set_source_files_properties(
-    ${esp_idf_dir}/components/bootloader_support/src/flash_qio_mode.c
-    PROPERTIES COMPILE_FLAGS
-    "-Wno-unused-variable")
diff --git a/boot/espressif/hal/include/esp32c3/sdkconfig.h b/boot/espressif/hal/include/esp32c3/sdkconfig.h
index f091a13..08c616a 100644
--- a/boot/espressif/hal/include/esp32c3/sdkconfig.h
+++ b/boot/espressif/hal/include/esp32c3/sdkconfig.h
@@ -7,7 +7,15 @@
 #define BOOTLOADER_BUILD 1
 #define CONFIG_IDF_FIRMWARE_CHIP_ID 0x0005
 #define CONFIG_IDF_TARGET_ESP32C3 1
+#define CONFIG_ESP32C3_REV_MIN_3 1
+#define CONFIG_ESP32C3_REV_MIN_FULL 3
+#define CONFIG_ESP_REV_MIN_FULL CONFIG_ESP32C3_REV_MIN_FULL
+#define CONFIG_ESP32C3_REV_MIN 3
+#define CONFIG_ESP32C3_REV_MAX_FULL 99
+#define CONFIG_ESP_REV_MAX_FULL CONFIG_ESP32C3_REV_MAX_FULL
 #define CONFIG_IDF_TARGET_ARCH_RISCV 1
+#define CONFIG_MMU_PAGE_SIZE 0x10000
+#define CONFIG_XTAL_FREQ 40
 #define CONFIG_SPI_FLASH_ROM_DRIVER_PATCH 1
 #define CONFIG_MCUBOOT 1
 #define NDEBUG 1
@@ -18,3 +26,4 @@
 #define CONFIG_EFUSE_VIRTUAL_OFFSET 0x250000
 #define CONFIG_EFUSE_VIRTUAL_SIZE 0x2000
 #define CONFIG_EFUSE_MAX_BLK_LEN 256
+#define CONFIG_BOOTLOADER_FLASH_XMC_SUPPORT 1
diff --git a/boot/espressif/hal/include/esp32s2/esp32s2.cmake b/boot/espressif/hal/include/esp32s2/esp32s2.cmake
index 7afafc6..4f78e42 100644
--- a/boot/espressif/hal/include/esp32s2/esp32s2.cmake
+++ b/boot/espressif/hal/include/esp32s2/esp32s2.cmake
@@ -3,12 +3,20 @@
 # SPDX-License-Identifier: Apache-2.0
 
 list(APPEND hal_srcs
-    ${esp_idf_dir}/components/esp_hw_support/port/${MCUBOOT_TARGET}/regi2c_ctrl.c
-    ${esp_idf_dir}/components/efuse/src/esp_efuse_api_key_esp32xx.c
-    ${esp_idf_dir}/components/esp_rom/patches/esp_rom_crc.c
+    ${esp_hal_dir}/components/esp_hw_support/port/${MCUBOOT_TARGET}/rtc_init.c
+    ${esp_hal_dir}/components/hal/cache_hal.c
+    ${esp_hal_dir}/components/efuse/src/efuse_controller/keys/with_key_purposes/esp_efuse_api_key.c
+    ${esp_hal_dir}/components/esp_rom/patches/esp_rom_crc.c
+    ${esp_hal_dir}/components/esp_rom/patches/esp_rom_regi2c_esp32s2.c
+
     )
 
 list(APPEND LINKER_SCRIPTS
-    -T${esp_idf_dir}/components/esp_rom/${MCUBOOT_TARGET}/ld/${MCUBOOT_TARGET}.rom.newlib-funcs.ld
-    -T${esp_idf_dir}/components/esp_rom/${MCUBOOT_TARGET}/ld/${MCUBOOT_TARGET}.rom.spiflash.ld
+    -T${esp_hal_dir}/components/esp_rom/${MCUBOOT_TARGET}/ld/${MCUBOOT_TARGET}.rom.newlib-funcs.ld
+    -T${esp_hal_dir}/components/esp_rom/${MCUBOOT_TARGET}/ld/${MCUBOOT_TARGET}.rom.spiflash.ld
     )
+
+set_source_files_properties(
+    ${esp_hal_dir}/components/bootloader_support/src/esp32s2/bootloader_esp32s2.c
+    PROPERTIES COMPILE_FLAGS
+    "-Wno-unused-but-set-variable")
diff --git a/boot/espressif/hal/include/esp32s2/sdkconfig.h b/boot/espressif/hal/include/esp32s2/sdkconfig.h
index ed61b9b..d041f96 100644
--- a/boot/espressif/hal/include/esp32s2/sdkconfig.h
+++ b/boot/espressif/hal/include/esp32s2/sdkconfig.h
@@ -7,6 +7,14 @@
 #define BOOTLOADER_BUILD 1
 #define CONFIG_IDF_FIRMWARE_CHIP_ID 0x0002
 #define CONFIG_IDF_TARGET_ESP32S2 1
+#define CONFIG_ESP32S2_REV_MIN_0 1
+#define CONFIG_ESP32S2_REV_MIN_FULL 0
+#define CONFIG_ESP_REV_MIN_FULL CONFIG_ESP32S2_REV_MIN_FULL
+#define CONFIG_ESP32S2_REV_MIN 0
+#define CONFIG_ESP32S2_REV_MAX_FULL 99
+#define CONFIG_ESP_REV_MAX_FULL CONFIG_ESP32S2_REV_MAX_FULL
+#define CONFIG_MMU_PAGE_SIZE 0x10000
+#define CONFIG_XTAL_FREQ 40
 #define CONFIG_SPI_FLASH_ROM_DRIVER_PATCH 1
 #define CONFIG_ESP32S2_XTAL_FREQ 40
 #define CONFIG_MCUBOOT 1
@@ -18,3 +26,4 @@
 #define CONFIG_EFUSE_VIRTUAL_OFFSET 0x250000
 #define CONFIG_EFUSE_VIRTUAL_SIZE 0x2000
 #define CONFIG_EFUSE_MAX_BLK_LEN 256
+#define CONFIG_BOOTLOADER_FLASH_XMC_SUPPORT 1
diff --git a/boot/espressif/hal/include/esp32s3/esp32s3.cmake b/boot/espressif/hal/include/esp32s3/esp32s3.cmake
index f3241ef..b894c07 100644
--- a/boot/espressif/hal/include/esp32s3/esp32s3.cmake
+++ b/boot/espressif/hal/include/esp32s3/esp32s3.cmake
@@ -3,15 +3,23 @@
 # SPDX-License-Identifier: Apache-2.0
 
 list(APPEND hal_srcs
-    ${esp_idf_dir}/components/efuse/src/esp_efuse_api_key_esp32xx.c
+    ${esp_hal_dir}/components/esp_hw_support/port/${MCUBOOT_TARGET}/rtc_init.c
+    ${esp_hal_dir}/components/hal/cache_hal.c
+    ${esp_hal_dir}/components/efuse/src/efuse_controller/keys/with_key_purposes/esp_efuse_api_key.c
 )
 
 if (DEFINED CONFIG_ESP_MULTI_PROCESSOR_BOOT)
     list(APPEND hal_srcs
         ${src_dir}/${MCUBOOT_TARGET}/app_cpu_start.c
+        ${esp_hal_dir}/components/esp_hw_support/cpu.c
         )
 endif()
 
 list(APPEND LINKER_SCRIPTS
-    -T${esp_idf_dir}/components/esp_rom/${MCUBOOT_TARGET}/ld/${MCUBOOT_TARGET}.rom.newlib.ld
+    -T${esp_hal_dir}/components/esp_rom/${MCUBOOT_TARGET}/ld/${MCUBOOT_TARGET}.rom.newlib.ld
     )
+
+set_source_files_properties(
+    ${esp_hal_dir}/components/bootloader_support/src/esp32s3/bootloader_esp32s3.c
+    PROPERTIES COMPILE_FLAGS
+    "-Wno-unused-variable -Wno-unused-but-set-variable")
diff --git a/boot/espressif/hal/include/esp32s3/sdkconfig.h b/boot/espressif/hal/include/esp32s3/sdkconfig.h
index e88d74f..25581c8 100644
--- a/boot/espressif/hal/include/esp32s3/sdkconfig.h
+++ b/boot/espressif/hal/include/esp32s3/sdkconfig.h
@@ -7,6 +7,14 @@
 #define BOOTLOADER_BUILD 1
 #define CONFIG_IDF_FIRMWARE_CHIP_ID 0x0009
 #define CONFIG_IDF_TARGET_ESP32S3 1
+#define CONFIG_ESP32S3_REV_MIN_0 1
+#define CONFIG_ESP32S3_REV_MIN_FULL 0
+#define CONFIG_ESP_REV_MIN_FULL CONFIG_ESP32S3_REV_MIN_FULL
+#define CONFIG_ESP32S3_REV_MIN 0
+#define CONFIG_ESP32S3_REV_MAX_FULL 99
+#define CONFIG_ESP_REV_MAX_FULL CONFIG_ESP32S3_REV_MAX_FULL
+#define CONFIG_MMU_PAGE_SIZE 0x10000
+#define CONFIG_XTAL_FREQ 40
 #define CONFIG_SPI_FLASH_ROM_DRIVER_PATCH 1
 #define CONFIG_MCUBOOT 1
 #define NDEBUG 1
diff --git a/boot/espressif/hal/include/esp_log.h b/boot/espressif/hal/include/esp_log.h
index 6fcab74..ad6270d 100644
--- a/boot/espressif/hal/include/esp_log.h
+++ b/boot/espressif/hal/include/esp_log.h
@@ -5,6 +5,7 @@
  */
 
 #pragma once
+#include <inttypes.h>
 #include <mcuboot_config/mcuboot_logging.h>
 
 /* Log levels from IDF are similar to MCUboot's */
@@ -24,3 +25,5 @@
 #define ESP_EARLY_LOGI(tag, fmt, ...) MCUBOOT_LOG_INF("[%s] " fmt, tag, ##__VA_ARGS__)
 #define ESP_EARLY_LOGD(tag, fmt, ...) MCUBOOT_LOG_DBG("[%s] " fmt, tag, ##__VA_ARGS__)
 #define ESP_EARLY_LOGV(tag, fmt, ...) MCUBOOT_LOG_DBG("[%s] " fmt, tag, ##__VA_ARGS__)
+
+uint32_t esp_log_early_timestamp(void);