summaryrefslogtreecommitdiffstats
path: root/jedec.c
diff options
context:
space:
mode:
authorEdward O'Callaghan <quasisec@google.com>2023-01-30 22:28:18 +1100
committerEdward O'Callaghan <quasisec@chromium.org>2023-02-21 13:15:29 +0000
commit707cd6bc737387dc925ad2b74d59b075ee335fc2 (patch)
tree15151bcd1b79171c8f35e5515d23b237785588a8 /jedec.c
parent86babd06276196facd3c0948b466ccb665e846a7 (diff)
downloadflashrom-707cd6bc737387dc925ad2b74d59b075ee335fc2.tar.gz
flashrom-707cd6bc737387dc925ad2b74d59b075ee335fc2.tar.bz2
flashrom-707cd6bc737387dc925ad2b74d59b075ee335fc2.zip
jedec.c: Rewrite control flow procedurally
Drop goto usage in fav of loop constructs. Change-Id: I0927ed40e54cc7e114a57dc40e3614f4825a0ca9 Signed-off-by: Edward O'Callaghan <quasisec@google.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/72608 Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'jedec.c')
-rw-r--r--jedec.c68
1 files changed, 33 insertions, 35 deletions
diff --git a/jedec.c b/jedec.c
index db01c08e3..7f72e5378 100644
--- a/jedec.c
+++ b/jedec.c
@@ -347,30 +347,27 @@ int erase_chip_block_jedec(struct flashctx *flash, unsigned int addr, unsigned i
static int write_byte_program_jedec_common(const struct flashctx *flash, const uint8_t *src,
chipaddr dst, unsigned int mask)
{
- int tried = 0, failed = 0;
- chipaddr bios = flash->virtual_memory;
+ int tries = 0;
/* If the data is 0xFF, don't program it and don't complain. */
if (*src == 0xFF) {
return 0;
}
-retry:
- /* Issue JEDEC Byte Program command */
- start_program_jedec_common(flash, mask);
+ for (; tries < MAX_REFLASH_TRIES; tries++) {
+ const chipaddr bios = flash->virtual_memory;
+ /* Issue JEDEC Byte Program command */
+ start_program_jedec_common(flash, mask);
- /* transfer data from source to destination */
- chip_writeb(flash, *src, dst);
- toggle_ready_jedec(flash, bios);
+ /* transfer data from source to destination */
+ chip_writeb(flash, *src, dst);
+ toggle_ready_jedec(flash, bios);
- if (chip_readb(flash, dst) != *src && tried++ < MAX_REFLASH_TRIES) {
- goto retry;
+ if (chip_readb(flash, dst) == *src)
+ break;
}
- if (tried >= MAX_REFLASH_TRIES)
- failed = 1;
-
- return failed;
+ return (tries >= MAX_REFLASH_TRIES) ? 1 : 0;
}
/* chunksize is 1 */
@@ -399,40 +396,41 @@ int write_jedec_1(struct flashctx *flash, const uint8_t *src, unsigned int start
static int write_page_write_jedec_common(struct flashctx *flash, const uint8_t *src,
unsigned int start, unsigned int page_size)
{
- unsigned int i;
- int tried = 0, failed;
+ int tries = 0, failed;
const uint8_t *s = src;
- chipaddr bios = flash->virtual_memory;
+ const chipaddr bios = flash->virtual_memory;
chipaddr dst = bios + start;
chipaddr d = dst;
const unsigned int mask = getaddrmask(flash->chip);
-retry:
- /* Issue JEDEC Start Program command */
- start_program_jedec_common(flash, mask);
-
- /* transfer data from source to destination */
- for (i = 0; i < page_size; i++) {
- /* If the data is 0xFF, don't program it */
- if (*src != 0xFF)
- chip_writeb(flash, *src, dst);
- dst++;
- src++;
- }
+ for (; tries < MAX_REFLASH_TRIES; tries++) {
+ /* Issue JEDEC Start Program command */
+ start_program_jedec_common(flash, mask);
+
+ /* transfer data from source to destination */
+ for (unsigned int i = 0; i < page_size; i++) {
+ /* If the data is 0xFF, don't program it */
+ if (*src != 0xFF)
+ chip_writeb(flash, *src, dst);
+ dst++;
+ src++;
+ }
- toggle_ready_jedec(flash, dst - 1);
+ toggle_ready_jedec(flash, dst - 1);
- dst = d;
- src = s;
- failed = verify_range(flash, src, start, page_size);
+ dst = d;
+ src = s;
+ failed = verify_range(flash, src, start, page_size);
+ if (!failed)
+ break;
- if (failed && tried++ < MAX_REFLASH_TRIES) {
msg_cerr("retrying.\n");
- goto retry;
}
+
if (failed) {
msg_cerr(" page 0x%" PRIxPTR " failed!\n", (d - bios) / page_size);
}
+
return failed;
}