Nikolai Artemiev has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/59529 )
Change subject: spi25_statusreg: delete read_status_register() ......................................................................
spi25_statusreg: delete read_status_register()
BUG=b:195381327,b:153800563 TEST=builds BRANCH=none
Change-Id: I146b4b5439872e66c5d33e156451a729d248c7da Signed-off-by: Nikolai Artemiev nartemiev@google.com --- M chipdrivers.h M it87spi.c M s25f.c M spi25.c M spi25_statusreg.c 5 files changed, 119 insertions(+), 55 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/29/59529/1
diff --git a/chipdrivers.h b/chipdrivers.h index 41b99e7..145abeb 100644 --- a/chipdrivers.h +++ b/chipdrivers.h @@ -62,8 +62,6 @@
/* spi25_statusreg.c */ -/* FIXME: replace spi_read_status_register() calls with spi_read_register() */ -uint8_t spi_read_status_register(const struct flashctx *flash); int spi_read_register(const struct flashctx *flash, enum flash_reg reg, uint8_t *value); int spi_write_register(const struct flashctx *flash, enum flash_reg reg, uint8_t value); void spi_prettyprint_status_register_bit(uint8_t status, int bit); diff --git a/it87spi.c b/it87spi.c index 5f6fb65..ae021e0 100644 --- a/it87spi.c +++ b/it87spi.c @@ -133,8 +133,16 @@ /* Wait until the Write-In-Progress bit is cleared. * This usually takes 1-10 ms, so wait in 1 ms steps. */ - while (spi_read_status_register(flash) & SPI_SR_WIP) + while (true) { + uint8_t status; + if(spi_read_register(flash, STATUS1, &status)) + return -1; + + if((status & SPI_SR_WIP) == 0) + return 0; + programmer_delay(1000); + } return 0; }
@@ -276,7 +284,8 @@ }
while (len >= chip->page_size) { - it8716f_spi_page_program(flash, buf, start); + if (it8716f_spi_page_program(flash, buf, start)) + return -1; start += chip->page_size; len -= chip->page_size; buf += chip->page_size; diff --git a/s25f.c b/s25f.c index 0bd4a7c..82ca610 100644 --- a/s25f.c +++ b/s25f.c @@ -133,9 +133,14 @@
static int s25f_poll_status(const struct flashctx *flash) { - uint8_t tmp = spi_read_status_register(flash); + while (true) { + uint8_t tmp; + if (spi_read_register(flash, STATUS1, &tmp)) + return -1;
- while (tmp & SPI_SR_WIP) { + if ((tmp & SPI_SR_WIP) == 0) + break; + /* * The WIP bit on S25F chips remains set to 1 if erase or * programming errors occur, so we must check for those @@ -156,7 +161,6 @@ }
programmer_delay(1000 * 10); - tmp = spi_read_status_register(flash); }
return 0; diff --git a/spi25.c b/spi25.c index 213273f..a8d1343 100644 --- a/spi25.c +++ b/spi25.c @@ -304,12 +304,16 @@
static int spi_poll_wip(struct flashctx *const flash, const unsigned int poll_delay) { - /* FIXME: We can't tell if spi_read_status_register() failed. */ - /* FIXME: We don't time out. */ - while (spi_read_status_register(flash) & SPI_SR_WIP) + for (int i = 0; i < 500; i++) { + uint8_t status; + int ret = spi_read_register(flash, STATUS1, &status); + if (ret) return ret; + if (!(status & SPI_SR_WIP)) return 0; + programmer_delay(poll_delay); - /* FIXME: Check the status register for errors. */ - return 0; + } + + return TIMEOUT_ERROR; }
/** diff --git a/spi25_statusreg.c b/spi25_statusreg.c index 07d9d5a..1204b66 100644 --- a/spi25_statusreg.c +++ b/spi25_statusreg.c @@ -110,17 +110,21 @@ * allow running RDSR only once. Therefore pick an initial delay of * 100 ms, then wait in 10 ms steps until a total of 5 s have elapsed. */ - int i = 0; programmer_delay(100 * 1000); - while (spi_read_status_register(flash) & SPI_SR_WIP) { - if (++i > 490) { - msg_cerr("Error: WIP bit after WRSR never cleared\n"); - return TIMEOUT_ERROR; - } + + uint8_t status; + for (int i = 0; i < 490; i++) { + result = spi_read_register(flash, STATUS1, &status); + if (result) + return result; + if ((status & SPI_SR_WIP) == 0) + return 0; + programmer_delay(10 * 1000); } - return 0; -} + + msg_cerr("Error: WIP bit after WRSR never cleared\n"); + return TIMEOUT_ERROR; }
int spi_read_register(const struct flashctx *flash, enum flash_reg reg, uint8_t *value) @@ -151,15 +155,6 @@ return 0; }
- -uint8_t spi_read_status_register(const struct flashctx *flash) -{ - uint8_t status = 0; - /* FIXME: We should propagate the error. */ - spi_read_register(flash, STATUS1, &status); - return status; -} - static int spi_restore_status(struct flashctx *flash, uint8_t status) { msg_cdbg("restoring chip status (0x%02x)\n", status); @@ -192,7 +187,10 @@ uint8_t status; int result;
- status = spi_read_status_register(flash); + int ret = spi_read_register(flash, STATUS1, &status); + if (ret) + return ret; + if ((status & bp_mask) == 0) { msg_cdbg2("Block protection is disabled.\n"); return 0; @@ -214,7 +212,10 @@ msg_cerr("spi_write_register failed.\n"); return result; } - status = spi_read_status_register(flash); + + if (spi_read_register(flash, STATUS1, &status)) + return -1; + if ((status & lock_mask) != 0) { msg_cerr("Unsetting lock bit(s) failed.\n"); return 1; @@ -227,7 +228,10 @@ msg_cerr("spi_write_register failed.\n"); return result; } - status = spi_read_status_register(flash); + + if (spi_read_register(flash, STATUS1, &status)) + return -1; + if ((status & bp_mask) != 0) { msg_cerr("Block protection could not be disabled!\n"); if (flash->chip->printlock) @@ -348,7 +352,9 @@
int spi_prettyprint_status_register_plain(struct flashctx *flash) { - uint8_t status = spi_read_status_register(flash); + uint8_t status; + if(spi_read_register(flash, STATUS1, &status)) + return -1; spi_prettyprint_status_register_hex(status); return 0; } @@ -356,7 +362,9 @@ /* Print the plain hex value and the welwip bits only. */ int spi_prettyprint_status_register_default_welwip(struct flashctx *flash) { - uint8_t status = spi_read_status_register(flash); + uint8_t status; + if(spi_read_register(flash, STATUS1, &status)) + return -1; spi_prettyprint_status_register_hex(status);
spi_prettyprint_status_register_welwip(status); @@ -369,7 +377,9 @@ */ int spi_prettyprint_status_register_bp1_srwd(struct flashctx *flash) { - uint8_t status = spi_read_status_register(flash); + uint8_t status; + if(spi_read_register(flash, STATUS1, &status)) + return -1; spi_prettyprint_status_register_hex(status);
spi_prettyprint_status_register_srwd(status); @@ -387,7 +397,9 @@ */ int spi_prettyprint_status_register_bp2_srwd(struct flashctx *flash) { - uint8_t status = spi_read_status_register(flash); + uint8_t status; + if(spi_read_register(flash, STATUS1, &status)) + return -1; spi_prettyprint_status_register_hex(status);
spi_prettyprint_status_register_srwd(status); @@ -404,7 +416,9 @@ */ int spi_prettyprint_status_register_bp3_srwd(struct flashctx *flash) { - uint8_t status = spi_read_status_register(flash); + uint8_t status; + if(spi_read_register(flash, STATUS1, &status)) + return -1; spi_prettyprint_status_register_hex(status);
spi_prettyprint_status_register_srwd(status); @@ -416,7 +430,9 @@
int spi_prettyprint_status_register_bp4_srwd(struct flashctx *flash) { - uint8_t status = spi_read_status_register(flash); + uint8_t status; + if(spi_read_register(flash, STATUS1, &status)) + return -1; spi_prettyprint_status_register_hex(status);
spi_prettyprint_status_register_srwd(status); @@ -427,7 +443,9 @@
int spi_prettyprint_status_register_bp2_bpl(struct flashctx *flash) { - uint8_t status = spi_read_status_register(flash); + uint8_t status; + if(spi_read_register(flash, STATUS1, &status)) + return -1; spi_prettyprint_status_register_hex(status);
spi_prettyprint_status_register_bpl(status); @@ -440,7 +458,9 @@
int spi_prettyprint_status_register_bp2_tb_bpl(struct flashctx *flash) { - uint8_t status = spi_read_status_register(flash); + uint8_t status; + if(spi_read_register(flash, STATUS1, &status)) + return -1; spi_prettyprint_status_register_hex(status);
spi_prettyprint_status_register_bpl(status); @@ -462,7 +482,9 @@
int spi_prettyprint_status_register_amic_a25l032(struct flashctx *flash) { - uint8_t status = spi_read_status_register(flash); + uint8_t status; + if(spi_read_register(flash, STATUS1, &status)) + return -1; spi_prettyprint_status_register_hex(status);
spi_prettyprint_status_register_srwd(status); @@ -518,7 +540,10 @@
int spi_prettyprint_status_register_at25df(struct flashctx *flash) { - uint8_t status = spi_read_status_register(flash); + uint8_t status; + if(spi_read_register(flash, STATUS1, &status)) + return -1; + spi_prettyprint_status_register_hex(status);
spi_prettyprint_status_register_atmel_at25_srpl(status); @@ -541,8 +566,9 @@ int spi_prettyprint_status_register_at25f(struct flashctx *flash) { uint8_t status; + if (spi_read_register(flash, STATUS1, &status)) + return -1;
- status = spi_read_status_register(flash); spi_prettyprint_status_register_hex(status);
spi_prettyprint_status_register_atmel_at25_wpen(status); @@ -557,8 +583,9 @@ int spi_prettyprint_status_register_at25f512a(struct flashctx *flash) { uint8_t status; + if (spi_read_register(flash, STATUS1, &status)) + return -1;
- status = spi_read_status_register(flash); spi_prettyprint_status_register_hex(status);
spi_prettyprint_status_register_atmel_at25_wpen(status); @@ -573,7 +600,9 @@
int spi_prettyprint_status_register_at25f512b(struct flashctx *flash) { - uint8_t status = spi_read_status_register(flash); + uint8_t status; + if(spi_read_register(flash, STATUS1, &status)) + return -1; spi_prettyprint_status_register_hex(status);
spi_prettyprint_status_register_atmel_at25_srpl(status); @@ -589,7 +618,9 @@ { uint8_t status;
- status = spi_read_status_register(flash); + if(spi_read_register(flash, STATUS1, &status)) + return -1; + spi_prettyprint_status_register_hex(status);
spi_prettyprint_status_register_atmel_at25_wpen(status); @@ -602,7 +633,9 @@
int spi_prettyprint_status_register_at25fs010(struct flashctx *flash) { - uint8_t status = spi_read_status_register(flash); + uint8_t status; + if(spi_read_register(flash, STATUS1, &status)) + return -1; spi_prettyprint_status_register_hex(status);
spi_prettyprint_status_register_atmel_at25_wpen(status); @@ -622,7 +655,9 @@
int spi_prettyprint_status_register_at25fs040(struct flashctx *flash) { - uint8_t status = spi_read_status_register(flash); + uint8_t status; + if(spi_read_register(flash, STATUS1, &status)) + return -1; spi_prettyprint_status_register_hex(status);
spi_prettyprint_status_register_atmel_at25_wpen(status); @@ -634,7 +669,9 @@
int spi_prettyprint_status_register_at26df081a(struct flashctx *flash) { - uint8_t status = spi_read_status_register(flash); + uint8_t status; + if(spi_read_register(flash, STATUS1, &status)) + return -1; spi_prettyprint_status_register_hex(status);
spi_prettyprint_status_register_atmel_at25_srpl(status); @@ -692,7 +729,9 @@
int spi_prettyprint_status_register_en25s_wp(struct flashctx *flash) { - uint8_t status = spi_read_status_register(flash); + uint8_t status; + if(spi_read_register(flash, STATUS1, &status)) + return -1; spi_prettyprint_status_register_hex(status);
spi_prettyprint_status_register_srwd(status); @@ -711,7 +750,9 @@
int spi_prettyprint_status_register_n25q(struct flashctx *flash) { - uint8_t status = spi_read_status_register(flash); + uint8_t status; + if(spi_read_register(flash, STATUS1, &status)) + return -1; spi_prettyprint_status_register_hex(status);
spi_prettyprint_status_register_srwd(status); @@ -736,7 +777,9 @@ /* Used by Intel/Numonyx S33 and Spansion S25FL-S chips */ int spi_prettyprint_status_register_bp2_ep_srwd(struct flashctx *flash) { - uint8_t status = spi_read_status_register(flash); + uint8_t status; + if(spi_read_register(flash, STATUS1, &status)) + return -1; spi_prettyprint_status_register_hex(status);
spi_prettyprint_status_register_srwd(status); @@ -764,7 +807,9 @@
int spi_prettyprint_status_register_sst25(struct flashctx *flash) { - uint8_t status = spi_read_status_register(flash); + uint8_t status; + if(spi_read_register(flash, STATUS1, &status)) + return -1; spi_prettyprint_status_register_sst25_common(status); return 0; } @@ -780,7 +825,9 @@ "100000H-1FFFFFH", "all", "all" }; - uint8_t status = spi_read_status_register(flash); + uint8_t status; + if(spi_read_register(flash, STATUS1, &status)) + return -1; spi_prettyprint_status_register_sst25_common(status); msg_cdbg("Resulting block protection : %s\n", bpt[(status & 0x1c) >> 2]); return 0; @@ -795,7 +842,9 @@ "0x40000-0x7ffff", "all blocks", "all blocks", "all blocks", "all blocks" }; - uint8_t status = spi_read_status_register(flash); + uint8_t status; + if(spi_read_register(flash, STATUS1, &status)) + return -1; spi_prettyprint_status_register_sst25_common(status); msg_cdbg("Resulting block protection : %s\n", bpt[(status & 0x1c) >> 2]); return 0;