市面上的资料大多是Rockchip平台的4G/5G模块的一些分享。对于其他平台,诸如高通、联发科之类的公司,因为他们自己做modem,所以对于4G/5G有着非常深厚的功底,但有时候多做反而不是好事,这就造成如果我想用别家的4G模块,就没办法按照厂商提供的方式把模块加载起来,对于linux还相对通用一些,但是对于Android,事情就没那么简单了。
这里基于联发科Genio510物联网芯片(Android13),以及移远的EC20 4G模块,来看看是怎么一个思路。
1. kernel按部就班
kernel部分对于大家来说区别并不算大,按照移远的教程一步步做即可,最后要通过USB识别到4G模块。目的就算达到了。简单列一下kernel需要开启的config。
CONFIG_USB_SERIAL=m
CONFIG_USB_SERIAL_WWAN=m
CONFIG_USB_SERIAL_OPTION=m
CONFIG_USB_NET_DRIVERS=y
CONFIG_USB_USBNET=m
CONFIG_PPP=y
CONFIG_PPP_BSDCOMP=y
CONFIG_PPP_DEFLATE=y
CONFIG_PPP_FILTER=y
CONFIG_PPP_MPPE=y
CONFIG_PPP_MULTILINK=y
CONFIG_PPPOE=y
CONFIG_PPTP=y
CONFIG_PPPOL2TP=y
CONFIG_PPP_ASYNC=y
CONFIG_PPP_SYNC_TTY=y
这里用了PPP的模式,别的没有调通。
2. 不要用MTK那一套
MTK在自己的vendor下面有自己的一套关于4G模块的东西,我猜他们也一定支持市面上的一些主流的4G模块。但是奈何庙小,寻求支持肯定又是一笔不菲的开支。于是就决定赌上一把,看看原生的能不能调通。
在 hardware/ril 下面把移远提供的so文件编译进系统。
diff --git a/libril/Android.mk b/libril/Android.mk_disabled
similarity index 100%
rename from libril/Android.mk
rename to libril/Android.mk_disabled
diff --git a/reference-ril/Android.mk b/reference-ril/Android.mk_disabled
similarity index 100%
rename from reference-ril/Android.mk
rename to reference-ril/Android.mk_disabled
diff --git a/rild/Android.mk b/rild/Android.mk
index d1c1b95..c8d7e56 100644
--- a/rild/Android.mk
+++ b/rild/Android.mk
@@ -1,7 +1,5 @@
# Copyright 2006 The Android Open Source Project
-ifndef ENABLE_VENDOR_RIL_SERVICE
-
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
@@ -41,4 +39,63 @@ endif
include $(BUILD_EXECUTABLE)
-endif
+include $(CLEAR_VARS)
+LOCAL_MODULE := libril
+LOCAL_SRC_FILES :=libril.so
+LOCAL_MODULE_CLASS := SHARED_LIBRARIES
+LOCAL_PROPRIETARY_MODULE := true
+LOCAL_MODULE_SUFFIX:= .so
+LOCAL_MULTILIB := 64
+LOCAL_SHARED_LIBRARIES := \
+ liblog \
+ libutils \
+ libcutils \
+ libhardware_legacy \
+ librilutils \
+ android.hardware.radio@1.0 \
+ android.hardware.radio@1.1 \
+ android.hardware.radio@1.2 \
+ android.hardware.radio@1.3 \
+ android.hardware.radio@1.4 \
+ android.hardware.radio@1.5 \
+ android.hardware.radio@1.6 \
+ android.hardware.secure_element@1.0 \
+ android.hardware.secure_element@1.1 \
+ android.hardware.secure_element@1.2 \
+ android.hardware.radio.config@1.0 \
+ android.hardware.radio.config@1.1 \
+ android.hardware.radio.config@1.2 \
+ android.hardware.radio.config@1.3 \
+ android.hardware.radio.deprecated@1.0 \
+ libhidlbase
+include $(BUILD_PREBUILT)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := libreference-ril
+LOCAL_SRC_FILES :=libreference-ril.so
+LOCAL_MODULE_CLASS := SHARED_LIBRARIES
+LOCAL_PROPRIETARY_MODULE := true
+LOCAL_MODULE_SUFFIX:= .so
+LOCAL_MULTILIB := 64
+LOCAL_SHARED_LIBRARIES := \
+ liblog \
+ libutils \
+ libcutils \
+ libril \
+ libnetutils \
+ android.hardware.radio@1.0 \
+ android.hardware.radio@1.1 \
+ android.hardware.radio@1.2 \
+ android.hardware.radio@1.3 \
+ android.hardware.radio@1.4 \
+ android.hardware.radio@1.5 \
+ android.hardware.radio@1.6 \
+ android.hardware.secure_element@1.0 \
+ android.hardware.secure_element@1.1 \
+ android.hardware.secure_element@1.2 \
+ android.hardware.radio.config@1.0 \
+ android.hardware.radio.config@1.1 \
+ android.hardware.radio.config@1.2 \
+ android.hardware.radio.config@1.3 \
+ libhidlbase
+include $(BUILD_PREBUILT)
diff --git a/rild/libreference-ril.so b/rild/libreference-ril.so
new file mode 100755
index 0000000..4e6a153
Binary files /dev/null and b/rild/libreference-ril.so differ
diff --git a/rild/libril.so b/rild/libril.so
new file mode 100755
index 0000000..5dd49e5
Binary files /dev/null and b/rild/libril.so differ
diff --git a/rild/rild.rc b/rild/rild.rc
index f6beb54..249e7ad 100644
--- a/rild/rild.rc
+++ b/rild/rild.rc
@@ -1,5 +1,5 @@
-service vendor.ril-daemon /vendor/bin/hw/rild
+service ril-daemon /vendor/bin/hw/rild
class main
- user radio
- group radio cache inet misc audio log readproc wakelock
+ user root
+ group radio cache inet misc audio sdcard_rw log
capabilities BLOCK_SUSPEND NET_ADMIN NET_RAW
其中rild会在开机之后启动,识别到匹配的USB设备之后便会去执行注网等等一系列操作。
2.1. framework/base/telephony
我们需要找到AOSP公版的代码,然后用公版的telephony目录取代MTK的telephony目录,诸如此类:
iff --git a/telephony/common/com/android/internal/telephony/GsmAlphabet.java b/telephony/common/com/android/internal/telephony/GsmAlphabet.java
index fb1a1dd..5c53f7e 100644
--- a/telephony/common/com/android/internal/telephony/GsmAlphabet.java
+++ b/telephony/common/com/android/internal/telephony/GsmAlphabet.java
@@ -121,14 +121,6 @@
@UnsupportedAppUsage
public int languageTable;
- // MTK-START
- public boolean useSingleShift = false;
-
- public boolean useLockingShift = false;
-
- public int shiftLangId = -1;
- // MTK-END
-
/**
* The GSM national language shift table to use, or 0 for the default 7-bit extension table.
*/
diff --git a/telephony/common/com/android/internal/telephony/SmsApplication.java b/telephony/common/com/android/internal/telephony/SmsApplication.java
index 8c7967a..4230225 100644
--- a/telephony/common/com/android/internal/telephony/SmsApplication.java
+++ b/telephony/common/com/android/internal/telephony/SmsApplication.java
@@ -60,11 +60,6 @@
import java.util.function.Consumer;
import java.util.stream.Collectors;
-// MTK-START
-import android.os.SystemProperties;
-import java.lang.reflect.Method;
-// MTK-END
-
/**
* Class for managing the primary application that we will deliver SMS/MMS messages to
*
...
2.2 device/mediatek
这里把移远PPP拨号的那一堆脚本编译进系统,这里最关键的是修改MTK的配置文件使其支持4G。
diff --git a/ProjectConfig.mk b/ProjectConfig.mk
index 0e2bd2e..9fd2a13 100644
--- a/ProjectConfig.mk
+++ b/ProjectConfig.mk
@@ -342,7 +342,7 @@
MTK_SWABF_SUPPORT = no
MTK_SWCHR_SUPPORT = no
MTK_SYSTEM_UPDATE_SUPPORT = no
-MTK_TB_WIFI_3G_MODE = WIFI_ONLY
+#MTK_TB_WIFI_3G_MODE = WIFI_ONLY
MTK_TC1_COMMON_SERVICE = no
MTK_TC1_FEATURE = no
MTK_TDM_MAS_MUX_SUPPORT = no
要把WIFI_ONLY的宏拿掉。
diff --git a/device.mk b/device.mk
index ece9d8c..10f7648 100644
--- a/device.mk
+++ b/device.mk
@@ -253,3 +253,25 @@
PRODUCT_PACKAGES += libmtkcam_fdipc_server
PRODUCT_PACKAGES += libcam_ipc_fwmvp_server
endif
+
+RAT_CONFIG_LTE_SUPPORT=yes
+
+PRODUCT_PACKAGES += \
+ android.hardware.radio@1.0 \
+ android.hardware.radio@1.1 \
+ android.hardware.radio@1.2 \
+ android.hardware.radio@1.3 \
+ android.hardware.radio@1.4 \
+ android.hardware.radio@1.5 \
+ android.hardware.radio@1.6 \
+ android.hardware.secure_element@1.0 \
+ android.hardware.secure_element@1.1 \
+ android.hardware.secure_element@1.2 \
+ android.hardware.radio.config@1.0 \
+ android.hardware.radio.config@1.1 \
+ android.hardware.radio.config@1.2 \
+ android.hardware.radio.config@1.3 \
+ android.hardware.radio.deprecated@1.0 \
+ libhidlbase
diff --git a/BoardConfig.mk b/BoardConfig.mk
index dbb9ec6..3af5601 100644
--- a/BoardConfig.mk
+++ b/BoardConfig.mk
@@ -127,7 +127,7 @@
EXTENDED_FONT_FOOTPRINT := true
# To disable AOSP rild
-ENABLE_VENDOR_RIL_SERVICE := true
+#ENABLE_VENDOR_RIL_SERVICE := true
ifeq (yes,$(strip $(MTK_GMO_RAM_OPTIMIZE)))
BOARD_MTK_GMO_SYSTEM_SIZE_KB := 1400832
diff --git a/SystemConfig.mk b/SystemConfig.mk
index 7f02d71..45fab54 100644
--- a/SystemConfig.mk
+++ b/SystemConfig.mk
@@ -54,7 +54,7 @@
MSSI_MTK_TC1_COMMON_SERVICE = no
MSSI_MTK_TC1_FEATURE = no
MSSI_MTK_TEE_TRUSTED_UI_SUPPORT = no
-MSSI_MTK_TELEPHONY_ADD_ON_POLICY = 0
+MSSI_MTK_TELEPHONY_ADD_ON_POLICY = 1
MSSI_MTK_HDMI_SUPPORT = no
MSSI_MTK_DRM_HDMI_SUPPORT = yes
MSSI_MTK_UCE_SUPPORT = no
2.3. framework/base/opt/telephony
和之前的framework/base同理,要将这里的代码还原回Android13。
2.4. packages/app/Settings
和之前的framework/base同理,要将这里的代码还原回Android13。
3. 关闭权限
/system/core
diff --git a/init/devices.cpp b/init/devices.cpp
index d4a3cb9..160bf16 100644
--- a/init/devices.cpp
+++ b/init/devices.cpp
@@ -550,6 +550,8 @@
int device_id = uevent.minor % 128 + 1;
devpath = StringPrintf("/dev/bus/usb/%03d/%03d", bus_id, device_id);
}
+ } else if (uevent.subsystem == "usbmisc" && !uevent.device_name.empty()) {
+ devpath = "/dev/" + uevent.device_name;
} else if (StartsWith(uevent.subsystem, "usb")) {
// ignore other USB events
return;
diff --git a/init/selinux.cpp b/init/selinux.cpp
index 4d77d33..68adb35 100644
--- a/init/selinux.cpp
+++ b/init/selinux.cpp
@@ -101,7 +101,7 @@
namespace {
enum EnforcingStatus { SELINUX_PERMISSIVE, SELINUX_ENFORCING };
-
+/*
EnforcingStatus StatusFromProperty() {
EnforcingStatus status = SELINUX_ENFORCING;
@@ -128,7 +128,7 @@
}
return true;
}
-
+*/
// Forks, executes the provided program in the child, and waits for the completion in the parent.
// Child's stderr is captured and logged using LOG(ERROR).
bool ForkExecveAndWaitForCompletion(const char* filename, char* const argv[]) {
@@ -715,7 +715,8 @@
void SelinuxSetEnforcement() {
bool kernel_enforcing = (security_getenforce() == 1);
- bool is_enforcing = IsEnforcing();
+ //bool is_enforcing = IsEnforcing();
+ bool is_enforcing = false;
if (kernel_enforcing != is_enforcing) {
if (security_setenforce(is_enforcing)) {
PLOG(FATAL) << "security_setenforce(" << (is_enforcing ? "true" : "false")
不出意外的话就可以在Android的界面上看到有网络的图标,并且可以正常上网了。