Creating a bootable SD card (old)

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 /home/root/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.


Discussion

  • Alex
    Alex
    2013-09-28

    I couldn't edit the wiki due to missing rights, so I'll post a comment here for some input:

    • easy way to run Ubuntu on Windows is VMware player, start it with Ubuntu ISO, after booting Ubuntu ISO, the "Try Ubuntu" button for the portable version of Ubuntu is sufficient, so no virtual installation has to be done. For the next steps create a work folder on Ubuntu "Desktop" (only note that such a folder is RAMdisk-based, it will no be persisted)

    • Use an USB-Stick to transfer files from the Windows host to the virtual Ubuntu (VMware will map a physical USB stick to either the host Windows or the guest VM, depending on which window has the focus. Switching just requires removing stick, changing window focus and inserting USB stick again.

    • there might be 3 sd* disks visible in Ubuntu: usually sda is the boot ISO file, sdb is the usb-stick and sdc is the sd card

    • in the VM, locate desktop/<yourfolder>/lejos/wpa_suplicant.conf
      edit it with gedit:
      replace psk=fe....fee with psk="your wifi psk password"
      (note the quotation marks used for cleartext psk's")
      (later on, this file can be found in /etc/wpa_suplicant.conf on the SD card)

    • "Ctrl-Alt-t" in Ubuntu starts a shell

    • use "sudo mount | grep sd" in the Ubuntu shell to find out the mount points of the drives
      e.g. output is something like "/media/ubuntu/something": then the mountpoint for update_sh-script is "/media/ubuntu"


    Troubleshooting:
    - if the update script fails, its usually because the mount point parameter was incorrect
    - if the SD card gets unusable, the windows commandline tool "diskpart" can help to low level format it (lots of help for diskpart on google)
    - if the brick boots from SD card, but boots endlessly, its either because supplicant.conf Wifi parameters are incorrect or because the Wifi router does not assign an IP address due to configured restrictions on the router. Check connection status on router, look for restrictions on the Wifi router config and verify the supplicant.conf. Make sure transfers mode is correct, if wpa_suplicant.conf gets copied from an existing file, make sure the line endings are of type Unix, not Windows(LF only, not CR LF)


    SD Backup:
    Once everything is running, a binary backup of the SD card can be done using the free tool "Win32 Disk Imager"


    Update:
    If you need to update to a newer version of lejos, you don't need to recreate the whole sd card:
    Just unpack the newer lejos bz2 image with 7zip on Windows, find the file ev3classes.jar and just copy that file to the EV3 (/home/root/lejos/lib) using SSH/Winscp. You will rarely need to update the whole SD card.
    If you want to update the Java runtime on your sd card, do the same: copy the file to the brick and use "tar" in an SSH session to expand it to the needed folders.

     
    Last edit: Alex 2013-09-28
  • garzol
    garzol
    2013-10-14

    Thank you for this contribution. Great job!
    I can confirm that it works fine with a netgear N150 WNA1100 wifi adapter
    A minor remark concerning update_sdcard.sh, line 63:
    tar -C (...) -axf $jvm
    got an error "tar: option a is invalid"
    I replaced it with a 'z' and everything worked fine.
    (using ubuntu in virtualbox on vista)

    Brilliant.

     
  • Chris Pitcher
    Chris Pitcher
    2013-11-21

    Is it worth adding to the instructions above that it works via the USB cable for anyone that does not have a compatible USB wifi dongle available? As a complete newbie I didn't realise that I could just plug in and play - I have just plugged the EV3 brick into a laptop running ubuntu and can telnet into it no problem :D