Exemple #1
0
int main(int argc, char *argv[])
{
    int ssp_address;
	SSP_PORT port;


    //check for command line arguments - first is port, second is ssp address
	if (argc <= 2)
	{
	    printf("Usage: BasicValidator <port> <sspaddress>\n");
	    return 1;
    }

    //open the com port
    printf("PORT: %s\n",argv[1]);
    port = OpenSSPPort(argv[1]);
    if (port == -1)
	{
	    printf("Port Error\n");
        return 1;
	}

    //set the ssp address
    ssp_address = atoi(argv[2]);
    printf("SSP ADDRESS: %d\n",ssp_address);


    //run the validator
	RunValidator(port,ssp_address);
	CloseSSPPort(port);
	return 0;

}
Exemple #2
0
unsigned long _download_main_file(ITL_FILE_DOWNLOAD * itlFile)
{
    unsigned char chk;
    unsigned long cur_block;
    unsigned long i;
    unsigned long block_offset;
    CloseSSPPort(itlFile->port);
    sleep(2);
    OpenSSPPort(itlFile->portname);
    SetBaud(itlFile->port,itlFile->baud);
    //ensure buffer clear after restart
    if (_send_download_command(&itlFile->fData[6],1,ram_OK_ACK,itlFile) == 0)
        return DATA_TRANSFER_FAIL;

    if (_send_download_command(itlFile->fData,128,ram_OK_ACK,itlFile) == 0)
        return DATA_TRANSFER_FAIL;

    for (cur_block = 1; cur_block <= itlFile->NumberOfBlocks; ++cur_block)
    {
        block_offset = 128 + ((cur_block-1)*itlFile->dwnlBlockSize) + itlFile->NumberOfRamBytes;
        chk = 0;
        for(i = 0; i < itlFile->dwnlBlockSize; ++i)
            chk ^= itlFile->fData[block_offset + i];
        /*
        for(i = 0; i < itlFile->dwnlBlockSize/128; ++i)
        {
            WriteData(&itlFile->fData[block_offset + (i*128)],128,itlFile->port);
            while (TransmitComplete(itlFile->port) == 0)
                    //usleep(1000);
                    sleep(0);

        }*/
        WriteData(&itlFile->fData[block_offset ],itlFile->dwnlBlockSize,itlFile->port);
        while (TransmitComplete(itlFile->port) == 0)
            usleep(1000);
        if (_send_download_command(&chk,1,chk,itlFile) ==0)
            return DATA_TRANSFER_FAIL;

        download_block = cur_block;
    }
    return DOWNLOAD_COMPLETE;

}
Exemple #3
0
int main(int argc, char *argv[])
{
    int ssp_address;
	SSP_PORT port;


    //check for command line arguments - first is port, second is ssp address
	if (argc <= 2)
	{
	    printf("Usage: BasicValidator <port> <sspaddress>\n");
	    return 1;
    }

    //open the com port
    printf("PORT: %s\n",argv[1]);
    port = OpenSSPPort(argv[1]);
    if (port == -1)
	{
	    printf("Port Error\n");
        return 1;
	}

    //set the ssp address
    ssp_address = atoi(argv[2]);
    printf("SSP ADDRESS: %d\n",ssp_address);


    //run the validator
	RunValidator(port,ssp_address);
	CloseSSPPort(port);
	return 0;


//    printf("%x\n",DownloadFileToTarget("/home/rstacey/CNY01609_NV02004000000TES_IF_01.bv1",PORT_TO_USE,0));

}
Exemple #4
0
/*
Name:   DownloadDataToTarget
Inputs:
    char * data: The array of data you wish to download
    long data_length: length of data to download
    char * port: The name of the port to use (eg /dev/ttyUSB0 for usb serial, /dev/ttyS0 for com port 1)
    unsigned char sspAddress: The ssp address to download to
Return:
    If the value is less than 0x100000 it is the number of blocks to be downloaded.
    On an error, the value will be greater than 0x100000, and one of the following
    Failure:
    OPEN_FILE_ERROR					0x100001
    READ_FILE_ERROR					0x100002
    NOT_ITL_FILE					0x100003
    PORT_OPEN_FAIL					0x100004
    SYNC_CONNECTION_FAIL			0x100005
    SECURITY_PROTECTED_FILE			0x100006
    DATA_TRANSFER_FAIL				0x100010
    PROG_COMMAND_FAIL				0x100011
    HEADER_FAIL						0x100012
    PROG_STATUS_FAIL				0x100013
    PROG_RESET_FAIL					0x100014
    DOWNLOAD_NOT_ALLOWED			0x100015
    HI_TRANSFER_SPEED_FAIL			0x100016
Notes:
    The download is done in a seperate thread - see GetDownloadStatus() for information about its progress
    Only one download operation may be in progress at once.
*/
int  DownloadDataToTarget(const unsigned char* data, const unsigned long dlength, const char * cPort, const unsigned char sspAddress, const unsigned long long key)
{

	int i;
	unsigned long numCurBytes;
	unsigned short dBlockSize;
    ITL_FILE_DOWNLOAD * itlFile;
    SSP_COMMAND sspC;
    SSP_PORT port;
    if (download_in_progress == 1)
        return PORT_OPEN_FAIL;
    itlFile = malloc(sizeof(ITL_FILE_DOWNLOAD));
    itlFile->fData = malloc(dlength);
    memcpy(itlFile->fData,data,dlength);

	/*ramStatus.currentRamBlocks = 0;
	ramStatus.ramState = rmd_RAM_DOWNLOAD_IDLE;
	ramStatus.totalRamBlocks = 0;
*/

    download_block = 0;
	// check for ITL BV/SH type file
    if (itlFile->fData[0] == 'I' && itlFile->fData[1] == 'T' && itlFile->fData[2] == 'L') {

		 numCurBytes = 0;
		 for(i = 0; i <4; i++){
			numCurBytes += (unsigned long)itlFile->fData[17 + i] << (8*(3-i));
		 }
		  //get the block size from header
		 dBlockSize = (256*(unsigned short)itlFile->fData[0x3e]) + (unsigned short)itlFile->fData[0x3f];
		// correct for NV9 type
		 if(dBlockSize == 0) dBlockSize = 4096;

		  itlFile->NumberOfBlocks = numCurBytes / dBlockSize;
		  if(numCurBytes % dBlockSize != 0) itlFile->NumberOfBlocks += 1;
	}
	else{
		free(itlFile->fData);
		free(itlFile);
		return NOT_ITL_FILE;
	}

	/* check target connection   */
	sspC.Timeout = 1000;
	sspC.BaudRate = 9600;
	sspC.RetryLevel = 2;
	sspC.SSPAddress = sspAddress;
	itlFile->SSPAddress = sspAddress;
	port = OpenSSPPort(cPort);
	strcpy(itlFile->portname,cPort);
	itlFile->port = port;
	if (port == -1)
	{
        free(itlFile->fData);
		free(itlFile);
		return PORT_OPEN_FAIL;
	}
	sspC.EncryptionStatus = 0;
	sspC.CommandDataLength = 1;
	sspC.CommandData[0]  = SSP_CMD_SYNC;

	if (SSPSendCommand(port,&sspC) == 0){
        CloseSSPPort(port);
		free(itlFile->fData);
		free(itlFile);
		return SYNC_CONNECTION_FAIL;
	}
	if(sspC.ResponseData[0] != SSP_RESPONSE_OK){
		CloseSSPPort(port);
		free(itlFile->fData);
		free(itlFile);
		return SYNC_CONNECTION_FAIL;
	}
	if (key > 0)
	{
        if (NegotiateSSPEncryption(port,sspAddress,&itlFile->Key) == 0)
        {
            CloseSSPPort(port);
            free(itlFile->fData);
            free(itlFile);
            return SYNC_CONNECTION_FAIL;
        }
        itlFile->EncryptionStatus = 1;
        itlFile->Key.FixedKey = key;
	}
    pthread_t thread;
    pthread_create(&thread,NULL,(void *)DownloadITLTarget,(void*)itlFile);
	//_beginthread(DownloadITLTarget,0,NULL);

	return itlFile->NumberOfBlocks;


}