Add compressed self-serve OTA and resilient native USB sleep
Use a bounded uzlib-derived block encoder with the existing strict tinf decoder, qualify infrastructure roles, budget temporary RAM, and cache running-image metadata. Add self-serve CLI and policy, USB host-loss sleep grace, hardware test harnesses, regression tests, and CI coverage.
This commit is contained in:
1 parent
29de7820e5
commit
5833ac2f1f
34 files changed
+5437
-40
No files matched your search
@@ -106,6 +106,28 @@ def requirements(platform, defines, target):
|
||||
parts["room_flood_rule_table"] = 31 * 200 + 16
|
||||
if "ENABLE_OTA" in defines and "OTA_HEAP_CONTEXT" in defines:
|
||||
parts["ota_context"] = 16384 + 16
|
||||
# Match OtaDeflateConfig.h's compile eligibility and build-role override.
|
||||
# Adaptive RAK may qualify only at runtime; reserve its worst eligible case.
|
||||
# The shared role hook qualifies sources, not environment names. An
|
||||
# infrastructure recipe can inherit a Companion-named custom environment.
|
||||
device_deflate = ("ENABLE_OTA" in defines and "OTA_SEEDER_ONLY" not in defines
|
||||
and integer(defines, "MESHCORE_OTA_DEVICE_DEFLATE", 0) != 0
|
||||
and (platform == "ESP32_PLATFORM" or
|
||||
(platform == "NRF52_PLATFORM" and any(name in defines for name in
|
||||
("OTA_QSPI_STORE", "OTA_SD_STORE", "OTA_RAK_AUTO_STORE")))))
|
||||
if device_deflate:
|
||||
hash_bits = integer(defines, "MESHCORE_OTA_DEFLATE_HASH_BITS", 9)
|
||||
if not 7 <= hash_bits <= 10:
|
||||
raise ValueError("device DEFLATE hash must have 128..1024 entries")
|
||||
# The encoder uses input offsets, not pointers: sizeof(uint16_t) per
|
||||
# bucket on every platform. This allocation is freed before radio TX.
|
||||
parts["ota_encoder_workspace"] = (1 << hash_bits) * 2 + 16
|
||||
if platform == "NRF52_PLATFORM":
|
||||
# The running nRF52840 app is <1 MiB: <=512 2-KiB leaves. Self-serve
|
||||
# holds its leaf cache plus max(leaves,2048) proof/output scratch.
|
||||
# Unlike ESP32's existing source scratch reserve these allocations
|
||||
# were formerly covered only by the general transient margin.
|
||||
parts["ota_self_source_scratch"] = 2 * 2048 + 2 * 16
|
||||
if display and display != "NullDisplayDriver":
|
||||
parts["display_pixels_and_driver"] = display_heap
|
||||
screen_budget = integer(defines, "MESH_COMPANION_SCREEN_STARTUP_BYTES", 0)
|
||||
@@ -137,7 +159,7 @@ def requirements(platform, defines, target):
|
||||
if "expanded_message_previews" in parts:
|
||||
largest = max(largest, 8192 + parts["expanded_message_previews"])
|
||||
for name in ("client_table", "flood_filter_table", "room_flood_rule_table",
|
||||
"ota_context", "screen_objects_and_history"):
|
||||
"ota_context", "screen_objects_and_history", "ota_encoder_workspace"):
|
||||
largest = max(largest, parts.get(name, 0))
|
||||
return {"required_heap_bytes": required, "required_contiguous_bytes": largest,
|
||||
"components": parts, "display": display, "full_companion": full}
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
"""Enable bounded on-device OTA encoding only for qualified infrastructure.
|
||||
|
||||
Inspect the EFFECTIVE ordered source filter, never the environment name. This
|
||||
pre-script contributes one shared compiler definition, so the C encoder and all
|
||||
C++ OTA translation units agree. A custom recipe that omits this hook keeps
|
||||
OtaDeflateConfig.h's fail-closed default. Companions keep host-precompressed OTA.
|
||||
"""
|
||||
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
SCRIPT_DIR = Path(__file__).resolve().parent if "__file__" in globals() else Path("scripts").resolve()
|
||||
SPEC = importlib.util.spec_from_file_location(
|
||||
"ota_device_deflate_source_policy", SCRIPT_DIR / "nrf52_flash_trim.py")
|
||||
SOURCE_POLICY = importlib.util.module_from_spec(SPEC)
|
||||
SPEC.loader.exec_module(SOURCE_POLICY)
|
||||
|
||||
DEFINITION = "MESHCORE_OTA_DEVICE_DEFLATE"
|
||||
ROLE_SOURCES = (
|
||||
"../examples/simple_repeater/main.cpp",
|
||||
"../examples/simple_room_server/main.cpp",
|
||||
"../examples/simple_sensor/main.cpp",
|
||||
)
|
||||
EXCLUDED_SOURCES = (
|
||||
"../examples/companion_radio/main.cpp",
|
||||
"../examples/companion_radio/MyMesh.cpp",
|
||||
"../examples/simple_secure_chat/main.cpp",
|
||||
"../examples/kiss_modem/main.cpp",
|
||||
"../examples/partition_expander/main.cpp",
|
||||
"../examples/esp32_partition_migrator/main.cpp",
|
||||
"../examples/esp32_partition_legacy_seed/main.cpp",
|
||||
)
|
||||
|
||||
|
||||
def enabled(values, name):
|
||||
value = values.get(name)
|
||||
return value is not None and str(value).strip("\"'() ") not in ("", "0")
|
||||
|
||||
|
||||
def bool_override(value):
|
||||
# -U leaves the header's default zero and is an explicit opt-out as well.
|
||||
if value is None:
|
||||
return 0
|
||||
text = str(value).strip("\"'() ")
|
||||
if text not in ("0", "1"):
|
||||
raise ValueError(DEFINITION + " override must be 0 or 1")
|
||||
return int(text)
|
||||
|
||||
|
||||
def role_policy(platform, mcu, src_filter, flags=(), cppdefines=()):
|
||||
"""Return a common define or reject an unsafe explicit enable override."""
|
||||
values = SOURCE_POLICY.flag_defines(flags, cppdefines)
|
||||
selected = SOURCE_POLICY.source_selected
|
||||
known_roles = sum(selected(src_filter, source) for source in ROLE_SOURCES)
|
||||
excluded = any(selected(src_filter, source) for source in EXCLUDED_SOURCES)
|
||||
seeder = values.get("OTA_SEEDER_ONLY") is not None
|
||||
companion = any(enabled(values, name) for name in values
|
||||
if name.startswith("COMPANION_"))
|
||||
ota_enabled = enabled(values, "ENABLE_OTA") and not enabled(values, "DISABLE_LORA_OTA")
|
||||
esp32 = (platform == "espressif32" and str(mcu).lower().startswith("esp32")
|
||||
and enabled(values, "ESP32_PLATFORM"))
|
||||
nrf52 = (platform == "nordicnrf52" and str(mcu).lower().startswith("nrf52")
|
||||
and enabled(values, "NRF52_PLATFORM")
|
||||
and any(enabled(values, store)
|
||||
for store in ("OTA_QSPI_STORE", "OTA_SD_STORE", "OTA_RAK_AUTO_STORE")))
|
||||
qualified = (known_roles == 1 and not excluded and not seeder and not companion
|
||||
and ota_enabled and (esp32 or nrf52))
|
||||
if DEFINITION in values:
|
||||
override = bool_override(values[DEFINITION])
|
||||
if override and not qualified:
|
||||
raise ValueError(DEFINITION + "=1 requires an OTA infrastructure source role "
|
||||
"and eligible ESP32/external-nRF52 storage")
|
||||
return {} # Preserve an explicit valid definition/opt-out without duplicates.
|
||||
return {DEFINITION: 1} if qualified else {}
|
||||
|
||||
|
||||
def install(build_env):
|
||||
platform = build_env.PioPlatform().name
|
||||
mcu = build_env.BoardConfig().get("build.mcu", "")
|
||||
src_filter = build_env.get("SRC_FILTER")
|
||||
if src_filter is None:
|
||||
src_filter = build_env.GetProjectOption("build_src_filter", "")
|
||||
definitions = role_policy(platform, mcu, src_filter,
|
||||
build_env.get("BUILD_FLAGS", ()),
|
||||
build_env.get("CPPDEFINES", ()))
|
||||
if definitions:
|
||||
build_env.AppendUnique(CPPDEFINES=list(definitions.items()))
|
||||
print("Device OTA DEFLATE: qualified infrastructure role; bounded per-block encoder")
|
||||
|
||||
|
||||
if "Import" in globals():
|
||||
Import("env")
|
||||
install(env)
|
||||
Reference in new issue
Block a user