Commit Graph

9 Commits

Author SHA1 Message Date
Sudeep Mohanty
9c778c954c feat(build): support KASAN in the build system v2 (cmakev2)
Mirror Kernel Address Sanitizer support into cmakev2 so that
CONFIG_COMPILER_KASAN instruments application code the same way build system v1
does.
2026-08-03 17:31:17 +02:00
Ivan Grokhotkov (bot)
493a770d40 feat(build): support LTO in the build system v2 (cmakev2)
Mirror the link-time optimization support into the cmakev2 build system so
that both build systems behave identically.

- project.cmake (__init_project_configuration): emit -flto=auto as a link
  option when CONFIG_COMPILER_LTO_LINKTIME is set, except for bootloader and
  ESP-TEE builds, otherwise keep -fno-lto.

- build.cmake (idf_build_library): when CONFIG_COMPILER_LTO_COMPILETIME is set,
  compile each linked component with -flto=auto unless it has linker fragments,
  is placed by another component's fragment (see tools/cmake/lto.cmake), has
  opted out via NO_LTO, or is not a static library.

- project.cmake: when CONFIG_APP_REPRODUCIBLE_BUILD is also enabled, apply
  the same three flags as the legacy build system to keep LTO output
  reproducible: pass the prefix-map options to the linker (so link-time code
  generation remaps DW_AT_comp_dir), add -save-temps (stable LTRANS object
  names instead of random $TMPDIR paths in the .map), and pin -frandom-seed
  (byte-identical LTO GIMPLE bytecode). See the commit message of
  "feat(build): add options to enable link-time optimization (LTO)" for the
  full analysis.

The gcc-ar / gcc-ranlib selection and the NO_LTO component property are shared
with the legacy build system through tools/cmake/toolchain.cmake and the common
component registration code, so no cmakev2-specific changes are needed there.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-14 19:32:19 +02:00
Sudeep Mohanty
ec4b87da4f fix(bootloader/cmakev2): exclude all paths matching BOOTLOADER_IGNORE_EXTRA_COMPONENT
Walk every directory contributed via BOOTLOADER_EXTRA_COMPONENT_DIRS
(both shared and direct component paths, not only those under the
application's bootloader_components/) and exclude any whose component
name matches BOOTLOADER_IGNORE_EXTRA_COMPONENT.
2026-07-01 13:17:25 +02:00
Sudeep Mohanty
832ad05a46 ci(bootloader): silence expected SECURE_BOOT_SIGNING_KEY CMake warning
Reference SECURE_BOOT_SIGNING_KEY in the bootloader subproject so CMake
does not warn about a manually-specified-but-unused variable when the
sign-key consumers are in config-gated blocks. Ports the same fix the
v1 subproject CMakeLists already has at line 119-120.
2026-06-15 14:58:46 +02:00
Sudeep Mohanty
3b4fbbb531 fix(cmakev2/bootloader): link bootloader_components discovered from EXTRA_COMPONENT_DIRS
idf_build_executable only links the COMPONENTS list and its
dependencies. However, bootloader_components provided by the application
get discovered, but not linked. This MR forces the extra components for
the bootloader to be linked to the bootloader binary as there is no way
for the application to specify the same.
2026-06-05 16:09:57 +02:00
Alexey Lapshin
a1cbc20a91 feat(bootloader): split linker scripts into memory and sections
Replaced per-target bootloader.ld.in with bootloader.memory.ld.in and
bootloader.sections.ld.in.

Common code moved to file bootloader.sections.common.ld

Unify ESP32-P4 ECO4- and ECO4+ linker scripts into one shared script
Revision-specific code is selected with CONFIG_ESP32P4_SELECTS_REV_LESS_V3
2026-04-03 11:40:33 +07:00
Frantisek Hrbata
3ba07d507e fix(cmakev2/bootloader): use bootloader.bin when signing is not enabled
When CONFIG_SECURE_BOOT_V2_ENABLED=y but
CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES is not set, produce the
binary directly as bootloader.bin instead of bootloader-unsigned.bin.

This matches the v1 behavior where the intermediate binary name is
conditional: bootloader-unsigned.bin only when build-time signing is
enabled (so the signed output can be named bootloader.bin), otherwise
the output is bootloader.bin directly.

Signed-off-by: Frantisek Hrbata <frantisek.hrbata@espressif.com>
2026-03-27 19:18:11 +08:00
Frantisek Hrbata
c6c1293d0c fix(cmakev2/project): guard compiler optimization flags with build property
The __init_project_configuration() function in cmakev2's project.cmake
unconditionally applied app-level compiler optimization flags based on
CONFIG_COMPILER_OPTIMIZATION_* Kconfig options. When the bootloader
subproject was built with cmakev2, these app-level flags leaked into the
bootloader compile command alongside the correct bootloader-specific
flags from CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_*.

For example, with the default configuration (app: DEBUG, bootloader:
SIZE), the bootloader received both "-Og -fno-shrink-wrap" (from app
config) and "-Os -freorder-blocks" (from bootloader config). While GCC
uses the last -O flag (-Os wins), the stray -fno-shrink-wrap persisted.

Introduce a SET_COMPILER_OPTIMIZATION build property that defaults to
YES when unset. Subprojects that manage their own optimization flags
(like the bootloader) can set this to NO before calling
idf_project_init() to prevent the default optimization flags from being
applied. This keeps project.cmake generic without requiring it to know
about specific subproject types.

Signed-off-by: Frantisek Hrbata <frantisek.hrbata@espressif.com>
2026-03-27 19:18:11 +08:00
Frantisek Hrbata
6416f75581 feat(bootloader): build bootloader using cmakev2
Add CMakeLists_v2.txt to the bootloader subproject, implementing the
bootloader build using the new cmakev2 IDF build framework.

The file covers the full bootloader build pipeline:
- Sets PROJECT_COMPONENTS_SOURCE to "idf_components" so that the
  subproject's built-in components (main/, components/) are treated as
  IDF components (priority 0) rather than project components (priority
  3).  This preserves the cmakev1 behaviour where user-supplied
  components in bootloader_components/ can override the built-in ones.
- Registers optional user-supplied bootloader components from the
  application project's bootloader_components/ directory, with support
  for selectively excluding individual components via
  IGNORE_EXTRA_COMPONENT.
- Bootstraps the cmakev2 framework (idf.cmake) and initialises the
  project with BOOTLOADER_BUILD and NON_OS_BUILD properties, which are
  also exposed as C preprocessor definitions.
- Sets GENERATE_SDKCONFIG to 0 to prevent the bootloader subproject
  from regenerating the main project's sdkconfig, as the bootloader
  has a different set of components and hence different Kconfig files.
- Sets the common implicit component dependencies shared by every
  bootloader component (log, esp_rom, esp_common, esp_hw_support,
  esp_libc, arch-specific component).
- Applies the compiler options specific for bootloader
- Selects the correct target-specific linker script, including a
  separate script for ESP32-P4 silicon revisions < v3.
- Links the bootloader ELF via idf_build_executable and then converts it
  to a flat binary via one of three paths depending on the secure boot
  configuration:
    * No secure boot: plain binary + size check + metadata.
    * Secure Boot V1 one-time-flash: plain binary with post-build
      instructions showing the esptool.py flash command.
    * Secure Boot V1 reflashable: derives the symmetric eFuse key from
      the ECDSA signing key, produces the reflash-digest image, and
      prints burn/flash instructions.
    * Secure Boot V2: produces an unsigned binary, optionally signs it
      with the configured signing key (RSA-PSS 3072, ECDSA P-256, or
      ECDSA P-384) via idf_sign_binary, and prints flash/multi-key
      signing instructions.
- Adds comprehensive inline documentation explaining each section's
  purpose, the rationale behind individual flags, and the relationships
  between Kconfig symbols and generated artefacts.

Signed-off-by: Frantisek Hrbata <frantisek.hrbata@espressif.com>
2026-03-27 19:18:11 +08:00