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

📄 jflash.cpp

📁 ARM 10 KEYPAD DESIGN
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/**********************************************************************************  COPYRIGHT (C) 2000, 2001, 2002 Intel Corporation.****  The information in this file is furnished for informational use **  only, is subject to change without notice, and should not be construed as **  a commitment by Intel Corporation. Intel Corporation assumes no **  responsibility or liability for any errors or inaccuracies that may appear **  in this document or any software that may be provided in association with **  this document. ****  FILENAME:       Jflash.cpp****  PURPOSE:        A utility to program Intel flash devices from a PC parallel port.****  LAST MODIFIED:  $Modtime: 2/20/04 10:39a $******************************************************************************//*****************************************************************************Note: Within these files there are porting instructions that are useful for adding additional platform support to this tool. These guides may be located bysearching for the string "PORTING_GUIDE".*******************************************************************************/#include <stdio.h>#if defined __linux__#include <stdlib.h>#include <unistd.h>#include <ctype.h>#include <string.h>#include <time.h>#include <sys/types.h>#include <sys/stat.h>#include <sys/perm.h>#include <errno.h>#include <sys/io.h>#define _getche		getchar#define _inp(a)		inb(a)#define _outp(a,d)	outb(d,a)#define BOOL		bool#define FALSE		false#define TRUE		truetypedef long		DWORD;typedef short		WORD;#include "Compile_switches.h"#include "Jflash.h"#include "jtag.h"#include "Global_Variables.h"#ifndef DATADIR#define DATADIR		"/usr/share/jflashmm/"#endif#define lastchar(s)	((s)[strlen(s)-1])#elif defined WIN32#include <windows.h>#include <time.h>#include <conio.h>#include "compile_switches.h"#include "jflash.h"#include "jtag.h"#include "string.h"#include "Global_Variables.h"#else#error "Platform is not defined"#endif/********************************************************************************Forward declarations********************************************************************************/int putp(int,int, int); // writes the JTAG data on the parallel portvoid id_command(void);	// issues the JTAG command to read the device ID for all 3 chips//void bypass_all(void);	// issues the JTAG command to put all 3 device in bypass mode//void extest(void);		// issues the JTAG command EXTEST to the ProcessorDWORD access_rom(int, DWORD, DWORD, int);	// Passes read/write/setup data for the Flash memoryDWORD access_bus(int, DWORD, DWORD, int);	// Read/write access to the Processor pinsvoid Write_Rom(DWORD address, DWORD data);	// Writes to ROMDWORD Read_Rom(DWORD address);				// Reads from ROMint test_port(void);	// Looks for and finds a valid parallel port addressint check_id(char*);	// Compares the device IDs for the 3 JTAG chips to expected valuesvoid error_out(char*);	// Prints error and exits program//void erase_flash(DWORD, DWORD, DWORD, DWORD, int);void program_flash(DWORD, DWORD, DWORD);void verify_flash(DWORD, DWORD);void test_logic_reset(void);//void test_lock_flash(DWORD, DWORD, DWORD, DWORD, int);void set_lock_flash(DWORD, DWORD, DWORD, DWORD, int);void set_address (DWORD);int PZ_scan_code(int, int, int);int controller_scan_code(int, int, int);void pre_DRSCAN(void);void post_DRSCAN(void);void pre_IRSCAN(void);void post_IRSCAN(void);void mem_rw_mode(int);void mem_data_driver(int);void mem_write_enable(int);void mem_output_enable(int);void clear_chip_selects(void);void set_chip_select(DWORD);DWORD shift_data(int);void set_data(DWORD);void jtag_test(void);void dump_chain(void);void init_workbuf(void);void invert_workbuf(void);void set_pin_chip_select(DWORD);void gpio_unlock_flash(void);void gpio_lock_flash(void);void ParseAndLoad(void);void ParseAndLoadFlashData(void);DWORD convert_to_dword(char*);void AnalyzeChain (void);void InitPinArray (void);void InitLockUnlock(void);void InitAddressOrder(void);void InitInputDataOrder(void);void InitOutputDataOrder(void);void InitChipSelectRegions(void);void InitFlashGlobals(void);void UnlockAndEraseBlock(DWORD);DWORD GetChipSelect(DWORD);void EraseBlocks(DWORD, DWORD);void check_file_info(DWORD *fsize , DWORD *last_non_zero, DWORD *last_non_ff, DWORD rom_size);void check_rom_info(DWORD *max_erase_time, DWORD * dsize, DWORD * max_write_buffer );int other_bypass(int rp, int ct, int length);void IR_Command(int command);void usage(void);void Set_Platform_Global_Variables(void);void DeclareDefaults(int);void Integrity_Check(void);#ifdef __linux__bool io_access_on(unsigned long port){	int res;	res = ioperm(port, 3, 1);	if (res){ perror("ioperm()"); return false; }	res = ioperm(0x80, 1, 1);	if (res){ perror("ioperm()"); return false; }	return true;}void io_access_off(unsigned long port){	ioperm(port, 3, 0);	ioperm(0x80, 1, 0);	return;}#else# define io_access_on(x)		(true)# define io_access_off(x)#endif/********************************************************************************** FUNCTION:         main** DESCRIPTION:      Entry point for utility** INPUT PARAMETERS: uses optional input parameters:*						argv[1] = Platform to which the binary file will be downloaded*                       argv[2] = filename to flash (binary files only)*                       argv[3] = program options, currently only 'P' for Program*                       argv[4] = Byte Address     *						argv[5] = INS or PAR (Insight or parallel cable)						argv[6] = Debug mode on or off* RETURNS:          void*********************************************************************************/#if defined WIN32int main( int argc, char *argv[] ){    time_t start;	DWORD fsize = 0;	DWORD last_non_zero = 0;	DWORD last_non_ff = 0;	DWORD base_address;    DWORD max_erase_time, dsize, max_write_buffer;	char base_address_string[12];	DWORD hexaddress; 	char plat_name[MAX_IN_LENGTH];	char buf[10];	int i = 0;//	int j;//	DWORD block_size;	strcpy(base_address_string, "");		if(argc >= 2)	{		//Copy the first argument into a character array		strcpy(plat_name, argv[1]);		// Convert the name of the platform to uppercase#if defined __linux__		do {			int res;			char buff[MAX_IN_LENGTH], *s;			struct stat fs;			if (!strchr(plat_name, '/')){				s = buff;									// fine in current directory				s += sprintf(s, plat_name);				if (strcmp(s + strlen(s) - 4, ".dat"))					s += sprintf(s, ".dat");				res = stat(buff, &fs);				if (!res){ strcpy(plat_name, buff); break; }				s = buff;									// fine in data directory				s += sprintf(s, "%s", DATADIR);				if (lastchar(s) != '/')					s += sprintf(s, "/");				s += sprintf(s, "%s", plat_name);				if (strcmp(s + strlen(s) - 4, ".dat"))					s += sprintf(s, ".dat");				res = stat(buff, &fs);				if (!res){ strcpy(plat_name, buff); break; }			} else {										// with '/'				s = buff;				s += sprintf(s, "%s", plat_name);				if (strcmp(s + strlen(s) - 4, ".dat"))					s += sprintf(s, ".dat");				res = stat(buff, &fs);				if (!res){ strcpy(plat_name, buff); break; }			}		} while (0);		sprintf(data_filename, "%s", plat_name);		sprintf(int_data_filename, DATADIR "%s_integrity.dat", plat_name);#elif defined WIN32		for(unsigned int i = 0; i < strlen(plat_name); i++)			plat_name[i] = toupper(plat_name[i]);		// use the parameter to construct a filename to parse		sprintf(data_filename, "%s.dat", plat_name);		// while we're at it, construct the integrity check filename derived from this.		sprintf(int_data_filename, "%s_integrity.dat", plat_name);#endif	}	else	{		if(!UsageShown) usage();		printf("\nEnter platform data file name: ");		fgets(plat_name, MAX_IN_LENGTH, stdin);			//gets(plat_name);		// Convert the name of the platform to uppercase		for(unsigned int i = 0; i < strlen(plat_name); i++)			plat_name[i] = toupper(plat_name[i]);		// use the parameter to construct a filename to parse		sprintf(data_filename, "%s.dat", plat_name);		// while we're at it, construct the integrity check filename derived from this.		sprintf(int_data_filename, "%s_integrity.dat", plat_name);	}		char DebugMode[4] = "NOD";			// Either NODebug or DEBug	if(argc >= 7)	{		// Copy the sixth argument into a character array		strcpy(DebugMode, argv[6]);		// Convert the parameter to uppercase		for(int i = 0; i < 4; i++)			DebugMode[i] = toupper(DebugMode[i]);		// Compare the mode with list of modes		if(!strcmp("DEB", DebugMode))		{			Debug_Mode = true;		}		else if(!strcmp("NOD", DebugMode))		{			 Debug_Mode = false;		}	}	// Inhibit questions from being asked. This is to assist in automation scripts	char AskMe[2] = "A";	if(argc >= 8)	{		// Copy the  argument into a character array		strcpy(AskMe, argv[7]);		// Convert the parameter to uppercase		for(int i = 0; i < 2; i++)			AskMe[i] = toupper(AskMe[i]);		// Compare the mode with list of modes		if(!strcmp("A", AskMe))		{			AskQuestions = true;		}		else if(!strcmp("D", AskMe))		{			 AskQuestions = false;		}	}	ParseAndLoad();	Set_Platform_Global_Variables();	InitPinArray();	InitLockUnlock();	InitAddressOrder();	InitInputDataOrder();	InitOutputDataOrder();	InitChipSelectRegions();	AnalyzeChain();	printf("\nJFLASH Version %s\n",  VERSION);    printf("COPYRIGHT (C) 2000 - 2003 Intel Corporation\n\n");	printf("PLATFORM SELECTION:\n");	printf(" Processor= \t\t%s\n", &WORDARRAY[p_processor][0]);	printf(" Development System= \t%s\n", &WORDARRAY[p_devsys][0]);	printf(" Data Version= \t\t%s\n\n", &WORDARRAY[p_dataver][0]);    //Test operating system, if WinNT or Win2000 then get device driver handle#ifdef WIN32	OSVERSIONINFO osvi;	osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);	GetVersionEx(&osvi);	if(osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)	{        HANDLE h;		h = CreateFile("\\\\.\\giveio", GENERIC_READ, 0, NULL,					OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);		if(h == INVALID_HANDLE_VALUE)			error_out("Couldn't access giveio device");		CloseHandle(h);	}#endif	lpt_address = test_port();	// find a valid parallel port address	if(!lpt_address)		error_out("Error, unable to find parallel port"); 	// set the extended control register and others for the parallel port	lpt_ECR = lpt_address + 0x402;	lpt_CTL = lpt_address + 0x02;	lpt_STAT = lpt_address + 0x01;	#define STATUS_READ _inp(lpt_STAT)	#define CONTROL_READ _inp(lpt_CTL)    test_logic_reset();     // Jtag test appears to have a bug that is preventing use of the Blackstone cable.   //		{//			//	jtag_test();  I want everyone to use blackstone so this needs to be out//		}	if(argc >= 3)		strcpy(filename,argv[2]);	else		{			if(!UsageShown) usage();			printf("Enter binary file name: ");			fgets(filename, MAX_IN_LENGTH, stdin);		// gets(filename);		}	char Cable_Type[4] = "INS";			// Either INS or PAR	if(argc >= 6)	{		// Copy the fifth argument into a character array		strcpy(Cable_Type, argv[5]);		// Convert the name of the cable to uppercase		for(int i = 0; i < 4; i++)			Cable_Type[i] = toupper(Cable_Type[i]);		// Compare the selected cable name with all supported cables		if(!strcmp("INS", Cable_Type))		{			CableType = Insight_Jtag;		}		else if(!strcmp("PAR", Cable_Type))		{			 CableType = Parallel_Jtag;		}	}	test_logic_reset();	id_command();	//bypass_all();	IR_Command(IR_Bypass);    test_logic_reset();	gpio_unlock_flash();    //check_rom_info(&max_erase_time, &dsize, &max_write_buffer, &block_size, &nblocks);    check_rom_info(&max_erase_time, &dsize, &max_write_buffer);	if( (in_file = fopen(filename, "rb" )) == NULL)    {		error_out("error, can not open binary input file");    }	check_file_info(&fsize , &last_non_zero, &last_non_ff, dsize);        // Don't waste time programming ff's at the end of the file this is the erase state    fsize = last_non_ff;  	if(argc >= 5)    {		sscanf(argv[4],"%lx", &hexaddress);		if(hexaddress & 0x3)		{			printf("Start address must be 32 bit aligned!\n");   			printf("Changing start address to: %lx\n",hexaddress & 0xFFFFFFFCul);   			base_address = (hexaddress & 0xFFFFFFFCul);   		}	   			// adjust address for flash addressing mode   			base_address = (hexaddress & 0xFFFFFFFCul)/ADDR_MULT;	}    else    {    	base_address = 0;    }		 	if(100 - (last_non_zero * 100)/last_non_ff > 20)	{		if(AskQuestions)		{			printf("The last %2ld percent of image file is all zeros\n",100 - (last_non_zero * 100)/last_non_ff);			printf("Would you like to save time by not programming that area? [y/n]: ");			if(toupper(_getche()) == 'Y')			fsize = last_non_zero;		}		else		{			fsize = last_non_zero;		}	}	printf("\n");	char option = 'P';	if(argc >= 4)	{    	option = toupper(*argv[3]);    }	    if(option == 'P')	{

⌨️ 快捷键说明

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