【随笔记】T507 Android10 EC200U-CN 4G Cat1 移植

基本信息

硬件信息

硬件平台:T507 (Android 10 Linux 4.9)

模组型号:EC200U-CN(Cat1)(展讯芯片)

相关文件

代理提供

longan/kernel/linux-4.9/drivers/net/usb/qmi_wwan_q.c
android/vendor/aw/public/prebuild/lib/librild/lib/lib32/libquectel-ril.so
android/vendor/aw/public/prebuild/lib/librild/lib/lib64/libquectel-ril.so

内核驱动

longan/kernel/linux-4.9/drivers/net/usb/Makefile
longan/kernel/linux-4.9/drivers/net/usb/qmi_wwan_q.c
longan/kernel/linux-4.9/drivers/usb/serial/option.c
longan/kernel/linux-4.9/drivers/usb/serial/usb_wwan.c

系统适配

android/hardware/ril/rild/rild.rc
android/hardware/ril/rild/radio.xml
android/device/softwinner/common/sepolicy/vendor/rild.te
android/vendor/aw/public/prebuild/lib/librild/radio_common.mk
android/vendor/aw/public/prebuild/lib/librild/lib/lib32/libquectel-ril.so
android/vendor/aw/public/prebuild/lib/librild/lib/lib64/libquectel-ril.so

驱动类型

  • GobiNet Driver

    会生成 /dev/qcqmiX 设备节点和虚拟的 ethX 网卡(2.6.39 以下版本为 usbX)。

    内核配置驱动文件
    CONFIG_USB_NET_DRIVERS
    CONFIG_USB_USBNET
    linux-4.9/drivers/net/usb/GobiNet/GobiUSBNet.c
    linux-4.9/drivers/net/usb/GobiNet/QMIDevice.c
    linux-4.9/drivers/net/usb/GobiNet/QMI.c
  • qmi_wwan_q Driver

    会生成 /dev/cdc-wdmX 设备节点和虚拟的 wwanX 网卡。

    内核配置驱动文件
    CONFIG_USB_NET_DRIVERS
    CONFIG_USB_USBNET
    CONFIG_USB_NET_QMI_WWAN
    CONFIG_USB_WDM
    linux-4.9/drivers/net/usb/qmi_wwan.c
    linux-4.9/drivers/net/usb/qmi_wwan_q.c
  • ACM/ECM/RNDIS/NCM/MBIM Driver

    会生成 /dev/ttyUSB0 ~ /dev/ttyUSB6 和虚拟的 usbX 网卡。

    驱动类型内核配置驱动文件
    ACMCONFIG_USB_ACMlinux-4.9/drivers/usb/serial/option.c
    linux-4.9/drivers/usb/serial/usb_wwan.c
    linux-4.9/drivers/net/usb/cdc-acm.c
    ECMCONFIG_USB_NET_DRIVERS
    CONFIG_USB_USBNET
    CONFIG_USB_NET_CDCETHER
    linux-4.9/drivers/usb/serial/option.c
    linux-4.9/drivers/usb/serial/usb_wwan.c
    linux-4.9/drivers/net/usb/cdc-ether.c
    RNDISCONFIG_USB_NET_DRIVERS
    CONFIG_USB_USBNET
    CONFIG_USB_NET_CDCETHER
    linux-4.9/drivers/usb/serial/option.c
    linux-4.9/drivers/usb/serial/usb_wwan.c
    linux-4.9/drivers/net/usb/rndis_host.c
    NCMCONFIG_USB_NET_DRIVERS
    CONFIG_USB_USBNET
    CONFIG_USB_NET_CDCETHER
    linux-4.9/drivers/usb/serial/option.c
    linux-4.9/drivers/usb/serial/usb_wwan.c
    linux-4.9/drivers/net/usb/cdc_ncm.c
    MBIMCONFIG_USB_NET_DRIVERS
    CONFIG_USB_USBNET
    CONFIG_USB_NET_CDCETHER
    linux-4.9/drivers/usb/serial/option.c
    linux-4.9/drivers/usb/serial/usb_wwan.c
    linux-4.9/drivers/net/usb/cdc_mbim.c

驱动适配

这里使用 ECM 的驱动方式,参考《Quectel_UMTS_LTE_5G_Linux_USB_Driver_User_Guide_V3.0.pdf》

驱动移植

未涉及到电源控制,调试时使用的是开发板,手动给模组开机,因此下列会缺少电源控制的步骤。

  • 涉及文件列表

    // 需要修改的内核配置
    longan/kernel/linux-4.9/.config
    

// 需要修改的驱动文件
longan/kernel/linux-4.9/drivers/usb/serial/option.c
longan/kernel/linux-4.9/drivers/usb/serial/usb_wwan.c

// 需要用到的驱动文件
longan/kernel/linux-4.9/drivers/net/usb/cdc-acm.c
longan/kernel/linux-4.9/drivers/net/usb/cdc-ether.c

在 option_ids 列表内增加 EC200U-CN 的 PID\VID, 这样才能识别到该 USB 设备为串口设备,文档内可查。

// linux-4.9/drivers/usb/serial/option.c
static const struct usb_device_id option_ids[] = {
#ifdef SUPPORT_QUECTEL
	{ USB_DEVICE(0x2C7C, 0x0901) }, // support EC200U/EG915U
#endif
    ......
}
一个 USB 设备可以有多个功能不同的接口,在 option_ids 添加该设备的 PID\VID 后,会导致该设备的所有接口都会绑定到 USB Serial Option 驱动上,导致 USBNet 驱动接口无法正常工作,因此需要在 option_probe 中根据类码、接口索引、端点数量、子类码将 USBNet 的接口排除出来。 
// linux-4.9/drivers/usb/serial/option.c
static int option_probe(struct usb_serial *serial, const struct usb_device_id *id)
{
	......	
#ifdef SUPPORT_QUECTEL 
	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;
		}
	}
	#ifdef SUPPORT_QUECTEL_AUTO_SUSPEND
	//For USB Auto Suspend
	if (serial->dev->descriptor.idVendor == cpu_to_le16(0x2C7C)) {
		pm_runtime_set_autosuspend_delay(&serial->dev->dev, 3000);
		usb_enable_autosuspend(serial->dev);
	}
	#endif 
	#ifdef SUPPORT_QUECTEL_REMOTE_WAKEUP
	//For USB Remote Wakeup
	if (serial->dev->descriptor.idVendor == cpu_to_le16(0x2C7C)) {
		device_init_wakeup(&serial->dev->dev, 1); //usb remote wakeup
	}
	#endif
#endif
	/* Store the device flags so we can use them during attach. */
	usb_set_serial_data(serial, (void *)device_flags);
	return 0;
}

  
  

    +#define SUPPORT_QUECTEL 1
    +
    /*

    • Generate DTR/RTS signals on the port using the SET_CONTROL_LINE_STATE request
    • in CDC ACM.
      @@ -504,6 +506,14 @@ static struct urb *usb_wwan_setup_urb(struct usb_serial_port *port,
      usb_fill_bulk_urb(urb, serial->dev,
      usb_sndbulkpipe(serial->dev, endpoint) | dir,
      buf, len, callback, ctx);

    +#ifdef SUPPORT_QUECTEL

    •   if (dir == USB_DIR_OUT) {
      
    •           struct usb_device_descriptor *desc = &serial->dev->descriptor;
      
    •           if (desc->idVendor == cpu_to_le16(0x2C7C))
      
    •                   urb->transfer_flags |= URB_ZERO_PACKET;
      
    •   }
      

    +#endif

        return urb;
    

    }

      3G Data Card Packages

      PRODUCT_PACKAGES += \

      •   android.hardware.radio@1.4 \
        
      •   android.hardware.radio@1.0 \
          android.hardware.radio.config@1.1-service \
          android.hardware.radio.config@1.1 \
          pppd_vendor \
        

      修改 hidl 使用 radio 1.0 版本

      diff --git a/android/hardware/ril/rild/radio.xml b/android/hardware/ril/rild/radio.xml
      old mode 100644
      new mode 100755
      index 866b401..885b150
      --- a/android/hardware/ril/rild/radio.xml
      +++ b/android/hardware/ril/rild/radio.xml
      @@ -1,12 +1,11 @@
       <manifest version="1.0" type="device" target-level="4">
      -    <hal format="hidl">
      -        <name>android.hardware.radio</name>
      -        <transport>hwbinder</transport>
      -        <version>1.4</version>
      -        <interface>
      -            <name>IRadio</name>
      -            <instance>slot1</instance>
      -        </interface>
      -        <fqname>@1.2::ISap/slot1</fqname>
      -    </hal>
      +       <hal format="hidl">
      +               <name>android.hardware.radio</name>
      +               <transport>hwbinder</transport>
      +               <version>1.0</version>
      +               <interface>
      +                       <name>IRadio</name>
      +                       <instance>slot1</instance>
      +               </interface>
      +       </hal>
       </manifest>
      
       
       

        allow rild vendor_toolbox_exec:file execute_no_trans;
        allow rild vendor_shell_exec:file execute_no_trans;

          lo Link encap:Local Loopback
          inet addr:127.0.0.1 Mask:255.0.0.0
          inet6 addr: ::1/128 Scope: Host
          UP LOOPBACK RUNNING MTU:65536 Metric:1
          RX packets:16 errors:0 dropped:0 overruns:0 frame:0
          TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1
          RX bytes:1920 TX bytes:1920

          eth0 Link encap:Ethernet HWaddr 36:c9:e3:f1:b8:05 Driver sunxi-gmac
          UP BROADCAST MULTICAST MTU:1500 Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 TX bytes:168
          Interrupt:65

          usb0 Link encap:Ethernet HWaddr 02:4b:b3:b9:eb:e5 Driver cdc_ether
          inet addr:10.209.124.163 Bcast:10.209.124.255 Mask:255.255.255.0
          inet6 addr: fe80::4b:b3ff:feb9:ebe5/64 Scope: Link
          UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
          RX packets:123 errors:0 dropped:0 overruns:0 frame:0
          TX packets:175 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:20877 TX bytes:23570

          • 查看是否能正常 ping 通外网:

            mercury-demo:/ # ping www.qq.com
            ping www.qq.com
            PING ins-r23tsuuf.ias.tencent-cloud.net (101.91.22.57) 56(84) bytes of data.
            64 bytes from 101.91.22.57: icmp_seq=1 ttl=48 time=63.5 ms
            64 bytes from 101.91.22.57: icmp_seq=2 ttl=48 time=55.8 ms
            64 bytes from 101.91.22.57: icmp_seq=3 ttl=48 time=55.1 ms
            64 bytes from 101.91.22.57: icmp_seq=4 ttl=48 time=55.8 ms
            64 bytes from 101.91.22.57: icmp_seq=5 ttl=48 time=54.9 ms
            64 bytes from 101.91.22.57: icmp_seq=6 ttl=48 time=62.9 ms
            64 bytes from 101.91.22.57: icmp_seq=7 ttl=48 time=54.8 ms
            64 bytes from 101.91.22.57: icmp_seq=8 ttl=48 time=55.4 ms
            64 bytes from 101.91.22.57: icmp_seq=9 ttl=48 time=54.8 ms
            
               
               
            • 调试技巧

              模组测试

              可以先将模组接到 PC 端,使用串口手动下发 AT 指令测试,确定模组可以正常使用。

              AT +CPIN?
              CPIN: READY
              

          OK
          AT+QNWINFO
          +QNWINFO:“FDD LTE”,“46011”,“LTE BAND 1”,100

          OK
          AT+COPS?
          +COPS: 0,0,“CHN-CT”,7

          OK
          AT+QIACT=1
          OK
          AT+QIACT?
          +QIACT: 1,1,1,“10.193.145.135”

          OK
          AT+QPING=1,“www.baidu.com”
          OK
          +QPING: 0,“101.91.22.57”,32,78,255
          +QPING: 0,“101.91.22.57”,32,83,255
          +QPING: 0,“101.91.22.57”,32,80,255

          • 日志提取

            启动日志保存,在 data 目录下创建 quectel_debug_log 目录,libquectel-ril.so 会自动生成日志文件。

            mkdir /data/quectel_debug_log
            
               
               
            • 1
            mercury-demo:/data/quectel_debug_log $ ls -l
            -rw-r--r-- 1 Administrator 197121 788266 1230 22:10 1229_144251_logcat.txt
            -rw-r--r-- 1 Administrator 197121  37788 1230 22:10 1229_144251_radio.txt
            -rw-r--r-- 1 Administrator 197121  87888 1230 22:10 1229_144251_usbmonlog.txt
            -rw-r--r-- 1 Administrator 197121  77156 1230 22:10 1229_144316_dmesg_mainLoop.txt
            
               
               
            评论
            添加红包

            请填写红包祝福语或标题

            红包个数最小为10个

            红包金额最低5元

            当前余额3.43前往充值 >
            需支付:10.00
            成就一亿技术人!
            领取后你会自动成为博主和红包主的粉丝 规则
            hope_wisdom
            发出的红包
            实付
            使用余额支付
            点击重新获取
            扫码支付
            钱包余额 0

            抵扣说明:

            1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
            2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

            余额充值