From d8ba64da55323200bbc860f0b112638132ee34d4 Mon Sep 17 00:00:00 2001 From: bonamin Date: Thu, 19 Mar 2026 21:01:17 +0200 Subject: [PATCH] fix: NVS Generator. cosmetic: Changed CloudFlash page a bit --- backend/public/router.py | 6 +++ backend/utils/nvs_generator.py | 22 ++++++----- frontend/src/cloudflash/CloudFlashPage.jsx | 44 ++++++++++++++++------ 3 files changed, 52 insertions(+), 20 deletions(-) diff --git a/backend/public/router.py b/backend/public/router.py index 55d237e..c34f1d6 100644 --- a/backend/public/router.py +++ b/backend/public/router.py @@ -123,6 +123,11 @@ class NvsRequest(BaseModel): serial_number: str hw_type: str hw_revision: str + nvs_schema: str = "new" # "legacy" | "new" + + @property + def legacy(self) -> bool: + return self.nvs_schema == "legacy" @router.post("/cloudflash/nvs.bin") @@ -149,6 +154,7 @@ async def generate_public_nvs(body: NvsRequest): serial_number=sn, hw_family=hw_type, hw_revision=hw_revision, + legacy=body.legacy, ) except Exception as e: raise HTTPException(status_code=500, detail=f"NVS generation failed: {str(e)}") diff --git a/backend/utils/nvs_generator.py b/backend/utils/nvs_generator.py index b2b72cb..4b7262d 100644 --- a/backend/utils/nvs_generator.py +++ b/backend/utils/nvs_generator.py @@ -177,17 +177,16 @@ def _build_page(entries: List[bytes], slot_counts: List[int], seq: int = 0) -> b return page -def generate(serial_number: str, hw_family: str, hw_revision: str) -> bytes: +def generate(serial_number: str, hw_family: str, hw_revision: str, legacy: bool = False) -> bytes: """Generate a 0x5000-byte NVS partition binary for a Vesper device. serial_number: full SN string e.g. 'BSVSPR-26C13X-STD01R-X7KQA' hw_family: board family e.g. 'vesper-standard', 'vesper-plus' hw_revision: hardware revision string e.g. '1.0' - - Writes the schema keys expected by ConfigManager (struct DeviceConfig): - serial ← full serial number - hw_family ← board family (lowercase) - hw_revision ← hardware revision string + legacy: if True, writes old key names expected by legacy firmware (pre-new-schema): + device_uid, hw_type, hw_version + if False (default), writes new key names: + serial, hw_family, hw_revision Returns raw bytes ready to flash at 0x9000. """ @@ -195,9 +194,14 @@ def generate(serial_number: str, hw_family: str, hw_revision: str) -> bytes: # Build entries for namespace "device_id" ns_entry, ns_span = _build_namespace_entry("device_id", ns_index) - uid_entry, uid_span = _build_string_entry(ns_index, "serial", serial_number) - hwt_entry, hwt_span = _build_string_entry(ns_index, "hw_family", hw_family.lower()) - hwv_entry, hwv_span = _build_string_entry(ns_index, "hw_revision", hw_revision) + if legacy: + uid_entry, uid_span = _build_string_entry(ns_index, "device_uid", serial_number) + hwt_entry, hwt_span = _build_string_entry(ns_index, "hw_type", hw_family.lower()) + hwv_entry, hwv_span = _build_string_entry(ns_index, "hw_version", hw_revision) + else: + uid_entry, uid_span = _build_string_entry(ns_index, "serial", serial_number) + hwt_entry, hwt_span = _build_string_entry(ns_index, "hw_family", hw_family.lower()) + hwv_entry, hwv_span = _build_string_entry(ns_index, "hw_revision", hw_revision) entries = [ns_entry, uid_entry, hwt_entry, hwv_entry] spans = [ns_span, uid_span, hwt_span, hwv_span] diff --git a/frontend/src/cloudflash/CloudFlashPage.jsx b/frontend/src/cloudflash/CloudFlashPage.jsx index 13f9c84..8f14757 100644 --- a/frontend/src/cloudflash/CloudFlashPage.jsx +++ b/frontend/src/cloudflash/CloudFlashPage.jsx @@ -130,7 +130,7 @@ function ProgressBar({ label, percent }) { {label} {Math.round(percent)}% -
+
0 ? `Firmware (${Math.round(fwPct)}%)` : + nvsPct > 0 ? `Device Identity (${Math.round(nvsPct)}%)` : + partPct > 0 ? `Partition Table (${Math.round(partPct)}%)` : + `Bootloader (${Math.round(blPct)}%)`; + + return ( +
+
+ {label} + {Math.round(overall)}% +
+
+
+
+
+ ); +} + function InfoBox({ type = "info", children }) { const styles = { info: { bg: "var(--badge-blue-bg)", border: "#1e3a5f", color: "var(--badge-blue-text)" }, @@ -858,17 +884,13 @@ function StepFlash({ firmware, flashType, serial, nvsSchema, onDone }) {
)} - {/* Progress bars */} + {/* Progress bar */} {(flashing || fwPct > 0) && ( -
- {isFullWipe && ( - <> - - - - - )} - +
+ {isFullWipe + ? + : + }
)}