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 为插上,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
-
通过 NetworkInfo.State 更灵活地处理网络状态,替代了 ETHERNET_IFACE 的硬编码。
-
新增了 getDefaultNetwork()方法,通过 NetworkInfo 检查当前活跃的以太网网络。
-
将 tryEthNode()替换为 haveEthernetInterface() 方法,直接使用以太网管理器来查询接口。
-
可以处理所有以太网接口的状态,而不仅仅是一个。
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;}