Add adaptive RAK4631 SD storage to full firmware profiles

This commit is contained in:
mikecarper committed 2026-10-16 01:18:26 -07:00
1 parent 9181e3e0ec
commit 774c2adc80
54 files changed
+3962 -477

No files matched your search

+30 -23
View File
@@ -26,6 +26,7 @@ ROOT = Path(__file__).resolve().parents[2]
OUT = ROOT / "src" / "helpers" / "ota" / "OtaTargets.h"
INTERNAL_BOOTLOADER_TARGETS = ROOT / "tools" / "mota" / "nrf52_internal_bootloader_targets.txt"
NAME_DECODE_CHUNK_SIZE = 512
RAK_FULL_NAME_DECODE_CHUNK_SIZE = 4096
def resolved_config():
@@ -126,9 +127,22 @@ def _compressed_name_chunks(rows, max_chunk_size):
def generate_header(rows):
data, offsets, raw_lengths, firsts = compressed_name_chunks(rows)
capacity = max((len(name.encode("utf-8")) + 1 for _, name in rows), default=1)
def chunk_tables(chunk_size):
data, offsets, raw_lengths, firsts = compressed_name_chunks(rows, chunk_size)
lines = [f" enum {{ DECODE_CHUNK_BYTES = {chunk_size} }};"]
for name, values in (("OFFSETS", offsets), ("RAW_LENGTHS", raw_lengths), ("FIRSTS", firsts)):
lines += [f" static const uint16_t {name}[] = {{"]
lines += [" " + ", ".join(str(value) for value in values[i:i + 12]) + ","
for i in range(0, len(values), 12)]
lines += [" };"]
lines += [f" // {len(data)} encoded bytes; {len(raw_lengths)} independent chunks, at most {chunk_size} decoded bytes.",
" static const uint8_t NAMES[] = {"]
lines += [" " + ", ".join(f"0x{byte:02x}" for byte in data[i:i + 16]) + ","
for i in range(0, len(data), 16)]
return lines + [" };"]
out = [
"#pragma once",
"#include <stdint.h>",
@@ -151,6 +165,9 @@ def generate_header(rows):
"",
"#if OTA_TARGET_NAME_TABLE && OTA_TARGET_NAME_FRONT_CODED",
' #include "tinf/tinf.h"',
" #if defined(OTA_RAK15002_SD_STORE) && defined(COMPANION_RADIO_FULL)",
" #include <stdlib.h>",
" #endif",
"#endif",
"",
"namespace mesh { namespace ota {",
@@ -167,33 +184,23 @@ def generate_header(rows):
]
out += [" " + ", ".join(f"0x{tid:08x}" for tid, _ in rows[i:i + 8]) + ","
for i in range(0, len(rows), 8)]
out += [" };", "#if defined(OTA_RAK15002_SD_STORE) && defined(COMPANION_RADIO_FULL)"]
out += chunk_tables(RAK_FULL_NAME_DECODE_CHUNK_SIZE)
out += ["#else"] + chunk_tables(NAME_DECODE_CHUNK_SIZE) + ["#endif"]
out += [
" };",
" static const uint16_t OFFSETS[] = {",
]
out += [" " + ", ".join(str(offset) for offset in offsets[i:i + 12]) + ","
for i in range(0, len(offsets), 12)]
out += [" };", " static const uint16_t RAW_LENGTHS[] = {"]
out += [" " + ", ".join(str(length) for length in raw_lengths[i:i + 12]) + ","
for i in range(0, len(raw_lengths), 12)]
out += [" };", " static const uint16_t FIRSTS[] = {"]
out += [" " + ", ".join(str(first) for first in firsts[i:i + 12]) + ","
for i in range(0, len(firsts), 12)]
out += [
" };",
f" // {len(data)} encoded bytes; {len(raw_lengths)} independent chunks, at most {NAME_DECODE_CHUNK_SIZE} decoded bytes.",
" static const uint8_t NAMES[] = {",
]
out += [" " + ", ".join(f"0x{byte:02x}" for byte in data[i:i + 16]) + ","
for i in range(0, len(data), 16)]
out += [
" };",
" for (unsigned i = 0; i < sizeof(IDS) / sizeof(IDS[0]); i++) {",
" if (IDS[i] != target_id) continue;",
" unsigned group = 0;",
" while (i >= FIRSTS[group + 1]) group++;",
f" uint8_t raw[{NAME_DECODE_CHUNK_SIZE}];",
" unsigned int produced = sizeof raw;",
"#if defined(OTA_RAK15002_SD_STORE) && defined(COMPANION_RADIO_FULL)",
" // Rare display lookup: larger chunks save flash without growing the loop stack.",
" uint8_t* raw = (uint8_t*)malloc(DECODE_CHUNK_BYTES);",
" if (!raw) return nullptr;",
" struct Scratch { uint8_t* bytes; ~Scratch() { free(bytes); } } scratch = {raw};",
"#else",
" uint8_t raw[DECODE_CHUNK_BYTES];",
"#endif",
" unsigned int produced = DECODE_CHUNK_BYTES;",
" if (tinf_uncompress_exact(raw, &produced, NAMES + OFFSETS[group],",
" OFFSETS[group + 1] - OFFSETS[group]) != TINF_OK ||",
" produced != RAW_LENGTHS[group]) return nullptr;",
@@ -3,7 +3,10 @@
# shared allowlist for build.sh release aliases and the subset that are also
# literal PlatformIO envs. Synthetic aliases are activated by build.sh.
# External QSPI/SD, internal ExtraFS, seeder-only, Ethernet, and full-sensor
# roles are intentionally absent.
# roles are intentionally absent, except for the explicitly listed RAK4631
# adaptive receiver aliases below. Their optional RAK15002 SD path retains
# the existing internal/NOR shared-slot contract and must use the matching
# all-in-one OTAFIX loader; it is not a generic SD-primary profile.
Heltec_tower_v2_repeater_lora_ota_no_external_sensors
Heltec_t096_repeater_lora_ota_no_external_sensors
Heltec_t096_repeater_bridge_rs232_lora_ota_no_external_sensors
@@ -20,6 +23,9 @@ ThinkNode_M3_repeater_lora_ota_no_external_sensors
RAK_3401_repeater_lora_ota_no_external_sensors
RAK_4631_repeater_lora_ota_no_external_sensors
RAK_4631_repeater_unified_lora_ota
RAK_4631_room_server_lora_ota_no_external_sensors
RAK_4631_room_server_ethernet_lora_ota_no_external_sensors
RAK_4631_sensor_lora_ota_no_external_sensors
RAK_3401_repeater_unified_lora_ota
RAK_4631_repeater_bridge_rs232_serial1_lora_ota_no_external_sensors
RAK_4631_repeater_bridge_rs232_serial2_lora_ota_no_external_sensors
+10 -2
View File
@@ -268,9 +268,18 @@ def _append_endf_hex(source, target, env): # Intel-HEX path (nRF52: app f
linked_app_end = app_start + app_region_size
internal_extrafs = (_cppdef("EXTRAFS") is not None and _cppdef("QSPIFLASH") is None
and _builds_companion_radio())
sd_backed = _cppdef("OTA_SD_STORE") is not None
sd_enabled = _cppdef("OTA_SD_STORE") is not None
qspi_backed = _cppdef("OTA_QSPI_STORE") is not None
auto_store = _cppdef("OTA_RAK_AUTO_STORE") is not None
seeder_only = _cppdef("OTA_SEEDER_ONLY") is not None
optional_rak_sd = _cppdef("OTA_RAK15002_SD_STORE") is not None
if optional_rak_sd and (not sd_enabled or _cppdef("RAK_4631") is None or
not (auto_store or (seeder_only and _builds_companion_radio()))):
raise RuntimeError("optional RAK15002 SD requires an exact RAK4631 adaptive receiver or source-only Companion")
# Optional SD does not change the frozen application layout: receivers
# retain AUTO+HYBRID internal staging, and Full Companion retains ExtraFS.
# The runtime selects SD only after validating its separate loader ABI.
sd_backed = sd_enabled and not optional_rak_sd
qspi_bootloader_update = _cppdef("OTA_QSPI_BOOTLOADER_UPDATE") is not None
hybrid_ram = _cppdef("OTA_HYBRID_RAM_STORE") is not None
internal_bootloader_update = _cppdef("OTA_INTERNAL_BOOTLOADER_UPDATE") is not None
@@ -315,7 +324,6 @@ def _append_endf_hex(source, target, env): # Intel-HEX path (nRF52: app f
body = ml.ensure_nrf52_layout(endf_free_body, layout)
ident = _firmware_ident()
out, h8 = ml.ensure_endf(body, ident)
seeder_only = _cppdef("OTA_SEEDER_ONLY") is not None
if seeder_only:
# A source-only full Companion never stages or applies an update to
# itself, so it does not need to fit in OTAFIX's in-place workspace.
+25 -4
View File
@@ -52,7 +52,16 @@ def test_internal_bootloader_target_wiring_is_central_and_not_duplicated():
if line.strip() and not line.lstrip().startswith("#")
]
assert len(inventory) == len(set(inventory))
assert len(inventory) == 23
# The RAK4631 adaptive RAK15002 receiver contract deliberately adds the
# three generated receiver roles to the established exact inventory. Keep
# the count and the names fixed so an unrelated target cannot silently
# acquire the retained-RAM / internal-bootloader-update layout.
assert len(inventory) == 26
assert {
"RAK_4631_room_server_lora_ota_no_external_sensors",
"RAK_4631_room_server_ethernet_lora_ota_no_external_sensors",
"RAK_4631_sensor_lora_ota_no_external_sensors",
} <= set(inventory)
gat_targets = {
"GAT562_30S_Mesh_Kit_repeater_lora_ota_no_external_sensors",
"GAT562_Mesh_Tracker_Pro_repeater_lora_ota_no_external_sensors",
@@ -1019,13 +1028,25 @@ def test_ota_target_generation_honors_explicit_disable():
def test_rak_nrf52_ota_profiles_keep_ina_and_gps_where_uart_is_available():
root = Path(__file__).resolve().parents[2]
def env_section(path, name):
def section(path, header):
text = path.read_text(encoding="utf-8")
return text.split(f"[env:{name}]", 1)[1].split("\n[", 1)[0]
return text.split(f"[{header}]", 1)[1].split("\n[", 1)[0]
def env_section(path, name):
return section(path, f"env:{name}")
rak4631_path = root / "variants/rak4631/platformio.ini"
rak4631_reduced = section(rak4631_path, "rak4631_repeater_reduced_ota_base")
rak4631_reduced_wrapper = env_section(
rak4631_path, "RAK_4631_repeater_lora_ota_no_external_sensors"
)
# The adaptive storage flags live in the wrapper; the pre-adaptive base
# remains the single source of the reduced INA/GPS contract and is also
# deliberately reused by the strict historical SD cache seeder.
assert "${rak4631_repeater_reduced_ota_base.build_flags}" in rak4631_reduced_wrapper
assert "${rak4631_repeater_reduced_ota_base.lib_deps}" in rak4631_reduced_wrapper
gps_profiles = (
env_section(rak4631_path, "RAK_4631_repeater_lora_ota_no_external_sensors"),
rak4631_reduced,
env_section(
rak4631_path,
"RAK_4631_repeater_bridge_rs232_serial2_lora_ota_no_external_sensors",