summaryrefslogtreecommitdiff
path: root/util/flashrom
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
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')
-rw-r--r--util/flashrom/82802ab.c54
-rw-r--r--util/flashrom/am29f040b.c44
-rw-r--r--util/flashrom/en29f002a.c40
-rw-r--r--util/flashrom/flash.h30
-rw-r--r--util/flashrom/jedec.c100
-rw-r--r--util/flashrom/m29f002.c32
-rw-r--r--util/flashrom/m29f400bt.c56
-rw-r--r--util/flashrom/mx29f002.c48
-rw-r--r--util/flashrom/pm49fl00x.c2
-rw-r--r--util/flashrom/sharplhf00l04.c58
-rw-r--r--util/flashrom/sst28sf040.c50
-rw-r--r--util/flashrom/sst49lfxxxc.c42
-rw-r--r--util/flashrom/sst_fwhub.c2
-rw-r--r--util/flashrom/stm50flw0x0x.c64
-rw-r--r--util/flashrom/w29ee011.c22
-rw-r--r--util/flashrom/w39v040c.c18
-rw-r--r--util/flashrom/w39v080fa.c52
17 files changed, 372 insertions, 342 deletions
diff --git a/util/flashrom/82802ab.c b/util/flashrom/82802ab.c
index 5e5b1a59ad..9bbee8d466 100644
--- a/util/flashrom/82802ab.c
+++ b/util/flashrom/82802ab.c
@@ -49,23 +49,23 @@ int probe_82802ab(struct flashchip *flash)
uint8_t id1, id2;
#if 0
- *(volatile uint8_t *)(bios + 0x5555) = 0xAA;
- *(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
- *(volatile uint8_t *)(bios + 0x5555) = 0x90;
+ writeb(0xAA, bios + 0x5555);
+ writeb(0x55, bios + 0x2AAA);
+ writeb(0x90, bios + 0x5555);
#endif
- *bios = 0xff;
+ writeb(0xff, bios);
myusec_delay(10);
- *bios = 0x90;
+ writeb(0x90, bios);
myusec_delay(10);
- id1 = *(volatile uint8_t *)bios;
- id2 = *(volatile uint8_t *)(bios + 0x01);
+ id1 = readb(bios);
+ id2 = readb(bios + 0x01);
/* Leave 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);
myusec_delay(10);
@@ -84,25 +84,25 @@ uint8_t wait_82802ab(volatile uint8_t *bios)
uint8_t status;
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) ;
}
- status = *bios;
+ status = readb(bios);
// put another command to get out of status register mode
- *bios = 0x90;
+ writeb(0x90, bios);
myusec_delay(10);
- id1 = *(volatile uint8_t *)bios;
- id2 = *(volatile uint8_t *)(bios + 0x01);
+ id1 = readb(bios);
+ id2 = readb(bios + 0x01);
// 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);
return status;
}
@@ -115,23 +115,23 @@ int erase_82802ab_block(struct flashchip *flash, int offset)
uint8_t status;
// clear status register
- *bios = 0x50;
+ writeb(0x50, bios);
//printf("Erase at %p\n", bios);
// clear write protect
//printf("write protect is at %p\n", (wrprotect));
//printf("write protect is 0x%x\n", *(wrprotect));
- *(wrprotect) = 0;
+ writeb(0, wrprotect);
//printf("write protect is 0x%x\n", *(wrprotect));
// now start it
- *(volatile uint8_t *)(bios) = 0x20;
- *(volatile uint8_t *)(bios) = 0xd0;
+ writeb(0x20, bios);
+ writeb(0xd0, bios);
myusec_delay(10);
// now let's see what the register is
status = wait_82802ab(flash->virtual_memory);
//print_82802ab_status(status);
for (j = 0; j < flash->page_size; j++) {
- if (*(bios + j) != 0xFF) {
+ if (readb(bios + j) != 0xFF) {
printf("BLOCK ERASE failed at 0x%x\n", offset);
return -1;
}
@@ -162,8 +162,8 @@ void write_page_82802ab(volatile uint8_t *bios, uint8_t *src,
for (i = 0; i < page_size; i++) {
/* transfer data from source to destination */
- *dst = 0x40;
- *dst++ = *src++;
+ writeb(0x40, dst);
+ writeb(*src++, dst++);
wait_82802ab(bios);
}
}
diff --git a/util/flashrom/am29f040b.c b/util/flashrom/am29f040b.c
index fbe435b888..78f417fe96 100644
--- a/util/flashrom/am29f040b.c
+++ b/util/flashrom/am29f040b.c
@@ -25,12 +25,12 @@
static __inline__ int erase_sector_29f040b(volatile uint8_t *bios,
unsigned long address)
{
- *(bios + 0x555) = 0xAA;
- *(bios + 0x2AA) = 0x55;
- *(bios + 0x555) = 0x80;
- *(bios + 0x555) = 0xAA;
- *(bios + 0x2AA) = 0x55;
- *(bios + address) = 0x30;
+ writeb(0xAA, bios + 0x555);
+ writeb(0x55, bios + 0x2AA);
+ writeb(0x80, bios + 0x555);
+ writeb(0xAA, bios + 0x555);
+ writeb(0x55, bios + 0x2AA);
+ writeb(0x30, bios + address);
sleep(2);
@@ -52,10 +52,10 @@ static __inline__ int write_sector_29f040b(volatile uint8_t *bios,
printf("0x%08lx", (unsigned long)dst -
(unsigned long)bios);
- *(bios + 0x555) = 0xAA;
- *(bios + 0x2AA) = 0x55;
- *(bios + 0x555) = 0xA0;
- *dst++ = *src++;
+ writeb(0xAA, bios + 0x555);
+ writeb(0x55, bios + 0x2AA);
+ writeb(0xA0, bios + 0x555);
+ writeb(*src++, dst++);
/* wait for Toggle bit ready */
toggle_ready_jedec(bios);
@@ -72,14 +72,14 @@ int probe_29f040b(struct flashchip *flash)
volatile uint8_t *bios = flash->virtual_memory;
uint8_t id1, id2;
- *(bios + 0x555) = 0xAA;
- *(bios + 0x2AA) = 0x55;
- *(bios + 0x555) = 0x90;
+ writeb(0xAA, bios + 0x555);
+ writeb(0x55, bios + 0x2AA);
+ writeb(0x90, bios + 0x555);
- id1 = *bios;
- id2 = *(bios + 0x01);
+ id1 = readb(bios);
+ id2 = readb(bios + 0x01);
- *bios = 0xF0;
+ writeb(0xF0, bios);
myusec_delay(10);
@@ -94,12 +94,12 @@ int erase_29f040b(struct flashchip *flash)
{
volatile uint8_t *bios = flash->virtual_memory;
- *(bios + 0x555) = 0xAA;
- *(bios + 0x2AA) = 0x55;
- *(bios + 0x555) = 0x80;
- *(bios + 0x555) = 0xAA;
- *(bios + 0x2AA) = 0x55;
- *(bios + 0x555) = 0x10;
+ writeb(0xAA, bios + 0x555);
+ writeb(0x55, bios + 0x2AA);
+ writeb(0x80, bios + 0x555);
+ writeb(0xAA, bios + 0x555);
+ writeb(0x55, bios + 0x2AA);
+ writeb(0x10, bios + 0x555);
myusec_delay(10);
toggle_ready_jedec(bios);
diff --git a/util/flashrom/en29f002a.c b/util/flashrom/en29f002a.c
index c70b37b115..41dac7f64c 100644
--- a/util/flashrom/en29f002a.c
+++ b/util/flashrom/en29f002a.c
@@ -35,19 +35,19 @@ int probe_en29f512(struct flashchip *flash)
volatile uint8_t *bios = flash->virtual_memory;
uint8_t id1, id2;
- *(volatile uint8_t *)(bios + 0x555) = 0xAA;
- *(volatile uint8_t *)(bios + 0x2AA) = 0x55;
- *(volatile uint8_t *)(bios + 0x555) = 0x90;
+ writeb(0xAA, bios + 0x555);
+ writeb(0x55, bios + 0x2AA);
+ writeb(0x90, bios + 0x555);
myusec_delay(10);
- id1 = *(volatile uint8_t *)(bios + 0x100);
- id2 = *(volatile uint8_t *)(bios + 0x101);
+ id1 = readb(bios + 0x100);
+ id2 = readb(bios + 0x101);
/* exit by writing F0 anywhere? or the code below */
- *(volatile uint8_t *)(bios + 0x555) = 0xAA;
- *(volatile uint8_t *)(bios + 0x2AA) = 0x55;
- *(volatile uint8_t *)(bios + 0x555) = 0xF0;
+ writeb(0xAA, bios + 0x555);
+ writeb(0x55, bios + 0x2AA);
+ writeb(0xF0, bios + 0x555);
printf_debug("%s: id1 0x%02x, id2 0x%02x\n", __FUNCTION__, id1, id2);
@@ -68,19 +68,19 @@ int probe_en29f002a(struct flashchip *flash)
volatile uint8_t *bios = flash->virtual_memory;
uint8_t id1, id2;
- *(volatile uint8_t *)(bios + 0x555) = 0xAA;
- *(volatile uint8_t *)(bios + 0xAAA) = 0x55;
- *(volatile uint8_t *)(bios + 0x555) = 0x90;
+ writeb(0xAA, bios + 0x555);
+ writeb(0x55, bios + 0xAAA);
+ writeb(0x90, bios + 0x555);
myusec_delay(10);
- id1 = *(volatile uint8_t *)(bios + 0x100);
- id2 = *(volatile uint8_t *)(bios + 0x101);
+ id1 = readb(bios + 0x100);
+ id2 = readb(bios + 0x101);
/* exit by writing F0 anywhere? or the code below */
- *(volatile uint8_t *)(bios + 0x555) = 0xAA;
- *(volatile uint8_t *)(bios + 0xAAA) = 0x55;
- *(volatile uint8_t *)(bios + 0x555) = 0xF0;
+ writeb(0xAA, bios + 0x555);
+ writeb(0x55, bios + 0xAAA);
+ writeb(0xF0, bios + 0x555);
printf_debug("%s: id1 0x%x, id2 0x%x\n", __FUNCTION__, id1, id2);
@@ -107,10 +107,10 @@ int write_en29f002a(struct flashchip *flash, uint8_t *buf)
/* write to the sector */
if ((i & 0xfff) == 0)
printf("address: 0x%08lx", (unsigned long)i);
- *(bios + 0x5555) = 0xAA;
- *(bios + 0x2AAA) = 0x55;
- *(bios + 0x5555) = 0xA0;
- *dst++ = *buf++;
+ writeb(0xAA, bios + 0x5555);
+ writeb(0x55, bios + 0x2AAA);
+ writeb(0xA0, bios + 0x5555);
+ writeb(*buf++, dst++);
/* wait for Toggle bit ready */
toggle_ready_jedec(dst);
diff --git a/util/flashrom/flash.h b/util/flashrom/flash.h
index 3985c600db..b33e1330c4 100644
--- a/util/flashrom/flash.h
+++ b/util/flashrom/flash.h
@@ -58,6 +58,36 @@
#define INL inl
#endif
+static inline void writeb(uint8_t b, volatile void *addr)
+{
+ *(volatile uint8_t *) addr = b;
+}
+
+static inline void writew(uint16_t b, volatile void *addr)
+{
+ *(volatile uint16_t *) addr = b;
+}
+
+static inline void writel(uint32_t b, volatile void *addr)
+{
+ *(volatile uint32_t *) addr = b;
+}
+
+static inline uint8_t readb(const volatile void *addr)
+{
+ return *(volatile uint8_t *) addr;
+}
+
+static inline uint16_t readw(const volatile void *addr)
+{
+ return *(volatile uint16_t *) addr;
+}
+
+static inline uint32_t readl(const volatile void *addr)
+{
+ return *(volatile uint32_t *) addr;
+}
+
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
struct flashchip {
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;
}
diff --git a/util/flashrom/m29f002.c b/util/flashrom/m29f002.c
index 8afef796ee..f806a2d15a 100644
--- a/util/flashrom/m29f002.c
+++ b/util/flashrom/m29f002.c
@@ -22,12 +22,12 @@
int erase_m29f002(struct flashchip *flash) {
volatile uint8_t *bios = flash->virtual_memory;
- *(volatile uint8_t *)(bios + 0x555) = 0xaa;
- *(volatile uint8_t *)(bios + 0xaaa) = 0x55;
- *(volatile uint8_t *)(bios + 0x555) = 0x80;
- *(volatile uint8_t *)(bios + 0x555) = 0xaa;
- *(volatile uint8_t *)(bios + 0xaaa) = 0x55;
- *(volatile uint8_t *)(bios + 0x555) = 0x10;
+ writeb(0xaa, bios + 0x555);
+ writeb(0x55, bios + 0xaaa);
+ writeb(0x80, bios + 0x555);
+ writeb(0xaa, bios + 0x555);
+ writeb(0x55, bios + 0xaaa);
+ writeb(0x10, bios + 0x555);
myusec_delay(10);
toggle_ready_jedec(bios);
return 0;
@@ -35,21 +35,21 @@ int erase_m29f002(struct flashchip *flash) {
static void rewrite_block(volatile uint8_t *bios, uint8_t *src, volatile uint8_t *dst, int size) {
/* erase */
- *(volatile uint8_t *)(bios + 0x555) = 0xaa;
- *(volatile uint8_t *)(bios + 0xaaa) = 0x55;
- *(volatile uint8_t *)(bios + 0x555) = 0x80;
- *(volatile uint8_t *)(bios + 0x555) = 0xaa;
- *(volatile uint8_t *)(bios + 0xaaa) = 0x55;
- *dst = 0x30;
+ writeb(0xaa, bios + 0x555);
+ writeb(0x55, bios + 0xaaa);
+ writeb(0x80, bios + 0x555);
+ writeb(0xaa, bios + 0x555);
+ writeb(0x55, bios + 0xaaa);
+ writeb(0x30, dst);
myusec_delay(10);
toggle_ready_jedec(bios);
/* program */
while (size--) {
- *(volatile uint8_t *)(bios + 0x555) = 0xaa;
- *(volatile uint8_t *)(bios + 0xaaa) = 0x55;
- *(volatile uint8_t *)(bios + 0x555) = 0xa0;
- *dst = *src;
+ writeb(0xaa, bios + 0x555);
+ writeb(0x55, bios + 0xaaa);
+ writeb(0xa0, bios + 0x555);
+ writeb(*src, dst);
toggle_ready_jedec(dst);
dst++;
src++;
diff --git a/util/flashrom/m29f400bt.c b/util/flashrom/m29f400bt.c
index d0b040de2d..2ca72e4e85 100644
--- a/util/flashrom/m29f400bt.c
+++ b/util/flashrom/m29f400bt.c
@@ -22,9 +22,9 @@
void protect_m29f400bt(volatile uint8_t *bios)
{
- *(volatile uint8_t *)(bios + 0xAAA) = 0xAA;
- *(volatile uint8_t *)(bios + 0x555) = 0x55;
- *(volatile uint8_t *)(bios + 0xAAA) = 0xA0;
+ writeb(0xAA, bios + 0xAAA);
+ writeb(0x55, bios + 0x555);
+ writeb(0xA0, bios + 0xAAA);
usleep(200);
}
@@ -35,18 +35,18 @@ void write_page_m29f400bt(volatile uint8_t *bios, uint8_t *src,
int i;
for (i = 0; i < page_size; i++) {
- *(volatile uint8_t *)(bios + 0xAAA) = 0xAA;
- *(volatile uint8_t *)(bios + 0x555) = 0x55;
- *(volatile uint8_t *)(bios + 0xAAA) = 0xA0;
+ writeb(0xAA, bios + 0xAAA);
+ writeb(0x55, bios + 0x555);
+ writeb(0xA0, bios + 0xAAA);
/* transfer data from source to destination */
- *dst = *src;
+ writeb(*src, dst);
//*(volatile char *) (bios) = 0xF0;
//usleep(5);
toggle_ready_jedec(dst);
printf
("Value in the flash at address %p = %#x, want %#x\n",
- (uint8_t *) (dst - bios), *dst, *src);
+ (uint8_t *) (dst - bios), readb(dst), *src);
dst++;
src++;
}
@@ -57,21 +57,21 @@ int probe_m29f400bt(struct flashchip *flash)
volatile uint8_t *bios = flash->virtual_memory;
uint8_t id1, id2;
- *(volatile uint8_t *)(bios + 0xAAA) = 0xAA;
- *(volatile uint8_t *)(bios + 0x555) = 0x55;
- *(volatile uint8_t *)(bios + 0xAAA) = 0x90;
+ writeb(0xAA, bios + 0xAAA);
+ writeb(0x55, bios + 0x555);
+ writeb(0x90, bios + 0xAAA);
myusec_delay(10);
- id1 = *(volatile uint8_t *)bios;
+ id1 = readb(bios);
/* The data sheet says id2 is at (bios + 0x01) and id2 listed in
* flash.h does not match. It should be possible to use JEDEC probe.
*/
- id2 = *(volatile uint8_t *)(bios + 0x02);
+ id2 = readb(bios + 0x02);
- *(volatile uint8_t *)(bios + 0xAAA) = 0xAA;
- *(volatile uint8_t *)(bios + 0x555) = 0x55;
- *(volatile uint8_t *)(bios + 0xAAA) = 0xF0;
+ writeb(0xAA, bios + 0xAAA);
+ writeb(0x55, bios + 0x555);
+ writeb(0xF0, bios + 0xAAA);
myusec_delay(10);
@@ -87,13 +87,13 @@ int erase_m29f400bt(struct flashchip *flash)
{
volatile uint8_t *bios = flash->virtual_memory;
- *(volatile uint8_t *)(bios + 0xAAA) = 0xAA;
- *(volatile uint8_t *)(bios + 0x555) = 0x55;
- *(volatile uint8_t *)(bios + 0xAAA) = 0x80;
+ writeb(0xAA, bios + 0xAAA);
+ writeb(0x55, bios + 0x555);
+ writeb(0x80, bios + 0xAAA);
- *(volatile uint8_t *)(bios + 0xAAA) = 0xAA;
- *(volatile uint8_t *)(bios + 0x555) = 0x55;
- *(volatile uint8_t *)(bios + 0xAAA) = 0x10;
+ writeb(0xAA, bios + 0xAAA);
+ writeb(0x55, bios + 0x555);
+ writeb(0x10, bios + 0xAAA);
myusec_delay(10);
toggle_ready_jedec(bios);
@@ -104,14 +104,14 @@ int erase_m29f400bt(struct flashchip *flash)
int block_erase_m29f400bt(volatile uint8_t *bios, volatile uint8_t *dst)
{
- *(volatile uint8_t *)(bios + 0xAAA) = 0xAA;
- *(volatile uint8_t *)(bios + 0x555) = 0x55;
- *(volatile uint8_t *)(bios + 0xAAA) = 0x80;
+ writeb(0xAA, bios + 0xAAA);
+ writeb(0x55, bios + 0x555);
+ writeb(0x80, bios + 0xAAA);
- *(volatile uint8_t *)(bios + 0xAAA) = 0xAA;
- *(volatile uint8_t *)(bios + 0x555) = 0x55;
+ writeb(0xAA, bios + 0xAAA);
+ writeb(0x55, bios + 0x555);
//*(volatile uint8_t *) (bios + 0xAAA) = 0x10;
- *dst = 0x30;
+ writeb(0x30, dst);
myusec_delay(10);
toggle_ready_jedec(bios);
diff --git a/util/flashrom/mx29f002.c b/util/flashrom/mx29f002.c
index 30adab1d72..0e3f5620cd 100644
--- a/util/flashrom/mx29f002.c
+++ b/util/flashrom/mx29f002.c
@@ -27,14 +27,14 @@ int probe_29f002(struct flashchip *flash)
volatile uint8_t *bios = flash->virtual_memory;
uint8_t id1, id2;
- *(bios + 0x5555) = 0xAA;
- *(bios + 0x2AAA) = 0x55;
- *(bios + 0x5555) = 0x90;
+ writeb(0xAA, bios + 0x5555);
+ writeb(0x55, bios + 0x2AAA);
+ writeb(0x90, bios + 0x5555);
- id1 = *(volatile uint8_t *)bios;
- id2 = *(volatile uint8_t *)(bios + 0x01);
+ id1 = readb(bios);
+ id2 = readb(bios + 0x01);
- *bios = 0xF0;
+ writeb(0xF0, bios);
myusec_delay(10);
@@ -49,13 +49,13 @@ int erase_29f002(struct flashchip *flash)
{
volatile uint8_t *bios = flash->virtual_memory;
- *(bios + 0x555) = 0xF0;
- *(bios + 0x555) = 0xAA;
- *(bios + 0x2AA) = 0x55;
- *(bios + 0x555) = 0x80;
- *(bios + 0x555) = 0xAA;
- *(bios + 0x2AA) = 0x55;
- *(bios + 0x555) = 0x10;
+ writeb(0xF0, bios + 0x555);
+ writeb(0xAA, bios + 0x555);
+ writeb(0x55, bios + 0x2AA);
+ writeb(0x80, bios + 0x555);
+ writeb(0xAA, bios + 0x555);
+ writeb(0x55, bios + 0x2AA);
+ writeb(0x10, bios + 0x555);
myusec_delay(100);
toggle_ready_jedec(bios);
@@ -65,12 +65,12 @@ int erase_29f002(struct flashchip *flash)
#if 0
toggle_ready_jedec(bios);
- *(bios + 0x0ffff) = 0x30;
- *(bios + 0x1ffff) = 0x30;
- *(bios + 0x2ffff) = 0x30;
- *(bios + 0x37fff) = 0x30;
- *(bios + 0x39fff) = 0x30;
- *(bios + 0x3bfff) = 0x30;
+ writeb(0x30, bios + 0x0ffff);
+ writeb(0x30, bios + 0x1ffff);
+ writeb(0x30, bios + 0x2ffff);
+ writeb(0x30, bios + 0x37fff);
+ writeb(0x30, bios + 0x39fff);
+ writeb(0x30, bios + 0x3bfff);
#endif
return 0;
@@ -83,7 +83,7 @@ int write_29f002(struct flashchip *flash, uint8_t *buf)
volatile uint8_t *bios = flash->virtual_memory;
volatile uint8_t *dst = bios;
- *bios = 0xF0;
+ writeb(0xF0, bios);
myusec_delay(10);
erase_29f002(flash);
//*bios = 0xF0;
@@ -93,10 +93,10 @@ int write_29f002(struct flashchip *flash, uint8_t *buf)
/* write to the sector */
if ((i & 0xfff) == 0)
printf("address: 0x%08lx", (unsigned long)i);
- *(bios + 0x5555) = 0xAA;
- *(bios + 0x2AAA) = 0x55;
- *(bios + 0x5555) = 0xA0;
- *dst++ = *buf++;
+ writeb(0xAA, bios + 0x5555);
+ writeb(0x55, bios + 0x2AAA);
+ writeb(0xA0, bios + 0x5555);
+ writeb(*buf++, dst++);
/* wait for Toggle bit ready */
toggle_ready_jedec(dst);
diff --git a/util/flashrom/pm49fl00x.c b/util/flashrom/pm49fl00x.c
index fe8b9741b4..e2ca7b6660 100644
--- a/util/flashrom/pm49fl00x.c
+++ b/util/flashrom/pm49fl00x.c
@@ -35,7 +35,7 @@ void write_lockbits_49fl00x(volatile uint8_t *bios, int size,
if (block_size == 16384 && i % 2)
continue;
- *(bios + (i * block_size) + 2) = bits;
+ writeb(bits, bios + (i * block_size) + 2);
}
}
diff --git a/util/flashrom/sharplhf00l04.c b/util/flashrom/sharplhf00l04.c
index 7db14fe4f4..06a14ef964 100644
--- a/util/flashrom/sharplhf00l04.c
+++ b/util/flashrom/sharplhf00l04.c
@@ -41,23 +41,23 @@ int probe_lhf00l04(struct flashchip *flash)
#if 0
/* Enter ID mode */
- *(volatile uint8_t *)(bios + 0x5555) = 0xAA;
- *(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
- *(volatile uint8_t *)(bios + 0x5555) = 0x90;
+ writeb(0xAA, bios + 0x5555);
+ writeb(0x55, bios + 0x2AAA);
+ writeb(0x90, bios + 0x5555);
#endif
- *bios = 0xff;
+ writeb(0xff, bios);
myusec_delay(10);
- *bios = 0x90;
+ writeb(0x90, bios);
myusec_delay(10);
- id1 = *(volatile uint8_t *)bios;
- id2 = *(volatile uint8_t *)(bios + 0x01);
+ id1 = readb(bios);
+ id2 = readb(bios + 0x01);
/* Leave 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);
myusec_delay(10);
@@ -76,25 +76,25 @@ uint8_t wait_lhf00l04(volatile uint8_t *bios)
uint8_t status;
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) ;
}
- status = *bios;
+ status = readb(bios);
// put another command to get out of status register mode
- *bios = 0x90;
+ writeb(0x90, bios);
myusec_delay(10);
- id1 = *(volatile uint8_t *)bios;
- id2 = *(volatile uint8_t *)(bios + 0x01);
+ id1 = readb(bios);
+ id2 = readb(bios + 0x01);
// 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);
return status;
}
@@ -106,19 +106,19 @@ int erase_lhf00l04_block(struct flashchip *flash, int offset)
uint8_t status;
// clear status register
- *bios = 0x50;
+ writeb(0x50, bios);
printf("Erase at %p\n", bios);
status = wait_lhf00l04(flash->virtual_memory);
print_lhf00l04_status(status);
// clear write protect
printf("write protect is at %p\n", (wrprotect));
- printf("write protect is 0x%x\n", *(wrprotect));
- *(wrprotect) = 0;
- printf("write protect is 0x%x\n", *(wrprotect));
+ printf("write protect is 0x%x\n", readb(wrprotect));
+ writeb(0, wrprotect);
+ printf("write protect is 0x%x\n", readb(wrprotect));
// now start it
- *(volatile uint8_t *)(bios) = 0x20;
- *(volatile uint8_t *)(bios) = 0xd0;
+ writeb(0x20, bios);
+ writeb(0xd0, bios);
myusec_delay(10);
// now let's see what the register is
status = wait_lhf00l04(flash->virtual_memory);
@@ -149,8 +149,8 @@ void write_page_lhf00l04(volatile uint8_t *bios, uint8_t *src,
for (i = 0; i < page_size; i++) {
/* transfer data from source to destination */
- *dst = 0x40;
- *dst++ = *src++;
+ writeb(0x40, dst);
+ writeb(*src++, dst++);
wait_lhf00l04(bios);
}
}
@@ -163,7 +163,7 @@ int write_lhf00l04(struct flashchip *flash, uint8_t *buf)
volatile uint8_t *bios = flash->virtual_memory;
erase_lhf00l04(flash);
- if (*bios != 0xff) {
+ if (readb(bios) != 0xff) {
printf("ERASE FAILED!\n");
return -1;
}
diff --git a/util/flashrom/sst28sf040.c b/util/flashrom/sst28sf040.c
index 89be9d8e81..ee8ee80990 100644
--- a/util/flashrom/sst28sf040.c
+++ b/util/flashrom/sst28sf040.c
@@ -35,13 +35,13 @@ static __inline__ void protect_28sf040(volatile uint8_t *bios)
/* ask compiler not to optimize this */
volatile uint8_t tmp;
- tmp = *(volatile uint8_t *)(bios + 0x1823);
- tmp = *(volatile uint8_t *)(bios + 0x1820);
- tmp = *(volatile uint8_t *)(bios + 0x1822);
- tmp = *(volatile uint8_t *)(bios + 0x0418);
- tmp = *(volatile uint8_t *)(bios + 0x041B);
- tmp = *(volatile uint8_t *)(bios + 0x0419);
- tmp = *(volatile uint8_t *)(bios + 0x040A);
+ tmp = readb(bios + 0x1823);
+ tmp = readb(bios + 0x1820);
+ tmp = readb(bios + 0x1822);
+ tmp = readb(bios + 0x0418);
+ tmp = readb(bios + 0x041B);
+ tmp = readb(bios + 0x0419);
+ tmp = readb(bios + 0x040A);
}
static __inline__ void unprotect_28sf040(volatile uint8_t *bios)
@@ -49,20 +49,20 @@ static __inline__ void unprotect_28sf040(volatile uint8_t *bios)
/* ask compiler not to optimize this */
volatile uint8_t tmp;
- tmp = *(volatile uint8_t *)(bios + 0x1823);
- tmp = *(volatile uint8_t *)(bios + 0x1820);
- tmp = *(volatile uint8_t *)(bios + 0x1822);
- tmp = *(volatile uint8_t *)(bios + 0x0418);
- tmp = *(volatile uint8_t *)(bios + 0x041B);
- tmp = *(volatile uint8_t *)(bios + 0x0419);
- tmp = *(volatile uint8_t *)(bios + 0x041A);
+ tmp = readb(bios + 0x1823);
+ tmp = readb(bios + 0x1820);
+ tmp = readb(bios + 0x1822);
+ tmp = readb(bios + 0x0418);
+ tmp = readb(bios + 0x041B);
+ tmp = readb(bios + 0x0419);
+ tmp = readb(bios + 0x041A);
}
static __inline__ int erase_sector_28sf040(volatile uint8_t *bios,
unsigned long address)
{
- *bios = AUTO_PG_ERASE1;
- *(bios + address) = AUTO_PG_ERASE2;
+ writeb(AUTO_PG_ERASE1, bios);
+ writeb(AUTO_PG_ERASE2, bios + address);
/* wait for Toggle bit ready */
toggle_ready_jedec(bios);
@@ -85,8 +85,8 @@ static __inline__ int write_sector_28sf040(volatile uint8_t *bios,
continue;
}
/*issue AUTO PROGRAM command */
- *dst = AUTO_PGRM;
- *dst++ = *src++;
+ writeb(AUTO_PGRM, dst);
+ writeb(*src++, dst++);
/* wait for Toggle bit ready */
toggle_ready_jedec(bios);
@@ -100,16 +100,16 @@ int probe_28sf040(struct flashchip *flash)
volatile uint8_t *bios = flash->virtual_memory;
uint8_t id1, id2;
- *bios = RESET;
+ writeb(RESET, bios);
myusec_delay(10);
- *bios = READ_ID;
+ writeb(READ_ID, bios);
myusec_delay(10);
- id1 = *(volatile uint8_t *)bios;
+ id1 = readb(bios);
myusec_delay(10);
- id2 = *(volatile uint8_t *)(bios + 0x01);
+ id2 = readb(bios + 0x01);
- *bios = RESET;
+ writeb(RESET, bios);
myusec_delay(10);
printf_debug("%s: id1 0x%02x, id2 0x%02x\n", __FUNCTION__, id1, id2);
@@ -124,8 +124,8 @@ int erase_28sf040(struct flashchip *flash)
volatile uint8_t *bios = flash->virtual_memory;
unprotect_28sf040(bios);
- *bios = CHIP_ERASE;
- *bios = CHIP_ERASE;
+ writeb(CHIP_ERASE, bios);
+ writeb(CHIP_ERASE, bios);
protect_28sf040(bios);
myusec_delay(10);
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;
}
diff --git a/util/flashrom/sst_fwhub.c b/util/flashrom/sst_fwhub.c
index 455107e01a..2c2992e682 100644
--- a/util/flashrom/sst_fwhub.c
+++ b/util/flashrom/sst_fwhub.c
@@ -51,7 +51,7 @@ int erase_sst_fwhub_block(struct flashchip *flash, int offset)
volatile uint8_t *wrprotect = flash->virtual_registers + offset + 2;
// clear write protect
- *(wrprotect) = 0;
+ writeb(0, wrprotect);
erase_block_jedec(flash->virtual_memory, offset);
toggle_ready_jedec(flash->virtual_memory);
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;
}
diff --git a/util/flashrom/w29ee011.c b/util/flashrom/w29ee011.c
index fa3aa7ccc0..80a4e66ad9 100644
--- a/util/flashrom/w29ee011.c
+++ b/util/flashrom/w29ee011.c
@@ -37,29 +37,29 @@ int probe_w29ee011(struct flashchip *flash)
}
/* 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) = 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) = 0x60;
+ writeb(0x60, bios + 0x5555);
myusec_delay(10);
/* Read product ID */
- id1 = *(volatile uint8_t *)bios;
- id2 = *(volatile uint8_t *)(bios + 0x01);
+ id1 = readb(bios);
+ id2 = readb(bios + 0x01);
/* 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(10);
printf_debug("%s: id1 0x%02x, id2 0x%02x\n", __FUNCTION__, id1, id2);
diff --git a/util/flashrom/w39v040c.c b/util/flashrom/w39v040c.c
index 37549d7b73..3a0f430295 100644
--- a/util/flashrom/w39v040c.c
+++ b/util/flashrom/w39v040c.c
@@ -26,22 +26,22 @@ int probe_w39v040c(struct flashchip *flash)
volatile uint8_t *bios = flash->virtual_memory;
uint8_t id1, id2, lock;
- *(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(10);
- id1 = *(volatile uint8_t *)bios;
- id2 = *(volatile uint8_t *)(bios + 1);
- lock = *(volatile uint8_t *)(bios + 0xfff2);
+ id1 = readb(bios);
+ id2 = readb(bios + 1);
+ lock = readb(bios + 0xfff2);
- *(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", __func__, id1, id2);
diff --git a/util/flashrom/w39v080fa.c b/util/flashrom/w39v080fa.c
index 66534ce911..6278fbc43e 100644
--- a/util/flashrom/w39v080fa.c
+++ b/util/flashrom/w39v080fa.c
@@ -27,19 +27,19 @@ int probe_winbond_fwhub(struct flashchip *flash)
uint8_t vid, did;
/* Product Identification Entry */
- *(volatile uint8_t *)(bios + 0x5555) = 0xAA;
- *(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
- *(volatile uint8_t *)(bios + 0x5555) = 0x90;
+ writeb(0xAA, bios + 0x5555);
+ writeb(0x55, bios + 0x2AAA);
+ writeb(0x90, bios + 0x5555);
myusec_delay(10);
/* Read product ID */
- vid = *(volatile uint8_t *)bios;
- did = *(volatile uint8_t *)(bios + 0x01);
+ vid = readb(bios);
+ did = readb(bios + 0x01);
/* Product Identifixation Exit */
- *(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);
myusec_delay(10);
printf_debug("%s: vid 0x%x, did 0x%x\n", __FUNCTION__, vid, did);
@@ -58,16 +58,16 @@ static int unlock_block_winbond_fwhub(struct flashchip *flash, int offset)
uint8_t locking;
printf_debug("Trying to unlock block @0x%08x = 0x%02x\n", offset,
- *wrprotect);
+ readb(wrprotect));
- locking = *wrprotect;
+ locking = readb(wrprotect);
switch (locking & 0x7) {
case 0:
printf_debug("Full Access.\n");
return 0;
case 1:
printf_debug("Write Lock (Default State).\n");
- *wrprotect = 0;
+ writeb(0, wrprotect);
return 0;
case 2:
printf_debug("Locked Open (Full Access, Lock Down).\n");
@@ -77,11 +77,11 @@ static int unlock_block_winbond_fwhub(struct flashchip *flash, int offset)
return -1;
case 4:
printf_debug("Read Lock.\n");
- *wrprotect = 0;
+ writeb(0, wrprotect);
return 0;
case 5:
printf_debug("Read/Write Lock.\n");
- *wrprotect = 0;
+ writeb(0, wrprotect);
return 0;
case 6:
fprintf(stderr, "Error: Read Lock, Locked Down.\n");
@@ -106,18 +106,18 @@ int unlock_winbond_fwhub(struct flashchip *flash)
*/
/* Product Identification Entry */
- *(volatile uint8_t *)(bios + 0x5555) = 0xAA;
- *(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
- *(volatile uint8_t *)(bios + 0x5555) = 0x90;
+ writeb(0xAA, bios + 0x5555);
+ writeb(0x55, bios + 0x2AAA);
+ writeb(0x90, bios + 0x5555);
myusec_delay(10);
/* Read Hardware Lock Bits */
- locking = *(volatile uint8_t *)(bios + 0xffff2);
+ locking = readb(bios + 0xffff2);
/* Product Identification Exit */
- *(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);
myusec_delay(10);
printf_debug("Lockout bits:\n");
@@ -151,13 +151,13 @@ static int erase_sector_winbond_fwhub(volatile uint8_t *bios,
printf("0x%08x\b\b\b\b\b\b\b\b\b\b", sector);
/* Sector Erase */
- *(volatile uint8_t *)(bios + 0x5555) = 0xAA;
- *(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
- *(volatile uint8_t *)(bios + 0x5555) = 0x80;
+ writeb(0xAA, bios + 0x5555);
+ writeb(0x55, bios + 0x2AAA);
+ writeb(0x80, bios + 0x5555);
- *(volatile uint8_t *)(bios + 0x5555) = 0xAA;
- *(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
- *(volatile uint8_t *)(bios + sector) = 0x30;
+ writeb(0xAA, bios + 0x5555);
+ writeb(0x55, bios + 0x2AAA);
+ writeb(0x30, bios + sector);
/* wait for Toggle bit ready */
toggle_ready_jedec(bios);