文档章节

Porting Libusb for Android on the Beagleboard i...

shouyong
 shouyong
发布于 2013/01/04 16:26
字数 663
阅读 285
收藏 0

    It is long overdue to talk about porting specific projects to Android. It is astonishingly easy to do so with the Android platform.
    Since we are using USB for our project we found it convenient to work with libusb 1.0. Using the Beagleboard we are able to make use of the USB 2.0 high speed functionality of libusb.

    Libusb itself consists of a shared library and two sample applications. One of those applications is the lsusb command which lists connected USB devices in the console.

    These five Steps is all it takes to port the existing libusb open source project to the Android platform.



1. Get the libusb-1.0 sources [link] and create an empty “libusb-1.0.3″ folder in the external directory of your Android sources. Unpack the libusb folder into the new directory.

2. Create Android.mk files in each of the libusb directories. In the top folder your Android.mk just calls your mk files in the libusb subfolders :

LOCAL_PATH := $(call my-dir)
subdirs := $(addprefix $(LOCAL_PATH)/,$(addsuffix /Android.mk, \
libusb \
))
include $(subdirs)
LOCAL_PATH := $(call my-dir)
ubdirs := $(addprefix $(LOCAL_PATH)/,$(addsuffix /Android.mk, \  libusb \
))
include $(subdirs)

in the libusb folder add the following Android.mk

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_SRC_FILES:= \
 core.c \
 descriptor.c \
 io.c \
 sync.c \
 os/linux_usbfs.c

LOCAL_C_INCLUDES += \
external/libusb-1.0.3/ \
external/libusb-1.0.3/libusb/ \
external/libusb-1.0.3/libusb/os

LOCAL_MODULE:= libusb
include $(BUILD_SHARED_LIBRARY)

You see the syntax of these Android.mk files is very simple. You just tell the compiler what modules you want to include and where your header files are.

3. Soon we are ready to compile the library; if we do so now, we will notice that the macro TIMESPEC_TO_TIMEVAL is not defined by the sources inside Android. To overcome this problem we just need to define the macro in the lubusb/io.c file.

#define TIMESPEC_TO_TIMEVAL(tv, ts)                                     \
        do {                                                            \
                (tv)->tv_sec = (ts)->tv_sec;                            \
                (tv)->tv_usec = (ts)->tv_nsec / 1000;                   \
        } while (0)

If you compile your libusb now, there is going to be the following error: build/tools/apriori/prelinkmap.c(137): library ‘libusb.so’ not in prelink map. This is because Android keeps track of all the shared libraries of the root file system (RFS). Therefore we need to add the library to the prelinked map found in ./build/core/prelink-linux-arm.map. We did so and just added libusb.so below libqcamera.so.

libqcamera.so       0xA9400000
libusb.so           0xA8000000

You are now all set to compile libusb. Execute the following commands in your Android root directory:

$ . build/envsetup.sh
$ choosecombo

Choose your build variant. Afterwards you can compile the whole RFS with make or just that one project:

mmm -j4 /external/libusb

4. Your library is ready… but your usb-file system is almost certainly not mounted yet. In your init.rc of the RFS add the following command to mount your USBFS.

mount usbfs none /proc/bus/usb -o devmode=0666

Add the line somewhere below the “on boot” event.

5. Now we need to compile lsusb. The sources are located in the examples folder of libusb. Create a folder lsusb in the ./external directory of the Android sources. Copy the lsusb.c module into it and create a Android.mk file:

LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)
LOCAL_SRC_FILES:= lsusb.c
LOCAL_MODULE := lsusb
LOCAL_C_INCLUDES += external/libusb-1.0.3/
LOCAL_SHARED_LIBRARIES := libc libusb
include $(BUILD_EXECUTABLE)

Execute the build command:

mmm -j4 /external/lsusb

and we are done! Congratulations! You just ported an entirely non-Android specific project to your Android platform!

Simply execute lsusb in your Android shell to verify if everything worked properly.

Update 15.07.2011
Thank you for all your comments. With the new Android versions there are a few things that changed for the tutorial.

  • 1. To correct the devmode you now need to adjust the uevent.rc file rather than the init.rc.
  • 2. The Android.mk requires LOCAL_MODULE_TAGS since Froyo. (for ex. LOCAL_MODULE_TAGS = eng user)
  • 3. It became pretty easy to exclude files from the prelinked map. Add LOCAL_PRELINK_MODULE := false to your Android mk files.
  • 4. As “kos” pointed out the sources will now compile when using ./configure –disable-timerfd before building to avoid compiling errors.

本文转载自:http://android.serverbox.ch/?p=151

shouyong

shouyong

粉丝 4
博文 24
码字总数 2773
作品 0
成都
程序员
私信 提问
还有好几款鼎鼎有名的开源硬件

@红薯 BeagleBoard PandaBoard Raspberry Pi 以及最新的 CubieBoard http://en.wikipedia.org/wiki/List_of_single-board_computers上有完整的列表,不过上面列出的应该是最知名的了,甚至淘...

mallon
2012/09/20
462
1
openSUSE 12.2 ARM 正式版发布

如我们上周所承诺的,openSUSE ARM 团队今天发布了 openSUSE 12.2 ARM 版本。几乎所有 openSUSE 分发包(超过5000个包)构建以及运行在 ARM 平台上并通过测试。 开发团队很自信该版本可运行于...

红薯
2012/11/07
1K
4
BeagleBone Black的Cape之基本概念

BBB的Cape的基本情况网上说的很详细,我觉得比较好的是一个兄弟的blog(http://blog.csdn.net/wyt2013?viewmode=contents),其中的如何使用GPIO/AD/SPI/I2C及 为BBB制作专属自己的cape(一)...

robeermy_cn
2014/03/13
581
0
DS-5 的示例项目

The example projects provided with DS-5 illustrate how to use the DS-5 toolchain to create and debug a variety of project types: nCalendar is a simple bare metal application, us......

长平狐
2013/06/03
45
0
Raspberry Pi 拥抱 RISC OS

Raspberry Pi 为圣诞节上线所准备的一切都在正常进展中;更令人兴奋的是:Raspberry Pi 将可以运行——RISC OS。一个英产的教育性ARM板可以运行RISC OS?没有比这更为令人高兴的了。 (正文有...

xyxzfj
2011/11/01
2.5K
1

没有更多内容

加载失败,请刷新页面

加载更多

JAVA--高级基础开发

//定义两个线程,一个线程输出偶数,一个线程输出奇数,并且是交替输出 public class Test08 { public static void main(String[]args){ //创建当前类的对象 Life num = new L...

李文杰-yaya
13分钟前
16
0
[开源] .NETCore websocket 即时通讯组件---ImCore

ImCore 利用 webSocket 协议实现简易、高性能、集群即时通讯组件,支持点对点通讯、群聊通讯、上线下线事件消息等众多实用性功能。 Quick Start dotnet add package ImCore IM服务端 public...

2881099
16分钟前
1
0
java保留小数点后几位,不足的用0补

在 java 中,如果小数点最后位是0,double类型会把这个0去掉,比如4.30变成了4.3,这样导致有的界面显示不好看。 所以要转换下,如下方法 /** * 将double格式化为指定小数位的String,...

Gotcha_
20分钟前
2
0
spring boot 1.x升2.x的注意事项

记录升级过程中的一些错误。 本次升级为1.5.x 升级为2.1.4 ---------------------------------------------- 如果java版本低于8请不要升级,spring boot 2.0需要至少java 8才行。 ----------...

玄影镜心
21分钟前
3
0
关于Spring

Spring整体架构: Core Container Core Container(核心容器)包含Beans、Core、Context、EspL四个模块 Core和Beans是Spring的基础部分,提供IOC(控制反转)和DI(依赖注入) Core模块 该模...

java后端开发
28分钟前
4
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部