{ description = '' TP-Link Archer AX23 / AX1800 Dual Band Wi-Fi 6 Router ***************************************************** Hardware summary ================ - MediaTek MT7621 (880MHz) - 16MB Flash - 128MB RAM - WLan hardware: Mediatek MT7905, MT7975 ''; system = { crossSystem = { config = "mips-unknown-linux-musl"; }; }; module = {pkgs, config, lib, lim, ... }: let firmware = pkgs.stdenv.mkDerivation { name = "wlan-firmware"; phases = ["installPhase"]; installPhase = '' mkdir $out cp ${pkgs.linux-firmware}/lib/firmware/mediatek/{mt7915,mt7615,mt7622}* $out ''; }; in { imports = [ ../../modules/arch/mips.nix ../../modules/outputs/tftpboot.nix ../../modules/outputs/ubifs.nix ]; config = { kernel = { src = pkgs.pkgsBuildBuild.fetchurl { name = "linux.tar.gz"; url = "https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.15.137.tar.gz"; hash = "sha256-PkdzUKZ0IpBiWe/RS70J76JKnBFzRblWcKlaIFNxnHQ="; }; extraPatchPhase = '' ${pkgs.openwrt.applyPatches.ramips} ''; config = { # Taken from the rt3200 and gl-mt300n RALINK="y"; PCI = "y"; SOC_MT7620="y"; # needed for "Cannot find regmap for /infracfg@10000000" MFD_SYSCON = "y"; PM_CLK="y"; REGMAP_MMIO = "y"; CLKSRC_MMIO = "y"; REGMAP = "y"; MEDIATEK_GE_PHY = "y"; # MEDIATEK_MT6577_AUXADC = "y"; # MEDIATEK_WATCHDOG = "y"; NET_MEDIATEK_SOC = "y"; NET_MEDIATEK_STAR_EMAC = "y"; # this enables REGMAP_MMIO NET_VENDOR_MEDIATEK = "y"; BLOCK = "y"; # move this to base option SPI_MASTER = "y"; SPI = "y"; SPI_MEM="y"; MTD = "y"; MTD_BLOCK = "y"; MTD_RAW_NAND = "y"; MTD_NAND_MTK_BMT = "y"; # Bad-block Management Table MTD_NAND_ECC_SW_HAMMING= "y"; MTD_SPI_NAND= "y"; MTD_OF_PARTS = "y"; MTD_NAND_CORE= "y"; MTD_SPI_NOR= "y"; MTD_SPLIT_FIRMWARE= "y"; MTD_SPLIT_FIT_FW= "y"; MMC = "y"; MMC_BLOCK = "y"; MMC_CQHCI = "y"; MMC_MTK = "y"; # Distributed Switch Architecture is needed # to make the ethernet ports visible NET_DSA="y"; NET_DSA_MT7530="y"; NET_DSA_TAG_MTK="y"; PSTORE = "y"; PSTORE_RAM = "y"; PSTORE_CONSOLE = "y"; PSTORE_DEFLATE_COMPRESS = "n"; GPIOLIB="y"; GPIO_MT7621 = "y"; PINCTRL="y"; ETHERNET="y"; SERIAL_8250 = "y"; SERIAL_8250_CONSOLE = "y"; # SERIAL_8250_NR_UARTS="3"; # SERIAL_8250_RUNTIME_UARTS="3"; SERIAL_CORE_CONSOLE = "y"; SERIAL_OF_PLATFORM="y"; } // lib.optionalAttrs (config.system.service ? watchdog) { RALINK_WDT = "y"; # watchdog MT7621_WDT = "y"; # or it might be this one }; }; boot = { commandLine = [ "console=ttyS0,115200" ]; tftp = { #ipaddr = "10.0.0.8"; # router address #serverip = "10.0.0.1"; # build machine or other tftp server # Should be a segment of free RAM, where the tftp artifact # can be stored before unpacking it to the 'hardware.loadAddress' # The 'hardware.loadAddress' is 0x80001000, which suggests the # RAM would start at 0x8000000 and (being 128MB) go to # to 0x8800000. Let's put it at the 100MB mark at # 0x8000000+0x0640000=0x86400000 loadAddress = lim.parseInt "0x86400000"; }; }; filesystem = let inherit (pkgs.pseudofile) dir symlink; in dir { lib = dir { firmware = dir { mediatek = symlink firmware; }; }; }; hardware = let openwrt = pkgs.openwrt; mac80211 = pkgs.mac80211.override { drivers = [ "mt7615e" "mt7915e" ]; klibBuild = config.system.outputs.kernel.modulesupport; }; in { #ubi = { # # TODO how to determine? # minIOSize = "2048"; # # TODO how to determine? # eraseBlockSize = "126976"; # # TODO how to determine? # maxLEBcount = "1024"; # guessing #}; # from OEM bootlog (openwrt wiki): # 4 cmdlinepart partitions found on MTD device raspi # Creating 4 MTD partitions on "raspi": # 0x000000000000-0x000000040000 : "uboot" # 0x000000040000-0x000000440000 : "uImage" # 0x000000440000-0x000000ff0000 : "rootfs" # 0x000000ff0000-0x000001000000 : "ART" # from openwrt bootlog (openwrt wiki): # 5 fixed-partitions partitions found on MTD device spi0.0 # OF: Bad cell count for /palmbus@1e000000/spi@b00/flash@0/partitions # OF: Bad cell count for /palmbus@1e000000/spi@b00/flash@0/partitions # OF: Bad cell count for /palmbus@1e000000/spi@b00/flash@0/partitions # OF: Bad cell count for /palmbus@1e000000/spi@b00/flash@0/partitions # Creating 5 MTD partitions on "spi0.0": # 0x000000000000-0x000000040000 : "u-boot" # 0x000000040000-0x000000fa0000 : "firmware" # 2 uimage-fw partitions found on MTD device firmware # Creating 2 MTD partitions on "firmware": # 0x000000000000-0x0000002c0000 : "kernel" # 0x0000002c0000-0x000000f60000 : "rootfs" # mtd: setting mtd3 (rootfs) as root device # 1 squashfs-split partitions found on MTD device rootfs # 0x000000640000-0x000000f60000 : "rootfs_data" # 0x000000fa0000-0x000000fb0000 : "config" # 0x000000fb0000-0x000000ff0000 : "tplink" # 0x000000ff0000-0x000001000000 : "radio" flash = { # from the OEM bootlog 'Booting image at bc040000' # (0x40000 from 0xbc000000) address = lim.parseInt "0xbc040000"; # 0x000000040000-0x000000fa0000 size = lim.parseInt "0xf60000"; # TODO how to determine? eraseBlockSize = 65536; }; # since this is mentioned in the partition table as well? defaultOutput = "uimage"; # taken from openwrt sysupgrade image: # openwrt-23.05.2-ramips-mt7621-tplink_archer-ax23-v1-squashfs-sysupgrade.bin: u-boot legacy uImage, MIPS OpenWrt Linux-5.15.137, Linux/MIPS, OS Kernel Image (lzma), 2797386 bytes, Tue Nov 14 13:38:11 2023, Load Address: 0X80001000, Entry Point: 0X80001000, Header CRC: 0X19F74C5B, Data CRC: 0XF685563C loadAddress = lim.parseInt "0x80001000"; entryPoint = lim.parseInt "0x80001000"; rootDevice = "ubi0:liminix"; dts = { src = "${openwrt.src}/target/linux/ramips/dts/mt7621_tplink_archer-ax23-v1.dts"; includes = [ "${openwrt.src}/target/linux/ramips/dts" "${config.system.outputs.kernel.modulesupport}/arch/arm64/boot/dts/mediatek/" ]; }; networkInterfaces = let inherit (config.system.service.network) link; inherit (config.system.service) bridge; in rec { lan1 = link.build { ifname = "lan1"; }; lan2 = link.build { ifname = "lan2"; }; lan3 = link.build { ifname = "lan3"; }; lan4 = link.build { ifname = "lan4"; }; wan = link.build { ifname = "wan"; dependencies = [ mac80211 ]; }; }; }; }; }; }