Posts: 23
Joined: Mon Mar 20, 2017 3:42 pm

MTP responder with functionfs

Mon Aug 28, 2017 2:17 pm


I'm currently trying to make my Rpi Zero W act as a MTP responder. After some researchs I found out that the best way to implement it would be to use functionfs and develop a userspace driver for MTP.

I also found an open source project implementing a MTP responder in userspace at :

I have absolutely no experience with driver programming or USB devices so to get used to this framework I began with configuring a mass storage gadget and then a gadget implementing both ACM and RNDIS functions.

It's now clearer but I still lacks explanation as the buteo-mtp project comes without any information on how it works or how to use it. And the README is deprecated.

If I understand well, the only thing I need is a configured function ffs and a mounted file system of type functionfs. Then the userspace driver should be able to run.

Here is my initialisation script :

Code: Select all


set -e


case "$1" in
        echo "Creating the USB gadget"
        echo "Loading composite module"
        modprobe libcomposite

       	echo "Creating gadget directory g1"
       	mkdir -p $GADGET/g1

	cd $GADGET/g1
        if [ $? -ne 0 ]; then
            echo "Error creating usb gadget in configfs"
            exit 1;
	    echo "OK"

        echo "Creating MTP responder interface"
	mkdir -p functions/ffs.mtp
	mkdir -p configs/c.1
	mkdir -p configs/c.1/strings/0x409
	echo "Custom configuration" > configs/c.1/strings/0x409/configuration
	ln -s functions/ffs.mtp configs/c.1/

	mkdir -p /dev/mtp
	mount mtp -t functionfs /dev/mtp
	echo "OK"

	echo "Setting Vendor and Product ID's"
        echo $VID > idVendor
        echo $PID > idProduct
        echo "OK"

        echo "Setting English strings"
        mkdir -p strings/0x409
        echo $SERIAL > strings/0x409/serialnumber
        echo $MANUF > strings/0x409/manufacturer
        echo $PRODUCT > strings/0x409/product
        echo "OK"

        echo "Binding USB Device Controller"
        echo `ls /sys/class/udc` > UDC
	echo "OK"
However when I run this script (cloned from other gadgets and adapted) it stops at "Binding USB Device Controller" when it was running for other gadgets.
The only Usb Device Controller I have in /sys/class/udc is 20980000.usb

Is there a reason why I can't bind this driver to the gadget when I can for mass_storage, acm and rndis?
Am I not forgetting something?

If I run the mtp responder I have the following output :

Code: Select all

pi@raspberrypi:~ $ sudo mtpd
transport/usb/mtptransporterusb.cpp 57 : MTPTransporterUSB::activate 
transport/usb/mtptransporterusb.cpp 82 : mtp function set up 
So for the Rpi it seems to be okay but on the host side no mtp device is detected with mtp-detect.

I would be glad to have some advices because I'm not able to go further by myself and I can feel that I'm not that far from having it working ^^
Thanks in advance

Posts: 1
Joined: Sat Oct 28, 2017 4:03 am

Re: MTP responder with functionfs

Sat Oct 28, 2017 4:19 am

I just started a very similar project! I got it working by using the "g_ffs" module instead of the "usb_f_fs" module. I run the following steps (as root) and it seems to work for me:
  • /sbin/modprobe g_ffs
  • /bin/mkdir /dev/mtp
  • /bin/mount -t functionfs mtp /dev/mtp
  • /usr/bin/mtpd
I've been pushing up my development to and I'd be interested in following what features you develop!

Posts: 25
Joined: Tue Jan 05, 2016 1:31 am

Re: MTP responder with functionfs

Wed Nov 22, 2017 8:17 pm

I have also been trying to do this.

I am not using buteo or the Ubuntu mtp responder, but instead writing my own from scratch in python. It does not need any android kernel patches etc.

It doesn't work yet but it is getting close.

Posts: 23
Joined: Mon Mar 20, 2017 3:42 pm

Re: MTP responder with functionfs

Thu Jan 11, 2018 2:59 pm

Sorry for the delayed answer, I was working on another project and I came back on this just few days ago.

I still have problem making buteo-mtp work as I'm porting it on another board running a custom Linux made through buildroot.... And I have a lot of dependency problems with Qt versions because my board is running Qt5.8 and buteo-mtp depends on qt-mobility which is :
1) Not in buildroot Qt modules by default
2) Deprecated for a long time
3) Running with Qt4 only (from what I know)

I'm still trying to port it to my Linux but I suck so much with Qt framework and c++ that I may let it go for a while since other solutions are available.

Dude, this is awesome, I had few little problems making it work as your Readme seems not to be up to date with your code but otherwise it works like a charm ;)
I still have few difficulties/questions that will come and I may contact you through your github project.


Posts: 3
Joined: Sat Apr 06, 2013 9:17 am

Re: MTP responder with functionfs

Wed May 09, 2018 8:30 am


FYI a new MTP responder was developed from scratch :

Ligthweight Media Transfer Protocol (MTP) responder daemon for GNU/Linux

The uMTP-Responder allows files to be transferred to and from devices through device USB port.

Main characteristics and features

- Implemented in C.

- Lightweight implementation.

- User space implementation.

- As less dependencies as possible.

- Hook to the Gadget FS Linux layer.

- Dynamic handles allocation (No file-system pre-scan).

- (Optional) Syslog support.

What is working

- Folder listing.

- Folder creation.

- Files & Folders upload.

- Files & Folders download.

- Files & Folders deletion.

- Up to 16 storage instances supported.

What is planned

- libcomposite support.
This was tested on a Raspberry PI Zero and a Sama5D2 boards.

Return to “Advanced users”