diff options
Diffstat (limited to 'tools')
| -rwxr-xr-x | tools/apply_nss.py | 149 | ||||
| -rw-r--r-- | tools/apply_wifi.py | 281 | ||||
| -rw-r--r-- | tools/bhvm.py | 119 | ||||
| -rwxr-xr-x | tools/collect_info.sh | 41 | ||||
| -rwxr-xr-x | tools/consolidate_ckb01.sh | 82 | ||||
| -rw-r--r-- | tools/mkboard.py | 147 | ||||
| -rwxr-xr-x | tools/update_usb.sh | 55 | ||||
| -rwxr-xr-x | tools/verify_build.sh | 47 | ||||
| -rwxr-xr-x | tools/verify_nss_build.sh | 53 | ||||
| -rwxr-xr-x | tools/watch_build.sh | 44 | ||||
| -rwxr-xr-x | tools/watch_build2.sh | 44 |
11 files changed, 1062 insertions, 0 deletions
diff --git a/tools/apply_nss.py b/tools/apply_nss.py new file mode 100755 index 0000000..fa520e8 --- /dev/null +++ b/tools/apply_nss.py @@ -0,0 +1,149 @@ +#!/usr/bin/env python3 +"""Port CKB01 to the qosmio 6.6 NSS tree (~/openwrt-nss). + +Idempotent. Run inside the build VM: python3 apply_nss.py [--dry-run] + +Steps + 1. target/linux/qualcommax/files/arch/arm64/boot/dts/qcom/ipq8072-ckb01.dts + (canonical copy in ~/ckb01/dts/ipq8072-ckb01-nss.dts) + - fixed 11 partitions (0:ART) instead of qcom,smem-part + - includes ipq8074-nss.dtsi + - qca-ssdk switch + qcom,nss-dp ports (6.6 binding, not the 6.18 DSA one) + 2. target/linux/qualcommax/image/ipq807x.mk: Device/oppo_ckb01 + 3. .../ipq807x/base-files/etc/hotplug.d/firmware/11-ath11k-caldata + - oppo,ckb01: caldata_extract "0:ART" 0x1000 0x20000 + 4. package/firmware/ckb01-wifi (board-2.bin -> ath11k/IPQ8074/hw2.0/) + 5. target/linux/qualcommax/config-6.6: pin the symbols added by the qca + skb_recycler patch (0981-1). Without them kconfig stops on a new prompt + during syncconfig and target/linux fails with "Error 1". +""" +import os +import shutil +import sys + +TREE = os.path.expanduser("~/openwrt-nss") +DTS_SRC = os.path.expanduser("~/ckb01/dts/ipq8072-ckb01-nss.dts") +PKG_MK = os.path.expanduser("~/ckb01/wifi/ckb01-wifi.Makefile") +BOARD = os.path.expanduser("~/ckb01/wifi/board-oppo_ckb01.ipq8074") +DRY = "--dry-run" in sys.argv + +DTS_DST = os.path.join(TREE, "target/linux/qualcommax/files/arch/arm64/boot/dts/qcom/ipq8072-ckb01.dts") +IPQ807X_MK = os.path.join(TREE, "target/linux/qualcommax/image/ipq807x.mk") +CALDATA = os.path.join(TREE, "target/linux/qualcommax/ipq807x/base-files/etc/hotplug.d/firmware/11-ath11k-caldata") +PKG_DIR = os.path.join(TREE, "package/firmware/ckb01-wifi") + +DEVICE_BLOCK = """ +define Device/oppo_ckb01 +\t$(call Device/FitImage) +\tDEVICE_VENDOR := OPPO +\tDEVICE_MODEL := CKB01 +\tDEVICE_ALT0_VENDOR := Softbank +\tDEVICE_ALT0_MODEL := AirTerminal 5 +\tDEVICE_DTS_CONFIG := config@hk09 +\tSOC := ipq8072 +\tDEVICE_PACKAGES := kmod-mhi-pci-generic kmod-mhi-net kmod-mhi-wwan-ctrl \\ +\t\tath11k-firmware-ipq8074 kmod-ath11k-ahb ckb01-wifi +endef +TARGET_DEVICES += oppo_ckb01 +""" + + +def read(p): + with open(p, encoding="utf-8") as f: + return f.read() + + +def write(p, s): + if DRY: + print(" [dry-run] would write", p) + return + with open(p, "w", encoding="utf-8") as f: + f.write(s) + + +def step_dts(): + if not os.path.exists(DTS_SRC): + raise SystemExit("missing canonical dts: " + DTS_SRC) + if DRY: + print(" [dry-run] would install", DTS_DST) + return + shutil.copyfile(DTS_SRC, DTS_DST) + print(" dts: installed ipq8072-ckb01.dts") + + +def step_device(): + s = read(IPQ807X_MK) + if "Device/oppo_ckb01" in s: + print(" device: already present") + return + write(IPQ807X_MK, s.rstrip("\n") + "\n" + DEVICE_BLOCK) + print(" device: added oppo_ckb01") + + +def step_caldata(): + s = read(CALDATA) + if "oppo,ckb01" in s: + print(" caldata: already patched") + return + anchor = "\tarcadyan,aw1000|\\\n" + if anchor not in s: + raise SystemExit("caldata: anchor not found") + new = ("\toppo,ckb01)\n" + "\t\t# vendor read_caldata_to_fs.sh (ap-hk* branch): ART+0x1000, 128 KiB\n" + "\t\tcaldata_extract \"0:ART\" 0x1000 0x20000\n" + "\t\t;;\n") + anchor + write(CALDATA, s.replace(anchor, new, 1)) + print(" caldata: oppo,ckb01 -> 0:ART 0x1000 0x20000") + + +def step_package(): + if os.path.exists(os.path.join(PKG_DIR, "Makefile")): + print(" ckb01-wifi: already present") + return + if DRY: + print(" [dry-run] would create", PKG_DIR) + return + os.makedirs(os.path.join(PKG_DIR, "files"), exist_ok=True) + shutil.copyfile(PKG_MK, os.path.join(PKG_DIR, "Makefile")) + shutil.copyfile(BOARD, os.path.join(PKG_DIR, "files", "board-2.bin")) + print(" ckb01-wifi: created") + + +KCONFIG_TAIL = """ +# qca skb_recycler patch (0981-1) adds these; pin them so kconfig does not +# stop on a new prompt during syncconfig. +# CONFIG_SKB_RECYCLER is not set +# CONFIG_ALLOC_SKB_PAGE_FRAG_DISABLE is not set + +# ...and its header uses skb->active_extensions, which only exists when the +# hidden SKB_EXTENSIONS bool is enabled. That symbol has no prompt, so it +# cannot be set directly; select it through BRIDGE_NETFILTER, which is a +# normal option for a bridge/router and also what bridged firewalling needs. +CONFIG_BRIDGE_NETFILTER=y +""" + + +def step_kconfig(): + p = os.path.join(TREE, "target/linux/qualcommax/config-6.6") + s = read(p) + if "CONFIG_BRIDGE_NETFILTER=y" in s and "ALLOC_SKB_PAGE_FRAG_DISABLE" in s: + print(" config-6.6: already pinned") + return + write(p, s.rstrip("\n") + "\n" + KCONFIG_TAIL) + print(" config-6.6: pinned SKB_RECYCLER / ALLOC_SKB_PAGE_FRAG_DISABLE / BRIDGE_NETFILTER") + + +def main(): + if not os.path.isdir(TREE): + raise SystemExit("no tree at " + TREE) + print("porting CKB01 to", TREE, "(dry-run)" if DRY else "") + step_dts() + step_device() + step_caldata() + step_package() + step_kconfig() + print("done") + + +if __name__ == "__main__": + main() diff --git a/tools/apply_wifi.py b/tools/apply_wifi.py new file mode 100644 index 0000000..578cc8b --- /dev/null +++ b/tools/apply_wifi.py @@ -0,0 +1,281 @@ +#!/usr/bin/env python3 +"""Apply the CKB01 Wi-Fi (ath11k) enablement to the OpenWrt tree. + +Idempotent. Run inside the build VM: python3 apply_wifi.py [--dry-run] + +What it changes (evidence in ~/ckb01/patches/WIFI_CKB01.md): + +1. target/linux/qualcommax/dts/ipq8072-ckb01.dts + - SPI flash: qcom,smem-part -> the 11 fixed partitions the vendor boot log + shows. smem-part parses the NAND table and refuses a 4K-sector NOR + device, so today 0:ART never appears. + - add &wifi { status = "okay"; }. + +2. package/firmware/ckb01-wifi/ (new, device-scoped) + - installs files/board-2.bin to /lib/firmware/ath11k/IPQ8074/hw2.0/. + (The generic ipq-wifi package does not work here: its source is a tarball + and its install-overlay globs $(PKG_BUILD_DIR)/board-*. See the doc.) + +3. .../ipq807x/base-files/etc/hotplug.d/firmware/11-ath11k-caldata + - oppo,ckb01: caldata_extract "0:ART" 0x1000 0x20000 + +4. target/linux/qualcommax/image/ipq807x.mk + - DEVICE_PACKAGES += ath11k-firmware-ipq8074 kmod-ath11k-ahb ckb01-wifi +""" +import os +import shutil +import sys + +TREE = os.path.expanduser("~/openwrt") +BOARD = os.path.expanduser("~/ckb01/wifi/board-oppo_ckb01.ipq8074") +DRY = "--dry-run" in sys.argv + +DTS = os.path.join(TREE, "target/linux/qualcommax/dts/ipq8072-ckb01.dts") +PKG_DIR = os.path.join(TREE, "package/firmware/ckb01-wifi") +CALDATA_SH = os.path.join(TREE, "target/linux/qualcommax/ipq807x/base-files/etc/hotplug.d/firmware/11-ath11k-caldata") +IPQ807X_MK = os.path.join(TREE, "target/linux/qualcommax/image/ipq807x.mk") + +PARTITIONS = """ partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + partition@0 { + label = "0:SBL1"; + reg = <0x0 0x40000>; + read-only; + }; + + partition@40000 { + label = "0:MIBIB"; + reg = <0x40000 0x10000>; + read-only; + }; + + partition@50000 { + label = "0:QSEE"; + reg = <0x50000 0x160000>; + read-only; + }; + + partition@1b0000 { + label = "0:DEVCFG"; + reg = <0x1b0000 0x10000>; + read-only; + }; + + partition@1c0000 { + label = "0:RPM"; + reg = <0x1c0000 0x20000>; + read-only; + }; + + partition@1e0000 { + label = "0:CDT"; + reg = <0x1e0000 0x10000>; + read-only; + }; + + partition@1f0000 { + label = "0:APPSBLENV"; + reg = <0x1f0000 0x10000>; + read-only; + }; + + partition@200000 { + label = "0:APPSBL"; + reg = <0x200000 0xa0000>; + read-only; + }; + + partition@2a0000 { + label = "0:ART"; + reg = <0x2a0000 0x40000>; + read-only; + }; + + partition@2e0000 { + label = "0:OEM"; + reg = <0x2e0000 0x10000>; + read-only; + }; + + partition@2f0000 { + label = "0:CRASH"; + reg = <0x2f0000 0x20000>; + read-only; + }; + };""" + +OLD_PARTITIONS = """ partitions { + compatible = "qcom,smem-part"; + };""" + +WIFI_NODE = """ +&wifi { + status = "okay"; +}; +""" + +PKG_MAKEFILE = """include $(TOPDIR)/rules.mk + +PKG_NAME:=ckb01-wifi +PKG_RELEASE:=1 + +include $(INCLUDE_DIR)/package.mk + +define Build/Compile +endef + +define Package/ckb01-wifi + SECTION:=firmware + CATEGORY:=Firmware + TITLE:=CKB01 ath11k board-2.bin + DEPENDS:=@TARGET_qualcommax +endef + +define Package/ckb01-wifi/install +\t$(INSTALL_DIR) $(1)/lib/firmware/ath11k/IPQ8074/hw2.0 +\t$(INSTALL_DATA) ./files/board-2.bin $(1)/lib/firmware/ath11k/IPQ8074/hw2.0/board-2.bin +endef + +$(eval $(call BuildPackage,ckb01-wifi)) +""" + + +def read(p): + with open(p, "r", encoding="utf-8") as f: + return f.read() + + +def write(p, s): + if DRY: + print(" [dry-run] would write", p) + return + tmp = p + ".new" + with open(tmp, "w", encoding="utf-8") as f: + f.write(s) + shutil.move(tmp, p) + + +def step_dts(): + s = read(DTS) + changed = False + if OLD_PARTITIONS in s: + s = s.replace(OLD_PARTITIONS, PARTITIONS) + changed = True + print(" dts: smem-part -> 11 fixed partitions") + elif 'label = "0:ART"' in s: + print(" dts: fixed partitions already present") + else: + raise SystemExit("dts: could not find the partitions block") + + if "&wifi {" not in s: + s = s.rstrip("\n") + "\n" + WIFI_NODE + changed = True + print(" dts: added &wifi node") + else: + print(" dts: &wifi already present") + + if changed: + write(DTS, s) + + +def step_package(): + if os.path.exists(os.path.join(PKG_DIR, "Makefile")): + print(" ckb01-wifi: already present") + return + if DRY: + print(" [dry-run] would create", PKG_DIR) + return + os.makedirs(os.path.join(PKG_DIR, "files"), exist_ok=True) + with open(os.path.join(PKG_DIR, "Makefile"), "w", encoding="utf-8") as f: + f.write(PKG_MAKEFILE) + shutil.copyfile(BOARD, os.path.join(PKG_DIR, "files", "board-2.bin")) + print(" ckb01-wifi: created package + board-2.bin") + + +def step_caldata(): + s = read(CALDATA_SH) + if "oppo,ckb01" in s: + print(" caldata: oppo,ckb01 already handled") + return + old = """ arcadyan,aw1000|\\ + buffalo,wxr-5950ax12|\\ + cmcc,rm2-6|\\ + compex,wpq873|\\ + edgecore,eap102|\\ + edimax,cax1800|\\ + linksys,mx5300|\\ + netgear,wax218|\\ + redmi,ax6|\\ + xiaomi,ax3600|\\ + xiaomi,ax9000|\\ + yuncore,ax880|\\ + zte,mf269) + caldata_extract "0:art" 0x1000 0x20000 + ;; +""" + new = """ oppo,ckb01) + # vendor read_caldata_to_fs.sh (ap-hk* branch): ART+0x1000, 128 KiB + caldata_extract "0:ART" 0x1000 0x20000 + ;; + arcadyan,aw1000|\\ + buffalo,wxr-5950ax12|\\ + cmcc,rm2-6|\\ + compex,wpq873|\\ + edgecore,eap102|\\ + edimax,cax1800|\\ + linksys,mx5300|\\ + netgear,wax218|\\ + redmi,ax6|\\ + xiaomi,ax3600|\\ + xiaomi,ax9000|\\ + yuncore,ax880|\\ + zte,mf269) + caldata_extract "0:art" 0x1000 0x20000 + ;; +""" + if old not in s: + raise SystemExit("caldata: case block not found (tree changed?)") + s = s.replace(old, new) + write(CALDATA_SH, s) + print(" caldata: added oppo,ckb01 -> 0:ART 0x1000 0x20000") + + +def step_device(): + s = read(IPQ807X_MK) + if "ckb01-wifi" in s: + print(" device: ckb01-wifi already in DEVICE_PACKAGES") + return + old = """ DEVICE_DTS_CONFIG := config@hk09 + SOC := ipq8072 + DEVICE_PACKAGES := kmod-mhi-pci-generic kmod-mhi-net kmod-mhi-wwan-ctrl +endef +TARGET_DEVICES += oppo_ckb01""" + new = """ DEVICE_DTS_CONFIG := config@hk09 + SOC := ipq8072 + DEVICE_PACKAGES := kmod-mhi-pci-generic kmod-mhi-net kmod-mhi-wwan-ctrl \\ + ath11k-firmware-ipq8074 kmod-ath11k-ahb ckb01-wifi +endef +TARGET_DEVICES += oppo_ckb01""" + if old not in s: + raise SystemExit("device: oppo_ckb01 block not found") + s = s.replace(old, new) + write(IPQ807X_MK, s) + print(" device: added ath11k-firmware-ipq8074 kmod-ath11k-ahb ckb01-wifi") + + +def main(): + if not os.path.isdir(TREE): + raise SystemExit("no tree at " + TREE) + print("applying to", TREE, "(dry-run)" if DRY else "") + step_dts() + step_package() + step_caldata() + step_device() + print("done") + + +if __name__ == "__main__": + main() diff --git a/tools/bhvm.py b/tools/bhvm.py new file mode 100644 index 0000000..a78846c --- /dev/null +++ b/tools/bhvm.py @@ -0,0 +1,119 @@ +#!/usr/bin/env python3 +"""Tiny client for bhyvemgrd's UNIX-socket JSON protocol. + +Why this exists: the only privileged channel on this host is bhyvemgrd (it runs +as root via mdo). beatrice is in group wheel, and the socket is srwxrwx--- root +wheel, so a plain user can ask the daemon to create/start/stop VMs and to +create/attach tap devices -- no sudo needed. + +Protocol (from /ROM/bhyve/bhyvemgr-src/src/unit_socket.pas): + one JSON object per line, '\n' terminated + request : {"type":"task","id":<uuid>,"method":<m>,"params":{...}} + reply : {"type":"task","id":<uuid>,"success":true,...} + events : {"type":"event",...} + on connect the daemon first sends {"type":"snapshot","vms":{...}} + +Methods seen in the GUI source: vm.create (params: vmname), vm.start +(vmname, isrebooting), vm.stop, vm.destroy, vm.delete, network.create_device +(device, vmname, mtu), network.attach_bridge (bridge, device), +network.destroy_device (ifname). + +Usage: + bhvm.py list + bhvm.py call <method> '<json params>' + bhvm.py create <name> # register an already-written VM dir + bhvm.py start <name> + bhvm.py destroy <name> # power off the instance (vm.stop is refused + # while vCPU threads are active; destroy works) + bhvm.py net <tap> <vmname> # ifconfig <tap> create + addm to bhyve0 + bhvm.py watch # connect and print events for 10 s +""" +import json +import select +import socket +import sys +import time +import uuid + +SOCK = "/var/run/bhyvemgrd/bhyvemgrd.sock" +BRIDGE = "bhyve0" + + +def client(): + s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + s.connect(SOCK) + return s + + +def drain(s, seconds, rid=None): + end = time.time() + seconds + buf = b"" + done = False + while time.time() < end: + r, _, _ = select.select([s], [], [], 0.3) + if not r: + continue + d = s.recv(65536) + if not d: + break + buf += d + if rid and ('"id" : "%s"' % rid) in buf.decode("utf-8", "replace"): + # keep reading briefly for the follow-up event + done = True + end = min(end, time.time() + 0.6) + lines = [l for l in buf.decode("utf-8", "replace").split("\n") if l.strip()] + if done: + return lines + return lines + + +def call(method, params=None, wait=6.0): + s = client() + rid = str(uuid.uuid4()) + req = {"type": "task", "id": rid, "method": method, "params": params or {}} + s.sendall((json.dumps(req) + "\n").encode()) + lines = drain(s, wait, rid) + s.close() + ok = any('"success" : true' in l and rid in l for l in lines) + for l in lines: + print(l[:800]) + return ok + + +def main(): + if len(sys.argv) < 2: + print(__doc__) + return 2 + cmd = sys.argv[1] + if cmd == "list": + s = client() + for l in drain(s, 2.0): + print(l[:2000]) + s.close() + elif cmd == "call": + call(sys.argv[2], json.loads(sys.argv[3]) if len(sys.argv) > 3 else {}) + elif cmd == "create": + call("vm.create", {"vmname": sys.argv[2]}) + elif cmd == "start": + call("vm.start", {"vmname": sys.argv[2], "isrebooting": "False"}, wait=10.0) + elif cmd == "destroy": + call("vm.destroy", {"vmname": sys.argv[2]}) + elif cmd == "delete": + call("vm.delete", {"vmname": sys.argv[2]}) + elif cmd == "net": + tap, vm = sys.argv[2], sys.argv[3] + call("network.create_device", {"device": tap, "vmname": vm, "mtu": "1500"}, wait=3) + call("network.attach_bridge", {"bridge": BRIDGE, "device": tap}, wait=3) + elif cmd == "watch": + s = client() + for l in drain(s, float(sys.argv[2]) if len(sys.argv) > 2 else 10.0): + print(l[:2000]) + s.close() + else: + print(__doc__) + return 2 + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tools/collect_info.sh b/tools/collect_info.sh new file mode 100755 index 0000000..2353871 --- /dev/null +++ b/tools/collect_info.sh @@ -0,0 +1,41 @@ +#!/bin/sh +# Collect CKB01 diagnostics on the device (OpenWrt initramfs). +# Run on the CKB01: sh collect_info.sh +# Result: /tmp/ckb01-info.tgz +set -u + +OUT=/tmp/ckb01-info +rm -rf "$OUT" +mkdir -p "$OUT" + +save() { + name=$1 + shift + { echo "# $*"; "$@"; } > "$OUT/$name.txt" 2>&1 || true +} + +save uname uname -a +save cmdline cat /proc/cmdline +save mtd cat /proc/mtd +save partitions cat /proc/partitions +save dmesg dmesg +save iw_phy iw phy +save iw_dev iw dev +save ip_link ip link +save ip_addr ip addr +save lsmod lsmod +save modules_d sh -c 'cat /etc/modules.d/* 2>/dev/null' +save firmware sh -c 'ls -lR /lib/firmware/ath11k /lib/firmware/IPQ8074 /lib/firmware/qca-nss* 2>/dev/null' +save nss_config sh -c 'cat /etc/config/nss /etc/config/ecm 2>/dev/null' +save nss_status sh -c '/etc/init.d/qca-nss-drv status 2>&1; /etc/init.d/qca-nss-ecm status 2>&1' +save nss_debugfs sh -c 'ls -lR /sys/kernel/debug/qca-nss-drv 2>/dev/null' +save nss_proc sh -c 'cat /proc/net/nss* 2>/dev/null' + +dmesg 2>/dev/null | grep -i -E 'ath11k|qmi|board_id|caldata|nss|ecm|ssdk|edma' \ + > "$OUT/dmesg_filtered.txt" 2>&1 || true +iw phy > "$OUT/iw_phy_clean.txt" 2>&1 || true + +cd /tmp || exit 1 +tar -czf /tmp/ckb01-info.tgz ckb01-info +ls -l /tmp/ckb01-info.tgz +echo "done: /tmp/ckb01-info.tgz" diff --git a/tools/consolidate_ckb01.sh b/tools/consolidate_ckb01.sh new file mode 100755 index 0000000..de314d6 --- /dev/null +++ b/tools/consolidate_ckb01.sh @@ -0,0 +1,82 @@ +#!/bin/sh +# Consolidate the CKB01 project into /ROM/Projects/ckb01. +# +# Run as beatrice AFTER root has created the target: +# mkdir -p /ROM/Projects/ckb01 && chown beatrice:wheel /ROM/Projects/ckb01 +# +# Idempotent. Stops the build VM, moves its disk (same filesystem: rename), +# updates the bhyve config, restarts it, then copies docs/artifacts/sources. +set -u + +DEST=/ROM/Projects/ckb01 +SRC_HOME=$HOME/ckb01 +VM_DISK_OLD=/ROM/ckb01vm/ckb01.raw +VM_DISK_NEW=$DEST/vm/ckb01.raw +VM_CONF=/ROM/bhyve/bhyvemgr/ckb01/bhyve_config.conf + +die() { echo "ERROR: $*" >&2; exit 1; } + +[ -d "$DEST" ] || die "$DEST does not exist (root must create it)" +[ -w "$DEST" ] || die "$DEST is not writable by $(id -un)" +[ -d "$SRC_HOME" ] || die "$SRC_HOME missing" + +echo "== layout ==" +mkdir -p "$DEST"/docs "$DEST"/out "$DEST"/tools "$DEST"/patches "$DEST"/dts \ + "$DEST"/wifi "$DEST"/analysis "$DEST"/evidence "$DEST"/firmware \ + "$DEST"/sources "$DEST"/vm "$DEST"/logs || die "mkdir failed" + +echo "== docs / artifacts from $SRC_HOME ==" +for f in README.md PLAN.md NSS_BUILD.md BUILD_VM.md NSS_DECOMPILE_PLAN.md MANIFEST.txt; do + [ -f "$SRC_HOME/$f" ] && cp -p "$SRC_HOME/$f" "$DEST/docs/" && echo " docs/$f" +done +for d in analysis evidence firmware patches tools dts wifi; do + [ -d "$SRC_HOME/$d" ] && cp -Rp "$SRC_HOME/$d/." "$DEST/$d/" && echo " $d/" +done +[ -d "$SRC_HOME/out" ] && cp -Rp "$SRC_HOME/out/." "$DEST/out/" && echo " out/" +for l in "$SRC_HOME"/build-progress*.log; do + [ -f "$l" ] && cp -p "$l" "$DEST/logs/" +done + +echo "== stock sources (read-only originals) ==" +[ -d /ROM/ckb01/ckb01-main ] && cp -Rp /ROM/ckb01/ckb01-main "$DEST/sources/" 2>/dev/null && echo " sources/ckb01-main" +[ -d /ROM/ckb01/src ] && cp -Rp /ROM/ckb01/src "$DEST/sources/" 2>/dev/null && echo " sources/src" +[ -f /ROM/ckb01/ckb01-repo.tar.gz ] && cp -p /ROM/ckb01/ckb01-repo.tar.gz "$DEST/sources/" && echo " sources/ckb01-repo.tar.gz" +for f in /ROM/ckb01/*.md; do [ -f "$f" ] && cp -p "$f" "$DEST/docs/"; done +if [ -d /ROM/ckb01/work/vroot ] && [ ! -d "$DEST/sources/stock-rootfs" ]; then + echo " copying stock rootfs (1.2G, unreadable files skipped)..." + cp -Rp /ROM/ckb01/work/vroot "$DEST/sources/stock-rootfs" 2>/dev/null || true +fi + +echo "== VM disk ==" +if [ -f "$VM_DISK_OLD" ]; then + if pgrep -f "bhyve.*ckb01" >/dev/null 2>&1; then + echo " stopping VM..." + python3 "$SRC_HOME/tools/bhvm.py" destroy ckb01 >/dev/null 2>&1 || true + i=0 + while pgrep -f "bhyve.*ckb01" >/dev/null 2>&1; do + i=$((i+1)); [ "$i" -gt 60 ] && die "VM did not stop" + sleep 2 + done + fi + if [ -e "$VM_DISK_NEW" ]; then + echo " $VM_DISK_NEW already exists (skipping move)" + else + echo " moving disk (rename on same fs)..." + mv "$VM_DISK_OLD" "$VM_DISK_NEW" || die "move failed" + fi + if [ -f "$VM_CONF" ] && grep -q "$VM_DISK_OLD" "$VM_CONF"; then + sed -i '' "s|$VM_DISK_OLD|$VM_DISK_NEW|" "$VM_CONF" + echo " updated $VM_CONF" + fi + grep -n "pci.0.3.0.path" "$VM_CONF" 2>/dev/null + echo " starting VM..." + python3 "$SRC_HOME/tools/bhvm.py" start ckb01 >/dev/null 2>&1 || true +else + echo " $VM_DISK_OLD not present (already moved?)" + grep -n "pci.0.3.0.path" "$VM_CONF" 2>/dev/null +fi + +echo "== sizes ==" +du -sh "$DEST" 2>/dev/null +du -sh "$DEST"/* 2>/dev/null +echo "done" diff --git a/tools/mkboard.py b/tools/mkboard.py new file mode 100644 index 0000000..ef45220 --- /dev/null +++ b/tools/mkboard.py @@ -0,0 +1,147 @@ +#!/usr/bin/env python3 +"""Build ath11k artefacts for CKB01 from the vendor material. + +Inputs (read-only): + /ROM/ckb01/ckb01-main/GD25LQ32C(1.8v)air5ok.BIN raw SPI flash (+0x600 trailing FF) + ~/ckb01/firmware/wifi-ckb01-ipq8074/files/bdwlan.* vendor per-board BDFs + +Outputs (~/ckb01/wifi/): + caldata.bin ART+0x1000, 128 KiB (this device's own calibration) + board-oppo_ckb01.ipq8074 board-2.bin container (all vendor BDFs + bus=ahb fallback) + +board-2.bin format (drivers/net/wireless/ath/ath11k/{core.c,hw.h}, linux master): + "QCA-ATH11K-BOARD\0" padded to 4 bytes (20 bytes total) + repeat: + le32 id = 0 (ATH11K_BD_IE_BOARD) + le32 len = inner length (name IE + data IE, padded) + inner: + le32 id = 0 (BOARD_NAME), le32 len, name bytes, pad to 4 + le32 id = 1 (BOARD_DATA), le32 len, bdf bytes, pad to 4 +""" +import glob +import os +import struct +import sys + +SPI = "/ROM/Projects/ckb01/sources/ckb01-main/GD25LQ32C(1.8v)air5ok.BIN" +BDFDIR = "/ROM/Projects/ckb01/firmware/wifi-ckb01-ipq8074/files" +OUT = "/ROM/Projects/ckb01/wifi" + +ART_OFF = 0x2A0000 +CAL_OFF = ART_OFF + 0x1000 +CAL_LEN = 0x20000 + +MAGIC = b"QCA-ATH11K-BOARD\0" +IE_BOARD = 0 +IE_BOARD_NAME = 0 +IE_BOARD_DATA = 1 + + +def pad4(b): + return b + b"\x00" * ((4 - len(b) % 4) % 4) + + +def ie(ie_id, payload): + return struct.pack("<II", ie_id, len(payload)) + pad4(payload) + + +def board_entry(name, data): + inner = ie(IE_BOARD_NAME, name.encode()) + ie(IE_BOARD_DATA, data) + return ie(IE_BOARD, inner) + + +def build_board2(entries): + out = MAGIC + b"\x00" * ((4 - len(MAGIC) % 4) % 4) + for name, data in entries: + out += board_entry(name, data) + return out + + +def parse_board2(buf, wanted): + """Re-implementation of the kernel's parser, to prove the file is readable.""" + magic_len = len(MAGIC) + magic_len = (magic_len + 3) & ~3 + if buf[:len(MAGIC)] != MAGIC: + raise SystemExit("bad magic") + pos = magic_len + found = {} + while len(buf) - pos > 8: + ie_id, ie_len = struct.unpack_from("<II", buf, pos) + pos += 8 + if len(buf) - pos < ((ie_len + 3) & ~3): + raise SystemExit("invalid outer ie length") + if ie_id == IE_BOARD: + inner = buf[pos:pos + ie_len] + p = 0 + name = None + while len(inner) - p > 8: + bid, blen = struct.unpack_from("<II", inner, p) + p += 8 + if len(inner) - p < ((blen + 3) & ~3): + raise SystemExit("invalid inner ie length") + val = inner[p:p + blen] + p += (blen + 3) & ~3 + if bid == IE_BOARD_NAME: + name = val.decode() + elif bid == IE_BOARD_DATA: + if name in wanted: + found[name] = len(val) + pos += (ie_len + 3) & ~3 + return found + + +def main(): + os.makedirs(OUT, exist_ok=True) + raw = open(SPI, "rb").read() + if len(raw) < ART_OFF + 0x40000: + raise SystemExit("SPI dump too short") + + cal = raw[CAL_OFF:CAL_OFF + CAL_LEN] + if cal[:4] != b"\x01\x00\x04\x04": + print("warning: caldata does not start with the expected 01 00 04 04", file=sys.stderr) + open(os.path.join(OUT, "caldata.bin"), "wb").write(cal) + print("caldata.bin %d bytes sha256=%s" % (len(cal), __import__("hashlib").sha256(cal).hexdigest()[:16])) + + bdfs = sorted(glob.glob(os.path.join(BDFDIR, "bdwlan.b*"))) + entries = [] + for p in bdfs: + suffix = os.path.basename(p).split(".b")[-1] + if not suffix.isdigit(): + continue + data = open(p, "rb").read() + if len(data) != CAL_LEN: + print("skip %s (size %d)" % (p, len(data)), file=sys.stderr) + continue + entries.append(("bus=ahb,qmi-chip-id=0,qmi-board-id=%s" % suffix, data)) + + # The stock DTS says qcom,board-id = <0x08 0x00> and the firmware has no + # bdwlan.b08, so the vendor default bdwlan.bin is the BDF this device uses. + # mainline ath11k asks for qmi-board-id=255 (the FW reports no board info), + # so bind that name (and the bus fallback) to bdwlan.bin as well. + default = os.path.join(BDFDIR, "bdwlan.bin") + if os.path.exists(default): + data = open(default, "rb").read() + else: + data = entries[0][1] + entries.insert(0, ("bus=ahb,qmi-chip-id=0,qmi-board-id=255", data)) + entries.append(("bus=ahb", data)) + + # board.bin (API1) is what the stock firmware loads; keep it as a fallback + open(os.path.join(OUT, "board.bin"), "wb").write(data) + print("board.bin %d bytes sha256=%s" % (len(data), __import__("hashlib").sha256(data).hexdigest()[:16])) + + blob = build_board2(entries) + path = os.path.join(OUT, "board-oppo_ckb01.ipq8074") + open(path, "wb").write(blob) + print("board-2.bin %d bytes entries=%d" % (len(blob), len(entries))) + + wanted = {n for n, _ in entries} + got = parse_board2(blob, wanted) + print("parser check: %d/%d entries readable" % (len(got), len(entries))) + print("fallback bus=ahb present:", "bus=ahb" in got) + for n in list(got)[:3]: + print(" %-50s %d" % (n, got[n])) + + +if __name__ == "__main__": + main() diff --git a/tools/update_usb.sh b/tools/update_usb.sh new file mode 100755 index 0000000..6d49e87 --- /dev/null +++ b/tools/update_usb.sh @@ -0,0 +1,55 @@ +#!/bin/sh +# Replace the OpenWrt initramfs ITB on the CKB01 boot USB stick (FreeBSD host). +# +# su -c 'sh /ROM/Projects/ckb01/tools/update_usb.sh' +# +# The stick must be the 7.5G "General UDisk" with +# da1s1: MBR fat32lba 512M (CKB01BOOT) +# da1s2: MBR linux-data 1.5G (ckb01-rootfs) +set -eu + +IMG=/ROM/Projects/ckb01/out/ckb01-nss-wifi-hb-initramfs.itb +DEV=/dev/da1s1 +DISK=/dev/da1 +MNT=/mnt/usb + +if [ "$(id -u)" != 0 ]; then + echo "root required: su -c 'sh $0'" >&2 + exit 1 +fi +[ -f "$IMG" ] || { echo "missing $IMG" >&2; exit 1; } +[ -c "$DEV" ] || { echo "missing $DEV (USB not plugged in?)" >&2; exit 1; } + +# --- safety: make sure da1 really is the CKB01 stick ----------------------- +geom=$(gpart show da1 2>/dev/null || true) +case "$geom" in +*fat32lba*) ;; +*) echo "da1 does not look like the CKB01 stick:" >&2; echo "$geom" >&2; exit 1 ;; +esac +size=$(diskinfo "$DISK" | awk '{print $3}') +if [ "$size" != "8053063680" ]; then + echo "da1 size is $size, expected 8053063680 (7.5G General UDisk)" >&2 + exit 1 +fi + +# --- replace the ITB ------------------------------------------------------- +mkdir -p "$MNT" +mount -t msdosfs "$DEV" "$MNT" +trap 'umount "$MNT" 2>/dev/null || true' EXIT + +echo "=== before ===" +ls -l "$MNT" + +cp "$IMG" "$MNT/uImage-initramfs.itb" +sync + +echo "=== after ===" +ls -l "$MNT" +echo "--- sha256 (USB) ---" +sha256 "$MNT/uImage-initramfs.itb" +echo "--- sha256 (source) ---" +sha256 "$IMG" + +umount "$MNT" +trap - EXIT +echo "done: USB updated" diff --git a/tools/verify_build.sh b/tools/verify_build.sh new file mode 100755 index 0000000..b2da53b --- /dev/null +++ b/tools/verify_build.sh @@ -0,0 +1,47 @@ +#!/bin/sh +# Verify the Wi-Fi-enabled build inside the bhyve guest (ckb01 / deb@10.1.0.4). +# Run: sh ~/ckb01/tools/verify_build.sh +set -u +cd "$HOME/openwrt" || exit 1 + +echo "=== 1. images ===" +ls -l bin/targets/qualcommax/ipq807x/*oppo_ckb01* 2>/dev/null + +echo +echo "=== 2. ITB size (limit 38 MB) ===" +ITB=$(ls bin/targets/qualcommax/ipq807x/*initramfs-uImage.itb 2>/dev/null | head -1) +if [ -n "$ITB" ]; then + SZ=$(stat -c%s "$ITB") + echo "$ITB $SZ bytes ($((SZ / 1024 / 1024)) MiB)" + if [ "$SZ" -lt 39845888 ]; then echo "OK: < 38 MiB"; else echo "NG: >= 38 MiB"; fi + sha256sum "$ITB" +else + echo "no ITB" +fi + +echo +echo "=== 3. manifest: ath11k / board-2 / ipq-wifi ===" +grep -E "ath11k|ipq-wifi|board-2" bin/targets/qualcommax/ipq807x/*.manifest | head -20 || echo "none" + +echo +echo "=== 4. rootfs: firmware files ===" +for p in build_dir/target-*/root-*/lib/firmware/ath11k/IPQ8074/hw2.0; do + [ -d "$p" ] || continue + echo "-- $p" + ls -l "$p" | head -10 +done + +echo +echo "=== 5. hotplug script contains oppo,ckb01 ===" +grep -n -A3 "oppo,ckb01" target/linux/qualcommax/ipq807x/base-files/etc/hotplug.d/firmware/11-ath11k-caldata + +echo +echo "=== 6. DTB: partitions + wifi node ===" +DTB=$(ls build_dir/target-*/linux-qualcommax_ipq807x/image/*ckb01*.dtb 2>/dev/null | head -1) +if [ -n "$DTB" ]; then + echo "-- $DTB" + dtc -I dtb -O dts "$DTB" 2>/dev/null | grep -n -E "0:ART|fixed-partitions|wifi@|wifi: wifi" | head -20 +else + echo "dtb not found; searching" + find build_dir -name '*ckb01*.dtb' 2>/dev/null | head +fi diff --git a/tools/verify_nss_build.sh b/tools/verify_nss_build.sh new file mode 100755 index 0000000..04a70db --- /dev/null +++ b/tools/verify_nss_build.sh @@ -0,0 +1,53 @@ +#!/bin/sh +# Verify the NSS + Wi-Fi build inside the bhyve guest (ckb01 / deb@10.1.0.4). +# Run: sh ~/ckb01/tools/verify_nss_build.sh +set -u +cd "$HOME/openwrt-nss" || exit 1 + +echo "=== 1. images ===" +ls -l bin/targets/qualcommax/ipq807x/*oppo_ckb01* 2>/dev/null + +echo +echo "=== 2. ITB size / sha256 ===" +ITB=$(ls bin/targets/qualcommax/ipq807x/*initramfs-uImage.itb 2>/dev/null | head -1) +if [ -n "$ITB" ]; then + SZ=$(stat -c%s "$ITB") + echo "$ITB $SZ bytes ($((SZ / 1024 / 1024)) MiB)" + sha256sum "$ITB" +fi + +echo +echo "=== 3. manifest: NSS + Wi-Fi ===" +grep -E "qca-nss|qca-ssdk|nss-firmware|ath11k|ckb01-wifi|wpad" bin/targets/qualcommax/ipq807x/*.manifest | head -30 + +echo +echo "=== 4. kernel config: NSS / ath11k offload ===" +KC=$(ls build_dir/target-*/linux-qualcommax_ipq807x/linux-6.6*/.config 2>/dev/null | head -1) +if [ -n "$KC" ]; then + grep -E "CONFIG_ATH11K_NSS|CONFIG_QCA_NSS|CONFIG_NSS" "$KC" | head -20 +fi + +echo +echo "=== 5. rootfs: NSS firmware ===" +R=build_dir/target-*/root-qualcommax +ls -l $R/lib/firmware/qca-nss* 2>/dev/null | head -10 +ls -l $R/lib/firmware/ | head -10 + +echo +echo "=== 6. rootfs: NSS modules + autoload ===" +ls -l $R/lib/modules/*/qca-nss*.ko $R/lib/modules/*/qca_ssdk.ko 2>/dev/null | head -10 +grep -l "qca-nss\|qca_nss" $R/etc/modules.d/* 2>/dev/null | head -10 +cat $R/etc/modules.d/*nss* 2>/dev/null | head -20 + +echo +echo "=== 7. rootfs: board-2.bin ===" +ls -l $R/lib/firmware/ath11k/IPQ8074/hw2.0/ 2>/dev/null + +echo +echo "=== 8. DTB: nss nodes / nss-dp / 0:ART ===" +D=$(ls build_dir/target-*/linux-qualcommax_ipq807x/image-ipq8072-ckb01.dtb 2>/dev/null | head -1) +if [ -n "$D" ]; then + dtc -I dtb -O dts "$D" 2>/dev/null | grep -E "nss@40|qcom,nss-dp|nss-common|0:ART|fixed-partitions|ipq8074-wifi" | head -20 +else + echo "dtb not found" +fi diff --git a/tools/watch_build.sh b/tools/watch_build.sh new file mode 100755 index 0000000..5c29ce9 --- /dev/null +++ b/tools/watch_build.sh @@ -0,0 +1,44 @@ +#!/bin/sh +# Wait for the OpenWrt build inside the bhyve guest (ckb01 / deb@10.1.0.4). +# Exits when the build finishes (RC= line) or when make disappears without one. +# Progress samples go to ~/ckb01/build-progress.log so a long build leaves a trail. +set -u +KEY=$HOME/.ssh/id_ckb01 +SSH="ssh -i $KEY -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o BatchMode=yes -o LogLevel=ERROR -o ConnectTimeout=20 deb@10.1.0.4" +LOG=$HOME/ckb01/build-progress.log +miss=0 + +say() { echo "$(date '+%Y-%m-%d %H:%M:%S') $*" | tee -a "$LOG"; } + +say "watcher start" +while :; do + out=$($SSH 'tail -1 ~/build.log 2>/dev/null; echo "@@"; grep -c "^RC=" ~/build.log 2>/dev/null; echo "@@"; pgrep -c -f "make -j6" 2>/dev/null || echo 0; echo "@@"; df -h / | tail -1' 2>/dev/null) || { + say "ssh failed (guest down?)"; sleep 120; continue + } + last=$(printf '%s\n' "$out" | sed -n '1p') + rc=$(printf '%s\n' "$out" | sed -n '3p') + nproc=$(printf '%s\n' "$out" | sed -n '5p') + df=$(printf '%s\n' "$out" | sed -n '7p') + + if [ "${rc:-0}" != "0" ]; then + say "build finished" + say "last: $last" + say "disk: $df" + $SSH 'grep "^RC=" ~/build.log; echo "--- tail 40 ---"; tail -40 ~/build.log; echo "--- images ---"; ls -l ~/openwrt/bin/targets/qualcommax/ipq807x/ 2>/dev/null | head -20' >> "$LOG" 2>&1 + exit 0 + fi + + if [ "${nproc:-0}" = "0" ]; then + miss=$((miss + 1)) + say "make not running (miss $miss): $last" + if [ "$miss" -ge 3 ]; then + say "make vanished without RC= -- build died" + $SSH 'tail -60 ~/build.log' >> "$LOG" 2>&1 + exit 2 + fi + else + miss=0 + say "running: $last" + fi + sleep 180 +done diff --git a/tools/watch_build2.sh b/tools/watch_build2.sh new file mode 100755 index 0000000..c3005d1 --- /dev/null +++ b/tools/watch_build2.sh @@ -0,0 +1,44 @@ +#!/bin/sh +# Watch an OpenWrt build inside the bhyve guest (ckb01 / deb@10.1.0.4). +# Usage: watch_build2.sh [logfile-in-guest] [progress-file] +set -u +KEY=$HOME/.ssh/id_ckb01 +SSH="ssh -i $KEY -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o BatchMode=yes -o LogLevel=ERROR -o ConnectTimeout=20 deb@10.1.0.4" +GLOG=${1:-/home/deb/build-nss.log} +LOG=${2:-$HOME/ckb01/build-progress-nss.log} +miss=0 + +say() { echo "$(date '+%Y-%m-%d %H:%M:%S') $*" | tee -a "$LOG"; } + +say "watcher start ($GLOG)" +while :; do + out=$($SSH "if [ -f $GLOG ]; then tail -1 $GLOG | sed 's/^/LAST: /'; grep -E '^(RC|BUILD_RC|DL_RC)=' $GLOG 2>/dev/null | sed 's/^/DONE: /'; else echo 'LAST: (no log yet)'; fi; pgrep -c -f 'make -j6' 2>/dev/null | sed 's/^/MAKE: /'; df -h / | tail -1 | sed 's/^/DISK: /'" 2>/dev/null) || { + say "ssh failed (guest down?)"; sleep 120; continue + } + last=$(printf '%s\n' "$out" | grep '^LAST: ' | sed 's/^LAST: //') + done_line=$(printf '%s\n' "$out" | grep '^DONE: ' | sed 's/^DONE: //') + nmake=$(printf '%s\n' "$out" | grep '^MAKE: ' | sed 's/^MAKE: //') + df=$(printf '%s\n' "$out" | grep '^DISK: ' | sed 's/^DISK: //') + + if [ -n "${done_line:-}" ]; then + say "build finished: $done_line" + say "last: $last" + say "disk: $df" + $SSH "grep -E '^(RC|BUILD_RC|DL_RC)=' $GLOG; echo '--- tail 40 ---'; tail -40 $GLOG; echo '--- images ---'; ls -l /home/deb/openwrt-nss/bin/targets/qualcommax/ipq807x/ 2>/dev/null | head -20" >> "$LOG" 2>&1 + exit 0 + fi + + if [ "${nmake:-0}" = "0" ]; then + miss=$((miss + 1)) + say "make not running (miss $miss): $last" + if [ "$miss" -ge 3 ]; then + say "make vanished without RC -- build died" + $SSH "tail -60 $GLOG" >> "$LOG" 2>&1 + exit 2 + fi + else + miss=0 + say "running: $last" + fi + sleep 180 +done |
