⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jflash.cpp

📁 ARM 10 KEYPAD DESIGN
💻 CPP
📖 第 1 页 / 共 5 页
字号:
		EraseBlocks(base_address, fsize);		program_flash(max_write_buffer, base_address, fsize);				Write_Rom(0, F_READ_ARRAY);				// put back into read mode		access_rom(READ, base_address, 0x0L, IGNORE_PORT); //extra read to get the pipeline going		time(&start);		gpio_lock_flash();		verify_flash(base_address, fsize);	}	else if(option == 'I') // just used for identifying the chips without programming anything	{		printf("Program successful completion.\n");		printf("Processor and Flash Memory Identified.\n");		printf("No programming operation performed.\n");	}	else if(option == 'N') // Program only with no verify cycle	{		EraseBlocks(base_address, fsize);		program_flash(max_write_buffer, base_address, fsize);				Write_Rom(0, F_READ_ARRAY);				// put back into read mode		access_rom(READ, base_address, 0x0L, IGNORE_PORT); //extra read to get the pipeline going		time(&start);		gpio_lock_flash();	}	else if(option == 'V')	{		Write_Rom(0, F_READ_ARRAY);				// put back into read mode		access_rom(READ, base_address, 0x0L, IGNORE_PORT); //extra read to get the pipeline going		time(&start);		gpio_lock_flash();		verify_flash(base_address, fsize);	}	else if(option == 'S')	{		Integrity_Check();	}	else if(option == 'T') // test the flash by attempting to write to all sectors	{		if(AskQuestions)		{			printf("About to test the entire flash memory..... \n");			printf("Is this what you want to do? (Y or N)\n");			if(toupper(_getche()) == 'Y')			{			i = 0;			do			{				test_logic_reset();				gpio_unlock_flash();				base_address = BLOCK_ADDRESS[i];				EraseBlocks(base_address, fsize);				program_flash(max_write_buffer, base_address, fsize);//    			Write_Rom(0, F_READ_ARRAY);				// put back into read mode//		  		access_rom(READ, base_address, 0x0L, IGNORE_PORT); //extra read to get the pipeline going//				gpio_lock_flash();//				verify_flash(base_address, fsize);				i++;			} while (BLOCK_ADDRESS[i] != 0);			i = 0;			do			{				test_logic_reset();				gpio_unlock_flash();				base_address = BLOCK_ADDRESS[i];//				EraseBlocks(base_address, fsize);//				program_flash(max_write_buffer, base_address, fsize);    			Write_Rom(0, F_READ_ARRAY);				// put back into read mode		  		access_rom(READ, base_address, 0x0L, IGNORE_PORT); //extra read to get the pipeline going				gpio_lock_flash();				verify_flash(base_address, fsize);				i++;			} while (BLOCK_ADDRESS[i] != 0);				printf("Successfully Completed a write to all sectors\n");			}			else			{				error_out("Cancelling the test....\n");			}		}		else		{			i = 0;			do			{				test_logic_reset();				gpio_unlock_flash();				base_address = BLOCK_ADDRESS[i];				EraseBlocks(base_address, fsize);				program_flash(max_write_buffer, base_address, fsize);//    			Write_Rom(0, F_READ_ARRAY);				// put back into read mode//		  		access_rom(READ, base_address, 0x0L, IGNORE_PORT); //extra read to get the pipeline going//				gpio_lock_flash();//				verify_flash(base_address, fsize);				i++;			} while (BLOCK_ADDRESS[i] != 0);			i = 0;			do			{				test_logic_reset();				gpio_unlock_flash();				base_address = BLOCK_ADDRESS[i];//				EraseBlocks(base_address, fsize);//				program_flash(max_write_buffer, base_address, fsize);    			Write_Rom(0, F_READ_ARRAY);				// put back into read mode		  		access_rom(READ, base_address, 0x0L, IGNORE_PORT); //extra read to get the pipeline going				gpio_lock_flash();				verify_flash(base_address, fsize);				i++;			} while (BLOCK_ADDRESS[i] != 0);			printf("Successfully Completed a write to all sectors\n");		}	}	else if(option == 'R')	{		Write_Rom(0, F_READ_ARRAY);				// put back into read mode		access_rom(READ, base_address, 0x0L, IGNORE_PORT); //extra read to get the pipeline going		if((intercom_file_pointer = fopen("VB2JFLASH_READ_DATA.BIN", "w")) == NULL)		{			printf("Cannot open output file: %s\n", "VB2JFLASH_READ_DATA.BIN");			exit(1);		}		else		{ 			 sprintf(buf, "%lX", Read_Rom(base_address)); 			 fputs(buf,intercom_file_pointer);			 fclose (intercom_file_pointer); 						//printf("%X\n",Read_Rom(base_address));		}	}		else if(option == 'E')	{		if(AskQuestions)		{			printf("About to erase the entire flash memory..... \n");			printf("Is this what you want to do? (Y or N)\n");			if(toupper(_getche()) == 'Y')			{				fsize = dsize - 1;				EraseBlocks(0, fsize);			}			else			{				error_out("Cancelling the erase....\n");			}		}		else		{			fsize = dsize - 1;			EraseBlocks(0, fsize);		}	}	else	{		printf("error specifying programming option. \n\n");		printf("Commands: \n");		printf("P = Program and verify\n");		printf("V = Verify only\n");		printf("T = Test flash. Program and verify same binary at every block.\n");		printf("I = Identify processor and flash type. No programming performed.\n");		printf("R = Read a location and write to file. RESERVED OPERATION\n");		printf("N = Program only with no verify\n");		printf("E = Erase entire flash memory\n");//		printf("S = Stuck bit search. Uses platform_integrity.dat file.\n");	}	fclose(in_file);	test_logic_reset();	return 0;}#endif/********************************************************************************** FUNCTION:         Set_Platform_Global_Variables** DESCRIPTION:    Evaluates some global variables based on the selected platform             *                   ** INPUT PARAMETERS: none					* RETURNS:          None** GLOBAL EFFECTS:   sets the global varibales in Global_Variables.h*********************************************************************************/void Set_Platform_Global_Variables(){		// Evaluate the following variables based on the selected platform	ChipSelect0		= convert_to_dword(&WORDARRAY[p_cs0][0]); 	// Global variable for chip select 0	ChipSelect1		= convert_to_dword(&WORDARRAY[p_cs1][0]); 	// Global variable for chip select 1	ChipSelect2		= convert_to_dword(&WORDARRAY[p_cs2][0]);	// Global variable for chip select 2	ChipSelect3		= convert_to_dword(&WORDARRAY[p_cs3][0]);	// Global variable for chip select 3	ChipSelect4		= convert_to_dword(&WORDARRAY[p_cs4][0]);	// Global variable for chip select 4	ChipSelect5		= convert_to_dword(&WORDARRAY[p_cs5][0]);	// Global variable for chip select 5	OutputEnable	= convert_to_dword(&WORDARRAY[p_nOE_OUT][0]);	// Global variable for output enable	WriteEnable		= convert_to_dword(&WORDARRAY[p_nWE_OUT][0]);	// Global variable for write enable	MdUpperControl	= convert_to_dword(&WORDARRAY[p_mdupper_ctrl][0]);	// Global variable for MD upper control	MdLowerControl	= convert_to_dword(&WORDARRAY[p_mdlower_ctrl][0]);	// Global variable for MD lower control	ReadWriteMode	= convert_to_dword(&WORDARRAY[p_RD_nWR_OUT][0]);	// Global variable for Read Write access mode	IR_Idcode		= convert_to_dword(&WORDARRAY[p_idcode][0]);	// Global variable for the IDCODE instruction of the IR	IR_Bypass		= convert_to_dword(&WORDARRAY[p_bypass][0]);	// Global variable for the BYPASS instruction of the IR	IR_Extest		= convert_to_dword(&WORDARRAY[p_extest][0]);  	// Global variable for the EXTEST instruction of the IR	ChainLength		= convert_to_dword(&WORDARRAY[p_blength][0]);  	// Global variable for the chain length of the selected platform	IrLength		= convert_to_dword(&WORDARRAY[p_irlength][0]);  	// Global variable for setting the correct IR length	if(!strcmp("16", &WORDARRAY[p_datawidth][0] ))		PlatformIs16bit = true;	else		PlatformIs16bit = false;	// set 16 and 32 bit command and query values	if (PlatformIs16bit)	{	     F_READ_ARRAY = 		0x00FFL;	     F_READ_IDCODES =   	0x0090L;	     F_READ_QUERY =     	0x0098L;	     F_READ_STATUS =    	0x0070L;	     F_CLEAR_STATUS =   	0x0050L;	     F_WRITE_BUFFER =   	0x00E8L;	     F_WORDBYTE_PROG =  	0x0040L;	     F_BLOCK_ERASE =    	0x0020L;	     F_BLOCK_ERASE_2ND =	0x00D0L; 	     F_BLK_ERASE_PS =       0x00B0L;	     F_BLK_ERASE_PR =       0x00D0L;	     F_CONFIGURATION =      0x00B8L;	     F_SET_READ_CFG_REG =   0x0060L;	     F_SET_READ_CFG_REG_2ND = 0x0003L;	     F_SET_BLOCK_LOCK =      0x0060L;	     F_SET_BLOCK_LOCK_2ND =  0x0001L;	     F_CLEAR_BLOCK_LOCK =    0x0060L;	     F_CLEAR_BLOCK_LOCK_2ND =0x00D0L;	     F_PROTECTION =          0x00C0L;	     F_ATTR_Q =              0x0051L;	     F_ATTR_R =              0x0052L;	     F_ATTR_Y =              0x0059L;	     F_BLOCK_LOCKED =        0x0001L;	     F_STATUS_READY =        0x0080L;	}	else	{ 	     F_READ_ARRAY = 		0x00FF00FFL;	     F_READ_IDCODES =   	0x00900090L;	     F_READ_QUERY =     	0x00980098L;	     F_READ_STATUS =    	0x00700070L;	     F_CLEAR_STATUS =   	0x00500050L;	     F_WRITE_BUFFER =   	0x00E800E8L;	     F_WORDBYTE_PROG =  	0x00400040L;	     F_BLOCK_ERASE =    	0x00200020L;	     F_BLOCK_ERASE_2ND =	0x00D000D0L; 	     F_BLK_ERASE_PS =       0x00B000B0L;	     F_BLK_ERASE_PR =       0x00D000D0L;	     F_CONFIGURATION =      0x00B800B8L;	     F_SET_READ_CFG_REG =   0x00600060L;	     F_SET_READ_CFG_REG_2ND = 0x00030003L;	     F_SET_BLOCK_LOCK =      0x00600060L;	     F_SET_BLOCK_LOCK_2ND =  0x00010001L;	     F_CLEAR_BLOCK_LOCK =    0x00600060L;	     F_CLEAR_BLOCK_LOCK_2ND =0x00D000D0L;	     F_PROTECTION =          0x00C000C0L;	     F_ATTR_Q =              0x00510051L;	     F_ATTR_R =              0x00520052L;	     F_ATTR_Y =              0x00590059L;	     F_BLOCK_LOCKED =        0x00010001L;	     F_STATUS_READY =        0x00800080L;	}	if (PlatformIs16bit)	{		ADDR_MULT = 2;	}	else	{		ADDR_MULT = 4;	}}/********************************************************************************** FUNCTION:         get_rom_info** DESCRIPTION:      get the flash information such as max erase time, flash size, *                   max write buffer, block number               *                   ** INPUT PARAMETERS: DWORD *max_erase_time	: max erase time, number of seconds*					DWORD *dsize			: each flash size, number of 16-bit word*					DWORD *max_write_buffer : each flash max write buffer, number of 16-bit word					DWORD *block_size		: each block size, number of 16-bit word*					DWORD *nblocks			: number of erase blocks in each Flash*					* RETURNS:          None** GLOBAL EFFECTS:   None*********************************************************************************/void check_rom_info(DWORD *max_erase_time, DWORD * dsize, DWORD * max_write_buffer){		DWORD FlashId;	DWORD FlashIdHigh;	DWORD FlashIdLow;	char constructed_string[50];	char FlashIdString[5];	bool IDFound = false;	int IDAttempts = 5;	do // Check for a recognized Flash ID a few times. Some devices are harder to read	{		Write_Rom(0x0, F_READ_ARRAY);			Write_Rom(0x0, F_READ_IDCODES);		   		    if(PlatformIs16bit)	    {	  			  	FlashIdLow = (Read_Rom(0x1) & 0xFFFF);		  	FlashIdLow = (Read_Rom(0x1) & 0xFFFF); // second read to handle misreads			FlashId = FlashIdLow;		}		else		{		  	FlashIdLow = (Read_Rom(0x1) & 0xFFFF);		  	FlashIdLow = (Read_Rom(0x1) & 0xFFFF);		    FlashIdHigh = (Read_Rom(0x1) & 0xFFFF0000) >> 16;		    FlashIdHigh = (Read_Rom(0x1) & 0xFFFF0000) >> 16;		    if (FlashIdHigh != FlashIdLow) 		    {				printf("Upper and Lower flash memory ID does not match.\n");				printf("You may have a damaged flash memory.\n");				printf("Upper half reads: %lX\n", FlashIdHigh);				printf("Lower half reads: %lX\n", FlashIdLow);			//	error_out("");		    }		    FlashId = FlashIdLow;		    		    // determine if the flash is a K3 family and apply the stability fix		    if ((FlashId == 0x8801) ||		        (FlashId == 0x8802) ||		        (FlashId == 0x8803)		       ) 		       {		        K3_STABILITY_FIX_ENABLE = true;		        if(Debug_Mode) printf("K3 Stability Fix Enabled\n"); 		       }		}		// open the data file for the flash device. If there is no file, then		// either the flash is not supported, not released, or there was an error		// reading the Device ID.		// construct the filename		sprintf(FlashIdString, "%lx", FlashId);		strcpy(constructed_string, "");		// construct the processor ID		strcat(constructed_string, "Flash_");		strcat(constructed_string, FlashIdString);		strcat(constructed_string, "_");		strcat(constructed_string, &WORDARRAY[p_fdevsacross][0]); 		strcat(constructed_string, "_");		strcat(constructed_string, &WORDARRAY[p_datawidth][0]);		strcat(constructed_string, ".dat");#if defined __linux		do {			int res;			char buff[MAX_IN_LENGTH], *s;			struct stat fs;			s = buff;									// fine in data directory			s += sprintf(s, "%s", DATADIR);			if (lastchar(s) != '/')				s += sprintf(s, "/");			s += sprintf(s, "%s", constructed_string);			res = stat(buff, &fs);			if (!res){ strcpy(flash_data_filename, buff); break; }			strcpy(flash_data_filename, constructed_string);		} while (0);#else		strcpy(flash_data_filename, constructed_string);  // set the filename#endif				// See if the file exists. If not then try again to confirm the flash ID		if((flash_file_pointer = fopen(flash_data_filename, "rb")) == NULL)		{			printf("Failed to read the Flash ID. Retrying %d more times...\n", IDAttempts -1);			IDAttempts--;			if (IDAttempts == 0)			{				printf("Cannot open input file: %s\n\n", flash_data_filename);				printf("This program supports flash devices defined by DAT files\n");				printf("contained in the same directory as the executable program. \n\n");				printf("If the file cannot be opened, there are four possibilities:\n\n");				printf(" 1 - The flash device installed is not supported.\n");				printf(" 2 - The flash device is a licensed product.\n");				printf(" 3 - The device ID could not be read, resulting in a poorly\n");				printf("     constructed filename. The first numeric value in the\n");				printf("     filename is the device ID. Verify this value with the\n");				printf("     component specification.\n");				printf(" 4 - The memory bus is not functional. Check all CPLD and FPGA\n");				printf("     devices. Make sure that you are using the correct \n");				printf("     platform data file. \n"); 				error_out("");			}			else			{				// hit the system with a JTAG reset and try again				test_logic_reset();				// try putting the flash into read mode again

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -