Honor board_build.ldscript for the native flash linker script

Published configs override it to reserve a filesystem region or correct
a board's assumed flash size; the routed value replaces the BOARDS
default, and a path is rejected since the name resolves via -L.
This commit is contained in:
J. Nick Koston
2026-08-21 20:30:30 -05:00
4 changed files with 87 additions and 8 deletions
@@ -1291,3 +1291,36 @@ def test_generate_ld_scripts_gcc_change_invalidates_stamp(tmp_path: Path) -> Non
with patch.object(arduino8266.subprocess, "run", return_value=result) as mock_run:
_run_generate_ld_scripts(paths)
mock_run.assert_called_once()
def test_defines_flags_honors_f_cpu_override() -> None:
"""board_build.f_cpu (a published-config overclock knob) reaches the
compile line; the default stays 80 MHz."""
_set_flags()
config = _resolve_build_config(_flag_defines(set(), []))
board_build = ESP8266_BOARD_BUILD["nodemcuv2"]
defines = _defines_flags(config, "dout", "nodemcuv2", board_build["defines"])
assert "-DF_CPU=80000000L" in defines
CORE.platformio_options = {"board_build.f_cpu": "160000000L"}
defines = _defines_flags(config, "dout", "nodemcuv2", board_build["defines"])
assert "-DF_CPU=160000000L" in defines
# A repeated option accumulates as a list; the last value wins
CORE.platformio_options = {"board_build.f_cpu": ["80000000L", "160000000L"]}
defines = _defines_flags(config, "dout", "nodemcuv2", board_build["defines"])
assert "-DF_CPU=160000000L" in defines
def test_flash_ld_name_honors_ldscript_override(tmp_path: Path) -> None:
"""board_build.ldscript (filesystem reservation, corrected flash size)
replaces the board default; a path is rejected since the name resolves
via the -L search path."""
assert arduino8266._flash_ld_name("nodemcuv2") == "eagle.flash.4m.ld"
CORE.platformio_options = {"board_build.ldscript": "eagle.flash.4m2m.ld"}
assert arduino8266._flash_ld_name("nodemcuv2") == "eagle.flash.4m2m.ld"
paths = _make_framework(tmp_path)
_set_flags()
content = _write_ninja(paths)
assert "-T eagle.flash.4m2m.ld" in content
CORE.platformio_options = {"board_build.ldscript": "../evil.ld"}
with pytest.raises(EsphomeError, match="bare script name"):
arduino8266._flash_ld_name("nodemcuv2")
+11 -3
View File
@@ -1397,8 +1397,8 @@ def test_esphome_build_internals_are_yaml_only() -> None:
async def test_add_platformio_options_native_arduino(
caplog: pytest.LogCaptureFixture,
) -> None:
"""The native ESP8266 Arduino toolchain warns about ignored options the
same way the native IDF toolchain does."""
"""The native ESP8266 Arduino toolchain honors board_build.f_cpu (a
real-world overclock knob) and warns about the rest like native IDF."""
CORE.toolchain = Toolchain.ARDUINO
CORE.data[KEY_CORE] = {
KEY_TARGET_PLATFORM: "esp8266",
@@ -1408,11 +1408,19 @@ async def test_add_platformio_options_native_arduino(
await config._add_platformio_options(
{
"board_build.f_cpu": "160000000L",
"board_build.ldscript": "eagle.flash.4m2m.ld",
"board_build.filesystem": "littlefs",
"upload_speed": "115200",
}
)
assert "esphome->platformio_options->board_build.f_cpu is ignored" in caplog.text
assert CORE.platformio_options["board_build.f_cpu"] == "160000000L"
assert CORE.platformio_options["board_build.ldscript"] == "eagle.flash.4m2m.ld"
assert "board_build.f_cpu is ignored" not in caplog.text
assert "board_build.ldscript is ignored" not in caplog.text
assert (
"esphome->platformio_options->board_build.filesystem is ignored" in caplog.text
)
assert "'arduino' toolchain" in caplog.text
assert "upload_speed" not in caplog.text