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

📄 main.cpp

📁 ARM 10 KEYPAD DESIGN
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/**********************************************************************************  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>#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>#include <getopt.h>#include "Compile_switches.h"#include "Jflash.h"#include "jtag.h"#define _getche			getchar#define _inp(a)			inb(a)#define _outp(a,d)		outb(d,a)#define BOOL			booltypedef long			DWORD;#ifndef DATADIR# define DATADIR		"/usr/share/jflashmm/"#endif#define lastchar(s)	((s)[strlen(s)-1])extern char data_filename[];extern char int_data_filename[];extern bool Debug_Mode;extern bool UsageShown;extern bool AskQuestions;extern char WORDARRAY[230][132];extern CABLE_TYPES CableType;extern DWORD IR_Bypass;extern FILE *in_file;extern FILE *intercom_file_pointer;extern int ADDR_MULT;extern DWORD F_READ_ARRAY;extern DWORD BLOCK_ADDRESS[];extern char WORDARRAY[230][132];;extern int lpt_address;/********************************************************************************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);extern void read_cpu_info(void);extern void show_mach_info(void);#define p_processor 	0#define p_devsys		1#define p_dataver		2#if 1struct operation {	char optchr;	char *optstr;	char *help;};static struct operation ops[] = {	{ 'p', "program",  "Program and verify." },	{ 'i', "identify", "Identify processor and flash type. No programming performed." },	/* just used for identifying the chips without programming anything */	{ 'n', "wirte",    "Program only with no verify." },		/* Program only with no verify cycle */	{ 'v', "verify",   "Verify only." },	{ 't', "test",     "Test flash. Program and verify same binary at every block." },		/* test the flash by attempting to write to all sectors */	{ 'r', "read",     "Read a location and write to file." },	{ 'e', "erase",    "Erase entire flash memory." }};static const int nops = sizeof(ops) / sizeof(*ops);#endifstatic const struct option jflashmm_options[] = {	{ "address", 1, 0, 'a' },	{ "cable", 1, 0, 'c' },	{ "debug", 0, 0, 'd' },	{ "force", 0, 0, 'f' },	{ "operation", 1, 0, 'o' },	{ "platform", 1, 0, 'p' },	{ "help", 0, 0, 'h' },	{ 0, 0, 0, 0 }};void jflashmm_usage(void){	struct operation *op;	printf(" Usage : jflashmm [-acdfop] [--address] [--cable] [--debug] [--force] [--operation] [--platform] image\n");	printf(" OPTIONS\n");	printf("   -a, --address\n");	printf("       store at address {hex format}. [default:0x00000000].\n");	printf("       ex) 0x00040000\n");	printf("   -c, --cable\n");	printf("       cable type. {parallel/insight}. [default:parallel].\n");	printf("   -d, --debug\n");	printf("       show debug messages\n");	printf("   -f, --force\n");	printf("       no questtion\n");	printf("   -o, --operation\n");	printf("       what you want.\n");	for (op=ops; op < ops + nops; op++)	printf("       %c, %-8s : %s\n", op->optchr, op->optstr, op->help);	printf("   -p, --platform\n");	printf("       platform name\n");	printf("   -h, --help\n");	printf("       show this help message\n");	return;}char *find_platform_filename(char *platform){	struct stat fs;	char _platform[strlen(platform) + 5];	static char buff[MAX_IN_LENGTH];	char fmt[10];	if (strcmp(platform + strlen(platform) - 4, ".dat")){	// add ".dat" (if not)		sprintf(_platform, "%s.dat", platform);		platform = _platform;	}	if (!strchr(platform, '/')){							// without '/'		// find in current director		snprintf(buff, sizeof(buff), platform);			if (!stat(buff, &fs)) return buff;		// find in data directory (in /usr/share/jflashmm/)		strcpy(fmt, (lastchar(DATADIR) == '/') ? "%s%s" : "%s/%s");		snprintf(buff, sizeof(buff), fmt, DATADIR, platform);		if (!stat(buff, &fs)) return buff;	} else {												// with '/'		snprintf(buff, sizeof(buff), "%s", platform);		if (!stat(buff, &fs)) return buff;	}	return 0;}int main(int argc, char *argv[]){   	int i;	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 plat_name[MAX_IN_LENGTH];	char buf[10];	char filename[MAX_IN_LENGTH];	char *platform;	char *s;	int option;	UsageShown = true;	Debug_Mode = false;	AskQuestions = true;	CableType = Parallel_Jtag;	base_address = 0;   	option = toupper('p');	platform="pxa270.dat";	while (1){		int opt, index;		opt = getopt_long(argc, argv, "a:c:dfo:p:", jflashmm_options, &index);		if (opt == -1) break;		switch (opt){			case 'a' :				sscanf(optarg, "%lx", &base_address);	   			base_address &= 0xFFFFFFFC;				break;			case 'c' :				CableType = (!strcmp(optarg, "insight")) ? Insight_Jtag : Parallel_Jtag;				break;			case 'd' :				Debug_Mode = true;

⌨️ 快捷键说明

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