USBDM_ErrorCode programFlashImage(FlashImagePtr flashImage, ProgressDialoguePtr callBack) {
   LOGGING_Q;
   FlashImage::EnumeratorPtr enumerator = flashImage->getEnumerator();
   USBDM_ErrorCode progRc = BDM_RC_OK;
   while (enumerator->isValid()) {
      // Start address of block to program to flash
      uint32_t startBlock = enumerator->getAddress();

      // Find end of block to program
      enumerator->lastValid();
      uint32_t blockSize = enumerator->getAddress() - startBlock + 1;

      //log.print("Block size = %4.4X (%d)\n", blockSize, blockSize);
      if (blockSize>0) {
         // Program block [startBlock..endBlock]
         progRc = programBlock(flashImage, blockSize, startBlock, callBack);
         if (progRc != BDM_RC_OK) {
            log.print("programming failed, Reason= %s\n", UsbdmSystem::getErrorString(progRc));
            break;
         }
      }
      // Move to start of next occupied range
      enumerator->nextValid();
   }
   return progRc;
}
ICP_ErrorType loadFile(FlashImage *flashImageDescription) {
   LOGGING_Q;
   FlashImage::Enumerator *enumerator = flashImageDescription->getEnumerator();
   ICP_ErrorType progRc = ICP_RC_OK;
   while (enumerator->isValid()) {
      // Start address of block to program to flash
      uint32_t startBlock = enumerator->getAddress();

      // Find end of block to program
      enumerator->lastValid();
      uint32_t blockSize = enumerator->getAddress() - startBlock + 1;

      //log.print("Block size = %4.4X (%d)\n", blockSize, blockSize);
      if (blockSize>0) {
         // Program block [startBlock..endBlock]
         progRc = programBlock(flashImageDescription, blockSize, startBlock);
         if (progRc != ICP_RC_OK) {
            log.print("loadFile() - programming failed, Reason= %s\n", ICP_GetErrorName(progRc));
            break;
         }
      }
      // Move to start of next occupied range
      enumerator->nextValid();
   }
   delete enumerator;
   enumerator = NULL;
   return progRc;
}