Merge branch 'feature/esp_system_common_ld_settings' into 'master'

esp_system: create ld template to abstract few common settings

Closes IDF-3624

See merge request espressif/esp-idf!14700
This commit is contained in:
Mahavir Jain 2021-09-03 04:24:16 +00:00
commit bce9d7c0d1
14 changed files with 105 additions and 14 deletions

View File

@ -113,9 +113,15 @@ menu "ESP System Settings"
menu "Memory protection"
config ESP_SYSTEM_MEMPROT_DEPCHECK
bool
default y if IDF_TARGET_ESP32S2
default y if IDF_TARGET_ESP32C3
default y if IDF_TARGET_ESP32H2
config ESP_SYSTEM_MEMPROT_FEATURE
bool "Enable memory protection"
depends on IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32H2
depends on ESP_SYSTEM_MEMPROT_DEPCHECK
default "y"
help
If enabled, the permission control module watches all the memory access and fires the panic handler
@ -133,6 +139,20 @@ menu "ESP System Settings"
Once locked, memory protection settings cannot be changed anymore.
The lock is reset only on the chip startup.
config ESP_SYSTEM_MEMPROT_CPU_PREFETCH_PAD_SIZE
# Hidden option for linker script usage
int
depends on ESP_SYSTEM_MEMPROT_DEPCHECK
default 16
config ESP_SYSTEM_MEMPROT_MEM_ALIGN_SIZE
# Hidden option for linker script usage
int
depends on ESP_SYSTEM_MEMPROT_DEPCHECK
default 4 if IDF_TARGET_ESP32S2
default 256 if IDF_TARGET_ESP32S3
default 512
endmenu # Memory protection
config ESP_SYSTEM_EVENT_QUEUE_SIZE

View File

@ -53,7 +53,7 @@ $(COMPONENT_LIBRARY): $(ld_output)
$(ld_output): $(ld_input) ../include/sdkconfig.h
mkdir -p $(COMPONENT_BUILD_DIR)/ld
$(CC) -I ../include -C -P -x c -E $< -o $@
$(CC) -I ../include -I $(COMPONENT_PATH)/ld -C -P -x c -E $< -o $@
COMPONENT_EXTRA_CLEAN := $(ld_output) $(sections_ld)
endif

View File

@ -20,6 +20,7 @@
to simple macros with numeric values, and/or #if/#endif blocks.
*/
#include "sdkconfig.h"
#include "ld.common"
/* If BT is not built at all */
#ifndef CONFIG_BT_RESERVE_DRAM

View File

@ -349,7 +349,7 @@ SECTIONS
* safe access to up to 16 bytes after the last real instruction, add
* dummy bytes to ensure this
*/
. += 16;
. += _esp_flash_mmap_prefetch_pad_size;
_text_end = ABSOLUTE(.);
_etext = .;

View File

@ -1,3 +1,9 @@
/*
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* ESP32-C3 Linker Script Memory Layout
* This file describes the memory layout (memory blocks) by virtual memory addresses.
@ -7,6 +13,7 @@
*/
#include "sdkconfig.h"
#include "ld.common"
#ifdef CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC
#define ESP_BOOTLOADER_RESERVE_RTC (CONFIG_BOOTLOADER_RESERVE_RTC_SIZE + CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC_SIZE)

View File

@ -1,3 +1,9 @@
/*
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/* Default entry point */
ENTRY(call_start_cpu0);
@ -228,7 +234,7 @@ SECTIONS
* safe access to up to 16 bytes after the last real instruction, add
* dummy bytes to ensure this
*/
. += 16;
. += _esp_flash_mmap_prefetch_pad_size;
_text_end = ABSOLUTE(.);
_instruction_reserved_end = ABSOLUTE(.);
@ -368,9 +374,9 @@ SECTIONS
/* Marks the end of IRAM code segment */
.iram0.text_end (NOLOAD) :
{
/* C3 memprot requires 16B padding for possible CPU prefetch and 512B alignment for PMS split lines */
. += 16;
. = ALIGN (0x200);
/* ESP32-C3 memprot requires 16B padding for possible CPU prefetch and 512B alignment for PMS split lines */
. += _esp_memprot_prefetch_pad_size;
. = ALIGN(_esp_memprot_align_size);
/* iram_end_test section exists for use by memprot unit tests only */
*(.iram_end_test)
_iram_text_end = ABSOLUTE(.);

View File

@ -1,3 +1,9 @@
/*
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* ESP32-H2 Linker Script Memory Layout
* This file describes the memory layout (memory blocks) by virtual memory addresses.
@ -7,6 +13,7 @@
*/
#include "sdkconfig.h"
#include "ld.common"
#ifdef CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC
#define ESP_BOOTLOADER_RESERVE_RTC (CONFIG_BOOTLOADER_RESERVE_RTC_SIZE + CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC_SIZE)

View File

@ -1,3 +1,9 @@
/*
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/* Default entry point */
ENTRY(call_start_cpu0);
@ -365,8 +371,9 @@ SECTIONS
/* Marks the end of IRAM code segment */
.iram0.text_end (NOLOAD) :
{
/* C3 memprot requires 512 B alignment for split lines */
. = ALIGN (0x200);
/* ESP32-H2 memprot requires 16B padding for possible CPU prefetch and 512B alignment for PMS split lines */
. += _esp_memprot_prefetch_pad_size;
. = ALIGN(_esp_memprot_align_size);
/* iram_end_test section exists for use by memprot unit tests only */
*(.iram_end_test)
_iram_text_end = ABSOLUTE(.);

View File

@ -13,6 +13,7 @@
Restrict to simple macros with numeric values, and/or #if/#endif blocks.
*/
#include "sdkconfig.h"
#include "ld.common"
#ifdef CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC
#define ESP_BOOTLOADER_RESERVE_RTC (CONFIG_BOOTLOADER_RESERVE_RTC_SIZE + CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC_SIZE)

View File

@ -1,3 +1,9 @@
/*
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/* Default entry point: */
ENTRY(call_start_cpu0);
@ -177,7 +183,7 @@ SECTIONS
_coredump_iram_end = 0;
/* align + add 16B for CPU dummy speculative instr. fetch */
. = ALIGN(4) + 16;
. = ALIGN(_esp_memprot_align_size) + _esp_memprot_prefetch_pad_size;
/* iram_end_test section exists for use by memprot unit tests only */
*(.iram_end_test)
_iram_text_end = ABSOLUTE(.);
@ -363,7 +369,7 @@ SECTIONS
* safe access to up to 16 bytes after the last real instruction, add
* dummy bytes to ensure this
*/
. += 16;
. += _esp_flash_mmap_prefetch_pad_size;
_text_end = ABSOLUTE(.);
_instruction_reserved_end = ABSOLUTE(.);

View File

@ -12,6 +12,7 @@
*/
#include "sdkconfig.h"
#include "ld.common"
#ifdef CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC
#define ESP_BOOTLOADER_RESERVE_RTC (CONFIG_BOOTLOADER_RESERVE_RTC_SIZE + CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC_SIZE)

View File

@ -1,3 +1,9 @@
/*
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/* Default entry point */
ENTRY(call_start_cpu0);
@ -264,7 +270,7 @@ SECTIONS
* safe access to up to 16 bytes after the last real instruction, add
* dummy bytes to ensure this
*/
. += 16;
. += _esp_flash_mmap_prefetch_pad_size;
_text_end = ABSOLUTE(.);
_instruction_reserved_end = ABSOLUTE(.);
@ -376,7 +382,11 @@ SECTIONS
/* Marks the end of IRAM code segment */
.iram0.text_end (NOLOAD) :
{
. = ALIGN (4);
/* ESP32-S3 memprot requires 16B padding for possible CPU prefetch and 256B alignment for PMS split lines */
. += _esp_memprot_prefetch_pad_size;
. = ALIGN(_esp_memprot_align_size);
/* iram_end_test section exists for use by memprot unit tests only */
*(.iram_end_test)
_iram_text_end = ABSOLUTE(.);
} > iram0_0_seg

View File

@ -22,7 +22,8 @@ idf_build_get_property(config_dir CONFIG_DIR)
# Preprocess memory.ld.in linker script to include configuration, becomes memory.ld
add_custom_command(
OUTPUT ${ld_output}
COMMAND "${CMAKE_C_COMPILER}" -C -P -x c -E -o ${ld_output} -I ${config_dir} ${ld_input}
COMMAND "${CMAKE_C_COMPILER}" -C -P -x c -E -o ${ld_output} -I ${config_dir}
-I "${CMAKE_CURRENT_LIST_DIR}" ${ld_input}
MAIN_DEPENDENCY ${ld_input}
DEPENDS ${sdkconfig_header}
COMMENT "Generating memory.ld linker script..."

View File

@ -0,0 +1,24 @@
/*
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "sdkconfig.h"
/* CPU instruction prefetch padding size for flash mmap scenario */
_esp_flash_mmap_prefetch_pad_size = 16;
/* CPU instruction prefetch padding size for memory protection scenario */
#ifdef CONFIG_ESP_SYSTEM_MEMPROT_CPU_PREFETCH_PAD_SIZE
_esp_memprot_prefetch_pad_size = CONFIG_ESP_SYSTEM_MEMPROT_CPU_PREFETCH_PAD_SIZE;
#else
_esp_memprot_prefetch_pad_size = 0;
#endif
/* Memory alignment size for PMS */
#ifdef CONFIG_ESP_SYSTEM_MEMPROT_MEM_ALIGN_SIZE
_esp_memprot_align_size = CONFIG_ESP_SYSTEM_MEMPROT_MEM_ALIGN_SIZE;
#else
_esp_memprot_align_size = 0;
#endif