a113d (Amlogic AXG/S21 Pro): .afw producer profile + double brick gate

Add the S21 Pro-class Amlogic A113D/AXG control board to the .afw producer
and the CI brick-prevention gate, matching the Zynq-7010 treatment.

- ci/afw_boards.py: a113d producer profile (arm64, preserve, buildable). Maps
  the 7-mtd layout, names nvdata (mtd6) the only image-bearing partition, and
  stages three images vmlinux.bin/devicetree.dtb/uramdisk.image.gz
  (arm64-image/fdt/uimage) into it.
- ci/afw_manifest.py: validate_a113d enforces exactly those three images, the
  formats, per-image ceilings, total <= nvdata usable, and that no
  bootloader/spl/fip/tpl member is present and no non-nvdata partition carries
  an image.
- ci/check-afw.py: the independent checker re-validates the produced bundle
  (arm64, preserve, no FIP member, three named images with formats/ceilings,
  total <= nvdata, mtd0-5 carry no image) and knows the arm64 Image magic.
- ci/test-afw.py: a113d bundle passes and installs all three into nvdata;
  non-arm64 kernel, oversize kernel, an added FIP member, and a preserved mtd
  made to carry an image are each refused.

All 37 afw tests pass.

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 21:01:56 -06:00
co-authored by Claude Opus 4.8
parent baf19ed6c8
commit 8d48e488bd
4 changed files with 224 additions and 2 deletions
+37 -2
View File
@@ -198,8 +198,43 @@ BOARDS = {
],
},
"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},
# Amlogic A113D / AXG (S21 Pro-class) control board. arm64. Our OS is staged
# as FILES in the nvdata UBI volume (mtd6): kernel (arm64 Image), dtb, and a
# uImage ramdisk. The signed FIP bootloader and the stock boot partition
# (mtd0-5) are PRESERVED - zero raw writes outside nvdata, so the stock OS in
# mtd4 stays as a one-setenv fallback. Hence bootloader_policy preserve and no
# bootloader member.
"a113d": {
"arch": "arm64",
"bootloader_policy": "preserve",
"buildable": True,
"format_checks": ["arm64-image", "fdt", "uimage"],
"partitions": [
{"name": "mtd0", "device": "/dev/mtd0", "offset": 0x0000000, "size": 0x200000,
"secure": True, "boot_critical": True, "write_order": 0, "image": None},
{"name": "mtd1", "device": "/dev/mtd1", "offset": 0x0800000, "size": 0x800000,
"secure": True, "boot_critical": True, "write_order": 0, "image": None},
{"name": "mtd2", "device": "/dev/mtd2", "offset": 0x1000000, "size": 0x200000,
"secure": True, "boot_critical": True, "write_order": 0, "image": None},
{"name": "mtd3", "device": "/dev/mtd3", "offset": 0x1200000, "size": 0x1000000,
"secure": True, "boot_critical": True, "write_order": 0, "image": None},
{"name": "mtd4", "device": "/dev/mtd4", "offset": 0x2200000, "size": 0x2000000,
"secure": True, "boot_critical": True, "write_order": 0, "image": None},
{"name": "mtd5", "device": "/dev/mtd5", "offset": 0x4200000, "size": 0x500000,
"secure": True, "boot_critical": True, "write_order": 0, "image": None},
{"name": "nvdata", "device": "/dev/mtd6", "offset": 0x4700000, "size": 0xB900000,
"secure": False, "boot_critical": True, "write_order": 1, "image": "kernel"},
],
"images": [
{"name": "kernel", "source": "vmlinux.bin", "role": "kernel",
"format": "arm64-image", "partition": "nvdata", "install": True, "exact_bytes": None},
{"name": "dtb", "source": "devicetree.dtb", "role": "dtb",
"format": "fdt", "partition": "nvdata", "install": True, "exact_bytes": None},
{"name": "rootfs", "source": "uramdisk.image.gz", "role": "rootfs",
"format": "uimage", "partition": "nvdata", "install": True, "exact_bytes": None},
],
},
"a113d-s21pro": {"arch": "arm64", "bootloader_policy": "preserve", "buildable": False},
"am335x-bb": {"arch": "armv7", "bootloader_policy": "preserve", "buildable": False},
}
+44
View File
@@ -64,6 +64,14 @@ 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}
# Amlogic A113D/AXG (tier 2, preserve): kernel (arm64 Image), dtb and a uImage
# ramdisk are staged as FILES in the nvdata UBI (mtd6); the FIP bootloader and
# the stock boot partition (mtd0-5) are preserved. Ceilings keep the three well
# within the ~185 MiB usable nvdata UBI.
A113D_FORMATS = {"kernel": "arm64-image", "dtb": "fdt", "rootfs": "uimage"}
A113D_CEILINGS = {"kernel": 0x4000000, "dtb": 0x100000, "rootfs": 0x6000000}
A113D_NVDATA_USABLE = 0xB900000 # mtd6 nvdata size; the three images must fit
def die(message):
print(f"afw_manifest: error: {message}", file=sys.stderr)
@@ -352,6 +360,40 @@ def validate_zynq(partitions, images):
die(f"zynq-7010 partition {partition['name']!r} has an unexpected image target")
def validate_a113d(partitions, images):
"""Reject the Amlogic A113D/AXG brick paths before packing (tier 2, preserve).
Our OS is staged as files in the nvdata UBI; the signed FIP bootloader and the
stock boot partition (mtd0-5) are preserved, so the bundle must carry NO
bootloader/spl/tpl/fip member. The kernel (arm64 Image), dtb and uImage
ramdisk must fit the nvdata UBI both individually (ceilings) and together.
"""
installs = [image for image in images if image["install"]]
if len(installs) != 3:
die("a113d must install exactly kernel, dtb and rootfs")
if {image["name"] for image in installs} != set(A113D_FORMATS):
die("a113d 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 "fip" in lowered or "tpl" in lowered or image.get("role") == "bootloader":
die(f"a113d bundle carries a bootloader/spl/fip member: {image['file']!r}")
total = 0
for image in installs:
name = image["name"]
if image["format"] != A113D_FORMATS[name]:
die(f"a113d {name} format must be {A113D_FORMATS[name]}")
if image["size"] > A113D_CEILINGS[name]:
die(f"a113d {name} is {image['size']} bytes, over the 0x{A113D_CEILINGS[name]:x}-byte ceiling")
total += image["size"]
if total > A113D_NVDATA_USABLE:
die(f"a113d images total {total} bytes, over the 0x{A113D_NVDATA_USABLE:x}-byte nvdata UBI")
# mtd0-5 (FIP + stock boot) are never a write target.
for partition in partitions:
if partition["name"] != "nvdata" and partition.get("image") is not None:
die(f"a113d partition {partition['name']!r} is preserved and must not carry an image")
def build(args):
board = args.board
if not afw_boards.known_board(board):
@@ -466,6 +508,8 @@ def build(args):
validate_am335x_stock(partitions, images)
elif board == "zynq-7010":
validate_zynq(partitions, images)
elif board == "a113d":
validate_a113d(partitions, images)
policy = profile["bootloader_policy"]
if policy == "preserve" and any(image["role"] == "bootloader" for image in images):
+33
View File
@@ -52,6 +52,9 @@ AM335X_STOCK_CEILINGS = {"u-boot": 0x1C0000, "kernel": 0x500000, "dtb": 0x20000,
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}
A113D_FORMATS = {"kernel": "arm64-image", "dtb": "fdt", "rootfs": "uimage"}
A113D_CEILINGS = {"kernel": 0x4000000, "dtb": 0x100000, "rootfs": 0x6000000}
A113D_NVDATA_USABLE = 0xB900000
class AfwError(Exception):
@@ -507,6 +510,36 @@ 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 == "a113d":
require(manifest["arch"] == "arm64", "a113d must be arm64")
require(manifest["bootloader_policy"] == "preserve", "a113d must preserve the FIP bootloader")
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 "fip" not in lowered and "tpl" not in lowered and image["role"] != "bootloader",
f"a113d bundle carries a bootloader/spl/fip member: {image['file']!r}",
)
require(len(install_images) == 3, "a113d installs exactly kernel, dtb and rootfs")
require(
{image["name"] for image in install_images} == set(A113D_FORMATS),
"a113d install images must be named kernel, dtb and rootfs",
)
total = 0
for image in install_images:
name = image["name"]
require(image["format"] == A113D_FORMATS[name], f"a113d {name} format must be {A113D_FORMATS[name]}")
require(
image["size"] <= A113D_CEILINGS[name],
f"a113d {name} ({image['size']} B) exceeds the 0x{A113D_CEILINGS[name]:x}-byte ceiling",
)
total += image["size"]
require(total <= A113D_NVDATA_USABLE, f"a113d images total {total} B exceed the nvdata UBI (0x{A113D_NVDATA_USABLE:x})")
# Only nvdata (mtd6) may carry an image; mtd0-5 (FIP + stock boot) are preserved.
for partition in partitions:
if partition["name"] != "nvdata":
require(partition.get("image") is None, f"a113d {partition['name']!r} is preserved and must not carry an image")
if board == "zynq-7010":
require(manifest["arch"] == "armv7", "zynq-7010 must be armv7")
require(manifest["bootloader_policy"] == "preserve", "zynq-7010 must preserve BOOT.bin")
+110
View File
@@ -762,3 +762,113 @@ class ZynqAfwTests(unittest.TestCase):
bad = rewrite_bundle(bundle, self.temp / "bl.afw", edit_manifest=edit)
result = self.check(bad, "--allow-unsigned")
self.assertNotEqual(result.returncode, 0)
def arm64_image_blob(payload=b"a64kernel"):
# arm64 Linux Image: ASCII "ARMd" at offset 0x38.
b = bytearray(64)
b[0x38:0x3C] = b"ARMd"
b[0x08:0x10] = (0x200000).to_bytes(8, "little") # text_offset / image_size hint
return bytes(b) + payload
def uramdisk_blob(payload=b"ramdisk"):
# legacy uImage ramdisk (magic 0x27051956); a113d does not enforce arch/type.
b = bytearray(64)
b[0:4] = b"\x27\x05\x19\x56"
b[12:16] = len(payload).to_bytes(4, "big")
return bytes(b) + payload
def a113d_fixture_input(directory):
directory.mkdir(parents=True, exist_ok=True)
(directory / "vmlinux.bin").write_bytes(arm64_image_blob())
dtb = bytearray(2048); dtb[0:4] = b"\xd0\x0d\xfe\xed"
(directory / "devicetree.dtb").write_bytes(bytes(dtb))
(directory / "uramdisk.image.gz").write_bytes(uramdisk_blob())
return directory
def build_a113d_afw(work, input_dir, extra=()):
output = work / "dist-a113d"
result = run(["bash", str(MAKE), "--board", "a113d", "--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 A113dAfwTests(unittest.TestCase):
"""a113d tier-2 bundle: kernel/dtb/rootfs staged into nvdata; FIP + mtd0-5 preserved."""
def setUp(self):
self.temp = Path(tempfile.mkdtemp(prefix="a113d-afw-test."))
self.input = a113d_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 make(self, outdir="d"):
return run(["bash", str(MAKE), "--board", "a113d", "--version", "0.1.0",
"--input", str(self.input), "--output", str(self.temp / outdir),
"--sdk-revision", REVISION, "--os-revision", REVISION, "--allow-unsigned"])
def test_good_a113d_bundle_passes_and_preserves(self):
bundle = build_a113d_afw(self.temp, self.input)
result = self.check(bundle, "--allow-unsigned", "--expect-board", "a113d")
self.assertEqual(result.returncode, 0, result.stderr)
self.assertIn("afw: OK", result.stdout)
self.assertIn("bootloader preserve", result.stdout)
# all three images install into the nvdata UBI, never a raw mtd0-5 write
self.assertEqual(result.stdout.count("-> nvdata"), 3)
def test_non_arm64_kernel_is_refused(self):
(self.input / "vmlinux.bin").write_bytes(b"\x00" * 4096) # no ARMd magic
result = self.make()
self.assertNotEqual(result.returncode, 0)
self.assertIn("arm64", (result.stderr + result.stdout).lower())
def test_oversize_kernel_is_refused(self):
(self.input / "vmlinux.bin").write_bytes(arm64_image_blob(b"\x00" * (0x4000000 + 1)))
result = self.make()
self.assertNotEqual(result.returncode, 0)
self.assertIn("ceiling", (result.stderr + result.stdout).lower())
def test_fip_member_is_refused(self):
bundle = build_a113d_afw(self.temp, self.input)
def edit(manifest, work):
manifest["images"].append({
"name": "fip", "file": "payload/fip.bin", "role": "bootloader",
"format": "raw", "size": 4,
"sha256": __import__("hashlib").sha256(b"fip!").hexdigest(),
"partition": None, "install": False,
})
(work / "payload" / "fip.bin").write_bytes(b"fip!")
bad = rewrite_bundle(bundle, self.temp / "fip.afw", edit_manifest=edit)
result = self.check(bad, "--allow-unsigned")
self.assertNotEqual(result.returncode, 0)
self.assertIn("fip", (result.stderr + result.stdout).lower())
def test_preserved_mtd_carrying_an_image_is_refused(self):
bundle = build_a113d_afw(self.temp, self.input)
def edit(manifest, work):
for partition in manifest["partitions"]:
if partition["name"] != "nvdata":
partition["image"] = "kernel" # try to aim a write at the FIP side
break
bad = rewrite_bundle(bundle, self.temp / "pre.afw", edit_manifest=edit)
result = self.check(bad, "--allow-unsigned")
self.assertNotEqual(result.returncode, 0)
self.assertIn("preserved", (result.stderr + result.stdout).lower())