第一部分:在AR6K_GPL_SDK.2.2.1.83\host 文件夹内:
一. WIFI驱动的交叉编译简述
手头上有一sdio 接口的 WIFI 开发板,核心芯片AR6000,厂家提供 LINUX 下的驱动,但是这个
驱动是 针对 X86 平 台,针对 嵌入式 平台 要 使用交叉编译器 重新编译 驱动,
make 命令:
make ATH_BUILD_TYPE=AT91 ATH_BUS_TYPE=sdio
在文件夹下:
/opt/AT91SAM9G45/AR6K_GPL_SDK.2.2.1.83/host/.output/AT91-sdio/image
有编译结果:
ar6000.ko bmiloader eeprom.AR6002 recEvent restore.sh sdio_busdriver.ko
sdio_lib.ko wmiconfig
二. MAKEFILE 文件分析
重点是前一段说明
==============================================================================
# AR6K Host driver makefile
#
# Minimal build invocation:
#
# make (all | clean | clobber)
#
# Extended Make invocation:
#
# make ATH_BUILD_TYPE= ATH_SDIO_STACK_BASE= (all |
clean | clobber)
#
# Notes:
# 1. This makefile must be invoked from the host/ directory
# 2. The must match an entry in localmake.linux.inc.
# 3. The localmake.linux.inc can be overridden using an include file outside the build
tree.
# This file (name and path) can be set via the ATH_MAKE_INCLUDE_OVERRIDE variable.
# ** If ATH_MAKE_INCLUDE_OVERRIDE is used, you can define all build variables in that
file
# instead of using command line arguments **. This feature is provided for
developers
# that may want to customize the build using a single include file.
#
# For example :
#
# " make ATH_MAKE_INCLUDE_OVERRIDE=$HOME/mymake.inc "
#
# could be used, as long as "mymake.inc" defines all the required variables (see
below)
#
# Required Variables:
#
# ATH_OS_SUB_TYPE - on linux, this must be "linux_2_4" for 2.4 kernels or left blank
for 2.6 kernels.
# ATH_LINUXPATH - linux kernel source path
# ATH_CROSS_COMPILE_TYPE - optional cross compiler path , leave blank for local gcc
compilation
# ATH_ARCH_CPU_TYPE - CPU architecture type, leave blank for local gcc compilation
# ATH_SDIO_STACK_BASE - SDIO Stack installation path to compile the SDIO HIF layer
against an externally supplied
# SDIO stack source.
#
# Override variables:
#
# ATH_MAKE_INCLUDE_OVERRIDE - full path to include file which overrides the default
(localmake.linux.inc)
# this file can contain other overrides specific to a
developers
# workspace environment.
# ATH_BUILD_OUTPUT_OVERRIDE - output path override for compiled executable and
# database image
#
# Include local variables
ifdef ATH_MAKE_INCLUDE_OVERRIDE
_LOCALMAKE_INCLUDE = $(ATH_MAKE_INCLUDE_OVERRIDE)
else
_LOCALMAKE_INCLUDE = localmake.linux.inc
endif
-include $(_LOCALMAKE_INCLUDE)
export ATH_SRC_BASE
export ATH_BUILD_TYPE
export ATH_OS_SUB_TYPE
export ATH_LINUXPATH
export ATH_CROSS_COMPILE_TYPE
export ATH_ARCH_CPU_TYPE
export ATH_SDIO_STACK_BASE
export ATH_BUS_TYPE
export ATH_HC_DRIVERS
三. localmake.linux 修改
#
# Local Makefile includes for tool and kernel source paths
# ***** This is only a sample, modify the paths for your specific build environment *****
#
# Copyright 2004-2006 Atheros Communications, Inc.
#
# When creating a new build type, use the following template:
# ifeq ($(ATH_BUILD_TYPE),
)
# ATH_ARCH_CPU_TYPE := < cpu architecture >
# ATH_CROSS_COMPILE_TYPE := < cross compiler path >
# ATH_LINUXPATH := < kernel source path >
#
ifeq ($(ATH_BUILD_TYPE),AT91)
ATH_ARCH_CPU_TYPE := arm
ATH_CROSS_COMPILE_TYPE := /usr/local/arm-2007q1/bin/arm-none-linux-gnueabi-
ATH_LINUXPATH := /opt/AT91SAM9G45/linux-2.6.30/
endif
四. 结果:
make 命令:
make ATH_BUILD_TYPE=AT91 ATH_BUS_TYPE=sdio
在文件夹下:
/opt/AT91SAM9G45/AR6K_GPL_SDK.2.2.1.83/host/.output/AT91-sdio/image
有编译结果:
ar6000.ko bmiloader eeprom.AR6002 recEvent restore.sh sdio_busdriver.ko sdio_lib.ko
wmiconfig
五. 疑问
1. make 编译选项中 没有指定 ATH_SDIO_STACK_BASE= SDIOSTACKBASE
以下为 MAKEFILE 文件的说明:
# Extended Make invocation:
#
# make ATH_BUILD_TYPE= ATH_SDIO_STACK_BASE=
(all | clean | clobber)
现用的make 命令为:
make ATH_BUILD_TYPE=AT91 ATH_BUS_TYPE=sdio
要不要先编译AR6K_GPL_SDK.2.2.1.83\host\sdiostack\src,后 将ATH_SDIO_STACK_BAS指定为
AR6K_GPL_SDK.2.2.1.83\host\sdiostack\src
但是在 MAKEFILE 文件中,只是引入了ATH_SDIO_STACK_BASE:
export ATH_SDIO_STACK_BASE
# ATH_SDIO_STACK_BASE - SDIO Stack installation path to compile the SDIO HIF
layer against an externally supplied
# SDIO stack source.
其他地方并没有调用ATH_SDIO_STACK_BASE,
上面提到了the SDIO HIF layer 是不是可以用 AR6K_GPL_SDK.2.2.1.83
\host\hif\sdio\linux_sdio\src\hif 代替
文件夹中 对于 SDIOSTACKBASE 文件夹中有两处:
AR6K_GPL_SDK.2.2.1.83\host\sdiostack\src
和
AR6K_GPL_SDK.2.2.1.83\host\hif\sdio\linux_sdio\src
根据这两组文件夹能编译出两组 SDIOBUS 的驱动,详见第二部分。
到底 用哪一个呢,试了才知道
2. tools/wfa_sta 文件 没有 找到,不知对结果 有无影响。
六. 过程中的问题及解决办法:
1. 没有正确填写localmake.linux 和 make 选项不正确
一上来直接MAKE ,提示出错:Please edit the localmake.linux.inc file
查看 makefile 文件 发现,其中有
modules:
ifndef ATH_BUILD_TYPE
@echo "Please edit the $(_LOCALMAKE_INCLUDE) file"
exit
原来是ATH_BUILD_TYPE 的问题,仔细查看MAKEFILE 文件的 前半部分说明 才发现 原
来 要 依赖localmake.linux.inc 文件,没有正确正确填写localmake.linux 和 make 选项不正确。填
写localmake.linux 后, make 选项改为make ATH_BUILD_TYPE=AT91 ,问题解决。
2. wakelock .h 文件没有找到
错误提示:
./os/linux/ar6000_drv.c://#include
查看./os/linux/ar6000_drv.c
#include
#ifdef CONFIG_PM
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
//masked by gu
//#include
#endif
原来是Linux内核版本的判断,我们的linux 版本是 2.6.30 ,所以会 #include
。但是 从linux 源代码中 根本搜不到 wakelock.h 文件,没办法只好将其 注释掉
,料也无妨,果然编译顺利通过。
3. 错误提示 :
make -C hif/`echo | tr [:upper:] [:lower:]`
make[1]: Entering directory `/opt/AT91SAM9G45/AR6K_GPL_SDK.2.2.1.83/host/hif'
make[1]: *** No targets specified and no makefile found. Stop.
make[1]: Leaving directory `/opt/AT91SAM9G45/AR6K_GPL_SDK.2.2.1.83/host/hif'
make: *** [modules] Error 2
查看 Makefile:
$(MAKE) -C hif/$(ATH_HIF_TYPE)
ATH_HIF_TYPE :=`echo $(ATH_BUS_TYPE) | tr [:upper:] [:lower:]
export ATH_BUS_TYP
结合 MAKEFILE 文件的 前半部分说明,原来export ATH_BUS_TYPE 没有定义 ,发现 hif 文件
夹下有sdio 文件夹 ,sdio 文件夹里有makefile ,添加make 选项,添加ATH_BUS_TYPE=sdio
修改后的结果:
make ATH_BUILD_TYPE=AT91 ATH_BUS_TYPE=sdio
编译通过,如果不添加 ATH_BUS_TYPE=sdio 将没有 任何编译结果
4.wfa_sta 文件夹没有找到
错误提示:
make[1]: Leaving directory
`/opt/AT91SAM9G45/AR6K_GPL_SDK.2.2.1.83/host/tools/recEvent'
make -C tools/wfa_sta
make: *** tools/wfa_sta: No such file or directory. Stop.
make: *** [modules] Error 2
$(MAKE) -C tools/wfa_st
虽然MAKEFILE 里提到了要 编译wfa_st, $(MAKE) -C tools/wfa_st 但是 在tools 文件夹下
并没有wfa_sta 文件夹,从名字上看 估计是 WIFI 联盟的 一个什么标准,既然厂家不提供我们也没办法
。
将 MAKEFILE 中相关的 两条语句 屏蔽掉了
#masked by gu
# $(MAKE) -C tools/wfa_st
#maked by gu
# cp -f tools/wfa_sta/wfa_sta $(COMPILED_IMAGE_OBJECTS_PATH
编译完全通过
第二部分:在\AR6K_GPL_SDK.2.2.1.83\host\sdiostack\src 文件夹内
一. 正确的编译选项:
make BUS_BUILD=1 CT_BUILD_TYPE=AT91 CT_OS_TYPE=linux default
参考:Makefile 文件:
# Minimal build invocation:
#
# make ALL_BUILD=1 CT_BUILD_TYPE= CT_OS_TYPE= default | clea
编译结果:/../output/AT91/sdio_lib.ko'
sdio_busdriver.ko sdio_lib.ko
file
../output/AT91/*../output/AT91/sdio_busdriver.ko: ELF 32-bit LSB relocatable, ARM, version 1
(SYSV), not stripped
../output/AT91/sdio_lib.ko: ELF 32-bit LSB relocatable, ARM, version 1 (SYSV), not
stripped
二:疑问:
我猜测 编译出来的两个驱动文件 sdio_lib.ko,sdio_busdriver.ko 是用于驱动 linux 下的
SDIO 总线的,在使用 SDIO 接口的 WIFI 无线网卡之前,要先加载(insmod)SDIO 总线 驱动再加载
WIFI 无线网卡芯片的驱动 ar6000.ko 。
但是在 编译无线网卡芯片的驱动 时也编译出了两个SDIO 总线的驱动 sdio_busdriver.ko
sdio_lib.ko。这两组驱动 到底有什么差别呢?只好 联系 WIFI 开发板厂家 的技术支持。
三: 正确编写 localmake.linux.inc 文件
ifeq ($(CT_BUILD_TYPE),AT91)
CT_ARCH_CPU_TYPE := arm
CT_CROSS_COMPILE_TYPE := /usr/local/arm-2007q1/bin/arm-none-linux-gnueabi-
CT_LINUXPATH := /opt/AT91SAM9G45/linux-2.6.30/
endif
参考 MAKEFILE 文件:
#include local variables
ifdef CT_MAKE_INCLUDE_OVERRIDE
-include $(、)
else
-include localmake.$(CT_OS_TYPE).inc
-include localmake.$(CT_OS_TYPE).private.inc
endif
export CT_OS_TYPE
export CT_OS_SUB_TYPE
export CT_OS_TOP_LEVEL_RULE
export CT_PASS_CFLAGS
export CT_SRC_BASE
export CT_BUILD_SUB_PRO
所以添加 make 编译选项 CT_OS_TYPE=linux
四: 编译过程中的错误及解决办法:
1.错误1:
make ALL_BUILD=1
提示:
make[3]: *** No rule to make target
`/opt/AT91SAM9G45/AR6K_GPL_SDK.2.2.1.83/host/sdiostack/src/function/Makefile'. Stop.
make[2]: *** [/opt/AT91SAM9G45/AR6K_GPL_SDK.2.2.1.83/host/sdiostack/src/function] Error 2
make[1]: *** [_module_/opt/AT91SAM9G45/AR6K_GPL_SDK.2.2.1.83/host/sdiostack/src] Error 2
make[1]: Leaving directory `/opt/AT91SAM9G45/linux-2.6.30'
make: *** [default] Error 2
实际上src 文件夹里 并没有function ,查看MAKEFILE
# One of the following should be used to build the tree:
# ALL_BUILD=1 - build all source code
# HDK_BUILD=1 - build only HCD and sample function drivers
# PDK_BUILD=1 - build only the sample function drivers
# BUS_BUILD=1 - build bus driver, library and HCDs for use with built-in SDIO cards
大不了我们不编译the sample function drivers,所以设置make 编译选项 BUS_BUILD=1
2. 编译选项没加 CT_OS_TYPE=linux 时
错误提示:
ake: *** No rule to make target `default'. Stop.
原因是没找到 localmake.linux.inc 文件。
ifdef CT_MAKE_INCLUDE_OVERRIDE
-include $(、)
else
-include localmake.$(CT_OS_TYPE).inc
-include localmake.$(CT_OS_TYPE).private.inc
endif
实验证明 与文件 localmake.linux.private.inc无关
3. make 选项 没加 default 时
mkdir --parents
/opt/AT91SAM9G45/AR6K_GPL_SDK.2.2.1.83/host/sdiostack/src/../output/AT91
但是../output/AT91 下没有生成 任何东西
查看MAKEFILE:
其中有:
# Minimal build invocation:
#
# make ALL_BUILD=1 CT_BUILD_TYPE= CT_OS_TYPE= default | clea
和
makeoutputdirs:
$(_MAKE_OUTPUT_DIR)
default: makeoutputdirs
$(MAKE) $(CT_MAKE_COMMAND_LINE) EXTRA_CFLAGS="$(EXTRA_CFLAGS)" modules
$(CT_SRC_BASE)/../scripts/getobjects.scr $(CT_SRC_BASE) $(_CT_COMPILED_OBJECTS_PATH)
$(_CT_MOD_EXTENSION)
ifeq ($(CT_OS_SUB_TYPE),linux_2_4)
# on 2.4 we can't invoke the linux clean with SUBDIRS, it will just clean out the kernel
clean:
find $(_CT_SUBDIRS) \( -name '*.[oas]' -o -name core -o -name '.*.flags' -o -name
'.ko' -o -name '.*.cmd' \) -type f -print \
| grep -v lxdialog/ | xargs rm -f
$(_CLEAN_OUTPUT_DIR)
else
clean:
$(MAKE) $(CT_MAKE_COMMAND_LINE) clea
所以设置make 编译选项 default