summaryrefslogtreecommitdiff
path: root/util/flashrom/stm50flw0x0x.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/stm50flw0x0x.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/stm50flw0x0x.c')
-rw-r--r--util/flashrom/stm50flw0x0x.c64
1 files changed, 32 insertions, 32 deletions
diff --git a/util/flashrom/stm50flw0x0x.c b/util/flashrom/stm50flw0x0x.c
index c06bab9791..edb76cc594 100644
--- a/util/flashrom/stm50flw0x0x.c
+++ b/util/flashrom/stm50flw0x0x.c
@@ -33,9 +33,9 @@
void protect_stm50flw0x0x(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);
}
@@ -47,37 +47,37 @@ int probe_stm50flw0x0x(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);
myusec_delay(40);
/* 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\n", __FUNCTION__, largeid1,
@@ -96,21 +96,21 @@ static void wait_stm50flw0x0x(volatile uint8_t *bios)
uint8_t id1;
// id2;
- *bios = 0x70;
- if ((*bios & 0x80) == 0) { // it's busy
- while ((*bios & 0x80) == 0) ;
+ writeb(0x70, bios);
+ if ((readb(bios) & 0x80) == 0) { // it's busy
+ while ((readb(bios) & 0x80) == 0) ;
}
// put another command to get out of status register mode
- *bios = 0x90;
+ writeb(0x90, bios);
myusec_delay(10);
- id1 = *(volatile uint8_t *)bios;
+ id1 = readb(bios);
// this is needed to jam it out of "read id" mode
- *(volatile uint8_t *)(bios + 0x5555) = 0xAA;
- *(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
- *(volatile uint8_t *)(bios + 0x5555) = 0xF0;
+ writeb(0xAA, bios + 0x5555);
+ writeb(0x55, bios + 0x2AAA);
+ writeb(0xF0, bios + 0x5555);
}
/*
@@ -142,8 +142,8 @@ int unlock_block_stm50flw0x0x(struct flashchip *flash, int offset)
// unlock each 4k-sector
for (j = 0; j < 0x10000; j += 0x1000) {
printf_debug("unlocking at 0x%x\n", offset + j);
- *(flash_addr + offset + j) = unlock_sector;
- if (*(flash_addr + offset + j) != unlock_sector) {
+ writeb(unlock_sector, flash_addr + offset + j);
+ if (readb(flash_addr + offset + j) != unlock_sector) {
printf("Cannot unlock sector @ 0x%x\n",
offset + j);
return -1;
@@ -151,8 +151,8 @@ int unlock_block_stm50flw0x0x(struct flashchip *flash, int offset)
}
} else {
printf_debug("unlocking at 0x%x\n", offset);
- *(flash_addr + offset) = unlock_sector;
- if (*(flash_addr + offset) != unlock_sector) {
+ writeb(unlock_sector, flash_addr + offset);
+ if (readb(flash_addr + offset) != unlock_sector) {
printf("Cannot unlock sector @ 0x%x\n", offset);
return -1;
}
@@ -167,17 +167,17 @@ int erase_block_stm50flw0x0x(struct flashchip *flash, int offset)
int j;
// clear status register
- *bios = 0x50;
+ writeb(0x50, bios);
printf_debug("Erase at %p\n", bios);
// now start it
- *(volatile uint8_t *)(bios) = 0x20;
- *(volatile uint8_t *)(bios) = 0xd0;
+ writeb(0x20, bios);
+ writeb(0xd0, bios);
myusec_delay(10);
wait_stm50flw0x0x(flash->virtual_memory);
for (j = 0; j < flash->page_size; j++) {
- if (*(bios + j) != 0xFF) {
+ if (readb(bios + j) != 0xFF) {
printf("Erase failed at 0x%x\n", offset + j);
return -1;
}
@@ -197,8 +197,8 @@ int write_page_stm50flw0x0x(volatile uint8_t *bios, uint8_t *src,
/* transfer data from source to destination */
for (i = 0; i < page_size; i++) {
- *dst = 0x40;
- *dst++ = *src++;
+ writeb(0x40, dst);
+ writeb(*src++, dst++);
wait_stm50flw0x0x(bios);
}
@@ -210,7 +210,7 @@ int write_page_stm50flw0x0x(volatile uint8_t *bios, uint8_t *src,
dst = d;
src = s;
for (i = 0; i < page_size; i++) {
- if (*dst != *src) {
+ if (readb(dst) != *src) {
rc = -1;
break;
}