flipperzero-firmware icon indicating copy to clipboard operation
flipperzero-firmware copied to clipboard

USB Mass Storage emulation (DRAFT)

Open kevinwallace opened this issue 2 years ago • 8 comments

What's new

I created this hoping that I would be able to put a bunch of bootable ISOs on a microSD card, then emulate and boot off of them using my Flipper Zero. It turns out that it's WAY too slow for this to be usable (120~180kBps in my testing), but probably still fast enough for some uses of "Twin Duck" mode requested in #1040. Presenting this as a draft PR to get people's thoughts on integrating it with BadUSB.

Open questions:

  • "Mass Storage" app is a bit thrown together, mostly copied from BadUSB as a template. Should this be completely integrated into BadUSB or should both apps be kept?
  • USB stuff is currently implemented in applications/mass_storage/helpers/ instead of targets/f7/furi_hal/ like the other USB modes. Should it be moved there? SCSI code, too?
  • Dual USB Mass Storage + HID mode. How do we get them to play along? It might be possible to throw together a combined usb_device_descriptor and set of FuriHalUsbInterface functions that delegate to existing unmodified HID and Mass Storage functions, or it might be more involved. Haven't attempted this yet.
  • Speed. Can it be improved? If the bottleneck is SD SPI, then probably no. If the bottleneck is USB or FS code, maybe.

If someone is interested in taking this code, polishing it up, and integrating it with BadUSB -- or just using it as a starting point for their own independent implementation -- I would be thrilled. My personal use case didn't pan out, and I'm not likely to need "Twin Duck" myself, but it would be a shame to throw this out since it could be useful to others, and given the trial, error, blood, sweat, and tears it took to get to this point.

Here I am booting Debian off of my Flipper. GRUB took several minutes to load. :)

mass_storage_boot_debian

Verification

  • Create mass_storage/ dir on SD card and place disk images in it.
  • Open "Mass Storage" app (under plugins) and select your image
  • Connect Flipper to computer and access over USB Mass Storage interface

Checklist (For Reviewer)

  • [ ] PR has description of feature/bug or link to Confluence/Jira task
  • [ ] Description contains actions to verify feature/bugfix
  • [ ] I've built this code, uploaded it to the device and verified feature/bugfix

kevinwallace avatar Mar 26 '22 05:03 kevinwallace

Unfortunately, this is exactly the case, SD cards are very slow when connected via SPI, and the maximum theoretical speed is around 500 kbps. That is why we have abandoned the idea of mass storage emulation.

DrZlo13 avatar Mar 26 '22 09:03 DrZlo13

There are couple things that can improve speed:

  • DMA for SPI
  • Read Cache

skotopes avatar Mar 27 '22 16:03 skotopes

Maybe it can be usable for tiny stuff like one file linux https://github.com/zhovner/OneFileLinux

zhovner avatar Jul 08 '22 11:07 zhovner

+1 This would be amazing... I really hope this will get implemented

Woodie4 avatar Aug 20 '22 18:08 Woodie4

The best would be to use Ventoy (https://www.ventoy.net) on it... but don't absolutely know if it's possible... (i'm just a user..)

Foul avatar Aug 25 '22 15:08 Foul

The best would be to use Ventoy (https://www.ventoy.net) on it... but don't absolutely know if it's possible... (i'm just a user..)

For booting a full ISO it's too slow, but maybe could be just enough to boot rEFInd when your bootloader is broken.

Also maybe small payloads 🤔

kowalski7cc avatar Dec 21 '22 09:12 kowalski7cc

I would say even if it's slow it can be useful.

Would be also nice if the data flipper collects could be accessed - that's typically small but might be useful to view from the PC.

hramrach avatar Dec 29 '22 15:12 hramrach

Just as a potential use case for even very slow mass storage emulation: I stumbled across this PR when looking to see if the Flipper Zero might be able to do one of the things that I want, which is to scan an RFID card and present its ID as a text file over USB.

turmoni avatar Feb 02 '23 12:02 turmoni

Closing, subsumed by https://github.com/flipperdevices/flipperzero-good-faps/pull/1

kevinwallace avatar Jul 27 '23 04:07 kevinwallace