将 Linux 驱动程序迁移到 Android
我正在将专为 Linux 笔记本电脑编写的 3G 调制解调器移植到带有 ARM 处理器的嵌入式 Android (Gingerbread) 设备。我已经将设备驱动程序编译(C 代码)为模块(.ko 文件)并安装。当我启动内核时我看到它并且运行良好。它按预期连接到 USB 端口。它很乐意与人交谈。
下一个必需的部分是用 C++ 编写的“连接管理器”。这是我遇到问题的地方。它不在内核空间中运行,但它不是具有用户界面的常规 Android 应用程序。这是一个在后台运行的“任务”,应在启动时从“init.rc”文件启动。源代码提供的 makefile 可以很好地设置依赖关系,但对于我想要的目标平台来说它是无用的。我正在使用 Android 源代码“arm-eabi-*”(在 Ubuntu 机器上运行)提供的工具链,我用它来编译 Android 和内核。我遇到很多编译错误,主要是因为它使用了 Android 中不存在的标准“libc”库。我将其替换为“bionic libc”,它是适用于 Android 的 linux libc 的轻量级子集版本。最重要的是,它查找“crt0.o”,这是 Linux 环境(以及其他几个操作系统)中静态链接程序的启动代码。在 Android 中,它在运行时动态链接,因此使用 crt0.o 以外的其他内容。
网络上有大量有关 Android 应用程序编程的信息,但有关此类低级内容的信息却很少。如果有人有一个可用的 makefile 来构建这种 C++ 代码以作为 Android ARM 下的后台任务运行,我将非常感激地看一下它,或者是否有任何信息可以帮助我找到一种方法来做到这一点。或者如果有人做过类似的事情可以给我一些关于如何实现这一目标的线索。
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.
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 Ubuntu 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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
差不多一年后,这里有一个 makefile,将编译一个简单的本机应用程序:
它将同一目录中的任何 .c 文件编译到名为“out”的应用程序中。它需要环境变量NDK_USR指向ndk目录“ndk/android-ndk-r7/platforms/android-14/arch-arm/usr/”。
这应该动态链接到仿生 libc,并且应该启用 Android 驱动程序开发。
复制和粘贴上述 makefile 时要小心。 Make 对于制表符非常具体。
Almost a year later, but here is a makefile that will compile a simple native app:
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/".
This should dynamically link to the bionic libc, and should enable android driver development.
Be careful when copying and pasting the above makefile. Make is very specific about tab characters.