Results 1 to 8 of 8
  1. #1

    USB/IP on android

    I'm working on a project that requires an android port of the USB/IP project. I managed to build the required modules for the phone kernel (using the NDK) and build the user space application (using crosstool-ng for glibc requirements) but I cannot find any information on the net how to set the correct permissions for the usbip userland application. When I execute the usbip binary I get "sh: usbip: permission denied" although I'm logged in on the phone as root (su) and the permissions are correct.

    Any help will be appreciated.

  2. #2
    Hi evdsande,

    I am doing similar thing. I can compile kernel modules. But when I tried to compile userspace application, I realized that was removed from Android, which is required by usbip application. How did you compile it?

    If you can compile it, then you can avoid "permission denied error" by using eng build of android.


  3. #3
    Hi Bernard,

    I solved the "permission denied issue" some time ago but ran into a new issue involving an segfault at the getopt() call in usbip client app. This I'm still not able to solve.
    I used crosstool-ng using this -- -- as a guide to create the toolchain. Then I used the following sequence to build usbip

    Get the following libraries from gnu: glib-2.18.4.tar.bz2, sysfsutils-2.1.0.tar.gz

    For glib-2.18.4:

    echo "glib_cv_long_long_format=ll
    ac_cv_func_realloc_works=yes" > arm.cache

    ./configure --host=arm-unknown-linux-gnueabi --target=$TOOLCHAIN_EABI CFLAGS="-g -O0" CPPFLAGS="$TOOLCHAIN_INCLUDES" \
    LDFLAGS="$TOOLCHAIN_LIBS" --prefix="$PREFIX" --enable-static --enable-shared --cache-file=arm.cache

    Used settings are:
    TOOLCHAIN_INCLUDES=-I$HOME/data/include -Ipath_to_x-tools/arm-unknown-linux-gnueabi/include
    TOOLCHAIN_LIBS=-L$HOME/data/lib -Lpath_to_x-tools/arm-unknown-linux-gnueabi/lib

    $HOME/data is my local installation directory

    For libsysfs:

    ./configure --build=i686-pc-linux-gnu --host=arm-unknown-linux-gnueabi --target=$TOOLCHAIN_EABI --prefix="$PREFIX" \
    CFLAGS="-g -O0" CPPFLAGS="$TOOLCHAIN_INCLUDES" LDFLAGS="$TOOLCHAIN_LIBS" --enable-shared --enable-static

    For libsysfs:
    TOOLCHAIN_INCLUDES=-I$HOME/data/include -Ipath_to_x-tools/arm-unknown-linux-gnueabi/include -I$HOME/data/include/glib-2.0

    the make install of glib-2.0 misses the copy of glibconfig.h to the $HOME/data/include directory so you have to do that by hand

    Now usbip/usbipd can be build, I use the following configure build up from info found in this NDK example:

    ./configure --host=arm-unknown-linux-gnueabi --target=$TOOLCHAIN_EABI --enable-static=libusbip \
    LDFLAGS="-nostdlib -Wl,--entry=main,-rpath=$TARGET_DATAPATH,-rpath-link=$PREFIX/lib,-dynamic-linker=$TARGET_LIBPATH/ -lsysfs -lglib-2.0 -lc" \
    --prefix=$PREFIX --datarootdir=$PREFIX/data --datadir=$PREFIX/data --with-usbids-dir=$TARGET_DATAPATH \
    --includedir=$PREFIX/include --libdir=$PREFIX/lib

    TARGET_DATAPATH=/data/data/usbip # will be located on the phone
    TARGET_LIBPATH=/lib # will be located on the phone

    To run the usbip application you have to copy it to the phone in a partition that allows execution, e.g. /lib and next you copy the libraries (,, from x-tools and the created libraries to /lib on the phone) to /lib on the phone (this is identified in the configure with -rpath=). Then you make the symbolic links (>,>,> and> and> You can find the dependencies of usbip with running arm-unknown-linuxgnueabi-ldd on usbip (root=$HOME/data). Both usbip and need permissions be set 777.

    From here on I'm stuck, I'm able to remote debug the application but on execution of getopt() it will segfault. I have not yet figured out what the cause is.

    If you have any ideas for me how to get past the segfault I will be pleased.

    Best regards, Eric

  4. #4
    Hi Eric,

    I feel that my existing toolchain can compile kernel modules and applications, it is not reasonable to change it for this application. getopt() is in libc, It should have existed on your phone before you overwrote it. Having an incompatible might be the reason of your segfault.

    I saw the comments somewhere that libsysfs is not much useful so it was removed from Android. But I found the following source code.

    The code is confusing to me. But I copied the sysfslib from it to my own staging/usbip/userspace folder. With some minor changes, I was able to compile it as shared library, and compile usbip. I can't compile usbipd without glib, which I don't need at the moment.

    I am debugging usbip now. I got usbip_net_send() error. It didn't work yet because I am using existing usbip server and it is not compatible.

    Best wishes


  5. #5
    Hi Bernard,

    Can you tell me which toolchain you use to compile the code?

    Best Regards, Eric

  6. #6

  7. #7
    Hi Bernard,

    I'm trying to follow your path in using the ndk, but I get different errors now

    Are you willing to share your configuration/Makefiles?


  8. #8
    A very very late answer to Eric's question: the segfault is because the arguments in command line are not passed to the main() function in bind-driver.c, i.e., argv is null. When getopt() tries to access the strings in null pointer argv, segfault happens. My solution is using scanf to pass strings, instead of through arguments for main().

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts