Index: flash.h
===================================================================
--- flash.h	(revision 2543)
+++ flash.h	(working copy)
@@ -1,7 +1,9 @@
 #ifndef __FLASH_H__
 #define __FLASH_H__ 1
 
+#if defined(linux)
 #include <sys/io.h>
+#endif
 #include <unistd.h>
 #include <stdint.h>
 
Index: flash_enable.c
===================================================================
--- flash_enable.c	(revision 2543)
+++ flash_enable.c	(working copy)
@@ -11,27 +11,43 @@
  *
  */
 
+#if defined(linux)
 #include <sys/io.h>
+#endif
 #include <stdio.h>
 #include <pci/pci.h>
 #include <stdlib.h>
 #include <stdint.h>
 #include <string.h>
+#if defined(__sun)
+#include <strings.h>
+#include <sys/sysi86.h>
+#include <sys/psw.h>
+#include <asm/sunddi.h>
+#endif
 #include "lbtable.h"
 #include "debug.h"
 
 // We keep this for the others.
 static struct pci_access *pacc;
 
+static void setup_io() {
+#if defined(__sun)
+	if (sysi86(SI86V86, V86SC_IOPL, PS_IOPL) != 0){
+#else
+	if (iopl(3) != 0) {
+#endif
+		perror("Can not set io privilege");
+		exit(1);
+	}
+}
+
 static int enable_flash_sis630(struct pci_dev *dev, char *name)
 {
 	char b;
 
 	/* get io privilege access PCI configuration space */
-	if (iopl(3) != 0) {
-		perror("Can not set io priviliage");
-		exit(1);
-	}
+	setup_io();
 
 	/* Enable 0xFFF8000~0xFFFF0000 decoding on SiS 540/630 */
 	outl(0x80000840, 0x0cf8);
@@ -165,10 +181,7 @@
 	int ok;
 
 	/* get io privilege access PCI configuration space */
-	if (iopl(3) != 0) {
-		perror("Can not set io priviliage");
-		exit(1);
-	}
+	setup_io();
 
 	old = pci_read_byte(dev, 0x40);
 
@@ -348,10 +361,7 @@
 	struct pci_dev *smbusdev;
 
 	/* get io privilege access */
-	if (iopl(3) != 0) {
-		perror("Can not set io priviliage");
-		exit(1);
-	}
+	setup_io();
 
 	/* then look for the smbus device */
 	pci_filter_init((struct pci_access *) 0, &f);
@@ -492,10 +502,8 @@
  */
 
 	/* get io privilege access winbond config space */
-	if (iopl(3) != 0) {
-		perror("Can not set io priviliage");
-		exit(1);
-	}
+	setup_io();
+
 	
 	printf("Disabling mainboard flash write protection.\n");
 
Index: lbtable.c
===================================================================
--- lbtable.c	(revision 2543)
+++ lbtable.c	(working copy)
@@ -9,6 +9,7 @@
 #include <sys/mman.h>
 #include "../../src/include/boot/linuxbios_tables.h"
 #include "debug.h"
+#include "mem.h"
 
 char *lb_part=NULL, *lb_vendor=NULL;
 
@@ -158,15 +159,15 @@
 	struct lb_record *rec, *last;
 	
 	int fd;
-	fd = open("/dev/mem", O_RDONLY);
+	fd = open(MEM_DEV, O_RDONLY);
 	if (fd < 0) {
-		fprintf(stderr, "Can not open /dev/mem\n");
+		fprintf(stderr, "Can not open memory device\n");
 		exit(-1);
 	}
 	low_1MB = mmap(0, 1024*1024, PROT_READ, MAP_SHARED, fd, 0x00000000);
 	if (low_1MB == ((void *) -1)) {
-		fprintf(stderr, "Can not mmap /dev/mem at %08lx errno(%d):%s\n",
-			0x00000000UL, errno, strerror(errno));
+		fprintf(stderr, "Can not mmap %s at %08lx errno(%d):%s\n",
+			MEM_DEV, 0x00000000UL, errno, strerror(errno));
 		exit(-2);
 	}
 	lb_table = 0;
Index: sst49lfxxxc.c
===================================================================
--- sst49lfxxxc.c	(revision 2543)
+++ sst49lfxxxc.c	(working copy)
@@ -28,7 +28,9 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <sys/mman.h>
+#if defined(linux)
 #include <sys/io.h>
+#endif
 #include <unistd.h>
 #include <stdio.h>
 #include <stdlib.h>
Index: sharplhf00l04.c
===================================================================
--- sharplhf00l04.c	(revision 2543)
+++ sharplhf00l04.c	(working copy)
@@ -25,7 +25,9 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <sys/mman.h>
+#if defined(linux)
 #include <sys/io.h>
+#endif
 #include <unistd.h>
 #include <stdio.h>
 #include <stdlib.h>
Index: Makefile
===================================================================
--- Makefile	(revision 2543)
+++ Makefile	(working copy)
@@ -12,9 +12,14 @@
 PREFIX  = /usr/local
 #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 
+STRIP_ARGS = -s
+endif
 
-
 OBJS  = flash_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 \
@@ -24,7 +29,7 @@
 
 $(PROGRAM): $(OBJS)
 	$(CC) -o $(PROGRAM) $(OBJS) $(LDFLAGS)
-	$(STRIP) -s $(PROGRAM)
+	$(STRIP) $(STRIP_ARGS) $(PROGRAM)
 
 clean:
 	rm -f *.o *~
@@ -46,7 +51,7 @@
 		echo "Please install pciutils and pciutils-devel.";	\
 		echo "See README for more information."; echo;		\
 		rm -f .test.c .test; exit 1)
-	@rm -f .test.c .test
+#	@rm -f .test.c .test
 
 install: $(PROGRAM)
 	$(INSTALL) flashrom $(PREFIX)/bin
Index: sst_fwhub.c
===================================================================
--- sst_fwhub.c	(revision 2543)
+++ sst_fwhub.c	(working copy)
@@ -23,7 +23,9 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <sys/mman.h>
+#if defined(linux)
 #include <sys/io.h>
+#endif
 #include <unistd.h>
 #include <stdio.h>
 #include <stdlib.h>
Index: flash_rom.c
===================================================================
--- flash_rom.c	(revision 2543)
+++ flash_rom.c	(working copy)
@@ -40,6 +40,7 @@
 #include "lbtable.h"
 #include "layout.h"
 #include "debug.h"
+#include "mem.h"
 
 char *chip_to_probe = NULL;
 
@@ -52,8 +53,8 @@
 	volatile uint8_t *bios;
 	unsigned long size;
 
-	if ((fd_mem = open("/dev/mem", O_RDWR)) < 0) {
-		perror("Error: Can not open /dev/mem. You need to be root.");
+	if ((fd_mem = open(MEM_DEV, O_RDWR)) < 0) {
+		perror("Error: Can not open memory device. You need to be root.");
 		exit(1);
 	}
 
Index: 82802ab.c
===================================================================
--- 82802ab.c	(revision 2543)
+++ 82802ab.c	(working copy)
@@ -26,7 +26,9 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <sys/mman.h>
+#if defined(linux)
 #include <sys/io.h>
+#endif
 #include <unistd.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -83,7 +85,7 @@
 			    flash->fd_mem, (off_t) (0 - 0x400000 - size));
 		if (bios == MAP_FAILED) {
 			// it's this part but we can't map it ...
-			perror("Error MMAP /dev/mem");
+			perror("Error MMAP memory device");
 			exit(1);
 		}
 
