Unify RAK repeater storage firmware and bootloader handoff

This commit is contained in:
mikecarper committed 2026-09-25 10:35:04 -07:00
1 parent 7a8bddda53
commit fca10471c3
27 files changed
+723 -29

No files matched your search

+9 -1
View File
@@ -86,6 +86,7 @@ NRF52_LAYOUT_FLAG_INTERNAL_EXTRAFS = 0x02
NRF52_LAYOUT_FLAG_QSPI = 0x04
NRF52_LAYOUT_FLAG_BOOTLOADER_SCRATCH = 0x08
NRF52_LAYOUT_FLAG_HYBRID_RAM = 0x10
NRF52_LAYOUT_FLAG_AUTO_STORE = 0x20
XIAO_BOOT_BOARD_ID_BASE = 0x28860044
XIAO_BOOT_BOARD_ID_SENSE = 0x28860045
@@ -309,6 +310,10 @@ class Nrf52Layout:
def hybrid_ram(self) -> bool:
return bool(self.flags & NRF52_LAYOUT_FLAG_HYBRID_RAM)
@property
def auto_store(self) -> bool:
return bool(self.flags & NRF52_LAYOUT_FLAG_AUTO_STORE)
def nrf52_stage_ceiling_for_layout(linked_app_end: int, uses_internal_extrafs: bool) -> int:
"""Select a safe staging ceiling from linker geometry and actual secondary-storage type."""
if uses_internal_extrafs:
@@ -357,11 +362,14 @@ def build_nrf52_layout(layout: Nrf52Layout) -> bytes:
raise ValueError("invalid nRF52 app region")
known_flags = (NRF52_LAYOUT_FLAG_SD | NRF52_LAYOUT_FLAG_INTERNAL_EXTRAFS |
NRF52_LAYOUT_FLAG_QSPI | NRF52_LAYOUT_FLAG_BOOTLOADER_SCRATCH |
NRF52_LAYOUT_FLAG_HYBRID_RAM)
NRF52_LAYOUT_FLAG_HYBRID_RAM | NRF52_LAYOUT_FLAG_AUTO_STORE)
if layout.flags & ~known_flags:
raise ValueError(f"unsupported nRF52 layout flags 0x{layout.flags:X}")
if layout.sd_backed and layout.qspi_backed:
raise ValueError("nRF52 layout cannot use both SD and QSPI staging")
if layout.auto_store and (layout.sd_backed or layout.qspi_backed or
layout.flags & NRF52_LAYOUT_FLAG_INTERNAL_EXTRAFS):
raise ValueError("nRF52 adaptive staging has its own exclusive layout flag")
if layout.external_backed and layout.flags & NRF52_LAYOUT_FLAG_INTERNAL_EXTRAFS:
raise ValueError("nRF52 external staging cannot also reserve internal ExtraFS")
if layout.hybrid_ram:
@@ -19,6 +19,8 @@ t1000e_repeater_lora_ota_no_external_sensors
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_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
GAT562_Mesh_Tracker_Pro_repeater_lora_ota_no_external_sensors
+8 -3
View File
@@ -265,6 +265,7 @@ def _append_endf_hex(source, target, env): # Intel-HEX path (nRF52: app f
and _builds_companion_radio())
sd_backed = _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
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
@@ -276,6 +277,9 @@ def _append_endf_hex(source, target, env): # Intel-HEX path (nRF52: app f
env["PROJECT_DIR"])
if sd_backed and qspi_backed:
raise RuntimeError("nRF52 build cannot enable both SD and QSPI OTA stores")
if auto_store and (not qspi_backed or _cppdef("OTA_FLASH_STORE") is None or
not hybrid_ram or not internal_bootloader_update):
raise RuntimeError("RAK adaptive OTA requires both stores and retained-RAM internal support")
if qspi_backed and _cppdef("QSPIFLASH") is not None:
raise RuntimeError("raw QSPI OTA staging cannot share a chip with QSPIFLASH")
if qspi_bootloader_update:
@@ -285,7 +289,7 @@ def _append_endf_hex(source, target, env): # Intel-HEX path (nRF52: app f
if linked_app_end != ml.NRF52_BOOT_SCRATCH_START:
raise RuntimeError("bootloader-update build must link exactly below scratch at 0xE0000")
if internal_bootloader_update:
if sd_backed or qspi_backed or _cppdef("QSPIFLASH") is not None or internal_extrafs:
if sd_backed or (qspi_backed and not auto_store) or _cppdef("QSPIFLASH") is not None or internal_extrafs:
raise RuntimeError("internal bootloader update cannot use SD/QSPI/ExtraFS")
if linked_app_end != ml.NRF52_APP_END:
raise RuntimeError("shared-slot bootloader update requires the normal 0xED000 linker ceiling")
@@ -297,10 +301,11 @@ def _append_endf_hex(source, target, env): # Intel-HEX path (nRF52: app f
stage_ceiling = (ml.NRF52_APP_END if (sd_backed or qspi_backed) else
ml.nrf52_stage_ceiling_for_layout(linked_app_end, internal_extrafs))
layout_flags = ((ml.NRF52_LAYOUT_FLAG_SD if sd_backed else 0) |
(ml.NRF52_LAYOUT_FLAG_QSPI if qspi_backed else 0) |
(ml.NRF52_LAYOUT_FLAG_QSPI if qspi_backed and not auto_store else 0) |
(ml.NRF52_LAYOUT_FLAG_INTERNAL_EXTRAFS if internal_extrafs else 0) |
(ml.NRF52_LAYOUT_FLAG_BOOTLOADER_SCRATCH if qspi_bootloader_update else 0) |
(ml.NRF52_LAYOUT_FLAG_HYBRID_RAM if hybrid_ram else 0))
(ml.NRF52_LAYOUT_FLAG_HYBRID_RAM if hybrid_ram else 0) |
(ml.NRF52_LAYOUT_FLAG_AUTO_STORE if auto_store else 0))
layout = ml.Nrf52Layout(app_start, linked_app_end, stage_ceiling, layout_flags)
body = ml.ensure_nrf52_layout(raw_body, layout)
ident = _firmware_ident()
+14 -1
View File
@@ -52,7 +52,7 @@ 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) == 21
assert len(inventory) == 23
gat_targets = {
"GAT562_30S_Mesh_Kit_repeater_lora_ota_no_external_sensors",
"GAT562_Mesh_Tracker_Pro_repeater_lora_ota_no_external_sensors",
@@ -66,6 +66,8 @@ def test_internal_bootloader_target_wiring_is_central_and_not_duplicated():
"Heltec_t096_repeater_lora_ota_no_external_sensors",
"Heltec_t114_repeater_lora_ota_no_external_sensors",
"RAK_3401_repeater_lora_ota_no_external_sensors",
"RAK_3401_repeater_unified_lora_ota",
"RAK_4631_repeater_unified_lora_ota",
} <= set(inventory)
target_header = (root / "src/helpers/ota/OtaTargets.h").read_text(encoding="utf-8")
@@ -1206,6 +1208,14 @@ def test_nrf52_layout_record_roundtrip_and_policy():
ml.ensure_nrf52_layout(_fw(10, 2048), hybrid))
assert ml.parse_nrf52_layout(hybrid_image) == hybrid
assert hybrid.hybrid_ram and not hybrid.external_backed
adaptive = ml.Nrf52Layout(
ml.NRF52_APP_BASE_S140_V6, ml.NRF52_APP_END,
ml.NRF52_APP_END,
ml.NRF52_LAYOUT_FLAG_HYBRID_RAM | ml.NRF52_LAYOUT_FLAG_AUTO_STORE)
adaptive_image, _ = ml.ensure_endf(
ml.ensure_nrf52_layout(_fw(11, 2048), adaptive))
assert ml.parse_nrf52_layout(adaptive_image) == adaptive
assert adaptive.auto_store and adaptive.hybrid_ram and not adaptive.external_backed
assert ml.build_nrf52_layout(hybrid) == bytes.fromhex(
"6d4f54414c617931011018000060020000d00e0000d00e00")
hybrid_v7 = ml.Nrf52Layout(
@@ -1228,6 +1238,9 @@ def test_nrf52_layout_record_roundtrip_and_policy():
ml.NRF52_LAYOUT_FLAG_HYBRID_RAM | ml.NRF52_LAYOUT_FLAG_QSPI,
ml.NRF52_LAYOUT_FLAG_HYBRID_RAM |
ml.NRF52_LAYOUT_FLAG_INTERNAL_EXTRAFS,
ml.NRF52_LAYOUT_FLAG_AUTO_STORE | ml.NRF52_LAYOUT_FLAG_QSPI,
ml.NRF52_LAYOUT_FLAG_AUTO_STORE | ml.NRF52_LAYOUT_FLAG_SD,
ml.NRF52_LAYOUT_FLAG_AUTO_STORE | ml.NRF52_LAYOUT_FLAG_INTERNAL_EXTRAFS,
):
try:
ml.build_nrf52_layout(ml.Nrf52Layout(