Files
frame/tools/frame_tools/partitions.py
T
lainandSisyphus a6d6168fd5 chore: add community files, CI workflows, and host test tooling
Add the repository-facing scaffolding:

- Community/legal: README.md, LICENSE (GPL-3.0-or-later), NOTICE,
  CONTRIBUTING.md, SECURITY.md, CODE_OF_CONDUCT.md, .gitleaks.toml
- CI: .github/ workflows (ci.yml aggregate gate, nightly.yml, codeql.yml),
  issue/PR templates, dependabot config (pinned Actions per README)
- Host tooling: tools/frame_tools (ruff/pyright/pytest gates, partition,
  evidence-schema, doc-links, SBOM checks), tests/, pyproject.toml, uv.lock
- poc/ host side: poc/host contract-test suite (ASan/TSan-capable),
  poc/README.md, poc/poc-a.code-workspace

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <[email protected]>
2026-08-31 08:00:51 +08:00

75 lines
2.6 KiB
Python

"""Validate the frozen 16 MiB Frame partition layout."""
from __future__ import annotations
import argparse
import csv
import sys
from collections.abc import Sequence
from pathlib import Path
EXPECTED_HEADER = ("# Name", "Type", "SubType", "Offset", "Size", "Flags")
EXPECTED_PARTITIONS = (
("nvs", "data", "nvs", "0x9000", "0x14000", ""),
("nvs_keys", "data", "nvs_keys", "0x1D000", "0x1000", "encrypted"),
("otadata", "data", "ota", "0x1E000", "0x2000", ""),
("coredump", "data", "coredump", "0x20000", "0x20000", ""),
("ota_0", "app", "ota_0", "0x40000", "0x500000", ""),
("ota_1", "app", "ota_1", "0x540000", "0x500000", ""),
("plugin_fs", "data", "littlefs", "0xA40000", "0x4C0000", ""),
("system_fs", "data", "littlefs", "0xF00000", "0x100000", ""),
)
def read_layout(path: Path) -> tuple[tuple[str, ...], ...]:
with path.open(encoding="utf-8", newline="") as stream:
rows = csv.reader(stream, skipinitialspace=True)
return tuple(
tuple(cell.strip() for cell in row) for row in rows if any(cell.strip() for cell in row)
)
def validate_partitions(path: Path) -> list[str]:
try:
rows = read_layout(path)
except (OSError, UnicodeError, csv.Error) as error:
return [f"{path}: cannot read partition CSV: {error}"]
expected = (EXPECTED_HEADER, *EXPECTED_PARTITIONS)
if rows == expected:
return []
errors: list[str] = []
if not rows:
return [f"{path}: partition CSV is empty"]
if rows[0] != EXPECTED_HEADER:
errors.append(f"{path}: header changed: expected {EXPECTED_HEADER!r}, got {rows[0]!r}")
actual_partitions = rows[1:]
for index in range(max(len(actual_partitions), len(EXPECTED_PARTITIONS))):
expected_row = EXPECTED_PARTITIONS[index] if index < len(EXPECTED_PARTITIONS) else None
actual_row = actual_partitions[index] if index < len(actual_partitions) else None
if actual_row != expected_row:
errors.append(
f"{path}: partition row {index + 1} changed: "
f"expected {expected_row!r}, got {actual_row!r}"
)
return errors
def main(argv: Sequence[str] | None = None) -> int:
parser = argparse.ArgumentParser(description="Validate the frozen Frame partition table")
parser.add_argument("path", nargs="?", type=Path, default=Path("partitions.csv"))
args = parser.parse_args(argv)
errors = validate_partitions(args.path)
if errors:
print("\n".join(errors), file=sys.stderr)
return 1
print(f"{args.path}: partition layout matches the frozen layout")
return 0
if __name__ == "__main__":
raise SystemExit(main())