From 5b91a8173ec23dd8704262609bb6ec01b9a5704a 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 eb5c94726e..7e8de91526 100644 --- a/components/bootloader/subproject/main/esp32.bootloader.ld +++ b/components/bootloader/subproject/main/esp32.bootloader.ld @@ -164,6 +164,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 6b10c86948..8805b0302b 100644 --- a/components/esp32/ld/esp32.project.ld.in +++ b/components/esp32/ld/esp32.project.ld.in @@ -320,6 +320,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 = .;