On 05.03.2009 15:45, FENG Yu Ning wrote:
Carl-Daniel Hailfinger wrote:
This patch has the additional advantage of removing lots of unnecessary casts to volatile uint8_t * and now-superfluous parentheses which caused poor readability.
Generally, patched code looks much nicer. As a trade-off, some code loses symmetry, e.g.
*dst = *src;
writeb(*src, dst);
True.
I used the semantic patcher Coccinelle to create this patch.
That is interesting. I have a new tool to learn.
The patch is
Acked-by: FENG Yu Ning fengyuning1984@gmail.com
Thanks!
I'll commit shortly. Below is the updated patch which performs the conversion completely. And the semantic patch shrunk quite a bit. @@ 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
Index: flashrom-inband_chipaccess_helper_functions/flash.h =================================================================== --- flashrom-inband_chipaccess_helper_functions/flash.h (Revision 3970) +++ flashrom-inband_chipaccess_helper_functions/flash.h (Arbeitskopie) @@ -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 { Index: flashrom-inband_chipaccess_helper_functions/pm49fl00x.c =================================================================== --- flashrom-inband_chipaccess_helper_functions/pm49fl00x.c (Revision 3970) +++ flashrom-inband_chipaccess_helper_functions/pm49fl00x.c (Arbeitskopie) @@ -35,7 +35,7 @@ if (block_size == 16384 && i % 2) continue;
- *(bios + (i * block_size) + 2) = bits; + writeb(bits, bios + (i * block_size) + 2); } }
Index: flashrom-inband_chipaccess_helper_functions/en29f002a.c =================================================================== --- flashrom-inband_chipaccess_helper_functions/en29f002a.c (Revision 3970) +++ flashrom-inband_chipaccess_helper_functions/en29f002a.c (Arbeitskopie) @@ -35,19 +35,19 @@ 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 @@ 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 @@ /* 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); Index: flashrom-inband_chipaccess_helper_functions/jedec.c =================================================================== --- flashrom-inband_chipaccess_helper_functions/jedec.c (Revision 3970) +++ flashrom-inband_chipaccess_helper_functions/jedec.c (Arbeitskopie) @@ -40,10 +40,10 @@ 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 @@ data &= 0x80;
while (i++ < 0xFFFFFFF) { - tmp = *dst & 0x80; + tmp = readb(dst) & 0x80; if (tmp == data) { break; } @@ -68,21 +68,21 @@
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 @@ 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 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_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 @@ 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 @@
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 @@ 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 @@
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; }
Index: flashrom-inband_chipaccess_helper_functions/w29ee011.c =================================================================== --- flashrom-inband_chipaccess_helper_functions/w29ee011.c (Revision 3970) +++ flashrom-inband_chipaccess_helper_functions/w29ee011.c (Arbeitskopie) @@ -37,29 +37,29 @@ }
/* 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); Index: flashrom-inband_chipaccess_helper_functions/sst49lfxxxc.c =================================================================== --- flashrom-inband_chipaccess_helper_functions/sst49lfxxxc.c (Revision 3970) +++ flashrom-inband_chipaccess_helper_functions/sst49lfxxxc.c (Arbeitskopie) @@ -50,20 +50,20 @@ //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 @@ { 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 @@ 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 @@ 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 @@
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 @@ if (erase_sector_49lfxxxc(bios, i) != 0) return (-1);
- *bios = RESET; + writeb(RESET, bios);
return 0; } @@ -183,7 +183,7 @@ } printf("\n");
- *bios = RESET; + writeb(RESET, bios);
return 0; } Index: flashrom-inband_chipaccess_helper_functions/sharplhf00l04.c =================================================================== --- flashrom-inband_chipaccess_helper_functions/sharplhf00l04.c (Revision 3970) +++ flashrom-inband_chipaccess_helper_functions/sharplhf00l04.c (Arbeitskopie) @@ -41,23 +41,23 @@
#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 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 @@ 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 @@
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 @@ volatile uint8_t *bios = flash->virtual_memory;
erase_lhf00l04(flash); - if (*bios != 0xff) { + if (readb(bios) != 0xff) { printf("ERASE FAILED!\n"); return -1; } Index: flashrom-inband_chipaccess_helper_functions/w39v040c.c =================================================================== --- flashrom-inband_chipaccess_helper_functions/w39v040c.c (Revision 3970) +++ flashrom-inband_chipaccess_helper_functions/w39v040c.c (Arbeitskopie) @@ -26,22 +26,22 @@ 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); Index: flashrom-inband_chipaccess_helper_functions/m29f002.c =================================================================== --- flashrom-inband_chipaccess_helper_functions/m29f002.c (Revision 3970) +++ flashrom-inband_chipaccess_helper_functions/m29f002.c (Arbeitskopie) @@ -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 @@
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++; Index: flashrom-inband_chipaccess_helper_functions/sst28sf040.c =================================================================== --- flashrom-inband_chipaccess_helper_functions/sst28sf040.c (Revision 3970) +++ flashrom-inband_chipaccess_helper_functions/sst28sf040.c (Arbeitskopie) @@ -35,13 +35,13 @@ /* 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 @@ /* 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 @@ 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 @@ 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 @@ 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); Index: flashrom-inband_chipaccess_helper_functions/stm50flw0x0x.c =================================================================== --- flashrom-inband_chipaccess_helper_functions/stm50flw0x0x.c (Revision 3970) +++ flashrom-inband_chipaccess_helper_functions/stm50flw0x0x.c (Arbeitskopie) @@ -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 @@ 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 @@ 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 @@ // 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 @@ } } 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 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 @@
/* 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 @@ dst = d; src = s; for (i = 0; i < page_size; i++) { - if (*dst != *src) { + if (readb(dst) != *src) { rc = -1; break; } Index: flashrom-inband_chipaccess_helper_functions/sst_fwhub.c =================================================================== --- flashrom-inband_chipaccess_helper_functions/sst_fwhub.c (Revision 3970) +++ flashrom-inband_chipaccess_helper_functions/sst_fwhub.c (Arbeitskopie) @@ -51,7 +51,7 @@ 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); Index: flashrom-inband_chipaccess_helper_functions/am29f040b.c =================================================================== --- flashrom-inband_chipaccess_helper_functions/am29f040b.c (Revision 3970) +++ flashrom-inband_chipaccess_helper_functions/am29f040b.c (Arbeitskopie) @@ -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 @@ 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 @@ 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 @@ { 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); Index: flashrom-inband_chipaccess_helper_functions/w39v080fa.c =================================================================== --- flashrom-inband_chipaccess_helper_functions/w39v080fa.c (Revision 3970) +++ flashrom-inband_chipaccess_helper_functions/w39v080fa.c (Arbeitskopie) @@ -27,19 +27,19 @@ 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 @@ 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 @@ 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 @@ */
/* 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 @@ 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); Index: flashrom-inband_chipaccess_helper_functions/82802ab.c =================================================================== --- flashrom-inband_chipaccess_helper_functions/82802ab.c (Revision 3970) +++ flashrom-inband_chipaccess_helper_functions/82802ab.c (Arbeitskopie) @@ -49,23 +49,23 @@ 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 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 @@ 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 @@
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); } } Index: flashrom-inband_chipaccess_helper_functions/m29f400bt.c =================================================================== --- flashrom-inband_chipaccess_helper_functions/m29f400bt.c (Revision 3970) +++ flashrom-inband_chipaccess_helper_functions/m29f400bt.c (Arbeitskopie) @@ -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 @@ 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 @@ 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 @@ { 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 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); Index: flashrom-inband_chipaccess_helper_functions/mx29f002.c =================================================================== --- flashrom-inband_chipaccess_helper_functions/mx29f002.c (Revision 3970) +++ flashrom-inband_chipaccess_helper_functions/mx29f002.c (Arbeitskopie) @@ -27,14 +27,14 @@ 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 @@ { 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 @@
#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 @@ 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 @@ /* 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);