RK3288 Android11 mini-pcie接口 4G模组EC200A适配(含自适应功能)

这里写目录标题

  • 1、修改驱动内核配置
    • ①使能USBNET功能
    • ②使能 USB 串口 GSM、CDMA 驱动
    • ③使能 USB 的 CDC ACM模式
    • ④使能PPP功能
  • 2、使用lsusb命令查看是否识别到usb接口的“EC200A”4G模组
  • 3、在drivers/usb/serial/option.c添加VID和PID信息
    • ①添加VID和PID定义
    • ②在option_ids 数组中添加
    • ③支持 ECM 接口,可以通过 ECM 接口轻松联网,在option_probe 函数添加如下
    • ④添加休眠后唤醒接口,在option_1port_device 结构体变量里面添加如下
  • 4、在drivers/usb/serial/usb_wwan.c 文件中的usb_wwan_setup_urb函数中添加零包处理代码
  • 5、插入EC200A模块,查看日志是否虚拟出USB接口,现象如下
  • 6、关闭SELINUX,路径:a\device\rockchip\common\BoardConfig.mk
  • 7、开启BOARD_HAVE_DONGLE和BOARD_HAS_RK_4G_MODEM,路径与第6点一样
  • 8、无自适应功能的适配方法,也就是不会动态加载RIL库,而是写死的方法,如下
    • ①将ril拷贝到对应的系统路径,创建adevice\rockchip\rk3288\rk3288_Android11\modify.mk文件,内容如下:
    • ②设置vendor.rild.libpath属性
    • ③设置rild.libpath属性
    • ④修改开启rild服务,加载libreference-ril-QUECTEL.so库文件
  • 9、自适应功能的适配方法,也就是会动态加载RIL库,如下
  • 10、添加权限,在a\device\rockchip\common\ueventd.rockchip.rc文件下添加如下
  • 11、查看库是否有和加载库是否正确及日志
  • 12、ping百度是否能上网
  • 13、PATCH补丁文件和需要添加的文件

1、修改驱动内核配置

①使能USBNET功能

-> Device Drivers 
	-> -*- Network device support 
 		-> USB Network Adapters 
			-> -*- Multi-purpose USB Networking Framework

②使能 USB 串口 GSM、CDMA 驱动

Device Drivers  --->
	[*] USB support  --->
	        <*> USB Serial Converter support
		          [*] USB Generic Serail Driver
		          [*] USB Driver for GSM and CMDA modems

③使能 USB 的 CDC ACM模式

-> Device Drivers 
	-> [*] USB support 
		-> <*> Support for Host-side USB
			-> <*> USB Modem (CDC ACM) support

④使能PPP功能

Device Drivers  --->
      [*] Network device support  --->
	        <*> PPP (point-to-point protocol) support
	        <*> PPP support for async serial ports
	        <*> PPP support for sync tty ports
	        <*> PPP Deflate compression

2、使用lsusb命令查看是否识别到usb接口的“EC200A”4G模组

rk3288_Android10:/ $ lsusb
Bus 001 Device 005: ID 2c7c:6005

  这里解释一下信息,“2c7c”指的是VID,“6005”指的是PID。

3、在drivers/usb/serial/option.c添加VID和PID信息

①添加VID和PID定义

#define QUECTEL_VENDOR_ID		0x2c7c	/* VID */
#define QUECTEL_PRODUCT_EC200A_CN       0x6005	/* PID */

②在option_ids 数组中添加

{ USB_DEVICE(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EC200A_CN) },	/* Quectel EC200A */

③支持 ECM 接口,可以通过 ECM 接口轻松联网,在option_probe 函数添加如下

#if 1 //Added by Quectel  
    //Quectel UC20's interface 4 can be used as USB Network device  
    if (serial->dev->descriptor.idVendor == cpu_to_le16(0x05C6) && serial->dev->descriptor.idProduct == cpu_to_le16(0x9003)  
        && serial->interface->cur_altsetting->desc.bInterfaceNumber >= 4)  
        return -ENODEV;  
  
    //Quectel EC20(MDM9215)'s interface 4 can be used as USB Network device  
    if (serial->dev->descriptor.idVendor == cpu_to_le16(0x05C6) && serial->dev->descriptor.idProduct == cpu_to_le16(0x9215)  
        && serial->interface->cur_altsetting->desc.bInterfaceNumber >= 4)  
        return -ENODEV;  
  
    if (serial->dev->descriptor.idVendor == cpu_to_le16(0x2C7C)) {  
        __u16 idProduct = le16_to_cpu(serial->dev->descriptor.idProduct);  
        struct usb_interface_descriptor *intf = &serial->interface->cur_altsetting->desc;  
  
        if (intf->bInterfaceClass != 0xFF || intf->bInterfaceSubClass == 0x42) {  
            //ECM, RNDIS, NCM, MBIM, ACM, UAC, ADB  
            return -ENODEV;  
        }  
  
        if ((idProduct&0xF000) == 0x0000) {  
            //MDM interface 4 is QMI  
            if (intf->bInterfaceNumber == 4 && intf->bNumEndpoints == 3  
                && intf->bInterfaceSubClass == 0xFF && intf->bInterfaceProtocol == 0xFF)  
                return -ENODEV;  
        }  
    }  
#endif 

④添加休眠后唤醒接口,在option_1port_device 结构体变量里面添加如下

.reset_resume = usb_wwan_resume,

4、在drivers/usb/serial/usb_wwan.c 文件中的usb_wwan_setup_urb函数中添加零包处理代码

#if 1 //Added by Quectel for Zero Packet  
    if (dir == USB_DIR_OUT) {  
        if (serial->dev->descriptor.idVendor == cpu_to_le16(0x05C6) && serial->dev->descriptor.idProduct == cpu_to_le16(0x9090))  
            urb->transfer_flags |= URB_ZERO_PACKET;  
        if (serial->dev->descriptor.idVendor == cpu_to_le16(0x05C6) && serial->dev->descriptor.idProduct == cpu_to_le16(0x9003))  
            urb->transfer_flags |= URB_ZERO_PACKET;  
        if (serial->dev->descriptor.idVendor == cpu_to_le16(0x05C6) && serial->dev->descriptor.idProduct == cpu_to_le16(0x9215))  
            urb->transfer_flags |= URB_ZERO_PACKET;  
        if (serial->dev->descriptor.idVendor == cpu_to_le16(0x2C7C))  
            urb->transfer_flags |= URB_ZERO_PACKET;  
    }  
#endif

5、插入EC200A模块,查看日志是否虚拟出USB接口,现象如下

[ 2537.919546] option 1-1.4:1.2: GSM modem (1-port) converter detected
[ 2537.920339] usb 1-1.4: GSM modem (1-port) converter now attached to ttyUSB0
[ 2537.921527] option 1-1.4:1.3: GSM modem (1-port) converter detected
[ 2537.922340] usb 1-1.4: GSM modem (1-port) converter now attached to ttyUSB1
[ 2537.923486] option 1-1.4:1.4: GSM modem (1-port) converter detected
[ 2537.924214] usb 1-1.4: GSM modem (1-port) converter now attached to ttyUSB2

  再使用ls /dev/ttyUSB*命令查看,如下:

rk3288_Android10:/ $ ls /dev/ttyUSB*
/dev/ttyUSB0 /dev/ttyUSB1 /dev/ttyUSB2

6、关闭SELINUX,路径:a\device\rockchip\common\BoardConfig.mk

BOARD_SELINUX_ENFORCING ?= false

  当BOARD_SELINUX_ENFORCING设置为1时,表示SELinux处于强制执行模式;当设置为0时,表示SELinux处于宽松模式。在强制执行模式下,SELinux会严格限制应用程序和系统服务的权限,确保它们只能访问其被授权的资源。

7、开启BOARD_HAVE_DONGLE和BOARD_HAS_RK_4G_MODEM,路径与第6点一样

  如果编译时报android.hardware.radio.deprecated这个错误,那么就是BOARD_HAS_RK_4G_MODEM引起的错误。
  解决方法:

a\device\rockchip\common\manifest.xml
     <hal format="hidl">
         <name>android.hardware.radio</name>
         <transport>hwbinder</transport>
         <fqname>@1.1::IRadio/slot1</fqname>
         <fqname>@1.1::IRadio/slot2</fqname>
         <fqname>@1.2::ISap/slot1</fqname>
     </hal>
-     <hal format="hidl">
-         <name>android.hardware.radio.deprecated</name>
-         <transport>hwbinder</transport>
-         <version>1.0</version>
-         <interface>
-             <name>IOemHook</name>
-             <instance>slot1</instance>
-         </interface>
-     </hal>
-     <kernel target-level="5"/>
  </manifest>	

a\device\rockchip\common\4g_modem\manifest.xml
<manifest version="1.0" type="device">
    <hal format="hidl">
        <name>android.hardware.radio</name>
        <transport>hwbinder</transport>
        <fqname>@1.1::IRadio/slot1</fqname>
        <fqname>@1.1::IRadio/slot2</fqname>
        <fqname>@1.2::ISap/slot1</fqname>
    </hal>
    <hal format="hidl">
        <name>android.hardware.radio.deprecated</name>
        <transport>hwbinder</transport>
        <version>1.0</version>
        <interface>
            <name>IOemHook</name>
            <instance>slot1</instance>
        </interface>
    </hal>
    <hal format="hidl">
-        <name>android.hardware.radio.config</name>
+        <name>android.hardware.radio</name>
        <transport>hwbinder</transport>
        <version>1.0</version>
        <interface>
-            <name>IRadioConfig</name>
+            <name>IRadio</name>
-            <instance>default</instance>
+            <instance>slot1</instance>
        </interface>
    </hal>
</manifest>

  如果报的错误是FAILED: out/target/product/rk3568_r/obj/EXECUTABLES/usb_dongle_intermediates/Misc.o
  解决方法:

\external\usb_modeswitch\usb_dongle\Android.mk
- common_local_tidy_flags := -warnings-as-errors=clang-analyzer-security*,cert-*
+ #common_local_tidy_flags := -warnings-as-errors=clang-analyzer-security*,cert-*

8、无自适应功能的适配方法,也就是不会动态加载RIL库,而是写死的方法,如下

①将ril拷贝到对应的系统路径,创建adevice\rockchip\rk3288\rk3288_Android11\modify.mk文件,内容如下:

PRODUCT_PACKAGES += rild
PRODUCT_COPY_FILES += \
    device/rockchip/rk3288/rk3288_Android11/modify/xG_module/libquectel-ril/armeabi/libreference-ril-QUECTEL.so:vendor/lib/libreference-ril-QUECTEL.so \
    device/rockchip/rk3288/rk3288_Android11/modify/xG_module/libquectel-ril/armeabi/chat:system/bin/chat \
    device/rockchip/rk3288/rk3288_Android11/modify/xG_module/libquectel-ril/armeabi/ip-up:system/bin/ip-up \
    device/rockchip/rk3288/rk3288_Android11/modify/xG_module/libquectel-ril/armeabi/ip-down:system/bin/ip-down \
    device/rockchip/rk3288/rk3288_Android11/apns-conf.xml:system/etc/apns-conf.xml
然后a\device\rockchip\rk3288\device.mk文件下添加如下:
include $(LOCAL_PATH)/rk3288_Android11/modify.mk

②设置vendor.rild.libpath属性

a\device\rockchip\common\device.mk
ifeq ($(strip $(BOARD_HAS_RK_4G_MODEM)),true)
PRODUCT_PACKAGES += \
    CarrierDefaultApp \
    CarrierConfig \
    rild \
-   librk-ril \
+   libreference-ril-QUECTEL.so \
    dhcpcd
 
PRODUCT_COPY_FILES += vendor/rockchip/common/phone/etc/apns-full-conf.xml:$(TARGET_COPY_OUT_PRODUCT)/etc/apns-conf.xml
 
PRODUCT_PACKAGES += \
    android.hardware.radio@1.2-radio-service \
    android.hardware.radio.config@1.0-service
 
PRODUCT_PROPERTY_OVERRIDES += \
		ro.boot.noril=false \
		ro.telephony.default_network=9
 
ifeq ($(strip $(TARGET_ARCH)), arm64)
PRODUCT_PROPERTY_OVERRIDES += \
-        vendor.rild.libpath=/vendor/lib64/librk-ril.so
+		 vendor.rild.libpath=/vendor/lib64/libreference-ril-QUECTEL.so
 
PRODUCT_COPY_FILES += \
		$(LOCAL_PATH)/4g_modem/bin64/dhcpcd:$(TARGET_COPY_OUT_VENDOR)/bin/dhcpcd \
		$(LOCAL_PATH)/4g_modem/lib64/librk-ril.so:$(TARGET_COPY_OUT_VENDOR)/lib64/librk-ril.so
else
PRODUCT_PROPERTY_OVERRIDES += \
-		vendor.rild.libpath=/vendor/lib/librk-ril.so
+		vendor.rild.libpath=/vendor/lib/libreference-ril-QUECTEL.so
 
PRODUCT_COPY_FILES += \
		$(LOCAL_PATH)/4g_modem/bin32/dhcpcd:$(TARGET_COPY_OUT_VENDOR)/bin/dhcpcd \
		$(LOCAL_PATH)/4g_modem/lib32/librk-ril.so:$(TARGET_COPY_OUT_VENDOR)/lib/librk-ril.so
 
endif
endif

③设置rild.libpath属性

a\device\rockchip\rk3288\device.mk
PRODUCT_PROPERTY_OVERRIDES += \
                ro.ril.ecclist=112,911 \
                ro.opengles.version=196610 \
                wifi.interface=wlan0 \
+		ro.telephony.default_network=9 \
+		rild.libpath=/vendor/lib64/libreference-ril-QUECTEL.so \
+		rild.libargs=-d /dev/ttyUSB2 \
                ro.audio.monitorOrientation=true \
                debug.nfc.fw_download=false \
                debug.nfc.se=false \
                vendor.hwc.compose_policy=1 \
                sys.wallpaper.rgb565=0 \
                sf.power.control=2073600 \
                sys.rkadb.root=0 \
                ro.sf.fakerotation=false \
                ro.tether.denied=false \
                sys.resolution.changed=false \
                ro.default.size=100 \
                ro.product.usbfactory=rockchip_usb \
                wifi.supplicant_scan_interval=15 \
                ro.factory.tool=0 \
                ro.kernel.android.checkjni=0 \
                ro.build.shutdown_timeout=6 \
                persist.enable_task_snapshots=false \
                ro.vendor.frameratelock=true

④修改开启rild服务,加载libreference-ril-QUECTEL.so库文件

-	service ril-daemon /vendor/bin/hw/rild
+	service ril-daemon /vendor/bin/hw/rild -l /vendor/lib/libreference-ril-QUECTEL.so
    socket rild stream 660 root radio
    socket rild-debug stream 660 radio system
    class main
    user radio
    group radio cache inet misc audio log readproc wakelock
    capabilities BLOCK_SUSPEND NET_ADMIN NET_RAW

9、自适应功能的适配方法,也就是会动态加载RIL库,如下

参考博客链接

10、添加权限,在a\device\rockchip\common\ueventd.rockchip.rc文件下添加如下

#quectel port
/dev/ttyUSB*              0660   radio      radio
/dev/ttyACM*              0660   radio      radio
/dev/cdc-wdm*             0660   radio      radio
/dev/qcqmi*               0660   radio      radio
/dev/cdc-acm*             0660   radio      radio

11、查看库是否有和加载库是否正确及日志

①查看库是否存在:cd vendor/lib/
②查看加载库:getprop | grep rild
③应用日志:logcat -b radio

12、ping百度是否能上网

RK3288 Android11 mini-pcie接口 4G模组EC200A适配(含自适应功能)_第1张图片

13、PATCH补丁文件和需要添加的文件

文件链接

你可能感兴趣的:(瑞芯微RK3288,Android11驱动开发,linux,驱动开发,嵌入式)