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. If you get permission errors, you found a problem in the code. (There are quite a few.)
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Index: flashrom-external_dummyflasher/flash.h =================================================================== --- flashrom-external_dummyflasher/flash.h (Revision 477) +++ flashrom-external_dummyflasher/flash.h (Arbeitskopie) @@ -78,6 +78,7 @@
extern int programmer; #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); } Index: flashrom-external_dummyflasher/Makefile =================================================================== --- flashrom-external_dummyflasher/Makefile (Revision 477) +++ flashrom-external_dummyflasher/Makefile (Arbeitskopie) @@ -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)
Index: flashrom-external_dummyflasher/dummyflasher.c =================================================================== --- flashrom-external_dummyflasher/dummyflasher.c (Revision 0) +++ flashrom-external_dummyflasher/dummyflasher.c (Revision 0) @@ -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=%02x\n", __func__, addr, val); +} + +void dummy_chip_writew(uint16_t val, volatile void *addr) +{ + printf("%s: addr=%p, val=%04x\n", __func__, addr, val); +} + +void dummy_chip_writel(uint32_t val, volatile void *addr) +{ + printf("%s: addr=%p, val=%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; +} + Index: flashrom-external_dummyflasher/flashrom.c =================================================================== --- flashrom-external_dummyflasher/flashrom.c (Revision 477) +++ flashrom-external_dummyflasher/flashrom.c (Arbeitskopie) @@ -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, + }, + {}, };
@@ -436,6 +447,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);
On Sat, May 09, 2009 at 12:38:56AM +0200, Carl-Daniel Hailfinger wrote:
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. If you get permission errors, you found a problem in the code. (There are quite a few.)
Yep, indeed. Not all external flashers will need root access so we should definately fix this.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Acked-by: Uwe Hermann uwe@hermann-uwe.de
...with the changes below.
Index: flashrom-external_dummyflasher/flash.h
--- flashrom-external_dummyflasher/flash.h (Revision 477) +++ flashrom-external_dummyflasher/flash.h (Arbeitskopie) @@ -78,6 +78,7 @@
extern int programmer; #define PROGRAMMER_INTERNAL 0x00 +#define PROGRAMMER_DUMMY 0x01
^ Please align the 0x00 and 0x01 with spaces or tabs.
Index: flashrom-external_dummyflasher/dummyflasher.c
--- flashrom-external_dummyflasher/dummyflasher.c (Revision 0) +++ flashrom-external_dummyflasher/dummyflasher.c (Revision 0) +void dummy_chip_writeb(uint8_t val, volatile void *addr) +{
- printf("%s: addr=%p, val=%02x\n", __func__, addr, val);
^
Make this 0x%02x please (i.e. prepend "0x" to the value).
+}
+void dummy_chip_writew(uint16_t val, volatile void *addr) +{
- printf("%s: addr=%p, val=%04x\n", __func__, addr, val);
Ditto.
+void dummy_chip_writel(uint32_t val, volatile void *addr) +{
- printf("%s: addr=%p, val=%08x\n", __func__, addr, val);
Ditto.
+uint8_t dummy_chip_readb(const volatile void *addr) +{
- printf("%s: addr=%p\n", __func__, addr);
Please add a space after the ":". As 'read' is one character shorter than 'write' that will align the output nicely.
Also: Please document the 'dummy' flasher in the manpage.
Uwe.
On 09.05.2009 02:43, Uwe Hermann wrote:
On Sat, May 09, 2009 at 12:38:56AM +0200, Carl-Daniel Hailfinger wrote:
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. If you get permission errors, you found a problem in the code. (There are quite a few.)
Yep, indeed. Not all external flashers will need root access so we should definately fix this.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Acked-by: Uwe Hermann uwe@hermann-uwe.de
Thanks for the review, committed in r483.
...with the changes below.
Changed.
Regards, Carl-Daniel