Add optional SPI command blacklisting to the flash chip emulator in the
dummy programmer.

Usage:
flashrom -p dummy:spi_blacklist=hexstring

If hexstring is 0302, flashrom will blacklist command 0x03 (READ) and
command 0x02 (WRITE). The hexstring can have up to 521 bytes (256
commands) length, and must not start with 0x.

TODO: Should 0x at the beginning of hexstring be tolerated?

Very useful for testing corner cases if you don't own a locked down
Intel chipset and want to simulate such a thing.

Signed-off-by: Carl-Daniel Hailfinger <[email protected]>

Index: flashrom-emulate_spi_flashchip_command_blacklist/dummyflasher.c
===================================================================
--- flashrom-emulate_spi_flashchip_command_blacklist/dummyflasher.c     
(Revision 1224)
+++ flashrom-emulate_spi_flashchip_command_blacklist/dummyflasher.c     
(Arbeitskopie)
@@ -19,6 +19,7 @@
 
 #include <string.h>
 #include <stdlib.h>
+#include <stdio.h>
 #include <ctype.h>
 #include "flash.h"
 #include "chipdrivers.h"
@@ -56,6 +57,8 @@
 static int emu_jedec_be_d8_size = 0;
 static int emu_jedec_ce_60_size = 0;
 static int emu_jedec_ce_c7_size = 0;
+unsigned char spi_blacklist[256];
+int spi_blacklist_size = 0;
 #endif
 #endif
 
@@ -71,6 +74,7 @@
 {
        char *bustext = NULL;
        char *tmp = NULL;
+       int i;
 #if EMULATE_CHIP
        struct stat image_stat;
 #endif
@@ -116,6 +120,31 @@
                }
        }
 
+       tmp = extract_programmer_param("spi_blacklist");
+       if (tmp) {
+               i = strlen(tmp);
+               if (i % 2) {
+                       msg_perr("Invalid SPI command blacklist\n");
+                       free(tmp);
+                       return 1;
+               }
+               tolower_string(tmp);
+               if (strspn(tmp, "0123456789abcdef") != i) {
+                       msg_perr("Invalid SPI command blacklist\n");
+                       free(tmp);
+                       return 1;
+               }
+               spi_blacklist_size = i / 2;
+               for (i = 0; i < spi_blacklist_size; i++) {
+                       sscanf(tmp, "%2hhx", &spi_blacklist[i]);
+               }
+               msg_pdbg("SPI blacklist is ");
+               for (i = 0; i < spi_blacklist_size; i++)
+                       msg_pdbg("%02x ", spi_blacklist[i]);
+               msg_pdbg(", size %i\n", spi_blacklist_size);
+       }
+       free(tmp);
+
 #if EMULATE_CHIP
        tmp = extract_programmer_param("emulate");
        if (!tmp) {
@@ -285,7 +314,7 @@
 static int emulate_spi_chip_response(unsigned int writecnt, unsigned int 
readcnt,
                      const unsigned char *writearr, unsigned char *readarr)
 {
-       int offs;
+       int offs, i;
        static int aai_offs;
        static int aai_active = 0;
 
@@ -293,7 +322,16 @@
                msg_perr("No command sent to the chip!\n");
                return 1;
        }
-       /* TODO: Implement command blacklists here. */
+       for (i = 0; i < spi_blacklist_size; i++) {
+               if (writearr[0] == spi_blacklist[i]) {
+                       msg_perr("Refusing blacklisted SPI command 0x%02x\n",
+                                spi_blacklist[i]);
+                       /* FIXME: Do we want a separate return code for
+                        * command unavailable?
+                        */
+                       return 1;
+               }
+       }
        switch (writearr[0]) {
        case JEDEC_RES:
                if (emu_chip != EMULATE_ST_M25P10_RES)


-- 
http://www.hailfinger.org/


_______________________________________________
flashrom mailing list
[email protected]
http://www.flashrom.org/mailman/listinfo/flashrom

Reply via email to