Index: error_msg.c
===================================================================
--- error_msg.c	(revision 6)
+++ error_msg.c	(revision 1)
@@ -1,30 +0,0 @@
-#include <windows.h>
-#include <stdio.h>
-#include "error_msg.h"
-
-VOID display_error_message(DWORD error_number)
-{
-	
-    LPVOID lpMsgBuf;
-    if (!FormatMessage( 
-		FORMAT_MESSAGE_ALLOCATE_BUFFER | 
-        FORMAT_MESSAGE_FROM_SYSTEM | 
-		FORMAT_MESSAGE_IGNORE_INSERTS,
-        NULL,
-		error_number,
-        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
-		(LPTSTR) &lpMsgBuf,
-        0,
-		NULL ))
-    {
-	// Handle the error.
-	return;
-    }
-
-    // Display the string.
-    printf("Error! %s\n", (LPCTSTR)lpMsgBuf );
-
-    // Free the buffer.
-    LocalFree( lpMsgBuf );
-}
-
Index: todo.txt
===================================================================
--- todo.txt	(revision 6)
+++ todo.txt	(revision 1)
@@ -1,12 +0,0 @@
-############################################################################################
-#  
-#  TODO list by Darmawan Salihun 28th June 2007
-#
-#
-
-1. Code review to find logic incompatibilities.
-2. Reworking the driver to limit I/O Port accesses and mappable physical address ranges.
-3. Creating diff/patch from the ilast modified code with regard to flashrom base code.
-
-
-
Index: error_msg.h
===================================================================
--- error_msg.h	(revision 6)
+++ error_msg.h	(revision 1)
@@ -1,11 +0,0 @@
-#ifndef __ERROR_MSG_H__
-#define __ERROR_MSG_H__
-
-/*
- * Note: Error number can be found easily with GetLastError() function
- */
-
-void display_error_message(unsigned long error_number);
-
-#endif //__ERROR_MSG_H__
-
Index: winflashrom.rc
===================================================================
--- winflashrom.rc	(revision 6)
+++ winflashrom.rc	(revision 1)
@@ -1,6 +0,0 @@
-/////////////////////////////////////////////////////////////////////////
-//  winflashrom resource file
-//  28 June 2007 Darmawan Salihun
-//
-
-WINFLASHROMDRV	DRIVER	DISCARDABLE	"driver/i386/winflashrom.sys"	
Index: interfaces.h
===================================================================
--- interfaces.h	(revision 6)
+++ interfaces.h	(revision 1)
@@ -1,71 +0,0 @@
-/*
- *  This is the interface file that connects the user mode application and the kernel mode driver
- *
- *  NOTE:
- *  -----
- *  - You __have__ to put #include <winioctl.h> prior to including this file in your user mode application
- *  - You probably need to put #include <devioctl.h> prior to including this file in your kernel mode driver 
- *  These includes are needed for the CTL_CODE macro to work.
- */
-
-#ifndef __INTERFACES_H__
-#define __INTERFACES_H__
-
-#define IOCTL_READ_PORT_BYTE	CTL_CODE(FILE_DEVICE_UNKNOWN, 0x0801, METHOD_IN_DIRECT, FILE_READ_DATA | FILE_WRITE_DATA)
-#define IOCTL_READ_PORT_WORD	CTL_CODE(FILE_DEVICE_UNKNOWN, 0x0802, METHOD_IN_DIRECT, FILE_READ_DATA | FILE_WRITE_DATA)
-#define IOCTL_READ_PORT_LONG	CTL_CODE(FILE_DEVICE_UNKNOWN, 0x0803, METHOD_IN_DIRECT, FILE_READ_DATA | FILE_WRITE_DATA)
-
-#define IOCTL_WRITE_PORT_BYTE	CTL_CODE(FILE_DEVICE_UNKNOWN, 0x0804, METHOD_OUT_DIRECT, FILE_READ_DATA | FILE_WRITE_DATA)
-#define IOCTL_WRITE_PORT_WORD	CTL_CODE(FILE_DEVICE_UNKNOWN, 0x0805, METHOD_OUT_DIRECT, FILE_READ_DATA | FILE_WRITE_DATA)
-#define IOCTL_WRITE_PORT_LONG	CTL_CODE(FILE_DEVICE_UNKNOWN, 0x0806, METHOD_OUT_DIRECT, FILE_READ_DATA | FILE_WRITE_DATA)
-
-#define IOCTL_MAP_MMIO		CTL_CODE(FILE_DEVICE_UNKNOWN, 0x0809, METHOD_IN_DIRECT, FILE_READ_DATA | FILE_WRITE_DATA)
-#define IOCTL_UNMAP_MMIO	CTL_CODE(FILE_DEVICE_UNKNOWN, 0x080A, METHOD_OUT_DIRECT, FILE_READ_DATA | FILE_WRITE_DATA)
-
-
-#ifdef __GNUC__ // are we using GCC to compile this code?
-#define PACK_STRUC __attribute__((packed))
-#else
-#define PACK_STRUC 
-#endif 
-
-
-enum {
-    MAX_MAPPED_MMIO = 256 // maximum number of mapped memory-mapped I/O zones
-};
-
-#ifdef _MSC_VER // are we using MSVC to compile this code?
-#pragma pack (push, 1)
-#endif
-
-struct _IO_BYTE {
-    unsigned short port8;
-    unsigned char value8;
-}PACK_STRUC; 
-typedef struct _IO_BYTE IO_BYTE;
-
-struct _IO_WORD {
-    unsigned short port16; 
-    unsigned short value16;
-}PACK_STRUC;
-typedef struct _IO_WORD IO_WORD;
-
-struct _IO_LONG {
-    unsigned short port32;
-    unsigned long value32;
-}PACK_STRUC;
-typedef struct _IO_LONG IO_LONG; 
-
-struct _MMIO_MAP {
-    unsigned long phy_addr_start; // start address in physical address space to be mapped
-    unsigned long size; // size of the physical address space to map
-    void * usermode_virt_addr; // starting virtual address of the MMIO as seen from user mode
-}PACK_STRUC;
-typedef struct _MMIO_MAP MMIO_MAP;
-
-#ifdef _MSC_VER // are we using MSVC to compile this code?
-#pragma pack (pop)
-#endif
-
-
-#endif //__INTERFACES_H__
Index: direct_io.c
===================================================================
--- direct_io.c	(revision 6)
+++ direct_io.c	(revision 1)
@@ -1,653 +0,0 @@
-#include <windows.h>
-#include <winioctl.h>
-#include <stdio.h>
-
-#include "interfaces.h" // Must be included after winioctl.h
-#include "direct_io.h"
-#include "error_msg.h"
-
-#define DRIVER_NAME       "winflashrom"
-
-//
-// verbosity of messages
-//
-#define VERBOSE_PORT_MESSAGE
-#undef VERBOSE_PORT_MESSAGE
-
-//
-// Globals
-//
-static HANDLE h_device = INVALID_HANDLE_VALUE;
-static UCHAR driver_path[MAX_PATH];
-
-//
-// Function implementation
-//
-
-static BOOLEAN setup_driver_name( PUCHAR driver_path )
-{
-    HANDLE file_handle;
-    DWORD err_no;
-    DWORD driver_path_len = 0;
-
-    //
-    // Get the current directory.
-    //
-    driver_path_len = GetCurrentDirectory(MAX_PATH, driver_path );
-
-    if (!driver_path_len) {
-	err_no = GetLastError();	    
-        printf("GetCurrentDirectory failed!  Error = %d \n",(int) err_no);
-				display_error_message(err_no);
-
-        return FALSE;
-    }
-
-    //
-    // Setup path name to driver file.
-    //
-
-    strcat(driver_path, "\\");
-    strcat(driver_path, DRIVER_NAME);
-    strcat(driver_path, ".sys");
-
-    //
-    // Insure driver file is in the specified directory.
-    //
-
-    if ((file_handle = CreateFile(driver_path,
-                                 GENERIC_READ | GENERIC_WRITE,
-                                 0,
-                                 NULL,
-                                 OPEN_EXISTING,
-                                 FILE_ATTRIBUTE_NORMAL,
-                                 NULL
-                                 )) == INVALID_HANDLE_VALUE) {
-
-
-        printf("Driver: BIOS_PROBE.SYS is not in the system directory. \n");
-
-        //
-        // Indicate failure.
-        //
-
-        return FALSE;
-    }
-
-    //
-    // Close open file handle.
-    //
-
-    if (file_handle) {
-
-        CloseHandle(file_handle);
-    }
-
-    //
-    // Indicate success.
-    //
-
-    return TRUE;
-
-
-}   // setup_driver_name
-
-
-static BOOL extract_driver(char *sz_driver, char *sz_out)
-/*++
-Routine Description:
-	find, load and extract the driver from resource
-
-Arguments: 
-	sz_driver = resource name or number
-	sz_out    = output filename
-    
-Return Value:
-	FALSE = function fails
-	TRUE = function succeds
---*/
-
-{
-	HRSRC h_res;
-	HGLOBAL h_sys;
-	LPVOID p_sys;
-	HANDLE h_file;
-	DWORD dw_size, dw_wri;
-
-	// find and load resources, return false if failed
-	if(!(h_res = FindResource(NULL, sz_driver, TEXT("DRIVER"))))
-		return FALSE;
-
-	if(!(h_sys = LoadResource(0, h_res)))
-		return FALSE;
-
-	dw_size = SizeofResource(0, h_res);
-	p_sys = LockResource(h_sys);
-
-	// create the driver file to the choosen path
-	if((h_file = CreateFile(sz_out, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0)) == INVALID_HANDLE_VALUE)
-		return FALSE;
-
-	// write the driver and and close the file handle
-	if(!WriteFile(h_file, p_sys, dw_size, &dw_wri, 0))
-	{
-		CloseHandle(h_file);
-	 	return FALSE;
-	}
-	
-	CloseHandle(h_file);
-	return TRUE;
-}
-
-
-static BOOL activate_driver(char *sz_serv, char *sz_path, BOOL activate)
-/*++
-Routine Description:
-	register, run, stop and unregister driver
-
-Arguments: 
-	sz_serv   = driver service name
-	sz_path   = path to driver
-	activate = register/unregisterNone
-    
-Return Value:
-	0 = function fails
-	1 = function succeds
---*/
-{
-	BOOL b_stat;
-	SC_HANDLE h_sc, h_sr;
-	SERVICE_STATUS srv_stat;
-
-	b_stat = FALSE;
-	
-	h_sc = OpenSCManager(0, 0, SC_MANAGER_ALL_ACCESS);
-	if(!h_sc) 
-	{
-	    printf("Error: failed to open service control manager\n");
-	    return FALSE;
-	}
-
-	if(activate)
-	{
-	    // start debug		
- 	    printf("creating new service... \n");
-	    // end debug
-	    
-	    h_sr = CreateService(h_sc, sz_serv, sz_serv, SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER, 
-				SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, sz_path, 
-				NULL, NULL, NULL, NULL, NULL);
-		
-	    if(!h_sr) 
-	    {
-	    	// start debug		
- 	    	printf("invalid service handle... \n");
-	    	// end debug
-		    
-		if(GetLastError() == ERROR_SERVICE_EXISTS)
-		{
-		    h_sr = OpenService(h_sc, sz_serv, SERVICE_ALL_ACCESS);
-		    
-		    if(!h_sr)
-		    {
-			printf("Error: failed to open access to the service (service already exists)\n");
-			    
-			CloseServiceHandle(h_sc);
-			return FALSE;
-		    }
-
-		    printf("Error: service already exist!\n");
-		}   
-		else
-		{
-		    // start debug
-		    printf("CreateService failed. But, not because of service exists :(\n");
-		    // end debug
-		    
-		    CloseServiceHandle(h_sc);
-		    return FALSE;
-		}
-	    }
-	    else
-	    {
-		if(StartService(h_sr, 0, NULL) == 0) 
-		{
-		    if(ERROR_SERVICE_ALREADY_RUNNING != GetLastError())
-		    {    
-                        CloseServiceHandle(h_sc);
-                        CloseServiceHandle(h_sr);
-                        return FALSE;
-		    }
-		} 
-		else 
-		{
-		    b_stat = TRUE;
-		}
-	    }
-	}
-	else
-	{
-		if(!(h_sr = OpenService(h_sc, sz_serv, SERVICE_ALL_ACCESS)))
-			b_stat = FALSE;
-		else
-			b_stat = (ControlService(h_sr, SERVICE_CONTROL_STOP, &srv_stat) == 0) ? FALSE : TRUE;
-
-		// unregister the driver
-		b_stat = (DeleteService(h_sr) == 0) ? FALSE : TRUE;
-	}
-
-	// close the service handle
-	if(h_sr) CloseServiceHandle(h_sr);
-	if(h_sc) CloseServiceHandle(h_sc);
-	return b_stat;
-}
-
-
-int init_driver()
-/*++
-Routine Description:
-	Initialize the driver interface
-
-Arguments: None
-    
-Return Value:
-    0 if error
-    1 if succeeded
---*/
-{
-	DWORD err_no;
-
-	// 
-    // Extract the driver binary from the resource in the executable
-    // 
-    if (extract_driver(TEXT("WINFLASHROMDRV"), "winflashrom.sys") == TRUE) {
-		printf("The driver has been extracted\n");
-		
-    } else {
-		display_error_message(GetLastError());
-		printf("Exiting..\n");
-		return 0;
-    }
-    
-    
-    //
-    // Setup full path to driver name.
-    //
-    if (!setup_driver_name(driver_path)) {
-		printf("Error: failed to setup driver name \n");
-        return 0;
-    }
-
-
-    //
-    // Try to activate the driver 
-    //
-    if(activate_driver(DRIVER_NAME, driver_path, TRUE) == TRUE) {
-		printf("The driver is registered and activated\n"); 
-    } else {
-		printf("Error: unable to register and activate the driver\n");
-		DeleteFile(driver_path);
-		return 0;		
-    }
-
-    //
-    // Try to open the newly installed driver.
-    //
-        
-    h_device = CreateFile( "\\\\.\\winflashrom",
-                GENERIC_READ | GENERIC_WRITE,
-                0,
-                NULL,
-                OPEN_EXISTING,
-                FILE_ATTRIBUTE_NORMAL,
-                NULL);
-
-    if ( h_device == INVALID_HANDLE_VALUE ){
-        err_no = GetLastError();	
-		printf ( "Error: CreateFile Failed : %d\n", (int) err_no );
-		display_error_message(err_no);
-
-		// cleanup resurces created and used up to now
-		activate_driver(DRIVER_NAME, driver_path, FALSE);
-		DeleteFile(driver_path);
-	
-        return 0;
-    }
-
-	return 1;
-}
-
-
-void cleanup_driver()
-{
-    //
-    // Close the access to the exported device interface in user-mode
-    //
-	if(h_device != INVALID_HANDLE_VALUE) {
-		CloseHandle(h_device); 
-	}
-
-    //
-    // Unload the driver.  Ignore any errors.
-    //
-    if(activate_driver(DRIVER_NAME, driver_path, FALSE) == TRUE) {
-		printf("The driver stopped and unloaded\n"); 
-    } else {
-		printf("Error: failed to stop and unload the driver\n");
-    }
-
-    //
-    // Delete the driver file
-    // 
-    DeleteFile(driver_path);
-}
-
-
-
-unsigned char inb(unsigned short port)
-{
-    IO_BYTE ioBuf;
-    DWORD bytes_returned;
-    
-    ioBuf.port8 = port; // port address to read from
-    
-
-    if( INVALID_HANDLE_VALUE == h_device) {
-	printf("(inl) Error: the driver handle is invalid!\n");
-	return -1;
-    }
-    
-    if( FALSE == DeviceIoControl( h_device, 
-				 IOCTL_READ_PORT_BYTE,
-				 &ioBuf,
-				 sizeof(ioBuf),
-				 &ioBuf,
-				 sizeof(ioBuf),
-				 &bytes_returned,
-				 NULL))
-    {
-	display_error_message(GetLastError());
-	return -1;
-    }
-
-#ifdef VERBOSE_PORT_MESSAGE
-    printf("number of bytes returned from kernel (IOCTL_READ_PORT_BYTE) : %d\n", 
-	    bytes_returned);
-#endif //VERBOSE_PORT_MESSAGE
-
-    return ioBuf.value8;
-}
-
-
-void outb(unsigned char value, unsigned short port)
-{
-    IO_BYTE ioBuf;
-    DWORD bytes_returned;
-    
-    ioBuf.port8 = port; // port address to write to
-    ioBuf.value8 = value; 
-
-    if( INVALID_HANDLE_VALUE == h_device) {
-	printf("(outw) Error: the driver handle is invalid!\n");
-	return;
-    }
-    
-    if( FALSE == DeviceIoControl( h_device, 
-				 IOCTL_WRITE_PORT_BYTE,
-				 &ioBuf,
-				 sizeof(ioBuf),
-				 &ioBuf,
-				 sizeof(ioBuf),
-				 &bytes_returned,
-				 NULL))
-    {
-	display_error_message(GetLastError());
-    }
-    
- #ifdef VERBOSE_PORT_MESSAGE
-    printf("number of bytes returned from kernel (IOCTL_WRITE_PORT_BYTE) : %d\n", 
-	    bytes_returned);
- #endif //VERBOSE_PORT_MESSAGE
-}
-
-
-unsigned short inw(unsigned short port)
-{
-    IO_WORD ioBuf;
-    DWORD bytes_returned;
-    
-    ioBuf.port16 = port; // port address to read from
-    
-
-    if( INVALID_HANDLE_VALUE == h_device) {
-	printf("(inl) Error: the driver handle is invalid!\n");
-	return -1;
-    }
-    
-    if( FALSE == DeviceIoControl( h_device, 
-				 IOCTL_READ_PORT_WORD,
-				 &ioBuf,
-				 sizeof(ioBuf),
-				 &ioBuf,
-				 sizeof(ioBuf),
-				 &bytes_returned,
-				 NULL))
-    {
-	display_error_message(GetLastError());
-	return -1;
-    }
-
-#ifdef VERBOSE_PORT_MESSAGE
-    printf("number of bytes returned from kernel (IOCTL_READ_PORT_WORD) : %d\n", 
-	    bytes_returned);
-#endif //VERBOSE_PORT_MESSAGE
-
-    return ioBuf.value16;
-}
-
-
-void outw(unsigned short value, unsigned short port)
-{
-    IO_WORD ioBuf;
-    DWORD bytes_returned;
-    
-    ioBuf.port16 = port; // port address to write to
-    ioBuf.value16 = value; 
-
-    if( INVALID_HANDLE_VALUE == h_device) {
-	printf("(outw) Error: the driver handle is invalid!\n");
-	return;
-    }
-    
-    if( FALSE == DeviceIoControl( h_device, 
-				 IOCTL_WRITE_PORT_WORD,
-				 &ioBuf,
-				 sizeof(ioBuf),
-				 &ioBuf,
-				 sizeof(ioBuf),
-				 &bytes_returned,
-				 NULL))
-    {
-	display_error_message(GetLastError());
-    }
-
-#ifdef VERBOSE_PORT_MESSAGE
-    printf("number of bytes returned from kernel (IOCTL_WRITE_PORT_WORD) : %d\n", 
-	    bytes_returned);
-#endif //VERBOSE_PORT_MESSAGE
-}
-
-
-unsigned long inl(unsigned short port)
-{
-    IO_LONG ioBuf;
-    DWORD bytes_returned;
-    
-    ioBuf.port32 = port; // port address to read from
-    
-
-    if( INVALID_HANDLE_VALUE == h_device) {
-	printf("(inl) Error: the driver handle is invalid!\n");
-	return -1;
-    }
-    
-    if( FALSE == DeviceIoControl( h_device, 
-				 IOCTL_READ_PORT_LONG,
-				 &ioBuf,
-				 sizeof(ioBuf),
-				 &ioBuf,
-				 sizeof(ioBuf),
-				 &bytes_returned,
-				 NULL))
-    {
-	display_error_message(GetLastError());
-	return -1;
-    }
-
-	 #ifdef VERBOSE_PORT_MESSAGE
-    printf("number of bytes returned from kernel (IOCTL_READ_PORT_LONG) : %d\n", 
-	    bytes_returned);
-	 #endif //VERBOSE_PORT_MESSAGE
-
-    return ioBuf.value32;
-}
-
-
-void outl(unsigned long value, unsigned short port)
-{
-    IO_LONG ioBuf;
-    DWORD bytes_returned;
-    
-    ioBuf.port32 = port; // port address to write to
-    ioBuf.value32 = value; 
-
-    if( INVALID_HANDLE_VALUE == h_device) {
-	printf("(outl) Error: the driver handle is invalid!\n");
-	return;
-    }
-    
-    if( FALSE == DeviceIoControl( h_device, 
-				 IOCTL_WRITE_PORT_LONG,
-				 &ioBuf,
-				 sizeof(ioBuf),
-				 &ioBuf,
-				 sizeof(ioBuf),
-				 &bytes_returned,
-				 NULL))
-    {
-	display_error_message(GetLastError());
-    }
-
- #ifdef VERBOSE_PORT_MESSAGE
-    printf("number of bytes returned from kernel (IOCTL_WRITE_PORT_LONG) : %d\n", 
-	    bytes_returned);
- #endif //VERBOSE_PORT_MESSAGE
-}
-
-
-void* map_physical_addr_range( unsigned long phy_addr_start, unsigned long size )
-/*++
-Routine Description:
-	Maps an MMIO range.
-
-Arguments:
-    phy_addr_start -  The start of physical address to be mapped.
-	size - The size of the MMIO range to map, in bytes.
-
-Return Value:
-    NULL - on error
-	pointer to the virtual address of the mapped MMIO range - on success
-
-Note:
-	-	The pointer returned from this function is in the context of the 
-	    usermode application that use this function.
-	-	You must call unmap_physical_addr_range when you are done with the  
-		mapped physical memory/MMIO range that you obtain with this function.
---*/
-{
-	MMIO_MAP mmio_map;
-	DWORD bytes_returned;
-
-	if( INVALID_HANDLE_VALUE == h_device) {
-		printf("(map_physical_addr_range) Error: the driver handle is invalid!\n");
-		return 0; // error
-    }
-    
-	mmio_map.phy_addr_start = phy_addr_start;
-	mmio_map.size = size;
-
-    if( FALSE == DeviceIoControl( h_device, 
-					IOCTL_MAP_MMIO,
-					&mmio_map,
-					sizeof(mmio_map),
-					&mmio_map,
-					sizeof(mmio_map),
-					&bytes_returned,
-					NULL))
-    {
-		display_error_message(GetLastError());
-		return NULL; // error
-    }
-
- #ifdef VERBOSE_PORT_MESSAGE
-    printf("number of bytes returned from kernel (IOCTL_MAP_BIOS_CHIP) : %d\n", 
-	    bytes_returned);
- #endif //VERBOSE_PORT_MESSAGE
-
-    return mmio_map.usermode_virt_addr; 
-}	
-
-
-int unmap_physical_addr_range( void* virt_addr_start, unsigned long size )
-/*++
-Routine Description:
-	Unmaps a previously mapped MMIO range.
-
-Arguments:
-    virt_addr_start - The start address of the mapped physical address.
-	                This parameter _must_ _be_ in the context of the 
-					currently executing application. It must be a 
-					pointer returned from a previous call to 
-					map_physical_addr_range function.
-	size - The size of the mapped MMIO range in bytes.
-
-Return Value:
-    0 - on error
-	1 - on success
-
-Note:
-	This function must be called when you are done with a 
-	mapped physical memory/MMIO range.
---*/
-{
-	MMIO_MAP mmio_map;
-	DWORD bytes_returned;
-
-	if( INVALID_HANDLE_VALUE == h_device) {
-		printf("(unmap_physical_addr_range) Error: the driver handle is invalid!\n");
-		return 0; // error
-    	}
-    
-	mmio_map.usermode_virt_addr = virt_addr_start;
-	mmio_map.size = size;
-
-    if( FALSE == DeviceIoControl( h_device, 
-					IOCTL_UNMAP_MMIO,
-					&mmio_map,
-					sizeof(mmio_map),
-					&mmio_map,
-					sizeof(mmio_map),
-					&bytes_returned,
-					NULL))
-    {
-		display_error_message(GetLastError());
-		return 0; // error
-    }
-
- #ifdef VERBOSE_PORT_MESSAGE
-    printf("number of bytes returned from kernel (IOCTL_UNMAP_BIOS_CHIP) : %d\n", 
-	    bytes_returned);
- #endif //VERBOSE_PORT_MESSAGE
-
-	return 1; // success
-}
Index: direct_io.h
===================================================================
--- direct_io.h	(revision 6)
+++ direct_io.h	(revision 1)
@@ -1,20 +0,0 @@
-#ifndef __DIRECT_IO_H__
-#define __DIRECT_IO_H__
-
-int init_driver(); // returns 0 on error, 1 on success
-void cleanup_driver(); // must be called after done using the driver
-
-void* map_physical_addr_range( unsigned long phy_addr_start, 
-						 unsigned long size ); // returns NULL on error, valid pointer on success
-int unmap_physical_addr_range( void* virt_addr_start, 
-		        unsigned long size ); // must be called after done with the mapped physical memory
-
-void outb(unsigned char value, unsigned short port);
-void outw(unsigned short value, unsigned short port);
-void outl(unsigned long value, unsigned short port);
-
-unsigned char inb(unsigned short port);
-unsigned short inw(unsigned short port);
-unsigned long inl(unsigned short port);
-
-#endif //__DIRECT_IO_H__
Index: .dependencies
===================================================================
--- .dependencies	(revision 6)
+++ .dependencies	(revision 1)
@@ -1,29 +0,0 @@
-82802ab.o: 82802ab.c flash.h 82802ab.h debug.h
-am29f040b.o: am29f040b.c flash.h jedec.h udelay.h debug.h
-board_enable.o: board_enable.c libpci/pci.h libpci/header.h flash.h \
-  debug.h direct_io.h
-chipset_enable.o: chipset_enable.c libpci/pci.h libpci/header.h flash.h \
-  debug.h direct_io.h
-direct_io.o: direct_io.c interfaces.h direct_io.h error_msg.h
-error_msg.o: error_msg.c error_msg.h
-flashchips.o: flashchips.c flash.h jedec.h udelay.h m29f400bt.h 82802ab.h \
-  msys_doc.h am29f040b.h sst28sf040.h sst49lfxxxc.h w49f002u.h \
-  sst39sf020.h sst49lf040.h pm49fl004.h mx29f002.h sharplhf00l04.h \
-  sst_fwhub.h
-flashrom.o: flashrom.c libpci/pci.h libpci/header.h direct_io.h flash.h \
-  lbtable.h layout.h debug.h
-jedec.o: jedec.c flash.h jedec.h udelay.h debug.h
-layout.o: layout.c layout.h lbtable.h debug.h
-lbtable.o: lbtable.c flash.h linuxbios_tables.h debug.h direct_io.h
-m29f400bt.o: m29f400bt.c flash.h m29f400bt.h debug.h
-msys_doc.o: msys_doc.c flash.h msys_doc.h debug.h
-mx29f002.o: mx29f002.c flash.h jedec.h udelay.h mx29f002.h debug.h
-pm49fl004.o: pm49fl004.c flash.h jedec.h udelay.h pm49fl004.h
-sharplhf00l04.o: sharplhf00l04.c flash.h sharplhf00l04.h debug.h
-sst28sf040.o: sst28sf040.c flash.h jedec.h udelay.h debug.h
-sst39sf020.o: sst39sf020.c flash.h jedec.h udelay.h sst39sf020.h
-sst49lf040.o: sst49lf040.c flash.h jedec.h udelay.h sst49lf040.h
-sst49lfxxxc.o: sst49lfxxxc.c flash.h jedec.h udelay.h debug.h
-sst_fwhub.o: sst_fwhub.c flash.h jedec.h udelay.h sst_fwhub.h
-udelay.o: udelay.c debug.h
-w49f002u.o: w49f002u.c flash.h jedec.h udelay.h w49f002u.h
Index: udelay.h
===================================================================
--- udelay.h	(revision 6)
+++ udelay.h	(revision 1)
@@ -1,6 +0,0 @@
-#ifndef __UDELAY_H__
-#define __UDELAY_H__
-
-void myusec_delay(int time);
-
-#endif
Index: lbtable.c
===================================================================
--- lbtable.c	(revision 6)
+++ lbtable.c	(revision 1)
@@ -29,10 +29,10 @@
 #include <sys/types.h>
 #include <string.h>
 #include <errno.h>
+#include <sys/mman.h>
 #include "flash.h"
 #include "linuxbios_tables.h"
 #include "debug.h"
-#include "direct_io.h"
 
 char *lb_part = NULL, *lb_vendor = NULL;
 
@@ -181,21 +181,12 @@
 	struct lb_header *lb_table;
 	struct lb_record *rec, *last;
 
-	/*
 	low_1MB = mmap(0, 1024 * 1024, PROT_READ, MAP_SHARED, fd_mem,
 		       0x00000000);
 	if (low_1MB == MAP_FAILED) {
 		perror("Can't mmap memory using " MEM_DEV);
 		exit(-2);
 	}
-	*/
-
-	low_1MB = map_physical_addr_range(0x00000000, 1024 * 1024);
-	if (low_1MB == NULL) {
-		perror("Can't map low 1MB");
-		exit(-2);
-	}
-	
 	lb_table = 0;
 	if (!lb_table)
 		lb_table = find_lb_table(low_1MB, 0x00000, 0x1000);
Index: jedec.h
===================================================================
--- jedec.h	(revision 6)
+++ jedec.h	(revision 1)
@@ -1,8 +1,5 @@
 #ifndef __JEDEC_H__
 #define __JEDEC_H__ 1
-
-#include "udelay.h"
-
 int write_byte_program_jedec(volatile uint8_t *bios, uint8_t *src,
 			     volatile uint8_t *dst);
 
@@ -54,7 +51,7 @@
 	*(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
 	*(volatile uint8_t *)(bios + 0x5555) = 0x20;
 
-	myusec_delay(200);
+	usleep(200);
 }
 
 extern __inline__ void protect_jedec(volatile uint8_t *bios)
@@ -63,7 +60,7 @@
 	*(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
 	*(volatile uint8_t *)(bios + 0x5555) = 0xA0;
 
-	myusec_delay(200);
+	usleep(200);
 }
 
 #endif				/* !__JEDEC_H__ */
Index: sst49lfxxxc.c
===================================================================
--- sst49lfxxxc.c	(revision 6)
+++ sst49lfxxxc.c	(revision 1)
@@ -27,7 +27,7 @@
 
 #include <errno.h>
 #include <fcntl.h>
-//#include <sys/mman.h>
+#include <sys/mman.h>
 #include <unistd.h>
 #include <stdio.h>
 #include <stdlib.h>
Index: sharplhf00l04.h
===================================================================
--- sharplhf00l04.h	(revision 6)
+++ sharplhf00l04.h	(revision 1)
@@ -42,8 +42,7 @@
 	*(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
 	*(volatile uint8_t *)(bios + 0x5555) = 0xA0;
 
-	//usleep(200);
-	myusec_delay(200);
+	usleep(200);
 }
 
 #endif				/* !__SHARPLHF00L04_H__ */
Index: Makefile
===================================================================
--- Makefile	(revision 6)
+++ Makefile	(revision 1)
@@ -6,62 +6,53 @@
 
 PROGRAM = flashrom
 
-RC 	= windres
 CC      = gcc
 STRIP	= strip
 INSTALL = /usr/bin/install
 PREFIX  = /usr/local
-MAKE 	= make
 #CFLAGS  = -O2 -g -Wall -Werror
 CFLAGS  = -Os -Wall -Werror -DDISABLE_DOC # -DTS5300
-#OS_ARCH	= $(shell uname)
-#ifeq ($(OS_ARCH), SunOS)
-#LDFLAGS = -lpci -lz
-#else
-#LDFLAGS = -lpci -lz -static 
-LDFLAGS = -L./libpci -lpci -static 
+OS_ARCH	= $(shell uname)
+ifeq ($(OS_ARCH), SunOS)
+LDFLAGS = -lpci -lz
+else
+LDFLAGS = -lpci -lz -static 
 STRIP_ARGS = -s
-#endif
+endif
 
 OBJS = chipset_enable.o board_enable.o udelay.o jedec.o sst28sf040.o \
 	am29f040b.o mx29f002.o sst39sf020.o m29f400bt.o w49f002u.o \
 	82802ab.o msys_doc.o pm49fl004.o sst49lf040.o sst49lfxxxc.o \
 	sst_fwhub.o layout.o lbtable.o flashchips.o flashrom.o \
-	sharplhf00l04.o direct_io.o error_msg.o 
+	sharplhf00l04.o
 
-RESOURCES = winflashrom.rc
-RESOURCE_OBJ = winflashrom.o
+all: pciutils dep $(PROGRAM)
 
-all: dep $(PROGRAM)
-
 $(PROGRAM): $(OBJS)
-	$(RC) -o $(RESOURCE_OBJ) $(RESOURCES)
-	$(CC) -o $(PROGRAM) $(OBJS) $(RESOURCE_OBJ) $(LDFLAGS)
-	$(STRIP) $(STRIP_ARGS) $(PROGRAM).exe
+	$(CC) -o $(PROGRAM) $(OBJS) $(LDFLAGS)
+	$(STRIP) $(STRIP_ARGS) $(PROGRAM)
 
 clean:
-	$(MAKE) -C libpci clean
-	rm -f $(PROGRAM).exe *.o *~
+	rm -f *.o *~
 
 distclean: clean
-	rm -f $(PROGRAM).exe .dependencies
+	rm -f $(PROGRAM) .dependencies
 	
 dep:
 	@$(CC) -MM *.c > .dependencies
-	$(MAKE) -C libpci
 
-#pciutils:
-#	@echo; echo -n "Checking for pciutils and zlib... "
-#	@$(shell ( echo "#include <pci/pci.h>";		   \
-#		   echo "struct pci_access *pacc;";	   \
-#		   echo "int main(int argc, char **argv)"; \
-#		   echo "{ pacc = pci_alloc(); return 0; }"; ) > .test.c )
-#	@$(CC) $(CFLAGS) .test.c -o .test $(LDFLAGS) &>/dev/null &&	\
-#		echo "found." || ( echo "not found."; echo;		\
-#		echo "Please install pciutils-devel and zlib-devel.";	\
-#		echo "See README for more information."; echo;		\
-#		rm -f .test.c .test; exit 1)
-#	@rm -f .test.c .test
+pciutils:
+	@echo; echo -n "Checking for pciutils and zlib... "
+	@$(shell ( echo "#include <pci/pci.h>";		   \
+		   echo "struct pci_access *pacc;";	   \
+		   echo "int main(int argc, char **argv)"; \
+		   echo "{ pacc = pci_alloc(); return 0; }"; ) > .test.c )
+	@$(CC) $(CFLAGS) .test.c -o .test $(LDFLAGS) &>/dev/null &&	\
+		echo "found." || ( echo "not found."; echo;		\
+		echo "Please install pciutils-devel and zlib-devel.";	\
+		echo "See README for more information."; echo;		\
+		rm -f .test.c .test; exit 1)
+	@rm -f .test.c .test
 
 install: $(PROGRAM)
 	$(INSTALL) flashrom $(PREFIX)/bin
Index: am29f040b.c
===================================================================
--- am29f040b.c	(revision 6)
+++ am29f040b.c	(revision 1)
@@ -24,11 +24,9 @@
 
 #include <stdio.h>
 #include <stdint.h>
-#include <windows.h>
 #include "flash.h"
 #include "jedec.h"
 #include "debug.h"
-//#include "udelay.h"
 
 static __inline__ int erase_sector_29f040b(volatile uint8_t *bios,
 					   unsigned long address)
@@ -40,7 +38,7 @@
 	*(bios + 0x2AA) = 0x55;
 	*(bios + address) = 0x30;
 
-	myusec_delay(2000000);
+	sleep(2);
 
 	/* wait for Toggle bit ready         */
 	toggle_ready_jedec(bios + address);
Index: chipset_enable.c
===================================================================
--- chipset_enable.c	(revision 6)
+++ chipset_enable.c	(revision 1)
@@ -12,14 +12,12 @@
  */
 
 #include <stdio.h>
-#include "libpci/pci.h"
+#include <pci/pci.h>
 #include <stdlib.h>
 
 #include "flash.h"
 #include "debug.h"
 
-#include "direct_io.h"
-
 static int enable_flash_ali_m1533(struct pci_dev *dev, char *name)
 {
 	uint8_t tmp;
Index: flashrom.c
===================================================================
--- flashrom.c	(revision 6)
+++ flashrom.c	(revision 1)
@@ -27,6 +27,7 @@
 
 #include <errno.h>
 #include <fcntl.h>
+#include <sys/mman.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
@@ -34,8 +35,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include <getopt.h>
-#include "libpci/pci.h"
-#include "direct_io.h"
+#include <pci/pci.h>
 
 /* for iopl */
 #if defined (__sun) && (defined(__i386) || defined(__amd64))
@@ -104,7 +104,6 @@
 	volatile uint8_t *registers;
 	size_t size = flash->total_size * 1024;
 
-	/*
 	registers = mmap(0, size, PROT_WRITE | PROT_READ, MAP_SHARED,
 			 fd_mem, (off_t) (0xFFFFFFFF - 0x400000 - size + 1));
 
@@ -112,15 +111,6 @@
 		perror("Can't mmap registers using " MEM_DEV);
 		exit(1);
 	}
-	*/
-	
-	registers = map_physical_addr_range((0xFFFFFFFF - 0x400000 - size + 1), size);
-	if (registers == NULL) {
-		perror("Can't map registers");
-		exit(1);
-	}
-
-	
 	flash->virtual_registers = registers;
 
 	return 0;
@@ -155,17 +145,16 @@
 		 * smaller than 4k or 8k (yet).
 		 */
 
-		/*
 		if (getpagesize() > size) {
 			size = getpagesize();
 			printf("WARNING: size: %d -> %ld (page size)\n",
 			       flash->total_size * 1024, (unsigned long)size);
 		}
-		*/
 
-		bios = map_physical_addr_range(flash_baseaddr, size);
-		if (bios == NULL) {
-			perror("Can't map bios chip");
+		bios = mmap(0, size, PROT_WRITE | PROT_READ, MAP_SHARED,
+			    fd_mem, (off_t) flash_baseaddr);
+		if (bios == MAP_FAILED) {
+			perror("Can't mmap memory using " MEM_DEV);
 			exit(1);
 		}
 		flash->virtual_memory = bios;
@@ -175,8 +164,7 @@
 			       flash->name, flash_baseaddr);
 			return flash;
 		}
-		//munmap((void *)bios, size);
-		unmap_physical_addr_range((void*)bios, size);
+		munmap((void *)bios, size);
 
 		flash++;
 	}
@@ -349,25 +337,16 @@
 	if (optind < argc)
 		filename = argv[optind++];
 
-	
 	/* First get full io access */
-/*
 #if defined (__sun) && (defined(__i386) || defined(__amd64))
 	if (sysi86(SI86V86, V86SC_IOPL, PS_IOPL) != 0) {
 #else
 	if (iopl(3) != 0) {
-        
 #endif
 		fprintf(stderr, "ERROR: iopl failed: \"%s\"\n",
 			strerror(errno));
 		exit(1);
 	}
-*/
-	if( init_driver() == 0)
-	{
-		printf("Error: failed to initialize driver interface\n");
-		exit(1);
-	}	
 
 	/* Initialize PCI access for flash enables */
 	pacc = pci_alloc();	/* Get the pci_access structure */
@@ -376,13 +355,11 @@
 	pci_scan_bus(pacc);	/* We want to get the list of devices */
 
 	/* Open the memory device. A lot of functions need it */
-	/*
 	if ((fd_mem = open(MEM_DEV, O_RDWR)) < 0) {
 		perror("Error: Can not access memory using " MEM_DEV
 		       ". You need to be root.");
 		exit(1);
 	}
-	*/
 
 	myusec_calibrate_delay();
 
@@ -404,7 +381,6 @@
 
 	if ((flash = probe_flash(flashchips)) == NULL) {
 		printf("No EEPROM/flash device found.\n");
-		cleanup_driver();
 		exit(1);
 	}
 
@@ -413,7 +389,6 @@
 	if (!filename && !erase_it) {
 		// FIXME: Do we really want this feature implicitly?
 		printf("OK, only ENABLING flash write, but NOT FLASHING.\n");
-		cleanup_driver();
 		return 0;
 	}
 
@@ -423,12 +398,10 @@
 	if (erase_it) {
 		printf("Erasing flash chip\n");
 		flash->erase(flash);
-		cleanup_driver();
 		exit(0);
 	} else if (read_it) {
 		if ((image = fopen(filename, "w")) == NULL) {
 			perror(filename);
-			cleanup_driver();
 			exit(1);
 		}
 		printf("Reading Flash...");
@@ -449,17 +422,14 @@
 
 		if ((image = fopen(filename, "r")) == NULL) {
 			perror(filename);
-			cleanup_driver();
 			exit(1);
 		}
 		if (fstat(fileno(image), &image_stat) != 0) {
 			perror(filename);
-			cleanup_driver();
 			exit(1);
 		}
 		if (image_stat.st_size != flash->total_size * 1024) {
 			fprintf(stderr, "Error: Image size doesnt match\n");
-			cleanup_driver();
 			exit(1);
 		}
 
@@ -501,7 +471,5 @@
 	if (verify_it)
 		ret |= verify_flash(flash, buf);
 
-	cleanup_driver();
-	
 	return ret;
 }
Index: msys_doc.c
===================================================================
--- msys_doc.c	(revision 6)
+++ msys_doc.c	(revision 1)
@@ -200,7 +200,7 @@
 	doc_read_4nop(bios);
 
 	while (_doc_busy(bios) && (i != 0)) {
-		myusec_delay(timeout * 1000 / 20);
+		usleep(timeout * 1000 / 20);
 		i--;
 	}
 
Index: 82802ab.h
===================================================================
--- 82802ab.h	(revision 6)
+++ 82802ab.h	(revision 1)
@@ -43,7 +43,7 @@
 	*(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
 	*(volatile uint8_t *)(bios + 0x5555) = 0xA0;
 
-	myusec_delay(200);
+	usleep(200);
 }
 
 #endif				/* !__82802AB_H__ */
Index: m29f400bt.h
===================================================================
--- m29f400bt.h	(revision 6)
+++ m29f400bt.h	(revision 1)
@@ -48,7 +48,7 @@
 	*(volatile uint8_t *)(bios + 0x555) = 0x55;
 	*(volatile uint8_t *)(bios + 0xAAA) = 0xA0;
 
-	myusec_delay(200);
+	usleep(200);
 }
 
 extern __inline__ void write_page_m29f400bt(volatile uint8_t *bios,
Index: board_enable.c
===================================================================
--- board_enable.c	(revision 6)
+++ board_enable.c	(revision 1)
@@ -16,15 +16,13 @@
  */
 
 #include <stdio.h>
-#include "libpci/pci.h"
+#include <pci/pci.h>
 #include <stdint.h>
 #include <string.h>
 
 #include "flash.h"
 #include "debug.h"
 
-#include "direct_io.h"
-
 /*
  * Helper functions for many Winbond superIOs of the w836xx range.
  */
