1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-26 22:52:34 +02:00

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).

Corresponding to flashrom svn r1798.

Signed-off-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at>
Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
This commit is contained in:
Stefan Tauner 2014-05-26 00:36:24 +00:00
parent ffb0cf649c
commit 6455dff07b
5 changed files with 113 additions and 71 deletions

59
flash.h
View File

@ -120,6 +120,26 @@ enum write_granularity {
#define FEATURE_OTP (1 << 8) #define FEATURE_OTP (1 << 8)
#define FEATURE_QPI (1 << 9) #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; struct flashctx;
typedef int (erasefunc_t)(struct flashctx *flash, unsigned int addr, unsigned int blocklen); typedef int (erasefunc_t)(struct flashctx *flash, unsigned int addr, unsigned int blocklen);
@ -143,11 +163,13 @@ struct flashchip {
unsigned int page_size; unsigned int page_size;
int feature_bits; int feature_bits;
/* /* Indicate how well flashrom supports different operations of this flash chip. */
* Indicate if flashrom has been tested with this flash chip and if struct tested {
* everything worked correctly. enum test_state probe;
*/ enum test_state read;
uint32_t tested; enum test_state erase;
enum test_state write;
} tested;
int (*probe) (struct flashctx *flash); int (*probe) (struct flashctx *flash);
@ -192,27 +214,6 @@ struct flashctx {
struct registered_programmer *pgm; 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 /* Timing used in probe routines. ZERO is -2 to differentiate between an unset
* field and zero delay. * field and zero delay.
* *
@ -265,12 +266,6 @@ int doit(struct flashctx *flash, int force, const char *filename, int read_it, i
int read_buf_from_file(unsigned char *buf, unsigned long size, const char *filename); 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); 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. */ /* Something happened that shouldn't happen, but we can go on. */
#define ERROR_NONFATAL 0x100 #define ERROR_NONFATAL 0x100

View File

@ -2189,7 +2189,7 @@ const struct flashchip flashchips[] = {
.model_id = ATMEL_AT26F004, .model_id = ATMEL_AT26F004,
.total_size = 512, .total_size = 512,
.page_size = 256, .page_size = 256,
.tested = TEST_BAD_WRITE, .tested = {.probe = NT, .read = NT, .erase = NT, .write = BAD },
.feature_bits = FEATURE_WRSR_WREN, .feature_bits = FEATURE_WRSR_WREN,
.probe = probe_spi_rdid, .probe = probe_spi_rdid,
.probe_timing = TIMING_ZERO, .probe_timing = TIMING_ZERO,
@ -5915,7 +5915,7 @@ const struct flashchip flashchips[] = {
.model_id = MACRONIX_MX23L3254, .model_id = MACRONIX_MX23L3254,
.total_size = 4096, .total_size = 4096,
.page_size = 256, .page_size = 256,
.tested = TEST_OK_PR | TEST_BAD_EW, .tested = {.probe = OK, .read = OK, .erase = NA, .write = NA},
.probe = probe_spi_rdid, .probe = probe_spi_rdid,
.probe_timing = TIMING_ZERO, .probe_timing = TIMING_ZERO,
.write = NULL, /* MX23L3254 is a mask ROM, so it is read-only */ .write = NULL, /* MX23L3254 is a mask ROM, so it is read-only */

View File

@ -1791,32 +1791,43 @@ void check_chip_supported(const struct flashchip *chip)
"clone the contents of this chip (see man page for " "clone the contents of this chip (see man page for "
"details).\n"); "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"); 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:"); 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"); msg_cinfo(" PROBE");
if (chip->tested & TEST_BAD_READ) if (chip->tested.read == BAD)
msg_cinfo(" READ"); msg_cinfo(" READ");
if (chip->tested & TEST_BAD_ERASE) if (chip->tested.erase == BAD)
msg_cinfo(" ERASE"); msg_cinfo(" ERASE");
if (chip->tested & TEST_BAD_WRITE) if (chip->tested.write == BAD)
msg_cinfo(" WRITE"); msg_cinfo(" WRITE");
msg_cinfo("\n"); msg_cinfo("\n");
} }
if ((!(chip->tested & TEST_BAD_PROBE) && !(chip->tested & TEST_OK_PROBE)) || if ((chip->tested.probe == NT) ||
(!(chip->tested & TEST_BAD_READ) && !(chip->tested & TEST_OK_READ)) || (chip->tested.read == NT) ||
(!(chip->tested & TEST_BAD_ERASE) && !(chip->tested & TEST_OK_ERASE)) || (chip->tested.erase == NT) ||
(!(chip->tested & TEST_BAD_WRITE) && !(chip->tested & TEST_OK_WRITE))) { (chip->tested.write == NT)) {
msg_cinfo("This flash part has status UNTESTED for operations:"); 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"); msg_cinfo(" PROBE");
if (!(chip->tested & TEST_BAD_READ) && !(chip->tested & TEST_OK_READ)) if (chip->tested.read == NT)
msg_cinfo(" READ"); msg_cinfo(" READ");
if (!(chip->tested & TEST_BAD_ERASE) && !(chip->tested & TEST_OK_ERASE)) if (chip->tested.erase == NT)
msg_cinfo(" ERASE"); msg_cinfo(" ERASE");
if (!(chip->tested & TEST_BAD_WRITE) && !(chip->tested & TEST_OK_WRITE)) if (chip->tested.write == NT)
msg_cinfo(" WRITE"); msg_cinfo(" WRITE");
msg_cinfo("\n"); msg_cinfo("\n");
} }
@ -1859,7 +1870,7 @@ int chip_safety_check(const struct flashctx *flash, int force, int read_it, int
if (read_it || erase_it || write_it || verify_it) { if (read_it || erase_it || write_it || verify_it) {
/* Everything needs read. */ /* Everything needs read. */
if (chip->tested & TEST_BAD_READ) { if (chip->tested.read == BAD) {
msg_cerr("Read is not working on this chip. "); msg_cerr("Read is not working on this chip. ");
if (!force) if (!force)
return 1; return 1;
@ -1873,7 +1884,11 @@ int chip_safety_check(const struct flashctx *flash, int force, int read_it, int
} }
if (erase_it || write_it) { if (erase_it || write_it) {
/* Write needs erase. */ /* 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. "); msg_cerr("Erase is not working on this chip. ");
if (!force) if (!force)
return 1; return 1;
@ -1886,7 +1901,11 @@ int chip_safety_check(const struct flashctx *flash, int force, int read_it, int
} }
} }
if (write_it) { 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. "); msg_cerr("Write is not working on this chip. ");
if (!force) if (!force)
return 1; return 1;

24
print.c
View File

@ -249,38 +249,46 @@ static int print_supported_chips(void)
for (i = curdevlen; i < maxchiplen; i++) for (i = curdevlen; i < maxchiplen; i++)
msg_ginfo(" "); msg_ginfo(" ");
if ((chip->tested & TEST_OK_PROBE)) if (chip->tested.probe == OK)
msg_ginfo("P"); msg_ginfo("P");
else if (chip->tested.probe == NA)
msg_ginfo("-");
else else
msg_ginfo(" "); msg_ginfo(" ");
if ((chip->tested & TEST_OK_READ)) if (chip->tested.read == OK)
msg_ginfo("R"); msg_ginfo("R");
else if (chip->tested.read == NA)
msg_ginfo("-");
else else
msg_ginfo(" "); msg_ginfo(" ");
if ((chip->tested & TEST_OK_ERASE)) if (chip->tested.erase == OK)
msg_ginfo("E"); msg_ginfo("E");
else if (chip->tested.erase == NA)
msg_ginfo("-");
else else
msg_ginfo(" "); msg_ginfo(" ");
if ((chip->tested & TEST_OK_WRITE)) if (chip->tested.write == OK)
msg_ginfo("W"); msg_ginfo("W");
else if (chip->tested.write == NA)
msg_ginfo("-");
else else
msg_ginfo(" "); msg_ginfo(" ");
for (i = 0; i < border; i++) for (i = 0; i < border; i++)
msg_ginfo(" "); msg_ginfo(" ");
if ((chip->tested & TEST_BAD_PROBE)) if (chip->tested.probe == BAD)
msg_ginfo("P"); msg_ginfo("P");
else else
msg_ginfo(" "); msg_ginfo(" ");
if ((chip->tested & TEST_BAD_READ)) if (chip->tested.read == BAD)
msg_ginfo("R"); msg_ginfo("R");
else else
msg_ginfo(" "); msg_ginfo(" ");
if ((chip->tested & TEST_BAD_ERASE)) if (chip->tested.erase == BAD)
msg_ginfo("E"); msg_ginfo("E");
else else
msg_ginfo(" "); msg_ginfo(" ");
if ((chip->tested & TEST_BAD_WRITE)) if (chip->tested.write == BAD)
msg_ginfo("W"); msg_ginfo("W");
else else
msg_ginfo(" "); msg_ginfo(" ");

View File

@ -249,7 +249,6 @@ static void print_supported_boards_wiki(void)
static void print_supported_chips_wiki(int cols) static void print_supported_chips_wiki(int cols)
{ {
unsigned int lines_per_col; unsigned int lines_per_col;
uint32_t t;
char *s; char *s;
char vmax[6]; char vmax[6];
char vmin[6]; char vmin[6];
@ -287,7 +286,35 @@ static void print_supported_chips_wiki(int cols)
c = !c; c = !c;
old = f; 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); s = flashbuses_to_text(f->bustype);
sprintf(vmin, "%0.03f", f->voltage.min / (double)1000); sprintf(vmin, "%0.03f", f->voltage.min / (double)1000);
sprintf(vmax, "%0.03f", f->voltage.max / (double)1000); sprintf(vmax, "%0.03f", f->voltage.max / (double)1000);
@ -298,16 +325,9 @@ static void print_supported_chips_wiki(int cols)
"|| %s || %s \n", "|| %s || %s \n",
(c == 1) ? "eeeeee" : "dddddd", f->vendor, f->name, (c == 1) ? "eeeeee" : "dddddd", f->vendor, f->name,
f->total_size, s, f->total_size, s,
(t & TEST_OK_PROBE) ? "OK" : probe, read, erase, write,
(t & TEST_BAD_PROBE) ? "No" : "?3", f->voltage.min ? vmin : "?",
(t & TEST_OK_READ) ? "OK" : f->voltage.max ? vmax : "?");
(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");
free(s); free(s);
if (((i % lines_per_col) + 1) == lines_per_col) if (((i % lines_per_col) + 1) == lines_per_col)