diff options
| author | dangofactory <root@dangofactory.net> | 2026-11-22 04:09:02 +0000 |
|---|---|---|
| committer | dangofactory <root@dangofactory.net> | 2026-11-22 04:09:02 +0000 |
| commit | 1f61487e5c4931e00f5702b6016222ffaa4276d4 (patch) | |
| tree | acf451f7b47758e8d4c722b655d1772113fc0dcc /tools/apply_wifi.py | |
| download | ckb01-master.tar.gz ckb01-master.zip | |
Diffstat (limited to 'tools/apply_wifi.py')
| -rw-r--r-- | tools/apply_wifi.py | 281 |
1 files changed, 281 insertions, 0 deletions
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() |
