联系管理员

开通文章发布权限

扫码 添加微信
微信图片
电话: QQ:1602036736

RK3566 解决 Debian 补丁 多网络不能自动切换网关导致域名解析失败

rk3566_rk3568_linux6.1_release/device/rockchip

diff --git a/common/scripts/kernel-helper b/common/scripts/kernel-helper
index 1bbdd04..7422f72 100644
--- a/common/scripts/kernel-helper
+++ b/common/scripts/kernel-helper
@@ -22,9 +22,28 @@ if [ "$RK_CHIP_RISCV64" ]; then
        # Kernel uses "riscv" arch for RISCV64.
        export RK_KERNEL_TOOLCHAIN="$(get_toolchain kernel riscv64)"
 else
-       export RK_KERNEL_TOOLCHAIN="$(get_toolchain kernel "$RK_KERNEL_ARCH")"
+       # Try system toolchain first
+       if [ "$RK_KERNEL_ARCH" = arm64 ]; then
+               if which aarch64-linux-gnu-gcc >/dev/null 2>&1; then
+                       notice "Using system toolchain for kernel: aarch64-linux-gnu-"
+                       export RK_KERNEL_TOOLCHAIN="aarch64-linux-gnu-"
+               else
+                       export RK_KERNEL_TOOLCHAIN="$(get_toolchain kernel "$RK_KERNEL_ARCH")"
+                       [ "$RK_KERNEL_TOOLCHAIN" ] || exit 1
+               fi
+       elif [ "$RK_KERNEL_ARCH" = arm ]; then
+               if which arm-linux-gnueabihf-gcc >/dev/null 2>&1; then
+                       notice "Using system toolchain for kernel: arm-linux-gnueabihf-"
+                       export RK_KERNEL_TOOLCHAIN="arm-linux-gnueabihf-"
+               else
+                       export RK_KERNEL_TOOLCHAIN="$(get_toolchain kernel "$RK_KERNEL_ARCH")"
+                       [ "$RK_KERNEL_TOOLCHAIN" ] || exit 1
+               fi
+       else
+               export RK_KERNEL_TOOLCHAIN="$(get_toolchain kernel "$RK_KERNEL_ARCH")"
+               [ "$RK_KERNEL_TOOLCHAIN" ] || exit 1
+       fi
 fi
-[ "$RK_KERNEL_TOOLCHAIN" ] || exit 1
 
 export KMAKE="make -C "$RK_SDK_DIR/kernel/" -j$(( $(nproc) + 1 )) \
        CROSS_COMPILE=$RK_KERNEL_TOOLCHAIN ARCH=$RK_KERNEL_ARCH"
diff --git a/common/scripts/mk-loader.sh b/common/scripts/mk-loader.sh
index 550f0a9..1bacf37 100755
--- a/common/scripts/mk-loader.sh
+++ b/common/scripts/mk-loader.sh
@@ -99,8 +99,27 @@ build_hook()
                export RK_UBOOT_ARCH=arm
        fi
 
-       RK_UBOOT_TOOLCHAIN="$(get_toolchain U-Boot "$RK_UBOOT_ARCH")"
-       [ "$RK_UBOOT_TOOLCHAIN" ] || exit 1
+       # Try system toolchain first
+       if [ "$RK_UBOOT_ARCH" = arm64 ]; then
+               if which aarch64-linux-gnu-gcc >/dev/null 2>&1; then
+                       notice "Using system toolchain for U-Boot: aarch64-linux-gnu-"
+                       RK_UBOOT_TOOLCHAIN="aarch64-linux-gnu-"
+               else
+                       RK_UBOOT_TOOLCHAIN="$(get_toolchain U-Boot "$RK_UBOOT_ARCH")"
+                       [ "$RK_UBOOT_TOOLCHAIN" ] || exit 1
+               fi
+       elif [ "$RK_UBOOT_ARCH" = arm ]; then
+               if which arm-linux-gnueabihf-gcc >/dev/null 2>&1; then
+                       notice "Using system toolchain for U-Boot: arm-linux-gnueabihf-"
+                       RK_UBOOT_TOOLCHAIN="arm-linux-gnueabihf-"
+               else
+                       RK_UBOOT_TOOLCHAIN="$(get_toolchain U-Boot "$RK_UBOOT_ARCH")"
+                       [ "$RK_UBOOT_TOOLCHAIN" ] || exit 1
+               fi
+       else
+               RK_UBOOT_TOOLCHAIN="$(get_toolchain U-Boot "$RK_UBOOT_ARCH")"
+               [ "$RK_UBOOT_TOOLCHAIN" ] || exit 1
+       fi
 
        message "Toolchain for loader (U-Boot):"
        message "${RK_UBOOT_TOOLCHAIN:-gcc}"

rk3566_rk3568_linux6.1_release/external/rkwifibt

diff --git a/drivers/bcmdhd/Makefile b/drivers/bcmdhd/Makefile
index c673785..40ebad0 100644
--- a/drivers/bcmdhd/Makefile
+++ b/drivers/bcmdhd/Makefile
@@ -56,7 +56,7 @@ CONFIG_MACH_PLATFORM := y
 #CONFIG_BCMDHD_DTS := y
 
 DHDCFLAGS = -Wall -Wstrict-prototypes -Wno-date-time -Wno-strict-prototypes   \
-       -Wno-uninitialized -Wno-unused-but-set-variable -Wno-address          \
+       -Wno-uninitialized -Wno-unused-but-set-variable -Wno-address -Wno-error      \
        -Dlinux -DLINUX -DBCMDRIVER -DBCMUTILS_ERR_CODES                      \
        -DBCMDONGLEHOST -DBCMDMA32 -DBCMFILEIMAGE                             \
        -DDHDTHREAD -DDHD_DEBUG -DSHOW_EVENTS -DGET_OTP_MAC_ENABLE            \

debian

diff --git a/debian/overlay/etc/network/interfaces.d/network-priority b/debian/overlay/etc/network/interfaces.d/network-priority
new file mode 100644
index 0000000..1234567
--- /dev/null
+++ b/debian/overlay/etc/network/interfaces.d/network-priority
@@ -0,0 +1,19 @@
+# Network interfaces configuration with priority settings
+
+# EC20-4G interface (highest priority, but only if active)
+allow-hotplug ec20
+iface ec20 inet dhcp
+    metric 100
+    timeout 5
+
+# WIFI interface (medium priority)
+allow-hotplug wlan0
+iface wlan0 inet dhcp
+    metric 600
+    timeout 5
+
+# Ethernet interface (lowest priority)
+allow-hotplug end1
+iface end1 inet dhcp
+    metric 1000
+    timeout 5

diff --git a/debian/overlay/etc/network/check-connection.sh b/debian/overlay/etc/network/check-connection.sh
new file mode 100644
index 0000000..1234567
--- /dev/null
+++ b/debian/overlay/etc/network/check-connection.sh
@@ -0,0 +1,56 @@
+#!/bin/bash
+
+# Check network connection status and remove default routes for inactive interfaces
+
+# Function to check if an interface is active
+is_interface_active() {
+    local interface=$1
+    # Check if interface exists and has an IP address
+    if ip addr show $interface | grep -q "inet "; then
+        # Try to ping a reliable server
+        if ping -c 1 -W 2 8.8.8.8 > /dev/null 2>&1; then
+            return 0
+        fi
+    fi
+    return 1
+}
+
+# Get all interfaces with default routes
+interfaces=$(ip route show default | awk '{print $5}' | sort -u)
+
+for interface in $interfaces; do
+    if ! is_interface_active $interface; then
+        # Remove default route for inactive interface
+        ip route del default dev $interface 2>/dev/null
+        echo "Removed default route for inactive interface: $interface"
+    fi
+done
+
+# Ensure only the highest priority active interface has default route
+active_interfaces=()
+for interface in $interfaces; do
+    if is_interface_active $interface; then
+        active_interfaces+=($interface)
+    fi
+done
+
+if [ ${#active_interfaces[@]} -gt 1 ]; then
+    # Get metrics for active interfaces
+    declare -A metrics
+    for interface in "${active_interfaces[@]}"; do
+        metric=$(ip route show default dev $interface | awk '{print $7}' | grep -o '[0-9]*')
+        metrics[$interface]=$metric
+    done
+    
+    # Sort interfaces by metric (ascending)
+    sorted=($(for iface in "${!metrics[@]}"; do echo "$iface ${metrics[$iface]}"; done | sort -k2 -n | awk '{print $1}'))
+    
+    # Keep only the first (highest priority) interface
+    primary_interface=${sorted[0]}
+    
+    # Remove default routes for other active interfaces
+    for interface in "${sorted[@]:1}"; do
+        ip route del default dev $interface 2>/dev/null
+        echo "Removed default route for lower priority interface: $interface"
+    done
+fi

diff --git a/debian/overlay/etc/systemd/system/network-check.service b/debian/overlay/etc/systemd/system/network-check.service
new file mode 100644
index 0000000..1234567
--- /dev/null
+++ b/debian/overlay/etc/systemd/system/network-check.service
@@ -0,0 +1,10 @@
+[Unit]
+Description=Network connection check service
+After=network.target
+
+[Service]
+Type=oneshot
+ExecStart=/bin/bash /etc/network/check-connection.sh
+
+[Install]
+WantedBy=multi-user.target

diff --git a/debian/overlay/etc/systemd/system/network-check.timer b/debian/overlay/etc/systemd/system/network-check.timer
new file mode 100644
index 0000000..1234567
--- /dev/null
+++ b/debian/overlay/etc/systemd/system/network-check.timer
@@ -0,0 +1,9 @@
+[Unit]
+Description=Network connection check timer
+
+[Timer]
+OnBootSec=5min
+OnUnitActiveSec=5min
+
+[Install]
+WantedBy=timers.target

diff --git a/debian/overlay/etc/rc.local b/debian/overlay/etc/rc.local
new file mode 100644
index 0000000..1234567
--- /dev/null
+++ b/debian/overlay/etc/rc.local
@@ -0,0 +1,9 @@
+#!/bin/bash
+
+# Enable and start network check services
+systemctl enable network-check.service
+systemctl enable network-check.timer
+systemctl start network-check.service
+systemctl start network-check.timer
+
+exit 0

diff --git a/debian/overlay/etc/udev/rules.d/99-ec20.rules b/debian/overlay/etc/udev/rules.d/99-ec20.rules
new file mode 100644
index 0000000..1234567
--- /dev/null
+++ b/debian/overlay/etc/udev/rules.d/99-ec20.rules
@@ -0,0 +1,2 @@
+# EC20-4G modem rule
+SUBSYSTEM=="net", ACTION=="add", ATTRS{idVendor}=="2c7c", ATTRS{idProduct}=="0125", NAME="ec20"
diff --git a/debian/overlay/etc/network/interfaces b/debian/overlay/etc/network/interfaces
new file mode 100644
index 0000000..1234567
--- /dev/null
+++ b/debian/overlay/etc/network/interfaces
@@ -0,0 +1,9 @@
+# /etc/network/interfaces - main network configuration file
+
+auto lo
+iface lo inet loopback
+
+# Load interface configurations from interfaces.d directory
+source /etc/network/interfaces.d/*
+

最后给 heck-connection.sh 给予权限:

chmod +x ./debian/overlay/etc/network/check-connection.sh

 

  1. overlay/etc/network/interfaces.d/network-priority :

    • 添加了网络接口优先级配置

    • 为EC20-4G、WiFi和以太网接口设置了不同的优先级和超时时间

  2. overlay/etc/network/check-connection.sh :

    • 添加了网络连接检查脚本

    • 检测接口连接状态并移除无效接口的默认路由

    • 确保只有最高优先级的活动接口保留默认路由

  3. overlay/etc/systemd/system/network-check.service :

    • 添加了网络连接检查系统服务

    • 在系统启动后执行网络连接检查

  4. overlay/etc/systemd/system/network-check.timer :

    • 添加了网络连接检查定时器

    • 每5分钟定期检查网络连接状态

  5. overlay/etc/rc.local :

    • 添加了rc.local脚本

    • 在系统启动时启用并启动网络检查服务

  6. overlay/etc/udev/rules.d/99-ec20.rules :

    • 添加了udev规则

    • 为EC20-4G模块分配固定的接口名称 ec20

 

评论

快捷导航

把好文章收藏到微信

打开微信,扫码查看

关闭

还没有账号?立即注册