Files
alkane-os/ci/afw_boards.py
T
noahandClaude Opus 4.8 6b24c85fce Add am335x-stock (tier-3) .afw producer profile + brick gates
Mirrors the alkane-sdk tier-3 plan gate on the producer side so a from-stock
bundle can be built and verified. The am335x-stock profile writes our non-RSA
U-Boot to mtd4 (legacy firmware uImage, ih_type 5) plus kernel/dtb/root, and:
- afw_boards.py: am335x-stock profile (bootloader_policy include, mtd4 write
  target at order 3, kernel at order 4, u-boot image).
- afw_manifest.py + check-afw.py: validate_am335x_stock - shares the 12-part map
  and 0x780000 hole with tier-2 but asserts policy include, the 4-image set,
  mtd4 ceiling 0x1c0000, the U-Boot member is a type-5 firmware uImage, and that
  no SPL copy (mtd0-3) or bootenv (mtd5) is ever a write target.
- check_format: am335x uImage checks now cover am335x-stock, incl. u-boot type 5.
- tests: 3 am335x-stock producer cases (good 4-install bundle, wrong U-Boot type,
  SPL-write refusal). Full afw suite 28 green; am335x tier-2 + cv1835 unchanged.

Built and double-gated the real bundle locally: alkane-os-0.1.0-am335x-stock-arm.afw
(u-boot 723440 B type5 -> mtd4, kernel -> mtd7, dtb -> mtd6, rootfs -> mtd8).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B1W6qHxYpv7yf7Ah57g4rQ
2026-11-05 20:18:43 -06:00

213 lines
8.0 KiB
Python

# SPDX-License-Identifier: MIT
"""Board profiles used by the .afw producer and the CI checker.
An .afw is valid for exactly one board family. The arch and bootloader policy
come from this table, never from the caller alone, so a bundle cannot claim a
board it was not built for. cv1835 and am335x have complete, buildable profiles in this release; the
other Antminer families are listed so a wrong-board bundle is rejected by name
instead of being accepted as "unknown".
"""
AM335X_PARTITIONS = [
{"name": "mtd0", "device": "/dev/mtd0", "offset": 0x0000000, "size": 0x20000,
"secure": True, "boot_critical": True, "write_order": 0, "image": None},
{"name": "mtd1", "device": "/dev/mtd1", "offset": 0x0020000, "size": 0x20000,
"secure": True, "boot_critical": True, "write_order": 0, "image": None},
{"name": "mtd2", "device": "/dev/mtd2", "offset": 0x0040000, "size": 0x20000,
"secure": True, "boot_critical": True, "write_order": 0, "image": None},
{"name": "mtd3", "device": "/dev/mtd3", "offset": 0x0060000, "size": 0x20000,
"secure": True, "boot_critical": True, "write_order": 0, "image": None},
{"name": "mtd4", "device": "/dev/mtd4", "offset": 0x0080000, "size": 0x1C0000,
"secure": True, "boot_critical": True, "write_order": 0, "image": None},
{"name": "mtd5", "device": "/dev/mtd5", "offset": 0x0240000, "size": 0x20000,
"secure": True, "boot_critical": True, "write_order": 0, "image": None},
{"name": "mtd6", "device": "/dev/mtd6", "offset": 0x0260000, "size": 0x20000,
"secure": False, "boot_critical": True, "write_order": 2, "image": "dtb"},
{"name": "mtd7", "device": "/dev/mtd7", "offset": 0x0280000, "size": 0x500000,
"secure": False, "boot_critical": True, "write_order": 3, "image": "kernel"},
{"name": "mtd8", "device": "/dev/mtd8", "offset": 0x0800000, "size": 0x1400000,
"secure": False, "boot_critical": True, "write_order": 1, "image": "rootfs"},
{"name": "mtd9", "device": "/dev/mtd9", "offset": 0x1C00000, "size": 0x200000,
"secure": True, "boot_critical": False, "write_order": 0, "image": None},
{"name": "mtd10", "device": "/dev/mtd10", "offset": 0x1E00000, "size": 0x200000,
"secure": True, "boot_critical": False, "write_order": 0, "image": None},
{"name": "mtd11", "device": "/dev/mtd11", "offset": 0x2000000, "size": 0x6000000,
"secure": True, "boot_critical": False, "write_order": 0, "image": None},
]
AM335X_IMAGES = [
{"name": "kernel", "source": "alkane-am335x.uImage", "role": "kernel",
"format": "uimage", "partition": "mtd7", "install": True, "exact_bytes": None},
{"name": "dtb", "source": "am335x-alkane.dtb", "role": "dtb",
"format": "fdt", "partition": "mtd6", "install": True, "exact_bytes": None},
{"name": "rootfs", "source": "alkane-am335x-ramdisk.uImage", "role": "rootfs",
"format": "uimage", "partition": "mtd8", "install": True, "exact_bytes": None},
]
# Tier-3 from-stock variant: same 12-partition NAND map, but mtd4 is written
# with our non-RSA U-Boot (a legacy uImage the preserved SPL chainloads), so its
# secure flag is False and it carries the u-boot image at write_order 3; the
# kernel moves to write_order 4 (U-Boot lands before the kernel). The SPL copies
# (mtd0-3) and bootenv (mtd5) stay preserved and are never write targets.
AM335X_STOCK_PARTITIONS = []
for _p in AM335X_PARTITIONS:
_q = dict(_p)
if _q["name"] == "mtd4":
_q.update(secure=False, write_order=3, image="u-boot")
elif _q["name"] == "mtd7":
_q.update(write_order=4)
AM335X_STOCK_PARTITIONS.append(_q)
AM335X_STOCK_IMAGES = [
{"name": "u-boot", "source": "alkane-am335x-uboot-mtd4.uImage", "role": "bootloader",
"format": "uimage", "partition": "mtd4", "install": True, "exact_bytes": None},
] + [dict(_img) for _img in AM335X_IMAGES]
BOARDS = {
"am335x": {
"arch": "arm",
"bootloader_policy": "preserve",
"buildable": True,
"format_checks": ["uimage", "fdt", "uimage"],
"partitions": AM335X_PARTITIONS,
"images": AM335X_IMAGES,
},
"am335x-stock": {
"arch": "arm",
"bootloader_policy": "include",
"buildable": True,
"format_checks": ["uimage", "uimage", "fdt", "uimage"],
"partitions": AM335X_STOCK_PARTITIONS,
"images": AM335X_STOCK_IMAGES,
},
"cv1835": {
"arch": "arm64",
"bootloader_policy": "preserve",
"buildable": True,
"format_checks": ["fit", "arm64-image", "fdt", "cpio-gzip"],
"partitions": [
{
"name": "p1",
"device": "/dev/mmcblk0p1",
"offset": 0,
"size": 16 * 1024 * 1024,
"secure": False,
"boot_critical": True,
"write_order": 1,
"image": "p1",
},
{
"name": "p3",
"device": "/dev/mmcblk0p3",
"offset": 0,
"size": 32 * 1024 * 1024,
"secure": True,
"boot_critical": False,
"write_order": 0,
"image": None,
},
{
"name": "boot0",
"device": "/dev/mmcblk0boot0",
"offset": 0,
"size": 4 * 1024 * 1024,
"secure": True,
"boot_critical": True,
"write_order": 0,
"image": None,
},
{
"name": "boot1",
"device": "/dev/mmcblk0boot1",
"offset": 0,
"size": 4 * 1024 * 1024,
"secure": True,
"boot_critical": True,
"write_order": 0,
"image": None,
},
],
"images": [
{
"name": "kernel",
"source": "Image",
"role": "kernel",
"format": "arm64-image",
"partition": None,
"install": False,
"exact_bytes": None,
},
{
"name": "dtb",
"source": "cv-alkane.dtb",
"role": "dtb",
"format": "fdt",
"partition": None,
"install": False,
"exact_bytes": None,
},
{
"name": "rootfs",
"source": "rootfs.cpio.gz",
"role": "rootfs",
"format": "cpio-gzip",
"partition": None,
"install": False,
"exact_bytes": None,
},
{
"name": "p1",
"source": "alkane-cv1835-p1.fit",
"role": "boot",
"format": "fit",
"partition": "p1",
"install": True,
"exact_bytes": 16 * 1024 * 1024,
},
],
},
# Antminer families that the seven-board release gate still lists. They are
# known, so a wrong-board bundle is refused by identity, but they do not
# have a buildable .afw profile in this release.
"zynq-7010": {"arch": "armv7", "bootloader_policy": "preserve", "buildable": False},
"zynq-s17": {"arch": "armv7", "bootloader_policy": "include", "buildable": False},
"a113d": {"arch": "armv7", "bootloader_policy": "preserve", "buildable": False},
"a113d-s21pro": {"arch": "armv7", "bootloader_policy": "preserve", "buildable": False},
"am335x-bb": {"arch": "armv7", "bootloader_policy": "preserve", "buildable": False},
}
SAFE_IMAGE_FORMATS = {
"fit",
"arm64-image",
"fdt",
"cpio-gzip",
"uimage",
"raw",
}
SAFE_IMAGE_ROLES = {
"kernel",
"dtb",
"rootfs",
"bootloader",
"boot",
"component",
}
def board(name):
"""Return the profile for a board family, or raise KeyError."""
return BOARDS[name]
def known_board(name):
return name in BOARDS
def expect_arch(name):
return BOARDS[name]["arch"]
def expect_policy(name):
return BOARDS[name]["bootloader_policy"]