Files
alkane-os/ci/afw_boards.py
T
noahandClaude Opus 4.8 baf19ed6c8 Formalize zynq-7010 tier-2 .afw: producer profile + brick gate (zimage format, ceilings, preserve)
Adds a buildable zynq-7010 profile and its .afw brick-prevention gate, so the
proven Zynq image is a first-class .afw like cv1835/am335x.
- afw_boards.py: full zynq-7010 profile (armv7, preserve; kernel(zimage)+dtb(fdt)
  into mtd0, rootfs(cpio-gzip) into mtd1); new strict 'zimage' SAFE_IMAGE_FORMAT.
- afw_manifest.py + check-afw.py: validate_zynq / the zynq-7010 gate - exactly the
  kernel/dtb/rootfs image set, correct formats, size ceilings (kernel <= 0x500000
  fits the slot, dtb <= 0x20000, rootfs <= 0x2000000 fits mtd1), and NO
  bootloader/spl/BOOT.bin member (stock BOOT.bin + FPGA bitstream preserved). The
  per-unit kernel-slot offset is placed by the install method (differs S17/S19),
  so the gate enforces formats+ceilings+policy, not a fixed offset map.
- check-afw: strict zimage magic (0x016f2818 at 0x24).
- tests: good bundle, non-zImage kernel, oversize kernel, bootloader-member refusals.
Built + double-gated the real bundle: alkane-os-0.1.0-zynq-7010-armv7.afw
(kernel 4.1 MiB, dtb 11 KB, rootfs 2.5 MiB). Full afw suite green.

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

241 lines
9.5 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": True,
# kernel (zImage), dtb (FDT), rootfs (gzip cpio ramdisk)
"format_checks": ["zimage", "fdt", "cpio-gzip"],
# Both bench Zynq-7010 units (S19, S17) share mtd0 (40 MiB: BOOT.bin +
# the kernel slot) and mtd1 (32 MiB: ramfs). BOOT.bin (FSBL + FPGA
# bitstream + stock U-Boot) is PRESERVED - the bundle carries no
# bootloader member; only the kernel slot in mtd0 and the ramfs in mtd1
# are our OS. The exact kernel-slot sub-offset is placed by the install
# method (it differs by unit), so this profile gates image formats and
# size ceilings, not a fixed offset map.
"partitions": [
{"name": "mtd0", "device": "/dev/mtd0", "offset": 0, "size": 0x2800000,
"secure": False, "boot_critical": True, "write_order": 1, "image": "kernel"},
{"name": "mtd1", "device": "/dev/mtd1", "offset": 0x2800000, "size": 0x2000000,
"secure": False, "boot_critical": True, "write_order": 2, "image": "rootfs"},
],
"images": [
{"name": "kernel", "source": "zImage", "role": "kernel",
"format": "zimage", "partition": "mtd0", "install": True, "exact_bytes": None},
{"name": "dtb", "source": "zynq-alkane.dtb", "role": "dtb",
"format": "fdt", "partition": "mtd0", "install": True, "exact_bytes": None},
{"name": "rootfs", "source": "rootfs.cpio.gz", "role": "rootfs",
"format": "cpio-gzip", "partition": "mtd1", "install": True, "exact_bytes": None},
],
},
"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",
"zimage",
"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"]