mips的交叉编译驱动程序

时间:2015-04-30 15:21:11

标签: driver mips cross-compiling

我正在尝试为mips设备编译一个简单的驱动程序示例。司机真的只是一个考验:

#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");

int ath_pci_init(void)
{
    printk(KERN_ALERT "alive and hacked\n");
    return 0;
}

void ath_pci_exit(void)
{
    printk(KERN_ALERT "dead and hacked\n");
}

module_init (ath_pci_init);
module_exit (ath_pci_exit);

使用此Makefile编译:

ifneq ($(KERNELRELEASE),)
    obj-m := driver.o
else
    KERNELDIR ?= /lib/modules/3.2.0-81-generic/build
    PWD := $(shell pwd)
default:
    $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
endif

对于x86完美无缺。对于mips,我尝试将Makefile更改为:

ifneq ($(KERNELRELEASE),)
    obj-m := driver.o
else
    KERNELDIR ?= /lib/modules/3.2.0-81-generic/build
    PWD := $(shell pwd)
default:
    $(MAKE) -C $(KERNELDIR) ARCH=mips CROSS_COMPILE=~/Downloads/openwrt2/openwrt/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-uclibc- M=$(PWD) modules

endif

但它不起作用。 在消化之后,我看到我使用了第一个Makefile但是没有运行make default我跑了:

make ARCH=mips CROSS_COMPILE=~/openwrt2/openwrt/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-uclibc- default

在这两种情况下,我都明白了:

make -C /lib/modules/3.2.0-81-generic/build M=<folder> modules
make[1]: Entering directory `/usr/src/linux-headers-3.2.0-81-generic'
/usr/src/linux-headers-3.2.0-81-generic/arch/mips/Kbuild.platforms:35: /usr/src/linux-headers-3.2.0-81-generic/arch/mips/alchemy/Platform: No such file or directory
/usr/src/linux-headers-3.2.0-81-generic/arch/mips/Kbuild.platforms:35: /usr/src/linux-headers-3.2.0-81-generic/arch/mips/ar7/Platform: No such file or directory
/usr/src/linux-headers-3.2.0-81-generic/arch/mips/Kbuild.platforms:35: /usr/src/linux-headers-3.2.0-81-generic/arch/mips/ath79/Platform: No such file or directory
/usr/src/linux-headers-3.2.0-81-generic/arch/mips/Kbuild.platforms:35: /usr/src/linux-headers-3.2.0-81-generic/arch/mips/bcm47xx/Platform: No such file or directory
/usr/src/linux-headers-3.2.0-81-generic/arch/mips/Kbuild.platforms:35: /usr/src/linux-headers-3.2.0-81-generic/arch/mips/bcm63xx/Platform: No such file or directory
/usr/src/linux-headers-3.2.0-81-generic/arch/mips/Kbuild.platforms:35: /usr/src/linux-headers-3.2.0-81-generic/arch/mips/cavium-octeon/Platform: No such file or directory
/usr/src/linux-headers-3.2.0-81-generic/arch/mips/Kbuild.platforms:35: /usr/src/linux-headers-3.2.0-81-generic/arch/mips/cobalt/Platform: No such file or directory
/usr/src/linux-headers-3.2.0-81-generic/arch/mips/Kbuild.platforms:35: /usr/src/linux-headers-3.2.0-81-generic/arch/mips/dec/Platform: No such file or directory
/usr/src/linux-headers-3.2.0-81-generic/arch/mips/Kbuild.platforms:35: /usr/src/linux-headers-3.2.0-81-generic/arch/mips/emma/Platform: No such file or directory
/usr/src/linux-headers-3.2.0-81-generic/arch/mips/Kbuild.platforms:35: /usr/src/linux-headers-3.2.0-81-generic/arch/mips/jazz/Platform: No such file or directory
/usr/src/linux-headers-3.2.0-81-generic/arch/mips/Kbuild.platforms:35: /usr/src/linux-headers-3.2.0-81-generic/arch/mips/jz4740/Platform: No such file or directory
/usr/src/linux-headers-3.2.0-81-generic/arch/mips/Kbuild.platforms:35: /usr/src/linux-headers-3.2.0-81-generic/arch/mips/lantiq/Platform: No such file or directory
/usr/src/linux-headers-3.2.0-81-generic/arch/mips/Kbuild.platforms:35: /usr/src/linux-headers-3.2.0-81-generic/arch/mips/lasat/Platform: No such file or directory
/usr/src/linux-headers-3.2.0-81-generic/arch/mips/Kbuild.platforms:35: /usr/src/linux-headers-3.2.0-81-generic/arch/mips/loongson/Platform: No such file or directory
/usr/src/linux-headers-3.2.0-81-generic/arch/mips/Kbuild.platforms:35: /usr/src/linux-headers-3.2.0-81-generic/arch/mips/mipssim/Platform: No such file or directory
/usr/src/linux-headers-3.2.0-81-generic/arch/mips/Kbuild.platforms:35: /usr/src/linux-headers-3.2.0-81-generic/arch/mips/mti-malta/Platform: No such file or directory
/usr/src/linux-headers-3.2.0-81-generic/arch/mips/Kbuild.platforms:35: /usr/src/linux-headers-3.2.0-81-generic/arch/mips/netlogic/Platform: No such file or directory
/usr/src/linux-headers-3.2.0-81-generic/arch/mips/Kbuild.platforms:35: /usr/src/linux-headers-3.2.0-81-generic/arch/mips/pmc-sierra/Platform: No such file or directory
/usr/src/linux-headers-3.2.0-81-generic/arch/mips/Kbuild.platforms:35: /usr/src/linux-headers-3.2.0-81-generic/arch/mips/pnx833x/Platform: No such file or directory
/usr/src/linux-headers-3.2.0-81-generic/arch/mips/Kbuild.platforms:35: /usr/src/linux-headers-3.2.0-81-generic/arch/mips/pnx8550/Platform: No such file or directory
/usr/src/linux-headers-3.2.0-81-generic/arch/mips/Kbuild.platforms:35: /usr/src/linux-headers-3.2.0-81-generic/arch/mips/powertv/Platform: No such file or directory
/usr/src/linux-headers-3.2.0-81-generic/arch/mips/Kbuild.platforms:35: /usr/src/linux-headers-3.2.0-81-generic/arch/mips/rb532/Platform: No such file or directory
/usr/src/linux-headers-3.2.0-81-generic/arch/mips/Kbuild.platforms:35: /usr/src/linux-headers-3.2.0-81-generic/arch/mips/sgi-ip22/Platform: No such file or directory
/usr/src/linux-headers-3.2.0-81-generic/arch/mips/Kbuild.platforms:35: /usr/src/linux-headers-3.2.0-81-generic/arch/mips/sgi-ip27/Platform: No such file or directory
/usr/src/linux-headers-3.2.0-81-generic/arch/mips/Kbuild.platforms:35: /usr/src/linux-headers-3.2.0-81-generic/arch/mips/sgi-ip32/Platform: No such file or directory
/usr/src/linux-headers-3.2.0-81-generic/arch/mips/Kbuild.platforms:35: /usr/src/linux-headers-3.2.0-81-generic/arch/mips/sibyte/Platform: No such file or directory
/usr/src/linux-headers-3.2.0-81-generic/arch/mips/Kbuild.platforms:35: /usr/src/linux-headers-3.2.0-81-generic/arch/mips/sni/Platform: No such file or directory
/usr/src/linux-headers-3.2.0-81-generic/arch/mips/Kbuild.platforms:35: /usr/src/linux-headers-3.2.0-81-generic/arch/mips/txx9/Platform: No such file or directory
/usr/src/linux-headers-3.2.0-81-generic/arch/mips/Kbuild.platforms:35: /usr/src/linux-headers-3.2.0-81-generic/arch/mips/vr41xx/Platform: No such file or directory
/usr/src/linux-headers-3.2.0-81-generic/arch/mips/Kbuild.platforms:35: /usr/src/linux-headers-3.2.0-81-generic/arch/mips/wrppmc/Platform: No such file or directory
expr: syntax error
make[1]: *** No rule to make target `/usr/src/linux-headers-3.2.0-81-generic/arch/mips/wrppmc/Platform'.  Stop.
make[1]: Leaving directory `/usr/src/linux-headers-3.2.0-81-generic'
make: *** [default] Error 2

我猜测通过将CC重定向到工具链,我必须为它提供与本机编译器相同的资源(或等效资源)。但是,我不知道如何做到这一点。

如何编译我的驱动程序?

提前致谢

1 个答案:

答案 0 :(得分:1)

我发现要交叉编译驱动程序,你还需要一个交叉编译的预备内核,以及一个有效的内核配置文件。

你必须下载内核,想要编译驱动程序,然后运行:

make ARCH=mips CROSS_COMPILE=mips-openwrt-linux-uclibc- oldconfig
make ARCH=mips CROSS_COMPILE=mips-openwrt-linux-uclibc- prepare

然后更新makefile以使用此内核,例如:

KERNELDIR ?= <path to kernel>/kernel/3.2.0-81-generic/