Using g_mass_storage to upload programs to the EV3

A place to discus the development of leJOS for the EV3. Please do not use this section to post questions about how to use leJOS or to report problems etc.
New User
Posts: 1
Joined: Mon Aug 14, 2017 6:53 pm

Using g_mass_storage to upload programs to the EV3

Postby cmfcmf » Mon Aug 14, 2017 7:32 pm


I've used leJOS last year at our university to teach kids some JAVA using your LEGO EV3 robotics. We were using Windows 8 and connected to the EV3 via USB/RNDIS.
I talked to our admins and they installed the RNDIS driver beforehand.
However, we were constantly running into issues with Windows forgetting that the driver was installed. I assume it was a Windows problem or a problem with the management scripts the admins used to update the pcs. It was difficult to fix these issues, as the students and I don't have admin rights.

Long story short, due to configuration issues at our university, using the USB/RNDIS driver resulted in constant troubles. Of course this is not leJOS' fault. This winter, I will be mentoring a leJOS/JAVA course again. My goal is to get rid of the requirement to install any kind of drivers, so I sat down a couple of days ago, downloaded the leJOS source code and tried to understand how things work together. Using WiFI/Bluetooth/LAN also isn't an option, because it would require to buy new hardware and would (W)LAN would be difficult to integrate into our network.

First approach: Each student receives a USB drive anyways. I was thinking of altering the Eclipse plugin to save compiled .jar files onto the USB drive instead of uploading it to the robot. Then students take out the USB drive of the pc and put it into the 'normal-sized' USB port of the brick. I was able to alter the EV3Menu source code to be able to list and execute .jar files from the USB drive just fine.

  • no need to recompile the kernel, only need to update a single jar file per robot
  • need to alter the Eclipse plugin
  • switching the USB drive back and forth between PC and robot is cumbersome
  • it takes a few seconds until the PC, and even longer until the brick recognizes a USB drive has been inserted

Second approach: I went ahead and tinkered with the kernel, specifically the g_mass_storage kernel module. I was able successfully recompile the kernel with this module and connect the robot to a fresh Windows 8 installation using the small USB port. It was recognized as a flash drive immediately, without installing any drivers. Yes! To do so, I created a 32MB FAT formatted file and uploaded it to the brick. I am then able to execute:

Code: Select all

modprobe -r g_ether #unload RNDIS module
modprobe g_mass_storage stall=0 file=/home/cmfcmf/mass-storage # Load mass storage module
# EV3 will appear as USB drive at host PC
mkdir /m # Create mount point
mount -o loop,ro /home/cmfcmf/mass-storage /m # Mount mass storage file to /m

The only issue is that the files mounted at /m aren't updated with changes done from the Windows host. Only unmounting and mounting it again using the followin script updates the files at /m.

Code: Select all

umount /m
mount -o loop,ro /home/cmfcmf/mass-storage /m

This is in line with the g_mass_storage docs stating that you shouldn't even read the mass storage file while the brick is connected to a host PC - so mounting it already is a violation.

  • no need to use an extra USB drive
  • no more RNDIS support (although this might be fixable using the g_multi kernel module. I haven't looked into it, because I personally don't need to access the robot via USB/RNDIS).
  • having to recompile the kernel
  • need to alter the Eclipse plugin

  1. do you guys have any experience with g_mass_storage?
  2. can you imagine a way to circumvent the issue that the files mounted at /m don't update if I do changes from the host PC
  3. any other feedback?

I will likely post a full tutorial of these changes once I got it all working reliably.

User avatar
leJOS Team Member
Posts: 6047
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Using g_mass_storage to upload programs to the EV3

Postby gloomyandy » Mon Aug 14, 2017 9:35 pm

An interesting approach!

Before we start I can think of one further potential disadvantage of using the mass storage system. You may find that when being used by students accessing the file from both the USB module and the filesystem (even ro) could cause problems like kernal crashing wtc, or at the very least issues with the VM (and maybe menu). What you are doing is basically not a good idea! You may get away with it, but I suspect it puts you firmly in the area of not very well tested! One thing for sure if this a problem then a class of students will probably find it!

a) no.
b) not really, but you could modify the menu so that it performs the mount/unmount operations before listing the contents of the programs folder you could even arrange things so that the drive is not mounted most of the time and only when actually listing files or running an app. Another approach might be to have a background process that mounts the drive file and syncs the contents to the standard leJOS programs directory then unmounts the file. If you do it right this should be a relatively low overhead operation and can probably done via a shell script.
c) The major problem is that you will not have network access which means you lose a lot of functionality...
1) Run the program after download.
2) remote debug tools
3) copy log files etc back from the EV3
4) Ability to run all or part of your program on the PC
5) Ability to stream data (like video) from the EV3.
6) Probably others I've not thought of!
Personally I'd opt for Bluetooth (you can get a USB Bluetooth dongle for £3 pounds or so). That also gives you the capability to talk to a mobile robot, which I would have thought would make things a lot easier in a classroom setup? But I've no experience of trying to have multiple PCs and EV3s all using Bluetooth at once so it may not work so well.

But good luck with things and well done on working out how to compile the kernel, not many people have done that!
leJOS news

Return to “leJOS EV3 Development”

Who is online

Users browsing this forum: No registered users and 2 guests