一、搭建平台
1)平台:Win7 + VMware15 + Ubuntu16.04(64) + Hi3516A
2)4G模块:华为ME909s-821
3)交叉工具链:arm-hisiv300-linux-
4)说明:最近工作中用到华为 ME909s-821 模块在海思上实现拨号上网,特此记录。
二、编译 SDK
1)SDK版本:
Hi3516A_SDK_V1.0.7.0.tgz。之前写过在 Ubuntu12.04 版本上进行编译,没有出现什么错误。但是本次在 Ubuntu16.04 上 编译出现了几个问题。
2)问题一:
解决办法:修改 /usr/include/netdb.h 文件,将有 __USE_XOPEN2K 宏的行注释,注意 #ifdef 和 #endif 对应。 如下所示:
3)问题二:
解决办法:将 mkfs.jffs2 文件拷贝到 osdrv/pub/bin/pic 目录,并且修改 osdrv 目录下的 Makefile 文件。如下所示:
root@ubuntu:~/Hi3516A_SDK_V1.0.7.0/osdrv# cd tools/pc/jffs2_tool/tmp/mtd-utils-1.5.0/
root@ubuntu:~/Hi3516A_SDK_V1.0.7.0/osdrv/tools/pc/jffs2_tool/tmp/mtd-utils-1.5.0# ls
common.mk COPYING flashcp flash_otp_dump flash_unlock.o jffs2dump.o mcast_image.h nanddump nftldump.c recv_image.o summary.h
compr.c device_table.txt flashcp.c flash_otp_dump.c ftl_check jffs2reader mkfs.jffs2 nanddump.c nftldump.o rfddump sumtool
compr.h docfdisk flashcp.o flash_otp_dump.o ftl_check.c jffs2reader.c mkfs.jffs2.1 nanddump.o nftl_format rfddump.c sumtool.c
compr_lzo.c docfdisk.c flash_erase flash_otp_info ftl_check.o jffs2reader.o mkfs.jffs2.c nandtest nftl_format.c rfddump.o sumtool.o
compr_lzo.o docfdisk.o flash_eraseall flash_otp_info.c ftl_format jffs-dump.c mkfs.jffs2.o nandtest.c nftl_format.o rfdformat tar
compr.o doc_loadbios flash_erase.c flash_otp_info.o ftl_format.c lib mkfs.ubifs nandtest.o rbtree.c rfdformat.c tests
compr_rtime.c doc_loadbios.c flash_erase.o flash_otp_lock.c ftl_format.o load_nandsim.sh mtd_debug nandwrite rbtree.h rfdformat.o ubi-utils
compr_rtime.o doc_loadbios.o flash_lock flash_otp_write.c include make_a_release.sh mtd_debug.c nandwrite.c rbtree.o serve_image
compr_zlib.c feature-removal-schedule.txt flash_lock.c flash_unlock jffs2dump MAKEDEV mtd_debug.o nandwrite.o recv_image serve_image.c
compr_zlib.o fectest.c flash_lock.o flash_unlock.c jffs2dump.c Makefile mtd-utils.spec nftldump recv_image.c serve_image.o
root@ubuntu:~/Hi3516A_SDK_V1.0.7.0/osdrv/tools/pc/jffs2_tool/tmp/mtd-utils-1.5.0# cp ./mkfs.jffs2 ./../../../../../pub/bin/pc/
root@ubuntu:~/Hi3516A_SDK_V1.0.7.0/osdrv/tools/pc/jffs2_tool/tmp/mtd-utils-1.5.0# ls ./../../../../../pub/bin/pc/
mkfs.jffs2 mkyaffs2image400
root@ubuntu:~/Hi3516A_SDK_V1.0.7.0/osdrv/tools/pc/jffs2_tool/tmp/mtd-utils-1.5.0#
4)问题三:
In file included from ./common/common-utils.h:23:0,
from defs.h:564,
from gdb.c:19:
../bfd/config.h:7:4: error: #error config.h must be #included before system headers
# error config.h must be #included before system headers
^
../bfd/config.h:267:0: warning: "PACKAGE" redefined [enabled by default]
#define PACKAGE "bfd"
说明:前两个问题解决之后重新编译 SDK 就会出现这个问题,目前这个问题暂时未能解决,但是这个并不影响我们编译 uboot.bin 、uImage 以及 rootfs。所以暂时不管。
5)单独编译 uboot.bin
进入 uboot 目录 Hi3516A_SDK_V1.0.7.0/osdrv/opensource/uboot/u-boot-2010.06
make ARCH=arm CROSS_COMPILE=arm-hisiv300-linux- hi3516a_config
make ARCH=arm CROSS_COMPILE=arm-hisiv300-linux-
将生成的u-boot.bin 复制到osdrv/tools/pc/uboot_tools/目录下
运行./mkboot.sh reg_info.bin u-boot_hi3516a.bin
生成的u-boot_hi3516a.bin即为可用的u-boot镜像
这样的方式有个缺陷,需要在 uboot 启动之后设置启动参数,否则无法启动内核
解决方式一:启动 uboot 之后在命令行输入一下信息,保存退出即可
setenv bootargs 'mem=256M console=ttyAMA0,115200 root=/dev/mtdblock2 rootfstype=jffs2 rw mtdparts=hi_sfc:1M(boot),3M(kernel),12M(rootfs)'
setenv bootcmd 'sf probe 0;sf read 0x82000000 0x100000 0x300000;bootm 0x82000000'
sa
解决方式二:直接在编译 uboot 之前设置启动参数
进入 Hi3516A_SDK_V1.0.7.0/osdrv/opensource/uboot/u-boot-2010.06/include/configs 目录
root@ubuntu:~/Hi3516A_SDK_V1.0.7.0/osdrv/opensource/uboot/u-boot-2010.06/include/configs# ls hi3516*.h
hi3516a.h hi3516a_spinand.h hi3516c.h hi3516cv200.h hi3516cv300.h
当前编译的是 hi3516a 型号,所以修改 hi3516a.h 文件
/*-----------------------------------------------------------------------
* Environment Configuration
*-----------------------------------------------------------------------*/
这一行 #define CONFIG_BOOTCOMMAND "sf probe 0;sf read 0x82000000 0x100000 0x300000;bootm 0x82000000"
这一行 #define CONFIG_BOOTARGS "mem=256M console=ttyAMA0,115200 root=/dev/mtdblock2 rootfstype=jffs2 rw mtdparts=hi_sfc:1M(boot),3M(kernel),12M(rootfs)"
//#define CONFIG_BOOTCOMMAND "bootm 0x82000000"
#define CONFIG_BOOTDELAY 1
//#define CONFIG_BOOTARGS "mem=96M console=ttyAMA0,115200"
#define CONFIG_NETMASK 255.255.255.0 /* talk on MY local net */
#define CONFIG_IPADDR 192.168.1.10 /* static IP I currently own */
#define CONFIG_SERVERIP 192.168.1.2 /* current IP of tftp server ip */
#define CONFIG_ETHADDR 00:00:23:34:45:66
#define CONFIG_BOOTFILE "uImage" /* file to load */
#define CONFIG_BAUDRATE 115200
6)单独编译 uImage
因为要编译出支持 4G 模块拨号上网的功能,所以需要在内核中增加相应模块,具体如下:
进入 Hi3516A_SDK_V1.0.7.0/osdrv/opensource/kernel/linux-3.4.y 目录
编译内核命令三部曲如下:
cp arch/arm/configs/hi3516a_full_defconfig .config
make ARCH=arm CROSS_COMPILE=arm-hisiv300-linux- menuconfig
make ARCH=arm CROSS_COMPILE=arm-hisiv300-linux- uImage
增加 ME909s-821 模块驱动功能 ,执行 menuconfig 命令之后
保存退出之后编译 uImage ,成功之后在 arch/arm/boot/uImage 。
7)制作 rootfs
进入 Hi3516A_SDK_V1.0.7.0/osdrv/pub 目录
root@ubuntu:~/Hi3516A_SDK_V1.0.7.0/osdrv/pub# ls
bin image_uclibc rootfs_uclibc_hi3516a
root@ubuntu:~/Hi3516A_SDK_V1.0.7.0/osdrv/pub# ./bin/pc/mkfs.jffs2 -d ./rootfs_uclibc_hi3516a/ -l -e 0x10000 -o ./rootfs_hi3516a_64k.jffs2
root@ubuntu:~/Hi3516A_SDK_V1.0.7.0/osdrv/pub# ls
bin image_uclibc rootfs_hi3516a_64k.jffs2 rootfs_uclibc_hi3516a
root@ubuntu:~/Hi3516A_SDK_V1.0.7.0/osdrv/pub#
这样就可以得到 u-boot_hi3516a.bin \ uImage \ rootfs_hi3516a_64k.jffs2 三个文件,将其烧写到 Hi3516A 板子即可
三、拨号上网
1)交叉编译 pppd 拨号工具
tar -zxvf ppp-2.4.7.tar.gz
cd ppp-2.4.7
mkdir ppp_install
./configure -prefix=$PWD/ppp_install
make CC=arm-hisiv300-linux-gcc -j 20
出现以下错误提示:
arm-hisiv300-linux-gcc -o radattr.so -shared radattr.o
sendserver.c:493:17: error: ‘_PATH_DEV_URANDOM’ undeclared (first use in this function)
if ((fd = open(_PATH_DEV_URANDOM, O_RDONLY)) >= 0)
^
sendserver.c:493:17: note: each undeclared identifier is reported only once for each function it appears in
<builtin>: recipe for target 'sendserver.o' failed
make[2]: *** [sendserver.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: Leaving directory '/home/work/ppp/ppp-2.4.7/pppd/plugins/radius'
Makefile:30: recipe for target 'all' failed
make[1]: *** [all] Error 2
make[1]: Leaving directory '/home/work/ppp/ppp-2.4.7/pppd/plugins'
Makefile:13: recipe for target 'all' failed
make: *** [all] Error 2
根据上述文件提示的错误文件以及行号,解决办法如下:
root@ubuntu:~/ppp/ppp-2.4.7# find . -name sendserver.c
./pppd/plugins/radius/sendserver.c
root@ubuntu:~/ppp/ppp-2.4.7# vim ./pppd/plugins/radius/sendserver.c
482 #define _PATH_DEV_URANDOM "/dev/urandom" 增加这一句
483
484 static void rc_random_vector (unsigned char *vector)
485 {
486 int randno;
487 int i;
488 int fd;
489
490 /* well, I added this to increase the security for user passwords.
491 we use /dev/urandom here, as /dev/random might block and we don't
492 need that much randomness. BTW, great idea, Ted! -lf, 03/18/95 */
493
494 if ((fd = open(_PATH_DEV_URANDOM, O_RDONLY)) >= 0)
495 {
重新 make CC=arm-hisiv300-linux-gcc -j 20 即可。
将 chat 目录下的 chat 文件拷贝出来
将 pppd 目录下的 pppd 文件拷贝出来
2)拨号上网
2.1)查看开发板信息,大致有如下信息
option 1-1.1:2.2: GSM modem (1-port) converter detected
usb 1-1.1: GSM modem (1-port) converter now attached to ttyUSB0
option 1-1.1:2.3: GSM modem (1-port) converter detected
usb 1-1.1: GSM modem (1-port) converter now attached to ttyUSB1
option 1-1.1:2.4: GSM modem (1-port) converter detected
usb 1-1.1: GSM modem (1-port) converter now attached to ttyUSB2
option 1-1.1:2.5: GSM modem (1-port) converter detected
usb 1-1.1: GSM modem (1-port) converter now attached to ttyUSB3
option 1-1.1:2.6: GSM modem (1-port) converter detected
usb 1-1.1: GSM modem (1-port) converter now attached to ttyUSB4
2.2)将交叉编译好的 pppd 拨号工具 chat 和 pppd 两个文件下载到开发板 /usr/sbin 目录下,并且增加执行权限
2.3)将上网拨号脚本下载到开发板 /etc/ppp/peers/ 目录下,并且增加执行权限。前面制作文件系统时已将其放入其中。
ppp-on \ ppp-off \ wcmda-huawei \ wcmda-chat-connect 四个文件。
2.4)开始拨号,在开发板执行:/etc/ppp/peers/ppp-on ,拨号成功信息如下
~ # /etc/ppp/peers/ppp-on
find /dev/ttyUSB0 dev
~ # timeout set to 1800 seconds
abort on (NO CARRIER)
abort on (ERROR)
abort on (NODIALTONE)
abort on (BUSY)
abort on (NO ANSWER)
send (^MAT^M)
expect (OK)
^M
^M
^M
^M
^MAT^M^M
OK
-- got it
send (^MATZ^M)
expect (OK)
^M
^MATZ^M^M
OK
-- got it
send (^MAT+CGDCONT=1,"IP","3gnet","",0,0^M)
expect (OK)
^M
^MAT+CGDCONT=1,"IP","3gnet","",0,0^M^M
OK
-- got it
send (ATDT*99#^M)
expect (CONNECT)
^M
ATDT*99#^M^M
CONNECT
-- got it
send (\d)
Script /usr/sbin/chat -s -v -f /etc/ppp/peers/wcdma-chat-connect finished (pid 951), status = 0x0
Serial connection established.
using channel 1
Using interface ppp0
Connect: ppp0 <--> /dev/ttyUSB0
sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0x565c9aa> <pcomp> <accomp>]
rcvd [LCP ConfReq id=0x1 <accomp> <pcomp> <asyncmap 0x0> <mru 1500> <magic 0x543> <auth chap MD5>]
No auth is possible
sent [LCP ConfRej id=0x1 <auth chap MD5>]
rcvd [LCP ConfAck id=0x1 <asyncmap 0x0> <magic 0x565c9aa> <pcomp> <accomp>]
rcvd [LCP ConfReq id=0x2 <accomp> <pcomp> <asyncmap 0x0> <mru 1500> <magic 0x543>]
sent [LCP ConfAck id=0x2 <accomp> <pcomp> <asyncmap 0x0> <mru 1500> <magic 0x543>]
sent [IPCP ConfReq id=0x1 <addr 0.0.0.0> <ms-dns1 0.0.0.0> <ms-dns2 0.0.0.0>]
rcvd [IPCP ConfReq id=0x1]
sent [IPCP ConfNak id=0x1 <addr 0.0.0.0>]
rcvd [IPCP ConfNak id=0x1]
sent [IPCP ConfReq id=0x2 <addr 0.0.0.0> <ms-dns1 0.0.0.0> <ms-dns2 0.0.0.0>]
rcvd [IPCP ConfReq id=0x2]
sent [IPCP ConfAck id=0x2]
rcvd [IPCP ConfNak id=0x2 <addr 10.30.143.210> <ms-dns1 202.96.128.86> <ms-dns2 202.96.134.133>]
sent [IPCP ConfReq id=0x3 <addr 10.30.143.210> <ms-dns1 202.96.128.86> <ms-dns2 202.96.134.133>]
rcvd [IPCP ConfAck id=0x3 <addr 10.30.143.210> <ms-dns1 202.96.128.86> <ms-dns2 202.96.134.133>]
Could not determine remote IP address: defaulting to 10.64.64.64
local IP address 10.30.143.210
remote IP address 10.64.64.64
primary DNS address 202.96.128.86
secondary DNS address 202.96.134.133
使用 ps 查看会有一个拨号进程存在
~ # ps
PID USER TIME COMMAND
1 root 0:01 init
2 root 0:00 [kthreadd]
3 root 0:00 [ksoftirqd/0]
4 root 0:00 [kworker/0:0]
5 root 1:19 [kworker/u:0]
6 root 0:00 [khelper]
7 root 0:00 [kworker/u:1]
144 root 0:00 [sync_supers]
146 root 0:00 [bdi-default]
147 root 0:00 [kintegrityd]
149 root 0:00 [kblockd]
158 root 0:00 [spi0]
161 root 0:00 [spi1]
169 root 0:00 [khubd]
171 root 0:00 [kusbotg]
260 root 0:00 [rpciod]
262 root 0:00 [kworker/0:1]
267 root 0:00 [kswapd0]
317 root 0:00 [fsnotify_mark]
335 root 0:00 [nfsiod]
351 root 0:00 [xfsalloc]
352 root 0:00 [xfs_mru_cache]
353 root 0:00 [xfslogd]
421 root 0:00 [romblock0]
424 root 0:00 [mtdblock0]
429 root 0:00 [romblock1]
432 root 0:00 [mtdblock1]
437 root 0:00 [romblock2]
440 root 0:00 [mtdblock2]
578 root 0:00 [kpsmoused]
592 root 0:00 [cfinteractive]
597 root 0:00 [kworker/u:2]
610 root 0:00 [deferwq]
611 root 0:03 [jffs2_gcd_mtd2]
625 root 0:00 udevd --daemon
712 root 0:00 udevd --daemon
715 root 0:00 udevd --daemon
764 root 0:00 [kworker/u:3]
941 root 0:00 -sh
948 root 0:00 pppd call wcdma-huawei 这个
955 root 0:00 [flush-mtd-unmap]
956 root 0:00 ps
直接 ping 百度失败
~ # ping www.baidu.com
ping: bad address 'www.baidu.com'
原因是缺少 DNS 地址,所以需要在 /etc 目录下增加一个 resolv.conf 文件,里面写入对应的 DNS 地址。刚好在拨号的时候在 /etc/ppp/ 目录下生成了一个 resolv.conf 文件,将其拷贝到 /etc 目录即可,再次 ping 百度如下:
~ # ping www.baidu.com
PING www.baidu.com (14.215.177.39): 56 data bytes
64 bytes from 14.215.177.39: seq=0 ttl=54 time=21.753 ms
64 bytes from 14.215.177.39: seq=1 ttl=54 time=21.102 ms
64 bytes from 14.215.177.39: seq=2 ttl=54 time=22.541 ms
64 bytes from 14.215.177.39: seq=3 ttl=54 time=21.520 ms
64 bytes from 14.215.177.39: seq=4 ttl=54 time=32.680 ms
3)注意事项:
不要增加别的网卡的网关,否则 ping 不同外网。如果别的网卡网关已经存在,可以执行 route del default 命令
~ # route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default * 0.0.0.0 U 0 0 0 ppp0
10.64.64.64 * 255.255.255.255 UH 0 0 0 ppp0
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
~ # route add default gw 192.168.1.1
~ #
~ #
~ # route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
default * 0.0.0.0 U 0 0 0 ppp0
10.64.64.64 * 255.255.255.255 UH 0 0 0 ppp0
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
~ # ping www.baidu.com
有其他网关的情况下去掉别的网关
~ # route del default
~ # route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default * 0.0.0.0 U 0 0 0 ppp0
10.64.64.64 * 255.255.255.255 UH 0 0 0 ppp0
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
~ # ping www.baidu.com
PING www.baidu.com (14.215.177.38): 56 data bytes
64 bytes from 14.215.177.38: seq=0 ttl=54 time=29.635 ms
64 bytes from 14.215.177.38: seq=1 ttl=54 time=29.894 ms
4)相关资料
4.1)可以参考 2、ubuntu16.06安装Hi3518EV200 SDK - Ocean&Star - 博客园
4.2)百度网盘链接:百度网盘 请输入提取码 提取码:x28p