Ejemplo n.º 1
0
void Programmer::VerifyMainBlock(const std::string& hexfilename, const bool ignoreCheck)
{
	// is MainBlock readback disabled?
	if (!ignoreCheck  &&  !CanReadMainBlock())
		throw std::string("MainBlock readback is disabled by the target configuration.");

	ProgressBar pb("Verifying");
	
	FlashMemory flash(flashSize);
	flash.LoadHex(hexfilename);		// read the HEX file
	
	FlashMemory verifyFlash(flashSize);

	int address = 0;
	while (address < flashSize)
	{
		ReadChunk(false, verifyFlash, address);

		address += PROG_CHUNK_SIZE;

		// update the progress bar
		pb.Refresh(address / double(flashSize));
	}

	// now compare
	if (flash != verifyFlash)
	{
		//flash.SaveHex("orig.hex");
		//verifyFlash.SaveHex("verif.hex");
		throw std::string("MainBlock verification failed.");
	}
}
Ejemplo n.º 2
0
int A3818UpgradeFromFile(int32_t A3818_handle, FILE * binfile, int fwcopy, A3818Upgrade_Mode mode) {
  
        uint32_t baseAddress;
        long currentTime, elapsedTime;        
        int finish;
        unsigned char c, c1;
        uint32_t      bp;        
        uint32_t      bufferLength;      

        uint32_t      *buffer;
        unsigned int  verifyErrors = 0;
        buffer = malloc(BITSTREAM_BYTES * sizeof(uint32_t));
        switch(fwcopy) {
          case 0 :
             baseAddress =  FIRST_FIRMWARE_PAGE_BASE_WORD_ADDRESS;
             break;
          case 1 :
             baseAddress =  SECOND_FIRMWARE_PAGE_BASE_WORD_ADDRESS;
             break;
          case 2 :
             baseAddress =  THIRD_FIRMWARE_PAGE_BASE_WORD_ADDRESS;
             break;
          case 3 :
             baseAddress =  FOURTH_FIRMWARE_PAGE_BASE_WORD_ADDRESS;
             break;
          default :
             baseAddress =  SECOND_FIRMWARE_PAGE_BASE_WORD_ADDRESS;     
             break;
                  
        }
        
        bp = 0;
        finish = 0;
        
        // Carica il bitsream in un buffer di memoria
        currentTime = get_time();  
        while( !finish ) {
               
           c = (unsigned char)fgetc(binfile);  // read one byte from file
           c1 = (unsigned char)fgetc(binfile);  // read one byte from file (Strataflash a 16 bit)
      
#ifdef __SWAP__                
           swap = 0;
                
           // Swap primo byte
           for( i = 0; i < 8; i++ )
             if( c & (1 << i) )
                swap = swap | (0x80 >> i);
                
           swap1 = 0;        
           // Swap secondo byte        
           for( i = 0; i < 8; i++ )
             if( c1 & (1 << i) )
               swap1 = swap1 | (0x80 >> i);
                       
           buffer[bp] = (uint32_t) ((swap1 <<8) | swap); // HACK : swap o non swap?
#else               
           buffer[bp] = (uint32_t) ((c1 <<8) | c);
#endif // __SWAP__   

           bp++;
           if( feof(binfile) )
             finish = 1;
        }  // end of while loop     

        bufferLength = (--bp);
        
        if ((bufferLength*2) != BITSTREAM_BYTES) {
           printf("\nERROR: Input BIN file length (%d bytes) is different than expected bitstream size (%d bytes). Exiting.....\n", bufferLength*2, BITSTREAM_BYTES);
           free(buffer);
           return -1;
        }
        
        elapsedTime = get_time() - currentTime;
        printf("\nBitstream (%d bytes) loaded in %ld milliseconds\n", bufferLength*2, elapsedTime);
        
        A3818_EnableBPIAccess(A3818_handle);     

        /* Cancellazione della zona di flash riservata al firmware */
        if ( (mode == A3818_UPGRADE_FULL      ) ||
             (mode == A3818_UPGRADE_ERASE_ONLY) ) {
            printf("Erasing flash ");
            fflush(stdout);            
            currentTime = get_time();         
            eraseFirmware(A3818_handle, baseAddress, fwcopy);
            elapsedTime = get_time() - currentTime;
            printf("\nFlash erased in %ld milliseconds\n", elapsedTime);
        }
        
        /* Programmazione immagine firmware in flash */
        if ( (mode == A3818_UPGRADE_FULL      ) ) {
            currentTime = get_time();      
            writeFlash(A3818_handle, buffer, bufferLength, baseAddress);
            elapsedTime = get_time() - currentTime;
            printf("\n%d 16-bit words programmed in %ld milliseconds\n", bufferLength, elapsedTime);
        }
	    
        /* Verifica immagine firmware in flash */
        if ( (mode == A3818_UPGRADE_FULL      ) ||
             (mode == A3818_UPGRADE_VERIFY_ONLY) ) {
            currentTime = get_time();        
            verifyErrors = verifyFlash(A3818_handle, buffer, bufferLength, baseAddress);
            elapsedTime = get_time() - currentTime;
            printf("\n%d 16-bit words verified in %ld milliseconds\n", bufferLength, elapsedTime);
        }
        
        A3818_EnableSPIAccess(A3818_handle);      
        

        if( verifyErrors > 0 ) {
                printf("\n\n%d errors found during verify!\n",verifyErrors);
        } else {
                printf("\n\nFirmware updated without errors. Written %d words\n",bufferLength);
        }
        free(buffer);
        return 0;
}