Cubieboard2使用小米wifi

下载MT7601U驱动和linux-sunxi源码


$ git clone https://github.com/jfojfo/MT7601U.git

common/rtusb_dev_id.c文件修改如下:

#ifdef MT7601U
{USB_DEVICE(0x148f,0x6370)}, / Ralink 6370 /
{USB_DEVICE(0x2955,0x1001)}, / xiaodu wifi /
{USB_DEVICE(0x148f,0x7601)}, / MT 6370 /
{USB_DEVICE(0x148f,0x760b)}, / 360 wifi 2 /
{USB_DEVICE(0x2717,0x4106)}, / XiaoMi wifi /
#endif / MT7601U /

或者下面git库(支持AP模式)
$ git clone https://github.com/jfojfo/MT7601U-1.git

该驱动源码已经加入了xiaomi wifi支持
修改Makefile,在export LINUX_SRC CROSS_COMPILE之前添加:
# add following 2 lines
LINUX_SRC=../linux-sunxi
CROSS_COMPILE=arm-linux-gnueabihf-

export OSABL RT28xx_DIR RT28xx_MODE LINUX_SRC CROSS_COMPILE CROSS_COMPILE_INCLUDE PLATFORM RELEASE CHIPSET MODULE RTMP_SRC_DIR LINUX_SRC_MODULE TARGET HAS_WOW_SUPPORT

# The targets that may be used.
PHONY += all build_tools test UCOS THREADX LINUX release prerelease clean uninstall install libwapi osabl

下载linux-sunxi
$ git clone -b cubie/sunxi-3.4.91 https://github.com/jfojfo/linux-sunxi.git

linux kernel环境准备


产生.config文件、fixdep script工具
$ cd linux-sunxi
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- cubieboard2_defconfig
HOSTCC scripts/basic/fixdep
HOSTCC scripts/kconfig/conf.o
HOSTCC scripts/kconfig/zconf.tab.o
HOSTLD scripts/kconfig/conf
drivers/net/wireless/bcmdhd/Kconfig:42:warning: defaults for choice values not supported
#
# configuration written to .config
#


生成generated的头文件和version.h
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- prepare
scripts/kconfig/conf –silentoldconfig Kconfig
drivers/net/wireless/bcmdhd/Kconfig:42:warning: defaults for choice values not supported
WRAP arch/arm/include/generated/asm/auxvec.h
WRAP arch/arm/include/generated/asm/bitsperlong.h
WRAP arch/arm/include/generated/asm/cputime.h
WRAP arch/arm/include/generated/asm/emergency-restart.h
WRAP arch/arm/include/generated/asm/errno.h
WRAP arch/arm/include/generated/asm/ioctl.h
WRAP arch/arm/include/generated/asm/irq_regs.h
WRAP arch/arm/include/generated/asm/kdebug.h
WRAP arch/arm/include/generated/asm/local.h
WRAP arch/arm/include/generated/asm/local64.h
WRAP arch/arm/include/generated/asm/percpu.h
WRAP arch/arm/include/generated/asm/poll.h
WRAP arch/arm/include/generated/asm/resource.h
WRAP arch/arm/include/generated/asm/sections.h
WRAP arch/arm/include/generated/asm/siginfo.h
WRAP arch/arm/include/generated/asm/sizes.h
CHK include/linux/version.h
UPD include/linux/version.h
CHK include/generated/utsrelease.h
UPD include/generated/utsrelease.h
Generating include/generated/mach-types.h
CC kernel/bounds.s
GEN include/generated/bounds.h
CC arch/arm/kernel/asm-offsets.s
GEN include/generated/asm-offsets.h
CALL scripts/checksyscalls.sh


产生scripts工具,如genksyms
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- scripts
HOSTCC scripts/genksyms/genksyms.o
HOSTCC scripts/genksyms/lex.lex.o
HOSTCC scripts/genksyms/parse.tab.o
HOSTLD scripts/genksyms/genksyms
CC scripts/mod/empty.o
HOSTCC scripts/mod/mk_elfconfig
MKELF scripts/mod/elfconfig.h
HOSTCC scripts/mod/file2alias.o
HOSTCC scripts/mod/modpost.o
HOSTCC scripts/mod/sumversion.o
HOSTLD scripts/mod/modpost
HOSTCC scripts/selinux/genheaders/genheaders
HOSTCC scripts/selinux/mdp/mdp
HOSTCC scripts/kallsyms
HOSTCC scripts/conmakehash
HOSTCC scripts/bin2c



注:
前面的make prepare 和make scripts两步也可以用下面代替
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- modules_prepare


编译驱动

$ cd ../
$ cd MT7601U
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-
产生驱动os/linux/mt7601Usta.ko 将mt7601Usta.ko拷贝至cubieboard2的/lib/modules/3.4.91/kernel/net/wireless/目录,并运行depmod 将RT2870STA.dat拷贝至/etc/Wireless/RT2870STA/目录 以后插入小米wifi就会自动加载驱动 编译过程中会产生warning,Module.symvers is missing; modules will have no dependencies and modversions. 需要build linux-sunxi的内核和驱动(参考:Cubieboard2 A20 SD卡启动及根文件系统制作) 运行如下命令产生Module.symvers文件
$ scripts/mod/modpost -o /home/yihect/linux-2.6.31/Module.symvers -S -c vmlinux.o

如果碰到因为把warning当做error而失败的情况,可以在Makefile开头处添加一行:

export KCFLAGS = -w
禁止将warning当成error处理

配置DMA大小

前面编译出来驱动,insmod时会发现出错,报DMA内存不足,cubieboard2中默认使用256k,需要修改成1M以上
--> RTMPAllocTxRxRingMemory
ERROR: 256 KiB atomic DMA coherent pool is too small!
Please increase it with coherent_pool= kernel parameter!
修改boot.cmd,在setenv一行最后添加 coherent_pool=6M,重新烧写SD卡后启动就可以正常使用了
setenv bootargs console=ttyS0,115200 noinitrd disp.screen0_output_mode=EDID:1280x1024p60 init=/sbin/init root=/dev/mmcblk0p2 rootfstype=ext4 rootwait panic=10 coherent_pool=6M
fatload mmc 0 0x43000000 boot/script.bin
fatload mmc 0 0x48000000 boot/uImage
bootm 0x48000000

在Cubieboard上配置wifi

iwconfig是针对WEP的wifi,现在wifi大部分都是wpa2的,可以用wpa_cli来设置 安装wireless-tools和wpasupplicant
# apt-get install wpasupplicant wireless-tools
# wpa_passphrase ESSID PASSWORD > xxx.conf
# wpa_supplicant -B -i ra0 -Dwext -c xxx.conf
# iwconfig ra0
# dhclient -v ra0

无线网卡就可以正常运行了

配置wifi自动启动

# wpa_passphrase ESSID PASSWORD > /etc/wpa_supplicant.conf

在/etc/network/interfaces中添加如下内容:
auto ra0
iface ra0 inet dhcp
wpa-conf /etc/wpa_supplicant.conf