diff options
author | Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> | 2009-03-05 19:24:22 +0000 |
---|---|---|
committer | Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> | 2009-03-05 19:24:22 +0000 |
commit | c6c526cfd4cd2a604dd07aaa73cb1cb64678743d (patch) | |
tree | 42326fb1bdeb491df1db567eacdec088bee46c7d /jedec.c | |
parent | f2170967edfccc72d4a3b4665f2ab5dee3c42d70 (diff) | |
download | flashrom-c6c526cfd4cd2a604dd07aaa73cb1cb64678743d.zip flashrom-c6c526cfd4cd2a604dd07aaa73cb1cb64678743d.tar.gz |
Use helper functions to access flash chips
Right now we perform direct pointer manipulation without any abstraction
to read from and write to memory mapped flash chips. That makes it
impossible to drive any flasher which does not mmap the whole chip.
Using helper functions readb() and writeb() allows a driver for external
flash programmers like Paraflasher to replace readb and writeb with
calls to its own chip access routines.
This patch has the additional advantage of removing lots of unnecessary
casts to volatile uint8_t * and now-superfluous parentheses which caused
poor readability.
I used the semantic patcher Coccinelle to create this patch. The
semantic patch follows:
@@
expression a;
typedef uint8_t;
volatile uint8_t *b;
@@
- *(b) = (a);
+ writeb(a, b);
@@
volatile uint8_t *b;
@@
- *(b)
+ readb(b)
@@
type T;
T b;
@@
(
readb
|
writeb
)
(...,
- (T)
- (b)
+ b
)
In contrast to a sed script, the semantic patch performs type checking
before converting anything.
Tested-by: Joe Julian
Corresponding to flashrom svn r418 and coreboot v2 svn r3971.
Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Acked-by: FENG Yu Ning <fengyuning1984@gmail.com>
Diffstat (limited to 'jedec.c')
-rw-r--r-- | jedec.c | 100 |
1 files changed, 50 insertions, 50 deletions
@@ -40,10 +40,10 @@ void toggle_ready_jedec(volatile uint8_t *dst) unsigned int i = 0; uint8_t tmp1, tmp2; - tmp1 = *dst & 0x40; + tmp1 = readb(dst) & 0x40; while (i++ < 0xFFFFFFF) { - tmp2 = *dst & 0x40; + tmp2 = readb(dst) & 0x40; if (tmp1 == tmp2) { break; } @@ -59,7 +59,7 @@ void data_polling_jedec(volatile uint8_t *dst, uint8_t data) data &= 0x80; while (i++ < 0xFFFFFFF) { - tmp = *dst & 0x80; + tmp = readb(dst) & 0x80; if (tmp == data) { break; } @@ -68,21 +68,21 @@ void data_polling_jedec(volatile uint8_t *dst, uint8_t data) void unprotect_jedec(volatile uint8_t *bios) { - *(volatile uint8_t *)(bios + 0x5555) = 0xAA; - *(volatile uint8_t *)(bios + 0x2AAA) = 0x55; - *(volatile uint8_t *)(bios + 0x5555) = 0x80; - *(volatile uint8_t *)(bios + 0x5555) = 0xAA; - *(volatile uint8_t *)(bios + 0x2AAA) = 0x55; - *(volatile uint8_t *)(bios + 0x5555) = 0x20; + writeb(0xAA, bios + 0x5555); + writeb(0x55, bios + 0x2AAA); + writeb(0x80, bios + 0x5555); + writeb(0xAA, bios + 0x5555); + writeb(0x55, bios + 0x2AAA); + writeb(0x20, bios + 0x5555); usleep(200); } void protect_jedec(volatile uint8_t *bios) { - *(volatile uint8_t *)(bios + 0x5555) = 0xAA; - *(volatile uint8_t *)(bios + 0x2AAA) = 0x55; - *(volatile uint8_t *)(bios + 0x5555) = 0xA0; + writeb(0xAA, bios + 0x5555); + writeb(0x55, bios + 0x2AAA); + writeb(0xA0, bios + 0x5555); usleep(200); } @@ -94,40 +94,40 @@ int probe_jedec(struct flashchip *flash) uint32_t largeid1, largeid2; /* Issue JEDEC Product ID Entry command */ - *(volatile uint8_t *)(bios + 0x5555) = 0xAA; + writeb(0xAA, bios + 0x5555); myusec_delay(10); - *(volatile uint8_t *)(bios + 0x2AAA) = 0x55; + writeb(0x55, bios + 0x2AAA); myusec_delay(10); - *(volatile uint8_t *)(bios + 0x5555) = 0x90; + writeb(0x90, bios + 0x5555); /* Older chips may need up to 100 us to respond. The ATMEL 29C020 * needs 10 ms according to the data sheet. */ myusec_delay(10000); /* Read product ID */ - id1 = *(volatile uint8_t *)bios; - id2 = *(volatile uint8_t *)(bios + 0x01); + id1 = readb(bios); + id2 = readb(bios + 0x01); largeid1 = id1; largeid2 = id2; /* Check if it is a continuation ID, this should be a while loop. */ if (id1 == 0x7F) { largeid1 <<= 8; - id1 = *(volatile uint8_t *)(bios + 0x100); + id1 = readb(bios + 0x100); largeid1 |= id1; } if (id2 == 0x7F) { largeid2 <<= 8; - id2 = *(volatile uint8_t *)(bios + 0x101); + id2 = readb(bios + 0x101); largeid2 |= id2; } /* Issue JEDEC Product ID Exit command */ - *(volatile uint8_t *)(bios + 0x5555) = 0xAA; + writeb(0xAA, bios + 0x5555); myusec_delay(10); - *(volatile uint8_t *)(bios + 0x2AAA) = 0x55; + writeb(0x55, bios + 0x2AAA); myusec_delay(10); - *(volatile uint8_t *)(bios + 0x5555) = 0xF0; + writeb(0xF0, bios + 0x5555); myusec_delay(40); printf_debug("%s: id1 0x%02x, id2 0x%02x", __FUNCTION__, largeid1, largeid2); @@ -143,18 +143,18 @@ int probe_jedec(struct flashchip *flash) int erase_sector_jedec(volatile uint8_t *bios, unsigned int page) { /* Issue the Sector Erase command */ - *(volatile uint8_t *)(bios + 0x5555) = 0xAA; + writeb(0xAA, bios + 0x5555); myusec_delay(10); - *(volatile uint8_t *)(bios + 0x2AAA) = 0x55; + writeb(0x55, bios + 0x2AAA); myusec_delay(10); - *(volatile uint8_t *)(bios + 0x5555) = 0x80; + writeb(0x80, bios + 0x5555); myusec_delay(10); - *(volatile uint8_t *)(bios + 0x5555) = 0xAA; + writeb(0xAA, bios + 0x5555); myusec_delay(10); - *(volatile uint8_t *)(bios + 0x2AAA) = 0x55; + writeb(0x55, bios + 0x2AAA); myusec_delay(10); - *(volatile uint8_t *)(bios + page) = 0x30; + writeb(0x30, bios + page); myusec_delay(10); /* wait for Toggle bit ready */ @@ -166,18 +166,18 @@ int erase_sector_jedec(volatile uint8_t *bios, unsigned int page) int erase_block_jedec(volatile uint8_t *bios, unsigned int block) { /* Issue the Sector Erase command */ - *(volatile uint8_t *)(bios + 0x5555) = 0xAA; + writeb(0xAA, bios + 0x5555); myusec_delay(10); - *(volatile uint8_t *)(bios + 0x2AAA) = 0x55; + writeb(0x55, bios + 0x2AAA); myusec_delay(10); - *(volatile uint8_t *)(bios + 0x5555) = 0x80; + writeb(0x80, bios + 0x5555); myusec_delay(10); - *(volatile uint8_t *)(bios + 0x5555) = 0xAA; + writeb(0xAA, bios + 0x5555); myusec_delay(10); - *(volatile uint8_t *)(bios + 0x2AAA) = 0x55; + writeb(0x55, bios + 0x2AAA); myusec_delay(10); - *(volatile uint8_t *)(bios + block) = 0x50; + writeb(0x50, bios + block); myusec_delay(10); /* wait for Toggle bit ready */ @@ -191,18 +191,18 @@ int erase_chip_jedec(struct flashchip *flash) volatile uint8_t *bios = flash->virtual_memory; /* Issue the JEDEC Chip Erase command */ - *(volatile uint8_t *)(bios + 0x5555) = 0xAA; + writeb(0xAA, bios + 0x5555); myusec_delay(10); - *(volatile uint8_t *)(bios + 0x2AAA) = 0x55; + writeb(0x55, bios + 0x2AAA); myusec_delay(10); - *(volatile uint8_t *)(bios + 0x5555) = 0x80; + writeb(0x80, bios + 0x5555); myusec_delay(10); - *(volatile uint8_t *)(bios + 0x5555) = 0xAA; + writeb(0xAA, bios + 0x5555); myusec_delay(10); - *(volatile uint8_t *)(bios + 0x2AAA) = 0x55; + writeb(0x55, bios + 0x2AAA); myusec_delay(10); - *(volatile uint8_t *)(bios + 0x5555) = 0x10; + writeb(0x10, bios + 0x5555); myusec_delay(10); toggle_ready_jedec(bios); @@ -219,15 +219,15 @@ int write_page_write_jedec(volatile uint8_t *bios, uint8_t *src, retry: /* Issue JEDEC Data Unprotect comand */ - *(volatile uint8_t *)(bios + 0x5555) = 0xAA; - *(volatile uint8_t *)(bios + 0x2AAA) = 0x55; - *(volatile uint8_t *)(bios + 0x5555) = 0xA0; + writeb(0xAA, bios + 0x5555); + writeb(0x55, bios + 0x2AAA); + writeb(0xA0, bios + 0x5555); /* transfer data from source to destination */ for (i = start_index; i < page_size; i++) { /* If the data is 0xFF, don't program it */ if (*src != 0xFF) - *dst = *src; + writeb(*src, dst); dst++; src++; } @@ -238,7 +238,7 @@ retry: src = s; ok = 1; for (i = 0; i < page_size; i++) { - if (*dst != *src) { + if (readb(dst) != *src) { ok = 0; break; } @@ -269,15 +269,15 @@ int write_byte_program_jedec(volatile uint8_t *bios, uint8_t *src, retry: /* Issue JEDEC Byte Program command */ - *(volatile uint8_t *)(bios + 0x5555) = 0xAA; - *(volatile uint8_t *)(bios + 0x2AAA) = 0x55; - *(volatile uint8_t *)(bios + 0x5555) = 0xA0; + writeb(0xAA, bios + 0x5555); + writeb(0x55, bios + 0x2AAA); + writeb(0xA0, bios + 0x5555); /* transfer data from source to destination */ - *dst = *src; + writeb(*src, dst); toggle_ready_jedec(bios); - if (*dst != *src && tried++ < MAX_REFLASH_TRIES) { + if (readb(dst) != *src && tried++ < MAX_REFLASH_TRIES) { goto retry; } |