Serial Flash Loading

The Gateway has the feature that the firmware can be upgraded via USB.

There are two pieces of firmware, the bootloader and the application:
 * The bootloader starts at location 0x0000 in flash and contains the code required to copy over the main application.
 * The main application starts at location 0x1000 in flash and contains the main application code.

All devices are preprogrammed with the bootloader and application. When the Gateway starts, the bootloader loads and if there is nothing to do then jumps to the start of the application.

Configuring the Gateway to Accept a new Firmware Image
To start the firmware update process you must first start the application and enter the command to switch control to bootloader. This is done by pressing a key combination "Control-_". This is done by pressing the following three buttons at the same time: This complicated key combination was chosen to prevent accidental entry into the bootloader, since doing so terminates the main application.
 * Control
 * Shift
 * -/_ button (to the right of the 0 button and left of the +/= button on a US keyboard)

Once you do so, you will be asked to confirm whether you want to continue. Press 'Y' or 'y' to continue; any other button will terminate the command.

If you pressed 'Y' or 'y' then you will notice that the device becomes unresponsive. At this time, look at the title bar of the terminal window and note what COM port this device is using (e.g. COM45).

Close the terminal window. If you don't then this won't work.

Now the Gateway is ready to receive a new firmware image. If for any reason you do not want to continue then power cycle the Gateway now and it will return to normal operation.

Using the Serial Flash Loader Application
Assuming you want to continue, open a command prompt window (in Windows 7 click on the Start button and enter "cmd.exe" in the search bar and click on the application listed).

You will now need to know the location in your file system of two things:
 * The serial flash utility, sflash.exe. For this tutorial we assume it is located at C:\TeslaTools\sflash.exe
 * The firmware image you want to load, for example TeslaGatewayFirmware2013_02_27.bin. For this tutorial we assume it is located in the same directory as above, at C:\TeslaTools.

In the command prompt window, navigate to the directory containing the files: cd c:\TeslaTools

If you would like then use the dir command to list the files in the directory and verify that they are both there.

Now run the application. This must be done correctly or your device can be bricked. C:\TeslaTools>sflash "C:\TeslaTools\TeslaGatewayFirmware2013_02_27.bin" -p 0x1000 -c 45 -d The order of arguments is:
 * "C:\TeslaTools\TeslaGatewayFirmware2013_02_27.bin" Location of firmware to be uploaded
 * -p 0x1000 where the firmware is loaded - it must be pointed here
 * -c 45 which COM port to use
 * -d

The serial flash utility will now load the firmware image. This may take a few minutes. While it is running you should see the "Remaining Bytes" counter decrementing, e.g. in the middle of the process you will see something like: Application   : C:\TeslaTools\TeslaGatewayFirmware2013_02_27.bin Program Address: 0x1000 COM Port: \\.\COM45 Baud Rate: 115200 Erasing Flash: Remaining Bytes: 00059112

Once the application has completed then you will see a message indicating the same: Application   : C:\TeslaTools\TeslaGatewayFirmware2013_02_27.bin Program Address: 0x1000 COM Port: \\.\COM45 Baud Rate: 115200 Erasing Flash: Remaining Bytes: 00000000 Successfully downloaded to device.

Failed to configure Host UART
This means that the flash loader was not able to open the COM port. This is caused by either:
 * The COM port you specified is invalid - check that this is the correct COM port
 * Another application (e.g. TeraTerm) is still using the COM port - close the offending application