Add a dummy external flasher which just prints each operation

Usage:
flashrom --programmer dummy

This is a great way to test flashrom without root access.

Corresponding to flashrom svn r483.

Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Acked-by: Uwe Hermann <uwe@hermann-uwe.de>
diff --git a/Makefile b/Makefile
index ecaef6c..2a54af5 100644
--- a/Makefile
+++ b/Makefile
@@ -34,7 +34,8 @@
 	w49f002u.o 82802ab.o pm49fl00x.o sst49lf040.o en29f002a.o \
 	sst49lfxxxc.o sst_fwhub.o layout.o cbtable.o flashchips.o physmap.o \
 	flashrom.o w39v080fa.o sharplhf00l04.o w29ee011.o spi.o it87spi.o \
-	ichspi.o w39v040c.o sb600spi.o wbsio_spi.o m29f002.o internal.o
+	ichspi.o w39v040c.o sb600spi.o wbsio_spi.o m29f002.o internal.o \
+	dummyflasher.o
 
 all: pciutils dep $(PROGRAM)
 
diff --git a/dummyflasher.c b/dummyflasher.c
new file mode 100644
index 0000000..4a4ea0f
--- /dev/null
+++ b/dummyflasher.c
@@ -0,0 +1,75 @@
+/*
+ * This file is part of the flashrom project.
+ *
+ * Copyright (C) 2009 Carl-Daniel Hailfinger
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+#include <stdint.h>
+#include <string.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <pci/pci.h>
+#include "flash.h"
+
+int dummy_init(void)
+{
+	printf("%s\n", __func__);
+	return 0; 
+}
+
+int dummy_shutdown(void)
+{
+	printf("%s\n", __func__);
+	return 0;
+}
+
+void dummy_chip_writeb(uint8_t val, volatile void *addr)
+{
+	printf("%s: addr=%p, val=0x%02x\n", __func__, addr, val);
+}
+
+void dummy_chip_writew(uint16_t val, volatile void *addr)
+{
+	printf("%s: addr=%p, val=0x%04x\n", __func__, addr, val);
+}
+
+void dummy_chip_writel(uint32_t val, volatile void *addr)
+{
+	printf("%s: addr=%p, val=0x%08x\n", __func__, addr, val);
+}
+
+uint8_t dummy_chip_readb(const volatile void *addr)
+{
+	printf("%s:  addr=%p\n", __func__, addr);
+	return 0xff;
+}
+
+uint16_t dummy_chip_readw(const volatile void *addr)
+{
+	printf("%s:  addr=%p\n", __func__, addr);
+	return 0xffff;
+}
+
+uint32_t dummy_chip_readl(const volatile void *addr)
+{
+	printf("%s:  addr=%p\n", __func__, addr);
+	return 0xffffffff;
+}
+
diff --git a/flash.h b/flash.h
index ef9ae6e..6b4dcb8 100644
--- a/flash.h
+++ b/flash.h
@@ -77,7 +77,8 @@
 #endif
 
 extern int programmer;
-#define PROGRAMMER_INTERNAL 0x00
+#define PROGRAMMER_INTERNAL	0x00
+#define PROGRAMMER_DUMMY	0x01
 
 struct programmer_entry {
 	const char *vendor;
@@ -575,6 +576,16 @@
 uint16_t internal_chip_readw(const volatile void *addr);
 uint32_t internal_chip_readl(const volatile void *addr);
 
+/* dummyflasher.c */
+int dummy_init(void);
+int dummy_shutdown(void);
+void dummy_chip_writeb(uint8_t val, volatile void *addr);
+void dummy_chip_writew(uint16_t val, volatile void *addr);
+void dummy_chip_writel(uint32_t val, volatile void *addr);
+uint8_t dummy_chip_readb(const volatile void *addr);
+uint16_t dummy_chip_readw(const volatile void *addr);
+uint32_t dummy_chip_readl(const volatile void *addr);
+
 /* flashrom.c */
 extern int verbose;
 #define printf_debug(x...) { if (verbose) printf(x); }
diff --git a/flashrom.8 b/flashrom.8
index c8ace15..46a3742 100644
--- a/flashrom.8
+++ b/flashrom.8
@@ -127,6 +127,8 @@
 Specify the programmer device. Currently supported are:
 .sp
 .BR " internal" " (default, for in-system flashing in the mainboard)"
+
+.BR " dummy" " (just prints all operations and accesses)"
 .TP
 .B "\-h, \-\-help"
 Show a help text and exit.
diff --git a/flashrom.c b/flashrom.c
index 4bf41d9..eb9fca8 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -48,6 +48,17 @@
 		.chip_writel	= internal_chip_writel,
 	},
 
+	{
+		.init		= dummy_init,
+		.shutdown	= dummy_shutdown,
+		.chip_readb	= dummy_chip_readb,
+		.chip_readw	= dummy_chip_readw,
+		.chip_readl	= dummy_chip_readl,
+		.chip_writeb	= dummy_chip_writeb,
+		.chip_writew	= dummy_chip_writew,
+		.chip_writel	= dummy_chip_writel,
+	},
+
 	{},
 };
 
@@ -437,6 +448,8 @@
 		case 'p':
 			if (strncmp(optarg, "internal", 8) == 0) {
 				programmer = PROGRAMMER_INTERNAL;
+			} else if (strncmp(optarg, "dummy", 5) == 0) {
+				programmer = PROGRAMMER_DUMMY;
 			} else {
 				printf("Error: Unknown programmer.\n");
 				exit(1);