Infineon: Switch to 1.9.0 code base, add xmc7000 family support, refactor memory layer
diff --git a/boot/espressif/port/esp32/ld/bootloader.ld b/boot/espressif/port/esp32/ld/bootloader.ld
new file mode 100644
index 0000000..9933bd3
--- /dev/null
+++ b/boot/espressif/port/esp32/ld/bootloader.ld
@@ -0,0 +1,164 @@
+/*
+ * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+/* Simplified memory map for the bootloader.
+ *
+ * The main purpose is to make sure the bootloader can load into main memory
+ * without overwriting itself.
+ */
+
+MEMORY
+{
+ iram_seg (RWX) : org = 0x40093000, len = 0x8800
+ iram_loader_seg (RWX) : org = 0x4009B800, len = 0x4800
+ dram_seg (RW) : org = 0x3FFF5000, len = 0x8900
+}
+
+/* Default entry point: */
+ENTRY(main);
+
+SECTIONS
+{
+ .iram_loader.text :
+ {
+ . = ALIGN (16);
+ _loader_text_start = ABSOLUTE(.);
+ *(.stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
+ *(.iram1 .iram1.*) /* catch stray IRAM_ATTR */
+ *libhal.a:bootloader_flash.*(.literal .text .literal.* .text.*)
+ *libhal.a:bootloader_flash_config_esp32.*(.literal .text .literal.* .text.*)
+ *libhal.a:bootloader_clock_loader.*(.literal .text .literal.* .text.*)
+ *libhal.a:bootloader_common_loader.*(.literal .text .literal.* .text.*)
+ *libhal.a:bootloader_flash.*(.literal .text .literal.* .text.*)
+ *libhal.a:bootloader_random.*(.literal .text .literal.* .text.*)
+ *libhal.a:bootloader_random*.*(.literal.bootloader_random_disable .text.bootloader_random_disable)
+ *libhal.a:bootloader_random*.*(.literal.bootloader_random_enable .text.bootloader_random_enable)
+ *libhal.a:bootloader_efuse_esp32.*(.literal .text .literal.* .text.*)
+ *libhal.a:bootloader_utility.*(.literal .text .literal.* .text.*)
+ *libhal.a:bootloader_sha.*(.literal .text .literal.* .text.*)
+ *libhal.a:bootloader_console_loader.*(.literal .text .literal.* .text.*)
+ *libhal.a:bootloader_panic.*(.literal .text .literal.* .text.*)
+ *libhal.a:bootloader_soc.*(.literal .text .literal.* .text.*)
+ *libhal.a:esp_image_format.*(.literal .text .literal.* .text.*)
+ *libhal.a:flash_encrypt.*(.literal .text .literal.* .text.*)
+ *libhal.a:flash_encryption_secure_features.*(.literal .text .literal.* .text.*)
+ *libhal.a:flash_partitions.*(.literal .text .literal.* .text.*)
+ *libhal.a:secure_boot.*(.literal .text .literal.* .text.*)
+ *libhal.a:secure_boot_secure_features.*(.literal .text .literal.* .text.*)
+ *libhal.a:secure_boot_signatures_bootloader.*(.literal .text .literal.* .text.*)
+ *libhal.a:wdt_hal_iram.*(.literal .text .literal.* .text.*)
+ *libhal.a:esp_efuse_table.*(.literal .text .literal.* .text.*)
+ *libhal.a:esp_efuse_fields.*(.literal .text .literal.* .text.*)
+ *libhal.a:esp_efuse_api.*(.literal .text .literal.* .text.*)
+ *libhal.a:esp_efuse_utility.*(.literal .text .literal.* .text.*)
+ *libhal.a:esp_efuse_api_key_esp32.*(.literal .text .literal.* .text.*)
+ *esp_mcuboot.*(.literal .text .literal.* .text.*)
+ *esp_loader.*(.literal .text .literal.* .text.*)
+ *(.fini.literal)
+ *(.fini)
+ *(.gnu.version)
+ _loader_text_end = ABSOLUTE(.);
+ } > iram_loader_seg
+ .iram.text :
+ {
+ . = ALIGN (16);
+ *(.entry.text)
+ *(.init.literal)
+ *(.init)
+ } > iram_seg
+ .dram0.bss (NOLOAD) :
+ {
+ . = ALIGN (8);
+ _dram_start = ABSOLUTE(.);
+ _bss_start = ABSOLUTE(.);
+ *(.dynsbss)
+ *(.sbss)
+ *(.sbss.*)
+ *(.gnu.linkonce.sb.*)
+ *(.scommon)
+ *(.sbss2)
+ *(.sbss2.*)
+ *(.gnu.linkonce.sb2.*)
+ *(.dynbss)
+ *(.bss)
+ *(.bss.*)
+ *(.gnu.linkonce.b.*)
+ *(COMMON)
+ . = ALIGN (8);
+ _bss_end = ABSOLUTE(.);
+ } >dram_seg
+ .dram0.data :
+ {
+ _data_start = ABSOLUTE(.);
+ *(.data)
+ *(.data.*)
+ *(.gnu.linkonce.d.*)
+ *(.data1)
+ *(.sdata)
+ *(.sdata.*)
+ *(.gnu.linkonce.s.*)
+ *(.sdata2)
+ *(.sdata2.*)
+ *(.gnu.linkonce.s2.*)
+ *(.jcr)
+ _data_end = ABSOLUTE(.);
+ } >dram_seg
+ .dram0.rodata :
+ {
+ _rodata_start = ABSOLUTE(.);
+ *(.rodata)
+ *(.rodata.*)
+ *(.gnu.linkonce.r.*)
+ *(.rodata1)
+ __XT_EXCEPTION_TABLE_ = ABSOLUTE(.);
+ *(.xt_except_table)
+ *(.gcc_except_table)
+ *(.gnu.linkonce.e.*)
+ *(.gnu.version_r)
+ *(.eh_frame)
+ . = (. + 3) & ~ 3;
+ /* C++ constructor and destructor tables, properly ordered: */
+ __init_array_start = ABSOLUTE(.);
+ KEEP (*crtbegin.*(.ctors))
+ KEEP (*(EXCLUDE_FILE (*crtend.*) .ctors))
+ KEEP (*(SORT(.ctors.*)))
+ KEEP (*(.ctors))
+ __init_array_end = ABSOLUTE(.);
+ KEEP (*crtbegin.*(.dtors))
+ KEEP (*(EXCLUDE_FILE (*crtend.*) .dtors))
+ KEEP (*(SORT(.dtors.*)))
+ KEEP (*(.dtors))
+ /* C++ exception handlers table: */
+ __XT_EXCEPTION_DESCS_ = ABSOLUTE(.);
+ *(.xt_except_desc)
+ *(.gnu.linkonce.h.*)
+ __XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.);
+ *(.xt_except_desc_end)
+ *(.dynamic)
+ *(.gnu.version_d)
+ _rodata_end = ABSOLUTE(.);
+ /* Literals are also RO data. */
+ _lit4_start = ABSOLUTE(.);
+ *(*.lit4)
+ *(.lit4.*)
+ *(.gnu.linkonce.lit4.*)
+ _lit4_end = ABSOLUTE(.);
+ . = ALIGN(4);
+ _dram_end = ABSOLUTE(.);
+ } >dram_seg
+ .iram.text :
+ {
+ _stext = .;
+ _text_start = ABSOLUTE(.);
+ *(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
+ *(.iram .iram.*) /* catch stray IRAM_ATTR */
+ *(.fini.literal)
+ *(.fini)
+ *(.gnu.version)
+ _text_end = ABSOLUTE(.);
+ _etext = .;
+ } > iram_seg
+}
diff --git a/boot/espressif/port/esp32c3/ld/bootloader.ld b/boot/espressif/port/esp32c3/ld/bootloader.ld
new file mode 100644
index 0000000..c627cb9
--- /dev/null
+++ b/boot/espressif/port/esp32c3/ld/bootloader.ld
@@ -0,0 +1,172 @@
+/*
+ * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+/* Simplified memory map for the bootloader.
+ *
+ * The main purpose is to make sure the bootloader can load into main memory
+ * without overwriting itself.
+ */
+
+MEMORY
+{
+ iram_seg (RWX) : org = 0x403C8000, len = 0x8000
+ iram_loader_seg (RWX) : org = 0x403D0000, len = 0x4800
+ dram_seg (RW) : org = 0x3FCD5000, len = 0x8C00
+}
+
+/* Default entry point: */
+ENTRY(main);
+
+SECTIONS
+{
+ .iram_loader.text :
+ {
+ . = ALIGN (16);
+ _loader_text_start = ABSOLUTE(.);
+ *(.stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
+ *(.iram1 .iram1.*) /* catch stray IRAM_ATTR */
+ *libhal.a:bootloader_flash.*(.literal .text .literal.* .text.*)
+ *libhal.a:bootloader_flash_config_esp32c3.*(.literal .text .literal.* .text.*)
+ *libhal.a:bootloader_clock_loader.*(.literal .text .literal.* .text.*)
+ *libhal.a:bootloader_common_loader.*(.literal .text .literal.* .text.*)
+ *libhal.a:bootloader_flash.*(.literal .text .literal.* .text.*)
+ *libhal.a:bootloader_random.*(.literal .text .literal.* .text.*)
+ *libhal.a:bootloader_random*.*(.literal.bootloader_random_disable .text.bootloader_random_disable)
+ *libhal.a:bootloader_random*.*(.literal.bootloader_random_enable .text.bootloader_random_enable)
+ *libhal.a:bootloader_efuse_esp32c3.*(.literal .text .literal.* .text.*)
+ *libhal.a:bootloader_utility.*(.literal .text .literal.* .text.*)
+ *libhal.a:bootloader_sha.*(.literal .text .literal.* .text.*)
+ *libhal.a:bootloader_console_loader.*(.literal .text .literal.* .text.*)
+ *libhal.a:bootloader_panic.*(.literal .text .literal.* .text.*)
+ *libhal.a:bootloader_soc.*(.literal .text .literal.* .text.*)
+ *libhal.a:esp_image_format.*(.literal .text .literal.* .text.*)
+ *libhal.a:flash_encrypt.*(.literal .text .literal.* .text.*)
+ *libhal.a:flash_encryption_secure_features.*(.literal .text .literal.* .text.*)
+ *libhal.a:flash_partitions.*(.literal .text .literal.* .text.*)
+ *libhal.a:secure_boot.*(.literal .text .literal.* .text.*)
+ *libhal.a:secure_boot_secure_features.*(.literal .text .literal.* .text.*)
+ *libhal.a:secure_boot_signatures_bootloader.*(.literal .text .literal.* .text.*)
+ *libhal.a:wdt_hal_iram.*(.literal .text .literal.* .text.*)
+ *libhal.a:esp_efuse_table.*(.literal .text .literal.* .text.*)
+ *libhal.a:esp_efuse_fields.*(.literal .text .literal.* .text.*)
+ *libhal.a:esp_efuse_api.*(.literal .text .literal.* .text.*)
+ *libhal.a:esp_efuse_utility.*(.literal .text .literal.* .text.*)
+ *libhal.a:esp_efuse_api_key_esp32xx.*(.literal .text .literal.* .text.*)
+ *esp_mcuboot.*(.literal .text .literal.* .text.*)
+ *esp_loader.*(.literal .text .literal.* .text.*)
+ *(.fini.literal)
+ *(.fini)
+ *(.gnu.version)
+ _loader_text_end = ABSOLUTE(.);
+ } > iram_loader_seg
+
+ .iram.text :
+ {
+ . = ALIGN (16);
+ *(.entry.text)
+ *(.init.literal)
+ *(.init)
+ } > iram_seg
+
+
+ /* Shared RAM */
+ .dram0.bss (NOLOAD) :
+ {
+ . = ALIGN (8);
+ _dram_start = ABSOLUTE(.);
+ _bss_start = ABSOLUTE(.);
+ *(.dynsbss)
+ *(.sbss)
+ *(.sbss.*)
+ *(.gnu.linkonce.sb.*)
+ *(.scommon)
+ *(.sbss2)
+ *(.sbss2.*)
+ *(.gnu.linkonce.sb2.*)
+ *(.dynbss)
+ *(.bss)
+ *(.bss.*)
+ *(.gnu.linkonce.b.*)
+ *(COMMON)
+ . = ALIGN (8);
+ _bss_end = ABSOLUTE(.);
+ } >dram_seg
+
+ .dram0.data :
+ {
+ _data_start = ABSOLUTE(.);
+ *(.data)
+ *(.data.*)
+ *(.gnu.linkonce.d.*)
+ *(.data1)
+ *(.sdata)
+ *(.sdata.*)
+ *(.gnu.linkonce.s.*)
+ *(.sdata2)
+ *(.sdata2.*)
+ *(.gnu.linkonce.s2.*)
+ *(.jcr)
+ _data_end = ABSOLUTE(.);
+ } >dram_seg
+
+ .dram0.rodata :
+ {
+ _rodata_start = ABSOLUTE(.);
+ *(.rodata)
+ *(.rodata.*)
+ *(.gnu.linkonce.r.*)
+ *(.rodata1)
+ __XT_EXCEPTION_TABLE_ = ABSOLUTE(.);
+ *(.xt_except_table)
+ *(.gcc_except_table)
+ *(.gnu.linkonce.e.*)
+ *(.gnu.version_r)
+ *(.eh_frame)
+ . = (. + 3) & ~ 3;
+ /* C++ constructor and destructor tables, properly ordered: */
+ __init_array_start = ABSOLUTE(.);
+ KEEP (*crtbegin.*(.ctors))
+ KEEP (*(EXCLUDE_FILE (*crtend.*) .ctors))
+ KEEP (*(SORT(.ctors.*)))
+ KEEP (*(.ctors))
+ __init_array_end = ABSOLUTE(.);
+ KEEP (*crtbegin.*(.dtors))
+ KEEP (*(EXCLUDE_FILE (*crtend.*) .dtors))
+ KEEP (*(SORT(.dtors.*)))
+ KEEP (*(.dtors))
+ /* C++ exception handlers table: */
+ __XT_EXCEPTION_DESCS_ = ABSOLUTE(.);
+ *(.xt_except_desc)
+ *(.gnu.linkonce.h.*)
+ __XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.);
+ *(.xt_except_desc_end)
+ *(.dynamic)
+ *(.gnu.version_d)
+ _rodata_end = ABSOLUTE(.);
+ /* Literals are also RO data. */
+ _lit4_start = ABSOLUTE(.);
+ *(*.lit4)
+ *(.lit4.*)
+ *(.gnu.linkonce.lit4.*)
+ _lit4_end = ABSOLUTE(.);
+ . = ALIGN(4);
+ _dram_end = ABSOLUTE(.);
+ } >dram_seg
+
+ .iram.text :
+ {
+ _stext = .;
+ _text_start = ABSOLUTE(.);
+ *(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
+ *(.iram .iram.*) /* catch stray IRAM_ATTR */
+ *(.fini.literal)
+ *(.fini)
+ *(.gnu.version)
+ _text_end = ABSOLUTE(.);
+ _etext = .;
+ } > iram_seg
+
+}
diff --git a/boot/espressif/port/esp32s2/ld/bootloader.ld b/boot/espressif/port/esp32s2/ld/bootloader.ld
new file mode 100644
index 0000000..3521894
--- /dev/null
+++ b/boot/espressif/port/esp32s2/ld/bootloader.ld
@@ -0,0 +1,172 @@
+/*
+ * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+/* Simplified memory map for the bootloader.
+ *
+ * The main purpose is to make sure the bootloader can load into main memory
+ * without overwriting itself.
+ */
+
+MEMORY
+{
+ iram_seg (RWX) : org = 0x40048000, len = 0x8000
+ iram_loader_seg (RWX) : org = 0x40050000, len = 0x5000
+ dram_seg (RW) : org = 0x3FFE5000, len = 0x8E00
+}
+
+/* Default entry point: */
+ENTRY(main);
+
+SECTIONS
+{
+ .iram_loader.text :
+ {
+ . = ALIGN (16);
+ _loader_text_start = ABSOLUTE(.);
+ *(.stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
+ *(.iram1 .iram1.*) /* catch stray IRAM_ATTR */
+ *libhal.a:bootloader_flash.*(.literal .text .literal.* .text.*)
+ *libhal.a:bootloader_flash_config_esp32s2.*(.literal .text .literal.* .text.*)
+ *libhal.a:bootloader_clock_loader.*(.literal .text .literal.* .text.*)
+ *libhal.a:bootloader_common_loader.*(.literal .text .literal.* .text.*)
+ *libhal.a:bootloader_flash.*(.literal .text .literal.* .text.*)
+ *libhal.a:bootloader_random.*(.literal .text .literal.* .text.*)
+ *libhal.a:bootloader_random*.*(.literal.bootloader_random_disable .text.bootloader_random_disable)
+ *libhal.a:bootloader_random*.*(.literal.bootloader_random_enable .text.bootloader_random_enable)
+ *libhal.a:bootloader_efuse_esp32s2.*(.literal .text .literal.* .text.*)
+ *libhal.a:bootloader_utility.*(.literal .text .literal.* .text.*)
+ *libhal.a:bootloader_sha.*(.literal .text .literal.* .text.*)
+ *libhal.a:bootloader_console_loader.*(.literal .text .literal.* .text.*)
+ *libhal.a:bootloader_panic.*(.literal .text .literal.* .text.*)
+ *libhal.a:bootloader_soc.*(.literal .text .literal.* .text.*)
+ *libhal.a:esp_image_format.*(.literal .text .literal.* .text.*)
+ *libhal.a:flash_encrypt.*(.literal .text .literal.* .text.*)
+ *libhal.a:flash_encryption_secure_features.*(.literal .text .literal.* .text.*)
+ *libhal.a:flash_partitions.*(.literal .text .literal.* .text.*)
+ *libhal.a:secure_boot.*(.literal .text .literal.* .text.*)
+ *libhal.a:secure_boot_secure_features.*(.literal .text .literal.* .text.*)
+ *libhal.a:secure_boot_signatures_bootloader.*(.literal .text .literal.* .text.*)
+ *libhal.a:wdt_hal_iram.*(.literal .text .literal.* .text.*)
+ *libhal.a:esp_efuse_table.*(.literal .text .literal.* .text.*)
+ *libhal.a:esp_efuse_fields.*(.literal .text .literal.* .text.*)
+ *libhal.a:esp_efuse_api.*(.literal .text .literal.* .text.*)
+ *libhal.a:esp_efuse_utility.*(.literal .text .literal.* .text.*)
+ *libhal.a:esp_efuse_api_key_esp32xx.*(.literal .text .literal.* .text.*)
+ *esp_mcuboot.*(.literal .text .literal.* .text.*)
+ *esp_loader.*(.literal .text .literal.* .text.*)
+ *(.fini.literal)
+ *(.fini)
+ *(.gnu.version)
+ _loader_text_end = ABSOLUTE(.);
+ } > iram_loader_seg
+
+ .iram.text :
+ {
+ . = ALIGN (16);
+ *(.entry.text)
+ *(.init.literal)
+ *(.init)
+ } > iram_seg
+
+
+ /* Shared RAM */
+ .dram0.bss (NOLOAD) :
+ {
+ . = ALIGN (8);
+ _dram_start = ABSOLUTE(.);
+ _bss_start = ABSOLUTE(.);
+ *(.dynsbss)
+ *(.sbss)
+ *(.sbss.*)
+ *(.gnu.linkonce.sb.*)
+ *(.scommon)
+ *(.sbss2)
+ *(.sbss2.*)
+ *(.gnu.linkonce.sb2.*)
+ *(.dynbss)
+ *(.bss)
+ *(.bss.*)
+ *(.gnu.linkonce.b.*)
+ *(COMMON)
+ . = ALIGN (8);
+ _bss_end = ABSOLUTE(.);
+ } >dram_seg
+
+ .dram0.data :
+ {
+ _data_start = ABSOLUTE(.);
+ *(.data)
+ *(.data.*)
+ *(.gnu.linkonce.d.*)
+ *(.data1)
+ *(.sdata)
+ *(.sdata.*)
+ *(.gnu.linkonce.s.*)
+ *(.sdata2)
+ *(.sdata2.*)
+ *(.gnu.linkonce.s2.*)
+ *(.jcr)
+ _data_end = ABSOLUTE(.);
+ } >dram_seg
+
+ .dram0.rodata :
+ {
+ _rodata_start = ABSOLUTE(.);
+ *(.rodata)
+ *(.rodata.*)
+ *(.gnu.linkonce.r.*)
+ *(.rodata1)
+ __XT_EXCEPTION_TABLE_ = ABSOLUTE(.);
+ *(.xt_except_table)
+ *(.gcc_except_table)
+ *(.gnu.linkonce.e.*)
+ *(.gnu.version_r)
+ *(.eh_frame)
+ . = (. + 3) & ~ 3;
+ /* C++ constructor and destructor tables, properly ordered: */
+ __init_array_start = ABSOLUTE(.);
+ KEEP (*crtbegin.*(.ctors))
+ KEEP (*(EXCLUDE_FILE (*crtend.*) .ctors))
+ KEEP (*(SORT(.ctors.*)))
+ KEEP (*(.ctors))
+ __init_array_end = ABSOLUTE(.);
+ KEEP (*crtbegin.*(.dtors))
+ KEEP (*(EXCLUDE_FILE (*crtend.*) .dtors))
+ KEEP (*(SORT(.dtors.*)))
+ KEEP (*(.dtors))
+ /* C++ exception handlers table: */
+ __XT_EXCEPTION_DESCS_ = ABSOLUTE(.);
+ *(.xt_except_desc)
+ *(.gnu.linkonce.h.*)
+ __XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.);
+ *(.xt_except_desc_end)
+ *(.dynamic)
+ *(.gnu.version_d)
+ _rodata_end = ABSOLUTE(.);
+ /* Literals are also RO data. */
+ _lit4_start = ABSOLUTE(.);
+ *(*.lit4)
+ *(.lit4.*)
+ *(.gnu.linkonce.lit4.*)
+ _lit4_end = ABSOLUTE(.);
+ . = ALIGN(4);
+ _dram_end = ABSOLUTE(.);
+ } >dram_seg
+
+ .iram.text :
+ {
+ _stext = .;
+ _text_start = ABSOLUTE(.);
+ *(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
+ *(.iram .iram.*) /* catch stray IRAM_ATTR */
+ *(.fini.literal)
+ *(.fini)
+ *(.gnu.version)
+ _text_end = ABSOLUTE(.);
+ _etext = .;
+ } > iram_seg
+
+}
diff --git a/boot/espressif/port/esp32s3/ld/bootloader.ld b/boot/espressif/port/esp32s3/ld/bootloader.ld
new file mode 100644
index 0000000..0bc9af6
--- /dev/null
+++ b/boot/espressif/port/esp32s3/ld/bootloader.ld
@@ -0,0 +1,172 @@
+/*
+ * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+/* Simplified memory map for the bootloader.
+ *
+ * The main purpose is to make sure the bootloader can load into main memory
+ * without overwriting itself.
+ */
+
+MEMORY
+{
+ iram_seg (RWX) : org = 0x403B2500, len = 0x7B00
+ iram_loader_seg (RWX) : org = 0x403BA000, len = 0x6000
+ dram_seg (RW) : org = 0x3FCD8000, len = 0x9A00
+}
+
+/* Default entry point: */
+ENTRY(main);
+
+SECTIONS
+{
+ .iram_loader.text :
+ {
+ . = ALIGN (16);
+ _loader_text_start = ABSOLUTE(.);
+ *(.stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
+ *(.iram1 .iram1.*) /* catch stray IRAM_ATTR */
+ *libhal.a:bootloader_flash.*(.literal .text .literal.* .text.*)
+ *libhal.a:bootloader_flash_config_esp32s3.*(.literal .text .literal.* .text.*)
+ *libhal.a:bootloader_clock_loader.*(.literal .text .literal.* .text.*)
+ *libhal.a:bootloader_common_loader.*(.literal .text .literal.* .text.*)
+ *libhal.a:bootloader_flash.*(.literal .text .literal.* .text.*)
+ *libhal.a:bootloader_random.*(.literal .text .literal.* .text.*)
+ *libhal.a:bootloader_random*.*(.literal.bootloader_random_disable .text.bootloader_random_disable)
+ *libhal.a:bootloader_random*.*(.literal.bootloader_random_enable .text.bootloader_random_enable)
+ *libhal.a:bootloader_efuse_esp32s3.*(.literal .text .literal.* .text.*)
+ *libhal.a:bootloader_utility.*(.literal .text .literal.* .text.*)
+ *libhal.a:bootloader_sha.*(.literal .text .literal.* .text.*)
+ *libhal.a:bootloader_console_loader.*(.literal .text .literal.* .text.*)
+ *libhal.a:bootloader_panic.*(.literal .text .literal.* .text.*)
+ *libhal.a:bootloader_soc.*(.literal .text .literal.* .text.*)
+ *libhal.a:esp_image_format.*(.literal .text .literal.* .text.*)
+ *libhal.a:flash_encrypt.*(.literal .text .literal.* .text.*)
+ *libhal.a:flash_encryption_secure_features.*(.literal .text .literal.* .text.*)
+ *libhal.a:flash_partitions.*(.literal .text .literal.* .text.*)
+ *libhal.a:secure_boot.*(.literal .text .literal.* .text.*)
+ *libhal.a:secure_boot_secure_features.*(.literal .text .literal.* .text.*)
+ *libhal.a:secure_boot_signatures_bootloader.*(.literal .text .literal.* .text.*)
+ *libhal.a:wdt_hal_iram.*(.literal .text .literal.* .text.*)
+ *libhal.a:esp_efuse_table.*(.literal .text .literal.* .text.*)
+ *libhal.a:esp_efuse_fields.*(.literal .text .literal.* .text.*)
+ *libhal.a:esp_efuse_api.*(.literal .text .literal.* .text.*)
+ *libhal.a:esp_efuse_utility.*(.literal .text .literal.* .text.*)
+ *libhal.a:esp_efuse_api_key_esp32xx.*(.literal .text .literal.* .text.*)
+ *esp_mcuboot.*(.literal .text .literal.* .text.*)
+ *esp_loader.*(.literal .text .literal.* .text.*)
+ *(.fini.literal)
+ *(.fini)
+ *(.gnu.version)
+ _loader_text_end = ABSOLUTE(.);
+ } > iram_loader_seg
+
+ .iram.text :
+ {
+ . = ALIGN (16);
+ *(.entry.text)
+ *(.init.literal)
+ *(.init)
+ } > iram_seg
+
+
+ /* Shared RAM */
+ .dram0.bss (NOLOAD) :
+ {
+ . = ALIGN (8);
+ _dram_start = ABSOLUTE(.);
+ _bss_start = ABSOLUTE(.);
+ *(.dynsbss)
+ *(.sbss)
+ *(.sbss.*)
+ *(.gnu.linkonce.sb.*)
+ *(.scommon)
+ *(.sbss2)
+ *(.sbss2.*)
+ *(.gnu.linkonce.sb2.*)
+ *(.dynbss)
+ *(.bss)
+ *(.bss.*)
+ *(.gnu.linkonce.b.*)
+ *(COMMON)
+ . = ALIGN (8);
+ _bss_end = ABSOLUTE(.);
+ } >dram_seg
+
+ .dram0.data :
+ {
+ _data_start = ABSOLUTE(.);
+ *(.data)
+ *(.data.*)
+ *(.gnu.linkonce.d.*)
+ *(.data1)
+ *(.sdata)
+ *(.sdata.*)
+ *(.gnu.linkonce.s.*)
+ *(.sdata2)
+ *(.sdata2.*)
+ *(.gnu.linkonce.s2.*)
+ *(.jcr)
+ _data_end = ABSOLUTE(.);
+ } >dram_seg
+
+ .dram0.rodata :
+ {
+ _rodata_start = ABSOLUTE(.);
+ *(.rodata)
+ *(.rodata.*)
+ *(.gnu.linkonce.r.*)
+ *(.rodata1)
+ __XT_EXCEPTION_TABLE_ = ABSOLUTE(.);
+ *(.xt_except_table)
+ *(.gcc_except_table)
+ *(.gnu.linkonce.e.*)
+ *(.gnu.version_r)
+ *(.eh_frame)
+ . = (. + 3) & ~ 3;
+ /* C++ constructor and destructor tables, properly ordered: */
+ __init_array_start = ABSOLUTE(.);
+ KEEP (*crtbegin.*(.ctors))
+ KEEP (*(EXCLUDE_FILE (*crtend.*) .ctors))
+ KEEP (*(SORT(.ctors.*)))
+ KEEP (*(.ctors))
+ __init_array_end = ABSOLUTE(.);
+ KEEP (*crtbegin.*(.dtors))
+ KEEP (*(EXCLUDE_FILE (*crtend.*) .dtors))
+ KEEP (*(SORT(.dtors.*)))
+ KEEP (*(.dtors))
+ /* C++ exception handlers table: */
+ __XT_EXCEPTION_DESCS_ = ABSOLUTE(.);
+ *(.xt_except_desc)
+ *(.gnu.linkonce.h.*)
+ __XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.);
+ *(.xt_except_desc_end)
+ *(.dynamic)
+ *(.gnu.version_d)
+ _rodata_end = ABSOLUTE(.);
+ /* Literals are also RO data. */
+ _lit4_start = ABSOLUTE(.);
+ *(*.lit4)
+ *(.lit4.*)
+ *(.gnu.linkonce.lit4.*)
+ _lit4_end = ABSOLUTE(.);
+ . = ALIGN(4);
+ _dram_end = ABSOLUTE(.);
+ } >dram_seg
+
+ .iram.text :
+ {
+ _stext = .;
+ _text_start = ABSOLUTE(.);
+ *(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
+ *(.iram .iram.*) /* catch stray IRAM_ATTR */
+ *(.fini.literal)
+ *(.fini)
+ *(.gnu.version)
+ _text_end = ABSOLUTE(.);
+ _etext = .;
+ } > iram_seg
+
+}
diff --git a/boot/espressif/port/esp_loader.c b/boot/espressif/port/esp_loader.c
new file mode 100644
index 0000000..1d3e55f
--- /dev/null
+++ b/boot/espressif/port/esp_loader.c
@@ -0,0 +1,91 @@
+/*
+ * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#include <string.h>
+
+#include <bootutil/bootutil_log.h>
+#include <bootutil/fault_injection_hardening.h>
+
+#include "bootloader_flash_priv.h"
+#include "esp_flash_encrypt.h"
+#include "soc/soc_memory_layout.h"
+
+#if CONFIG_IDF_TARGET_ESP32
+#include "esp32/rom/uart.h"
+#elif CONFIG_IDF_TARGET_ESP32S2
+#include "esp32s2/rom/uart.h"
+#elif CONFIG_IDF_TARGET_ESP32S3
+#include "esp32s3/rom/uart.h"
+#elif CONFIG_IDF_TARGET_ESP32C3
+#include "esp32c3/rom/uart.h"
+#endif
+
+#include "esp_mcuboot_image.h"
+#include "esp_loader.h"
+#include "flash_map_backend/flash_map_backend.h"
+
+
+static int load_segment(const struct flash_area *fap, uint32_t data_addr, uint32_t data_len, uint32_t load_addr)
+{
+ const uint32_t *data = (const uint32_t *)bootloader_mmap((fap->fa_off + data_addr), data_len);
+ if (!data) {
+ BOOT_LOG_ERR("%s: Bootloader mmap failed", __func__);
+ return -1;
+ }
+ memcpy((void *)load_addr, data, data_len);
+ bootloader_munmap(data);
+ return 0;
+}
+
+void esp_app_image_load(int slot, unsigned int hdr_offset)
+{
+ const struct flash_area *fap;
+ int area_id;
+ int rc;
+
+ area_id = flash_area_id_from_image_slot(slot);
+ rc = flash_area_open(area_id, &fap);
+ if (rc != 0) {
+ BOOT_LOG_ERR("%s: flash_area_open failed with %d", __func__, rc);
+ }
+
+ const uint32_t *data = (const uint32_t *)bootloader_mmap((fap->fa_off + hdr_offset), sizeof(esp_image_load_header_t));
+ esp_image_load_header_t load_header = {0};
+ memcpy((void *)&load_header, data, sizeof(esp_image_load_header_t));
+ bootloader_munmap(data);
+
+ if (load_header.header_magic != ESP_LOAD_HEADER_MAGIC) {
+ BOOT_LOG_ERR("Load header magic verification failed. Aborting");
+ FIH_PANIC;
+ }
+
+ if (!esp_ptr_in_iram((void *)load_header.iram_dest_addr) || !esp_ptr_in_iram((void *)(load_header.iram_dest_addr + load_header.iram_size))) {
+ BOOT_LOG_ERR("IRAM region in load header is not valid. Aborting");
+ FIH_PANIC;
+ }
+
+ if (!esp_ptr_in_dram((void *)load_header.dram_dest_addr) || !esp_ptr_in_dram((void *)load_header.dram_dest_addr + load_header.dram_size)) {
+ BOOT_LOG_ERR("DRAM region in load header is not valid. Aborting");
+ FIH_PANIC;
+ }
+
+ if (!esp_ptr_in_iram((void *)load_header.entry_addr)) {
+ BOOT_LOG_ERR("Application entry point (0x%x) is not in IRAM. Aborting", load_header.entry_addr);
+ FIH_PANIC;
+ }
+
+ BOOT_LOG_INF("DRAM segment: start=0x%x, size=0x%x, vaddr=0x%x", load_header.dram_flash_offset, load_header.dram_size, load_header.dram_dest_addr);
+ load_segment(fap, load_header.dram_flash_offset, load_header.dram_size, load_header.dram_dest_addr);
+
+ BOOT_LOG_INF("IRAM segment: start=0x%x, size=0x%x, vaddr=0x%x", load_header.iram_flash_offset, load_header.iram_size, load_header.iram_dest_addr);
+ load_segment(fap, load_header.iram_flash_offset, load_header.iram_size, load_header.iram_dest_addr);
+
+ BOOT_LOG_INF("start=0x%x", load_header.entry_addr);
+ uart_tx_wait_idle(0);
+ void *start = (void *) load_header.entry_addr;
+ ((void (*)(void))start)(); /* Call to application entry address should not return */
+ FIH_PANIC;
+}
diff --git a/boot/espressif/port/esp_mcuboot.c b/boot/espressif/port/esp_mcuboot.c
new file mode 100644
index 0000000..5cda2ae
--- /dev/null
+++ b/boot/espressif/port/esp_mcuboot.c
@@ -0,0 +1,316 @@
+/*
+ * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#include <stdbool.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <bootutil/bootutil.h>
+#include <bootutil/bootutil_log.h>
+
+#include "sdkconfig.h"
+#include "esp_err.h"
+#include "bootloader_flash_priv.h"
+#include "esp_flash_encrypt.h"
+
+#include "flash_map_backend/flash_map_backend.h"
+#include "sysflash/sysflash.h"
+
+#ifndef ARRAY_SIZE
+# define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+#endif
+
+#ifndef MIN
+# define MIN(a, b) (((a) < (b)) ? (a) : (b))
+#endif
+
+#ifndef ALIGN_UP
+# define ALIGN_UP(num, align) (((num) + ((align) - 1)) & ~((align) - 1))
+#endif
+
+#ifndef ALIGN_DOWN
+# define ALIGN_DOWN(num, align) ((num) & ~((align) - 1))
+#endif
+
+#ifndef ALIGN_OFFSET
+# define ALIGN_OFFSET(num, align) ((num) & ((align) - 1))
+#endif
+
+#ifndef IS_ALIGNED
+# define IS_ALIGNED(num, align) (ALIGN_OFFSET((num), (align)) == 0)
+#endif
+
+#define FLASH_BUFFER_SIZE 256 /* SPI Flash block size */
+
+_Static_assert(IS_ALIGNED(FLASH_BUFFER_SIZE, 4), "Buffer size for SPI Flash operations must be 4-byte aligned.");
+
+#define BOOTLOADER_START_ADDRESS CONFIG_BOOTLOADER_OFFSET_IN_FLASH
+#define BOOTLOADER_SIZE CONFIG_ESP_BOOTLOADER_SIZE
+#define APPLICATION_PRIMARY_START_ADDRESS CONFIG_ESP_APPLICATION_PRIMARY_START_ADDRESS
+#define APPLICATION_SECONDARY_START_ADDRESS CONFIG_ESP_APPLICATION_SECONDARY_START_ADDRESS
+#define APPLICATION_SIZE CONFIG_ESP_APPLICATION_SIZE
+#define SCRATCH_OFFSET CONFIG_ESP_SCRATCH_OFFSET
+#define SCRATCH_SIZE CONFIG_ESP_SCRATCH_SIZE
+
+extern int ets_printf(const char *fmt, ...);
+
+static const struct flash_area bootloader = {
+ .fa_id = FLASH_AREA_BOOTLOADER,
+ .fa_device_id = FLASH_DEVICE_INTERNAL_FLASH,
+ .fa_off = BOOTLOADER_START_ADDRESS,
+ .fa_size = BOOTLOADER_SIZE,
+};
+
+static const struct flash_area primary_img0 = {
+ .fa_id = FLASH_AREA_IMAGE_PRIMARY(0),
+ .fa_device_id = FLASH_DEVICE_INTERNAL_FLASH,
+ .fa_off = APPLICATION_PRIMARY_START_ADDRESS,
+ .fa_size = APPLICATION_SIZE,
+};
+
+static const struct flash_area secondary_img0 = {
+ .fa_id = FLASH_AREA_IMAGE_SECONDARY(0),
+ .fa_device_id = FLASH_DEVICE_INTERNAL_FLASH,
+ .fa_off = APPLICATION_SECONDARY_START_ADDRESS,
+ .fa_size = APPLICATION_SIZE,
+};
+
+static const struct flash_area scratch_img0 = {
+ .fa_id = FLASH_AREA_IMAGE_SCRATCH,
+ .fa_device_id = FLASH_DEVICE_INTERNAL_FLASH,
+ .fa_off = SCRATCH_OFFSET,
+ .fa_size = SCRATCH_SIZE,
+};
+
+static const struct flash_area *s_flash_areas[] = {
+ &bootloader,
+ &primary_img0,
+ &secondary_img0,
+ &scratch_img0,
+};
+
+static const struct flash_area *prv_lookup_flash_area(uint8_t id) {
+ for (size_t i = 0; i < ARRAY_SIZE(s_flash_areas); i++) {
+ const struct flash_area *area = s_flash_areas[i];
+ if (id == area->fa_id) {
+ return area;
+ }
+ }
+ return NULL;
+}
+
+int flash_area_open(uint8_t id, const struct flash_area **area_outp)
+{
+ BOOT_LOG_DBG("%s: ID=%d", __func__, (int)id);
+ const struct flash_area *area = prv_lookup_flash_area(id);
+ *area_outp = area;
+ return area != NULL ? 0 : -1;
+}
+
+void flash_area_close(const struct flash_area *area)
+{
+
+}
+
+static bool aligned_flash_read(uintptr_t addr, void *dest, size_t size)
+{
+ if (IS_ALIGNED(addr, 4) && IS_ALIGNED((uintptr_t)dest, 4) && IS_ALIGNED(size, 4)) {
+ /* A single read operation is enough when when all parameters are aligned */
+
+ return bootloader_flash_read(addr, dest, size, true) == ESP_OK;
+ }
+
+ const uint32_t aligned_addr = ALIGN_DOWN(addr, 4);
+ const uint32_t addr_offset = ALIGN_OFFSET(addr, 4);
+ uint32_t bytes_remaining = size;
+ uint8_t read_data[FLASH_BUFFER_SIZE] = {0};
+
+ /* Align the read address to 4-byte boundary and ensure read size is a multiple of 4 bytes */
+
+ uint32_t bytes = MIN(bytes_remaining + addr_offset, sizeof(read_data));
+ if (bootloader_flash_read(aligned_addr, read_data, ALIGN_UP(bytes, 4), true) != ESP_OK) {
+ return false;
+ }
+
+ /* Skip non-useful data which may have been read for adjusting the alignment */
+
+ uint32_t bytes_read = bytes - addr_offset;
+ memcpy(dest, &read_data[addr_offset], bytes_read);
+
+ bytes_remaining -= bytes_read;
+
+ /* Read remaining data from Flash in case requested size is greater than buffer size */
+
+ uint32_t offset = bytes;
+
+ while (bytes_remaining != 0) {
+ bytes = MIN(bytes_remaining, sizeof(read_data));
+ if (bootloader_flash_read(aligned_addr + offset, read_data, ALIGN_UP(bytes, 4), true) != ESP_OK) {
+ return false;
+ }
+
+ memcpy(&((uint8_t *)dest)[bytes_read], read_data, bytes);
+
+ offset += bytes;
+ bytes_read += bytes;
+ bytes_remaining -= bytes;
+ }
+
+ return true;
+}
+
+int flash_area_read(const struct flash_area *fa, uint32_t off, void *dst,
+ uint32_t len)
+{
+ if (fa->fa_device_id != FLASH_DEVICE_INTERNAL_FLASH) {
+ return -1;
+ }
+
+ const uint32_t end_offset = off + len;
+ if (end_offset > fa->fa_size) {
+ BOOT_LOG_ERR("%s: Out of Bounds (0x%x vs 0x%x)", __func__, end_offset, fa->fa_size);
+ return -1;
+ }
+
+ bool success = aligned_flash_read(fa->fa_off + off, dst, len);
+ if (!success) {
+ BOOT_LOG_ERR("%s: Flash read failed", __func__);
+
+ return -1;
+ }
+
+ return 0;
+}
+
+int flash_area_write(const struct flash_area *fa, uint32_t off, const void *src,
+ uint32_t len)
+{
+ if (fa->fa_device_id != FLASH_DEVICE_INTERNAL_FLASH) {
+ return -1;
+ }
+
+ const uint32_t end_offset = off + len;
+ if (end_offset > fa->fa_size) {
+ BOOT_LOG_ERR("%s: Out of Bounds (0x%x vs 0x%x)", __func__, end_offset, fa->fa_size);
+ return -1;
+ }
+
+ bool flash_encryption_enabled = esp_flash_encryption_enabled();
+
+ const uint32_t start_addr = fa->fa_off + off;
+ BOOT_LOG_DBG("%s: Addr: 0x%08x Length: %d", __func__, (int)start_addr, (int)len);
+
+ if (bootloader_flash_write(start_addr, (void *)src, len, flash_encryption_enabled) != ESP_OK) {
+ BOOT_LOG_ERR("%s: Flash write failed", __func__);
+ return -1;
+ }
+
+ return 0;
+}
+
+int flash_area_erase(const struct flash_area *fa, uint32_t off, uint32_t len)
+{
+ if (fa->fa_device_id != FLASH_DEVICE_INTERNAL_FLASH) {
+ return -1;
+ }
+
+ if ((len % FLASH_SECTOR_SIZE) != 0 || (off % FLASH_SECTOR_SIZE) != 0) {
+ BOOT_LOG_ERR("%s: Not aligned on sector Offset: 0x%x Length: 0x%x",
+ __func__, (int)off, (int)len);
+ return -1;
+ }
+
+ const uint32_t start_addr = fa->fa_off + off;
+ BOOT_LOG_DBG("%s: Addr: 0x%08x Length: %d", __func__, (int)start_addr, (int)len);
+
+ if (bootloader_flash_erase_range(start_addr, len) != ESP_OK) {
+ BOOT_LOG_ERR("%s: Flash erase failed", __func__);
+ return -1;
+ }
+#if VALIDATE_PROGRAM_OP
+ for (size_t i = 0; i < len; i++) {
+ uint8_t *val = (void *)(start_addr + i);
+ if (*val != 0xff) {
+ BOOT_LOG_ERR("%s: Erase at 0x%x Failed", __func__, (int)val);
+ assert(0);
+ }
+ }
+#endif
+
+ return 0;
+}
+
+uint32_t flash_area_align(const struct flash_area *area)
+{
+ static size_t align = 0;
+
+ if (align == 0) {
+ bool flash_encryption_enabled = esp_flash_encryption_enabled();
+
+ if (flash_encryption_enabled) {
+ align = 32;
+ } else {
+ align = 4;
+ }
+ }
+ return align;
+}
+
+uint8_t flash_area_erased_val(const struct flash_area *area)
+{
+ return 0xff;
+}
+
+int flash_area_get_sectors(int fa_id, uint32_t *count,
+ struct flash_sector *sectors)
+{
+ const struct flash_area *fa = prv_lookup_flash_area(fa_id);
+ if (fa->fa_device_id != FLASH_DEVICE_INTERNAL_FLASH) {
+ return -1;
+ }
+
+ const size_t sector_size = FLASH_SECTOR_SIZE;
+ uint32_t total_count = 0;
+ for (size_t off = 0; off < fa->fa_size; off += sector_size) {
+ // Note: Offset here is relative to flash area, not device
+ sectors[total_count].fs_off = off;
+ sectors[total_count].fs_size = sector_size;
+ total_count++;
+ }
+
+ *count = total_count;
+ return 0;
+}
+
+int flash_area_id_from_multi_image_slot(int image_index, int slot)
+{
+ BOOT_LOG_DBG("%s", __func__);
+ switch (slot) {
+ case 0:
+ return FLASH_AREA_IMAGE_PRIMARY(image_index);
+ case 1:
+ return FLASH_AREA_IMAGE_SECONDARY(image_index);
+ }
+
+ BOOT_LOG_ERR("Unexpected Request: image_index=%d, slot=%d", image_index, slot);
+ return -1; /* flash_area_open will fail on that */
+}
+
+int flash_area_id_from_image_slot(int slot)
+{
+ return flash_area_id_from_multi_image_slot(0, slot);
+}
+
+int flash_area_to_sectors(int idx, int *cnt, struct flash_area *fa)
+{
+ return -1;
+}
+
+void mcuboot_assert_handler(const char *file, int line, const char *func)
+{
+ ets_printf("assertion failed: file \"%s\", line %d, func: %s\n", file, line, func);
+ abort();
+}