fix: NVS Generator. cosmetic: Changed CloudFlash page a bit
This commit is contained in:
@@ -123,6 +123,11 @@ class NvsRequest(BaseModel):
|
|||||||
serial_number: str
|
serial_number: str
|
||||||
hw_type: str
|
hw_type: str
|
||||||
hw_revision: 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")
|
@router.post("/cloudflash/nvs.bin")
|
||||||
@@ -149,6 +154,7 @@ async def generate_public_nvs(body: NvsRequest):
|
|||||||
serial_number=sn,
|
serial_number=sn,
|
||||||
hw_family=hw_type,
|
hw_family=hw_type,
|
||||||
hw_revision=hw_revision,
|
hw_revision=hw_revision,
|
||||||
|
legacy=body.legacy,
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise HTTPException(status_code=500, detail=f"NVS generation failed: {str(e)}")
|
raise HTTPException(status_code=500, detail=f"NVS generation failed: {str(e)}")
|
||||||
|
|||||||
@@ -177,17 +177,16 @@ def _build_page(entries: List[bytes], slot_counts: List[int], seq: int = 0) -> b
|
|||||||
return page
|
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.
|
"""Generate a 0x5000-byte NVS partition binary for a Vesper device.
|
||||||
|
|
||||||
serial_number: full SN string e.g. 'BSVSPR-26C13X-STD01R-X7KQA'
|
serial_number: full SN string e.g. 'BSVSPR-26C13X-STD01R-X7KQA'
|
||||||
hw_family: board family e.g. 'vesper-standard', 'vesper-plus'
|
hw_family: board family e.g. 'vesper-standard', 'vesper-plus'
|
||||||
hw_revision: hardware revision string e.g. '1.0'
|
hw_revision: hardware revision string e.g. '1.0'
|
||||||
|
legacy: if True, writes old key names expected by legacy firmware (pre-new-schema):
|
||||||
Writes the schema keys expected by ConfigManager (struct DeviceConfig):
|
device_uid, hw_type, hw_version
|
||||||
serial ← full serial number
|
if False (default), writes new key names:
|
||||||
hw_family ← board family (lowercase)
|
serial, hw_family, hw_revision
|
||||||
hw_revision ← hardware revision string
|
|
||||||
|
|
||||||
Returns raw bytes ready to flash at 0x9000.
|
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"
|
# Build entries for namespace "device_id"
|
||||||
ns_entry, ns_span = _build_namespace_entry("device_id", ns_index)
|
ns_entry, ns_span = _build_namespace_entry("device_id", ns_index)
|
||||||
uid_entry, uid_span = _build_string_entry(ns_index, "serial", serial_number)
|
if legacy:
|
||||||
hwt_entry, hwt_span = _build_string_entry(ns_index, "hw_family", hw_family.lower())
|
uid_entry, uid_span = _build_string_entry(ns_index, "device_uid", serial_number)
|
||||||
hwv_entry, hwv_span = _build_string_entry(ns_index, "hw_revision", hw_revision)
|
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]
|
entries = [ns_entry, uid_entry, hwt_entry, hwv_entry]
|
||||||
spans = [ns_span, uid_span, hwt_span, hwv_span]
|
spans = [ns_span, uid_span, hwt_span, hwv_span]
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ function ProgressBar({ label, percent }) {
|
|||||||
<span>{label}</span>
|
<span>{label}</span>
|
||||||
<span>{Math.round(percent)}%</span>
|
<span>{Math.round(percent)}%</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="h-2 rounded-full overflow-hidden" style={{ backgroundColor: "var(--bg-card-hover)" }}>
|
<div className="h-3 rounded-full overflow-hidden" style={{ backgroundColor: "var(--bg-card-hover)" }}>
|
||||||
<div
|
<div
|
||||||
className="h-full rounded-full transition-all duration-200"
|
className="h-full rounded-full transition-all duration-200"
|
||||||
style={{ width: `${percent}%`, backgroundColor: "var(--accent)" }}
|
style={{ width: `${percent}%`, backgroundColor: "var(--accent)" }}
|
||||||
@@ -140,6 +140,32 @@ function ProgressBar({ label, percent }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function CombinedProgressBar({ blPct, partPct, nvsPct, fwPct }) {
|
||||||
|
// Weights: bl=10%, part=10%, nvs=10%, fw=70%
|
||||||
|
const overall = blPct * 0.10 + partPct * 0.10 + nvsPct * 0.10 + fwPct * 0.70;
|
||||||
|
|
||||||
|
const label =
|
||||||
|
fwPct > 0 ? `Firmware (${Math.round(fwPct)}%)` :
|
||||||
|
nvsPct > 0 ? `Device Identity (${Math.round(nvsPct)}%)` :
|
||||||
|
partPct > 0 ? `Partition Table (${Math.round(partPct)}%)` :
|
||||||
|
`Bootloader (${Math.round(blPct)}%)`;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-1.5">
|
||||||
|
<div className="flex justify-between text-xs" style={{ color: "var(--text-secondary)" }}>
|
||||||
|
<span>{label}</span>
|
||||||
|
<span>{Math.round(overall)}%</span>
|
||||||
|
</div>
|
||||||
|
<div className="h-3 rounded-full overflow-hidden" style={{ backgroundColor: "var(--bg-card-hover)" }}>
|
||||||
|
<div
|
||||||
|
className="h-full rounded-full transition-all duration-200"
|
||||||
|
style={{ width: `${overall}%`, backgroundColor: "var(--accent)" }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function InfoBox({ type = "info", children }) {
|
function InfoBox({ type = "info", children }) {
|
||||||
const styles = {
|
const styles = {
|
||||||
info: { bg: "var(--badge-blue-bg)", border: "#1e3a5f", color: "var(--badge-blue-text)" },
|
info: { bg: "var(--badge-blue-bg)", border: "#1e3a5f", color: "var(--badge-blue-text)" },
|
||||||
@@ -858,17 +884,13 @@ function StepFlash({ firmware, flashType, serial, nvsSchema, onDone }) {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Progress bars */}
|
{/* Progress bar */}
|
||||||
{(flashing || fwPct > 0) && (
|
{(flashing || fwPct > 0) && (
|
||||||
<div className="space-y-3 mb-4">
|
<div className="mb-4">
|
||||||
{isFullWipe && (
|
{isFullWipe
|
||||||
<>
|
? <CombinedProgressBar blPct={blPct} partPct={partPct} nvsPct={nvsPct} fwPct={fwPct} />
|
||||||
<ProgressBar label="Bootloader" percent={blPct} />
|
: <ProgressBar label="Firmware" percent={fwPct} />
|
||||||
<ProgressBar label="Partition Table" percent={partPct} />
|
}
|
||||||
<ProgressBar label="Device Identity (NVS)" percent={nvsPct} />
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
<ProgressBar label="Firmware" percent={fwPct} />
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user