From 4cf7472df860a9b4ffefadffb4c74dabdd393c46 Mon Sep 17 00:00:00 2001 From: Arnout Engelen Date: Tue, 30 Jan 2024 11:33:39 +0100 Subject: [PATCH 1/3] WIP: example of using the Archer AX23 as extender Needs cleaning up. Perhaps (some of) the hostap configuration should be moved to the 'device' somehow? --- examples/ax23-extneder.nix | 150 +++++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 examples/ax23-extneder.nix diff --git a/examples/ax23-extneder.nix b/examples/ax23-extneder.nix new file mode 100644 index 0000000..388e957 --- /dev/null +++ b/examples/ax23-extneder.nix @@ -0,0 +1,150 @@ +{ config, pkgs, lib, ... } : +let + secrets = import ./ax23-secrets.nix; + inherit (pkgs) serviceFns; + svc = config.system.service; + wirelessConfig = { + country_code = "NL"; + ssid = "FRITZ!Box 7581 TN"; + wpa_passphrase = secrets.wpa_passphrase; + auth_algs = 1; # 1=wpa2, 2=wep, 3=both + wpa = 2; # 1=wpa, 2=wpa2, 3=both + wpa_key_mgmt = "WPA-PSK"; + wpa_pairwise = "TKIP CCMP"; # auth for wpa (may not need this?) + rsn_pairwise = "CCMP"; # auth for wpa2 + wmm_enabled = 1; + bridge = "int"; + }; + +in rec { + imports = [ + ../modules/wlan.nix + ../modules/network + ../modules/dhcp6c + ../modules/ssh + ../modules/bridge + ../modules/hostapd + ]; + + hostname = "yardbird"; + + services.hostap = svc.hostapd.build { + interface = config.hardware.networkInterfaces.wlan; + params = { + # b/g/n/ax + hw_mode = "g"; + channel = "2"; + ieee80211n = 1; + driver="nl80211"; + supported_rates="60 90 120 180 240 360 480 540"; + basic_rates="60 120 240"; + beacon_int="100"; + ht_coex="0"; + ht_capab="[LDPC][SHORT-GI-20][SHORT-GI-40][TX-STBC][RX-STBC1][MAX-AMSDU-7935]"; + ap_isolate="1"; + bss_load_update_period="60"; + chan_util_avg_period="600"; + disassoc_low_ack="1"; + skip_inactivity_poll="0"; + preamble="1"; + wmm_enabled="1"; + ignore_broadcast_ssid="0"; + uapsd_advertisement_enabled="1"; + utf8_ssid="1"; + multi_ap="0"; + auth_algs="1"; + wpa="0"; + wds_bridge=""; + bssid="5c:e9:31:63:90:48"; + } // wirelessConfig; + }; + + services.hostap5 = svc.hostapd.build { + interface = config.hardware.networkInterfaces.wlan5; + params = rec { + # a/n/ac/ax + hw_mode = "a"; + channel = 36; + #ht_capab = "[HT40+]"; + vht_oper_chwidth = 1; + vht_oper_centr_freq_seg0_idx = channel + 6; + ieee80211ac = 1; + driver="nl80211"; + country_code="NL"; + ieee80211d="1"; + ieee80211h="1"; + beacon_int="100"; + chanlist="36"; + + tx_queue_data2_burst="2.0"; + + #num_global_macaddr=1; + ieee80211n="1"; + ht_coex="0"; + ht_capab="[HT40+][LDPC][SHORT-GI-20][SHORT-GI-40][TX-STBC][RX-STBC1][MAX-AMSDU-7935]"; + #ieee80211ac="1"; + #vht_oper_chwidth="1"; + #vht_oper_centr_freq_seg0_idx="42"; + vht_capab="[RXLDPC][SHORT-GI-80][TX-STBC-2BY1][SU-BEAMFORMER][SU-BEAMFORMEE][MU-BEAMFORMER][MU-BEAMFORMEE][RX-ANTENNA-PATTERN][TX-ANTENNA-PATTERN][RX-STBC-1][SOUNDING-DIMENSION-2][BF-ANTENNA-2][MAX-MPDU-7991][MAX-A-MPDU-LEN-EXP7]"; + + ap_isolate="1"; + bss_load_update_period="60"; + chan_util_avg_period="600"; + disassoc_low_ack="1"; + skip_inactivity_poll="0"; + preamble="1"; + wmm_enabled="1"; + ignore_broadcast_ssid="0"; + uapsd_advertisement_enabled="1"; + utf8_ssid="1"; + multi_ap="0"; + eapol_version="1"; + auth_algs="1"; + wpa="1"; + wpa_pairwise="CCMP TKIP"; + wds_bridge=""; + wpa_disable_eapol_key_retries="0"; + wpa_key_mgmt="WPA-PSK"; + bssid="5c:e9:31:63:90:47"; + #default_macaddr + } // wirelessConfig; + }; + + services.int = svc.network.address.build { + interface = svc.bridge.primary.build { ifname = "int"; }; + family = "inet"; address = "10.8.0.1"; prefixLength = 16; + }; + + services.bridge = svc.bridge.members.build { + primary = services.int; + members = with config.hardware.networkInterfaces; + [ wlan + wlan5 + lan1 + lan2 + lan3 + lan4 + wan + ]; + }; + + services.dhcpc = svc.network.dhcp.client.build { + interface = services.int; + + # don't start DHCP until the hostname is configured, + # so it can identify itself to the DHCP server + dependencies = [ config.services.hostname ]; + }; + services.dhcp6c = svc.dhcp6c.client.build { + interface = services.int; + }; + + services.sshd = svc.ssh.build { }; + + users.root = secrets.root; + + defaultProfile.packages = with pkgs; [ + figlet + #tcpdump + ]; +} -- 2.42.0 From 1a85d0907741545ed5d4865d6a6814d4cdb3b203 Mon Sep 17 00:00:00 2001 From: Arnout Engelen Date: Tue, 30 Jan 2024 11:25:08 +0100 Subject: [PATCH 2/3] WIP: support for TFTP on 'old' uboot versions Older uboot versions don't have an option to override the DTB from the `mboot` command, so the updated DTB needs to be replaced in the image itself. --- devices/tp-archer-ax23/default.nix | 2 ++ examples/ax23-extneder.nix | 5 +++++ modules/outputs/tftpboot.nix | 33 ++++++++++++++++++++++++++++-- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/devices/tp-archer-ax23/default.nix b/devices/tp-archer-ax23/default.nix index 2357e69..d240812 100644 --- a/devices/tp-archer-ax23/default.nix +++ b/devices/tp-archer-ax23/default.nix @@ -337,6 +337,8 @@ # to 0x8800000. Let's put it at the 100MB mark at # 0x8000000+0x0640000=0x86400000 loadAddress = lim.parseInt "0x86400000"; + compressRoot = true; + replaceDtb = true; }; }; filesystem = diff --git a/examples/ax23-extneder.nix b/examples/ax23-extneder.nix index 388e957..1e0928f 100644 --- a/examples/ax23-extneder.nix +++ b/examples/ax23-extneder.nix @@ -28,6 +28,11 @@ in rec { hostname = "yardbird"; + boot.tftp = { + serverip = "192.168.0.1"; + ipaddr = "192.168.0.2"; + }; + services.hostap = svc.hostapd.build { interface = config.hardware.networkInterfaces.wlan; params = { diff --git a/modules/outputs/tftpboot.nix b/modules/outputs/tftpboot.nix index 36d96ff..bf5a77e 100644 --- a/modules/outputs/tftpboot.nix +++ b/modules/outputs/tftpboot.nix @@ -22,6 +22,16 @@ in { type = types.bool; default = false; }; + replaceDtb = mkOption { + description = '' + Replace DTB instead of overriding it. + + Useful for older versions of uboot that don't support + overriding the DTB from the bootm/bootz command line. + ''; + type = types.bool; + default = false; + }; }; options.system.outputs = { tftpboot = mkOption { @@ -63,8 +73,13 @@ in { zimage = "bootz"; }; in choices.${cfg.kernelFormat}; cmdline = concatStringsSep " " config.boot.commandLine; + objcopy = "${pkgs.stdenv.cc.bintools.targetPrefix}objcopy"; + stripAndZip = '' + ${objcopy} -O binary -R .reginfo -R .notes -R .note -R .comment -R .mdebug -R .note.gnu.build-id -S vmlinux.elf vmlinux.bin + rm -f vmlinux.bin.lzma ; lzma -k -z vmlinux.bin + ''; in - pkgs.runCommand "tftpboot" { nativeBuildInputs = with pkgs.pkgsBuildBuild; [ lzma dtc ]; } '' + pkgs.runCommand "tftpboot" { nativeBuildInputs = with pkgs.pkgsBuildBuild; [ lzma dtc pkgs.stdenv.cc ubootTools ]; } '' mkdir $out cd $out binsize() { local s=$(stat -L -c %s $1); echo $(($s + 0x1000 &(~0xfff))); } @@ -77,12 +92,19 @@ in { imageSize=$(binsize ${image}) ln -s ${o.manifest} manifest - ln -s ${image} image ln -s ${o.kernel} vmlinux # handy for gdb + ${if cfg.compressRoot && cfg.replaceDtb + then '' + echo "Having both compressRoot and replaceDtb enabled is not currently supported" + exit 1 + '' else "" + } + ${if cfg.compressRoot then '' lzma -z9cv ${o.rootfs} > rootfs.lz + # TODO this is no longer correct rootfsLzStart=$(($imageStart + $imageSize)) rootfsLzSize=$(binsize rootfs.lz) '' @@ -107,6 +129,13 @@ in { cmd="liminix ${cmdline} mtdparts=phram0:''${rootfsSize}(rootfs) phram.phram=phram0,''${rootfsStart},''${rootfsSize},${toString config.hardware.flash.eraseBlockSize} root=/dev/mtdblock0"; fdtput -t s dtb /chosen bootargs "$cmd" + # re-package image with updated dtb + cp ${o.kernel} vmlinux.elf; chmod +w vmlinux.elf + ${objcopy} --update-section .appended_dtb=dtb vmlinux.elf + ${stripAndZip} + # TODO don't hardcode mips, entryPoint, loadAddress, name + mkimage -A mips -O linux -T kernel -C lzma -a 0x80001000 -e 0x80001000 -n 'MIPS Liminix Linux' -d vmlinux.bin.lzma image + # dtc -I dtb -O dts -o /dev/stdout dtb | grep -A10 chosen ; exit 1 cat > boot.scr << EOF -- 2.42.0 From d20b79e06a8c6b1f6c93c3adcc12abbb997c5baa Mon Sep 17 00:00:00 2001 From: Arnout Engelen Date: Wed, 21 Feb 2024 15:32:42 +0100 Subject: [PATCH 3/3] jffs, kexecboot --- devices/tp-archer-ax23/default.nix | 1 + examples/ax23-extneder.nix | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/devices/tp-archer-ax23/default.nix b/devices/tp-archer-ax23/default.nix index d240812..600a6af 100644 --- a/devices/tp-archer-ax23/default.nix +++ b/devices/tp-archer-ax23/default.nix @@ -47,6 +47,7 @@ ../../modules/arch/mipsel.nix ../../modules/outputs/tftpboot.nix ../../modules/outputs/tplink-safeloader.nix + ../../modules/outputs/jffs2.nix ]; config = { kernel = { diff --git a/examples/ax23-extneder.nix b/examples/ax23-extneder.nix index 1e0928f..2082c1c 100644 --- a/examples/ax23-extneder.nix +++ b/examples/ax23-extneder.nix @@ -24,6 +24,7 @@ in rec { ../modules/ssh ../modules/bridge ../modules/hostapd + ../modules/outputs/kexecboot.nix ]; hostname = "yardbird"; @@ -149,7 +150,10 @@ in rec { users.root = secrets.root; defaultProfile.packages = with pkgs; [ - figlet - #tcpdump + tcpdump + # for arp + nettools + # for kexec booting + gnutar ]; } -- 2.42.0