Creating a bootable SD card

Andy Shaw Lawrie Griffiths

Creating a bootable SD card


Note: The way that the leJOS SD card is created has changed at the 0.8.0-alpha release.

You need to 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 formatted as FAT32.
2. Optionally, 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 or Microsoft Windows, or any operating system that can run Eclipse and a full Java JDK.
4. Optionally, 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 for the EV3.
6. Optionally, a Telnet or ssh program to connect to the EV3.

Getting started.

At the 0.8.0 release onwards, you do not need to write an image file to your SD card. Instead you can just copy the relevant files to it as a normal file system or Windows drive, and when you boot it in the EV3, it will be reformatted to run leJOS EV3.

For this to be possible, the card must be formatted with a FAT32 file system of at least 200Mb and must contain no files. Most new cards will contain a FAT32 file system that occupies the whole card, and that is fine.

If your card was used for a previous version of leJOS it will not meet these conditions as the first partition is a FAT (not FAT32) one and only 50Mb.

If, for any reason, your card does not meet these conditions, you will need to reformat or repartition it. If your card is a 2Gb one, check that it has a FAT32, not FAT, partition.

You can use disk partition utilities to repartition your SD card if you are confident with them.

However, the simplest way to repartition it is to use the sd500.zip file from the sourceforge download page, unzip it and write the sd500.img image file to your card. It will reformat your card to contain a single 500Mb FAT32 partition. On Windows, you can use https://sourceforge.net/projects/win32diskimager/ to write the image to the file. Make very sure you specify the correct drive as it wipes all data from the specified drive.

Once you have a suitably formatted SD card, do the following:

  1. Download the zipped image file (file lejosimage) from:
    https://sourceforge.net/projects/lejos/files/lejos-EV3/ and unzip it, to get the single sd.img file.
  2. Download the Oracle Java SE Embedded JRE file from the Oracle download site:
    http://www.oracle.com/technetwork/java/embedded/downloads/javase/index.html

The file to use is ejre-7u51-fcs-b13-linux-arm-sflt-headless-18_dec_2013.tar.gz (ARMv5 Linux - Headless EABI, SoftFP ABI, Little Endian). It's the last ARM build in the list.

OK, now we are ready to create the image.

  1. Delete any existing files on your SD card
  2. Unzip leosimage.zip to the SD card drive
  3. Copy the Oracle JRE .gz file to the SD card drive
  4. Safely eject the SD card.
  5. Make sure the EV3 is switch off, insert the SD card, and boot the EV3.

The EV3 should then reformat your SD card and install leJOS EV3. The LCD screen will show you the progress of the reformat and install. The whole process takes about 8 minutes.

Once this is finished you are ready to configure Wifi (if required) and then start developing with leJOS.

If you want to configure Wifi yourself, rather than use the leJOS EV3 menu to do it, you can write a wpa_supplicant.conf file to the root directory on the SD card before inserting it into the EV3, and that configuration will be used.

If you look at your SD card after leJOS has reformatted it, you will see that the FAT32 partition has been resized to about 500Mb. A Linux ext2 partition will have been added to the card. It is used for running leJOS. It won't be visible on Microsoft Windows.

Another subtle change is that the uImage file will have been renamed as uImageNoobs and the uImageStandard file will have been named as uImage. That is because leJOS now uses two Linux kernels. It uses uImageNoobs (originally uImage) to repartition the card and install leJOS, and uImage (originally uImageStandard) to run leJOS.

You may also notice that some configuration files have been copied to the FAT32 partition.