public void Run() { thisUSB.adjustBaudRate(Parameters.BaudRate_SSL); //InsertCustomParameters(); //load ssl using RAMLoader RAMLoader loadSSL = new RAMLoader(parameters, thisUSB, parameters.SSLfilepath, mf_parent); loadSSL.Run(true); thisUSB.adjustBaudRate(Parameters.BaudRate_SSL); //increase the baud rate 8x, saves six seconds on loading (goes from 14 to 8) mf_parent.UpdateOutputText("Loading production firmware, filename \"" + parameters.FWimagefilename + "\"..."); SSLInterface sslinterface = new SSLInterface(parameters, thisUSB); try { //Read the firmware image into memory and check its length int filesize = 0; byte[] fullfilebuffer = readimagefromfile(parameters.FWimagefilepath, ref filesize); try { sslinterface.SSL_FULLERASE(); //cut this out before giving to controltek, this is here just to clear the hw info pars out while we're debugging. } catch (Exception_Yellow exc) { if (!exc.Message.Contains("retry failed")) throw new Exception_Yellow(exc.Message); //if it's some other exception, don't catch it else sslinterface.SSL_FULLERASE(); //retry once, if the exception comes back again, we won't catch it and it'll go on to be displayed as "retry failed" } LoadFW(sslinterface, fullfilebuffer, filesize); LoadHardwareSettings(sslinterface); Commit(sslinterface, filesize); } catch (Exception_Yellow ey) { if (ey.Message.Contains("CRC")) { mf_parent.UpdateOutputText("Error! Reverting to empty state, do not unplug..."); sslinterface.SSL_FULLERASE(); throw new Exception_Yellow("SSL throws CRC check error; packet was corrupted over UART. Memory has been erased, please try again."); } else if (ey.Message.Contains("Write")) { mf_parent.UpdateOutputText("Error! Reverting to empty state, do not unplug..."); sslinterface.SSL_FULLERASE(); throw new Exception_Yellow("SSL throws write error; write operation fails. Memory has been erased, please try again."); } else throw ey; } thisUSB.adjustBaudRate(Parameters.BaudRate_UARTandTesting); }
private void LoadFW(SSLInterface sslinterface, byte[] fullfilebuffer, int filesize) { int currentReadAddress = 0; uint currentWriteAddress = FLASH_IMAGE_HEADER; //Initialize the write address with the first byte after the FLASH header UInt16 bytesToRead; //only used in testing to erase partially-cleared dongles: if (parameters.reprogramming_oldFW_HW3_SW2 || parameters.reprogramming_newFW) { try { mf_parent.UpdateOutputText("Finalizing erase of old firmware..."); sslinterface.SSL_FULLERASE(); } catch (Exception_Yellow exc) { if (!exc.Message.Contains("retry failed")) throw new Exception_Yellow(exc.Message); //if it's some other exception, don't catch it else sslinterface.SSL_FULLERASE(); //retry once, if the exception comes back again, we won't catch it and it'll go on to be displayed as "retry failed" } } mf_parent.UpdateOutputText("Loading production firmware, filename \"" + parameters.FWimagefilename + "\"..."); //now chop it up into chunks the SSL will be able to handle, and write each chunk to the ssl, which then writes it to RAM and sends back a confirm while (currentReadAddress != filesize) { if (filesize - currentReadAddress > Parameters.SSL_ENG_BUFFER_SIZE) bytesToRead = Parameters.SSL_ENG_BUFFER_SIZE; //make chunks in the max buffer size the SSL can take (512 bytes) else bytesToRead = (UInt16)(filesize - currentReadAddress); //the last chunk will be smaller than the max buffer size byte[] tempbuffer = new byte[bytesToRead]; for (int i = 0; i < bytesToRead; i++) { tempbuffer[i] = fullfilebuffer[currentReadAddress]; currentReadAddress++; } try { sslinterface.SSL_WRITE(currentWriteAddress, tempbuffer, bytesToRead); } catch (Exception_Yellow exc) { if (!exc.Message.Contains("retry failed")) throw new Exception_Yellow(exc.Message); //if it's some other exception, don't catch it else sslinterface.SSL_WRITE(currentWriteAddress, tempbuffer, bytesToRead); //retry once, if the exception comes back again, we won't catch it and it'll go on to be displayed as "retry failed" } //catch (Exception e) //{ // if (!e.Message.Contains("reference not set")) throw new Exception(e.Message); //if it's some other exception, don't catch it // else throw new Exception(e.Message + " it happened inside SSL_WRITE"); //} currentWriteAddress += bytesToRead; mf_parent.UpdateProgressBar_Detail((int)(100 * (currentWriteAddress - FLASH_IMAGE_HEADER) / filesize)); } }