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
This commit is contained in:
2026-11-06 19:43:47 -06:00
co-authored by Claude Opus 4.8
parent 6b24c85fce
commit baf19ed6c8
4 changed files with 189 additions and 1 deletions
+29 -1
View File
@@ -169,7 +169,34 @@ BOARDS = {
# 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-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},
@@ -179,6 +206,7 @@ BOARDS = {
SAFE_IMAGE_FORMATS = {
"fit",
"arm64-image",
"zimage",
"fdt",
"cpio-gzip",
"uimage",
+44
View File
@@ -59,6 +59,11 @@ AM335X_STOCK_CEILINGS = {"u-boot": 0x1C0000, "kernel": 0x500000, "dtb": 0x20000,
# SPL copies (mtd0-3) and bootenv (mtd5) must never be written on either tier.
AM335X_NEVER_WRITE = {"mtd0", "mtd1", "mtd2", "mtd3", "mtd5"}
# Zynq-7010 (tier 2, preserve): kernel into the mtd0 kernel slot, dtb, rootfs
# into mtd1; BOOT.bin (FSBL + FPGA bitstream + stock U-Boot) preserved.
ZYNQ_FORMATS = {"kernel": "zimage", "dtb": "fdt", "rootfs": "cpio-gzip"}
ZYNQ_CEILINGS = {"kernel": 0x500000, "dtb": 0x20000, "rootfs": 0x2000000}
def die(message):
print(f"afw_manifest: error: {message}", file=sys.stderr)
@@ -310,6 +315,43 @@ def validate_am335x_stock(partitions, images):
die("am335x-stock partition sizes must sum to 0x7F80000")
def validate_zynq(partitions, images):
"""Reject the Zynq-7010 brick paths before packing (tier 2, preserve).
The board reuses the stock BOOT.bin (FSBL + FPGA bitstream + stock U-Boot),
so the bundle must carry NO bootloader/spl/BOOT.bin member; it installs our
kernel (zImage) into the mtd0 kernel slot, the dtb, and the rootfs
(gzip cpio) into mtd1. The exact kernel-slot offset is placed per-unit by the
install method, so this gate enforces the image set, formats and the
size ceilings (so an oversize image cannot overrun the slot) - not a fixed
offset map.
"""
installs = [image for image in images if image["install"]]
if len(installs) != 3:
die("zynq-7010 must install exactly kernel, dtb and rootfs")
if {image["name"] for image in installs} != set(ZYNQ_FORMATS):
die("zynq-7010 install images must be named kernel, dtb and rootfs")
for image in images:
lowered = f"{image['name']} {image['file']} {image.get('role','')}".lower()
if "spl" in lowered or "u-boot" in lowered or "uboot" in lowered \
or "boot.bin" in lowered or image.get("role") == "bootloader":
die(f"zynq-7010 bundle carries a bootloader/spl member: {image['file']!r}")
for image in installs:
name = image["name"]
if image["format"] != ZYNQ_FORMATS[name]:
die(f"zynq-7010 {name} format must be {ZYNQ_FORMATS[name]}")
if image["size"] > ZYNQ_CEILINGS[name]:
die(
f"zynq-7010 {name} is {image['size']} bytes, over the "
f"0x{ZYNQ_CEILINGS[name]:x}-byte ceiling"
)
# BOOT.bin lives at the front of mtd0 and is never a write target here.
for partition in partitions:
if partition.get("image") in (None, "kernel", "rootfs"):
continue
die(f"zynq-7010 partition {partition['name']!r} has an unexpected image target")
def build(args):
board = args.board
if not afw_boards.known_board(board):
@@ -422,6 +464,8 @@ def build(args):
validate_am335x(partitions, images)
elif board == "am335x-stock":
validate_am335x_stock(partitions, images)
elif board == "zynq-7010":
validate_zynq(partitions, images)
policy = profile["bootloader_policy"]
if policy == "preserve" and any(image["role"] == "bootloader" for image in images):
+33
View File
@@ -50,6 +50,8 @@ AM335X_STOCK_TARGETS = {"u-boot": "mtd4", "kernel": "mtd7", "dtb": "mtd6", "root
AM335X_STOCK_FORMATS = {"u-boot": "uimage", "kernel": "uimage", "dtb": "fdt", "rootfs": "uimage"}
AM335X_STOCK_CEILINGS = {"u-boot": 0x1C0000, "kernel": 0x500000, "dtb": 0x20000, "rootfs": 0x1400000}
AM335X_NEVER_WRITE = {"mtd0", "mtd1", "mtd2", "mtd3", "mtd5"}
ZYNQ_FORMATS = {"kernel": "zimage", "dtb": "fdt", "rootfs": "cpio-gzip"}
ZYNQ_CEILINGS = {"kernel": 0x500000, "dtb": 0x20000, "rootfs": 0x2000000}
class AfwError(Exception):
@@ -169,6 +171,10 @@ def check_format(manifest, image, payload, name):
require(payload.startswith(b"\xd0\x0d\xfe\xed"), f"{name} is not an FDT")
elif fmt == "arm64-image":
require(len(payload) >= 64 and payload[0x38:0x3C] == b"ARMd", f"{name} is not an arm64 Image")
elif fmt == "zimage":
# ARM zImage: magic 0x016f2818 (little-endian) at offset 0x24.
require(len(payload) >= 0x28 and payload[0x24:0x28] == b"\x18\x28\x6f\x01",
f"{name} is not an ARM zImage")
elif fmt == "cpio-gzip":
require(payload.startswith(b"\x1f\x8b"), f"{name} is not gzip-compressed")
elif fmt == "uimage":
@@ -501,6 +507,33 @@ def validate(path, allow_unsigned=False, public_key=None, expect_board=None, pla
if board == "am335x-stock":
validate_am335x_stock(manifest, images, partitions, install_images)
if board == "zynq-7010":
require(manifest["arch"] == "armv7", "zynq-7010 must be armv7")
require(manifest["bootloader_policy"] == "preserve", "zynq-7010 must preserve BOOT.bin")
for image in images:
lowered = f"{image['name']} {image['file']} {image['role']}".lower()
require(
"spl" not in lowered and "u-boot" not in lowered and "uboot" not in lowered
and "boot.bin" not in lowered and image["role"] != "bootloader",
f"zynq-7010 bundle carries a bootloader/spl member: {image['file']!r}",
)
require(len(install_images) == 3, "zynq-7010 installs exactly kernel, dtb and rootfs")
require(
{image["name"] for image in install_images} == set(ZYNQ_FORMATS),
"zynq-7010 install images must be named kernel, dtb and rootfs",
)
for image in install_images:
name = image["name"]
require(
image["format"] == ZYNQ_FORMATS[name],
f"zynq-7010 {name} format must be {ZYNQ_FORMATS[name]}",
)
require(
image["size"] <= ZYNQ_CEILINGS[name],
f"zynq-7010 {name} ({image['size']} B) exceeds the "
f"0x{ZYNQ_CEILINGS[name]:x}-byte ceiling",
)
if board == "cv1835":
require(len(install_images) == 1 and install_images[0]["name"] == "p1", "cv1835 installs only p1")
p1 = install_images[0]
+83
View File
@@ -679,3 +679,86 @@ class Am335xStockAfwTests(unittest.TestCase):
result = self.check(bad, "--allow-unsigned")
self.assertNotEqual(result.returncode, 0)
self.assertIn("mtd0", result.stderr)
def zimage_blob(payload=b"zkernel"):
# ARM zImage: magic 0x016f2818 (LE) at offset 0x24.
b = bytearray(64)
b[0x24:0x28] = b"\x18\x28\x6f\x01"
return bytes(b) + payload
def zynq_fixture_input(directory):
directory.mkdir(parents=True, exist_ok=True)
(directory / "zImage").write_bytes(zimage_blob())
dtb = bytearray(1024); dtb[0:4] = b"\xd0\x0d\xfe\xed"
(directory / "zynq-alkane.dtb").write_bytes(dtb)
(directory / "rootfs.cpio.gz").write_bytes(b"\x1f\x8b" + b"rootfs")
return directory
def build_zynq_afw(work, input_dir, extra=()):
output = work / "dist-zynq"
result = run(["bash", str(MAKE), "--board", "zynq-7010", "--version", "0.1.0",
"--input", str(input_dir), "--output", str(output),
"--sdk-revision", REVISION, "--os-revision", REVISION,
"--allow-unsigned", *extra])
if result.returncode != 0:
raise AssertionError(f"producer failed:\n{result.stdout}\n{result.stderr}")
files = list(output.glob("*.afw"))
if len(files) != 1:
raise AssertionError(f"expected one bundle, found {files}")
return files[0]
class ZynqAfwTests(unittest.TestCase):
"""zynq-7010 tier-2 bundle: kernel(zImage)/dtb/rootfs, BOOT.bin preserved."""
def setUp(self):
self.temp = Path(tempfile.mkdtemp(prefix="zynq-afw-test."))
self.input = zynq_fixture_input(self.temp / "sdk-out")
def tearDown(self):
shutil.rmtree(self.temp, ignore_errors=True)
def check(self, path, *extra):
return run([sys.executable, str(CHECK), str(path), *extra])
def test_good_zynq_bundle_passes(self):
bundle = build_zynq_afw(self.temp, self.input)
result = self.check(bundle, "--allow-unsigned", "--expect-board", "zynq-7010")
self.assertEqual(result.returncode, 0, result.stderr)
self.assertIn("afw: OK", result.stdout)
self.assertIn("bootloader preserve", result.stdout)
def test_non_zimage_kernel_is_refused(self):
(self.input / "zImage").write_bytes(b"\x00" * 4096) # no zImage magic
result = run(["bash", str(MAKE), "--board", "zynq-7010", "--version", "0.1.0",
"--input", str(self.input), "--output", str(self.temp / "d"),
"--sdk-revision", REVISION, "--os-revision", REVISION, "--allow-unsigned"])
self.assertNotEqual(result.returncode, 0)
self.assertIn("zImage", result.stderr + result.stdout)
def test_oversize_kernel_is_refused(self):
(self.input / "zImage").write_bytes(zimage_blob(b"\x00" * (0x500000 + 1)))
result = run(["bash", str(MAKE), "--board", "zynq-7010", "--version", "0.1.0",
"--input", str(self.input), "--output", str(self.temp / "d"),
"--sdk-revision", REVISION, "--os-revision", REVISION, "--allow-unsigned"])
self.assertNotEqual(result.returncode, 0)
self.assertIn("ceiling", result.stderr + result.stdout)
def test_bootloader_member_is_refused(self):
bundle = build_zynq_afw(self.temp, self.input)
def edit(manifest, work):
manifest["images"].append({
"name": "u-boot", "file": "payload/BOOT.bin", "role": "bootloader",
"format": "raw", "size": 4,
"sha256": __import__("hashlib").sha256(b"boot").hexdigest(),
"partition": None, "install": False,
})
(work / "payload" / "BOOT.bin").write_bytes(b"boot")
bad = rewrite_bundle(bundle, self.temp / "bl.afw", edit_manifest=edit)
result = self.check(bad, "--allow-unsigned")
self.assertNotEqual(result.returncode, 0)