de.cau.cs.kieler.klots.util
Class NXTFlashUpdate

java.lang.Object
  extended by de.cau.cs.kieler.klots.util.NXTFlashUpdate

public class NXTFlashUpdate
extends Object

Class to allow the updating and verification of the leJOS firmware. The firmware image files can be located inside of jar archives, such as Eclipse plugins, as well as on the file system. This adapted implementation is based on Andy Shaw original code.

Rating red

Constructor Summary
NXTFlashUpdate(NXJFlashUI ui)
           
 
Method Summary
 byte[] createFilesystemImage()
          Create a memory image for the leJOS file system.
 byte[] createFirmwareImage(String vmPath, String menuPath, String klotsPath)
          Create the memory image ready to be flashed to the device.
 NXTSamba openSambaDevice(int timeout)
          Locate and open an nxt device in SAM-BA mode.
 void rebootDevice(NXTSamba nxt)
           
 void resetDevice(NXTInfo nxt)
          Attempt to restart the nxt in SAM-BA mode.
 void updateDevice(NXTSamba nxt, byte[] memoryImage, byte[] fs, boolean verify)
          Update the NXT with the new memory image.
 void updateDevice(NXTSamba nxt, byte[] memoryImage, byte[] fs, boolean verifyFirm, boolean verifyFS, boolean reboot)
          Update the NXT with the new memory image.
 int verifyFilesystem(NXTSamba nxt, byte[] fs)
          Verify the file system downloaded to the device.
 int verifyFirmware(NXTSamba nxt, byte[] image)
          Verify the firmware downloaded to the device.
 int verifyPages(NXTSamba nxt, int first, byte[] memoryImage)
          Verify that the contents of the nxt flash memory match the supplied image.
 void writeFilesystem(NXTSamba nxt, byte[] fs)
          Format the nxt file system.
 void writeFirmware(NXTSamba nxt, byte[] memoryImage)
          Update the NXT with the new memory image.
 void writePages(NXTSamba nxt, int first, byte[] memoryImage)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NXTFlashUpdate

public NXTFlashUpdate(NXJFlashUI ui)
Parameters:
ui -
Method Detail

createFirmwareImage

public byte[] createFirmwareImage(String vmPath,
                                  String menuPath,
                                  String klotsPath)
                           throws IOException,
                                  FileNotFoundException
Create the memory image ready to be flashed to the device. Load the firmware and menu images into memory ready for flashing.

Parameters:
vmPath - Relative path to the leJOS VM firmware image in the KLOTS plugin jar file.
menuPath - Relative path to the leJOS menu system firmware image in the KLOTS plugin jar file.
klotsPath - Full path to the KLOTS plugin jar file.
Returns:
Memory image ready to be flashed to the device.
Throws:
IOException
FileNotFoundException

createFilesystemImage

public byte[] createFilesystemImage()
Create a memory image for the leJOS file system. We create an in memory image for the settings, and directory pages. We then fill the remainder of the space with a test pattern to help detect any flash memory problems

Returns:
byte array containing the file system data

openSambaDevice

public NXTSamba openSambaDevice(int timeout)
                         throws NXTCommException,
                                IOException
Locate and open an nxt device in SAM-BA mode. If none are present wait up to timeout ms checking to see if one has become available.

Parameters:
timeout -
Returns:
NXTSamba
Throws:
NXTCommException
IOException

resetDevice

public void resetDevice(NXTInfo nxt)
                 throws NXTCommException,
                        IOException
Attempt to restart the nxt in SAM-BA mode.

Parameters:
nxt - The device to reset
Throws:
NXTCommException
IOException

verifyPages

public int verifyPages(NXTSamba nxt,
                       int first,
                       byte[] memoryImage)
                throws IOException
Verify that the contents of the nxt flash memory match the supplied image.

Parameters:
nxt - device to verify
first - starting address
memoryImage - memory address to compare with
Returns:
number of mismatched bytes found
Throws:
IOException

writePages

public void writePages(NXTSamba nxt,
                       int first,
                       byte[] memoryImage)
                throws IOException
Parameters:
nxt -
first -
memoryImage -
Throws:
IOException

writeFirmware

public void writeFirmware(NXTSamba nxt,
                          byte[] memoryImage)
                   throws IOException
Update the NXT with the new memory image.

Parameters:
nxt - Device to update, must be open in SAM-BA mode.
memoryImage - New image for the device
Throws:
IOException

writeFilesystem

public void writeFilesystem(NXTSamba nxt,
                            byte[] fs)
                     throws IOException
Format the nxt file system.

Parameters:
nxt - Device to format
fs - File system image to use
Throws:
IOException

verifyFirmware

public int verifyFirmware(NXTSamba nxt,
                          byte[] image)
                   throws IOException
Verify the firmware downloaded to the device.

Parameters:
nxt - device to verify
image - firmware image to compare against
Returns:
the number of mismatched bytes.
Throws:
IOException

verifyFilesystem

public int verifyFilesystem(NXTSamba nxt,
                            byte[] fs)
                     throws IOException
Verify the file system downloaded to the device.

Parameters:
nxt - device to verify
image - file system image to compare against
Returns:
the number of mismatched bytes.
Throws:
IOException

rebootDevice

public void rebootDevice(NXTSamba nxt)
                  throws IOException
Parameters:
nxt -
Throws:
IOException

updateDevice

public void updateDevice(NXTSamba nxt,
                         byte[] memoryImage,
                         byte[] fs,
                         boolean verify)
                  throws IOException
Update the NXT with the new memory image.

Parameters:
nxt - Device to update, must be open in SAM-BA mode.
memoryImage - New firmware image for the device
fs - File system image.
verify - Should we verify the updates?
Throws:
IOException

updateDevice

public void updateDevice(NXTSamba nxt,
                         byte[] memoryImage,
                         byte[] fs,
                         boolean verifyFirm,
                         boolean verifyFS,
                         boolean reboot)
                  throws IOException
Update the NXT with the new memory image.

Parameters:
nxt - Device to update, must be open in SAM-BA mode.
memoryImage - New firmware image for the device
fs - File system image.
verifyFirm - Should we verify the firmware updates?
verifyFS - Should we verify the file system updates?
reboot - Reboot after update.
Throws:
IOException