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

📄 jflash.cpp.diff

📁 jflash linux 2.0.03,linux下的jflash源代码
💻 DIFF
字号:
--- Jflash.cpp.orig	Wed Jul 24 09:56:02 2002+++ Jflash.cpp	Wed Aug 14 16:04:09 2002@@ -17,13 +17,43 @@ ******************************************************************************/
 
 #include <stdio.h>
-#include <windows.h>
 #include <time.h>
+
+#ifndef __linux__
+#include <windows.h>
 #include <conio.h>
-#include "compile_switches.h"
-#include "jflash.h"
+#endif
+
+#include "Compile_switches.h"
+#include "Jflash.h"
 #include "cotullajtag.h"
 
+/*
+* Linux compatibility definitions
+*/
+
+#ifdef __linux__
+
+#include <unistd.h>
+#include <ctype.h>
+#include <stdlib.h>
+#include <sys/io.h>
+#include <errno.h>
+#include <string.h>
+
+#define FALSE	0
+#define TRUE	1
+
+typedef int BOOL;
+typedef long DWORD;
+typedef short WORD;
+
+#define _inp(a)  inb(a)
+#define _outp(a,d)  outb(d,a)
+#define _getche getchar
+
+#endif
+
 
 /*
 *******************************************************************************
@@ -145,6 +175,7 @@     printf("JFLASH Version %s\n",VERSION);
     printf("COPYRIGHT (C) 2000, 2001 Intel Corporation\n");
 
+#ifndef __linux__
     //Test operating system, if WinNT or Win2000 then get device driver handle
 	OSVERSIONINFO osvi;
 	osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
@@ -159,6 +190,7 @@ 			error_out("Couldn't access giveio device");
 		CloseHandle(h);
 	}
+#endif
 
 	lpt_address = test_port();	// find a valid parallel port address
 	if(!lpt_address)
@@ -173,7 +205,7 @@ 	else
 		{
 		printf("enter binary file name: ");
-		gets(filename);
+		fgets(filename, sizeof(filename), stdin);
 		}
 
 	test_logic_reset();
@@ -183,7 +215,7 @@     //init_workbuf();
 
     test_logic_reset();
- 
+  
     check_rom_info(&max_erase_time, &dsize, &max_write_buffer, &block_size, &nblocks);
 	
 	if( (in_file = fopen(filename, "rb" )) == NULL)
@@ -1017,34 +1049,73 @@ *******************************************************************************
 */
 
+#ifdef __linux__
+
+int io_access_on( unsigned long port )
+{
+	if (ioperm (port, 3, 1)) {
+		perror ("ioperm()");
+		return 0;
+	}
+	if (ioperm (0x80, 1, 1)) {
+		perror ("ioperm()");
+		return 0;
+	}
+	return 1;
+}
+
+void io_access_off( unsigned long port )
+{
+	ioperm (port, 3, 0);
+	ioperm (0x80, 1, 0);
+}
+
+#else
+#define io_access_on(x) (1)
+#define io_access_off(x)
+#endif
+
+
 int test_port(void)
 {
 	// search for valid parallel port
+	if(io_access_on(LPT1))
+	{
 		_outp(LPT1, 0x55);
 		if((int)_inp(LPT1) == 0x55)
-        {
-            #ifdef DEBUG
-            printf("Parallel Com port found at I/O address: %X\n", LPT1);
-            #endif
-            return LPT1;
-        }
-		_outp(LPT2, 0x55);
+		{
+			#ifdef DEBUG
+			printf("Parallel Com port found at I/O address: %X\n", LPT1);
+			#endif
+			return LPT1;
+		}
+		io_access_off(LPT1);
+	}
+	if(io_access_on(LPT2))
+	{
+                _outp(LPT2, 0x55);
 		if((int)_inp(LPT2) == 0x55)
-        {
-            #ifdef DEBUG
-            printf("Parallel Com port found at I/O address: %X\n", LPT2);
-            #endif
-            return LPT2;
+		{
+			#ifdef DEBUG
+			printf("Parallel Com port found at I/O address: %X\n", LPT2);
+			#endif
+			return LPT2;
 		}
-        _outp(LPT3, 0x55);
-		if((int)_inp(LPT3) == 0x55)
-        {
-            #ifdef DEBUG
-            printf("Parallel Com port found at I/O address: %X\n", LPT3);
-            #endif
-            return LPT3;
-        }
-        
+		io_access_off(LPT2);
+	}
+	if(io_access_on(LPT3))
+	{
+		_outp(LPT3, 0x55);
+	if((int)_inp(LPT3) == 0x55)
+		{
+			#ifdef DEBUG
+			printf("Parallel Com port found at I/O address: %X\n", LPT3);
+			#endif
+			return LPT3;
+		}
+		io_access_off(LPT3);
+	}
+
 	return(0);	// return zero if none found
 }
 /*
@@ -1335,6 +1406,9 @@ 			{
 			printf("Writing flash at hex address %8lx, %5.2f%% done    \r"
 				,lj * 4,(float)(lj - base_address)/(float)fsize*100.0);
+#ifdef __linux__
+			  fflush(0);
+#endif
 			time(&start);
 			}
 
@@ -1392,6 +1466,9 @@ 				{
 				printf("Verifying flash at hex address %8lx, %5.2f%% done    \r"
 					,lj * 4,(float)(lj - base_address)/(float)fsize*100.0);
+#ifdef __linux__
+				fflush(0);
+#endif
 				time(&start);
 				}
 			if(li != li1)

⌨️ 快捷键说明

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