lukelang 发表于 2014-6-12 19:02:43

安卓交叉编译工具

本帖最后由 lukelang 于 2014-6-12 21:23 编辑

请问,为E9写安卓驱动的时候,如何设置交叉编译工具?是选择TQIMX6_android-4.2.2\prebuilts\gcc\linux-x86\arm\arm-eabi-4.6
还是选择TQIMX6_android-4.2.2\prebuilts\gcc\linux-x86\arm\arm-linux-androideabi-4.6

wbz073 发表于 2014-6-13 08:56:29

选择TQIMX6_android-4.2.2\prebuilts\gcc\linux-x86\arm\arm-eabi-4.6

lukelang 发表于 2014-6-25 03:01:09

如果用/usr/src/linux-headers-3.11.0-15-generic指定内核,电脑的/usr/bin/gcc-4.4作为gcc,编译就成功。
可是按你的提示做,却失败了。请指教。
root@lkl-X200:/opt/linux_drv/1th_hello# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/Embedsky/TQIMX6/E9/TQIMX6_android-4.2.2/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin/../libexec/gcc/arm-eabi/4.6.x-google/lto-wrapper
Target: arm-eabi
Configured with: /tmp/android-15472/src/build/../gcc/gcc-4.6/configure --prefix=/usr/local --target=arm-eabi --host=x86_64-linux-gnu --build=x86_64-linux-gnu --with-gnu-as --with-gnu-ld --enable-languages=c,c++ --with-gmp=/tmp/android-15472/obj/temp-install --with-mpfr=/tmp/android-15472/obj/temp-install --with-mpc=/tmp/android-15472/obj/temp-install --without-ppl --without-cloog --disable-libssp --enable-threads --disable-nls --disable-libmudflap --disable-libgomp --disable-libstdc__-v3 --disable-sjlj-exceptions --disable-shared --disable-tls --disable-libitm --with-float=soft --with-fpu=vfp --with-arch=armv5te --enable-target-optspace --with-abi=aapcs --with-gcc-version=4.6 --with-binutils-version=2.21 --with-gmp-version=4.2.4 --with-mpfr-version=2.4.1 --with-gdb-version=7.3.x --with-arch=armv5te --with-sysroot=/tmp/android-15472/install/sysroot --with-prefix=/tmp/android-15472/install --with-gold-version=2.21 --enable-gold --disable-gold --disable-multilib --program-transform-name='s&^&arm-eabi-&'
Thread model: single
gcc version 4.6.x-google 20120106 (prerelease) (GCC)


root@lkl-X200:/opt/linux_drv/1th_hello# make
make -C /opt/Embedsky/TQIMX6/E9/TQIMX6_android-4.2.2/kernel_imx M=/opt/linux_drv/1th_hello modules
make: 正在进入目录 `/opt/Embedsky/TQIMX6/E9/TQIMX6_android-4.2.2/kernel_imx'
CC /opt/linux_drv/1th_hello/hello_world.o
Building modules, stage 2.
MODPOST 1 modules
CC      /opt/linux_drv/1th_hello/hello_world.mod.o
LD /opt/linux_drv/1th_hello/hello_world.ko
ld: /opt/linux_drv/1th_hello/hello_world.o: Relocations in generic ELF (EM: 40)
ld: /opt/linux_drv/1th_hello/hello_world.o: Relocations in generic ELF (EM: 40)
ld: /opt/linux_drv/1th_hello/hello_world.o: Relocations in generic ELF (EM: 40)
ld: /opt/linux_drv/1th_hello/hello_world.o: Relocations in generic ELF (EM: 40)
ld: /opt/linux_drv/1th_hello/hello_world.o: Relocations in generic ELF (EM: 40)
ld: /opt/linux_drv/1th_hello/hello_world.o: Relocations in generic ELF (EM: 40)
ld: /opt/linux_drv/1th_hello/hello_world.o: Relocations in generic ELF (EM: 40)
ld: /opt/linux_drv/1th_hello/hello_world.o: Relocations in generic ELF (EM: 40)
ld: /opt/linux_drv/1th_hello/hello_world.o: Relocations in generic ELF (EM: 40)
ld: /opt/linux_drv/1th_hello/hello_world.o: Relocations in generic ELF (EM: 40)
ld: /opt/linux_drv/1th_hello/hello_world.o: Relocations in generic ELF (EM: 40)
ld: /opt/linux_drv/1th_hello/hello_world.o: Relocations in generic ELF (EM: 40)
/opt/linux_drv/1th_hello/hello_world.o: could not read symbols: File in wrong format
make: *** 错误 1
make: *** 错误 2
make:正在离开目录 `/opt/Embedsky/TQIMX6/E9/TQIMX6_android-4.2.2/kernel_imx'
make: *** 错误 2

驱动代码
#include<linux/init.h>
#include<linux/module.h>

/*1.装载模块的时候会执行这个函数*/
static int __init hello_init(void)
{
        printk("%s()-%d!\n",__func__,__LINE__);
        return 0;
}

/*2.卸载模块的时候会执行这个函数*/
static void __exit hello_exit(void)
{
        printk("%s()-%d\n",__func__,__LINE__);
}

module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("GPL");

Makefile代码
1 ifeq ($(KERNELRELEASE),)
2
3 KERNELDIR ?= /opt/Embedsky/TQIMX6/E9/TQIMX6_android-4.2.2/kernel_imx
4
5 PWD := $(shell pwd)
6
7 modules:
8   $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
9
10 modules_install:
11   $(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
12
13 clean:
14   rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions Module* mod    ule* test
15 else
16   obj-m := hello_world.o
17 endif
18
~

wbz073 发表于 2014-6-25 10:28:25

lukelang 发表于 2014-6-25 03:01
如果用/usr/src/linux-headers-3.11.0-15-generic指定内核,电脑的/usr/bin/gcc-4.4作为gcc,编译就成功。
...

你不用去选择交叉编译器,你如果是自己想联系写驱动,可以直接把你的驱动加到下载的内核源码,然后编译就行了,系统会自动替你找交叉编译器。CROSS_COMPILE=`pwd`/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin/arm-eabi-

lukelang 发表于 2014-6-25 15:02:24

有没有办法单独编译自己的驱动呢?即是自己的.c驱动文件和Makefile文件放在硬盘的任意目录,都可以编译通过,无需放到下载的内核源码

lukelang 发表于 2014-6-25 15:26:25

放到内核源码里,在TQIMX6_android-4.2.2目录下make,睡醒一觉都没结束

wbz073 发表于 2014-6-25 16:35:28

lukelang 发表于 2014-6-25 15:26
放到内核源码里,在TQIMX6_android-4.2.2目录下make,睡醒一觉都没结束

prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin/arm-eabi-gcc
你可以把这里的交叉编译器arm-eabi-4.6设置到你的环境变量中,使用arm-eabi-gcc代替你电脑的gcc去编译,就可以单个编译了

lukelang 发表于 2014-6-25 17:01:37

gcc -v显示我已经是用arm-eabi-gcc了哦。

root@lkl-X200:/usr/bin# ll gcc
lrwxrwxrwx 1 root root 1026月 25 02:42 gcc -> /opt/Embedsky/TQIMX6/E9/TQIMX6_android-4.2.2/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin/arm-eabi-gcc*

/etc/environment设置如下
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/game    s:/opt/Embedsky/TQIMX6/E9/TQIMX6_android-4.2.2/prebuilts/gcc/linux-x86/arm/a    rm-eabi-4.6/bin:/usr/lib/jvm/jdk1.6.0_30/bin:/usr/lib/jvm/jdk1.6.0_30/jre/bi    n:/opt/adt-bundle-linux-x86_64-20140321/android-ndk-r9d:/opt/adt-bundle-linu    x-x86_64-20140321/sdk/platform-tools"

出现的错误依然如上面贴出来的情况一样
页: [1]
查看完整版本: 安卓交叉编译工具