Skip to content

Commit 20e866c

Browse files
committed
Compile IDF bootloader with optimizations by default
By default the size of bootloader is limited to 0x2000 bytes, in debug mode the footprint can be easily grow beyond this limit Issue platformio#793
1 parent f72d698 commit 20e866c

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

builder/frameworks/espidf.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -273,13 +273,15 @@ def load_target_configurations(cmake_codemodel, cmake_api_reply_dir):
273273
return configs
274274

275275

276-
def build_library(default_env, lib_config, project_src_dir, prepend_dir=None):
276+
def build_library(
277+
default_env, lib_config, project_src_dir, prepend_dir=None, debug_allowed=True
278+
):
277279
lib_name = lib_config["nameOnDisk"]
278280
lib_path = lib_config["paths"]["build"]
279281
if prepend_dir:
280282
lib_path = os.path.join(prepend_dir, lib_path)
281283
lib_objects = compile_source_files(
282-
lib_config, default_env, project_src_dir, prepend_dir
284+
lib_config, default_env, project_src_dir, prepend_dir, debug_allowed
283285
)
284286
return default_env.Library(
285287
target=os.path.join("$BUILD_DIR", lib_path, lib_name), source=lib_objects
@@ -553,11 +555,11 @@ def generate_project_ld_script(sdk_config, ignore_targets=None):
553555
)
554556

555557

556-
def prepare_build_envs(config, default_env):
558+
def prepare_build_envs(config, default_env, debug_allowed=True):
557559
build_envs = []
558560
target_compile_groups = config.get("compileGroups")
559561

560-
is_build_type_debug = "debug" in env.GetBuildType()
562+
is_build_type_debug = "debug" in env.GetBuildType() and debug_allowed
561563
for cg in target_compile_groups:
562564
includes = []
563565
sys_includes = []
@@ -587,8 +589,8 @@ def prepare_build_envs(config, default_env):
587589
return build_envs
588590

589591

590-
def compile_source_files(config, default_env, project_src_dir, prepend_dir=None):
591-
build_envs = prepare_build_envs(config, default_env)
592+
def compile_source_files(config, default_env, project_src_dir, prepend_dir=None, debug_allowed=True):
593+
build_envs = prepare_build_envs(config, default_env, debug_allowed)
592594
objects = []
593595
components_dir = fs.to_unix_path(os.path.join(FRAMEWORK_DIR, "components"))
594596
for source in config.get("sources", []):
@@ -703,7 +705,7 @@ def find_lib_deps(components_map, elf_config, link_args, ignore_components=None)
703705
return result
704706

705707

706-
def build_bootloader():
708+
def build_bootloader(sdk_config):
707709
bootloader_src_dir = os.path.join(
708710
FRAMEWORK_DIR, "components", "bootloader", "subproject"
709711
)
@@ -743,7 +745,15 @@ def build_bootloader():
743745
target_configs, ["STATIC_LIBRARY", "OBJECT_LIBRARY"]
744746
)
745747

746-
build_components(bootloader_env, components_map, bootloader_src_dir, "bootloader")
748+
# Note: By default the size of bootloader is limited to 0x2000 bytes,
749+
# in debug mode the footprint size can be easily grow beyond this limit
750+
build_components(
751+
bootloader_env,
752+
components_map,
753+
bootloader_src_dir,
754+
"bootloader",
755+
debug_allowed=sdk_config.get("BOOTLOADER_COMPILER_OPTIMIZATION_DEBUG", False),
756+
)
747757
link_args = extract_link_args(elf_config)
748758
extra_flags = filter_args(link_args["LINKFLAGS"], ["-T", "-u"])
749759
link_args["LINKFLAGS"] = sorted(
@@ -788,10 +798,12 @@ def get_components_map(target_configs, target_types, ignore_components=None):
788798
return result
789799

790800

791-
def build_components(env, components_map, project_src_dir, prepend_dir=None):
801+
def build_components(
802+
env, components_map, project_src_dir, prepend_dir=None, debug_allowed=True
803+
):
792804
for k, v in components_map.items():
793805
components_map[k]["lib"] = build_library(
794-
env, v["config"], project_src_dir, prepend_dir
806+
env, v["config"], project_src_dir, prepend_dir, debug_allowed
795807
)
796808

797809

@@ -1232,7 +1244,7 @@ def _get_installed_pip_packages():
12321244
# Compile bootloader
12331245
#
12341246

1235-
env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", build_bootloader())
1247+
env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", build_bootloader(sdk_config))
12361248

12371249
#
12381250
# Target: ESP-IDF menuconfig

0 commit comments

Comments
 (0)