Merge latest changes and retain TLS headroom during MQTT recovery
This commit is contained in:
commit
24e7ab1eaf
61 files changed
+2003
-205
No files matched your search
@@ -67,6 +67,9 @@ def mqtt_requirements(defines):
|
||||
# slots are lazy and each attempt must pass the production admission guard.
|
||||
startup = MQTT_STARTUP_ALLOWANCE + max(0, worker_stack - MQTT_WORKER_STACK_BYTES)
|
||||
active = min(slots, 5 if psram else 2)
|
||||
# Match the pinned SDK's bounded QoS0 wire-buffer/DMA scratch floor.
|
||||
# Larger QoS1 outbox records have a separate per-payload runtime guard.
|
||||
publish_contiguous = 4096 if psram else 8000
|
||||
potential = startup + max(0, active - 2) * (MQTT_CLIENT_STACK_BYTES + MQTT_CLIENT_BUFFER_BYTES)
|
||||
return {
|
||||
"budget_scope": "startup minimum with runtime connection admission",
|
||||
@@ -82,18 +85,33 @@ def mqtt_requirements(defines):
|
||||
"maximum_slot_stack_buffer_allowance_bytes": potential,
|
||||
"cold_start_allocation_allowance_bytes": 16384,
|
||||
"cold_start_dma_admission_free_bytes": 32768,
|
||||
"cold_start_dma_admission_contiguous_bytes": 8192,
|
||||
"cold_start_dma_admission_contiguous_bytes": max(publish_contiguous, 8192),
|
||||
"additional_broker_cold_start_dma_admission_contiguous_bytes": publish_contiguous + 16384,
|
||||
"restart_allocation_allowance_bytes": 8192,
|
||||
"restart_dma_admission_free_bytes": 24576,
|
||||
"restart_dma_admission_contiguous_bytes": 8192,
|
||||
"restart_dma_admission_contiguous_bytes": max(publish_contiguous, 8192),
|
||||
"additional_broker_restart_dma_admission_contiguous_bytes": publish_contiguous + 8192,
|
||||
"dma_admission_free_bytes": 16384,
|
||||
"dma_admission_contiguous_bytes": 4096,
|
||||
"dma_admission_contiguous_bytes": publish_contiguous,
|
||||
"publish_contiguous_bytes": publish_contiguous,
|
||||
"publish_contiguous_without_psram_bytes": 8000,
|
||||
"publish_contiguous_with_psram_bytes": 4096,
|
||||
# Incoming TLS records are independent of bounded outgoing QoS0 chunks.
|
||||
"tls_psram_admission_contiguous_bytes": 16000,
|
||||
"additional_broker_cold_start_tls_psram_admission_contiguous_bytes": 16000 + 16384,
|
||||
"additional_broker_restart_tls_psram_admission_contiguous_bytes": 16000 + 8192,
|
||||
"additional_broker_tls_psram_admission_contiguous_bytes": 16000,
|
||||
"tls_internal_admission_free_bytes": 61440,
|
||||
"tls_record_allocation_bytes": 17408,
|
||||
"additional_broker_cold_start_tls_internal_admission_contiguous_bytes": 8000 + 16384 + 17408,
|
||||
"additional_broker_restart_tls_internal_admission_contiguous_bytes": 8000 + 8192 + 17408,
|
||||
"tls_internal_admission_contiguous_bytes": 17408,
|
||||
"additional_broker_tls_internal_admission_contiguous_bytes": 8000 + 17408,
|
||||
"maximum_runtime_load_qualified": False,
|
||||
"physical_validation_performed": False,
|
||||
"limitations": "Maximum TLS/WSS/outbox workload is not covered by the startup allowance; "
|
||||
"runtime free DMA heap and fragmentation must satisfy connection admission.",
|
||||
"runtime free DMA heap and fragmentation must satisfy connection admission; "
|
||||
"additional brokers reserve publication headroom beside startup allocations.",
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
"""Use the smaller ClientInfo layout only for an effective repeater source role.
|
||||
"""Derive feature-preserving role definitions from effective application sources.
|
||||
|
||||
One shared compiler definition covers application and helper translation units.
|
||||
Shared compiler definitions cover application and helper translation units.
|
||||
Unknown/custom roles keep the complete layout; room and sensor session fields
|
||||
are never removed from builds that use them.
|
||||
are never removed from builds that use them. Companions omit only unbound
|
||||
forwarding-region callbacks because that role has no RegionMap.
|
||||
"""
|
||||
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
import re
|
||||
|
||||
|
||||
SCRIPT_DIR = Path(__file__).resolve().parent if "__file__" in globals() else Path("scripts").resolve()
|
||||
@@ -18,6 +20,39 @@ DEFINITION = "MESH_CLIENT_REPEATER_ONLY"
|
||||
REPEATER_SOURCES = ("../examples/simple_repeater/main.cpp", "../examples/simple_repeater/MyMesh.cpp")
|
||||
OTHER_ROLES = ("simple_room_server", "simple_sensor", "companion_radio", "simple_secure_chat",
|
||||
"kiss_modem", "partition_expander", "esp32_partition_migrator", "esp32_partition_legacy_seed")
|
||||
COMPANION_DEFINITION = "MESH_ROLE_COMPANION"
|
||||
COMPANION_SOURCES = ("../examples/companion_radio/main.cpp", "../examples/companion_radio/MyMesh.cpp")
|
||||
|
||||
|
||||
def companion_role_policy(src_filter, flags=(), cppdefines=()):
|
||||
"""Exclude unbound forwarding-scope callbacks, retaining all radio commands.
|
||||
|
||||
Companions have no RegionMap. Select the complete exclusive source role,
|
||||
never an environment-name alias, so every translation unit shares its ABI.
|
||||
Unknown and mixed roles retain the general callback implementation.
|
||||
"""
|
||||
values = SOURCE_POLICY.flag_defines(flags, cppdefines)
|
||||
selected = SOURCE_POLICY.source_selected
|
||||
other_roles = ("simple_repeater", *(role for role in OTHER_ROLES
|
||||
if role != "companion_radio"))
|
||||
filter_text = src_filter if isinstance(src_filter, str) else " ".join(map(str, src_filter))
|
||||
example_includes = re.findall(r"\+<\.\./examples/([^>]+)>", filter_text.replace("\\", "/"))
|
||||
known_companion_only = all(path == "companion_radio" or path.startswith("companion_radio/")
|
||||
for path in example_includes)
|
||||
qualified = (known_companion_only
|
||||
and all(selected(src_filter, source) for source in COMPANION_SOURCES)
|
||||
and not any(selected(src_filter, "../examples/" + role + "/" + source)
|
||||
for role in other_roles
|
||||
for source in ("main.cpp", "MyMesh.cpp", "SensorMesh.cpp")))
|
||||
if COMPANION_DEFINITION in values:
|
||||
value = values[COMPANION_DEFINITION]
|
||||
text = "0" if value is None else str(value).strip("\"'() ")
|
||||
if text not in ("0", "1"):
|
||||
raise ValueError(COMPANION_DEFINITION + " override must be 0 or 1")
|
||||
if text == "1" and not qualified:
|
||||
raise ValueError(COMPANION_DEFINITION + "=1 requires only the Companion source role")
|
||||
return {}
|
||||
return {COMPANION_DEFINITION: 1} if qualified else {}
|
||||
|
||||
|
||||
def role_policy(src_filter, flags=(), cppdefines=()):
|
||||
@@ -46,6 +81,8 @@ def install(build_env):
|
||||
src_filter = build_env.GetProjectOption("build_src_filter", "")
|
||||
definitions = role_policy(src_filter, build_env.get("BUILD_FLAGS", ()),
|
||||
build_env.get("CPPDEFINES", ()))
|
||||
definitions.update(companion_role_policy(src_filter, build_env.get("BUILD_FLAGS", ()),
|
||||
build_env.get("CPPDEFINES", ())))
|
||||
if definitions:
|
||||
build_env.AppendUnique(CPPDEFINES=list(definitions.items()))
|
||||
|
||||
|
||||
@@ -141,6 +141,20 @@ def trim_policy(platform, mcu, env_name, src_filter, flags=(), cppdefines=(),
|
||||
if ota_name_mode != "front-coded":
|
||||
raise ValueError("unsupported nRF52 OTA name trim policy: " + ota_name_mode)
|
||||
definitions = dict(TRIM_DEFINES, OTA_TARGET_NAME_FRONT_CODED=1)
|
||||
if _enabled(values.get("MESH_OTA_LOCAL_TARGET_NAME_ONLY")):
|
||||
# Release overlays can compile a different PIOENV from their deployed
|
||||
# OTA identity. Keep the logical name/ID in that case; direct builds
|
||||
# use the same PIOENV hash as the ordinary EndF/board identity code.
|
||||
target_id = values.get("MOTA_TARGET_ID")
|
||||
if target_id is None:
|
||||
target_id = "0x%08x" % int.from_bytes(
|
||||
hashlib.sha256(str(env_name).encode()).digest()[:4], "little")
|
||||
definitions.update(
|
||||
OTA_TARGET_NAME_TABLE=0,
|
||||
OTA_LOCAL_TARGET_ID=target_id,
|
||||
OTA_LOCAL_TARGET_NAME="OTA_VARIANT" if values.get("OTA_VARIANT")
|
||||
else '"%s"' % env_name,
|
||||
)
|
||||
# Explicit board/user flags retain their value. In particular never undo
|
||||
# an opt-out or a board-specific USB configuration by re-defining it.
|
||||
return {name: value for name, value in definitions.items() if name not in values}
|
||||
@@ -241,10 +255,21 @@ def install(build_env):
|
||||
build_env.get("SRC_FILTER", ()), flags, cppdefines)
|
||||
if not definitions:
|
||||
return
|
||||
local_name = definitions.get("OTA_LOCAL_TARGET_NAME", "")
|
||||
if local_name.startswith('"') and local_name.endswith('"'):
|
||||
definitions["OTA_LOCAL_TARGET_NAME"] = build_env.StringifyMacro(local_name[1:-1])
|
||||
build_env["MESH_NRF52_FLASH_TRIM_ACTIVE"] = True
|
||||
build_env.AppendUnique(CPPDEFINES=list(definitions.items()))
|
||||
hook_path = build_env.subst("$PROJECT_DIR/scripts/nrf52_vl53l0x_const.py")
|
||||
hook_spec = importlib.util.spec_from_file_location("mesh_nrf52_vl53_const", hook_path)
|
||||
hook = importlib.util.module_from_spec(hook_spec)
|
||||
hook_spec.loader.exec_module(hook)
|
||||
hook.install(build_env)
|
||||
if infrastructure:
|
||||
print("nRF52 infrastructure flash trim: compact crypto, unused USB device classes/GPS cache/vendor splash, compact OTA target names")
|
||||
names = ("local OTA target name only" if definitions.get("OTA_TARGET_NAME_TABLE") == 0
|
||||
or flag_defines(flags, cppdefines).get("OTA_TARGET_NAME_TABLE") == "0"
|
||||
else "compact OTA target names")
|
||||
print("nRF52 infrastructure flash trim: compact crypto, unused USB device classes/GPS cache/vendor splash, " + names)
|
||||
else:
|
||||
print("nRF52 Companion flash trim: small crypto table, unused USB device classes/GPS cache/vendor splash; fonts and Reader retained")
|
||||
hook_path = build_env.subst("$PROJECT_DIR/scripts/nrf52_gnss_version_trim.py")
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
"""Keep the reviewed VL53L0X tuning tables in nRF52 flash.
|
||||
|
||||
The vendor tuning loader only reads these bytes and copies register writes
|
||||
through a local buffer. Compile a private dependency copy with const inputs;
|
||||
leave its public caller-owned tuning-buffer setter/getter unchanged. Unknown
|
||||
library versions retain their ordinary implementation and RAM requirements.
|
||||
"""
|
||||
|
||||
import hashlib
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
|
||||
|
||||
FILES = {
|
||||
"vl53l0x_tuning.h": "0e0331b7df1084d183248355f75d835b3446200b22f71765b5c63a470ff01c63",
|
||||
"vl53l0x_interrupt_threshold_settings.h": "9e5e6c00af66497d03d6c6a13a269521c12b33c90455efcd3b8494487e1780c2",
|
||||
"vl53l0x_api_core.h": "948de4a0363339facc58c4e1bc5781b954b99cca1c13a4a105eb3969aeba8653",
|
||||
"core/src/vl53l0x_api_core.cpp": "d31da82edbad0f7fd89106340f7a006b61cd2e5b7c353460fb394978ce55953b",
|
||||
"core/src/vl53l0x_api.cpp": "6cfa0784600bd797e372b511761f4be10e97264b55d5c7269dd41ba607b8edb7",
|
||||
}
|
||||
REPLACEMENTS = {
|
||||
"vl53l0x_tuning.h": ("uint8_t DefaultTuningSettings[]", "const uint8_t DefaultTuningSettings[]"),
|
||||
"vl53l0x_interrupt_threshold_settings.h": (
|
||||
"uint8_t InterruptThresholdSettings[]", "const uint8_t InterruptThresholdSettings[]"),
|
||||
"vl53l0x_api_core.h": ("uint8_t* pTuningSettingBuffer);", "const uint8_t* pTuningSettingBuffer);"),
|
||||
"core/src/vl53l0x_api_core.cpp": (
|
||||
"uint8_t* pTuningSettingBuffer) {", "const uint8_t* pTuningSettingBuffer) {"),
|
||||
"core/src/vl53l0x_api.cpp": ("uint8_t* pTuningSettingBuffer;", "const uint8_t* pTuningSettingBuffer;"),
|
||||
}
|
||||
|
||||
|
||||
def digest(text):
|
||||
return hashlib.sha256(text.encode("utf-8")).hexdigest()
|
||||
|
||||
|
||||
def patched_files(source_root):
|
||||
result = {}
|
||||
for name, expected in FILES.items():
|
||||
text = (source_root / name).read_text(encoding="utf-8").replace("\r\n", "\n")
|
||||
old, new = REPLACEMENTS[name]
|
||||
if digest(text) != expected or text.count(old) != 1:
|
||||
raise RuntimeError("changed reviewed VL53L0X dependency: " + name)
|
||||
result[name] = text.replace(old, new, 1)
|
||||
return result
|
||||
|
||||
|
||||
def write_if_changed(path, content):
|
||||
if not path.exists() or path.read_text(encoding="utf-8") != content:
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_text(content, encoding="utf-8")
|
||||
|
||||
|
||||
def replace_vl53_source(build_env, node):
|
||||
source = Path(node.srcnode().get_abspath())
|
||||
source_root = next((parent for parent in source.parents
|
||||
if parent.name == "src" and parent.parent.name == "Adafruit_VL53L0X"), None)
|
||||
if source_root is None or source.suffix != ".cpp":
|
||||
return node
|
||||
try:
|
||||
patches = patched_files(source_root)
|
||||
except (OSError, UnicodeError, RuntimeError) as error:
|
||||
print("nRF52 VL53L0X const tables: ordinary source retained (" + str(error) + ")")
|
||||
return node
|
||||
destination = Path(build_env.subst("$BUILD_DIR")) / "readonly-nrf52-vl53l0x" / "src"
|
||||
# Keep every quoted sibling/relative include inside the same private copy.
|
||||
# All compilation units therefore see the same const loader declaration.
|
||||
for path in source_root.rglob("*"):
|
||||
if not path.is_file():
|
||||
continue
|
||||
relative = path.relative_to(source_root)
|
||||
output = destination / relative
|
||||
if relative.as_posix() in patches:
|
||||
write_if_changed(output, patches[relative.as_posix()])
|
||||
elif not output.exists() or output.read_bytes() != path.read_bytes():
|
||||
output.parent.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copyfile(path, output)
|
||||
return build_env.File(str(destination / source.relative_to(source_root)))
|
||||
|
||||
|
||||
def install(build_env):
|
||||
build_env.AddBuildMiddleware(replace_vl53_source, "*Adafruit_VL53L0X*/*.cpp")
|
||||
Reference in new issue
Block a user