fix: NVS Generator. cosmetic: Changed CloudFlash page a bit
This commit is contained in:
@@ -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)}")
|
||||
|
||||
@@ -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,6 +194,11 @@ 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)
|
||||
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)
|
||||
|
||||
@@ -130,7 +130,7 @@ function ProgressBar({ label, percent }) {
|
||||
<span>{label}</span>
|
||||
<span>{Math.round(percent)}%</span>
|
||||
</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
|
||||
className="h-full rounded-full transition-all duration-200"
|
||||
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 }) {
|
||||
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 }) {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Progress bars */}
|
||||
{/* Progress bar */}
|
||||
{(flashing || fwPct > 0) && (
|
||||
<div className="space-y-3 mb-4">
|
||||
{isFullWipe && (
|
||||
<>
|
||||
<ProgressBar label="Bootloader" percent={blPct} />
|
||||
<ProgressBar label="Partition Table" percent={partPct} />
|
||||
<ProgressBar label="Device Identity (NVS)" percent={nvsPct} />
|
||||
</>
|
||||
)}
|
||||
<ProgressBar label="Firmware" percent={fwPct} />
|
||||
<div className="mb-4">
|
||||
{isFullWipe
|
||||
? <CombinedProgressBar blPct={blPct} partPct={partPct} nvsPct={nvsPct} fwPct={fwPct} />
|
||||
: <ProgressBar label="Firmware" percent={fwPct} />
|
||||
}
|
||||
</div>
|
||||
)}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user