From 0dfe45249a29d36dce4bf35da7ebd28a7df2c8ee Mon Sep 17 00:00:00 2001 From: Marius Vikhammer Date: Mon, 29 Mar 2021 12:18:25 +0800 Subject: [PATCH] soc: add dummy bytes to ensure instr prefetch always valid The CPU might prefetch instructions, which means it in some cases will try to fetch instruction located after the last instruction in flash.text. Add dummy bytes to ensure fetching these wont result in an error, e.g. MMU exceptions --- .../bootloader/subproject/main/ld/esp32/bootloader.ld | 8 ++++++++ .../subproject/main/ld/esp32s2beta/bootloader.ld | 8 ++++++++ components/esp32/ld/esp32.project.ld.in | 8 ++++++++ components/esp32s2beta/ld/esp32s2beta.project.ld.in | 8 ++++++++ 4 files changed, 32 insertions(+) diff --git a/components/bootloader/subproject/main/ld/esp32/bootloader.ld b/components/bootloader/subproject/main/ld/esp32/bootloader.ld index f4dc192c0b..52aafe3f93 100644 --- a/components/bootloader/subproject/main/ld/esp32/bootloader.ld +++ b/components/bootloader/subproject/main/ld/esp32/bootloader.ld @@ -165,6 +165,14 @@ SECTIONS *(.fini.literal) *(.fini) *(.gnu.version) + + /** CPU will try to prefetch up to 16 bytes of + * of instructions. This means that any configuration (e.g. MMU, PMS) must allow + * safe access to up to 16 bytes after the last real instruction, add + * dummy bytes to ensure this + */ + . += 16; + _text_end = ABSOLUTE(.); _etext = .; } > iram_seg diff --git a/components/bootloader/subproject/main/ld/esp32s2beta/bootloader.ld b/components/bootloader/subproject/main/ld/esp32s2beta/bootloader.ld index ab74c72eff..c3b31ded30 100644 --- a/components/bootloader/subproject/main/ld/esp32s2beta/bootloader.ld +++ b/components/bootloader/subproject/main/ld/esp32s2beta/bootloader.ld @@ -157,6 +157,14 @@ SECTIONS *(.fini.literal) *(.fini) *(.gnu.version) + + /** CPU will try to prefetch up to 16 bytes of + * of instructions. This means that any configuration (e.g. MMU, PMS) must allow + * safe access to up to 16 bytes after the last real instruction, add + * dummy bytes to ensure this + */ + . += 16; + _text_end = ABSOLUTE(.); _etext = .; } > iram_seg diff --git a/components/esp32/ld/esp32.project.ld.in b/components/esp32/ld/esp32.project.ld.in index 4934f86c92..85c22572bb 100644 --- a/components/esp32/ld/esp32.project.ld.in +++ b/components/esp32/ld/esp32.project.ld.in @@ -324,6 +324,14 @@ SECTIONS *(.fini.literal) *(.fini) *(.gnu.version) + + /** CPU will try to prefetch up to 16 bytes of + * of instructions. This means that any configuration (e.g. MMU, PMS) must allow + * safe access to up to 16 bytes after the last real instruction, add + * dummy bytes to ensure this + */ + . += 16; + _text_end = ABSOLUTE(.); _etext = .; diff --git a/components/esp32s2beta/ld/esp32s2beta.project.ld.in b/components/esp32s2beta/ld/esp32s2beta.project.ld.in index a455e2e7d0..c379c85239 100644 --- a/components/esp32s2beta/ld/esp32s2beta.project.ld.in +++ b/components/esp32s2beta/ld/esp32s2beta.project.ld.in @@ -321,6 +321,14 @@ SECTIONS *(.fini.literal) *(.fini) *(.gnu.version) + + /** CPU will try to prefetch up to 16 bytes of + * of instructions. This means that any configuration (e.g. MMU, PMS) must allow + * safe access to up to 16 bytes after the last real instruction, add + * dummy bytes to ensure this + */ + . += 16; + _text_end = ABSOLUTE(.); _etext = .;