From 4463db7e7fc921ac7ec5b8bb74d56d15782f741c 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 --- components/bootloader/subproject/main/esp32.bootloader.ld | 8 ++++++++ components/esp32/ld/esp32.project.ld.in | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/components/bootloader/subproject/main/esp32.bootloader.ld b/components/bootloader/subproject/main/esp32.bootloader.ld index 3dca756097..ac0837d1c9 100644 --- a/components/bootloader/subproject/main/esp32.bootloader.ld +++ b/components/bootloader/subproject/main/esp32.bootloader.ld @@ -162,6 +162,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 2618b7dc48..93c724db21 100644 --- a/components/esp32/ld/esp32.project.ld.in +++ b/components/esp32/ld/esp32.project.ld.in @@ -327,6 +327,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 = .;