Project Description

I plan on continuing on with my Linux Kernel Library efforts from Hackweek 19. This time I'd like to spice things up a bit by plumbing USB devices into LKL, allowing reuse of native Linux USB host and filesystem drivers on non-root Android.

Goals

  • enumerate USB devices on Android
  • use the Android USB getFileDescriptor API to obtain a file descriptor for a connected USB device
  • find out what kind of magic is needed to plumb the USB device fd into LKL
    • XHCI emulation (see crosvm implementation) or...
    • a simple proxy: Android USB fd <-> LKL GadgetFS driver <-> LKL dummy-hcd loopback
  • successfully mount a Btrfs filesystem from LKL
  • stretch goal: help out again with LKL mainlining efforts
  • stretch goal: add DocumentsProvider integration so that LKL mounts are accessible to the Android device
  • stretch goal: map a LUKS/dm-crypt device

Resources

Looking for hackers with the skills:

Nothing? Add some keywords!

This project is part of:

Hack Week 20 Hack Week 21

Activity

  • almost 2 years ago: BEEDELLROKEJULIANLOCKHART liked this project.
  • over 3 years ago: kokin10 joined this project.
  • over 3 years ago: Pharaoh_Atem liked this project.
  • over 3 years ago: dmdiss started this project.
  • over 3 years ago: dmdiss originated this project.

  • Comments

    • dmdiss
      over 3 years ago by dmdiss | Reply

      With hackweek now over, below is a summary of what I achieved. I decided to prioritize learning a new language, which saw me use Rust for the implementation. This slowed me down quite a bit, leaving:

      • revisited current upstream lkl state
        • found current UML merge submissions lack Android support, so instead fell-back to thehajime's lkl-next repo
      • rebased ceph-walkley (from hw19) against lkl-v5.10
      • submitted a couple of minor PRs upstream: 1 and 2
      • rebased ceph-walkley's embedded wireguard library against upstream
      • reworked the ceph-walkley build process to better handle kconfig and parallel build jobs
      • learned Rust's bindgen to generate lkl_host and libusb language bindings
      • investigated Linux's functionfs gadget API, mostly via the upstream example
      • wrote basic lkl boot / init program in Rust
      • wrote libusb dev/config/interface/endpoint enumeration utility in Rust

    • dmdiss
      over 3 years ago by dmdiss | Reply

      I've published my Hackweek 20 source code at https://github.com/ddiss/walkley-usb. This is my first proper Rust project, which probably shows. To build, it requires lkl-next-5.10 liblkl at $LKL_DIR, which will be statically linked.

    • dmdiss
      over 2 years ago by dmdiss | Reply

      I plan on continuing with this project during the upcoming Hackweek 21. Upstream LKL appears to be lagging behind mainline a bit, so I'll probably start there. After that I'd like to get the USB host device &lt;-&gt; LKL GadgetFS driver &lt;-&gt; LKL dummy-hcd loopback I/O path working on "regular" openSUSE Linux first before attempting to port to Android.

      • dmdiss
        over 2 years ago by dmdiss | Reply

        I've pushed my work from Hack Week 21 to https://github.com/ddiss/walkley . USB device pass-through configuration is triggered via the ./walkley --usb VENDOR_ID:PRODUCT_ID where VENDOR_ID and PRODUCT_ID match a host-connected USB device.

        USB I/O proxying between host chardev and lkl functionfs endpoints needs more work and hasn't been merged yet.

        Demo:

        ``` Host shell: walkley (main)> lsusb ... Bus 004 Device 002: ID 11b0:3307 ATECH FLASH TECHNOLOGY UHSII uSD Reader

        walkley (main)> make -j3 DEBUG=yes LKLCONFIG=lklusbconfig && ./walkley --usb 11b0:3307

        [ 0.014564] dummyhcd dummyhcd.0: USB Host+Gadget Emulator, driver 02 May 2005 [ 0.014576] dummyhcd dummyhcd.0: Dummy host controller [ 0.014589] dummyhcd dummyhcd.0: new USB bus registered, assigned bus number 1 [ 0.014792] hub 1-0:1.0: USB hub found [ 0.014813] hub 1-0:1.0: 1 port detected [ 0.015186] Btrfs loaded, crc32c=crc32c-generic ... (walkley.c:865) checking USB bus at /dev/bus/usb/004 (walkley.c:884) opening USB device at /dev/bus/usb/004/002 (walkley.c:760) read 62 bytes data from /dev/bus/usb/004/002 /dev/bus/usb/002/003 Vendor=0x11b0 Product=0x3307 -> matched, proceeding with passthrough. (walkley.c:696) USB interface Class=8, SubClass=6, Protocol=80, Endpoints=2 [ 0.292754] file system registered (walkley.c:715) -> EP 9: IN (0x81) (walkley.c:723) -> Skipping non-endpoint type 0x30 (walkley.c:718) -> EP 22: OUT (0x2) (walkley.c:723) -> Skipping non-endpoint type 0x30

        walkley:/> cat /proc/mounts none / rootfs rw 0 0 proc /proc proc rw,relatime 0 0 configfs /configfs configfs rw,relatime 0 0 devtmpfs /dev devtmpfs rw,relatime 0 0 walkley /walkley_ffs functionfs rw,relatime 0 0

        walkley:/> cat /configfs/usbgadget/0x0/idProduct 0x3307 walkley:/> cat /configfs/usbgadget/0x0/idVendor 0x11b0 walkley:/> ls /walkley_ffs . .. ep0

        ```

    Similar Projects

    This project is one of its kind!