summaryrefslogtreecommitdiffstats
path: root/stm50flw0x0x.c
diff options
context:
space:
mode:
Diffstat (limited to 'stm50flw0x0x.c')
-rw-r--r--stm50flw0x0x.c64
1 files changed, 32 insertions, 32 deletions
diff --git a/stm50flw0x0x.c b/stm50flw0x0x.c
index c06bab9..edb76cc 100644
--- a/stm50flw0x0x.c
+++ b/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;
}
OpenPOWER on IntegriCloud