Author: stefanct Date: Mon May 26 02:36:24 2014 New Revision: 1798 URL: http://flashrom.org/trac/flashrom/changeset/1798
Log: Add two new states to enum test_state and use it for flashchips.
The new enum test_state looks like this: enum test_state { OK = 0, NT = 1, /* Not tested */ BAD, /* Known to not work */ DEP, /* Support depends on configuration (e.g. Intel flash descriptor) */ NA, /* Not applicable (e.g. write support on ROM chips) */ };
The second new state 'NA' is introduced, among other things, to indicate the erase and write states of real ROMs correctly. This is also implemented by this patch and required to exchange the previous bit mask in struct flashchip with a new struct containing an enum test_state for each operation. The -L output is changed accordingly to print '-' in the case of an N/A state and the wiki output uses a new template producing a greyed out cell. Previous users of enum test_state are not affected by this change (yet).
Signed-off-by: Stefan Tauner stefan.tauner@alumni.tuwien.ac.at Acked-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Modified: trunk/flash.h trunk/flashchips.c trunk/flashrom.c trunk/print.c trunk/print_wiki.c
Modified: trunk/flash.h ============================================================================== --- trunk/flash.h Sun May 25 09:47:47 2014 (r1797) +++ trunk/flash.h Mon May 26 02:36:24 2014 (r1798) @@ -120,6 +120,26 @@ #define FEATURE_OTP (1 << 8) #define FEATURE_QPI (1 << 9)
+enum test_state { + OK = 0, + NT = 1, /* Not tested */ + BAD, /* Known to not work */ + DEP, /* Support depends on configuration (e.g. Intel flash descriptor) */ + NA, /* Not applicable (e.g. write support on ROM chips) */ +}; + +#define TEST_UNTESTED (struct tested){ .probe = NT, .read = NT, .erase = NT, .write = NT } + +#define TEST_OK_PROBE (struct tested){ .probe = OK, .read = NT, .erase = NT, .write = NT } +#define TEST_OK_PR (struct tested){ .probe = OK, .read = OK, .erase = NT, .write = NT } +#define TEST_OK_PRE (struct tested){ .probe = OK, .read = OK, .erase = OK, .write = NT } +#define TEST_OK_PREW (struct tested){ .probe = OK, .read = OK, .erase = OK, .write = OK } + +#define TEST_BAD_PROBE (struct tested){ .probe = BAD, .read = NT, .erase = NT, .write = NT } +#define TEST_BAD_PR (struct tested){ .probe = BAD, .read = BAD, .erase = NT, .write = NT } +#define TEST_BAD_PRE (struct tested){ .probe = BAD, .read = BAD, .erase = BAD, .write = NT } +#define TEST_BAD_PREW (struct tested){ .probe = BAD, .read = BAD, .erase = BAD, .write = BAD } + struct flashctx; typedef int (erasefunc_t)(struct flashctx *flash, unsigned int addr, unsigned int blocklen);
@@ -143,11 +163,13 @@ unsigned int page_size; int feature_bits;
- /* - * Indicate if flashrom has been tested with this flash chip and if - * everything worked correctly. - */ - uint32_t tested; + /* Indicate how well flashrom supports different operations of this flash chip. */ + struct tested { + enum test_state probe; + enum test_state read; + enum test_state erase; + enum test_state write; + } tested;
int (*probe) (struct flashctx *flash);
@@ -192,27 +214,6 @@ struct registered_programmer *pgm; };
-#define TEST_UNTESTED 0 - -#define TEST_OK_PROBE (1 << 0) -#define TEST_OK_READ (1 << 1) -#define TEST_OK_ERASE (1 << 2) -#define TEST_OK_WRITE (1 << 3) -#define TEST_OK_PR (TEST_OK_PROBE | TEST_OK_READ) -#define TEST_OK_PRE (TEST_OK_PROBE | TEST_OK_READ | TEST_OK_ERASE) -#define TEST_OK_PRW (TEST_OK_PROBE | TEST_OK_READ | TEST_OK_WRITE) -#define TEST_OK_PREW (TEST_OK_PROBE | TEST_OK_READ | TEST_OK_ERASE | TEST_OK_WRITE) -#define TEST_OK_MASK 0x0f - -#define TEST_BAD_PROBE (1 << 4) -#define TEST_BAD_READ (1 << 5) -#define TEST_BAD_ERASE (1 << 6) -#define TEST_BAD_WRITE (1 << 7) -#define TEST_BAD_EW (TEST_BAD_ERASE | TEST_BAD_WRITE) -#define TEST_BAD_REW (TEST_BAD_READ | TEST_BAD_ERASE | TEST_BAD_WRITE) -#define TEST_BAD_PREW (TEST_BAD_PROBE | TEST_BAD_READ | TEST_BAD_ERASE | TEST_BAD_WRITE) -#define TEST_BAD_MASK 0xf0 - /* Timing used in probe routines. ZERO is -2 to differentiate between an unset * field and zero delay. * @@ -265,12 +266,6 @@ int read_buf_from_file(unsigned char *buf, unsigned long size, const char *filename); int write_buf_to_file(const unsigned char *buf, unsigned long size, const char *filename);
-enum test_state { - OK = 0, - NT = 1, /* Not tested */ - BAD -}; - /* Something happened that shouldn't happen, but we can go on. */ #define ERROR_NONFATAL 0x100
Modified: trunk/flashchips.c ============================================================================== --- trunk/flashchips.c Sun May 25 09:47:47 2014 (r1797) +++ trunk/flashchips.c Mon May 26 02:36:24 2014 (r1798) @@ -2189,7 +2189,7 @@ .model_id = ATMEL_AT26F004, .total_size = 512, .page_size = 256, - .tested = TEST_BAD_WRITE, + .tested = {.probe = NT, .read = NT, .erase = NT, .write = BAD }, .feature_bits = FEATURE_WRSR_WREN, .probe = probe_spi_rdid, .probe_timing = TIMING_ZERO, @@ -5915,7 +5915,7 @@ .model_id = MACRONIX_MX23L3254, .total_size = 4096, .page_size = 256, - .tested = TEST_OK_PR | TEST_BAD_EW, + .tested = {.probe = OK, .read = OK, .erase = NA, .write = NA}, .probe = probe_spi_rdid, .probe_timing = TIMING_ZERO, .write = NULL, /* MX23L3254 is a mask ROM, so it is read-only */
Modified: trunk/flashrom.c ============================================================================== --- trunk/flashrom.c Sun May 25 09:47:47 2014 (r1797) +++ trunk/flashrom.c Mon May 26 02:36:24 2014 (r1798) @@ -1791,32 +1791,43 @@ "clone the contents of this chip (see man page for " "details).\n"); } - if (TEST_OK_MASK != (chip->tested & TEST_OK_MASK)) { + + if ((chip->tested.erase == NA) && (chip->tested.write == NA)) { + msg_cdbg("This chip's main memory can not be erased/written by design.\n"); + } + + if ((chip->tested.probe == BAD) || (chip->tested.probe == NT) || + (chip->tested.read == BAD) || (chip->tested.read == NT) || + (chip->tested.erase == BAD) || (chip->tested.erase == NT) || + (chip->tested.write == BAD) || (chip->tested.write == NT)){ msg_cinfo("===\n"); - if (chip->tested & TEST_BAD_MASK) { + if ((chip->tested.probe == BAD) || + (chip->tested.read == BAD) || + (chip->tested.erase == BAD) || + (chip->tested.write == BAD)) { msg_cinfo("This flash part has status NOT WORKING for operations:"); - if (chip->tested & TEST_BAD_PROBE) + if (chip->tested.probe == BAD) msg_cinfo(" PROBE"); - if (chip->tested & TEST_BAD_READ) + if (chip->tested.read == BAD) msg_cinfo(" READ"); - if (chip->tested & TEST_BAD_ERASE) + if (chip->tested.erase == BAD) msg_cinfo(" ERASE"); - if (chip->tested & TEST_BAD_WRITE) + if (chip->tested.write == BAD) msg_cinfo(" WRITE"); msg_cinfo("\n"); } - if ((!(chip->tested & TEST_BAD_PROBE) && !(chip->tested & TEST_OK_PROBE)) || - (!(chip->tested & TEST_BAD_READ) && !(chip->tested & TEST_OK_READ)) || - (!(chip->tested & TEST_BAD_ERASE) && !(chip->tested & TEST_OK_ERASE)) || - (!(chip->tested & TEST_BAD_WRITE) && !(chip->tested & TEST_OK_WRITE))) { + if ((chip->tested.probe == NT) || + (chip->tested.read == NT) || + (chip->tested.erase == NT) || + (chip->tested.write == NT)) { msg_cinfo("This flash part has status UNTESTED for operations:"); - if (!(chip->tested & TEST_BAD_PROBE) && !(chip->tested & TEST_OK_PROBE)) + if (chip->tested.probe == NT) msg_cinfo(" PROBE"); - if (!(chip->tested & TEST_BAD_READ) && !(chip->tested & TEST_OK_READ)) + if (chip->tested.read == NT) msg_cinfo(" READ"); - if (!(chip->tested & TEST_BAD_ERASE) && !(chip->tested & TEST_OK_ERASE)) + if (chip->tested.erase == NT) msg_cinfo(" ERASE"); - if (!(chip->tested & TEST_BAD_WRITE) && !(chip->tested & TEST_OK_WRITE)) + if (chip->tested.write == NT) msg_cinfo(" WRITE"); msg_cinfo("\n"); } @@ -1859,7 +1870,7 @@
if (read_it || erase_it || write_it || verify_it) { /* Everything needs read. */ - if (chip->tested & TEST_BAD_READ) { + if (chip->tested.read == BAD) { msg_cerr("Read is not working on this chip. "); if (!force) return 1; @@ -1873,7 +1884,11 @@ } if (erase_it || write_it) { /* Write needs erase. */ - if (chip->tested & TEST_BAD_ERASE) { + if (chip->tested.erase == NA) { + msg_cerr("Erase is not possible on this chip.\n"); + return 1; + } + if (chip->tested.erase == BAD) { msg_cerr("Erase is not working on this chip. "); if (!force) return 1; @@ -1886,7 +1901,11 @@ } } if (write_it) { - if (chip->tested & TEST_BAD_WRITE) { + if (chip->tested.write == NA) { + msg_cerr("Write is not possible on this chip.\n"); + return 1; + } + if (chip->tested.write == BAD) { msg_cerr("Write is not working on this chip. "); if (!force) return 1;
Modified: trunk/print.c ============================================================================== --- trunk/print.c Sun May 25 09:47:47 2014 (r1797) +++ trunk/print.c Mon May 26 02:36:24 2014 (r1798) @@ -249,38 +249,46 @@ for (i = curdevlen; i < maxchiplen; i++) msg_ginfo(" ");
- if ((chip->tested & TEST_OK_PROBE)) + if (chip->tested.probe == OK) msg_ginfo("P"); + else if (chip->tested.probe == NA) + msg_ginfo("-"); else msg_ginfo(" "); - if ((chip->tested & TEST_OK_READ)) + if (chip->tested.read == OK) msg_ginfo("R"); + else if (chip->tested.read == NA) + msg_ginfo("-"); else msg_ginfo(" "); - if ((chip->tested & TEST_OK_ERASE)) + if (chip->tested.erase == OK) msg_ginfo("E"); + else if (chip->tested.erase == NA) + msg_ginfo("-"); else msg_ginfo(" "); - if ((chip->tested & TEST_OK_WRITE)) + if (chip->tested.write == OK) msg_ginfo("W"); + else if (chip->tested.write == NA) + msg_ginfo("-"); else msg_ginfo(" "); for (i = 0; i < border; i++) msg_ginfo(" ");
- if ((chip->tested & TEST_BAD_PROBE)) + if (chip->tested.probe == BAD) msg_ginfo("P"); else msg_ginfo(" "); - if ((chip->tested & TEST_BAD_READ)) + if (chip->tested.read == BAD) msg_ginfo("R"); else msg_ginfo(" "); - if ((chip->tested & TEST_BAD_ERASE)) + if (chip->tested.erase == BAD) msg_ginfo("E"); else msg_ginfo(" "); - if ((chip->tested & TEST_BAD_WRITE)) + if (chip->tested.write == BAD) msg_ginfo("W"); else msg_ginfo(" ");
Modified: trunk/print_wiki.c ============================================================================== --- trunk/print_wiki.c Sun May 25 09:47:47 2014 (r1797) +++ trunk/print_wiki.c Mon May 26 02:36:24 2014 (r1798) @@ -249,7 +249,6 @@ static void print_supported_chips_wiki(int cols) { unsigned int lines_per_col; - uint32_t t; char *s; char vmax[6]; char vmin[6]; @@ -287,7 +286,35 @@ c = !c;
old = f; - t = f->tested; + const char *probe, *read, *write, *erase; + switch (f->tested.probe) { + case OK: probe = "OK"; break; + case BAD: probe = "No"; break; + case NA: probe = "NA"; break; + case DEP: probe = "Dep"; break; + default: probe = "?3"; break; + } + switch (f->tested.read) { + case OK: read = "OK"; break; + case BAD: read = "No"; break; + case NA: read = "NA"; break; + case DEP: read = "Dep"; break; + default: read = "?3"; break; + } + switch (f->tested.erase) { + case OK: erase = "OK"; break; + case BAD: erase = "No"; break; + case NA: erase = "NA"; break; + case DEP: erase = "Dep"; break; + default: erase = "?3"; break; + } + switch (f->tested.write) { + case OK: write = "OK"; break; + case BAD: write = "No"; break; + case NA: write = "NA"; break; + case DEP: write = "Dep"; break; + default: write = "?3"; break; + } s = flashbuses_to_text(f->bustype); sprintf(vmin, "%0.03f", f->voltage.min / (double)1000); sprintf(vmax, "%0.03f", f->voltage.max / (double)1000); @@ -298,16 +325,9 @@ "|| %s || %s \n", (c == 1) ? "eeeeee" : "dddddd", f->vendor, f->name, f->total_size, s, - (t & TEST_OK_PROBE) ? "OK" : - (t & TEST_BAD_PROBE) ? "No" : "?3", - (t & TEST_OK_READ) ? "OK" : - (t & TEST_BAD_READ) ? "No" : "?3", - (t & TEST_OK_ERASE) ? "OK" : - (t & TEST_BAD_ERASE) ? "No" : "?3", - (t & TEST_OK_WRITE) ? "OK" : - (t & TEST_BAD_WRITE) ? "No" : "?3", - f->voltage.min ? vmin : "N/A", - f->voltage.min ? vmax : "N/A"); + probe, read, erase, write, + f->voltage.min ? vmin : "?", + f->voltage.max ? vmax : "?"); free(s);
if (((i % lines_per_col) + 1) == lines_per_col)