change(bootloader): rename bootloader.ld -> bootloader.ld.in

This change passes file through compiler preprocessor which unlocks
future code refactoring.
This commit is contained in:
Alexey Lapshin
2025-09-18 12:48:50 +07:00
committed by BOT
parent c6e65586e3
commit d9389ba082
21 changed files with 169 additions and 67 deletions

View File

@@ -69,9 +69,9 @@ set(LD_DEFAULT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/main/ld/${IDF_TARGET}")
idf_build_set_property(BOOTLOADER_LINKER_SCRIPT "${LD_DEFAULT_PATH}/bootloader.rom.ld" APPEND)
project(bootloader)
if(CONFIG_ESP32P4_REV_MIN_300)
target_linker_script("__idf_main" INTERFACE "${LD_DEFAULT_PATH}/bootloader.rev3.ld")
target_linker_script("__idf_main" INTERFACE "${LD_DEFAULT_PATH}/bootloader.rev3.ld.in")
else()
target_linker_script("__idf_main" INTERFACE "${LD_DEFAULT_PATH}/bootloader.ld")
target_linker_script("__idf_main" INTERFACE "${LD_DEFAULT_PATH}/bootloader.ld.in")
endif()
idf_build_set_property(COMPILE_DEFINITIONS "BOOTLOADER_BUILD=1" APPEND)

View File

@@ -3,6 +3,9 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "sdkconfig.h"
/*
Linker file used to link the bootloader.
*/

View File

@@ -3,6 +3,9 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "sdkconfig.h"
/** Simplified memory map for the bootloader.
* Make sure the bootloader can load into main memory without overwriting itself.
*

View File

@@ -3,6 +3,9 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "sdkconfig.h"
/** Simplified memory map for the bootloader.
* Make sure the bootloader can load into main memory without overwriting itself.
*

View File

@@ -3,6 +3,9 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "sdkconfig.h"
/** Simplified memory map for the bootloader.
* Make sure the bootloader can load into main memory without overwriting itself.
*

View File

@@ -3,6 +3,9 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "sdkconfig.h"
/** Simplified memory map for the bootloader.
* Make sure the bootloader can load into main memory without overwriting itself.
*

View File

@@ -3,6 +3,9 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "sdkconfig.h"
/** Simplified memory map for the bootloader.
* Make sure the bootloader can load into main memory without overwriting itself.
*

View File

@@ -3,6 +3,9 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "sdkconfig.h"
/** Simplified memory map for the bootloader.
* Make sure the bootloader can load into main memory without overwriting itself.
*

View File

@@ -3,6 +3,9 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "sdkconfig.h"
/** Simplified memory map for the bootloader.
* Make sure the bootloader can load into main memory without overwriting itself.
*

View File

@@ -3,6 +3,9 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "sdkconfig.h"
/** Simplified memory map for the bootloader.
* Make sure the bootloader can load into main memory without overwriting itself.
*

View File

@@ -3,6 +3,9 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "sdkconfig.h"
/**
* Simplified memory map for the bootloader.
* Make sure the bootloader can load into main memory without overwriting itself.

View File

@@ -3,6 +3,9 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "sdkconfig.h"
/**
* Simplified memory map for the bootloader.
* Make sure the bootloader can load into main memory without overwriting itself.

View File

@@ -3,6 +3,9 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "sdkconfig.h"
/* Simplified memory map for the bootloader.
* Make sure the bootloader can load into main memory without overwriting itself.
*/

View File

@@ -3,6 +3,9 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "sdkconfig.h"
/** Simplified memory map for the bootloader.
* Make sure the bootloader can load into main memory without overwriting itself.
*

View File

@@ -14,7 +14,7 @@ extern "C" {
/**@{*/
/**
* @brief labels from bootloader linker script: bootloader.ld
* @brief labels from bootloader linker script: bootloader.ld.in
*
*/
extern int _bss_start;

View File

@@ -99,7 +99,15 @@ else()
PROPERTIES COMPILE_FLAGS
-fno-stack-protector)
include(${CMAKE_CURRENT_LIST_DIR}/ld/ld.cmake)
target_linker_script(${COMPONENT_LIB} INTERFACE "ld/${target}/memory.ld.in")
# Generate sections.ld.in and pass it through linker script generator
set(sections_name "ld/${target}/sections.ld.in")
if(CONFIG_ESP32P4_REV_MIN_300)
set(sections_name "ld/${target}/sections.rev3.ld.in")
endif()
target_linker_script(${COMPONENT_LIB} INTERFACE "${sections_name}"
PROCESS "${CMAKE_CURRENT_BINARY_DIR}/ld/sections.ld")
endif()
if(CONFIG_IDF_ENV_FPGA OR CONFIG_ESP_BRINGUP_BYPASS_CPU_CLK_SETTING)

View File

@@ -28,7 +28,7 @@
#define SRAM_IRAM_START 0x40370000
#define SRAM_DIRAM_I_START 0x40378000
#define SRAM_IRAM_END 0x403CB700 /* Please refer to ESP32-S3 bootloader.ld for more information on this */
#define SRAM_IRAM_END 0x403CB700 /* Please refer to ESP32-S3 bootloader linker script for more information on this */
#define I_D_SRAM_OFFSET (SRAM_DIRAM_I_START - SRAM_DRAM_START)
#define SRAM_DRAM_START 0x3FC88000

View File

@@ -1,57 +0,0 @@
idf_build_get_property(target IDF_TARGET)
idf_build_get_property(sdkconfig_header SDKCONFIG_HEADER)
idf_build_get_property(config_dir CONFIG_DIR)
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/ld")
# Cmake script that generates linker script from "*.ld.in" scripts using compiler preprocessor
set(linker_script_generator "${CMAKE_CURRENT_BINARY_DIR}/ld/linker_script_generator.cmake")
file(WRITE ${linker_script_generator}
[=[
execute_process(COMMAND "${CC}" "-C" "-P" "-x" "c" "-E" "-I" "${CONFIG_DIR}" "-I" "${LD_DIR}" "${SOURCE}"
RESULT_VARIABLE RET_CODE
OUTPUT_VARIABLE PREPROCESSED_LINKER_SCRIPT
ERROR_VARIABLE ERROR_VAR)
if(RET_CODE AND NOT RET_CODE EQUAL 0)
message(FATAL_ERROR "Can't generate ${TARGET}\nRET_CODE: ${RET_CODE}\nERROR_MESSAGE: ${ERROR_VAR}")
endif()
string(REPLACE "\\n" "\n" TEXT "${PREPROCESSED_LINKER_SCRIPT}")
file(WRITE "${TARGET}" "${TEXT}")
]=])
set(target_folder "${target}")
function(preprocess_linker_file name_in name_out out_path)
set(script_in "${CMAKE_CURRENT_LIST_DIR}/${target_folder}/${name_in}")
set(script_out "${CMAKE_CURRENT_BINARY_DIR}/ld/${name_out}")
set(${out_path} ${script_out} PARENT_SCOPE)
add_custom_command(
OUTPUT ${script_out}
COMMAND ${CMAKE_COMMAND}
"-DCC=${CMAKE_C_COMPILER}"
"-DSOURCE=${script_in}"
"-DTARGET=${script_out}"
"-DCONFIG_DIR=${config_dir}"
"-DLD_DIR=${CMAKE_CURRENT_LIST_DIR}"
-P "${linker_script_generator}"
MAIN_DEPENDENCY ${script_in}
DEPENDS ${sdkconfig_header}
COMMENT "Generating ${script_out} linker script..."
VERBATIM)
add_custom_target("${name_out}" DEPENDS "${script_out}")
add_dependencies(${COMPONENT_LIB} "${name_out}")
endfunction()
# Generate memory.ld
preprocess_linker_file("memory.ld.in" "memory.ld" ld_out_path)
target_linker_script(${COMPONENT_LIB} INTERFACE "${ld_out_path}")
# Generate sections.ld.in and pass it through linker script generator
if(CONFIG_ESP32P4_REV_MIN_300)
preprocess_linker_file("sections.rev3.ld.in" "sections.ld.in" ld_out_path)
else()
preprocess_linker_file("sections.ld.in" "sections.ld.in" ld_out_path)
endif()
target_linker_script(${COMPONENT_LIB} INTERFACE "${ld_out_path}"
PROCESS "${CMAKE_CURRENT_BINARY_DIR}/ld/sections.ld")