Edward O'Callaghan has uploaded this change for review.

View Change

jedec.c: Consolidate op,operand sequencing into func

Change-Id: I9a1b211b49777f6d7f62a052975c1759e036c8df
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
---
M jedec.c
1 file changed, 31 insertions(+), 59 deletions(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/02/72502/1
diff --git a/jedec.c b/jedec.c
index 171d343..0240afb 100644
--- a/jedec.c
+++ b/jedec.c
@@ -281,30 +281,29 @@
return 1;
}

-int erase_sector_jedec(struct flashctx *flash, unsigned int page, unsigned int size)
+static void issuecmd(const struct flashctx *flash, uint8_t op, unsigned int operand)
{
- chipaddr bios = flash->virtual_memory;
+ const chipaddr bios = flash->virtual_memory;
bool shifted = (flash->chip->feature_bits & FEATURE_ADDR_SHIFTED);
const unsigned int mask = getaddrmask(flash->chip);
- unsigned int delay_us = 0;
+ unsigned int delay_us = (flash->chip->probe_timing == TIMING_ZERO) ? 0 : 10;

- if(flash->chip->probe_timing != TIMING_ZERO)
- delay_us = 10;
+ if (!operand)
+ operand = (shifted ? 0x2AAA : 0x5555) & mask;

+ chip_writeb(flash, 0xAA, bios + ((shifted ? 0x2AAA : 0x5555) & mask));
+ programmer_delay(flash, delay_us);
+ chip_writeb(flash, 0x55, bios + ((shifted ? 0x5555 : 0x2AAA) & mask));
+ programmer_delay(flash, delay_us);
+ chip_writeb(flash, op, bios + operand);
+ programmer_delay(flash, delay_us);
+}
+
+int erase_sector_jedec(struct flashctx *flash, unsigned int page, unsigned int size)
+{
/* Issue the Sector Erase command */
- chip_writeb(flash, 0xAA, bios + ((shifted ? 0x2AAA : 0x5555) & mask));
- programmer_delay(flash, delay_us);
- chip_writeb(flash, 0x55, bios + ((shifted ? 0x5555 : 0x2AAA) & mask));
- programmer_delay(flash, delay_us);
- chip_writeb(flash, 0x80, bios + ((shifted ? 0x2AAA : 0x5555) & mask));
- programmer_delay(flash, delay_us);
-
- chip_writeb(flash, 0xAA, bios + ((shifted ? 0x2AAA : 0x5555) & mask));
- programmer_delay(flash, delay_us);
- chip_writeb(flash, 0x55, bios + ((shifted ? 0x5555 : 0x2AAA) & mask));
- programmer_delay(flash, delay_us);
- chip_writeb(flash, 0x30, bios + page);
- programmer_delay(flash, delay_us);
+ issuecmd(flash, 0x80, 0);
+ issuecmd(flash, 0x30, page);

/* wait for Toggle bit ready */
toggle_ready_jedec_slow(flash, bios);
@@ -315,28 +314,9 @@

int erase_block_jedec(struct flashctx *flash, unsigned int page, unsigned int size)
{
- chipaddr bios = flash->virtual_memory;
- bool shifted = (flash->chip->feature_bits & FEATURE_ADDR_SHIFTED);
- const unsigned int mask = getaddrmask(flash->chip);
- unsigned int delay_us = 0;
-
- if(flash->chip->probe_timing != TIMING_ZERO)
- delay_us = 10;
-
/* Issue the Sector Erase command */
- chip_writeb(flash, 0xAA, bios + ((shifted ? 0x2AAA : 0x5555) & mask));
- programmer_delay(flash, delay_us);
- chip_writeb(flash, 0x55, bios + ((shifted ? 0x5555 : 0x2AAA) & mask));
- programmer_delay(flash, delay_us);
- chip_writeb(flash, 0x80, bios + ((shifted ? 0x2AAA : 0x5555) & mask));
- programmer_delay(flash, delay_us);
-
- chip_writeb(flash, 0xAA, bios + ((shifted ? 0x2AAA : 0x5555) & mask));
- programmer_delay(flash, delay_us);
- chip_writeb(flash, 0x55, bios + ((shifted ? 0x5555 : 0x2AAA) & mask));
- programmer_delay(flash, delay_us);
- chip_writeb(flash, 0x50, bios + block);
- programmer_delay(flash, delay_us);
+ issuecmd(flash, 0x80, 0);
+ issuecmd(flash, 0x50, block);

/* wait for Toggle bit ready */
toggle_ready_jedec_slow(flash, bios);
@@ -347,27 +327,9 @@

static int erase_chip_jedec_common(struct flashctx *flash, unsigned int mask)
{
- chipaddr bios = flash->virtual_memory;
- bool shifted = (flash->chip->feature_bits & FEATURE_ADDR_SHIFTED);
- unsigned int delay_us = 0;
-
- if(flash->chip->probe_timing != TIMING_ZERO)
- delay_us = 10;
-
/* Issue the JEDEC Chip Erase command */
- chip_writeb(flash, 0xAA, bios + ((shifted ? 0x2AAA : 0x5555) & mask));
- programmer_delay(flash, delay_us);
- chip_writeb(flash, 0x55, bios + ((shifted ? 0x5555 : 0x2AAA) & mask));
- programmer_delay(flash, delay_us);
- chip_writeb(flash, 0x80, bios + ((shifted ? 0x2AAA : 0x5555) & mask));
- programmer_delay(flash, delay_us);
-
- chip_writeb(flash, 0xAA, bios + ((shifted ? 0x2AAA : 0x5555) & mask));
- programmer_delay(flash, delay_us);
- chip_writeb(flash, 0x55, bios + ((shifted ? 0x5555 : 0x2AAA) & mask));
- programmer_delay(flash, delay_us);
- chip_writeb(flash, 0x10, bios + ((shifted ? 0x2AAA : 0x5555) & mask));
- programmer_delay(flash, delay_us);
+ issuecmd(flash, 0x80, 0);
+ issuecmd(flash, 0x10, 0);

toggle_ready_jedec_slow(flash, bios);


To view, visit change 72502. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I9a1b211b49777f6d7f62a052975c1759e036c8df
Gerrit-Change-Number: 72502
Gerrit-PatchSet: 1
Gerrit-Owner: Edward O'Callaghan <quasisec@chromium.org>
Gerrit-MessageType: newchange