当前位置: 首页 > news >正文

Android13 以太网(YT8531)

一、基本调试

按照正常驱动调试基本流程移植驱动后(移植过程可查看前面linux调试以太网部分),启动网卡出现以下错误

Error: Could not connect to phy ethernet-phy

GMAC无法扫描到PHY设备,一般怀疑为硬件问题。

解决办法

  • 供电:PHY一般无需单独的供电,GMAC的PIN BANK在某些平台上需要单独供电,检查PIN的供电是否正常

  • 时钟:主要检查PHY的25M时钟,如果是外部晶振,用示波器量晶振频率是否在25Mhz左右,每款PHY对晶振的精确度要求不一致(PHY的datasheet上会有相关说明);如果是内部SOC25M时钟供电,查看SOC25M对应的是哪个PIN,用示波器量下PIN输出的时钟频率是否在25M左右

  • PHY-RST:确保对PHY在进行MDIO读写操作时需要10ms左右rst拉低以及150ms左右rst拉高操作(每款PHY的要求不一致,此处为典型值)

具体原因:使用外部晶振,25M时钟未焊接导致

修改phy地址

重新测试后正常:

正确识别ID:

联网测试:(需判断速率是否达标)

  1. 判断以太网网线插拔状态,1 为插上,0 为拔掉。

cat /sys/class/net/eth0/carrier

二、双网卡使用(双YT8531)

Android_双网口时无法关闭以太网功能

1、从 logcat 中看,点击 Settings 以太网开关,都只是对 eth0 进行了操作。

EthernetServiceImpl: enableInterface called with: iface=eth0 
EthernetServiceImpl: disableInterface called with: iface=eth0

eth1 无法被关闭,当然也就会导致以太网功能始终是可以被使用的状态。

控制网口的开关,是 Settings 负责的,如果 Settings 不去关闭 eth1,那么 eth1 肯定就无法被关闭。

解决办法:在Settings 部分增加了对多网口处理判断的逻辑

路径:packages/apps/Settings/src/com/android/settings/ethernet

(1)EthernetSettings.java

diff --git a/src/com/android/settings/ethernet/EthernetSettings.java b/src/com/android/settings/ethernet/EthernetSettings.java
index 90c757146bd..15e7b9800a4 100644
--- a/src/com/android/settings/ethernet/EthernetSettings.java
+++ b/src/com/android/settings/ethernet/EthernetSettings.java
@@ -43,7 +43,6 @@ public class EthernetSettings extends DashboardFragment implementsprivate static final String KEY_TOGGLE_ETHERNET = "main_toggle_ethernet";public static final String SHARED_PREFERENCES_NAME = "ethernet_prefs";public static final String ETHERNET_SETTINGS_CONFIG = "ethernet_settings_config";
-    public static final String ETHERNET_IFACE = "eth0";private static EthernetSwitchPreferenceController mEthernetUIController = null;

(2)EthernetSettingsManager.java

通过动态获取以太网接口列表,取代了原先 eth0 接口名称的方式

diff --git a/src/com/android/settings/ethernet/EthernetSettingsManager.java b/src/com/android/settings/ethernet/EthernetSettingsManager.java
index 55fb790a94c..fa8a65d3827 100644
--- a/src/com/android/settings/ethernet/EthernetSettingsManager.java
+++ b/src/com/android/settings/ethernet/EthernetSettingsManager.java
@@ -16,8 +16,6 @@package com.android.settings.ethernet;-import static com.android.settings.ethernet.EthernetSettings.ETHERNET_IFACE;
-import android.content.Context;import android.net.ConnectivityManager;import android.net.EthernetManager;
@@ -39,6 +37,7 @@ import java.net.Inet4Address;import java.net.InetAddress;import java.net.UnknownHostException;import java.util.ArrayList;
+import java.util.List;public class EthernetSettingsManager {private final static String TAG = "EthernetSettingsManager";
@@ -103,7 +102,15 @@ public class EthernetSettingsManager {final EthernetNetworkUpdateRequest request = new EthernetNetworkUpdateRequest.Builder().setIpConfiguration(mIpConfiguration).build();
-        mEthManager.updateConfiguration(ETHERNET_IFACE, request, r -> r.run(), null);
+
+        List<String> interfaces = mEthManager.getInterfaceList();
+        if (!interfaces.isEmpty()) {
+            // When there are two interfaces, only the interface configuration of the first access device will be modified
+            Log.d(TAG, "update Ethernet Configuration : " + interfaces.get(0));
+            mEthManager.updateConfiguration(interfaces.get(0), request, r -> r.run(), null);
+        } else {
+            Log.w(TAG, "Ethernet Interfaces is null");
+        }}public Network getFirstNetwork() {

(3)EthernetSwitchPreferenceController.java

  1. 通过 NetworkInfo.State 更灵活地处理网络状态,替代了 ETHERNET_IFACE 的硬编码。

  2. 新增了 getDefaultNetwork()方法,通过 NetworkInfo 检查当前活跃的以太网网络。

  3. tryEthNode()替换为 haveEthernetInterface() 方法,直接使用以太网管理器来查询接口。

  4. 可以处理所有以太网接口的状态,而不仅仅是一个。

diff --git a/src/com/android/settings/ethernet/EthernetSwitchPreferenceController.java b/src/com/android/settings/ethernet/EthernetSwitchPreferenceController.java
index d39d0e70b45..dac9efb1235 100644
--- a/src/com/android/settings/ethernet/EthernetSwitchPreferenceController.java
+++ b/src/com/android/settings/ethernet/EthernetSwitchPreferenceController.java
@@ -17,7 +17,7 @@package com.android.settings.ethernet;import static android.net.NetworkCapabilities.TRANSPORT_ETHERNET;
-import static com.android.settings.ethernet.EthernetSettings.ETHERNET_IFACE;
+import static android.net.NetworkInfo.State;import android.app.Activity;import android.content.Context;
@@ -28,6 +28,7 @@ import android.net.EthernetNetworkUpdateRequest;import android.net.IpConfiguration;import android.net.Network;import android.net.NetworkCapabilities;
+import android.net.NetworkInfo;import android.net.NetworkRequest;import android.net.wifi.WifiManager;import android.util.Log;
@@ -46,6 +47,7 @@ import com.android.settings.R;import com.android.settingslib.core.AbstractPreferenceController;import java.io.IOException;
+import java.util.List;/*** This controller helps to manage the state of wifi switch preference.*/
@@ -100,13 +102,32 @@ public class EthernetSwitchPreferenceController extends AbstractPreferenceContro@Overridepublic void onLost(@NonNull Network network) {
-                updatePreferenceStatus(false);
-                Log.w(TAG, "onLost setChecked");
+                if (getDefaultNetwork() == null) {
+                    Log.d(TAG, "There is no Ethernet interface, setChecked false");
+                    updatePreferenceStatus(false);
+                }}};Log.w(TAG, "initNetworkCallback");}+    private Network getDefaultNetwork() {
+        final Network[] networks = mConnectivityManager.getAllNetworks();
+        for (final Network network : networks) {
+            NetworkInfo networkInfo = mConnectivityManager.getNetworkInfo(network);
+            Log.w(TAG, "getDefaultNetwork, networkInfo:" + networkInfo);
+            if (networkInfo != null
+                    && (networkInfo.getType() == ConnectivityManager.TYPE_ETHERNET)) {
+                Log.w(TAG, "getDefaultNetwork, type is ethernet:" + network);
+                if (networkInfo.getState() == State.DISCONNECTED) {
+                    continue;
+                }
+                return network;
+            }
+        }
+        return null;
+    }
+private void updatePreferenceStatus(boolean isChecked) {if (mPrefs != null) {mPrefs.edit().putBoolean(KEY, isChecked).apply();
@@ -144,8 +165,7 @@ public class EthernetSwitchPreferenceController extends AbstractPreferenceControLog.w(TAG, "mPreference is null: " + (mPreference == null));boolean checked = mPrefs.getBoolean(KEY, false);Log.w(TAG, "mPreference is checked: " + checked);
-        updatePreferenceStatus(tryEthNode() && checked && mIsCheckEthernet);
-//        showEthernetSettings(checked);
+        updatePreferenceStatus(haveEthernetInterface() && checked && mIsCheckEthernet);}private void showEthernetSettings(boolean show) {
@@ -162,24 +182,21 @@ public class EthernetSwitchPreferenceController extends AbstractPreferenceControreturn true;}-    // TODO: We need to change to no longer use nodes here
-    private boolean tryEthNode() {
-        try {
-            Process p = Runtime.getRuntime().exec("ls sys/class/net/eth0");
-            int tmp = p.waitFor();
-            Log.w(TAG, "tryEthNode tmp: " + tmp);
-            return tmp == 0;
-        } catch (IOException | InterruptedException e) {
-            Log.w(TAG, "access /proc/net/dev failed!");
+    private boolean haveEthernetInterface() {
+        List<String> interfaces = mEthManager.getInterfaceList();
+        if (interfaces.isEmpty()) {
+            return false;
+        } else {
+            Log.v(TAG, "Ethernet Interfaces = " + interfaces);
+            return true;}
-        return false;}@Overridepublic boolean onPreferenceChange(Preference preference, Object newValue) {boolean isChecked = (Boolean) newValue;Log.w(TAG, "onPreferenceChange: " + isChecked);
-        if (!tryEthNode()) {
+        if (!haveEthernetInterface()) {Toast.makeText(mContext, mContext.getString(R.string.not_support_eth), Toast.LENGTH_LONG).show();return false;}
@@ -188,7 +205,11 @@ public class EthernetSwitchPreferenceController extends AbstractPreferenceControif (mPrefs != null) {mPrefs.edit().putBoolean(KEY, isChecked).apply();}
-        setIfaceState(ETHERNET_IFACE, isChecked);
+
+        List<String> interfaces = mEthManager.getInterfaceList();
+        for (int i = 0; i < interfaces.size(); i++) {
+            setIfaceState(interfaces.get(i), isChecked);
+        }return true;}

完整补丁:

diff --git a/src/com/android/settings/ethernet/EthernetSettings.java b/src/com/android/settings/ethernet/EthernetSettings.java
index 90c757146bd..15e7b9800a4 100644
--- a/src/com/android/settings/ethernet/EthernetSettings.java
+++ b/src/com/android/settings/ethernet/EthernetSettings.java
@@ -43,7 +43,6 @@ public class EthernetSettings extends DashboardFragment implementsprivate static final String KEY_TOGGLE_ETHERNET = "main_toggle_ethernet";public static final String SHARED_PREFERENCES_NAME = "ethernet_prefs";public static final String ETHERNET_SETTINGS_CONFIG = "ethernet_settings_config";
-    public static final String ETHERNET_IFACE = "eth0";private static EthernetSwitchPreferenceController mEthernetUIController = null;@Override
diff --git a/src/com/android/settings/ethernet/EthernetSettingsManager.java b/src/com/android/settings/ethernet/EthernetSettingsManager.java
index 55fb790a94c..fa8a65d3827 100644
--- a/src/com/android/settings/ethernet/EthernetSettingsManager.java
+++ b/src/com/android/settings/ethernet/EthernetSettingsManager.java
@@ -16,8 +16,6 @@package com.android.settings.ethernet;-import static com.android.settings.ethernet.EthernetSettings.ETHERNET_IFACE;
-import android.content.Context;import android.net.ConnectivityManager;import android.net.EthernetManager;
@@ -39,6 +37,7 @@ import java.net.Inet4Address;import java.net.InetAddress;import java.net.UnknownHostException;import java.util.ArrayList;
+import java.util.List;public class EthernetSettingsManager {private final static String TAG = "EthernetSettingsManager";
@@ -103,7 +102,15 @@ public class EthernetSettingsManager {final EthernetNetworkUpdateRequest request = new EthernetNetworkUpdateRequest.Builder().setIpConfiguration(mIpConfiguration).build();
-        mEthManager.updateConfiguration(ETHERNET_IFACE, request, r -> r.run(), null);
+
+        List<String> interfaces = mEthManager.getInterfaceList();
+        if (!interfaces.isEmpty()) {
+            // When there are two interfaces, only the interface configuration of the first access device will be modified
+            Log.d(TAG, "update Ethernet Configuration : " + interfaces.get(0));
+            mEthManager.updateConfiguration(interfaces.get(0), request, r -> r.run(), null);
+        } else {
+            Log.w(TAG, "Ethernet Interfaces is null");
+        }}public Network getFirstNetwork() {
diff --git a/src/com/android/settings/ethernet/EthernetSwitchPreferenceController.java b/src/com/android/settings/ethernet/EthernetSwitchPreferenceController.java
index d39d0e70b45..dac9efb1235 100644
--- a/src/com/android/settings/ethernet/EthernetSwitchPreferenceController.java
+++ b/src/com/android/settings/ethernet/EthernetSwitchPreferenceController.java
@@ -17,7 +17,7 @@package com.android.settings.ethernet;import static android.net.NetworkCapabilities.TRANSPORT_ETHERNET;
-import static com.android.settings.ethernet.EthernetSettings.ETHERNET_IFACE;
+import static android.net.NetworkInfo.State;import android.app.Activity;import android.content.Context;
@@ -28,6 +28,7 @@ import android.net.EthernetNetworkUpdateRequest;import android.net.IpConfiguration;import android.net.Network;import android.net.NetworkCapabilities;
+import android.net.NetworkInfo;import android.net.NetworkRequest;import android.net.wifi.WifiManager;import android.util.Log;
@@ -46,6 +47,7 @@ import com.android.settings.R;import com.android.settingslib.core.AbstractPreferenceController;import java.io.IOException;
+import java.util.List;/*** This controller helps to manage the state of wifi switch preference.*/
@@ -100,13 +102,32 @@ public class EthernetSwitchPreferenceController extends AbstractPreferenceContro@Overridepublic void onLost(@NonNull Network network) {
-                updatePreferenceStatus(false);
-                Log.w(TAG, "onLost setChecked");
+                if (getDefaultNetwork() == null) {
+                    Log.d(TAG, "There is no Ethernet interface, setChecked false");
+                    updatePreferenceStatus(false);
+                }}};Log.w(TAG, "initNetworkCallback");}+    private Network getDefaultNetwork() {
+        final Network[] networks = mConnectivityManager.getAllNetworks();
+        for (final Network network : networks) {
+            NetworkInfo networkInfo = mConnectivityManager.getNetworkInfo(network);
+            Log.w(TAG, "getDefaultNetwork, networkInfo:" + networkInfo);
+            if (networkInfo != null
+                    && (networkInfo.getType() == ConnectivityManager.TYPE_ETHERNET)) {
+                Log.w(TAG, "getDefaultNetwork, type is ethernet:" + network);
+                if (networkInfo.getState() == State.DISCONNECTED) {
+                    continue;
+                }
+                return network;
+            }
+        }
+        return null;
+    }
+private void updatePreferenceStatus(boolean isChecked) {if (mPrefs != null) {mPrefs.edit().putBoolean(KEY, isChecked).apply();
@@ -144,8 +165,7 @@ public class EthernetSwitchPreferenceController extends AbstractPreferenceControLog.w(TAG, "mPreference is null: " + (mPreference == null));boolean checked = mPrefs.getBoolean(KEY, false);Log.w(TAG, "mPreference is checked: " + checked);
-        updatePreferenceStatus(tryEthNode() && checked && mIsCheckEthernet);
-//        showEthernetSettings(checked);
+        updatePreferenceStatus(haveEthernetInterface() && checked && mIsCheckEthernet);}private void showEthernetSettings(boolean show) {
@@ -162,24 +182,21 @@ public class EthernetSwitchPreferenceController extends AbstractPreferenceControreturn true;}-    // TODO: We need to change to no longer use nodes here
-    private boolean tryEthNode() {
-        try {
-            Process p = Runtime.getRuntime().exec("ls sys/class/net/eth0");
-            int tmp = p.waitFor();
-            Log.w(TAG, "tryEthNode tmp: " + tmp);
-            return tmp == 0;
-        } catch (IOException | InterruptedException e) {
-            Log.w(TAG, "access /proc/net/dev failed!");
+    private boolean haveEthernetInterface() {
+        List<String> interfaces = mEthManager.getInterfaceList();
+        if (interfaces.isEmpty()) {
+            return false;
+        } else {
+            Log.v(TAG, "Ethernet Interfaces = " + interfaces);
+            return true;}
-        return false;}@Overridepublic boolean onPreferenceChange(Preference preference, Object newValue) {boolean isChecked = (Boolean) newValue;Log.w(TAG, "onPreferenceChange: " + isChecked);
-        if (!tryEthNode()) {
+        if (!haveEthernetInterface()) {Toast.makeText(mContext, mContext.getString(R.string.not_support_eth), Toast.LENGTH_LONG).show();return false;}
@@ -188,7 +205,11 @@ public class EthernetSwitchPreferenceController extends AbstractPreferenceControif (mPrefs != null) {mPrefs.edit().putBoolean(KEY, isChecked).apply();}
-        setIfaceState(ETHERNET_IFACE, isChecked);
+
+        List<String> interfaces = mEthManager.getInterfaceList();
+        for (int i = 0; i < interfaces.size(); i++) {
+            setIfaceState(interfaces.get(i), isChecked);
+        }return true;}

http://www.xdnf.cn/news/529309.html

相关文章:

  • 【JavaScript】用 Proxy 拦截对象属性
  • Xshell实战:远程连接VMware CentOS7虚拟机与高效运维指南——从零配置到自动化操作,解锁Xshell的核心价值
  • Bootstrap 5 容器与网格系统详解
  • 项目删除了,为什么vscode中的git还是存在未提交记录,应该怎么删除掉
  • vue3个生命周期解析,及setup
  • 遨游科普:三防平板是什么?有什么作用?
  • 线光谱共焦传感器:复杂材质检测
  • MCU 温度采样理论(-ADC Temperature sensor)
  • 用户账号及权限管理:企业安全的基石与艺术
  • python训练营day29
  • CAN总线采样点不一致的危害
  • 26、DAPO论文笔记(解耦剪辑与动态采样策略优化,GRPO的改进)
  • 计算机网络(2)——应用层(上)
  • Spring_Boot(一)Hello spring boot!
  • 2025年- H32-Lc140 --21. 合并两个有序链表--Java版
  • BM25(Best Matching 25)介绍与使用
  • BC27 计算球体的体积
  • hexo博客搭建使用
  • 数据库-oracle-包-视图传参
  • upload靶场1-5关
  • 【MYSQL】基本查询,表的增删查改
  • 云原生攻防1(基础介绍)
  • Unity预制体变体(Prefab Variants)、接口(Interface)、抽象类(Abstract Class)、枚举(Enumeration)
  • 如何快速更换电脑浏览器ip:教程与注意事项
  • Seata源码—6.Seata AT模式的数据源代理二
  • leetcode 74. Search a 2D Matrix
  • SQL注入——Sqlmap工具使用
  • 实景VR展厅制作流程与众趣科技实景VR展厅应用
  • Assistants API
  • upload-labs靶场通关详解:第10关