===============================================================================
    FDTCE.exe - Firmware Download Tool
===============================================================================

Description:

    FDT is a CE/WM application that downloads Sierra Wireless wireless
    modem firmware images.  Proper driver installation is required prior to 
    using this tool.
    
    
Command line options:

    fdtce.exe -o [normal/emergency] -d [9x00/9x15/9x25/9x30/g3k/g5k] 
              -fd [folder name] -f [file name 1] [file name 2] 
              -p [port #] -h -a -r -q -force -slot [slot #]
              -baud [baud rate] -nsc -ssdp -multi -reset -timeout [mins]
              -connectretry [retry #] -connectdelay [delay in seconds]
              -statuscheckdelay [delay in seconds] -ignswto
			  -gui -nogui -silent
    
    -h  Print out command line usage.
    
    -d  [9x00/9x15/9x25/9x30/g3k/g5k]
	This option specifies the device type.  Must be lower cases as below.
	This option is mandatory for emergency download and flash erase process,
	but optional for normal image download process.  If this option is
	omitted, 9x15 is the default setting.
        - 9x00: This is a 9x00 based device.
        - 9x15: This is a 9x15 based device.
        - 9x25: This is a 9x25 based device.
        - 9x30: This is a 9x30 based device.
        - g3k: This is a Gobi3000 device.
        - g5k: This is a Gobi5000 device.
        
    -fd [folder to firmware images]
        This specifies the folder location of the firmware images.  If this
        option is not specified, FDT will take the current working folder as
        the image folder location.
        
    -f  [image file 1] [image file 2]
    	This specifies the image files that need to be downloaded.  The usages
    	are different as below upon different devices.
    	- For G3K devices: There is no need to specify image names.  FDT will
    	  search for amss.mbn and uqcn.mbn files under the image folder (either
    	  specified or the current folder).
    	- For G5K devices: Image file 1 indicates the firmware image; while 
    	  image file 2 indicates the configuration image.  If the images contain
    	  the absolute path info, the folder information specified in "-fd" option
    	  is ignored; otherwise, FDT will search for the specified images under
    	  the image folder (either specified or the current folder).  If there
    	  are no images specified, FDT will search for the first pair of 
    	  firmware and configuration image in the image folder.
    	- For 9x15 and 9x00 devices: Only image file 1 is required, and image 
    	  file 2 will be ignored.  If this option is omitted, FDT will take the 
    	  first argument after "fdt.exe" as the image file.

    -o  [normal/emergency]
        This option specifies the operation type.  Must be lower cases as below.
        This option is optional, and if this option is omitted, normal is the 
        default setting.
        - normal: This is a regular firmware image download.
        - emergency: This is an emergency firmware image download.
        
    -p  [port #]
        This option specifies the serial port number that the FDT should be 
        using to perform the firmware download.  If omitted, the FDU will search
        for the serial ports, and use the first available port for the specified
        download purpose.  An example of valid port number is "com12".
        If the user wants to force the FDT to use the serial port specified, 
        -force option should be specified along with -p option.
     
    -a	Indicate automated mode.  If specified, there is no "Press Enter to continue"
    	prompt for console mode, and under GUI mode the application will not wait for
		the user to click the "Close" button.
    
    -r  Indicate to skip the final device arrival check after firmware download.
        If not specified, the default behaviour is to check at the end.
        
    -q  Indicate if reset device is required or not before download the images.
        This is an option for G3K devices.  In some scenarios, SetImagePreference
        is done via another application, like GobiImgMgr, or GobiTestApp.  FDT
        is only responsible for downloading the image data.
        
    -force	Indicate a force download.  If specified, both firmware and configuration
    		images will be downloaded to the modem.
    		
    -slot [slot #]
    	This option specifies the desired storage slot to store the downloaded image.
    	It is designed mainly for G3K devices, and has no effect on other devices.  If 
    	omitted, the device will decide the slot to use to store the image.  A valid 
    	slot number should be between 1 and 5 inclusive.  An example of usage would
    	be "-slot 2"
    	
    -baud [baud rate]
    	This option specifies the baud rate to use for a specified serial port.  An
    	example of the usage would be "-baud 115200".
    	
    -nsc	Indicate there is no final firmware update status check at firmware
    		download completion.  If not specified, the default is to check update
    		status via QMI.
    		
    -ssdp	Indicate FDT to start with SSDP command to the device.
    
    -multi 	Allow multiple FDT instances to run simultaneously.  By default, only one
    		instance allowed.
    		
    -reset  Reset device only.
    
    -timeout [mins]
    	This option allows to customize the total time out setting for the download
    	process.  The value specified is the time in minutes.  An example would be
    	"-timeout 20" meaning the time out is set to 20 minutes.
    	
    -connectretry [retry #]
    	This option allows to configure the total number of retries when FDT failed
    	to connect to device via GobiApi.  The retry interval is one retry per second.
    	If this option is missing, FDT uses 120 as the default value.
    	
    -connectdelay [delay in seconds]
    	This option allows to configure the delay before connecting to device during
    	FW update status check.  The maximal allowed delay is 120 seconds.  Any value
    	greater than 120 will be limited to 120.
    	
    -statuscheckdelay [delay in seconds]
    	This option allows to configure the delay before checking update status during
    	FW update status check.  The maximal allowed delay is 60 seconds.  Any value
    	greater than 60 will be limited to 60.
    	
    -ignswto
    	This option makes FDT to ignore the response timeout error when switching device
    	to boot&hold mode via DM command.
	
	-nogui/-gui
		This option specify the desired user interface mode. The default is console 
		mode(-nogui) under CE and Window GUI mode under Windows Mobile.
		
	-silent
		This option suppress console output
	
        
Usage examples:
    
    - G3K devices:
    	
    	/* Update G3K images from a specified folder location */
    	fdt.exe -d g3k -f "c:\FwFiles\g3k"
    	
    	/* Update G3K images from a specified folder location, and store to slot 2 */
    	fdt.exe -d g3k -f "c:\FwFiles\g3k" -slot 2
    	
    	/* Update G3K images from the current folder, and no pause at the end */
    	fdt.exe -d g3k -a
    	
    - G5K devices:
    
        /* Update G5K images from the current folder. Let FDT search for
           the first found pair of firmware and configuration image */
        fdt.exe -d g5k 
        
        /* Update G5K images from a specified folder. Let FDT search for
           the first found pair of firmware and configuration image */
        fdt.exe -d g5k -fd "c:\FwFiles\g5k"
        
        /* Update G5K images from a specified folder. Let FDT download
           spkg.cwe and config.cwe image file */
        fdt.exe -d g5k -fd "c:\FwFiles\g5k" -f spkg.cwe config.cwe
        
        /* Update spkg.cwe and config.cwe from the current folder */
        fdt.exe -d g5k -f spkg.cwe config.cwe
        
    - Normal firmware image download for 9x00, 9x15 and G5K devices:
    
    	/* Let FDT search for the first CWE file under the current folder */
    	fdt.exe
    
    	/* Update a.cwe file in the current folder */
    	fdt.exe a.cwe
    	
        /* To update the firmware image example.cwe from the current directory */
        fdt.exe example.cwe
    
        /* To update the firmware image example.cwe via com11 from the specified 
           location with baud rate 115200 */
        fdt.exe -f "c:\temp\example.cwe" -p com11 -force -baud 115200
    
    - 9x15 emergency firmware download
    
        /* Emergency download for 9x15 based devices */
        fdt.exe -d 9x15 -o emergency -fd "c:\FwFiles\9x15"
        
        /* 9x15 Emergency download with images files from the current folder, and
           following a normal spkg image download */
        fdt.exe -d 9x15 -o emergency -fd . -f spkg.cwe
        
    - 9x00 emergency firmware download
    
        /* Emergency download for 9x00 based devices */
        fdt.exe -d 9x00 -o emergency -fd "c:\FwFiles\9x00"
        
    - 9x25 emergency firmware download
        /* Emergency download for 9x25 based devices */
        fdt.exe -d 9x25 -o emergency -fd .
        
    - 9x30 emergency and regular combined firmware download
    	fdt.exe -d 9x30 -o emergency -fd binaries -f .\spkg.cwe
    	
    - 9x30 regular download (ignore timeout error when switching device to boot&hold)
    	fdt.exe -f spkg.cwe -ignswto


Notes:

    - For Gobi3000 devices, only the normal image download is supported.  The folder
      to the Gobi3000 image files needs to be specified as the first argument in the 
      "-f" option.  The image files have to be amss.mbn and uqcn.mbn at the specified
      folder location.  Other image file names are not accepted.
      
    - For normal firmware download, if the image file is at the current folder, 
      it is ok to omit the "-f" option, and specify the image file name only after the 
      fdt application name.  Please see example #1 above.
      
    - Port number option "-p" does not apply to Gobi3000 devices.  
    
    
Log files:

    The log file "fdt.txt" is located under "%appdata%\sierra wireless\logs" folder.
    If serial port option "-p" is specified, the log file is named as "fdt_comxx.txt"
    under the same "%appdata%\sierra wireless\logs" folder.
            

Firware update completion
    When FDT finishes firmware update, it signals a global event 
    "Global\SwiFwDwn_Complete".  Applications that wish to be notified should listen
    to this event.  This is a manual reset event with initial state to "non-signalled".
    Applications do not need to reset this event.
    

Update status logging:

    FDT logs the firmware update status in the registry at
    "HKLM\Software\Sierra Wireless Inc\QDL\FwDownloadErr".  This is a DWORD value with
    the following valid values:
    - 0:	  Indicating firmware update not completed yet.  This normally means
    	 	  FDT is still running.
    - 1:	  Indicating firmware update completed successfully.  This means
    		  the firmware has been downloaded to the device, and the device has
    		  flashed the new firmware to the storage successfully.
    - 5000:	  Indicating firmware download is not required as device is currently
    		  running on that image(s).  Also, there is no device reset afterwards.
    - 5001-6000:  FDT internal error codes.  This corresponding to the error code
    		  described below in section "Error code description".
    - 0xFFFFFFFF: Device final update status error "Unknown" due to a power off 
    		  reset after firmware update.
    - 0x100000nn: Device final update status error indicating FILE update errors while
    		  nn will be the exact error number.
    - 0x200000nn: Device final update status error indicating NVUP update errors while
       		  nn will be the exact error number.
    - 0x40000nnn: Device final update status error indicating FOTA update agent errors
    		  while nnn will be the exact error number.
    - 0x800000nn: Device final update status error indicating FDT/SSDP reported errors
    		  while nn will be the exact error number.
    

Error code description:

	If an error is encountered, the first error code returned is defined as follows:

    enum eSWIFwMgmtErrorCode
    {
        /* Operation successful */
        ERROR_SUCCESSFUL = 0,
    
        /*  ---------- Errors caused by application -----------  */
        
        /* Obsolete - CWE file doesn't exist */
        ERROR_APP_FILE_NOT_EXIST = 1,
        
        /* CWE file name pointer invalid */
        ERROR_APP_INVALID_PARAMETER = 2,
        
        /* Device is not connected */
        ERROR_APP_DEVICE_NOT_CONNECTED = 3,
        
        /* Device removed */
        ERROR_APP_DEVICE_REMOVED = 4,
        
        /* No serial port available to continue to ping the protocol */
        ERROR_APP_NO_SERIAL_PORT_AVAILBLE = 5,
        
        /* Another instance has been running */
        ERROR_APP_ANOTHER_INSTANCE_RUNNING = 6,
    
    	/* ----------- Errors from device --------------- */
    	
    	/* Image not required as it is already in the device */
    	ERROR_DEV_IMAGE_TYPE_NOT_REQUIRED = 30,
    	
        /* ----------- Errors from FwUpdateCore  --------------*/
        
        /* Obsolete - Failed to set QdlClient DM port name */
        ERROR_FWMGMT_GET_DM_PORT_NAME_FAIL = 50,
        
        /* Failed in switching to boot & hold mode.  Modem doesn't respond to 
           the SWITCH_TO_BOOT&HOLD command.  Possible causes:
           - The modem is already in HIP boot&hold mode.  
           - AT!QPSTDLOAD command was not sent to the modem prior calling
             FwUpdater tool for Direct IP devices. */
        ERROR_FWMGMT_SWITCH_TO_BOOT_MODE_FAIL = 51,
        
        /* Obsolete - Failed in Hello stage */
        ERROR_FWMGMT_HELLO_STATE_FAIL = 52,
        
        /* Failed in Open stage.  If extended error code is provide, see the
           detailed description of the second extended error code below.  */
        ERROR_FWMGMT_OPEN_STATE_FAIL = 53,
        
        /* Failed in Write stage.  If extended error code is provide, see the
           detailed description of the second extended error code below. */
        ERROR_FWMGMT_WRITE_STATE_FAIL = 54,
        
        /* Failed in Done stage.  One possible cause is that the boot loader 
           does not match the device type.  For example, an AC boot loader
           is downloaded to an MC device.  If extended error code is provide,
           see the detailed description of the second extended error code below.
           Another possible cause is that the usb bus was suspended during the 
           end of the download process.  USB suspend needs to be disabled 
           during FW download.  */
        ERROR_FWMGMT_DONE_STATE_FAIL = 55,
        
        /* Failed in Done_All stage */
        ERROR_FWMGMT_DONE_FINAL_STATE_FAIL = 56,
        
        /* Obsolete - Unexpected error in downloading */
        ERROR_FWMGMT_UNEXPECTED = 57,
        
        /* Failed when waiting for download finish, invalid event handle, should never happen */
        ERROR_FWMGMT_INTERNAL_WAIT_FAIL = 58,
        
        /* Communication to the device is broken */
        ERROR_FWMGMT_DEVICE_DISCONNECTED = 59,
        
        /* Failed to send command to the device */
        ERROR_FWMGMT_SEND_COMMAND_FAIL = 60,
        
        /* Obsolete - Failed to send data to the device */
        ERROR_FWMGMT_SEND_DATA_FAIL = 61,
        
        /* Obsolete - Failed to switch back to APP mode.  The device does not boot into 
           the app mode after the download.  This is not necessary a download
           error as the new FW might have been downloaded successfully, just
           the device boots into the boot&hold mode.  */
        ERROR_FWMGMT_SWITCH_TO_APP_MODE_FAIL = 62,
        
        /* Obsolete - Failed to receive response from the modem */
        ERROR_FWMGMT_NO_RESPONSE_FAIL = 63,
        
        /* Failed to get transaction resource */
        ERROR_FWMGMT_ALLOCATE_TRANSACTION_FAIL = 64,
        
        /* Timeout while receiving response */
        ERROR_FWMGMT_WAITING_RESPONSE_TIMEOUT_FAIL = 65,
        
        /* Failed to initialize comport */
        ERROR_FWMGMT_COMPORT_INIT_FAIL = 66,
        
        /* Timeout while updating the firmware */
        ERROR_FWMGMT_FIRMWARE_UPDATE_TIMEOUT = 67,
        
        /* Incorrect response received */
        ERROR_FWMGMT_INCORRECT_RESPONSE_FAIL = 68,
        
        /* Device/mode not supported, like Direct IP devices in BOOT&HOLD mode */
        ERROR_FWMGMT_DEVICE_NOT_SUPPORTED_FAIL = 69,
        
        /* One of the emergency download files does not exist in the 
           location specified. */
        ERROR_FWMGMT_EDL_FILE_NOT_EXIST = 70,
        
        /* Failed to allocate memory */
        ERROR_FWMGMT_ALLOCATE_MEMORY_FAIL = 71,
        
        /* Failed in read file */
        ERROR_FWMGMT_READ_FILE_FAIL = 72,
        
        /* Received NAK in DMSS download procotol.  If this error code happened
           during downloading the emergency flash programmer, it probably means
           the device is not in the emergency download mode.  In other words, 
           the device flash is not blank. */
        ERROR_FWMGMT_DMSS_DL_NAK_RECEIVED = 73,
        
        /* Invalid partition table image file.  The size of the partition table
           file should not exceed 512 bytes. */
        ERROR_FWMGMT_INVALID_PARTITION_FILE = 74,
        
        /* Failed to initialize the modem object */
        ERROR_FWMGMT_MODEM_INIT_FAIL = 75,
        
        /* Failed in switching the device to streaming download mode */
        ERROR_FWMGMT_SWITCH_TO_STREAMING_FAIL = 76,
        
        /* Failed in streaming download stage */
        ERROR_FWMGMT_STREAMING_DL_FAIL = 77,
        
        /* Failed in preparing the emergency download files */        
        ERROR_FWMGMT_PREPARE_ED_FAIL = 78,
        
        /* Failed in downloading the emergency download image files */
        ERROR_FWMGMT_EDL_FAIL = 79,
        
        /* Failed to launch the flash programmer */
        ERROR_FWMGMT_LAUNCH_FLASH_PROGRAMMER_FAIL = 80,
        
        /* Failed in resetting the device */
        ERROR_FWMGMT_RESET_DEVICE_FAIL = 81,
    
        /* Failed in checking modem mode */
        ERROR_FWMGMT_CHECK_MODE_FAIL = 82,
        
        /* Failed in FwUpdateCore initialization */
        ERROR_FWMGMT_INIT_FAIL = 83,
        
        /* Failed in checking FW update status */
        ERROR_FWMGMT_CHECK_FWUPDATE_STATUS_FAIL = 84,
        
        /* Time out in waiting for device command */
        ERROR_FWMGMT_WAIT_COMMAND_TIMEOUT_FAIL = 85,
        
        /* Image ID mismatch in Sahara read data command */
        ERROR_FWMGMT_IMAGE_ID_MISMATCH_FAIL = 86,
        
        /* Expected mode invalid, e.g., Image Transfer Pending mode expected
           in emergency download, but device is expecting other modes, like
           memory debug mode */
        ERROR_FWMGMT_INVALID_MODE_FAIL = 87,
        
        /* Image transfer has ended */
        ERROR_FWMGMT_IMAGE_TRANSFER_END = 88,
        
        /*  -------------  Errors caused in host OS or system ------------- */
        
        /* System CreateFile for CWE file fail */
        ERROR_SYS_OPEN_FILE_FAIL = 100,
        
        /* System GetFileSize fail */
        ERROR_SYS_GET_FILE_SIZE = 101,
        
        /* System GetCurrentDirectory fail */
        ERROR_SYS_GET_CURRENT_DIR_FAIL = 102,
        
        /* System SetupDiGetClassDevs fail */
        ERROR_SYS_GET_CLASS_DEV_INFO_FAIL = 103,
        
        /* System SetupDiGetDeviceInstanceId fail */
        ERROR_SYS_GET_DEVICE_INSTANCE_FAIL = 104,
        
        /* System SetupDiDestroyDeviceInfoList fail */
        ERROR_SYS_DESTROY_DEVICE_INFO_LIST_FAIL = 105,
        
        /* System SetupDiGetDeviceRegistryProperty fail */
        ERROR_SYS_GET_DEVICE_REG_PROPERTY_FAIL = 106,
        
        /* Obsolete - System CreateFile for DM or CNS port fail.  One possible cause is
           that the CNS port has been opened by another application.  */
        ERROR_SYS_OPEN_PORT_FAIL = 107,
        
        /* Obsolete - System SetCommTimeouts fail */
        ERROR_SYS_SET_COMM_TIMEOUTS_FAIL = 108,
        
        /* Obsolete - Failed to allocate buffer */
        ERROR_SYS_ALLOCATE_QDL_BUFFER_FAIL = 109,
        
        /* Failed to allocate buffer for CWE file */
        ERROR_SYS_ALLOCATE_CWE_FILE_BUFFER_FAIL = 110,
        
        /* System ReadFile fail */
        ERROR_SYS_READ_FILE_FAIL = 111,
        
        /* Obsolete - System CreateEvent fail */
        ERROR_SYS_CREATE_EVENT_FAIL = 112,
        
        /* Obsolete - System begin thread fail */
        ERROR_SYS_CREATE_THREAD_FAIL = 113,
        
        /*  --------------- Errors from GobiApi --------------------  */
        
        /* API QCWWANConnect fail */
        ERROR_API_QCWWANCONNECT_FAIL = 200,
        
        /* Failed to switch to QDL mode */
        ERROR_API_SWITCH_TO_QDL_MODE_FAIL = 201,
        
        /* API QCWWANDisconnect fail */
        ERROR_API_QCWWANDISCONNECT_FAIL  = 202,
        
        /* Failed to get GobiApi Wrapper */
        ERROR_API_GET_API_WRAPPER_FAIL = 203,
        
        /* Failed to initialize GobiApi Wrapper */
        ERROR_API_API_WRAPPER_INIT_FAIL = 204,
        
        /* Unsupported QMI command */
        ERROR_API_UNSUPPORTED_COMMAND_FAIL = 205,
        
        /* Invalid operation */
        ERROR_API_INVALID_OPERATION = 206,
        
        /* API SwiGetFwUpdateStatus fail */
        ERROR_API_CHECK_FWUPDATE_STATUS_FAIL = 207,
        
        /* API is not supported in GobiApi */
        ERROR_API_UNSUPPORTED_API_FAIL = 208
    };