Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

leJOS EV3 Creating a bootable SD card

Andy Shaw Lawrie Griffiths

Creating a bootable SD card


These tools are designed to help you create a bootable SD card for the Lego EV3. This card can then be used to run Java/leJOS programs on the device. The SD card image is based on the standard Lego firmware but has been enhanced to provide the following:
1. The Lego device access Kernel modules are loaded without having the Lego VM running.
2. The WiFi stack is loaded to allow connection to the EV3 via a supported USB WiFi adaptor. This allows you to connect to the EV3 via Telnet, SSH and NFS and makes program development very simple.
3. Driver modules for Atheros ATH9K and Realtex 8192cu based devices are included and will be loaded automatically based on the detected WiFi chipset. The EV3 has been tested using the NetGear WNA1100 and EDIMAX EW-7811Un adaptors, but others may work if they use the same chipsets.
4. Installs the Oracle Java SE Embedded JVM, JNA and leJOS classes so you are ready to run Java programs on the EV3.
5. Includes shutdown scripts to power off the device when Linux is shutdown.

So what do you need?
1. A micro SD card 2Gb or more in size.
2. A WiFi dongle that is supported by the EV3. At the moment the only devices used are the NetGear WNA1100 and EDIMAX EW-7811Un. But hopefully this list will be expanded.
3. A PC running Linux (the tools were created/tested on Ubuntu 12.10) to create the SD card and to use for program development. This can be a Windows system with Linux running under VirtualBox.
4. A WiFi Network and details of the SSID and PSK etc. needed to connect to it.
5. A download of the Oracle Java SE Embedded JVM.
6. A Telnet or ssh program to connect to the EV3
7. Optionally an NFS server to allow you to easily run programs developed on your PC.

Getting started.
1. Download the latest leJOS creation tools (file lejosimage.bz2) from:
https://sourceforge.net/projects/lejos/files/lejos-EV3/
2. Unpack them on your Linux system using tar xfj lejosimage.bz2. This will create a directory called lejosimage that contains the tools.
3. Download the Oracle Java SE Embedded JVM from the Oracle download site:
http://www.oracle.com/technetwork/java/embedded/downloads/javase/javaseemeddedev3-1982511.html
copy the downloaded tar file into the lejosimage directory.
4. You now need to set things up to allow access to your WiFi network. To do this you need to edit the wpa_supplicant.conf file to provide the details of your network. The sample file looks like this:

ctrl_interface=/var/run/wpa_supplicant
# Pers
network={
        ssid="legolan"
        key_mgmt=WPA-PSK
        psk=8e9116c7665b56a95c03e3e23ec707f4cbe18fea82d620d9b85b2f79fe34cfee
        pairwise=CCMP TKIP
        group=CCMP TKIP
        proto=RSN
}

Which basically defines a network that has an SSID of “legolan” and uses WPA2 authentication. You can find more details of the various settings and configuration options here:
http://linux.die.net/man/5/wpa_supplicant.conf
http://linux.die.net/man/8/wpa_supplicant
You will probably need to run the wpa_passphrase command:
http://linux.die.net/man/8/wpa_passphrase
to create the shared key required to connect to your network.

Ok now we are ready to create the image. First off we need to format the card. basically we are creating two partitions one DOS, the second Linux. To format the card hook up an SD card reader and use the command:

./format_sdcard.sh

This will prompt you for sudo access as required. Take care when specifying the device to format, you could end up formatting your hard disk!

Once you have a formatted card we can create the image. First remove and re-insert the card. On most Linux systems the system will automatically mount the two partitions (called LMS2012 and LMS2012_EXT), if they are not mounted automatically you will need to mount them before continuing. Make a note of the location that that card has been mounted (on Ubuntu this will be /media/<your username="">/), then issue the command:

./update_sdcard.sh <mount point> <JVM tar file>

Where <mount point> is the location that the SD card is mounted and <JVM tar file> is name of the file you downloaded previously. On my system the command line would be:
./update_sdcard.sh /media/andy ejre-7u21-fcs-b11-linux-arm-sflt-headless-04_apr_2013.tar.gz
The script will then go ahead and create the boot image.

Once complete eject the SD card using the eject option in the Linux file browser and remove it from the reader. Make sure the EV3 is powered off and then insert the card into the EV3 SD card slot. Press the enter button to boot the EV3. As the system boots it will turn on the Red LEDs when these turn off the EV3 will be ready to use. Shortly after the red light turns off the LCD screen will display the leJOS logo. Just below this you should see the IP address assigned to the EV3. If you do not see an IP address displayed then something has gone wrong with the WiFi setup, check that you have correctly configured the wpa_supplicant.conf and that you are using a supported WiFi device. If necessary re-run the update_sdcard.sh command to recreate the image.

Once the EV3 has booted you should be able to connect to the displayed IP address using either ssh or telnet. Login as root with no password. Once connected you can now check that it is possible to run leJOS based Java programs. cd to the the /lejos/samples directory and type:

jrun EV3HelloWorld

After a short while the program should play some sounds, light up the EV3 LEDs and display a message on the EV3 display.