Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Unified-diff context prefixes precede empty lines and upstream tab indentation.
ci/patches/*.patch whitespace=-blank-at-eol,-space-before-tab
4 changes: 2 additions & 2 deletions .github/workflows/esp32-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
workflow_dispatch:
push:
branches: [main]
paths: ['src/**', 'host/**', 'ci/**', 'firmware_inventory.py', 'examples/andysc/review/schema-sources.json', 'prj.conf', 'crypto.cmake', 'CMakeLists.txt', 'west.yml', '.github/workflows/esp32-images.yml']
paths: ['src/**', 'host/**', 'ci/**', 'docs/s2mini-pqc.md', 'firmware_inventory.py', 'examples/andysc/review/schema-sources.json', 'prj.conf', 'crypto.cmake', 'CMakeLists.txt', 'west.yml', '.github/workflows/esp32-images.yml']
# Applying this label is an explicit dispatch of a locally reviewed candidate.
# Synchronizing a labelled PR does not automatically approve the new revision.
pull_request:
Expand Down Expand Up @@ -40,7 +40,7 @@ jobs:
fail-fast: false
max-parallel: 1
matrix:
board: [esp32, esp32s3, esp32c3]
board: [esp32s2mini, esp32, esp32s3, esp32c3]
runs-on: [self-hosted, Linux, X64, dd-esl-proxmox]
timeout-minutes: 45
steps:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ certification**. A build, flash or signature test is not a PQC network test.
| Build Mac SSH tools | [SSH page and v9 download](https://dynamicdevices.github.io/pqc-testing/ssh/) · [instructions](examples/oqs-ssh/README.md) | Separate tools; one-time profile enables `ssh pqc-lab` and `scp file.txt pqc-lab:./`. Build generates no keys or connections. |
| Try Zephyr application code | [Native simulator setup](docs/zephyr-simulator.md) | Ten live HTTPS/MQTTS controls using host OpenSSL, **not embedded Zephyr TLS**. |
| Flash an ESP32 test image | [Builds and flashing](docs/esp32-images.md) · [browser installer](docs/browser-firmware.md) | Boot/resource and ML-DSA-44 signature-verification images, **not PQC network clients**. |
| Test an ESP32-S2 Mini | [S2 Mini bring-up](docs/s2mini-pqc.md) | Native USB baseline and ML-DSA-44 verifier; XTVTX hardware/PSRAM unverified; no TLS or KC heater control. |
| Explore ESP8266 feasibility | [D1 mini experiment](docs/esp8266-d1mini.md) | A limited hybrid-HTTPS prototype; no proved ML-DSA certificate authentication or complete PQC acceptance. |
| Review evidence and inventories | [Dated results](docs/testing-results.md) · [SBOM/CBOM guide](docs/inventories.md) | Which artifact was tested or inventoried, and the limits of each claim. |

Expand Down
105 changes: 94 additions & 11 deletions ci/esp32_images.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
"""Build six public test images ONLY on the admitted DD organisation runner.
"""Build public ESP32-family test images ONLY on the admitted DD runner.

No flashing, Wi-Fi secrets, broker credentials, host installs or local fallback.
Assisted-by: Briar
Expand All @@ -18,7 +18,8 @@
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT))
import firmware_inventory
ZEPHYR = "dccb09599635bdff17633fa7e9dab014b91dce90"
ZEPHYR = "41d10b59730406bbab4ca9f1fbbe9e96aafb4966" # Zephyr v4.5.0
HAL_ESPRESSIF = "cc81db00233af6020f2fea9fbb0d0098fb3d0d86"
DILITHIUM = "d35ba3fe5449bee3e6d43e1f296c3ca818bd36be"
IMAGE = "ghcr.io/zephyrproject-rtos/ci@sha256:37e841452087905085ffcd82ed44a223f3e7eb86bf9316443a313ae07e09cfe0"
IMAGE_COMPRESSED_BYTES = 6692490107
Expand All @@ -27,9 +28,19 @@
"esp32": ("esp32_devkitc/esp32/procpu", "esp32", 0x1000),
"esp32s3": ("esp32s3_devkitc/esp32s3/procpu", "esp32s3", 0),
"esp32c3": ("esp32c3_devkitm/esp32c3", "esp32c3", 0),
"esp32s2mini": ("esp32s2_lolin_mini/esp32s2", "esp32s2", 0x1000),
}


def board_build_args(board):
args = ["-DEXTRA_CONF_FILE=" + str(ROOT / "ci/esp32.conf")]
if board == "esp32s2mini":
args = ["-DEXTRA_CONF_FILE=" + str(ROOT / "ci/esp32.conf") + ";" +
str(ROOT / "ci/s2mini.conf"), "-DSNIPPET=cdc-acm-console",
"-DDTC_OVERLAY_FILE=" + str(ROOT / "ci/s2mini.overlay")]
return args


def command(args, **kwargs):
return subprocess.run(args, check=True, **kwargs)

Expand Down Expand Up @@ -109,6 +120,12 @@ def docker(work, arguments, *, network="none", seconds=1800):
subprocess.run(["docker", "stop", "--time", "15", name], capture_output=True, timeout=30)


def ensure_image():
# An existing exact-digest image is already the requested immutable input.
if subprocess.run(["docker", "image", "inspect", IMAGE], capture_output=True, timeout=20).returncode:
command(["docker", "pull", IMAGE], timeout=900)


def build(board):
guard_environment()
run, attempt = os.environ.get("GITHUB_RUN_ID", ""), os.environ.get("GITHUB_RUN_ATTEMPT", "")
Expand All @@ -132,8 +149,9 @@ def build(board):
raise RuntimeError("Source export failed")
head = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=ROOT, text=True, timeout=15).strip()
(work / "source-head.txt").write_text(head + "\n")
command(["docker", "pull", IMAGE], timeout=900)
docker(work, ["python3", "/work/pqc-testing/ci/esp32_images.py", "prepare-container"], network="bridge")
ensure_image()
docker(work, ["python3", "/work/pqc-testing/ci/esp32_images.py", "prepare-container",
"--board", board], network="bridge")
docker(work, ["/work/.venv/bin/python", "/work/pqc-testing/ci/esp32_images.py", "build-container", "--board", board])
destination = ROOT / "build-esp32-artifacts" / board
shutil.copytree(work / "artifacts" / board, destination)
Expand All @@ -156,7 +174,7 @@ def update_imported_modules(west):
# Last matching filter wins. Exclude everything except these pinned projects.
command(west + ["config", "--", "manifest.project-filter", "-.*,+zephyr,+hal_espressif,+hal_xtensa"], timeout=30)
# Named project updates cannot resolve imported manifest entries in west1.5.
command(west + ["update", "--narrow"], timeout=600)
command(west + ["update", "--narrow", "--fetch-opt=--depth=1"], timeout=600)


def install_zephyr_requirements(python):
Expand All @@ -167,17 +185,36 @@ def install_zephyr_requirements(python):
command([python, "-c", "import jsonschema, elftools, yaml, pykwalify, west"], timeout=30)


def prepare_container():
def s2mini_patch_specs():
return ((Path("/work/zephyr"), ZEPHYR, "s2mini-zephyr-cache.patch"),
(Path("/work/modules/hal/espressif"), HAL_ESPRESSIF, "s2mini-hal-usb.patch"))


def apply_board_patches(board):
if board != "esp32s2mini":
return
for repo, revision, name in s2mini_patch_specs():
observed = subprocess.check_output(["git", "-C", str(repo), "rev-parse", "HEAD"],
text=True, timeout=15).strip()
if observed != revision:
raise RuntimeError("Wrong source revision for S2 USB backport")
patch = str(ROOT / "ci/patches" / name)
command(["git", "-C", str(repo), "apply", "--check", patch], timeout=15)
command(["git", "-C", str(repo), "apply", patch], timeout=15)


def prepare_container(board):
container_guard()
command(["python3", "-m", "venv", "--system-site-packages", "/work/.venv"], timeout=60)
python = "/work/.venv/bin/python"
install_build_tools(python)
west = [python, "-m", "west"]
command(west + ["init", "-l", "pqc-testing"], timeout=60)
command(west + ["update", "--narrow", "zephyr"], timeout=600)
command(west + ["update", "--narrow", "--fetch-opt=--depth=1", "zephyr"], timeout=600)
update_imported_modules(west)
if subprocess.check_output(["git", "-C", "zephyr", "rev-parse", "HEAD"], text=True).strip() != ZEPHYR:
raise RuntimeError("Wrong Zephyr source")
apply_board_patches(board)
install_zephyr_requirements(python)
command([python, str(ROOT / "firmware_inventory.py"), "--schema-dir", "/work/inventory-schemas",
"--fetch-schemas"], timeout=90)
Expand All @@ -194,19 +231,56 @@ def read_config(path):
return dict(line.split("=", 1) for line in path.read_text().splitlines() if line.startswith("CONFIG_") and "=" in line)


def compiled_flash_bytes(dts):
# Zephyr 4.5 derives Espressif flash size from chosen DT, not CONFIG_FLASH_SIZE.
sys.path.insert(0, "/work/zephyr/scripts/dts/python-devicetree/src")
from devicetree.dtlib import DT
flash = DT(str(dts)).get_node("/chosen").props["zephyr,flash"].to_path()
cells = flash.props["reg"].to_nums()
if len(cells) != 2 or cells[0] != 0:
raise RuntimeError("Unexpected flash address/size encoding")
return cells[1]


def check_s2mini_policy(config, flash_bytes):
observed = dict(flash_bytes=flash_bytes,
usb_cdc=config.get("CONFIG_CDC_ACM_SERIAL_INITIALIZE_AT_BOOT") == "y",
psram=config.get("CONFIG_ESP_SPIRAM") == "y",
stack_sentinel=config.get("CONFIG_STACK_SENTINEL") == "y")
expected = dict(flash_bytes=4 * 1024 * 1024, usb_cdc=True, psram=False, stack_sentinel=True)
if observed != expected:
raise RuntimeError("S2 Mini requires 4MB flash, USB CDC, stack sentinel and PSRAM disabled: " +
json.dumps(observed, sort_keys=True))


def package(board, profile, build_dir, output, head):
zephyr = build_dir / "zephyr"
config = read_config(zephyr / ".config")
target, chip, offset = BOARDS[board]
if config.get("CONFIG_ESP_SIMPLE_BOOT") != "y" or config.get("CONFIG_SOC", "").strip('"') != chip:
raise RuntimeError("Unexpected boot layout/SoC; do not publish flash instructions")
flash_bytes = compiled_flash_bytes(zephyr / "zephyr.dts")
if type(flash_bytes) is not int or flash_bytes <= offset or offset + (zephyr / "zephyr.bin").stat().st_size > flash_bytes:
raise RuntimeError("Image exceeds compiled flash layout")
if board == "esp32s2mini":
check_s2mini_policy(config, flash_bytes)
destination = output / board / profile
destination.mkdir(parents=True)
for name in ("zephyr.bin", "zephyr.elf", "zephyr.map"):
shutil.copyfile(zephyr / name, destination / name)
shutil.copyfile(zephyr / ".config", destination / "zephyr.config")
shutil.copyfile(zephyr / "zephyr.dts", destination / "zephyr.dts")
shutil.copyfile(ROOT / "LICENSE", destination / "LICENSE")
shutil.copyfile(ROOT / "THIRD_PARTY.md", destination / "THIRD_PARTY.md")
if board == "esp32s2mini":
shutil.copyfile(ROOT / "docs/s2mini-pqc.md", destination / "S2MINI-TEST.md")
for _, _, name in s2mini_patch_specs():
shutil.copyfile(ROOT / "ci/patches" / name, destination / name)
reports = sorted(build_dir.rglob("*.su"))
if profile == "mldsa44" and not reports:
raise RuntimeError("Missing compiler stack-usage reports")
(destination / "stack-usage.txt").write_text("".join(
f"# {p.relative_to(build_dir)}\n{p.read_text()}\n" for p in reports))
for label, upstream in (("ZEPHYR", Path("/work/zephyr")),
("HAL-ESPRESSIF", Path("/work/modules/hal/espressif")),
("HAL-XTENSA", Path("/work/modules/hal/xtensa"))):
Expand All @@ -233,12 +307,18 @@ def package(board, profile, build_dir, output, head):
for name, path in (("hal_espressif", "modules/hal/espressif"), ("hal_xtensa", "modules/hal/xtensa"))},
"boot_method": "ESP_SIMPLE_BOOT; unsigned development image",
"flash_offset": hex(offset), "serial_baud": 115200,
"image_bytes": (destination / "zephyr.bin").stat().st_size,
"image_bytes": (destination / "zephyr.bin").stat().st_size, "flash_bytes": flash_bytes,
"static_writable_section_bytes": writable,
"main_stack_bytes": int(config["CONFIG_MAIN_STACK_SIZE"], 0),
"hardware_tested": False, "pqc_tls": False,
"expectation": "RESULT: PASS; signature acceptance/rejection checks" if profile == "mldsa44" else "RESULT: PASS; baseline boot only",
"sha256": hashes}
if board == "esp32s2mini":
manifest.update(flash_bytes=4 * 1024 * 1024, console="USB CDC ACM; DTR wait up to 30s",
psram_enabled=False, advertised_psram_bytes=2 * 1024 * 1024,
clone_compatibility="XTVTX S2 Mini V1.0.0: unverified on hardware",
source_patches={name: {"base_revision": revision, "sha256": hashes[name]}
for _, revision, name in s2mini_patch_specs()})
inventories = firmware_inventory.make_documents(manifest)
for name, content in inventories.items():
(destination / name).write_bytes(content)
Expand Down Expand Up @@ -280,12 +360,15 @@ def build_container(board):
env = dict(os.environ, ZEPHYR_BASE="/work/zephyr", PATH="/work/.venv/bin:" + os.environ["PATH"])
command(["cmake", "-S", str(ROOT / "host"), "-B", "/work/build-host", "-G", "Ninja"], env=env, timeout=60)
command(["cmake", "--build", "/work/build-host", "--target", "fixture", "-j", "2"], env=env, timeout=180)
# Profiles share board/Kconfig/toolchain. Snapshot baseline first, then
# reconfigure application sources only; Ninja retains unchanged Zephyr objects.
# Each board/job still gets its own fresh disposable workspace.
directory = Path("/work") / f"build-{board}"
for profile in ("baseline", "mldsa44"):
directory = Path("/work") / f"build-{board}-{profile}"
command(["cmake", "-S", str(ROOT), "-B", str(directory), "-G", "Ninja",
"-DBOARD=" + BOARDS[board][0], "-DPQC_ENABLED=" + ("ON" if profile == "mldsa44" else "OFF"),
"-DFIXTURE_DIR=/work/build-host", "-DPython3_EXECUTABLE=" + sys.executable,
"-DEXTRA_CONF_FILE=" + str(ROOT / "ci/esp32.conf")], env=env, timeout=180)
*board_build_args(board)], env=env, timeout=180)
command(["cmake", "--build", str(directory), "-j", "2"], env=env, timeout=600)
package(board, profile, directory, Path("/work/artifacts"), head)

Expand All @@ -299,7 +382,7 @@ def main(argv=None):
try:
if args.phase == "preflight": preflight(args.job_name)
elif args.phase == "verify-runner": verify_runner(args.job_name)
elif args.phase == "prepare-container": prepare_container()
elif args.phase == "prepare-container" and args.board: prepare_container(args.board)
elif args.phase == "build" and args.board: build(args.board)
elif args.phase == "cleanup" and args.board: cleanup(args.board)
elif args.phase == "build-container" and args.board: build_container(args.board)
Expand Down
18 changes: 18 additions & 0 deletions ci/patches/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# S2 Mini USB backport

Only `esp32s2mini` applies these patches in its disposable CI dependency checkouts.
The base Zephyr v4.5.0 and hal_espressif revisions stay pinned; the other board
builds remain unmodified. Patch applicability and exact HEAD checks fail closed.

- `s2mini-hal-usb.patch`: missing S2 USB HAL includes and wrapper compilation,
adapted from [hal_espressif #694](https://github.com/zephyrproject-rtos/hal_espressif/pull/694).
- `s2mini-zephyr-cache.patch`: zero-length cache-range handling from
[Zephyr #125458](https://github.com/zephyrproject-rtos/zephyr/pull/125458).
- The associated USB devicetree node is in `../s2mini.overlay`, loaded before
the CDC-console snippet. `../s2mini.conf` sets the matching DWC2 stack size.

Upstream code is Apache-2.0; the existing artifact licence bundle includes the
Zephyr and HAL notices. Original patch adaptation assistance: Briar.
Artifacts include both patches and their SHA256/base-revision metadata. Hardware
enumeration and clone compatibility are still unverified. Retire this backport
when adopting a stable release that contains the complete S2 USB fixes.
25 changes: 25 additions & 0 deletions ci/patches/s2mini-hal-usb.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
diff --git a/zephyr/esp32s2/CMakeLists.txt b/zephyr/esp32s2/CMakeLists.txt
--- a/zephyr/esp32s2/CMakeLists.txt
+++ b/zephyr/esp32s2/CMakeLists.txt
@@ -78,4 +78,6 @@
../../components/esp_hal_uart/include
../../components/esp_hal_uart/${CONFIG_SOC_SERIES}/include
+ ../../components/esp_hal_usb/include
+ ../../components/esp_hal_usb/${CONFIG_SOC_SERIES}/include
../../components/esp_hal_wdt/include
../../components/esp_hal_wdt/${CONFIG_SOC_SERIES}/include
@@ -249,9 +251,14 @@
zephyr_sources_ifdef(CONFIG_I2S_ESP32
../../components/esp_hal_i2s/i2s_hal.c
../../components/hal/hal_utils.c
)

+ if (CONFIG_UDC_DWC2 OR CONFIG_UHC_DWC2)
+ zephyr_include_directories(../../components/usb/include)
+ zephyr_sources(../../components/esp_hal_usb/usb_wrap_hal.c)
+ endif()
+
zephyr_sources_ifdef(CONFIG_UART_ESP32
../../components/esp_hal_uart/uart_hal.c
../../components/esp_hal_uart/uart_hal_iram.c
)
36 changes: 36 additions & 0 deletions ci/patches/s2mini-zephyr-cache.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
diff --git a/drivers/cache/cache_esp32.c b/drivers/cache/cache_esp32.c
--- a/drivers/cache/cache_esp32.c
+++ b/drivers/cache/cache_esp32.c
@@ -44,6 +44,10 @@
int cache_data_flush_range(void *addr, size_t size)
{
esp_err_t ret;

+ if (size == 0U) {
+ return 0;
+ }
+
ret = esp_cache_msync(addr, size,
ESP_CACHE_MSYNC_FLAG_DIR_C2M | ESP_CACHE_MSYNC_FLAG_UNALIGNED);
@@ -58,6 +62,10 @@
uintptr_t aligned_addr = (uintptr_t)addr & ~(line - 1);
size_t aligned_size = (((uintptr_t)addr + size + line - 1) & ~(line - 1)) - aligned_addr;

+ if (size == 0U) {
+ return 0;
+ }
+
ret = esp_cache_msync((void *)aligned_addr, aligned_size, ESP_CACHE_MSYNC_FLAG_DIR_M2C);

return (ret == ESP_OK || ret == ESP_ERR_NOT_SUPPORTED) ? 0 : -EIO;
@@ -67,6 +75,10 @@
int cache_data_flush_and_invd_range(void *addr, size_t size)
{
esp_err_t ret;

+ if (size == 0U) {
+ return 0;
+ }
+
ret = esp_cache_msync(addr, size,
ESP_CACHE_MSYNC_FLAG_DIR_C2M | ESP_CACHE_MSYNC_FLAG_INVALIDATE |
5 changes: 5 additions & 0 deletions ci/s2mini.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# First bring-up uses internal SRAM only; the clone's advertised PSRAM is untested.
CONFIG_ESP_SPIRAM=n
CONFIG_STACK_SENTINEL=y
# Match the upstream S2 DWC2 support fix, rather than the generic 512-byte default.
CONFIG_UDC_DWC2_STACK_SIZE=1024
25 changes: 25 additions & 0 deletions ci/s2mini.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* S2 USB node adapted from upstream Zephyr PR #125458 for v4.5.0.
* SPDX-License-Identifier: Apache-2.0
*/
/* Loaded before the CDC snippet so its zephyr_udc0 reference is resolvable. */
&{/soc} {
zephyr_udc0: usb_otg: usb_otg@60080000 {
compatible = "espressif,esp32-usb-otg-fs", "snps,dwc2";
reg = <0x60080000 DT_SIZE_K(256)>;
interrupts = <USB_INTR_SOURCE IRQ_DEFAULT_PRIORITY 0>;
interrupt-parent = <&intc>;
clocks = <&clock ESP32_USB_MODULE>;
num-out-eps = <7>;
num-in-eps = <5>;
ghwcfg1 = <0x00000000>;
ghwcfg2 = <0x224dd930>;
ghwcfg4 = <0xd3f0a030>;
g-rx-fifo-size = <64>;
g-np-tx-fifo-size = <16>;
g-tx-fifo-size = <32 32 32 24>;
phy-dp-pin = <20>;
phy-dm-pin = <19>;
status = "okay";
};
};
Loading