From 5036ec363b2382a9831bf17cbbcaa7391c11d8c2 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 ++++++++ .../bootloader/subproject/main/ld/esp32c3/bootloader.ld | 8 ++++++++ .../bootloader/subproject/main/ld/esp32s2/bootloader.ld | 8 ++++++++ .../bootloader/subproject/main/ld/esp32s3/bootloader.ld | 8 ++++++++ components/esp32/ld/esp32.project.ld.in | 8 ++++++++ components/esp32c3/ld/esp32c3.project.ld.in | 8 ++++++++ components/esp32s2/ld/esp32s2.project.ld.in | 8 ++++++++ components/esp32s3/ld/esp32s3.project.ld.in | 8 ++++++++ 8 files changed, 64 insertions(+) diff --git a/components/bootloader/subproject/main/ld/esp32/bootloader.ld b/components/bootloader/subproject/main/ld/esp32/bootloader.ld index 5619d409e8..e78051d7c6 100644 --- a/components/bootloader/subproject/main/ld/esp32/bootloader.ld +++ b/components/bootloader/subproject/main/ld/esp32/bootloader.ld @@ -167,6 +167,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/esp32c3/bootloader.ld b/components/bootloader/subproject/main/ld/esp32c3/bootloader.ld index 38b8be442d..330b376e83 100644 --- a/components/bootloader/subproject/main/ld/esp32c3/bootloader.ld +++ b/components/bootloader/subproject/main/ld/esp32c3/bootloader.ld @@ -156,6 +156,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/esp32s2/bootloader.ld b/components/bootloader/subproject/main/ld/esp32s2/bootloader.ld index 0c23769d82..8c6317be72 100644 --- a/components/bootloader/subproject/main/ld/esp32s2/bootloader.ld +++ b/components/bootloader/subproject/main/ld/esp32s2/bootloader.ld @@ -155,6 +155,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/esp32s3/bootloader.ld b/components/bootloader/subproject/main/ld/esp32s3/bootloader.ld index 2380e4aad2..d5cd564114 100644 --- a/components/bootloader/subproject/main/ld/esp32s3/bootloader.ld +++ b/components/bootloader/subproject/main/ld/esp32s3/bootloader.ld @@ -156,6 +156,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 84ff5fc672..6c5d40b524 100644 --- a/components/esp32/ld/esp32.project.ld.in +++ b/components/esp32/ld/esp32.project.ld.in @@ -347,6 +347,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/esp32c3/ld/esp32c3.project.ld.in b/components/esp32c3/ld/esp32c3.project.ld.in index fdf6be2881..00436e04f4 100644 --- a/components/esp32c3/ld/esp32c3.project.ld.in +++ b/components/esp32c3/ld/esp32c3.project.ld.in @@ -263,6 +263,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(.); _instruction_reserved_end = ABSOLUTE(.); _etext = .; diff --git a/components/esp32s2/ld/esp32s2.project.ld.in b/components/esp32s2/ld/esp32s2.project.ld.in index c60d29b665..1679241891 100644 --- a/components/esp32s2/ld/esp32s2.project.ld.in +++ b/components/esp32s2/ld/esp32s2.project.ld.in @@ -341,6 +341,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(.); _instruction_reserved_end = ABSOLUTE(.); _etext = .; diff --git a/components/esp32s3/ld/esp32s3.project.ld.in b/components/esp32s3/ld/esp32s3.project.ld.in index b1d19cae40..ff46c4d269 100644 --- a/components/esp32s3/ld/esp32s3.project.ld.in +++ b/components/esp32s3/ld/esp32s3.project.ld.in @@ -294,6 +294,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(.); _instruction_reserved_end = ABSOLUTE(.); _etext = .;