Index: sst39sf020.c
===================================================================
--- sst39sf020.c	(revision 3480)
+++ sst39sf020.c	(working copy)
@@ -18,8 +18,6 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
-#include <stdio.h>
-#include <stdint.h>
 #include "flash.h"
 
 int write_39sf020(struct flashchip *flash, uint8_t *buf)
Index: flash.h
===================================================================
--- flash.h	(revision 3480)
+++ flash.h	(working copy)
@@ -23,30 +23,139 @@
 #ifndef __FLASH_H__
 #define __FLASH_H__ 1
 
-#if defined(__GLIBC__)
-#include <sys/io.h>
-#endif
-#include <unistd.h>
-#include <stdint.h>
-#include <stdio.h>
+#ifdef USE_LIBPAYLOAD
+	#include <libpayload.h>
+	#include <coreboot_tables.h>
 
-#ifdef __FreeBSD__
-  #include <machine/cpufunc.h>
-  #define off64_t off_t
-  #define lseek64 lseek
-  #define OUTB(x, y) do { u_int tmp = (y); outb(tmp, (x)); } while (0)
-  #define OUTW(x, y) do { u_int tmp = (y); outw(tmp, (x)); } while (0)
-  #define OUTL(x, y) do { u_int tmp = (y); outl(tmp, (x)); } while (0)
-  #define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); })
-  #define INW(x) __extension__ ({ u_int tmp = (x); inw(tmp); })
-  #define INL(x) __extension__ ({ u_int tmp = (x); inl(tmp); })
+	#define OUTB outb
+	#define OUTW outw
+	#define OUTL outl
+	#define INB  inb
+	#define INW  inw
+	#define INL  inl
+
+	typedef unsigned int off_t;
+	typedef unsigned long off64_t;
+
+	#define PROT_READ 0x1
+	#define PROT_WRITE 0x2
+	#define MAP_FAILED ((void *) -1)
+	#define MAP_SHARED 0x01
+	#define O_RDWR 02
+	#define O_SYNC 00010000
+	#define FILE int
+	#define strcasecmp strcmp
+	#define usleep myusec_delay
+	#define sleep(x) myusec_delay(1000000*x)
+	
+	#define stdout ((void *)1)
+	#define stderr ((void *)2)
+
+	static inline int fflush(void *f)
+	{
+		return 0;
+	}
+	
+	static inline int fprintf(void *f, const char *fmt, ...)
+	{ 
+		int ret;
+		va_list ap;
+		va_start(ap, fmt);
+		ret = vprintf(fmt, ap);
+		va_end(ap);
+		return ret;
+	}
+
+	static inline void exit(int status)
+	{
+		__asm__ __volatile__("movl %0, %%eax" : : "g" (status) : "%eax");
+	}
+	
+	static inline void perror(const char* s)
+	{
+		printf("%s", s);
+	}
+	
+	static inline void *mem_map(void *start, int len, int offset)
+	{
+		return ((void*)start+offset);
+	}
+	
+	static inline int mem_unmap(void *start, int len)
+	{
+		return 0;
+	}
+
+	static inline void pci_find_card(uint16_t vendor, uint16_t device,
+				uint16_t card_vendor, uint16_t card_device, pcidev_t *dev_ret)
+	{
+		pci_find_device(vendor, device, dev_ret);
+	}
+	
+	static inline int iopl(int level)
+	{
+		return 0;
+	}
+	
+	static inline struct pci_access *pci_alloc(void)
+	{
+		return NULL;
+	}
+	
+	static inline void pci_init(struct pci_access *access)
+	{
+	
+	}
+
+	static inline void pci_scan_bus(struct pci_access *access)
+	{
+		
+	}
+	
 #else
-  #define OUTB outb
-  #define OUTW outw
-  #define OUTL outl
-  #define INB  inb
-  #define INW  inw
-  #define INL  inl
+	
+	#if defined(__GLIBC__)
+		#include <sys/io.h>
+	#endif
+
+	#include <unistd.h>
+	#include <stdint.h>
+	#include <stdio.h>
+
+	#include <sys/io.h>
+	#include <ctype.h>
+	
+	#include <pci/pci.h>
+	#include <stdlib.h>
+	#include <sys/types.h>
+	#include <sys/stat.h>
+	#include <sys/mman.h>
+	#include <fcntl.h>
+	#include <string.h>
+
+	#include "coreboot_tables.h"
+
+	#ifdef __FreeBSD__
+		#include <machine/cpufunc.h>
+		#define off64_t off_t
+		#define lseek64 lseek
+		#define OUTB(x, y) do { u_int tmp = (y); outb(tmp, (x)); } while (0)
+		#define OUTW(x, y) do { u_int tmp = (y); outw(tmp, (x)); } while (0)
+		#define OUTL(x, y) do { u_int tmp = (y); outl(tmp, (x)); } while (0)
+		#define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); })
+		#define INW(x) __extension__ ({ u_int tmp = (x); inw(tmp); })
+		#define INL(x) __extension__ ({ u_int tmp = (x); inl(tmp); })
+	#else
+		#define OUTB outb
+		#define OUTW outw
+		#define OUTL outl
+		#define INB  inb
+		#define INW  inw
+		#define INL  inl
+	#endif
+	
+	typedef struct pci_dev* pcidev_t;
+
 #endif
 
 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
@@ -360,11 +469,7 @@
 
 /* PCI handling for board/chipset_enable */
 struct pci_access *pacc;
-struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
-struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device,
-			      uint16_t card_vendor, uint16_t card_device);
 
-
 /* board_enable.c */
 int board_flash_enable(const char *vendor, const char *part);
 void print_supported_boards(void);
@@ -408,7 +513,7 @@
 
 /* lbtable.c */
 int coreboot_init(void);
-extern char *lb_part, *lb_vendor;
+extern char *cb_part, *cb_vendor;
 
 /* spi.c */
 int probe_spi_rdid(struct flashchip *flash);
@@ -538,4 +643,75 @@
 int erase_stm50flw0x0x(struct flashchip *flash);
 int write_stm50flw0x0x(struct flashchip *flash, uint8_t *buf);
 
+#ifndef USE_LIBPAYLOAD
+	static inline void *mem_map(void *start, int len, int offset)
+	{
+		return mmap(start, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd_mem, offset);
+	}
+
+	static inline int mem_unmap(void *start, int len)
+	{
+		return munmap(start, len);
+	}
+
+	static inline void pci_find_device(uint16_t vendor, uint16_t device, pcidev_t *dev_ret)
+	{
+		pcidev_t temp;
+		struct pci_filter filter;
+
+		pci_filter_init(NULL, &filter);
+		filter.vendor = vendor;
+		filter.device = device;
+
+		for (temp = pacc->devices; temp; temp = temp->next)
+			if (pci_filter_match(&filter, temp))
+				*dev_ret = temp;
+	}
+
+	static inline void pci_find_card(uint16_t vendor, uint16_t device,
+				      uint16_t card_vendor, uint16_t card_device, pcidev_t *dev_ret)
+	{
+		pcidev_t temp;
+		struct pci_filter filter;
+
+		pci_filter_init(NULL, &filter);
+		filter.vendor = vendor;
+		filter.device = device;
+
+		for (temp = pacc->devices; temp; temp = temp->next)
+			if (pci_filter_match(&filter, temp)) {
+				if ((card_vendor == pci_read_word(temp, PCI_SUBSYSTEM_VENDOR_ID)) &&
+				    (card_device == pci_read_word(temp, PCI_SUBSYSTEM_ID)))
+					*dev_ret = temp;
+			}
+	}
+
+	static inline uint8_t pci_read_config8(pcidev_t dev, uint8_t reg)
+	{
+		return pci_read_byte(dev, reg);
+	}
+
+	static inline uint8_t pci_read_config16(pcidev_t dev, uint8_t reg)
+	{
+		return pci_read_word(dev, reg);
+	}
+
+	static inline uint8_t pci_read_config32(pcidev_t dev, uint8_t reg)
+	{
+		return pci_read_long(dev, reg);
+	}
+
+	static inline void pci_write_config8(pcidev_t dev, uint8_t reg, uint16_t data)
+	{
+		pci_write_byte(dev, reg, data);
+	}
+
+	static inline void pci_write_config16(pcidev_t dev, uint8_t reg, uint16_t data)
+	{
+		pci_write_word(dev, reg, data);
+	}
+
+#endif
+
+
 #endif				/* !__FLASH_H__ */
Index: pm49fl00x.c
===================================================================
--- pm49fl00x.c	(revision 3480)
+++ pm49fl00x.c	(working copy)
@@ -20,7 +20,6 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
-#include <stdio.h>
 #include "flash.h"
 
 extern int exclude_start_page, exclude_end_page;
Index: it87spi.c
===================================================================
--- it87spi.c	(revision 3480)
+++ it87spi.c	(working copy)
@@ -23,10 +23,6 @@
  * Contains the ITE IT87* SPI specific routines
  */
 
-#include <stdio.h>
-#include <pci/pci.h>
-#include <stdint.h>
-#include <string.h>
 #include "flash.h"
 #include "spi.h"
 
Index: jedec.c
===================================================================
--- jedec.c	(revision 3480)
+++ jedec.c	(working copy)
@@ -21,8 +21,6 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
-#include <stdio.h>
-#include <stdint.h>
 #include "flash.h"
 
 #define MAX_REFLASH_TRIES 0x10
Index: coreboot_tables.h
===================================================================
--- coreboot_tables.h	(revision 3480)
+++ coreboot_tables.h	(working copy)
@@ -36,19 +36,19 @@
  * 64bit system, a uint64_t would be aligned to 64bit boundaries, 
  * breaking the table format.
  *
- * lb_uint64 will keep 64bit coreboot table values aligned to 32bit
+ * cb_uint64 will keep 64bit coreboot table values aligned to 32bit
  * to ensure compatibility. They can be accessed with the two functions
  * below: unpack_lb64() and pack_lb64()
  *
  * See also: util/lbtdump/lbtdump.c
  */
 
-struct lb_uint64 {
+struct cb_uint64 {
 	uint32_t lo;
 	uint32_t hi;
 };
 
-static inline uint64_t unpack_lb64(struct lb_uint64 value)
+static inline uint64_t unpack_lb64(struct cb_uint64 value)
 {
 	uint64_t result;
 	result = value.hi;
@@ -56,15 +56,15 @@
 	return result;
 }
 
-static inline struct lb_uint64 pack_lb64(uint64_t value)
+static inline struct cb_uint64 pack_lb64(uint64_t value)
 {
-	struct lb_uint64 result;
+	struct cb_uint64 result;
 	result.lo = (value >> 0) & 0xffffffff;
 	result.hi = (value >> 32) & 0xffffffff;
 	return result;
 }
 
-struct lb_header {
+struct cb_header {
 	uint8_t signature[4];	/* LBIO */
 	uint32_t header_bytes;
 	uint32_t header_checksum;
@@ -79,39 +79,39 @@
  * boot enviroment record if you don't know what it easy.  This allows
  * forward compatibility with records not yet defined.
  */
-struct lb_record {
+struct cb_record {
 	uint32_t tag;		/* tag ID */
 	uint32_t size;		/* size of record (in bytes) */
 };
 
-#define LB_TAG_UNUSED	0x0000
+#define CB_TAG_UNUSED	0x0000
 
-#define LB_TAG_MEMORY	0x0001
+#define CB_TAG_MEMORY	0x0001
 
-struct lb_memory_range {
-	struct lb_uint64 start;
-	struct lb_uint64 size;
+struct cb_memory_range {
+	struct cb_uint64 start;
+	struct cb_uint64 size;
 	uint32_t type;
-#define LB_MEM_RAM       1	/* Memory anyone can use */
-#define LB_MEM_RESERVED  2	/* Don't use this memory region */
-#define LB_MEM_TABLE     16	/* Ram configuration tables are kept in */
+#define CB_MEM_RAM       1	/* Memory anyone can use */
+#define CB_MEM_RESERVED  2	/* Don't use this memory region */
+#define CB_MEM_TABLE     16	/* Ram configuration tables are kept in */
 };
 
-struct lb_memory {
+struct cb_memory {
 	uint32_t tag;
 	uint32_t size;
-	struct lb_memory_range map[0];
+	struct cb_memory_range map[0];
 };
 
-#define LB_TAG_HWRPB	0x0002
-struct lb_hwrpb {
+#define CB_TAG_HWRPB	0x0002
+struct cb_hwrpb {
 	uint32_t tag;
 	uint32_t size;
 	uint64_t hwrpb;
 };
 
-#define LB_TAG_MAINBOARD	0x0003
-struct lb_mainboard {
+#define CB_TAG_MAINBOARD	0x0003
+struct cb_mainboard {
 	uint32_t tag;
 	uint32_t size;
 	uint8_t vendor_idx;
@@ -119,24 +119,24 @@
 	uint8_t strings[0];
 };
 
-#define LB_TAG_VERSION		0x0004
-#define LB_TAG_EXTRA_VERSION	0x0005
-#define LB_TAG_BUILD		0x0006
-#define LB_TAG_COMPILE_TIME	0x0007
-#define LB_TAG_COMPILE_BY	0x0008
-#define LB_TAG_COMPILE_HOST	0x0009
-#define LB_TAG_COMPILE_DOMAIN	0x000a
-#define LB_TAG_COMPILER		0x000b
-#define LB_TAG_LINKER		0x000c
-#define LB_TAG_ASSEMBLER	0x000d
-struct lb_string {
+#define CB_TAG_VERSION		0x0004
+#define CB_TAG_EXTRA_VERSION	0x0005
+#define CB_TAG_BUILD		0x0006
+#define CB_TAG_COMPILE_TIME	0x0007
+#define CB_TAG_COMPILE_BY	0x0008
+#define CB_TAG_COMPILE_HOST	0x0009
+#define CB_TAG_COMPILE_DOMAIN	0x000a
+#define CB_TAG_COMPILER		0x000b
+#define CB_TAG_LINKER		0x000c
+#define CB_TAG_ASSEMBLER	0x000d
+struct cb_string {
 	uint32_t tag;
 	uint32_t size;
 	uint8_t string[0];
 };
 
 /* The following structures are for the cmos definitions table */
-#define LB_TAG_CMOS_OPTION_TABLE 200
+#define CB_TAG_CMOS_OPTION_TABLE 200
 /* cmos header record */
 struct cmos_option_table {
 	uint32_t tag;		/* CMOS definitions table type */
@@ -151,7 +151,7 @@
         starts at the beginning of the byte and the length is
         fills complete bytes.
 */
-#define LB_TAG_OPTION 201
+#define CB_TAG_OPTION 201
 struct cmos_entries {
 	uint32_t tag;		/* entry type */
 	uint32_t size;		/* length of this record */
@@ -168,7 +168,7 @@
         This record is variable length.  The text field may be
         shorter than CMOS_MAX_TEXT_LENGTH.
 */
-#define LB_TAG_OPTION_ENUM 202
+#define CB_TAG_OPTION_ENUM 202
 struct cmos_enums {
 	uint32_t tag;		/* enumeration type */
 	uint32_t size;		/* length of this record */
@@ -182,7 +182,7 @@
 /* cmos defaults record
         This record contains default settings for the cmos ram.
 */
-#define LB_TAG_OPTION_DEFAULTS 203
+#define CB_TAG_OPTION_DEFAULTS 203
 struct cmos_defaults {
 	uint32_t tag;		/* default type */
 	uint32_t size;		/* length of this record */
@@ -192,7 +192,7 @@
 	uint8_t default_set[CMOS_IMAGE_BUFFER_SIZE];	/* default settings */
 };
 
-#define LB_TAG_OPTION_CHECKSUM 204
+#define CB_TAG_OPTION_CHECKSUM 204
 struct cmos_checksum {
 	uint32_t tag;
 	uint32_t size;
Index: w29ee011.c
===================================================================
--- w29ee011.c	(revision 3480)
+++ w29ee011.c	(working copy)
@@ -18,7 +18,6 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
-#include <string.h>
 #include "flash.h"
 
 int probe_w29ee011(struct flashchip *flash)
Index: sst49lfxxxc.c
===================================================================
--- sst49lfxxxc.c	(revision 3480)
+++ sst49lfxxxc.c	(working copy)
@@ -19,13 +19,6 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
-#include <errno.h>
-#include <fcntl.h>
-#include <sys/mman.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdint.h>
 #include "flash.h"
 
 #define SECTOR_ERASE		0x30
Index: sharplhf00l04.c
===================================================================
--- sharplhf00l04.c	(revision 3480)
+++ sharplhf00l04.c	(working copy)
@@ -18,8 +18,6 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
-#include <stdio.h>
-#include <stdlib.h>
 #include "flash.h"
 
 // I need that Berkeley bit-map printer
Index: spi.c
===================================================================
--- spi.c	(revision 3480)
+++ spi.c	(working copy)
@@ -22,10 +22,6 @@
  * Contains the generic SPI framework
  */
 
-#include <stdio.h>
-#include <pci/pci.h>
-#include <stdint.h>
-#include <string.h>
 #include "flash.h"
 #include "spi.h"
 
Index: Makefile
===================================================================
--- Makefile	(revision 3480)
+++ Makefile	(working copy)
@@ -5,18 +5,21 @@
 #
 
 PROGRAM = flashrom
+LIBPAYLOAD_DIR := /opt/libpayload
+LP_PREFIX := $(LIBPAYLOAD_DIR)/bin/lp
 
-CC      = gcc
+CC      = $(LP_PREFIX)gcc
+AS	= $(LP_PREFIX)as
 STRIP	= strip
 INSTALL = /usr/bin/install
 PREFIX  = /usr/local
 #CFLAGS  = -O2 -g -Wall -Werror
-CFLAGS  = -Os -Wall -Werror # -DTS5300
+CFLAGS  = -Os -Wall -Werror -DUSE_LIBPAYLOAD# -DTS5300
 OS_ARCH	= $(shell uname)
 ifeq ($(OS_ARCH), SunOS)
 LDFLAGS = -lpci -lz
 else
-LDFLAGS = -lpci -lz
+LDFLAGS = -lpci -lz -static
 STRIP_ARGS = -s
 endif
 ifeq ($(OS_ARCH), FreeBSD)
@@ -31,7 +34,7 @@
 	flashrom.o w39v080fa.o sharplhf00l04.o w29ee011.o spi.o it87spi.o \
 	ichspi.o w39v040c.o
 
-all: pciutils dep $(PROGRAM)
+all: dep $(PROGRAM)
 
 # Set the flashrom version string from the highest revision number
 # of the checked out flashrom files.
@@ -40,7 +43,7 @@
 
 $(PROGRAM): $(OBJS)
 	$(CC) -o $(PROGRAM) $(OBJS) $(LDFLAGS)
-	$(STRIP) $(STRIP_ARGS) $(PROGRAM)
+##	$(STRIP) $(STRIP_ARGS) $(PROGRAM)
 
 flashrom.o: flashrom.c
 	$(CC) -c $(CFLAGS) $(SVNDEF) $(CPPFLAGS) $< -o $@
Index: w39v040c.c
===================================================================
--- w39v040c.c	(revision 3480)
+++ w39v040c.c	(working copy)
@@ -18,7 +18,6 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
-#include <stdio.h>
 #include "flash.h"
 
 int probe_w39v040c(struct flashchip *flash)
Index: sst28sf040.c
===================================================================
--- sst28sf040.c	(revision 3480)
+++ sst28sf040.c	(working copy)
@@ -19,8 +19,6 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
-#include <stdio.h>
-#include <stdint.h>
 #include "flash.h"
 
 #define AUTO_PG_ERASE1		0x20
Index: w49f002u.c
===================================================================
--- w49f002u.c	(revision 3480)
+++ w49f002u.c	(working copy)
@@ -18,7 +18,6 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
-#include <stdio.h>
 #include "flash.h"
 
 int write_49f002(struct flashchip *flash, uint8_t *buf)
Index: stm50flw0x0x.c
===================================================================
--- stm50flw0x0x.c	(revision 3480)
+++ stm50flw0x0x.c	(working copy)
@@ -28,9 +28,6 @@
  *
  */
 
-#include <stdio.h>
-#include <string.h>
-#include <stdint.h>
 #include "flash.h"
 
 void protect_stm50flw0x0x(volatile uint8_t *bios)
Index: sst_fwhub.c
===================================================================
--- sst_fwhub.c	(revision 3480)
+++ sst_fwhub.c	(working copy)
@@ -20,7 +20,6 @@
 
 /* Adapted from the Intel FW hub stuff for 82802ax parts. */
 
-#include <stdio.h>
 #include "flash.h"
 
 // I need that Berkeley bit-map printer
Index: am29f040b.c
===================================================================
--- am29f040b.c	(revision 3480)
+++ am29f040b.c	(working copy)
@@ -18,8 +18,6 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
-#include <stdio.h>
-#include <stdint.h>
 #include "flash.h"
 
 static __inline__ int erase_sector_29f040b(volatile uint8_t *bios,
Index: chipset_enable.c
===================================================================
--- chipset_enable.c	(revision 3480)
+++ chipset_enable.c	(working copy)
@@ -25,14 +25,6 @@
 
 #define _LARGEFILE64_SOURCE
 
-#include <stdio.h>
-#include <pci/pci.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/mman.h>
-#include <fcntl.h>
-#include <unistd.h>
 #include "flash.h"
 
 /**
@@ -46,7 +38,7 @@
 void *spibar = NULL;
 
 
-static int enable_flash_ali_m1533(struct pci_dev *dev, const char *name)
+static int enable_flash_ali_m1533(pcidev_t dev, const char *name)
 {
 	uint8_t tmp;
 
@@ -54,24 +46,24 @@
 	 * ROM Write enable, 0xFFFC0000-0xFFFDFFFF and
 	 * 0xFFFE0000-0xFFFFFFFF ROM select enable.
 	 */
-	tmp = pci_read_byte(dev, 0x47);
+	tmp = pci_read_config8(dev, 0x47);
 	tmp |= 0x46;
-	pci_write_byte(dev, 0x47, tmp);
+	pci_write_config8(dev, 0x47, tmp);
 
 	return 0;
 }
 
-static int enable_flash_sis630(struct pci_dev *dev, const char *name)
+static int enable_flash_sis630(pcidev_t dev, const char *name)
 {
 	uint8_t b;
 
 	/* Enable 0xFFF8000~0xFFFF0000 decoding on SiS 540/630. */
-	b = pci_read_byte(dev, 0x40);
-	pci_write_byte(dev, 0x40, b | 0xb);
+	b = pci_read_config8(dev, 0x40);
+	pci_write_config8(dev, 0x40, b | 0xb);
 
 	/* Flash write enable on SiS 540/630. */
-	b = pci_read_byte(dev, 0x45);
-	pci_write_byte(dev, 0x45, b | 0x40);
+	b = pci_read_config8(dev, 0x45);
+	pci_write_config8(dev, 0x45, b | 0x40);
 
 	/* The same thing on SiS 950 Super I/O side... */
 
@@ -117,12 +109,12 @@
  *   - PDF: http://www.intel.com/design/intarch/datashts/29056201.pdf
  *   - Order Number: 290562-001
  */
-static int enable_flash_piix4(struct pci_dev *dev, const char *name)
+static int enable_flash_piix4(pcidev_t dev, const char *name)
 {
 	uint16_t old, new;
 	uint16_t xbcs = 0x4e;	/* X-Bus Chip Select register. */
 
-	old = pci_read_word(dev, xbcs);
+	old = pci_read_config16(dev, xbcs);
 
 	/* Set bit 9: 1-Meg Extended BIOS Enable (PCI master accesses to
 	 *            FFF00000-FFF7FFFF are forwarded to ISA).
@@ -140,9 +132,9 @@
 	if (new == old)
 		return 0;
 
-	pci_write_word(dev, xbcs, new);
+	pci_write_config16(dev, xbcs, new);
 
-	if (pci_read_word(dev, xbcs) != new) {
+	if (pci_read_config16(dev, xbcs) != new) {
 		printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", xbcs, new, name);
 		return -1;
 	}
@@ -154,7 +146,7 @@
  * See ie. page 375 of "Intel I/O Controller Hub 7 (ICH7) Family Datasheet"
  * http://download.intel.com/design/chipsets/datashts/30701303.pdf
  */
-static int enable_flash_ich(struct pci_dev *dev, const char *name,
+static int enable_flash_ich(pcidev_t dev, const char *name,
 			    int bios_cntl)
 {
 	uint8_t old, new;
@@ -163,7 +155,7 @@
 	 * Note: the ICH0-ICH5 BIOS_CNTL register is actually 16 bit wide, but
 	 * just treating it as 8 bit wide seems to work fine in practice.
 	 */
-	old = pci_read_byte(dev, bios_cntl);
+	old = pci_read_config8(dev, bios_cntl);
 
 	printf_debug("\nBIOS Lock Enable: %sabled, ",
 		     (old & (1 << 1)) ? "en" : "dis");
@@ -176,9 +168,9 @@
 	if (new == old)
 		return 0;
 
-	pci_write_byte(dev, bios_cntl, new);
+	pci_write_config8(dev, bios_cntl, new);
 
-	if (pci_read_byte(dev, bios_cntl) != new) {
+	if (pci_read_config8(dev, bios_cntl) != new) {
 		printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", bios_cntl, new, name);
 		return -1;
 	}
@@ -186,12 +178,12 @@
 	return 0;
 }
 
-static int enable_flash_ich_4e(struct pci_dev *dev, const char *name)
+static int enable_flash_ich_4e(pcidev_t dev, const char *name)
 {
 	return enable_flash_ich(dev, name, 0x4e);
 }
 
-static int enable_flash_ich_dc(struct pci_dev *dev, const char *name)
+static int enable_flash_ich_dc(pcidev_t dev, const char *name)
 {
 	return enable_flash_ich(dev, name, 0xdc);
 }
@@ -201,13 +193,12 @@
 #define ICH_STRAP_PCI  0x02
 #define ICH_STRAP_LPC  0x03
 
-static int enable_flash_vt8237s_spi(struct pci_dev *dev, const char *name) {
+static int enable_flash_vt8237s_spi(pcidev_t dev, const char *name) {
 	uint32_t mmio_base;
 
-	mmio_base = (pci_read_long(dev, 0xbc)) << 8;
+	mmio_base = (pci_read_config32(dev, 0xbc)) << 8;
 	printf_debug("MMIO base at = 0x%x\n", mmio_base);
-	spibar =  mmap(NULL, 0x70, PROT_READ | PROT_WRITE, MAP_SHARED,
-				fd_mem, mmio_base);
+	spibar =  mem_map(0, 0x70, mmio_base);
 
 	if (spibar == MAP_FAILED) {
 		perror("Can't mmap memory using " MEM_DEV);
@@ -221,7 +212,7 @@
 	return 0;
 }
 
-static int enable_flash_ich_dc_spi(struct pci_dev *dev, const char *name, int ich_generation)
+static int enable_flash_ich_dc_spi(pcidev_t dev, const char *name, int ich_generation)
 {
 	int ret, i;
 	uint8_t old, new, bbs, buc;
@@ -234,11 +225,11 @@
 	ret = enable_flash_ich_dc(dev, name);
 
 	/* Get physical address of Root Complex Register Block */
-	tmp = pci_read_long(dev, 0xf0) & 0xffffc000;
+	tmp = pci_read_config32(dev, 0xf0) & 0xffffc000;
 	printf_debug("\nRoot Complex Register Block address = 0x%x\n", tmp);
 
 	/* Map RCBA to virtual memory */
-	rcrb = mmap(0, 0x4000, PROT_READ | PROT_WRITE, MAP_SHARED, fd_mem, (off_t)tmp);
+	rcrb = mem_map(0, 0x4000, (off_t)tmp);
 	if (rcrb == MAP_FAILED) {
 		perror("Can't mmap memory using " MEM_DEV);
 		exit(1);
@@ -247,7 +238,7 @@
 	gcs = *(volatile uint32_t *)(rcrb + 0x3410);
 	printf_debug("GCS = 0x%x: ", gcs);
 	printf_debug("BIOS Interface Lock-Down: %sabled, ",
-		     (gcs & 0x1) ? "en" : "dis");
+		(gcs & 0x1) ? "en" : "dis");
 	bbs = (gcs >> 10) & 0x3;
 	printf_debug("BOOT BIOS Straps: 0x%x (%s)\n", bbs, straps_names[bbs]);
 
@@ -323,7 +314,7 @@
 		break;
 	}
 
-	old = pci_read_byte(dev, 0xdc);
+	old = pci_read_config8(dev, 0xdc);
 	printf_debug("SPI Read Configuration: ");
 	new = (old >> 2) & 0x3;
 	switch (new) {
@@ -342,34 +333,34 @@
 	return ret;
 }
 
-static int enable_flash_ich7(struct pci_dev *dev, const char *name)
+static int enable_flash_ich7(pcidev_t dev, const char *name)
 {
 	return enable_flash_ich_dc_spi(dev, name, 7);
 }
 
-static int enable_flash_ich8(struct pci_dev *dev, const char *name)
+static int enable_flash_ich8(pcidev_t dev, const char *name)
 {
 	return enable_flash_ich_dc_spi(dev, name, 8);
 }
 
-static int enable_flash_ich9(struct pci_dev *dev, const char *name)
+static int enable_flash_ich9(pcidev_t dev, const char *name)
 {
 	return enable_flash_ich_dc_spi(dev, name, 9);
 }
 
-static int enable_flash_vt823x(struct pci_dev *dev, const char *name)
+static int enable_flash_vt823x(pcidev_t dev, const char *name)
 {
 	uint8_t val;
 
 	/* enable ROM decode range (1MB) FFC00000 - FFFFFFFF*/
-	pci_write_byte(dev, 0x41, 0x7f);
+	pci_write_config8(dev, 0x41, 0x7f);
 
 	/* ROM write enable */
-	val = pci_read_byte(dev, 0x40);
+	val = pci_read_config8(dev, 0x40);
 	val |= 0x10;
-	pci_write_byte(dev, 0x40, val);
+	pci_write_config8(dev, 0x40, val);
 
-	if (pci_read_byte(dev, 0x40) != val) {
+	if (pci_read_config8(dev, 0x40) != val) {
 		printf("\nWARNING: Failed to enable ROM Write on \"%s\"\n",
 		       name);
 		return -1;
@@ -378,7 +369,7 @@
 	return 0;
 }
 
-static int enable_flash_cs5530(struct pci_dev *dev, const char *name)
+static int enable_flash_cs5530(pcidev_t dev, const char *name)
 {
 	uint8_t reg8;
 
@@ -394,16 +385,16 @@
 	 * decode 0xFF000000-0xFFFFFFFF (16 MB), not just 256 KB.
 	 * Make the configured ROM areas writable.
 	 */
-	reg8 = pci_read_byte(dev, ROM_AT_LOGIC_CONTROL_REG);
+	reg8 = pci_read_config8(dev, ROM_AT_LOGIC_CONTROL_REG);
 	reg8 |= LOWER_ROM_ADDRESS_RANGE;
 	reg8 |= UPPER_ROM_ADDRESS_RANGE;
 	reg8 |= ROM_WRITE_ENABLE;
-	pci_write_byte(dev, ROM_AT_LOGIC_CONTROL_REG, reg8);
+	pci_write_config8(dev, ROM_AT_LOGIC_CONTROL_REG, reg8);
 
 	/* Set positive decode on ROM. */
-	reg8 = pci_read_byte(dev, DECODE_CONTROL_REG2);
+	reg8 = pci_read_config8(dev, DECODE_CONTROL_REG2);
 	reg8 |= BIOS_ROM_POSITIVE_DECODE;
-	pci_write_byte(dev, DECODE_CONTROL_REG2, reg8);
+	pci_write_config8(dev, DECODE_CONTROL_REG2, reg8);
 
 	return 0;
 }
@@ -425,7 +416,8 @@
  *
  * This is probably not portable beyond Linux.
  */
-static int enable_flash_cs5536(struct pci_dev *dev, const char *name)
+#if 0
+static int enable_flash_cs5536(pcidev_t dev, const char *name)
 {
 	#define MSR_RCONF_DEFAULT	0x1808
 	#define MSR_NORF_CTL		0x51400018
@@ -499,14 +491,15 @@
 	#undef MSR_NORF_CTL
 	return 0;
 }
+#endif
 
-static int enable_flash_sc1100(struct pci_dev *dev, const char *name)
+static int enable_flash_sc1100(pcidev_t dev, const char *name)
 {
 	uint8_t new;
 
-	pci_write_byte(dev, 0x52, 0xee);
+	pci_write_config8(dev, 0x52, 0xee);
 
-	new = pci_read_byte(dev, 0x52);
+	new = pci_read_config8(dev, 0x52);
 
 	if (new != 0xee) {
 		printf("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x52, new, name);
@@ -516,18 +509,18 @@
 	return 0;
 }
 
-static int enable_flash_sis5595(struct pci_dev *dev, const char *name)
+static int enable_flash_sis5595(pcidev_t dev, const char *name)
 {
 	uint8_t new, newer;
 
-	new = pci_read_byte(dev, 0x45);
+	new = pci_read_config8(dev, 0x45);
 
 	new &= (~0x20);		/* Clear bit 5. */
 	new |= 0x4;		/* Set bit 2. */
 
-	pci_write_byte(dev, 0x45, new);
+	pci_write_config8(dev, 0x45, new);
 
-	newer = pci_read_byte(dev, 0x45);
+	newer = pci_read_config8(dev, 0x45);
 	if (newer != new) {
 		printf("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x45, new, name);
 		printf("Stuck at 0x%x\n", newer);
@@ -537,27 +530,27 @@
 	return 0;
 }
 
-static int enable_flash_amd8111(struct pci_dev *dev, const char *name)
+static int enable_flash_amd8111(pcidev_t dev, const char *name)
 {
 	uint8_t old, new;
 
 	/* Enable decoding at 0xffb00000 to 0xffffffff. */
-	old = pci_read_byte(dev, 0x43);
+	old = pci_read_config8(dev, 0x43);
 	new = old | 0xC0;
 	if (new != old) {
-		pci_write_byte(dev, 0x43, new);
-		if (pci_read_byte(dev, 0x43) != new) {
+		pci_write_config8(dev, 0x43, new);
+		if (pci_read_config8(dev, 0x43) != new) {
 			printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x43, new, name);
 		}
 	}
 
-	old = pci_read_byte(dev, 0x40);
+	old = pci_read_config8(dev, 0x40);
 	new = old | 0x01;
 	if (new == old)
 		return 0;
-	pci_write_byte(dev, 0x40, new);
+	pci_write_config8(dev, 0x40, new);
 
-	if (pci_read_byte(dev, 0x40) != new) {
+	if (pci_read_config8(dev, 0x40) != new) {
 		printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x40, new, name);
 		return -1;
 	}
@@ -565,26 +558,26 @@
 	return 0;
 }
 
-static int enable_flash_ck804(struct pci_dev *dev, const char *name)
+static int enable_flash_ck804(pcidev_t dev, const char *name)
 {
 	uint8_t old, new;
 
-	old = pci_read_byte(dev, 0x88);
+	old = pci_read_config8(dev, 0x88);
 	new = old | 0xc0;
 	if (new != old) {
-		pci_write_byte(dev, 0x88, new);
-		if (pci_read_byte(dev, 0x88) != new) {
+		pci_write_config8(dev, 0x88, new);
+		if (pci_read_config8(dev, 0x88) != new) {
 			printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x88, new, name);
 		}
 	}
 
-	old = pci_read_byte(dev, 0x6d);
+	old = pci_read_config8(dev, 0x6d);
 	new = old | 0x01;
 	if (new == old)
 		return 0;
-	pci_write_byte(dev, 0x6d, new);
+	pci_write_config8(dev, 0x6d, new);
 
-	if (pci_read_byte(dev, 0x6d) != new) {
+	if (pci_read_config8(dev, 0x6d) != new) {
 		printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x6d, new, name);
 		return -1;
 	}
@@ -592,12 +585,13 @@
 	return 0;
 }
 
+#if 0
 /* ATI Technologies Inc IXP SB400 PCI-ISA Bridge (rev 80) */
-static int enable_flash_sb400(struct pci_dev *dev, const char *name)
+static int enable_flash_sb400(pcidev_t dev, const char *name)
 {
 	uint8_t tmp;
 	struct pci_filter f;
-	struct pci_dev *smbusdev;
+	pcidev_t smbusdev;
 
 	/* Look for the SMBus device. */
 	pci_filter_init((struct pci_access *)0, &f);
@@ -616,14 +610,14 @@
 	}
 
 	/* Enable some SMBus stuff. */
-	tmp = pci_read_byte(smbusdev, 0x79);
+	tmp = pci_read_config8(smbusdev, 0x79);
 	tmp |= 0x01;
-	pci_write_byte(smbusdev, 0x79, tmp);
+	pci_write_config8(smbusdev, 0x79, tmp);
 
 	/* Change southbridge. */
-	tmp = pci_read_byte(dev, 0x48);
+	tmp = pci_read_config8(dev, 0x48);
 	tmp |= 0x21;
-	pci_write_byte(dev, 0x48, tmp);
+	pci_write_config8(dev, 0x48, tmp);
 
 	/* Now become a bit silly. */
 	tmp = INB(0xc6f);
@@ -636,30 +630,31 @@
 
 	return 0;
 }
+#endif
 
-static int enable_flash_mcp55(struct pci_dev *dev, const char *name)
+static int enable_flash_mcp55(pcidev_t dev, const char *name)
 {
 	uint8_t old, new, byte;
 	uint16_t word;
 
 	/* Set the 0-16 MB enable bits. */
-	byte = pci_read_byte(dev, 0x88);
+	byte = pci_read_config8(dev, 0x88);
 	byte |= 0xff;		/* 256K */
-	pci_write_byte(dev, 0x88, byte);
-	byte = pci_read_byte(dev, 0x8c);
+	pci_write_config8(dev, 0x88, byte);
+	byte = pci_read_config8(dev, 0x8c);
 	byte |= 0xff;		/* 1M */
-	pci_write_byte(dev, 0x8c, byte);
-	word = pci_read_word(dev, 0x90);
+	pci_write_config8(dev, 0x8c, byte);
+	word = pci_read_config16(dev, 0x90);
 	word |= 0x7fff;		/* 16M */
-	pci_write_word(dev, 0x90, word);
+	pci_write_config16(dev, 0x90, word);
 
-	old = pci_read_byte(dev, 0x6d);
+	old = pci_read_config8(dev, 0x6d);
 	new = old | 0x01;
 	if (new == old)
 		return 0;
-	pci_write_byte(dev, 0x6d, new);
+	pci_write_config8(dev, 0x6d, new);
 
-	if (pci_read_byte(dev, 0x6d) != new) {
+	if (pci_read_config8(dev, 0x6d) != new) {
 		printf
 		    ("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n",
 		     0x6d, new, name);
@@ -669,18 +664,18 @@
 	return 0;
 }
 
-static int enable_flash_ht1000(struct pci_dev *dev, const char *name)
+static int enable_flash_ht1000(pcidev_t dev, const char *name)
 {
 	uint8_t byte;
 
 	/* Set the 4MB enable bit. */
-	byte = pci_read_byte(dev, 0x41);
+	byte = pci_read_config8(dev, 0x41);
 	byte |= 0x0e;
-	pci_write_byte(dev, 0x41, byte);
+	pci_write_config8(dev, 0x41, byte);
 
-	byte = pci_read_byte(dev, 0x43);
+	byte = pci_read_config8(dev, 0x43);
 	byte |= (1 << 4);
-	pci_write_byte(dev, 0x43, byte);
+	pci_write_config8(dev, 0x43, byte);
 
 	return 0;
 }
@@ -688,7 +683,7 @@
 typedef struct penable {
 	uint16_t vendor, device;
 	const char *name;
-	int (*doit) (struct pci_dev *dev, const char *name);
+	int (*doit) (pcidev_t dev, const char *name);
 } FLASH_ENABLE;
 
 static const FLASH_ENABLE enables[] = {
@@ -731,7 +726,7 @@
 	{0x1078, 0x0100, "AMD CS5530(A)",	enable_flash_cs5530},
 	{0x100b, 0x0510, "AMD SC1100",		enable_flash_sc1100},
 	{0x1039, 0x0008, "SiS5595",		enable_flash_sis5595},
-	{0x1022, 0x2080, "AMD CS5536",		enable_flash_cs5536},
+//	{0x1022, 0x2080, "AMD CS5536",		enable_flash_cs5536},
 	{0x1022, 0x7468, "AMD8111",		enable_flash_amd8111},
 	{0x10B9, 0x1533, "ALi M1533",		enable_flash_ali_m1533},
 	{0x10de, 0x0050, "NVIDIA CK804",	enable_flash_ck804}, /* LPC */
@@ -751,7 +746,7 @@
 	{0x10de, 0x0366, "NVIDIA MCP55",	enable_flash_mcp55}, /* LPC */
 	{0x10de, 0x0367, "NVIDIA MCP55",	enable_flash_mcp55}, /* Pro */
 	{0x10de, 0x0548, "NVIDIA MCP67",	enable_flash_mcp55},
-	{0x1002, 0x4377, "ATI SB400",		enable_flash_sb400},
+//	{0x1002, 0x4377, "ATI SB400",		enable_flash_sb400},
 	{0x1166, 0x0205, "Broadcom HT-1000",	enable_flash_ht1000},
 };
 
@@ -768,13 +763,13 @@
 
 int chipset_flash_enable(void)
 {
-	struct pci_dev *dev = 0;
+	pcidev_t dev = 0;
 	int ret = -2;		/* Nothing! */
 	int i;
 
 	/* Now let's try to find the chipset we have... */
 	for (i = 0; i < ARRAY_SIZE(enables); i++) {
-		dev = pci_dev_find(enables[i].vendor, enables[i].device);
+		pci_find_device(enables[i].vendor, enables[i].device, &dev);
 		if (dev)
 			break;
 	}
Index: w39v080fa.c
===================================================================
--- w39v080fa.c	(revision 3480)
+++ w39v080fa.c	(working copy)
@@ -18,7 +18,6 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
-#include <stdio.h>
 #include "flash.h"
 
 int probe_winbond_fwhub(struct flashchip *flash)
Index: flashrom.c
===================================================================
--- flashrom.c	(revision 3480)
+++ flashrom.c	(working copy)
@@ -20,23 +20,25 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
-#include <errno.h>
-#include <fcntl.h>
-#include <sys/mman.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <getopt.h>
-#include <pci/pci.h>
-/* for iopl */
-#if defined (__sun) && (defined(__i386) || defined(__amd64))
-#include <strings.h>
-#include <sys/sysi86.h>
-#include <sys/psw.h>
-#include <asm/sunddi.h>
+#ifndef USE_LIBPAYLOAD
+	#include <errno.h>
+	#include <fcntl.h>
+	#include <sys/mman.h>
+	#include <sys/types.h>
+	#include <sys/stat.h>
+	#include <unistd.h>
+	#include <stdio.h>
+	#include <string.h>
+	#include <stdlib.h>
+	#include <getopt.h>
+	#include <pci/pci.h>
+	/* for iopl */
+	#if defined (__sun) && (defined(__i386) || defined(__amd64))
+		#include <strings.h>
+		#include <sys/sysi86.h>
+		#include <sys/psw.h>
+		#include <asm/sunddi.h>
+	#endif
 #endif
 #include "flash.h"
 
@@ -46,49 +48,12 @@
 int verbose = 0;
 int fd_mem;
 
-struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device)
-{
-	struct pci_dev *temp;
-	struct pci_filter filter;
-
-	pci_filter_init(NULL, &filter);
-	filter.vendor = vendor;
-	filter.device = device;
-
-	for (temp = pacc->devices; temp; temp = temp->next)
-		if (pci_filter_match(&filter, temp))
-			return temp;
-
-	return NULL;
-}
-
-struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device,
-			      uint16_t card_vendor, uint16_t card_device)
-{
-	struct pci_dev *temp;
-	struct pci_filter filter;
-
-	pci_filter_init(NULL, &filter);
-	filter.vendor = vendor;
-	filter.device = device;
-
-	for (temp = pacc->devices; temp; temp = temp->next)
-		if (pci_filter_match(&filter, temp)) {
-			if ((card_vendor == pci_read_word(temp, PCI_SUBSYSTEM_VENDOR_ID)) &&
-			    (card_device == pci_read_word(temp, PCI_SUBSYSTEM_ID)))
-				return temp;
-		}
-
-	return NULL;
-}
-
 int map_flash_registers(struct flashchip *flash)
 {
 	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));
+	registers = mem_map(0, size, (off_t) (0xFFFFFFFF - 0x400000 - size + 1));
 
 	if (registers == MAP_FAILED) {
 		perror("Can't mmap registers using " MEM_DEV);
@@ -124,6 +89,7 @@
 		flash_baseaddr = (0xffffffff - size + 1);
 #endif
 
+#ifndef USE_LIBPAYLOAD
 		/* If getpagesize() > size -> 
 		 * "Can't mmap memory using /dev/mem: Invalid argument"
 		 * This should never happen as we don't support any flash chips
@@ -138,9 +104,9 @@
 			 */
 			size = getpagesize();
 		}
+#endif
 
-		bios = mmap(0, size, PROT_WRITE | PROT_READ, MAP_SHARED,
-			    fd_mem, (off_t) flash_baseaddr);
+		bios = mem_map(0, size, (off_t) flash_baseaddr);
 		if (bios == MAP_FAILED) {
 			perror("Can't mmap memory using " MEM_DEV);
 			exit(1);
@@ -153,7 +119,9 @@
 		if (flash->probe(flash) == 1)
 			break;
 
-		munmap((void *)bios, size);
+#ifndef USE_LIBPAYLOAD
+		//mem_unmap((void *)bios, size);
+#endif
 	}
 
 	if (!flash || !flash->name)
@@ -247,11 +215,14 @@
 {
 	uint8_t *buf;
 	unsigned long size;
+#ifndef USE_LIBPAYLOAD
 	FILE *image;
-	/* Probe for up to three flash chips. */
-	struct flashchip *flash, *flashes[3];
 	int opt;
 	int option_index = 0;
+	char *tempstr = NULL, *tempstr2 = NULL;
+#endif
+	/* Probe for up to three flash chips. */
+	struct flashchip *flash, *flashes[3];
 	int force = 0;
 	int read_it = 0, write_it = 0, erase_it = 0, verify_it = 0;
 	int ret = 0, i;
@@ -259,6 +230,7 @@
 	int io_fd;
 #endif
 
+#ifndef USE_LIBPAYLOAD
 	static struct option long_options[] = {
 		{"read", 0, 0, 'r'},
 		{"write", 0, 0, 'w'},
@@ -277,11 +249,11 @@
 		{"version", 0, 0, 'R'},
 		{0, 0, 0, 0}
 	};
+#endif
 
 	char *filename = NULL;
 
 	unsigned int exclude_start_position = 0, exclude_end_position = 0;	// [x,y)
-	char *tempstr = NULL, *tempstr2 = NULL;
 
 	if (argc > 1) {
 		/* Yes, print them. */
@@ -290,7 +262,7 @@
 		for (i = 1; i < argc; ++i)
 			printf_debug("%s\n", argv[i]);
 	}
-
+#ifndef USE_LIBPAYLOAD
 	setbuf(stdout, NULL);
 	while ((opt = getopt_long(argc, argv, "rRwvVEfc:s:e:m:l:i:Lh",
 				  long_options, &option_index)) != EOF) {
@@ -326,11 +298,11 @@
 			strtok(tempstr, ":");
 			tempstr2 = strtok(NULL, ":");
 			if (tempstr2) {
-				lb_vendor = tempstr;
-				lb_part = tempstr2;
+				cb_vendor = tempstr;
+				cb_part = tempstr2;
 			} else {
-				lb_vendor = NULL;
-				lb_part = tempstr;
+				cb_vendor = NULL;
+				cb_part = tempstr;
 			}
 			break;
 		case 'f':
@@ -361,14 +333,17 @@
 			break;
 		}
 	}
+#endif
 
 	if (read_it && write_it) {
 		printf("Error: -r and -w are mutually exclusive.\n");
 		usage(argv[0]);
 	}
 
+#ifndef USE_LIBPAYLOAD
 	if (optind < argc)
 		filename = argv[optind++];
+#endif
 
 	/* First get full io access */
 #if defined (__sun) && (defined(__i386) || defined(__amd64))
@@ -378,8 +353,11 @@
 #else
 	if (iopl(3) != 0) {
 #endif
-               fprintf(stderr, "ERROR: Could not get IO privileges (%s).\nYou need to be root.\n",
+
+#ifndef USE_LIBPAYLOAD
+			fprintf(stderr, "ERROR: Could not get IO privileges (%s).\nYou need to be root.\n",
 			strerror(errno));
+#endif
 		exit(1);
 	}
 
@@ -389,13 +367,14 @@
 	pci_init(pacc);		/* Initialize the PCI library */
 	pci_scan_bus(pacc);	/* We want to get the list of devices */
 
+#ifndef USE_LIBPAYLOAD
 	/* Open the memory device UNCACHED. That's important for MMIO. */
 	if ((fd_mem = open(MEM_DEV, O_RDWR|O_SYNC)) < 0) {
 		perror("Error: Can not access memory using " MEM_DEV
 		       ". You need to be root.");
 		exit(1);
 	}
-
+#endif
 	myusec_calibrate_delay();
 
 	/* We look at the lbtable first to see if we need a
@@ -412,7 +391,7 @@
 		       "will most likely fail.\n");
 	}
 
-	board_flash_enable(lb_vendor, lb_part);
+	board_flash_enable(cb_vendor, cb_part);
 
 	for (i = 0; i < ARRAY_SIZE(flashes); i++) {
 		flashes[i] = probe_flash(i ? flashes[i - 1] + 1 : flashchips, 0);
@@ -447,10 +426,12 @@
 			size = flashes[0]->total_size * 1024;
 			buf = (uint8_t *) calloc(size, sizeof(char));
 
+#ifndef USE_LIBPAYLOAD
 			if ((image = fopen(filename, "w")) == NULL) {
 				perror(filename);
 				exit(1);
 			}
+#endif
 			printf("Force reading flash...");
 			if (!flashes[0]->read)
 				memcpy(buf, (const char *)flashes[0]->virtual_memory, size);
@@ -461,8 +442,10 @@
 				memset(buf + exclude_start_position, 0,
 				       exclude_end_position - exclude_start_position);
 
+#ifndef USE_LIBPAYLOAD
 			fwrite(buf, sizeof(char), size, image);
 			fclose(image);
+#endif
 			printf("done\n");
 			free(buf);
 			exit(0);
@@ -522,16 +505,20 @@
 	if (erase_it) {
 		printf("Erasing flash chip.\n");
 		if (!flash->erase) {
+#ifndef USE_LIBPAYLOAD
 			fprintf(stderr, "Error: flashrom has no erase function for this flash chip.\n");
+#endif
 			return 1;
 		}
 		flash->erase(flash);
 		exit(0);
 	} else if (read_it) {
+#ifndef USE_LIBPAYLOAD
 		if ((image = fopen(filename, "w")) == NULL) {
 			perror(filename);
 			exit(1);
 		}
+#endif
 		printf("Reading Flash...");
 		if (flash->read == NULL)
 			memcpy(buf, (const char *)flash->virtual_memory, size);
@@ -542,10 +529,13 @@
 			memset(buf + exclude_start_position, 0,
 			       exclude_end_position - exclude_start_position);
 
+#ifndef USE_LIBPAYLOAD
 		fwrite(buf, sizeof(char), size, image);
 		fclose(image);
+#endif
 		printf("done\n");
 	} else {
+#ifndef USE_LIBPAYLOAD
 		struct stat image_stat;
 
 		if ((image = fopen(filename, "r")) == NULL) {
@@ -564,6 +554,7 @@
 		fread(buf, sizeof(char), size, image);
 		show_id(buf, size, force);
 		fclose(image);
+#endif
 	}
 
 	/* exclude range stuff. Nice idea, but at the moment it is only
@@ -574,6 +565,7 @@
 	 */
 
 	// ////////////////////////////////////////////////////////////
+#ifndef USE_LIBPAYLOAD
 	if (exclude_end_position - exclude_start_position > 0)
 		memcpy(buf + exclude_start_position,
 		       (const char *)flash->virtual_memory +
@@ -585,6 +577,7 @@
 		exclude_start_page++;
 	}
 	exclude_end_page = exclude_end_position / flash->page_size;
+#endif
 	// ////////////////////////////////////////////////////////////
 
 	// This should be moved into each flash part's code to do it 
@@ -595,7 +588,9 @@
 
 	if (write_it) {
 		if (!flash->write) {
+#ifndef USE_LIBPAYLOAD
 			fprintf(stderr, "Error: flashrom has no write function for this flash chip.\n");
+#endif
 			return 1;
 		}
 		ret |= flash->write(flash, buf);
Index: layout.c
===================================================================
--- layout.c	(revision 3480)
+++ layout.c	(working copy)
@@ -18,11 +18,6 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <stdint.h>
 #include "flash.h"
 
 char *mainboard_vendor = NULL;
@@ -94,10 +89,10 @@
 	printf_debug("Mainboard ID: %s\n", mainboard_part);
 
 	/*
-	 * If lb_vendor is not set, the coreboot table was
+	 * If cb_vendor is not set, the coreboot table was
 	 * not found. Nor was -m VENDOR:PART specified.
 	 */
-	if (!lb_vendor || !lb_part) {
+	if (!cb_vendor || !cb_part) {
 		printf("Note: If the following flash access fails, "
 		       "try -m <vendor>:<mainboard>.\n");
 		return 0;
@@ -106,8 +101,8 @@
 	/* These comparisons are case insensitive to make things
 	 * a little less user^Werror prone. 
 	 */
-	if (!strcasecmp(mainboard_vendor, lb_vendor) &&
-	    !strcasecmp(mainboard_part, lb_part)) {
+	if (!strcasecmp(mainboard_vendor, cb_vendor) &&
+	    !strcasecmp(mainboard_part, cb_part)) {
 		printf_debug("This firmware image matches "
 			     "this motherboard.\n");
 	} else {
@@ -121,8 +116,8 @@
 			       "are absolutely sure that you\nare using a correct "
 			       "image for this mainboard or override\nthe detected "
 			       "values with --mainboard <vendor>:<mainboard>.\n\n",
-			       mainboard_vendor, mainboard_part, lb_vendor,
-			       lb_part);
+			       mainboard_vendor, mainboard_part, cb_vendor,
+			       cb_part);
 			exit(1);
 		}
 	}
@@ -130,6 +125,7 @@
 	return 0;
 }
 
+#ifndef USE_LIBPAYLOAD
 int read_romlayout(char *name)
 {
 	FILE *romlayout;
@@ -148,7 +144,7 @@
 		char *tstr1, *tstr2;
 		fscanf(romlayout, "%s %s\n", tempstr,
 		       rom_entries[romimages].name);
-#if 0
+#ifndef USE_LIBPAYLOAD
 		// fscanf does not like arbitrary comments like that :( later
 		if (tempstr[0] == '#') {
 			continue;
@@ -172,6 +168,7 @@
 
 	return 0;
 }
+#endif
 
 int find_romentry(char *name)
 {
Index: ichspi.c
===================================================================
--- ichspi.c	(revision 3480)
+++ ichspi.c	(working copy)
@@ -33,11 +33,6 @@
  *
  */
 
-#include <stdio.h>
-#include <string.h>
-#include <stdint.h>
-#include <sys/mman.h>
-#include <pci/pci.h>
 #include "flash.h"
 #include "spi.h"
 
Index: udelay.c
===================================================================
--- udelay.c	(revision 3480)
+++ udelay.c	(working copy)
@@ -17,9 +17,9 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
-
-#include <sys/time.h>
-#include <stdio.h>
+#ifndef USE_LIBPAYLOAD
+	#include <sys/time.h>
+#endif
 #include "flash.h"
 
 // count to a billion. Time it. If it's < 1 sec, count to 10B, etc.
Index: 82802ab.c
===================================================================
--- 82802ab.c	(revision 3480)
+++ 82802ab.c	(working copy)
@@ -26,9 +26,6 @@
  *  - Order number: 290658-004
  */
 
-#include <stdio.h>
-#include <string.h>
-#include <stdint.h>
 #include "flash.h"
 
 // I need that Berkeley bit-map printer
Index: mx29f002.c
===================================================================
--- mx29f002.c	(revision 3480)
+++ mx29f002.c	(working copy)
@@ -18,8 +18,6 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
-#include <stdio.h>
-#include <stdint.h>
 #include "flash.h"
 
 int probe_29f002(struct flashchip *flash)
Index: sst49lf040.c
===================================================================
--- sst49lf040.c	(revision 3480)
+++ sst49lf040.c	(working copy)
@@ -18,7 +18,6 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
-#include <stdio.h>
 #include "flash.h"
 
 int erase_49lf040(struct flashchip *flash)
Index: cbtable.c
===================================================================
--- cbtable.c	(revision 3480)
+++ cbtable.c	(working copy)
@@ -21,6 +21,7 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
+/*
 #include <stdio.h>
 #include <stdint.h>
 #include <stdlib.h>
@@ -30,10 +31,10 @@
 #include <string.h>
 #include <errno.h>
 #include <sys/mman.h>
+*/
 #include "flash.h"
-#include "coreboot_tables.h"
 
-char *lb_part = NULL, *lb_vendor = NULL;
+char *cb_part = NULL, *cb_vendor = NULL;
 
 static unsigned long compute_checksum(void *addr, unsigned long length)
 {
@@ -69,38 +70,38 @@
 	return (~value.word) & 0xFFFF;
 }
 
-#define for_each_lbrec(head, rec) \
-	for(rec = (struct lb_record *)(((char *)head) + sizeof(*head)); \
+#define for_each_cbrec(head, rec) \
+	for(rec = (struct cb_record *)(((char *)head) + sizeof(*head)); \
 		(((char *)rec) < (((char *)head) + sizeof(*head) + head->table_bytes))  && \
 		(rec->size >= 1) && \
 		((((char *)rec) + rec->size) <= (((char *)head) + sizeof(*head) + head->table_bytes)); \
-		rec = (struct lb_record *)(((char *)rec) + rec->size))
+		rec = (struct cb_record *)(((char *)rec) + rec->size))
 
-static int count_lb_records(struct lb_header *head)
+static int count_cb_records(struct cb_header *head)
 {
-	struct lb_record *rec;
+	struct cb_record *rec;
 	int count;
 
 	count = 0;
-	for_each_lbrec(head, rec) {
+	for_each_cbrec(head, rec) {
 		count++;
 	}
 
 	return count;
 }
 
-static struct lb_header *find_lb_table(void *base, unsigned long start,
+static struct cb_header *find_cb_table(void *base, unsigned long start,
 				       unsigned long end)
 {
 	unsigned long addr;
 
 	/* For now be stupid.... */
 	for (addr = start; addr < end; addr += 16) {
-		struct lb_header *head =
-		    (struct lb_header *)(((char *)base) + addr);
-		struct lb_record *recs =
-		    (struct lb_record *)(((char *)base) + addr + sizeof(*head));
-		if (memcmp(head->signature, "LBIO", 4) != 0)
+		struct cb_header *head =
+		    (struct cb_header *)(((char *)base) + addr);
+		struct cb_record *recs =
+		    (struct cb_record *)(((char *)base) + addr + sizeof(*head));
+		if (memcmp(head->signature, "CBIO", 4) != 0)
 			continue;
 		printf_debug("Found canidate at: %08lx-%08lx\n",
 			     addr, addr + head->table_bytes);
@@ -109,7 +110,7 @@
 				head->header_bytes);
 			continue;
 		}
-		if (count_lb_records(head) != head->table_entries) {
+		if (count_cb_records(head) != head->table_entries) {
 			fprintf(stderr, "Bad record count: %d.\n",
 				head->table_entries);
 			continue;
@@ -132,13 +133,13 @@
 	return 0;
 }
 
-static void find_mainboard(struct lb_record *ptr, unsigned long addr)
+static void find_mainboard(struct cb_record *ptr, unsigned long addr)
 {
-	struct lb_mainboard *rec;
+	struct cb_mainboard *rec;
 	int max_size;
 	char vendor[256], part[256];
 
-	rec = (struct lb_mainboard *)ptr;
+	rec = (struct cb_mainboard *)ptr;
 	max_size = rec->size - sizeof(*rec);
 	printf("Vendor ID: %.*s, part ID: %.*s\n",
 	       max_size - rec->vendor_idx,
@@ -150,23 +151,23 @@
 	snprintf(part, 255, "%.*s", max_size - rec->part_number_idx,
 		 rec->strings + rec->part_number_idx);
 
-	if (lb_part) {
-		printf("Overwritten by command line, vendor ID: %s, part ID: %s.\n", lb_vendor, lb_part);
+	if (cb_part) {
+		printf("Overwritten by command line, vendor ID: %s, part ID: %s.\n", cb_vendor, cb_part);
 	} else {
-		lb_part = strdup(part);
-		lb_vendor = strdup(vendor);
+		cb_part = strdup(part);
+		cb_vendor = strdup(vendor);
 	}
 }
 
-static struct lb_record *next_record(struct lb_record *rec)
+static struct cb_record *next_record(struct cb_record *rec)
 {
-	return (struct lb_record *)(((char *)rec) + rec->size);
+	return (struct cb_record *)(((char *)rec) + rec->size);
 }
 
-static void search_lb_records(struct lb_record *rec, struct lb_record *last,
+static void search_cb_records(struct cb_record *rec, struct cb_record *last,
 			      unsigned long addr)
 {
-	struct lb_record *next;
+	struct cb_record *next;
 	int count;
 	count = 0;
 
@@ -174,7 +175,7 @@
 	     rec = next, addr += rec->size) {
 		next = next_record(rec);
 		count++;
-		if (rec->tag == LB_TAG_MAINBOARD) {
+		if (rec->tag == CB_TAG_MAINBOARD) {
 			find_mainboard(rec, addr);
 			break;
 		}
@@ -184,31 +185,30 @@
 int coreboot_init(void)
 {
 	uint8_t *low_1MB;
-	struct lb_header *lb_table;
-	struct lb_record *rec, *last;
+	struct cb_header *cb_table;
+	struct cb_record *rec, *last;
 
-	low_1MB = mmap(0, 1024 * 1024, PROT_READ, MAP_SHARED, fd_mem,
-		       0x00000000);
+	low_1MB = mem_map(0, 1024 * 1024, 0x00000000);
 	if (low_1MB == MAP_FAILED) {
 		perror("Can't mmap memory using " MEM_DEV);
 		exit(-2);
 	}
-	lb_table = 0;
-	if (!lb_table)
-		lb_table = find_lb_table(low_1MB, 0x00000, 0x1000);
-	if (!lb_table)
-		lb_table = find_lb_table(low_1MB, 0xf0000, 1024 * 1024);
-	if (lb_table) {
+	cb_table = 0;
+	if (!cb_table)
+		cb_table = find_cb_table(low_1MB, 0x00000, 0x1000);
+	if (!cb_table)
+		cb_table = find_cb_table(low_1MB, 0xf0000, 1024 * 1024);
+	if (cb_table) {
 		unsigned long addr;
-		addr = ((char *)lb_table) - ((char *)low_1MB);
-		printf_debug("Coreboot table found at %p.\n", lb_table);
-		rec = (struct lb_record *)(((char *)lb_table) + lb_table->header_bytes);
-		last = (struct lb_record *)(((char *)rec) + lb_table->table_bytes);
+		addr = ((char *)cb_table) - ((char *)low_1MB);
+		printf_debug("Coreboot table found at %p.\n", cb_table);
+		rec = (struct cb_record *)(((char *)cb_table) + cb_table->header_bytes);
+		last = (struct cb_record *)(((char *)rec) + cb_table->table_bytes);
 		printf_debug("Coreboot header(%d) checksum: %04x table(%d) checksum: %04x entries: %d\n",
-		     lb_table->header_bytes, lb_table->header_checksum,
-		     lb_table->table_bytes, lb_table->table_checksum,
-		     lb_table->table_entries);
-		search_lb_records(rec, last, addr + lb_table->header_bytes);
+		     cb_table->header_bytes, cb_table->header_checksum,
+		     cb_table->table_bytes, cb_table->table_checksum,
+		     cb_table->table_entries);
+		search_cb_records(rec, last, addr + cb_table->header_bytes);
 	} else {
 		printf("No coreboot table found.\n");
 		return -1;
Index: board_enable.c
===================================================================
--- board_enable.c	(revision 3480)
+++ board_enable.c	(working copy)
@@ -24,11 +24,6 @@
  * Contains the board specific flash enables.
  */
 
-#include <stdio.h>
-#include <pci/pci.h>
-#include <stdint.h>
-#include <string.h>
-#include <fcntl.h>
 #include "flash.h"
 
 /*
@@ -159,23 +154,24 @@
  */
 static int board_via_epia_m(const char *name)
 {
-	struct pci_dev *dev;
+	pcidev_t dev;
 	uint16_t base;
 	uint8_t val;
 
-	dev = pci_dev_find(0x1106, 0x3177);	/* VT8235 ISA bridge */
+	pci_find_device(0x1106, 0x3177, &dev);	/* VT8235 ISA bridge */
+	
 	if (!dev) {
 		fprintf(stderr, "\nERROR: VT8235 ISA bridge not found.\n");
 		return -1;
 	}
 
 	/* GPIO12-15 -> output */
-	val = pci_read_byte(dev, 0xE4);
+	val = pci_read_config8(dev, 0xE4);
 	val |= 0x10;
-	pci_write_byte(dev, 0xE4, val);
+	pci_write_config8(dev, 0xE4, val);
 
 	/* Get Power Management IO address. */
-	base = pci_read_word(dev, 0x88) & 0xFF80;
+	base = pci_read_config16(dev, 0x88) & 0xFF80;
 
 	/* Enable GPIO15 which is connected to write protect. */
 	val = INB(base + 0x4D);
@@ -192,21 +188,21 @@
  */
 static int board_asus_a7v8x_mx(const char *name)
 {
-	struct pci_dev *dev;
+	pcidev_t dev;
 	uint8_t val;
 
-	dev = pci_dev_find(0x1106, 0x3177);	/* VT8235 ISA bridge */
+	pci_find_device(0x1106, 0x3177, &dev);	/* VT8235 ISA bridge */
 	if (!dev)
-		dev = pci_dev_find(0x1106, 0x3227);	/* VT8237 ISA bridge */
+		pci_find_device(0x1106, 0x3227, &dev);	/* VT8237 ISA bridge */
 	if (!dev) {
 		fprintf(stderr, "\nERROR: VT823x ISA bridge not found.\n");
 		return -1;
 	}
 
 	/* This bit is marked reserved actually. */
-	val = pci_read_byte(dev, 0x59);
+	val = pci_read_config8(dev, 0x59);
 	val &= 0x7F;
-	pci_write_byte(dev, 0x59, val);
+	pci_write_config8(dev, 0x59, val);
 
 	/* Raise ROM MEMW# line on Winbond W83697 Super I/O. */
 	w836xx_ext_enter(0x2E);
@@ -224,19 +220,19 @@
  */
 static int board_via_epia_sp(const char *name)
 {
-	struct pci_dev *dev;
+	pcidev_t dev;
 	uint8_t val;
 
-	dev = pci_dev_find(0x1106, 0x3227);	/* VT8237R ISA bridge */
+	pci_find_device(0x1106, 0x3227, &dev);	/* VT8237R ISA bridge */
 	if (!dev) {
 		fprintf(stderr, "\nERROR: VT8237R ISA bridge not found.\n");
 		return -1;
 	}
 
 	/* All memory cycles, not just ROM ones, go to LPC */
-	val = pci_read_byte(dev, 0x59);
+	val = pci_read_config8(dev, 0x59);
 	val &= ~0x80;
-	pci_write_byte(dev, 0x59, val);
+	pci_write_config8(dev, 0x59, val);
 
 	return 0;
 }
@@ -353,18 +349,18 @@
  */
 static int board_acorp_6a815epd(const char *name)
 {
-	struct pci_dev *dev;
+	pcidev_t dev;
 	uint16_t port;
 	uint8_t val;
 
-	dev = pci_dev_find(0x8086, 0x2440);     /* Intel ICH2 LPC */
+	pci_find_device(0x8086, 0x2440, &dev);     /* Intel ICH2 LPC */
 	if (!dev) {
 		fprintf(stderr, "\nERROR: ICH2 LPC bridge not found.\n");
 		return -1;
 	}
 
 	/* Use GPIOBASE register to find where the GPIO is mapped. */
-	port = (pci_read_word(dev, 0x58) & 0xFFC0) + 0xE;
+	port = (pci_read_config16(dev, 0x58) & 0xFFC0) + 0xE;
 
 	val = INB(port);
 	val |= 0x80; /* Top Block Lock -- pin 8 of PLCC32 */
@@ -374,6 +370,7 @@
 	return 0;
 }
 
+#if 0
 /**
  * Suited for Artec Group DBE61 and DBE62.
  */
@@ -436,6 +433,7 @@
 	close(msr_fd);
 	return 0;
 }
+#endif
 
 /**
  * Set the specified GPIO on the specified ICHx southbridge to high.
@@ -454,11 +452,11 @@
 			  uint8_t gp_lvl, uint32_t gp_lvl_bitmask,
 			  unsigned int gpio_bit)
 {
-	struct pci_dev *dev;
+	pcidev_t dev;
 	uint16_t gpiobar;
 	uint32_t reg32;
 
-	dev = pci_dev_find(ich_vendor, ich_device);     /* Intel ICHx LPC */
+	pci_find_device(ich_vendor, ich_device, &dev);     /* Intel ICHx LPC */
 	if (!dev) {
 		fprintf(stderr, "\nERROR: ICHx LPC dev %4x:%4x not found.\n",
 			ich_vendor, ich_device);
@@ -466,7 +464,7 @@
 	}
 
 	/* Use GPIOBASE register to find the I/O space for GPIO. */
-	gpiobar = pci_read_word(dev, gpiobase_reg) & gp_lvl_bitmask;
+	gpiobar = pci_read_config16(dev, gpiobase_reg) & gp_lvl_bitmask;
 
 	/* Set specified GPIO to high. */
 	reg32 = INL(gpiobar + gp_lvl);
@@ -486,13 +484,13 @@
 
 static int board_kontron_986lcd_m(const char *name)
 {
-	struct pci_dev *dev;
+	pcidev_t dev;
 	uint16_t gpiobar;
 	uint32_t val;
 
 #define ICH7_GPIO_LVL2 0x38
 
-	dev = pci_dev_find(0x8086, 0x27b8);     /* Intel ICH7 LPC */
+	pci_find_device(0x8086, 0x27b8, &dev);     /* Intel ICH7 LPC */
 	if (!dev) {
 		// This will never happen on this board
 		fprintf(stderr, "\nERROR: ICH7 LPC bridge not found.\n");
@@ -500,7 +498,7 @@
 	}
 
 	/* Use GPIOBASE register to find where the GPIO is mapped. */
-	gpiobar = pci_read_word(dev, 0x48) & 0xfffc;
+	gpiobar = pci_read_config16(dev, 0x48) & 0xfffc;
 
 	val = INL(gpiobar + ICH7_GPIO_LVL2);	/* GP_LVL2 */
 	printf_debug("\nGPIOBAR=0x%04x GP_LVL: 0x%08x\n", gpiobar, val);
@@ -573,8 +571,8 @@
 	uint16_t second_card_device;
 
 	/* The vendor / part name from the coreboot table. */
-	const char *lb_vendor;
-	const char *lb_part;
+	const char *cb_vendor;
+	const char *cb_part;
 
 	const char *name;
 	int (*enable) (const char *name);
@@ -613,10 +611,10 @@
 	 "epox", "ep-bx3", "EPoX EP-BX3", board_epox_ep_bx3},
 	{0x8086, 0x1130, 0x0000, 0x0000, 0x105a, 0x0d30, 0x105a, 0x4d33,
 	 "acorp", "6a815epd", "Acorp 6A815EPD", board_acorp_6a815epd},
-	{0x1022, 0x2090, 0x0000, 0x0000, 0x1022, 0x2080, 0x0000, 0x0000,
-	 "artecgroup", "dbe61", "Artec Group DBE61", board_artecgroup_dbe6x},
-	{0x1022, 0x2090, 0x0000, 0x0000, 0x1022, 0x2080, 0x0000, 0x0000,
-	 "artecgroup", "dbe62", "Artec Group DBE62", board_artecgroup_dbe6x},
+//	{0x1022, 0x2090, 0x0000, 0x0000, 0x1022, 0x2080, 0x0000, 0x0000,
+//	 "artecgroup", "dbe61", "Artec Group DBE61", board_artecgroup_dbe6x},
+//	{0x1022, 0x2090, 0x0000, 0x0000, 0x1022, 0x2080, 0x0000, 0x0000,
+//	 "artecgroup", "dbe62", "Artec Group DBE62", board_artecgroup_dbe6x},
  	{0x8086, 0x27b8, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  	 "kontron", "986lcd-m", "Kontron 986LCD-M", board_kontron_986lcd_m},
  	{0x1106, 0x3149, 0x1565, 0x3206, 0x1106, 0x3344, 0x1565, 0x1202,
@@ -635,10 +633,10 @@
 	printf("\nSupported mainboards (this list is not exhaustive!):\n\n");
 
 	for (i = 0; board_pciid_enables[i].name != NULL; i++) {
-		if (board_pciid_enables[i].lb_vendor != NULL) {
+		if (board_pciid_enables[i].cb_vendor != NULL) {
 			printf("%s (-m %s:%s)\n", board_pciid_enables[i].name,
-			       board_pciid_enables[i].lb_vendor,
-			       board_pciid_enables[i].lb_part);
+			       board_pciid_enables[i].cb_vendor,
+			       board_pciid_enables[i].cb_part);
 		} else {
 			printf("%s (autodetected)\n",
 			       board_pciid_enables[i].name);
@@ -656,19 +654,21 @@
 {
 	struct board_pciid_enable *board = board_pciid_enables;
 	struct board_pciid_enable *partmatch = NULL;
-
+	pcidev_t dev1=0, dev2=0;
+	
 	for (; board->name; board++) {
-		if (vendor && (!board->lb_vendor || strcasecmp(board->lb_vendor, vendor)))
+		if (vendor && (!board->cb_vendor || strcasecmp(board->cb_vendor, vendor)))
 			continue;
 
-		if (!board->lb_part || strcasecmp(board->lb_part, part))
+		if (!board->cb_part || strcasecmp(board->cb_part, part))
 			continue;
 
-		if (!pci_dev_find(board->first_vendor, board->first_device))
+		pci_find_device(board->first_vendor, board->first_device, &dev1);
+		if (!dev1)
 			continue;
 
-		if (board->second_vendor &&
-			!pci_dev_find(board->second_vendor, board->second_device))
+		pci_find_device(board->second_vendor, board->second_device, &dev2);
+		if (board->second_vendor && !dev2)
 			continue;
 
 		if (vendor)
@@ -678,7 +678,7 @@
 			/* a second entry has a matching part name */
 			printf("AMBIGUOUS BOARD NAME: %s\n", part);
 			printf("At least vendors '%s' and '%s' match.\n",
-				partmatch->lb_vendor, board->lb_vendor);
+				partmatch->cb_vendor, board->cb_vendor);
 			printf("Please use the full -m vendor:part syntax.\n");
 			return NULL;
 		}
@@ -699,26 +699,30 @@
 static struct board_pciid_enable *board_match_pci_card_ids(void)
 {
 	struct board_pciid_enable *board = board_pciid_enables;
-
+	pcidev_t dev1=0, dev2=0;
+	
 	for (; board->name; board++) {
 		if (!board->first_card_vendor || !board->first_card_device)
 			continue;
 
-		if (!pci_card_find(board->first_vendor, board->first_device,
+		pci_find_card(board->first_vendor, board->first_device,
 					board->first_card_vendor,
-					board->first_card_device))
+					board->first_card_device, &dev1);
+		if (!dev1)
 			continue;
 
 		if (board->second_vendor) {
 			if (board->second_card_vendor) {
-				if (!pci_card_find(board->second_vendor,
-						board->second_device,
-						board->second_card_vendor,
-						board->second_card_device))
+				pci_find_card(board->second_vendor,
+							board->second_device,
+							board->second_card_vendor,
+							board->second_card_device, &dev2);
+				if (!dev2)
 					continue;
 			} else {
-				if (!pci_dev_find(board->second_vendor,
-							board->second_device))
+				pci_find_device(board->second_vendor,
+							board->second_device, &dev2);
+				if (!dev2)
 					continue;
 			}
 		}
