diff --git a/esphome/components/esp8266/__init__.py b/esphome/components/esp8266/__init__.py index 5c8bef7fca..0c13625a64 100644 --- a/esphome/components/esp8266/__init__.py +++ b/esphome/components/esp8266/__init__.py @@ -409,8 +409,8 @@ async def to_code(config: ConfigType) -> None: ) if config[CONF_BOARD] in BOARDS: - flash_size = BOARDS[config[CONF_BOARD]][KEY_FLASH_SIZE] - ld_scripts = ESP8266_LD_SCRIPTS[flash_size] + board_data = BOARDS[config[CONF_BOARD]] + ld_scripts = ESP8266_LD_SCRIPTS[board_data[KEY_FLASH_SIZE]] if ver <= cv.Version(2, 3, 0): # No ld script support @@ -419,7 +419,9 @@ async def to_code(config: ConfigType) -> None: # Old ld script path ld_script = ld_scripts[0] else: - ld_script = ld_scripts[1] + # A per-board override preserves a layout the board shipped + # with (see d1_wroom_02 in boards.py) + ld_script = board_data.get("ldscript", ld_scripts[1]) if ld_script is not None: cg.add_platformio_option("board_build.ldscript", ld_script) diff --git a/esphome/components/esp8266/boards.py b/esphome/components/esp8266/boards.py index d458442dbd..397de60e24 100644 --- a/esphome/components/esp8266/boards.py +++ b/esphome/components/esp8266/boards.py @@ -199,6 +199,15 @@ BOARDS = { "name": "WeMos D1 mini Pro", "flash_size": FLASH_SIZE_16_MB, }, + "d1_wroom_02": { + "name": "WeMos D1 ESP-WROOM-02", + "flash_size": FLASH_SIZE_2_MB, + # This board joined BOARDS after shipping with the manifest default + # (64 KB filesystem region); the flash-size default (2m.ld) would + # move _FS_end and with it the preferences sector, wiping existing + # devices' flash-backed state on update. + "ldscript": "eagle.flash.2m64.ld", + }, "d1": { "name": "WEMOS D1 R1", "flash_size": FLASH_SIZE_4_MB,