Add opt-in combined RAK4631 Ethernet test image

Keep Full sensors, UART2, adaptive OTA storage and the 8 KiB loop stack. Arbitrate shared SPI and OTA workspace ownership, move network waits into a worker, and use bounded queued TCP operations. Add reproducible test configs, RAM checks and regression coverage. Validated the Full build, UF2 layout and 29 sanitizer runtime scenarios.
This commit is contained in:
mikecarper committed 2026-10-08 13:53:31 -07:00
1 parent 57036b1d66
commit df88a6ef95
31 files changed
+3581 -8

No files matched your search

+42 -1
View File
@@ -62,11 +62,28 @@ def requirements(platform, defines, target):
else:
raise ValueError(f"add a runtime allocation budget for display {display!r}")
parts = {}
combined_rak_ethernet = "RAK4631_COMBINED_ETHERNET" in defines
if combined_rak_ethernet and (platform != "NRF52_PLATFORM"
or not {"RAK_4631", "ETHERNET_ENABLED", "OTA_RAK_AUTO_STORE"}.issubset(defines)):
raise ValueError("combined RAK Ethernet budget requires RAK4631 adaptive nRF52 storage")
if combined_rak_ethernet and display == "SSD1306Display":
# The fixed 128x64 driver allocates one 1024-byte framebuffer and
# reuses it after power cycling. Its linked source assertion binds
# framebuffer + complete driver object + allocator overhead to 2 KiB.
# The actual linked ARM driver is 156 bytes; it is already static,
# so including it here again retains a conservative allocation bound.
display_heap = 2048
if platform == "NRF52_PLATFORM":
parts["loop_and_callback_stacks"] = integer(defines, "MESH_NRF52_LOOP_STACK_WORDS", 2048) * 4 + 3072
parts["core_usb_filesystems_sensors"] = 12288
if "BLE_PIN_CODE" in defines:
parts["bluetooth_worker_stacks"] = 5920
if combined_rak_ethernet and "WITH_RS232_BRIDGE" in defines:
# The bridge owns a packet/ACK duplicate table as well as its RX
# frame. Its source assertion bounds the object to 2304 bytes;
# retain room for allocation metadata and the UART TX semaphore.
# UART RX/TX arrays are embedded in the already-linked globals.
parts["uart_bridge_and_driver"] = 2560
elif platform == "ESP32_PLATFORM":
parts["core_tasks_usb_filesystems"] = 24576
wifi = 49152 if "WIFI_SSID" in defines or "WIFI_OTA_SEEDER" in defines else 0
@@ -133,6 +150,29 @@ def requirements(platform, defines, target):
# 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 combined_rak_ethernet:
words = integer(defines, "RAK4631_ETHERNET_TASK_STACK_WORDS", 1024)
if words < 1024:
raise ValueError("combined RAK Ethernet task requires at least 1024 stack words")
tx_capacity = integer(defines, "ETHERNET_CLI_TX_BUFFER_BYTES", 512)
if not 512 <= tx_capacity <= 2048:
raise ValueError("combined RAK Ethernet TX queue requires 512..2048 bytes")
# Ethernet owns the shared bus only after rejecting live/pinned OTA
# sessions and freeing the external self-source buffers. While it owns
# that bus, OTA encoder/self-source entry points refuse allocation.
# On shutdown the main loop deletes the parked worker synchronously
# and frees its TX queue before releasing ownership, so its stack
# cannot await idle cleanup
# while external OTA workspaces are allocated again.
# UART can remain enabled in either mode, so its budget stays above.
# The library's function-static DHCP object and SPI/socket globals are
# already present in the linked image. The bounded TCP TX queue is
# allocated only while Ethernet is enabled; reserve its capacity plus
# 64 bytes for allocator overhead alongside the worker stack and TCB.
external_ota = sum(parts.pop(name, 0) for name in (
"ota_encoder_workspace", "ota_self_source_scratch"))
parts["ethernet_or_external_ota_workspaces"] = max(words * 4 + 256 + tx_capacity + 64,
external_ota)
if display and display != "NullDisplayDriver":
parts["display_pixels_and_driver"] = display_heap
screen_budget = integer(defines, "MESH_COMPANION_SCREEN_STARTUP_BYTES", 0)
@@ -164,7 +204,8 @@ 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_encoder_workspace"):
"ota_context", "screen_objects_and_history", "ota_encoder_workspace",
"ethernet_or_external_ota_workspaces"):
largest = max(largest, parts.get(name, 0))
return {"required_heap_bytes": required, "required_contiguous_bytes": largest,
"components": parts, "display": display, "full_companion": full}
+134
View File
@@ -0,0 +1,134 @@
#!/usr/bin/env python3
"""Generate matched local RAK4631 baseline/combined test configs, without building.
The production environment and release artifacts are left untouched. The four
configs retain the unified target's OTA identity, 8 KiB loop stack, 63 flood rules
and exact board recipe. Full/Reduced sensor flags come from build.sh's normal
helpers. Run the printed PlatformIO commands individually; this checkout permits
only one PlatformIO process at a time. Preserve each build's outputs before the
next command reuses its environment directory.
"""
from __future__ import annotations
import argparse
import configparser
from datetime import datetime, timezone
import hashlib
import json
import os
from pathlib import Path
import re
import shlex
import subprocess
ROOT = Path(__file__).resolve().parents[1]
TARGET = "RAK_4631_repeater_unified_lora_ota"
ETHERNET_LIBRARY = "https://github.com/RAKWireless/RAK13800-W5100S/archive/1.0.2.zip"
PROFILE_HELPERS = r'''
set -euo pipefail
source build.sh
target=RAK_4631_repeater_unified_lora_ota
PIO_ENV_PLATFORM_BY_NAME[$target]=NRF52_PLATFORM
PIO_ENV_QSPI_OTA_BY_NAME[$target]=1
PIO_ENV_OTA_BY_NAME[$target]=1
PIO_ENV_SD_OTA_BY_NAME[$target]=0
NRF52_OTA_SENSOR_PROFILE=$MESH_TRIAL_SENSOR_PROFILE
SKIP_DECLARED_REDUCTIONS=$([ "$NRF52_OTA_SENSOR_PROFILE" = full ] && printf 1 || printf 0)
DISABLE_DEBUG=1
PLATFORMIO_BUILD_FLAGS=''
PLATFORMIO_BUILD_UNFLAGS=''
disable_debug_flags "$target"
apply_nrf52_size_profile "$target"
apply_lora_ota_no_external_sensors_profile "$target"
apply_radio_overrides
apply_firmware_profile_overrides
export PLATFORMIO_BUILD_FLAGS PLATFORMIO_BUILD_UNFLAGS
python3 -c 'import json,os;print(json.dumps({name:os.environ.get(name, "") for name in ("PLATFORMIO_BUILD_FLAGS","PLATFORMIO_BUILD_UNFLAGS")}))'
'''
def profile_flags(sensor: str) -> dict[str, str]:
# No project-context initialization, build worker or PlatformIO invocation.
environment = {**os.environ, "MESH_TRIAL_SENSOR_PROFILE": sensor,
"FIRMWARE_PROFILE_OVERRIDE": "cascade",
"RADIO_FREQ_OVERRIDE": "910.525", "RADIO_BW_OVERRIDE": "62.5",
"RADIO_SF_OVERRIDE": "7", "RADIO_CR_OVERRIDE": "5",
"RADIO_SETTING_TITLE": "USA Cascadia"}
result = subprocess.run(["bash", "-c", PROFILE_HELPERS], cwd=ROOT,
env=environment, capture_output=True, text=True, check=True)
values = json.loads(result.stdout.splitlines()[-1])
if set(values) != {"PLATFORMIO_BUILD_FLAGS", "PLATFORMIO_BUILD_UNFLAGS"}:
raise ValueError("unexpected build-profile helper output")
return values
def generate(output: Path, firmware_version: str) -> dict:
output = output.expanduser().resolve()
if output == ROOT or ROOT in output.parents:
raise ValueError("put experimental configs outside the repository and release output")
if not re.fullmatch(r"[A-Za-z0-9][A-Za-z0-9._+-]*", firmware_version):
raise ValueError("firmware version must contain only letters, digits, dots, underscores, plus or minus")
source = (ROOT / "platformio.ini").read_text()
extra_configs = " variants/*/platformio.ini\n platformio.local.ini"
if source.count(extra_configs) != 1:
raise ValueError("main extra_configs changed; refusing a disconnected trial config")
variant = configparser.ConfigParser(interpolation=None, inline_comment_prefixes=(";",))
variant.read(ROOT / "variants/rak4631/platformio.ini")
raw_flags = variant["env:" + TARGET]["build_flags"]
mota_id = "0x%08x" % int.from_bytes(hashlib.sha256(TARGET.encode()).digest()[:4], "little")
output.mkdir(parents=True, exist_ok=True)
profiles, configs = {}, []
for sensor in ("full", "reduced"):
flags = profile_flags(sensor)
profiles[sensor] = flags
for combined in (False, True):
name = ("combined" if combined else "baseline") + ("" if sensor == "full" else "-reduced")
common = (f"-DFIRMWARE_VERSION='\"{firmware_version}\"' "
f"-DOTA_VARIANT='\"{TARGET}\"' -DMOTA_TARGET_ID={mota_id}")
build_flags = raw_flags + "\n" + flags["PLATFORMIO_BUILD_FLAGS"] + " " + common
if combined:
build_flags += " -DETHERNET_ENABLED=1 -DRAK4631_COMBINED_ETHERNET=1"
overlay = "[env:" + TARGET + "]\nbuild_flags =\n"
overlay += "\n".join(" " + line.strip() for line in build_flags.splitlines() if line.strip()) + "\n"
overlay += "build_unflags = " + flags["PLATFORMIO_BUILD_UNFLAGS"].strip() + "\n"
if combined:
overlay += "lib_deps = ${rak4631.lib_deps}\n " + ETHERNET_LIBRARY + "\n"
overlay_path = output / ("overlay-" + name + ".ini")
overlay_path.write_text(overlay)
config = source.replace(extra_configs,
" " + str(ROOT / "variants/*/platformio.ini") + "\n"
" " + str(ROOT / "platformio.local.ini") + "\n"
" " + str(overlay_path))
config_path = output / ("platformio-" + name + ".ini")
config_path.write_text(config)
configs.append({"profile": name, "config": str(config_path),
"config_sha256": hashlib.sha256(config.encode()).hexdigest(),
"overlay_sha256": hashlib.sha256(overlay.encode()).hexdigest()})
source_commit = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=ROOT, text=True).strip()
receipt = {"schema_version": 1, "target": TARGET, "mota_target_id": mota_id,
"firmware_version": firmware_version, "full_rule_capacity": 63,
"loop_stack_bytes": 8192, "source_commit": source_commit,
"profiles": profiles, "configs": configs,
"scope": "Local config generation only; builds and hardware acceptance remain required."}
(output / "profile-flags.json").write_text(json.dumps(receipt, indent=2) + "\n")
return receipt
def main() -> int:
parser = argparse.ArgumentParser(description=__doc__)
default = Path.home() / ".cache" / ("meshcore-rak-combined-" + datetime.now(timezone.utc).strftime("%Y%m%d"))
parser.add_argument("--output", type=Path, default=default)
parser.add_argument("--firmware-version", default="v1.17.1.9-rak-combined-trial")
args = parser.parse_args()
receipt = generate(args.output, args.firmware_version)
for config in receipt["configs"]:
print(" ".join(shlex.quote(value) for value in (
"pio", "run", "-d", str(ROOT), "-c", config["config"], "-e", TARGET)))
return 0
if __name__ == "__main__":
raise SystemExit(main())