diff --git a/esphome/components/dfu/__init__.py b/esphome/components/dfu/__init__.py index b5d93bd093..aef7d8d421 100644 --- a/esphome/components/dfu/__init__.py +++ b/esphome/components/dfu/__init__.py @@ -8,6 +8,7 @@ from esphome.const import ( from esphome.core import CORE from esphome.components.zephyr import zephyr_add_prj_conf import esphome.final_validate as fv +from esphome.components.nrf52.const import BOOTLOADER_ADAFRUIT dfu_ns = cg.esphome_ns.namespace("dfu") DeviceFirmwareUpdate = dfu_ns.class_("DeviceFirmwareUpdate", cg.Component) @@ -31,7 +32,7 @@ def _validate_mcumgr(config): fconf = fv.full_config.get() try: bootloader = fconf.get_config_for_path(["nrf52", "bootloader"]) - if bootloader != "adafruit": + if bootloader != BOOTLOADER_ADAFRUIT: raise cv.Invalid(f"'{bootloader}' bootloader does not support DFU") except KeyError: pass diff --git a/esphome/components/nrf52/__init__.py b/esphome/components/nrf52/__init__.py index d92edf07c8..9d75e780b3 100644 --- a/esphome/components/nrf52/__init__.py +++ b/esphome/components/nrf52/__init__.py @@ -26,11 +26,11 @@ from esphome.components.zephyr.const import ( ZEPHYR_VARIANT_GENERIC, ZEPHYR_VARIANT_NRF_SDK, KEY_ZEPHYR, + KEY_BOOTLOADER, + BOOTLOADER_MCUBOOT, ) from .boards_zephyr import BOARDS_ZEPHYR from .const import ( - KEY_BOOTLOADER, - BOOTLOADER_MCUBOOT, BOOTLOADER_ADAFRUIT, ) @@ -130,8 +130,8 @@ CONFIG_SCHEMA = cv.All( cv.Optional(KEY_BOOTLOADER): cv.one_of(*BOOTLOADERS, lower=True), } ), - set_core_data, _detect_bootloader, + set_core_data, ) diff --git a/esphome/components/nrf52/boards_zephyr.py b/esphome/components/nrf52/boards_zephyr.py index 1afc3cf3f2..19c5c30f15 100644 --- a/esphome/components/nrf52/boards_zephyr.py +++ b/esphome/components/nrf52/boards_zephyr.py @@ -1,7 +1,5 @@ -from .const import ( - BOOTLOADER_ADAFRUIT, - KEY_BOOTLOADER, -) +from .const import BOOTLOADER_ADAFRUIT +from esphome.components.zephyr.const import KEY_BOOTLOADER BOARDS_ZEPHYR = { "adafruit_itsybitsy_nrf52840": {KEY_BOOTLOADER: BOOTLOADER_ADAFRUIT}, diff --git a/esphome/components/nrf52/const.py b/esphome/components/nrf52/const.py index 952a394739..0497c12196 100644 --- a/esphome/components/nrf52/const.py +++ b/esphome/components/nrf52/const.py @@ -1,3 +1 @@ -KEY_BOOTLOADER = "bootloader" -BOOTLOADER_MCUBOOT = "mcuboot" BOOTLOADER_ADAFRUIT = "adafruit" diff --git a/esphome/components/ota/__init__.py b/esphome/components/ota/__init__.py index 995f31256c..53439d9ac0 100644 --- a/esphome/components/ota/__init__.py +++ b/esphome/components/ota/__init__.py @@ -16,6 +16,7 @@ from esphome.const import ( ) from esphome.core import CORE, coroutine_with_priority import esphome.final_validate as fv +from esphome.components.zephyr.const import BOOTLOADER_MCUBOOT CODEOWNERS = ["@esphome/core"] @@ -120,7 +121,7 @@ def _validate_mcumgr(config): fconf = fv.full_config.get() try: bootloader = fconf.get_config_for_path(["nrf52", "bootloader"]) - if bootloader != "mcuboot": + if bootloader != BOOTLOADER_MCUBOOT: raise cv.Invalid(f"'{bootloader}' bootloader does not support OTA") except KeyError: pass diff --git a/esphome/components/zephyr/__init__.py b/esphome/components/zephyr/__init__.py index 71f85fb8bd..394db4bdde 100644 --- a/esphome/components/zephyr/__init__.py +++ b/esphome/components/zephyr/__init__.py @@ -15,18 +15,22 @@ from .const import ( KEY_PRJ_CONF, KEY_OVERLAY, zephyr_ns, + BOOTLOADER_MCUBOOT, ) AUTO_LOAD = ["preferences"] KEY_BOARD = "board" +KEY_BOOTLOADER = "bootloader" + def zephyr_set_core_data(config): CORE.data[KEY_ZEPHYR] = {} CORE.data[KEY_ZEPHYR][KEY_BOARD] = config[CONF_BOARD] CORE.data[KEY_ZEPHYR][KEY_PRJ_CONF] = {} CORE.data[KEY_ZEPHYR][KEY_OVERLAY] = "" + CORE.data[KEY_ZEPHYR][KEY_BOOTLOADER] = config[KEY_BOOTLOADER] return config @@ -131,21 +135,22 @@ def zephyr_copy_files(): CORE.data[KEY_ZEPHYR][KEY_OVERLAY], ) - fake_board_manifest = """ + if CORE.data[KEY_ZEPHYR][KEY_BOOTLOADER] == BOOTLOADER_MCUBOOT: + fake_board_manifest = """ { - "frameworks": [ +"frameworks": [ "zephyr" - ], - "name": "esphome nrf52", - "upload": { +], +"name": "esphome nrf52", +"upload": { "maximum_ram_size": 248832, "maximum_size": 815104 - }, - "url": "https://esphome.io/", - "vendor": "esphome" +}, +"url": "https://esphome.io/", +"vendor": "esphome" } """ - write_file_if_changed( - CORE.relative_build_path(f"boards/{CORE.data[KEY_ZEPHYR][KEY_BOARD]}.json"), - fake_board_manifest, - ) + write_file_if_changed( + CORE.relative_build_path(f"boards/{CORE.data[KEY_ZEPHYR][KEY_BOARD]}.json"), + fake_board_manifest, + ) diff --git a/esphome/components/zephyr/const.py b/esphome/components/zephyr/const.py index acbf83d4f3..de5f641108 100644 --- a/esphome/components/zephyr/const.py +++ b/esphome/components/zephyr/const.py @@ -5,5 +5,7 @@ ZEPHYR_VARIANT_NRF_SDK = "nrf-sdk" KEY_ZEPHYR = "zephyr" KEY_PRJ_CONF = "prj_conf" KEY_OVERLAY = "overlay" +KEY_BOOTLOADER = "bootloader" +BOOTLOADER_MCUBOOT = "mcuboot" zephyr_ns = cg.esphome_ns.namespace("zephyr")