esp-idf/tools/ldgen
Alexey Lapshin 824c8e0593 feat(esp_system): allow .bss to spill over into L2MEM above 0x4ff40000
This commit introduce SOC_MEM_NON_CONTIGUOUS_SRAM flag (that enebled for
esp32p4). If SOC_MEM_NON_CONTIGUOUS_SRAM is enabled:

- LDFLAGS+=--enable-non-contiguous-regions
- ldgen.py replaces "arrays[*]" from sections.ld.in with objects under
  SURROUND keyword. (e.g. from linker.lf: data -> dram0_data SURROUND(foo))
- "mapping[*]" - refers to all other data

If SOC_MEM_NON_CONTIGUOUS_SRAM, sections.ld.in file should contain at
least one block of code like this (otherwise it does not make sense):

  .dram0.bss (NOLOAD) :
  {
    arrays[dram0_bss]
    mapping[dram0_bss]
  } > sram_low

  .dram1.bss (NOLOAD) :
  {
    /* do not place here arrays[dram0_bss] because it may be splited
     * between segments */
    mapping[dram0_bss]
  } > sram_high
2024-02-28 19:41:25 +04:00
..
ldgen feat(esp_system): allow .bss to spill over into L2MEM above 0x4ff40000 2024-02-28 19:41:25 +04:00
samples change(esp_hw_support/sleep): rename ESP_SLEEP_DEEP_SLEEP_WAKEUP_DELAY 2023-12-18 19:56:56 +08:00
test feat(esp_system): allow .bss to spill over into L2MEM above 0x4ff40000 2024-02-28 19:41:25 +04:00
README.md ldgen: additional documentations re. internal workings 2021-03-09 14:42:38 +08:00
ldgen.py feat(esp_system): allow .bss to spill over into L2MEM above 0x4ff40000 2024-02-28 19:41:25 +04:00

README.md

Linker Script Generator

Contains code that implements linker script generation, ldgen. For more information about the feature, see docs/en/api-guides/linker-script-generation.rst.

Source Files

The following are the source files in the directory:

  • ldgen.py - Python executable that gets called during build.
  • entity.py - contains classes related to entities (library, object, symbol or combination of the above) with mappable input sections.
  • fragments.py - contains classes for parsing the different types of fragments in linker fragment files.
  • generation.py - contains bulk of the logic used to process fragments into output commands.
  • sdkconfig.py - used for evaluating conditionals in fragment files.
  • linker_script.py - augments the input linker script template with output commands from generation process to produce the output linker script.
  • output_commands.py - contains classes that represent the output commands in the output linker script.
  • ldgen_common.py - contains miscellaneous utilities/definitions that can be used in the files mentioned above.

Tests

Unit tests are in the test directory. These tests are run as part of CI in the job test_ldgen_on_host.

There is also a test app for ldgen in tools/test_apps/build_system/ldgen_test.

Build System

Linker script generation is a part of the build process. The build scripts tools/cmake/ldgen.cmake and make/ldgen.mk contain the build-system-side implementation for CMake and Make, respectively.

Basic Flow

The build system invokes ldgen.py, passing some information from the build.

The linker fragment files are parsed by fragments.py, evaluating conditional expressions with sdkconfig.py.

From the parsed fragments, generation.py generates output commands defined in output_commands.py, with some help from entity.py.

linker_script.py writes the output linker script, replacing markers with output commands generated.

More details about the implementation are in the respective source files.