libusb-1.0.20移植到RT5350原厂SDK

来源:互联网 发布:dct水印算法 matlab 编辑:程序博客网 时间:2024/04/29 05:39

使用RT5350原厂SDK,有时候可能想使用最新的usb_modeswitch,由于最新的usb_modeswitch使用仔细的libusb1.*库,而手头上的RT5350原厂SDK中的libusb-0.1.12以及libusb-1.0.0无法满足要求,因此移植最新的libusb-1.0.20到RT5350原厂SDK中

一)修改source/lib/Makefile

按照原厂手册中增加新lib的指导修改lib目录下的Makefile,依葫芦画瓢,有libusb-1.0.0的地方,增加libusb-1.0.20的相关定义

ifeq ($(CONFIG_LIB_USB0112_FORCE),y)
    DIRS += libusb-0.1.12
endif
ifeq ($(CONFIG_LIB_USB100_FORCE),y)
    DIRS += libusb-1.0.0
endif
ifeq ($(CONFIG_LIB_USB1020_FORCE),y)
    DIRS += libusb-1.0.20
endif


下面这个动态库实际上可以不要的,因为我们目前不需要libusb-1.0.20的动态库

ifeq ($(CONFIG_LIB_USB0112_FORCE),y)
@$(MAKE) -C libusb-0.1.12 shared
endif
ifeq ($(CONFIG_LIB_USB100_FORCE),y)
@$(MAKE) -C libusb-1.0.0 shared
endif
ifeq ($(CONFIG_LIB_USB1020_FORCE),y)
@$(MAKE) -C libusb-1.0.20 shared
endif


ifeq ($(CONFIG_LIB_USB0112_FORCE),y)
$(MAKE) -C libusb-0.1.12 clean
endif
ifeq ($(CONFIG_LIB_USB100_FORCE),y)
$(MAKE) -C libusb-1.0.0 clean
endif
ifeq ($(CONFIG_LIB_USB1020_FORCE),y)
$(MAKE) -C libusb-1.0.20 clean
endif



二)修改source/config/config.in

依葫芦画瓢,增加make menuconfig时libusb-1.0.20的编译选项

bool 'Build libusb-0.1.12' CONFIG_LIB_USB0112_FORCE
bool 'Build libusb-1.0.0' CONFIG_LIB_USB100_FORCE
bool 'Build libusb-1.0.20' CONFIG_LIB_USB1020_FORCE


三) libusb-1.0.20编译修改
./configure -build=i686-linux --host=mipsel-linux --disable-shared --enable-static --disable-udev


1)
生成的config.h如下
/* config.h.  Generated from config.h.in by configure.  */
/* config.h.in.  Generated from configure.ac by autoheader.  */


/* Default visibility */
#define DEFAULT_VISIBILITY /**/


/* Start with debug message logging enabled */
/* #undef ENABLE_DEBUG_LOGGING */


/* Message logging */
#define ENABLE_LOGGING 1


/* Define to 1 if you have the <asm/types.h> header file. */
#define HAVE_ASM_TYPES_H 1


/* Define to 1 if you have the <dlfcn.h> header file. */
#define HAVE_DLFCN_H 1


/* Define to 1 if you have the `gettimeofday' function. */
#define HAVE_GETTIMEOFDAY 1


/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1


/* Define to 1 if you have the `udev' library (-ludev). */
/* #undef HAVE_LIBUDEV */


/* Define to 1 if you have the <libudev.h> header file. */
/* #undef HAVE_LIBUDEV_H */


/* Define to 1 if you have the <linux/filter.h> header file. */
#define HAVE_LINUX_FILTER_H 1


/* Define to 1 if you have the <linux/netlink.h> header file. */
#define HAVE_LINUX_NETLINK_H 1


/* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1


/* Define to 1 if you have the <poll.h> header file. */
#define HAVE_POLL_H 1


/* Define to 1 if you have the <signal.h> header file. */
#define HAVE_SIGNAL_H 1


/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1


/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1


/* Define to 1 if you have the <strings.h> header file. */
#define HAVE_STRINGS_H 1


/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1


/* Define to 1 if the system has the type `struct timespec'. */
#define HAVE_STRUCT_TIMESPEC 1


/* syslog() function available */
#define HAVE_SYSLOG_FUNC 1


/* Define to 1 if you have the <syslog.h> header file. */
#define HAVE_SYSLOG_H 1


/* Define to 1 if you have the <sys/socket.h> header file. */
#define HAVE_SYS_SOCKET_H 1


/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1


/* Define to 1 if you have the <sys/time.h> header file. */
#define HAVE_SYS_TIME_H 1


/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1


/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1


/* Define to the sub-directory in which libtool stores uninstalled libraries.
   */
#define LT_OBJDIR ".libs/"


/* Darwin backend */
/* #undef OS_DARWIN */


/* Haiku backend */
/* #undef OS_HAIKU */


/* Linux backend */
#define OS_LINUX 1


/* NetBSD backend */
/* #undef OS_NETBSD */


/* OpenBSD backend */
/* #undef OS_OPENBSD */


/* Windows backend */
/* #undef OS_WINDOWS */


/* Name of package */
#define PACKAGE "libusb"


/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT "libusb-devel@lists.sourceforge.net"


/* Define to the full name of this package. */
#define PACKAGE_NAME "libusb"


/* Define to the full name and version of this package. */
#define PACKAGE_STRING "libusb 1.0.20"


/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "libusb"


/* Define to the home page for this package. */
#define PACKAGE_URL "http://libusb.info"


/* Define to the version of this package. */
#define PACKAGE_VERSION "1.0.20"


/* type of second poll() argument */
#define POLL_NFDS_TYPE nfds_t


/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1


/* Use POSIX Threads */
#define THREADS_POSIX 1


/* timerfd headers available */
/* #undef USBI_TIMERFD_AVAILABLE */


/* Enable output to system log */
/* #undef USE_SYSTEM_LOGGING_FACILITY */


/* Use udev for device enumeration/hotplug */
/* #undef USE_UDEV */


/* Version number of package */
#define VERSION "1.0.20"


/* Oldest Windows version supported */
/* #undef WINVER */


/* Use GNU extensions */
#define _GNU_SOURCE 1


/* Define to `__inline__' or `__inline' if that's what the C compiler
   calls it, or to nothing if 'inline' is not supported under any name.  */
#ifndef __cplusplus
/* #undef inline */
#endif


2)
Makefile修改如下;
由于我们编译libusb-1.0.20只是为了使用最新的usb-modeswitch-2.4.0,所以这里只编译static-library; 
并且也不将编译出来的libusb.a拷贝到romfs中;避免和原SDK中的libusb-0.1.12编译出来的libusb产生冲突;
另外usb-modeswitch-2.4.0编译时链接libusb.a也直接链接libusb-1.0.20目录中的libusb.a


TOPDIR=../
include $(TOPDIR)Rules.mak


CFLAGS+=-DHAVE_CONFIG_H -Ilibusb


LIBUSB=libusb.a
LIBUSB_VERS=1.0.20
LIBUSB_SHARED=libusb.so.$(LIBUSB_VERS)


OBJS    := libusb/core.o  libusb/descriptor.o  libusb/io.o  libusb/sync.o libusb/hotplug.o libusb/os/linux_usbfs.o libusb/os/threads_posix.o libusb/os/poll_posix.o libusb/os/linux_netlink.o


all: $(LIBUSB)


$(OBJS): %.o : %.c
$(CC) $(CFLAGS) -c $< -o $@
$(STRIPTOOL) -x -R .note -R .comment $*.o


shared: all
# $(LD) $(LDFLAGS) -soname=$(LIBUSB_SHARED) \
# -o $(LIBUSB_SHARED) --whole-archive $(LIBUSB) \
# --no-whole-archive $(TOPDIR)libc/misc/internals/interp.o \
# -L$(TOPDIR)lib -lc -lpthread $(LDADD_LIBFLOAT) $(LIBGCC);
# $(INSTALL) -d $(TOPDIR)lib
# $(RM) $(TOPDIR)lib/$(LIBUSB_SHARED)
# $(INSTALL) -m 644 $(LIBUSB_SHARED) $(TOPDIR)lib




$(LIBUSB) ar-target: $(OBJS)
$(AR) $(ARFLAGS) $(LIBUSB) $(OBJS)
# $(INSTALL) -d $(TOPDIR)lib
# $(RM) $(TOPDIR)lib/$(LIBUSB)
# $(INSTALL) -m 644 $(LIBUSB) $(TOPDIR)lib


romfs:
# $(INSTALL) -m 644 $(LIBUSB_SHARED) $(TOPDIR)lib


$(OBJS): Makefile


clean:
$(RM) *.[oa] $(LIBUSB_SHARED)* libusb/*.o libusb/os/*.o




3)
编译过程中会提示<linux/socket.h>和<bits/socket.h>中的相关定义冲突;修改“source/lib/include/linux/socket.h”中冲突的地方,增加类如如下的条件编译宏
#ifndef __BITS_SOCKET_H
....
#endif //#ifndef __BITS_SOCKET_H




4)编译过程中会提示“struct iovec”重复定义,修改“source/lib/include/linux/uio.h”中如下定义,增加条件编译宏,解决编译问题。
#ifndef _BITS_UIO_H
/* A word of warning: Our uio structure will clash with the C library one (which is now obsolete). Remove the C
   library one from sys/uio.h if you have a very old library set */


struct iovec
{
void __user *iov_base;/* BSD uses caddr_t (1003.1g requires void *) */
__kernel_size_t iov_len; /* Must be size_t (1003.1g) */
};
#endif


在我的机器上,按照以上操作后,系统编译OK,仅供参考。






0 0