summaryrefslogtreecommitdiff
path: root/util/flashrom/jedec.c
diff options
context:
space:
mode:
authorCarl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>2009-03-05 19:24:22 +0000
committerCarl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>2009-03-05 19:24:22 +0000
commitac12ecd27a8e32a02193ea22dc36c89a060cc22e (patch)
tree278f567c693fcc0f1b46149bb1f571d655661c30 /util/flashrom/jedec.c
parent51001fbd81543d738a07cd36063fe5705eeff3ad (diff)
flashrom: 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. Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> Acked-by: FENG Yu Ning <fengyuning1984@gmail.com> Tested-by: Joe Julian git-svn-id: svn://svn.coreboot.org/coreboot/trunk@3971 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Diffstat (limited to 'util/flashrom/jedec.c')
-rw-r--r--util/flashrom/jedec.c100
1 files changed, 50 insertions, 50 deletions
diff --git a/util/flashrom/jedec.c b/util/flashrom/jedec.c
index 9dbaa5327d..5403297cef 100644
--- a/util/flashrom/jedec.c
+++ b/util/flashrom/jedec.c
@@ -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;
}