summaryrefslogtreecommitdiff
path: root/util/flashrom/sst49lfxxxc.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/sst49lfxxxc.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/sst49lfxxxc.c')
-rw-r--r--util/flashrom/sst49lfxxxc.c42
1 files changed, 21 insertions, 21 deletions
diff --git a/util/flashrom/sst49lfxxxc.c b/util/flashrom/sst49lfxxxc.c
index 2c9a87b9d8..397ee61935 100644
--- a/util/flashrom/sst49lfxxxc.c
+++ b/util/flashrom/sst49lfxxxc.c
@@ -50,20 +50,20 @@ static __inline__ int write_lockbits_49lfxxxc(volatile uint8_t *bios, int size,
//printf("bios=0x%08lx\n", (unsigned long)bios);
for (i = 0; left > 65536; i++, left -= 65536) {
//printf("lockbits at address=0x%08lx is 0x%01x\n", (unsigned long)0xFFC00000 - size + (i * 65536) + 2, *(bios + (i * 65536) + 2) );
- *(bios + (i * 65536) + 2) = bits;
+ writeb(bits, bios + (i * 65536) + 2);
}
address = i * 65536;
//printf("lockbits at address=0x%08lx is 0x%01x\n", (unsigned long)0xFFc00000 - size + address + 2, *(bios + address + 2) );
- *(bios + address + 2) = bits;
+ writeb(bits, bios + address + 2);
address += 32768;
//printf("lockbits at address=0x%08lx is 0x%01x\n", (unsigned long)0xFFc00000 - size + address + 2, *(bios + address + 2) );
- *(bios + address + 2) = bits;
+ writeb(bits, bios + address + 2);
address += 8192;
//printf("lockbits at address=0x%08lx is 0x%01x\n", (unsigned long)0xFFc00000 - size + address + 2, *(bios + address + 2) );
- *(bios + address + 2) = bits;
+ writeb(bits, bios + address + 2);
address += 8192;
//printf("lockbits at address=0x%08lx is 0x%01x\n", (unsigned long)0xFFc00000 - size + address + 2, *(bios + address + 2) );
- *(bios + address + 2) = bits;
+ writeb(bits, bios + address + 2);
return 0;
}
@@ -73,14 +73,14 @@ static __inline__ int erase_sector_49lfxxxc(volatile uint8_t *bios,
{
unsigned char status;
- *bios = SECTOR_ERASE;
- *(bios + address) = ERASE;
+ writeb(SECTOR_ERASE, bios);
+ writeb(ERASE, bios + address);
do {
- status = *bios;
+ status = readb(bios);
if (status & (STATUS_ESS | STATUS_BPS)) {
printf("sector erase FAILED at address=0x%08lx status=0x%01x\n", (unsigned long)bios + address, status);
- *bios = CLEAR_STATUS;
+ writeb(CLEAR_STATUS, bios);
return (-1);
}
} while (!(status & STATUS_WSMS));
@@ -96,7 +96,7 @@ static __inline__ int write_sector_49lfxxxc(volatile uint8_t *bios,
int i;
unsigned char status;
- *bios = CLEAR_STATUS;
+ writeb(CLEAR_STATUS, bios);
for (i = 0; i < page_size; i++) {
/* transfer data from source to destination */
if (*src == 0xFF) {
@@ -105,14 +105,14 @@ static __inline__ int write_sector_49lfxxxc(volatile uint8_t *bios,
continue;
}
/*issue AUTO PROGRAM command */
- *bios = AUTO_PGRM;
- *dst++ = *src++;
+ writeb(AUTO_PGRM, bios);
+ writeb(*src++, dst++);
do {
- status = *bios;
+ status = readb(bios);
if (status & (STATUS_ESS | STATUS_BPS)) {
printf("sector write FAILED at address=0x%08lx status=0x%01x\n", (unsigned long)dst, status);
- *bios = CLEAR_STATUS;
+ writeb(CLEAR_STATUS, bios);
return (-1);
}
} while (!(status & STATUS_WSMS));
@@ -127,13 +127,13 @@ int probe_49lfxxxc(struct flashchip *flash)
uint8_t id1, id2;
- *bios = RESET;
+ writeb(RESET, bios);
- *bios = READ_ID;
- id1 = *(volatile uint8_t *)bios;
- id2 = *(volatile uint8_t *)(bios + 0x01);
+ writeb(READ_ID, bios);
+ id1 = readb(bios);
+ id2 = readb(bios + 0x01);
- *bios = RESET;
+ writeb(RESET, bios);
printf_debug("%s: id1 0x%02x, id2 0x%02x\n", __FUNCTION__, id1, id2);
@@ -157,7 +157,7 @@ int erase_49lfxxxc(struct flashchip *flash)
if (erase_sector_49lfxxxc(bios, i) != 0)
return (-1);
- *bios = RESET;
+ writeb(RESET, bios);
return 0;
}
@@ -183,7 +183,7 @@ int write_49lfxxxc(struct flashchip *flash, uint8_t *buf)
}
printf("\n");
- *bios = RESET;
+ writeb(RESET, bios);
return 0;
}