迁移Linux驱动程序到Android [英] migrating a linux driver to Android

查看:262
本文介绍了迁移Linux驱动程序到Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我移植的Linux笔记本电脑与ARM处理器写入到一个嵌入机器人(姜饼)设备的3G调制解调器。我已经有了编译设备驱动程序(C code)作为一个模块(.ko文件),并安装。我看到它时我启动内核,它运行良好。按计划它挂接到USB端口。这是幸福的准备说话。

I'm porting a 3G modem written for Linux for laptops to an embedded android (Gingerbread) device with an ARM processor. I already got the device driver compiled (C code) as a module (.ko file) and installed. I see it when I boot the kernel and it runs well. It hooks up to the USB port as intended. It's happy ready to be talked to.

接下来所需部分是连接管理器用C ++编写。这是我有一个问题。这并不运行在内核空间,但它不是一个用户界面,一个普通的Andr​​oid应用程序。这是一个任务,在后台运行,应该从在启动时init.rc文件启动。提供与源$ C ​​$ C Makefile是好设置的依赖关系,但它是无用尽可能的平台,我想要的目标。我使用提供了Android源$ C ​​$ c中的工具链臂eabi- *(运行了一个Unbuntu机),我用来编译Android和内核。我得到了很多主要是因为它使用了不存在的Andr​​oid标准的libc库的编译错误。我的仿生libc中,这是Linux的libc为Android的重量轻子集的版本替换它。在它的上面,它会寻找的crt0.o,这是初创code在Linux环境中静态链接程序(和其他几个OS)。在Android中它是在运行时动态链接,为此使用别的东西比crt0.o中。

The next required piece is the "connection manager" written in C++. This is where I have a problem. This doesn't run in Kernel space but it is not a regular Android application with a user interface. This is a "task" running in background that should be started from the "init.rc" file at boot time. The makefile provided with the source code is good to set the dependencies but it is useless as far as the platform I want to target. I'm using the toolchain provided with the Android source code "arm-eabi-*" (runs off of a Unbuntu machine) that I used to compile Android and the kernel. I got lots of compile errors primary because it uses the standard "libc" libraries which doesn't exist in Android. I replaced it by the "bionic libc" which is a light weight subset version of linux libc for android. On top of it, it looks for "crt0.o" which is the start-up code a statically linked program in a linux environment(and several other OS). In Android it is dynamically linked at run time, therefor uses something else than crt0.o.

有是吨在网络上的Andr​​oid应用程序,但是,在那种低层次的东西的信息非常少。如果有人有建立那种C ++ code,以作为下Android的ARM后台任务运行工作的makefile,我会非常AP preciate来看看它,或者,如果有,可以帮助我的任何信息找到一个方法来做到这一点。或者,如果有人做了这样的事情可以给我如何实现这一些线索。

There is tons of information on Android app programming on the web but, very little on that kind of low level stuff. If anybody has a working makefile for building that kind of C++ code to run as a background task under Android ARM, I would very appreciate to have a look at it or if there is any information that could help me find a way to do that. Or if anyone has done something like that could give me some clues on how to achieve this.

推荐答案

将近一年过去了,但这里是一个makefile,将编译一个简单的本机应用程序:

Almost a year later, but here is a makefile that will compile a simple native app:

NDK_USR_PATH := $(NDK_USR)

C_FILES := $(wildcard *.c) $(wildcard *.cpp)
O_FILES := $(patsubst %.cpp,%.o,$(C_FILES))
O_FILES := $(patsubst %.c,%.o,$(C_FILES))

out: $(O_FILES)
        @arm-eabi-gcc -o $@ $< -Bdynamic -Wl,--gc-section -Wl,-z,nocopyreloc -Wl,--no-undefined -Wl,--dynamic-linker=/system/bin/linker -Wl,-rpath-link=$(NDK_USR_PATH)/lib -nostdlib $(NDK_USR_PATH)/lib/crtend_android.o $(NDK_USR_PATH)/lib/crtbegin_dynamic.o -L$(NDK_USR_PATH)/lib -lc

%.o: %.c 
        @arm-eabi-gcc -o $@ $< -c -I$(NDK_USR_PATH)/include -fno-short-enums

clean:
        @rm -f *.o
        @rm -f out

它编译在同一个目录中的任何.c文件到一个名为走出去的应用程序。它要求环境变量NDK_USR指向NDK目录NDK / Android的NDK-R7 /平台/ Android的14 /弓臂的/ usr /\".

It compiles any .c files in the same directory into an app named "out". It requires the environment variable NDK_USR to point to the ndk directory "ndk/android-ndk-r7/platforms/android-14/arch-arm/usr/".

这应该动态链接到libc的仿生,并应启用Android驱动开发。

This should dynamically link to the bionic libc, and should enable android driver development.

复制时要小心和粘贴上面的Makefile。提出的是非常具体制表符。

Be careful when copying and pasting the above makefile. Make is very specific about tab characters.

这篇关于迁移Linux驱动程序到Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆