mirror of
https://github.com/esphome/esphome.git
synced 2025-04-11 21:30:29 +01:00
move install of smp to post build step
This commit is contained in:
parent
51719ec448
commit
42846032d0
@ -1,4 +1,3 @@
|
|||||||
import os
|
|
||||||
import esphome.codegen as cg
|
import esphome.codegen as cg
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
from esphome.const import (
|
from esphome.const import (
|
||||||
@ -13,12 +12,8 @@ from esphome.const import (
|
|||||||
CONF_PLATFORM_VERSION,
|
CONF_PLATFORM_VERSION,
|
||||||
)
|
)
|
||||||
from esphome.core import CORE, coroutine_with_priority
|
from esphome.core import CORE, coroutine_with_priority
|
||||||
from esphome.helpers import (
|
|
||||||
copy_file_if_changed,
|
|
||||||
)
|
|
||||||
|
|
||||||
from esphome.components.zephyr import (
|
from esphome.components.zephyr import (
|
||||||
zephyr_copy_files,
|
|
||||||
zephyr_set_core_data,
|
zephyr_set_core_data,
|
||||||
zephyr_to_code,
|
zephyr_to_code,
|
||||||
)
|
)
|
||||||
@ -153,27 +148,7 @@ async def to_code(config):
|
|||||||
cg.add_platformio_option("board_upload.require_upload_port", "true")
|
cg.add_platformio_option("board_upload.require_upload_port", "true")
|
||||||
cg.add_platformio_option("board_upload.wait_for_upload_port", "true")
|
cg.add_platformio_option("board_upload.wait_for_upload_port", "true")
|
||||||
#
|
#
|
||||||
cg.add_platformio_option(
|
|
||||||
"extra_scripts", [f"pre:build_{CORE.data[KEY_CORE][KEY_TARGET_FRAMEWORK]}.py"]
|
|
||||||
)
|
|
||||||
if CORE.using_zephyr:
|
if CORE.using_zephyr:
|
||||||
zephyr_to_code(conf)
|
zephyr_to_code(conf)
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
# Called by writer.py
|
|
||||||
def copy_files():
|
|
||||||
if CORE.using_zephyr:
|
|
||||||
zephyr_copy_files()
|
|
||||||
|
|
||||||
dir = os.path.dirname(__file__)
|
|
||||||
build_zephyr_file = os.path.join(
|
|
||||||
dir, f"build_{CORE.data[KEY_CORE][KEY_TARGET_FRAMEWORK]}.py.script"
|
|
||||||
)
|
|
||||||
copy_file_if_changed(
|
|
||||||
build_zephyr_file,
|
|
||||||
CORE.relative_build_path(
|
|
||||||
f"build_{CORE.data[KEY_CORE][KEY_TARGET_FRAMEWORK]}.py"
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
|
import os
|
||||||
from typing import Union
|
from typing import Union
|
||||||
import esphome.codegen as cg
|
import esphome.codegen as cg
|
||||||
from esphome.core import CORE
|
from esphome.core import CORE
|
||||||
from esphome.helpers import (
|
from esphome.helpers import (
|
||||||
write_file_if_changed,
|
write_file_if_changed,
|
||||||
|
copy_file_if_changed,
|
||||||
)
|
)
|
||||||
from esphome.const import (
|
from esphome.const import (
|
||||||
CONF_VARIANT,
|
CONF_VARIANT,
|
||||||
CONF_BOARD,
|
CONF_BOARD,
|
||||||
|
KEY_NAME,
|
||||||
)
|
)
|
||||||
from .const import (
|
from .const import (
|
||||||
ZEPHYR_VARIANT_GENERIC,
|
ZEPHYR_VARIANT_GENERIC,
|
||||||
@ -16,6 +19,8 @@ from .const import (
|
|||||||
KEY_OVERLAY,
|
KEY_OVERLAY,
|
||||||
zephyr_ns,
|
zephyr_ns,
|
||||||
BOOTLOADER_MCUBOOT,
|
BOOTLOADER_MCUBOOT,
|
||||||
|
KEY_EXTRA_BUILD_FILES,
|
||||||
|
KEY_PATH,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -31,6 +36,7 @@ def zephyr_set_core_data(config):
|
|||||||
CORE.data[KEY_ZEPHYR][KEY_PRJ_CONF] = {}
|
CORE.data[KEY_ZEPHYR][KEY_PRJ_CONF] = {}
|
||||||
CORE.data[KEY_ZEPHYR][KEY_OVERLAY] = ""
|
CORE.data[KEY_ZEPHYR][KEY_OVERLAY] = ""
|
||||||
CORE.data[KEY_ZEPHYR][KEY_BOOTLOADER] = config[KEY_BOOTLOADER]
|
CORE.data[KEY_ZEPHYR][KEY_BOOTLOADER] = config[KEY_BOOTLOADER]
|
||||||
|
CORE.data[KEY_ZEPHYR][KEY_EXTRA_BUILD_FILES] = {}
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
|
||||||
@ -58,6 +64,24 @@ def zephyr_add_overlay(content):
|
|||||||
CORE.data[KEY_ZEPHYR][KEY_OVERLAY] += content
|
CORE.data[KEY_ZEPHYR][KEY_OVERLAY] += content
|
||||||
|
|
||||||
|
|
||||||
|
def add_extra_build_file(filename: str, path: str) -> bool:
|
||||||
|
"""Add an extra build file to the project."""
|
||||||
|
if filename not in CORE.data[KEY_ZEPHYR][KEY_EXTRA_BUILD_FILES]:
|
||||||
|
CORE.data[KEY_ZEPHYR][KEY_EXTRA_BUILD_FILES][filename] = {
|
||||||
|
KEY_NAME: filename,
|
||||||
|
KEY_PATH: path,
|
||||||
|
}
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def add_extra_script(stage: str, filename: str, path: str):
|
||||||
|
"""Add an extra script to the project."""
|
||||||
|
key = f"{stage}:{filename}"
|
||||||
|
if add_extra_build_file(filename, path):
|
||||||
|
cg.add_platformio_option("extra_scripts", [key])
|
||||||
|
|
||||||
|
|
||||||
def zephyr_to_code(conf):
|
def zephyr_to_code(conf):
|
||||||
cg.add(zephyr_ns.setup_preferences())
|
cg.add(zephyr_ns.setup_preferences())
|
||||||
cg.add_build_flag("-DUSE_ZEPHYR")
|
cg.add_build_flag("-DUSE_ZEPHYR")
|
||||||
@ -110,6 +134,17 @@ def zephyr_to_code(conf):
|
|||||||
|
|
||||||
zephyr_add_prj_conf("USB_CDC_ACM_LOG_LEVEL_WRN", True)
|
zephyr_add_prj_conf("USB_CDC_ACM_LOG_LEVEL_WRN", True)
|
||||||
|
|
||||||
|
add_extra_script(
|
||||||
|
"pre",
|
||||||
|
"pre_build.py",
|
||||||
|
os.path.join(os.path.dirname(__file__), "pre_build.py.script"),
|
||||||
|
)
|
||||||
|
add_extra_script(
|
||||||
|
"post",
|
||||||
|
"post_build.py",
|
||||||
|
os.path.join(os.path.dirname(__file__), "post_build.py.script"),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def _format_prj_conf_val(value: PrjConfValueType) -> str:
|
def _format_prj_conf_val(value: PrjConfValueType) -> str:
|
||||||
if isinstance(value, bool):
|
if isinstance(value, bool):
|
||||||
@ -121,7 +156,8 @@ def _format_prj_conf_val(value: PrjConfValueType) -> str:
|
|||||||
raise ValueError
|
raise ValueError
|
||||||
|
|
||||||
|
|
||||||
def zephyr_copy_files():
|
# Called by writer.py
|
||||||
|
def copy_files():
|
||||||
want_opts = CORE.data[KEY_ZEPHYR][KEY_PRJ_CONF]
|
want_opts = CORE.data[KEY_ZEPHYR][KEY_PRJ_CONF]
|
||||||
contents = (
|
contents = (
|
||||||
"\n".join(
|
"\n".join(
|
||||||
@ -156,3 +192,9 @@ def zephyr_copy_files():
|
|||||||
CORE.relative_build_path(f"boards/{CORE.data[KEY_ZEPHYR][KEY_BOARD]}.json"),
|
CORE.relative_build_path(f"boards/{CORE.data[KEY_ZEPHYR][KEY_BOARD]}.json"),
|
||||||
fake_board_manifest,
|
fake_board_manifest,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
for _, file in CORE.data[KEY_ZEPHYR][KEY_EXTRA_BUILD_FILES].items():
|
||||||
|
copy_file_if_changed(
|
||||||
|
file[KEY_PATH],
|
||||||
|
CORE.relative_build_path(file[KEY_NAME]),
|
||||||
|
)
|
||||||
|
@ -2,10 +2,14 @@ import esphome.codegen as cg
|
|||||||
|
|
||||||
ZEPHYR_VARIANT_GENERIC = "generic"
|
ZEPHYR_VARIANT_GENERIC = "generic"
|
||||||
ZEPHYR_VARIANT_NRF_SDK = "nrf-sdk"
|
ZEPHYR_VARIANT_NRF_SDK = "nrf-sdk"
|
||||||
|
|
||||||
KEY_ZEPHYR = "zephyr"
|
KEY_ZEPHYR = "zephyr"
|
||||||
KEY_PRJ_CONF = "prj_conf"
|
KEY_PRJ_CONF = "prj_conf"
|
||||||
KEY_OVERLAY = "overlay"
|
KEY_OVERLAY = "overlay"
|
||||||
KEY_BOOTLOADER = "bootloader"
|
KEY_BOOTLOADER = "bootloader"
|
||||||
|
KEY_EXTRA_BUILD_FILES = "extra_build_files"
|
||||||
|
KEY_PATH = "path"
|
||||||
|
|
||||||
BOOTLOADER_MCUBOOT = "mcuboot"
|
BOOTLOADER_MCUBOOT = "mcuboot"
|
||||||
|
|
||||||
zephyr_ns = cg.esphome_ns.namespace("zephyr")
|
zephyr_ns = cg.esphome_ns.namespace("zephyr")
|
||||||
|
10
esphome/components/zephyr/post_build.py.script
Normal file
10
esphome/components/zephyr/post_build.py.script
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
Import("env")
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
try:
|
||||||
|
import smp
|
||||||
|
import smpclient
|
||||||
|
except ImportError:
|
||||||
|
if sys.version_info >= (3, 10):
|
||||||
|
env.Execute("$PYTHONEXE -m pip install smp==1.0.0 git+https://github.com/tomaszduda23/smpclient/@d25c8035ae2858fd41a106058297b619d58fbcb5")
|
@ -310,8 +310,8 @@ def copy_src_tree():
|
|||||||
CORE.relative_src_path("esphome.h"),
|
CORE.relative_src_path("esphome.h"),
|
||||||
ESPHOME_H_FORMAT.format(include_s + '\n#include "pio_includes.h"'),
|
ESPHOME_H_FORMAT.format(include_s + '\n#include "pio_includes.h"'),
|
||||||
)
|
)
|
||||||
elif CORE.is_nrf52:
|
elif CORE.using_zephyr:
|
||||||
from esphome.components.nrf52 import copy_files
|
from esphome.components.zephyr import copy_files
|
||||||
|
|
||||||
copy_files()
|
copy_files()
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ from bleak import BleakScanner, BleakClient
|
|||||||
from bleak.exc import BleakDeviceNotFoundError, BleakDBusError
|
from bleak.exc import BleakDeviceNotFoundError, BleakDBusError
|
||||||
from esphome.espota2 import ProgressBar
|
from esphome.espota2 import ProgressBar
|
||||||
|
|
||||||
if sys.version_info >= (3, 10):
|
try:
|
||||||
from smpclient.transport.ble import SMPBLETransport
|
from smpclient.transport.ble import SMPBLETransport
|
||||||
from smpclient.transport.serial import SMPSerialTransport
|
from smpclient.transport.serial import SMPSerialTransport
|
||||||
from smpclient import SMPClient
|
from smpclient import SMPClient
|
||||||
@ -17,6 +17,8 @@ if sys.version_info >= (3, 10):
|
|||||||
from smpclient.requests.os_management import ResetWrite
|
from smpclient.requests.os_management import ResetWrite
|
||||||
from smpclient.generics import error, success
|
from smpclient.generics import error, success
|
||||||
from smp.exceptions import SMPBadStartDelimiter
|
from smp.exceptions import SMPBadStartDelimiter
|
||||||
|
except ModuleNotFoundError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
SMP_SERVICE_UUID = "8D53DC1D-1DB7-4CD3-868B-8A527460AA84"
|
SMP_SERVICE_UUID = "8D53DC1D-1DB7-4CD3-868B-8A527460AA84"
|
||||||
@ -89,7 +91,7 @@ def get_image_tlv_sha256(file):
|
|||||||
|
|
||||||
async def smpmgr_upload(config, host, firmware):
|
async def smpmgr_upload(config, host, firmware):
|
||||||
if sys.version_info < (3, 10):
|
if sys.version_info < (3, 10):
|
||||||
_LOGGER.error("smpmgr requires at least python 3.10")
|
_LOGGER.error("BLE OTA requires at least python 3.10")
|
||||||
return 1
|
return 1
|
||||||
image_tlv_sha256 = get_image_tlv_sha256(firmware)
|
image_tlv_sha256 = get_image_tlv_sha256(firmware)
|
||||||
if image_tlv_sha256 is None:
|
if image_tlv_sha256 is None:
|
||||||
|
@ -29,11 +29,6 @@ pyparsing >= 3.0
|
|||||||
argcomplete>=2.0.0
|
argcomplete>=2.0.0
|
||||||
|
|
||||||
# for mcumgr
|
# for mcumgr
|
||||||
smp==1.0.0
|
|
||||||
smpclient @ git+https://github.com/tomaszduda23/smpclient/@d25c8035ae2858fd41a106058297b619d58fbcb5
|
|
||||||
bleak==0.21.1
|
bleak==0.21.1
|
||||||
pydantic==2.7.0
|
|
||||||
cbor2==5.6.1
|
cbor2==5.6.1
|
||||||
crcmod==1.7
|
|
||||||
# pretty print by logging?
|
|
||||||
rich==13.7.0
|
rich==13.7.0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user