lejos.pc.tools
Class NXJFlashUpdate

java.lang.Object
  extended by lejos.pc.tools.NXJFlashUpdate

public class NXJFlashUpdate
extends java.lang.Object

Class to allow the updating and verification of the leJOS firmware.

Author:
andy

Constructor Summary
NXJFlashUpdate(NXJFlashUI ui)
           
 
Method Summary
 byte[] createFilesystemImage()
          Create a memory image for the leJOS file system.
 byte[] createFirmwareImage(java.io.File vmName, java.io.File menuName, java.lang.String home)
          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)
           
 int verifyFilesystem(NXTSamba nxt, byte[] fs)
           
 int verifyFirmware(NXTSamba nxt, byte[] image)
          Verify the firware 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NXJFlashUpdate

public NXJFlashUpdate(NXJFlashUI ui)
Method Detail

createFirmwareImage

public byte[] createFirmwareImage(java.io.File vmName,
                                  java.io.File menuName,
                                  java.lang.String home)
                           throws java.io.IOException
Create the memory image ready to be flashed to the device. Load the firmware and menu images into memory ready for flashing. The command line provides details of the location of the image files to be used.

Parameters:
commandLine - Options for the location of the firmware and menu.
Returns:
Memory image ready to be flashed to the device.
Throws:
java.io.IOException

createFilesystemImage

public byte[] createFilesystemImage()
Create a memory image for the leJOS file system. We create an in memory image for the settinigs, 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,
                                java.io.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.

Returns:
Throws:
NXTCommException
java.io.IOException

resetDevice

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

Parameters:
nxt - The device to reset
Throws:
NXTCommException
java.io.IOException

verifyPages

public int verifyPages(NXTSamba nxt,
                       int first,
                       byte[] memoryImage)
                throws java.io.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:
java.io.IOException

writeFirmware

public void writeFirmware(NXTSamba nxt,
                          byte[] memoryImage)
                   throws java.io.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
commandLine - Update options
Throws:
java.io.IOException

writeFilesystem

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

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

verifyFirmware

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

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

verifyFilesystem

public int verifyFilesystem(NXTSamba nxt,
                            byte[] fs)
                     throws java.io.IOException
Throws:
java.io.IOException

rebootDevice

public void rebootDevice(NXTSamba nxt)
                  throws java.io.IOException
Throws:
java.io.IOException

updateDevice

public void updateDevice(NXTSamba nxt,
                         byte[] memoryImage,
                         byte[] fs,
                         boolean verify)
                  throws java.io.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:
java.io.IOException

updateDevice

public void updateDevice(NXTSamba nxt,
                         byte[] memoryImage,
                         byte[] fs,
                         boolean verifyFirm,
                         boolean verifyFS,
                         boolean reboot)
                  throws java.io.IOException
Throws:
java.io.IOException