1. 程式人生 > >android4.2.2除錯mu609 3G模組

android4.2.2除錯mu609 3G模組

1.修改kernel\drivers\usb\serial\option.c,新增MU609的ID號
[cpp] view plaincopyprint?
  1. #define HUAWEI_PRODUCT_E353   0x1506
#define HUAWEI_PRODUCT_E353   0x1506
[cpp] view plaincopyprint?
  1. 更新了firmware之後ID號改為:  
更新了firmware之後ID號改為:
[cpp] view plaincopyprint?
  1. #define HUAWEI_PRODUCT_E353   0x1573
#define HUAWEI_PRODUCT_E353   0x1573


2.對kernel進行配置,make menuconfig開啟以下幾項

[html] view plaincopyprint?
  1. Device Drivers -> USB support -> USB Serial Converter support -><*> USB driver for GSM and CDMA modems  
  2. Device Drivers -> Network device support -> PPP (point-to-point protocol) support -><*> PPP MPPE compression (encryption) (EXPERIMENTAL)  
  3. Device Drivers -> Network device support -> PPP (point-to-point protocol) support -><*> PPP support for async serial ports  
Device Drivers -> USB support -> USB Serial Converter support -> <*> USB driver for GSM and CDMA modems
Device Drivers -> Network device support -> PPP (point-to-point protocol) support -> <*> PPP MPPE compression (encryption) (EXPERIMENTAL)
Device Drivers -> Network device support -> PPP (point-to-point protocol) support -> <*> PPP support for async serial ports

第一個選項開啟之後開機就會識別到MU609為GSM modem,否則只會看到有USB插拔的資訊,不會識別為GSM MODEM,正確識別後的Log如下:

[html] view plaincopyprint?
  1. <6>[    1.929557] usb 3-1: new high-speed USB device number 2 using exynos-xhci  
  2. <6>[    1.949389] usb 3-1: New USB device found, idVendor=12d1idProduct=1506
  3. <6>[    1.949483] usb 3-1: New USB device strings: Mfr=3Product=2SerialNumber=0
  4. <6>[    1.949595] usb 3-1: Product: HUAWEI Mobile  
  5. <6>[    1.949645] usb 3-1: Manufacturer: Huawei Technologies  
  6. <6>[    1.949950] mmc_host mmc1: Bus speed (slot 0) = 25000000Hz (slot req 400000Hz, actual 390625HZ div = 32)  
  7. <6>[    1.956711] option 3-1:1.0: GSM modem (1-port) converter detected  
  8. <6>[    1.956911] usb 3-1: GSM modem (1-port) converter now attached to ttyUSB0  
  9. <6>[    1.957187] option 3-1:1.1: GSM modem (1-port) converter detected  
  10. <6>[    1.957353] usb 3-1: GSM modem (1-port) converter now attached to ttyUSB1  
  11. <6>[    1.957588] option 3-1:1.2: GSM modem (1-port) converter detected  
  12. <6>[    1.957729] usb 3-1: GSM modem (1-port) converter now attached to ttyUSB2  
<6>[    1.929557] usb 3-1: new high-speed USB device number 2 using exynos-xhci
<6>[    1.949389] usb 3-1: New USB device found, idVendor=12d1, idProduct=1506
<6>[    1.949483] usb 3-1: New USB device strings: Mfr=3, Product=2, SerialNumber=0
<6>[    1.949595] usb 3-1: Product: HUAWEI Mobile
<6>[    1.949645] usb 3-1: Manufacturer: Huawei Technologies
<6>[    1.949950] mmc_host mmc1: Bus speed (slot 0) = 25000000Hz (slot req 400000Hz, actual 390625HZ div = 32)
<6>[    1.956711] option 3-1:1.0: GSM modem (1-port) converter detected
<6>[    1.956911] usb 3-1: GSM modem (1-port) converter now attached to ttyUSB0
<6>[    1.957187] option 3-1:1.1: GSM modem (1-port) converter detected
<6>[    1.957353] usb 3-1: GSM modem (1-port) converter now attached to ttyUSB1
<6>[    1.957588] option 3-1:1.2: GSM modem (1-port) converter detected
<6>[    1.957729] usb 3-1: GSM modem (1-port) converter now attached to ttyUSB2

第二和第三個選項開啟之後pppd才可以建立ppp0介面,否則logcat會出現如下pppd錯誤資訊:

[plain] view plaincopyprint?
  1. Couldn't set tty to PPP discipline: Invalid argument  
Couldn't set tty to PPP discipline: Invalid argument

此時雖然rild已經執行,apn也設定好了但是仍舊無法上網,netcfg看不到ppp0介面。

3.copy libhuawei-ril.so,ip-up,ip-down到指定位置,修改device.mk,新增:

[plain] view plaincopyprint?
  1. # stone add mu609  
  2. PRODUCT_COPY_FILES += \  
  3.     $(LOCAL_PATH)/mu609/libhuawei-ril.so:system/lib/libhuawei-ril.so \  
  4.     $(LOCAL_PATH)/mu609/ip-up:system/etc/ppp/ip-up \  
  5.     $(LOCAL_PATH)/mu609/ip-down:system/etc/ppp/ip-down \  
  6.     $(LOCAL_PATH)/mu609/chat:system/bin/chat \  
  7.     $(LOCAL_PATH)/mu609/busybox:system/bin/busybox  
# stone add mu609
PRODUCT_COPY_FILES += \
    $(LOCAL_PATH)/mu609/libhuawei-ril.so:system/lib/libhuawei-ril.so \
    $(LOCAL_PATH)/mu609/ip-up:system/etc/ppp/ip-up \
    $(LOCAL_PATH)/mu609/ip-down:system/etc/ppp/ip-down \
    $(LOCAL_PATH)/mu609/chat:system/bin/chat \
    $(LOCAL_PATH)/mu609/busybox:system/bin/busybox

最後兩個chat和busybox是為了除錯方便加進去的。

4.修改android\system\core\rootdir\init.rc,新增ttyUSB許可權和ril的載入

[plain] view plaincopyprint?
  1. on boot  
  2. # stone add mu609  
  3.     chmod 777 /dev/ttyUSB0  
  4.     chmod 777 /dev/ttyUSB2  
  5.     chmod 777 /etc/ppp/ip-up  
  6.     chmod 777 /etc/ppp/ip-down  
  7. # stone modify mu609  
  8. service ril-daemon /system/bin/rild -l libhuawei-ril.so  
on boot
# stone add mu609
    chmod 777 /dev/ttyUSB0
    chmod 777 /dev/ttyUSB2
    chmod 777 /etc/ppp/ip-up
    chmod 777 /etc/ppp/ip-down

# stone modify mu609
service ril-daemon /system/bin/rild -l libhuawei-ril.so

5.修改android\hardware\ril\rild\rild.c,按照mu609 porting guide遮蔽掉switchUser();這行程式碼,如果不遮蔽掉會出現手動撥號正常,但是android下提示pppd缺少模組的情況,如下:

[plain] view plaincopyprint?
  1. E/pppd    ( 2082): This system lacks kernel support for PPP.  This could be because  
  2. E/pppd    ( 2082): the PPP kernel module could not be loaded, or because PPP was not  
  3. E/pppd    ( 2082): included in the kernel configuration.  If PPP was included as a  
  4. E/pppd    ( 2082): module, try `/sbin/modprobe -v ppp'.  If that fails, check that  
  5. E/pppd    ( 2082): ppp.o exists in /lib/modules/`uname -r`/net.  
  6. E/pppd    ( 2082): See README.linux file in the ppp distribution for more details.  
E/pppd    ( 2082): This system lacks kernel support for PPP.  This could be because
E/pppd    ( 2082): the PPP kernel module could not be loaded, or because PPP was not
E/pppd    ( 2082): included in the kernel configuration.  If PPP was included as a
E/pppd    ( 2082): module, try `/sbin/modprobe -v ppp'.  If that fails, check that
E/pppd    ( 2082): ppp.o exists in /lib/modules/`uname -r`/net.
E/pppd    ( 2082): See README.linux file in the ppp distribution for more details.

到此就已經porting完了,如果出問題了還要排查,現在從底層開始一步步排查驗證。

1.首先要確定mu609模組識別到了沒有,可以在shell下busybox lsusb檢視usb裝置,如果出現如下資訊,就是已經識別到mu609了。

[plain] view plaincopyprint?
  1. [email protected]:/ # busybox lsusb  
  2. Bus 003 Device 002: ID 12d1:1506  
[email protected]:/ # busybox lsusb
Bus 003 Device 002: ID 12d1:1506


2.檢視ttyUSB介面屬性是否修改為0777

[plain] view plaincopyprint?
  1. [email protected]:/ # ll /dev/ttyUSB*  
  2. crwxrwxrwx root     root     188,   0 2013-05-15 12:01 ttyUSB0  
  3. crw------- root     root     188,   1 2013-05-15 12:00 ttyUSB1  
  4. crwxrwxrwx root     root     188,   2 2013-05-15 12:00 ttyUSB2  
[email protected]:/ # ll /dev/ttyUSB*
crwxrwxrwx root     root     188,   0 2013-05-15 12:01 ttyUSB0
crw------- root     root     188,   1 2013-05-15 12:00 ttyUSB1
crwxrwxrwx root     root     188,   2 2013-05-15 12:00 ttyUSB2

3.模組已經識別了,ttyUSB介面都有,現在手動發AT命令看mu609是否響應。

[plain] view plaincopyprint?
  1. [email protected]:/ # cd /dev/  
  2. [email protected]:/dev # cat ttyUSB0 &                                               
  3. [1] 869  
  4. [email protected]:/dev # echo AT+CGMI > ttyUSB0                                      
  5. [email protected]:/dev #   
  6. Huawei Technologies Co., Ltd.  
  7. OK  
  8. [email protected]:/dev # echo AT+CGMM > ttyUSB0                                      
  9. [email protected]:/dev #   
  10. MU609  
  11. OK  
  12. [email protected]:/dev #   
[email protected]:/ # cd /dev/
[email protected]:/dev # cat ttyUSB0 &                                             
[1] 869
[email protected]:/dev # echo AT+CGMI > ttyUSB0                                    
[email protected]:/dev # 

Huawei Technologies Co., Ltd.



OK


[email protected]:/dev # echo AT+CGMM > ttyUSB0                                    
[email protected]:/dev # 

MU609



OK


[email protected]:/dev # 

OK,mu609正常響應了。

4.現在先拋開上層RIL不管,單純從shell手動撥號看能否正常工作。需要自己寫兩個指令碼,拷貝到/etc/ppp目錄下
第一個指令碼是/etc/ppp/chat/unicom,內容如下:

[plain] view plaincopyprint?
  1. # this is the chat script for unicom  
  2. ABORT "NO CARRIER"  
  3. ABORT "NO DIALTONE"  
  4. ABORT "ERROR"  
  5. ABORT "NO ANSWER"  
  6. ABORT "BUSY"  
  7. TIMEOUT 120  
  8. "" at  
  9. OK AT+CGDCONT=1,"IP","3gnet"  
  10. OK atdt*99***1#  
  11. CONNECT  
# this is the chat script for unicom
ABORT "NO CARRIER"
ABORT "NO DIALTONE"
ABORT "ERROR"
ABORT "NO ANSWER"
ABORT "BUSY"
TIMEOUT 120
"" at
OK AT+CGDCONT=1,"IP","3gnet"
OK atdt*99***1#
CONNECT

第二個指令碼是/etc/ppp/peers/unicom,內容如下:

[plain] view plaincopyprint?
  1. # /system/etc/ppp/peers/unicom  
  2. /dev/ttyUSB0  
  3. 115200  
  4. crtscts  
  5. connect '/system/bin/chat -s -v -f /system/etc/ppp/chat/unicom'  
  6. debug  
  7. nodetach  
  8. ipcp-accept-local  
  9. ipcp-accept-remote  
  10. defaultroute  
  11. usepeerdns  
  12. user card  
  13. password card  
# /system/etc/ppp/peers/unicom
/dev/ttyUSB0
115200
crtscts
connect '/system/bin/chat -s -v -f /system/etc/ppp/chat/unicom'
debug
nodetach
ipcp-accept-local
ipcp-accept-remote
defaultroute
usepeerdns
user card
password card

chat和peers兩個目錄沒有,需要自己mkdir。還需要用到chat,就是之前在device.mk中copy過來的,android自身不帶,在我的資源中有編譯好的。因為rild一開始就會啟動,把pppd搞起來,影響手動撥號,所以要先把rild改個名字,這樣rild服務就不會起來了

[plain] view plaincopyprint?
  1. mv /system/bin/rild /system/bin/ril-d  
mv /system/bin/rild /system/bin/ril-d

改完後記得重啟機器。好了,現在可以手動撥號了:

[plain] view plaincopyprint?
  1. [email protected]:/ # pppd call unicom &  
  2. [1] 912  
  3. [email protected]:/ # abort on (NO CARRIER)  
  4. abort on (NO DIALTONE)  
  5. abort on (ERROR)  
  6. abort on (NO ANSWER)  
  7. abort on (BUSY)  
  8. timeout set to 120 seconds  
  9. send (at^M)  
  10. expect (OK)  
  11. ^M  
  12. OK  
  13.  -- got it  
  14. send (AT+CGDCONT=1,"IP","3gnet"^M)  
  15. expect (OK)  
  16. ^M  
  17. ^M  
  18. OK  
  19.  -- got it  
  20. send (atdt*99***1#^M)  
  21. expect (CONNECT)  
  22. ^M  
  23. ^M  
  24. CONNECT  
  25.  -- got it  
  26. [email protected]:/ #  
[email protected]:/ # pppd call unicom &
[1] 912
[email protected]:/ # abort on (NO CARRIER)
abort on (NO DIALTONE)
abort on (ERROR)
abort on (NO ANSWER)
abort on (BUSY)
timeout set to 120 seconds
send (at^M)
expect (OK)
^M
OK
 -- got it

send (AT+CGDCONT=1,"IP","3gnet"^M)
expect (OK)
^M
^M
OK
 -- got it

send (atdt*99***1#^M)
expect (CONNECT)
^M
^M
CONNECT
 -- got it

[email protected]:/ #

好了,到這裡就算是撥號成功了,然後看ppp0介面是否建立。

[plain] view plaincopyprint?
  1. [email protected]:/ # netcfg  
  2. ip6tnl0  DOWN                                   0.0.0.0/0   0x00000080 00:00:00:00:00:00  
  3. lo       UP                                   127.0.0.1/8   0x00000049 00:00:00:00:00:00  
  4. ppp0     UP                              10.105.219.114/32  0x000010d1 00:00:00:00:00:00  
  5. sit0     DOWN                                   0.0.0.0/0   0x00000080 00:00:00:00:00:00  
  6. [email protected]:/ #   
[email protected]:/ # netcfg
ip6tnl0  DOWN                                   0.0.0.0/0   0x00000080 00:00:00:00:00:00
lo       UP                                   127.0.0.1/8   0x00000049 00:00:00:00:00:00
ppp0     UP                              10.105.219.114/32  0x000010d1 00:00:00:00:00:00
sit0     DOWN                                   0.0.0.0/0   0x00000080 00:00:00:00:00:00
[email protected]:/ # 

好了,ppp0介面也建立了,ip地址也獲得了,ping一下baidu試試看。

[plain] view plaincopyprint?
  1. [email protected]:/ # ping www.baidu.com     
  2. PING www.a.shifen.com (220.181.112.143) 56(84) bytes of data.  
  3. 64 bytes from 220.181.112.143: icmp_seq=1 ttl=48 time=164 ms  
  4. 64 bytes from 220.181.112.143: icmp_seq=2 ttl=48 time=172 ms  
  5. 64 bytes from 220.181.112.143: icmp_seq=3 ttl=48 time=160 ms  
  6. ^C64 bytes from 220.181.112.143: icmp_seq=4 ttl=48 time=148 ms  
  7. --- www.a.shifen.com ping statistics ---  
  8. 4 packets transmitted, 4 received, 0% packet loss, time 3005ms  
  9. rtt min/avg/max/mdev = 148.703/161.427/172.377/8.508 ms  
  10. [email protected]:/ #  
[email protected]:/ # ping www.baidu.com   
PING www.a.shifen.com (220.181.112.143) 56(84) bytes of data.
64 bytes from 220.181.112.143: icmp_seq=1 ttl=48 time=164 ms
64 bytes from 220.181.112.143: icmp_seq=2 ttl=48 time=172 ms
64 bytes from 220.181.112.143: icmp_seq=3 ttl=48 time=160 ms
^C64 bytes from 220.181.112.143: icmp_seq=4 ttl=48 time=148 ms

--- www.a.shifen.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3005ms
rtt min/avg/max/mdev = 148.703/161.427/172.377/8.508 ms
[email protected]:/ #

OK,一切正常,現在可以確定撥號沒有問題了,剩下驗證android上層ril是否工作正常了。

5.把rild的名字改回來,進入系統設定一下APN,

[plain] view plaincopyprint?
  1. APN:3gnet  
  2. MCC:460  
  3. MNC:01  
APN:3gnet
MCC:460
MNC:01

儲存,然後重啟,起來後就可以在狀態列看到3G的圖示了,當然要開啟“啟動資料網路”選項。
如果沒有工作,就"logcat -b radio &"看一下ril的log,ril是否認到ttyUSB的介面了。

除錯時候經常用到的幾個小命令。
netcfg : 檢視當前所有網路介面
getprop net.dns1 : 檢視dns(有時候dns不對也會上不了網,比如8.8.8.8,這時候需要修改pppd)
logcat -s pppd : 檢視pppd log
logcat -b radio &: 檢視radio log
cat ttyUSB0 &然後echo AT+CMD > ttyUSB0: 對modem發命令看是否有應答。