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
This commit is contained in:
parent
51001fbd81
commit
ac12ecd27a
@ -49,23 +49,23 @@ int probe_82802ab(struct flashchip *flash)
|
|||||||
uint8_t id1, id2;
|
uint8_t id1, id2;
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xAA;
|
writeb(0xAA, bios + 0x5555);
|
||||||
*(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
|
writeb(0x55, bios + 0x2AAA);
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0x90;
|
writeb(0x90, bios + 0x5555);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
*bios = 0xff;
|
writeb(0xff, bios);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
*bios = 0x90;
|
writeb(0x90, bios);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
|
|
||||||
id1 = *(volatile uint8_t *)bios;
|
id1 = readb(bios);
|
||||||
id2 = *(volatile uint8_t *)(bios + 0x01);
|
id2 = readb(bios + 0x01);
|
||||||
|
|
||||||
/* Leave ID mode */
|
/* Leave ID mode */
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xAA;
|
writeb(0xAA, bios + 0x5555);
|
||||||
*(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
|
writeb(0x55, bios + 0x2AAA);
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xF0;
|
writeb(0xF0, bios + 0x5555);
|
||||||
|
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
|
|
||||||
@ -84,25 +84,25 @@ uint8_t wait_82802ab(volatile uint8_t *bios)
|
|||||||
uint8_t status;
|
uint8_t status;
|
||||||
uint8_t id1, id2;
|
uint8_t id1, id2;
|
||||||
|
|
||||||
*bios = 0x70;
|
writeb(0x70, bios);
|
||||||
if ((*bios & 0x80) == 0) { // it's busy
|
if ((readb(bios) & 0x80) == 0) { // it's busy
|
||||||
while ((*bios & 0x80) == 0) ;
|
while ((readb(bios) & 0x80) == 0) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = *bios;
|
status = readb(bios);
|
||||||
|
|
||||||
// put another command to get out of status register mode
|
// put another command to get out of status register mode
|
||||||
|
|
||||||
*bios = 0x90;
|
writeb(0x90, bios);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
|
|
||||||
id1 = *(volatile uint8_t *)bios;
|
id1 = readb(bios);
|
||||||
id2 = *(volatile uint8_t *)(bios + 0x01);
|
id2 = readb(bios + 0x01);
|
||||||
|
|
||||||
// this is needed to jam it out of "read id" mode
|
// this is needed to jam it out of "read id" mode
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xAA;
|
writeb(0xAA, bios + 0x5555);
|
||||||
*(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
|
writeb(0x55, bios + 0x2AAA);
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xF0;
|
writeb(0xF0, bios + 0x5555);
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@ -115,23 +115,23 @@ int erase_82802ab_block(struct flashchip *flash, int offset)
|
|||||||
uint8_t status;
|
uint8_t status;
|
||||||
|
|
||||||
// clear status register
|
// clear status register
|
||||||
*bios = 0x50;
|
writeb(0x50, bios);
|
||||||
//printf("Erase at %p\n", bios);
|
//printf("Erase at %p\n", bios);
|
||||||
// clear write protect
|
// clear write protect
|
||||||
//printf("write protect is at %p\n", (wrprotect));
|
//printf("write protect is at %p\n", (wrprotect));
|
||||||
//printf("write protect is 0x%x\n", *(wrprotect));
|
//printf("write protect is 0x%x\n", *(wrprotect));
|
||||||
*(wrprotect) = 0;
|
writeb(0, wrprotect);
|
||||||
//printf("write protect is 0x%x\n", *(wrprotect));
|
//printf("write protect is 0x%x\n", *(wrprotect));
|
||||||
|
|
||||||
// now start it
|
// now start it
|
||||||
*(volatile uint8_t *)(bios) = 0x20;
|
writeb(0x20, bios);
|
||||||
*(volatile uint8_t *)(bios) = 0xd0;
|
writeb(0xd0, bios);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
// now let's see what the register is
|
// now let's see what the register is
|
||||||
status = wait_82802ab(flash->virtual_memory);
|
status = wait_82802ab(flash->virtual_memory);
|
||||||
//print_82802ab_status(status);
|
//print_82802ab_status(status);
|
||||||
for (j = 0; j < flash->page_size; j++) {
|
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);
|
printf("BLOCK ERASE failed at 0x%x\n", offset);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -162,8 +162,8 @@ void write_page_82802ab(volatile uint8_t *bios, uint8_t *src,
|
|||||||
|
|
||||||
for (i = 0; i < page_size; i++) {
|
for (i = 0; i < page_size; i++) {
|
||||||
/* transfer data from source to destination */
|
/* transfer data from source to destination */
|
||||||
*dst = 0x40;
|
writeb(0x40, dst);
|
||||||
*dst++ = *src++;
|
writeb(*src++, dst++);
|
||||||
wait_82802ab(bios);
|
wait_82802ab(bios);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,12 +25,12 @@
|
|||||||
static __inline__ int erase_sector_29f040b(volatile uint8_t *bios,
|
static __inline__ int erase_sector_29f040b(volatile uint8_t *bios,
|
||||||
unsigned long address)
|
unsigned long address)
|
||||||
{
|
{
|
||||||
*(bios + 0x555) = 0xAA;
|
writeb(0xAA, bios + 0x555);
|
||||||
*(bios + 0x2AA) = 0x55;
|
writeb(0x55, bios + 0x2AA);
|
||||||
*(bios + 0x555) = 0x80;
|
writeb(0x80, bios + 0x555);
|
||||||
*(bios + 0x555) = 0xAA;
|
writeb(0xAA, bios + 0x555);
|
||||||
*(bios + 0x2AA) = 0x55;
|
writeb(0x55, bios + 0x2AA);
|
||||||
*(bios + address) = 0x30;
|
writeb(0x30, bios + address);
|
||||||
|
|
||||||
sleep(2);
|
sleep(2);
|
||||||
|
|
||||||
@ -52,10 +52,10 @@ static __inline__ int write_sector_29f040b(volatile uint8_t *bios,
|
|||||||
printf("0x%08lx", (unsigned long)dst -
|
printf("0x%08lx", (unsigned long)dst -
|
||||||
(unsigned long)bios);
|
(unsigned long)bios);
|
||||||
|
|
||||||
*(bios + 0x555) = 0xAA;
|
writeb(0xAA, bios + 0x555);
|
||||||
*(bios + 0x2AA) = 0x55;
|
writeb(0x55, bios + 0x2AA);
|
||||||
*(bios + 0x555) = 0xA0;
|
writeb(0xA0, bios + 0x555);
|
||||||
*dst++ = *src++;
|
writeb(*src++, dst++);
|
||||||
|
|
||||||
/* wait for Toggle bit ready */
|
/* wait for Toggle bit ready */
|
||||||
toggle_ready_jedec(bios);
|
toggle_ready_jedec(bios);
|
||||||
@ -72,14 +72,14 @@ int probe_29f040b(struct flashchip *flash)
|
|||||||
volatile uint8_t *bios = flash->virtual_memory;
|
volatile uint8_t *bios = flash->virtual_memory;
|
||||||
uint8_t id1, id2;
|
uint8_t id1, id2;
|
||||||
|
|
||||||
*(bios + 0x555) = 0xAA;
|
writeb(0xAA, bios + 0x555);
|
||||||
*(bios + 0x2AA) = 0x55;
|
writeb(0x55, bios + 0x2AA);
|
||||||
*(bios + 0x555) = 0x90;
|
writeb(0x90, bios + 0x555);
|
||||||
|
|
||||||
id1 = *bios;
|
id1 = readb(bios);
|
||||||
id2 = *(bios + 0x01);
|
id2 = readb(bios + 0x01);
|
||||||
|
|
||||||
*bios = 0xF0;
|
writeb(0xF0, bios);
|
||||||
|
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
|
|
||||||
@ -94,12 +94,12 @@ int erase_29f040b(struct flashchip *flash)
|
|||||||
{
|
{
|
||||||
volatile uint8_t *bios = flash->virtual_memory;
|
volatile uint8_t *bios = flash->virtual_memory;
|
||||||
|
|
||||||
*(bios + 0x555) = 0xAA;
|
writeb(0xAA, bios + 0x555);
|
||||||
*(bios + 0x2AA) = 0x55;
|
writeb(0x55, bios + 0x2AA);
|
||||||
*(bios + 0x555) = 0x80;
|
writeb(0x80, bios + 0x555);
|
||||||
*(bios + 0x555) = 0xAA;
|
writeb(0xAA, bios + 0x555);
|
||||||
*(bios + 0x2AA) = 0x55;
|
writeb(0x55, bios + 0x2AA);
|
||||||
*(bios + 0x555) = 0x10;
|
writeb(0x10, bios + 0x555);
|
||||||
|
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
toggle_ready_jedec(bios);
|
toggle_ready_jedec(bios);
|
||||||
|
@ -35,19 +35,19 @@ int probe_en29f512(struct flashchip *flash)
|
|||||||
volatile uint8_t *bios = flash->virtual_memory;
|
volatile uint8_t *bios = flash->virtual_memory;
|
||||||
uint8_t id1, id2;
|
uint8_t id1, id2;
|
||||||
|
|
||||||
*(volatile uint8_t *)(bios + 0x555) = 0xAA;
|
writeb(0xAA, bios + 0x555);
|
||||||
*(volatile uint8_t *)(bios + 0x2AA) = 0x55;
|
writeb(0x55, bios + 0x2AA);
|
||||||
*(volatile uint8_t *)(bios + 0x555) = 0x90;
|
writeb(0x90, bios + 0x555);
|
||||||
|
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
|
|
||||||
id1 = *(volatile uint8_t *)(bios + 0x100);
|
id1 = readb(bios + 0x100);
|
||||||
id2 = *(volatile uint8_t *)(bios + 0x101);
|
id2 = readb(bios + 0x101);
|
||||||
|
|
||||||
/* exit by writing F0 anywhere? or the code below */
|
/* exit by writing F0 anywhere? or the code below */
|
||||||
*(volatile uint8_t *)(bios + 0x555) = 0xAA;
|
writeb(0xAA, bios + 0x555);
|
||||||
*(volatile uint8_t *)(bios + 0x2AA) = 0x55;
|
writeb(0x55, bios + 0x2AA);
|
||||||
*(volatile uint8_t *)(bios + 0x555) = 0xF0;
|
writeb(0xF0, bios + 0x555);
|
||||||
|
|
||||||
printf_debug("%s: id1 0x%02x, id2 0x%02x\n", __FUNCTION__, id1, id2);
|
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;
|
volatile uint8_t *bios = flash->virtual_memory;
|
||||||
uint8_t id1, id2;
|
uint8_t id1, id2;
|
||||||
|
|
||||||
*(volatile uint8_t *)(bios + 0x555) = 0xAA;
|
writeb(0xAA, bios + 0x555);
|
||||||
*(volatile uint8_t *)(bios + 0xAAA) = 0x55;
|
writeb(0x55, bios + 0xAAA);
|
||||||
*(volatile uint8_t *)(bios + 0x555) = 0x90;
|
writeb(0x90, bios + 0x555);
|
||||||
|
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
|
|
||||||
id1 = *(volatile uint8_t *)(bios + 0x100);
|
id1 = readb(bios + 0x100);
|
||||||
id2 = *(volatile uint8_t *)(bios + 0x101);
|
id2 = readb(bios + 0x101);
|
||||||
|
|
||||||
/* exit by writing F0 anywhere? or the code below */
|
/* exit by writing F0 anywhere? or the code below */
|
||||||
*(volatile uint8_t *)(bios + 0x555) = 0xAA;
|
writeb(0xAA, bios + 0x555);
|
||||||
*(volatile uint8_t *)(bios + 0xAAA) = 0x55;
|
writeb(0x55, bios + 0xAAA);
|
||||||
*(volatile uint8_t *)(bios + 0x555) = 0xF0;
|
writeb(0xF0, bios + 0x555);
|
||||||
|
|
||||||
printf_debug("%s: id1 0x%x, id2 0x%x\n", __FUNCTION__, id1, id2);
|
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 */
|
/* write to the sector */
|
||||||
if ((i & 0xfff) == 0)
|
if ((i & 0xfff) == 0)
|
||||||
printf("address: 0x%08lx", (unsigned long)i);
|
printf("address: 0x%08lx", (unsigned long)i);
|
||||||
*(bios + 0x5555) = 0xAA;
|
writeb(0xAA, bios + 0x5555);
|
||||||
*(bios + 0x2AAA) = 0x55;
|
writeb(0x55, bios + 0x2AAA);
|
||||||
*(bios + 0x5555) = 0xA0;
|
writeb(0xA0, bios + 0x5555);
|
||||||
*dst++ = *buf++;
|
writeb(*buf++, dst++);
|
||||||
|
|
||||||
/* wait for Toggle bit ready */
|
/* wait for Toggle bit ready */
|
||||||
toggle_ready_jedec(dst);
|
toggle_ready_jedec(dst);
|
||||||
|
@ -58,6 +58,36 @@
|
|||||||
#define INL inl
|
#define INL inl
|
||||||
#endif
|
#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]))
|
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
|
||||||
|
|
||||||
struct flashchip {
|
struct flashchip {
|
||||||
|
@ -40,10 +40,10 @@ void toggle_ready_jedec(volatile uint8_t *dst)
|
|||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
uint8_t tmp1, tmp2;
|
uint8_t tmp1, tmp2;
|
||||||
|
|
||||||
tmp1 = *dst & 0x40;
|
tmp1 = readb(dst) & 0x40;
|
||||||
|
|
||||||
while (i++ < 0xFFFFFFF) {
|
while (i++ < 0xFFFFFFF) {
|
||||||
tmp2 = *dst & 0x40;
|
tmp2 = readb(dst) & 0x40;
|
||||||
if (tmp1 == tmp2) {
|
if (tmp1 == tmp2) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -59,7 +59,7 @@ void data_polling_jedec(volatile uint8_t *dst, uint8_t data)
|
|||||||
data &= 0x80;
|
data &= 0x80;
|
||||||
|
|
||||||
while (i++ < 0xFFFFFFF) {
|
while (i++ < 0xFFFFFFF) {
|
||||||
tmp = *dst & 0x80;
|
tmp = readb(dst) & 0x80;
|
||||||
if (tmp == data) {
|
if (tmp == data) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -68,21 +68,21 @@ void data_polling_jedec(volatile uint8_t *dst, uint8_t data)
|
|||||||
|
|
||||||
void unprotect_jedec(volatile uint8_t *bios)
|
void unprotect_jedec(volatile uint8_t *bios)
|
||||||
{
|
{
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xAA;
|
writeb(0xAA, bios + 0x5555);
|
||||||
*(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
|
writeb(0x55, bios + 0x2AAA);
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0x80;
|
writeb(0x80, bios + 0x5555);
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xAA;
|
writeb(0xAA, bios + 0x5555);
|
||||||
*(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
|
writeb(0x55, bios + 0x2AAA);
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0x20;
|
writeb(0x20, bios + 0x5555);
|
||||||
|
|
||||||
usleep(200);
|
usleep(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
void protect_jedec(volatile uint8_t *bios)
|
void protect_jedec(volatile uint8_t *bios)
|
||||||
{
|
{
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xAA;
|
writeb(0xAA, bios + 0x5555);
|
||||||
*(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
|
writeb(0x55, bios + 0x2AAA);
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xA0;
|
writeb(0xA0, bios + 0x5555);
|
||||||
|
|
||||||
usleep(200);
|
usleep(200);
|
||||||
}
|
}
|
||||||
@ -94,40 +94,40 @@ int probe_jedec(struct flashchip *flash)
|
|||||||
uint32_t largeid1, largeid2;
|
uint32_t largeid1, largeid2;
|
||||||
|
|
||||||
/* Issue JEDEC Product ID Entry command */
|
/* Issue JEDEC Product ID Entry command */
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xAA;
|
writeb(0xAA, bios + 0x5555);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
*(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
|
writeb(0x55, bios + 0x2AAA);
|
||||||
myusec_delay(10);
|
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
|
/* Older chips may need up to 100 us to respond. The ATMEL 29C020
|
||||||
* needs 10 ms according to the data sheet.
|
* needs 10 ms according to the data sheet.
|
||||||
*/
|
*/
|
||||||
myusec_delay(10000);
|
myusec_delay(10000);
|
||||||
|
|
||||||
/* Read product ID */
|
/* Read product ID */
|
||||||
id1 = *(volatile uint8_t *)bios;
|
id1 = readb(bios);
|
||||||
id2 = *(volatile uint8_t *)(bios + 0x01);
|
id2 = readb(bios + 0x01);
|
||||||
largeid1 = id1;
|
largeid1 = id1;
|
||||||
largeid2 = id2;
|
largeid2 = id2;
|
||||||
|
|
||||||
/* Check if it is a continuation ID, this should be a while loop. */
|
/* Check if it is a continuation ID, this should be a while loop. */
|
||||||
if (id1 == 0x7F) {
|
if (id1 == 0x7F) {
|
||||||
largeid1 <<= 8;
|
largeid1 <<= 8;
|
||||||
id1 = *(volatile uint8_t *)(bios + 0x100);
|
id1 = readb(bios + 0x100);
|
||||||
largeid1 |= id1;
|
largeid1 |= id1;
|
||||||
}
|
}
|
||||||
if (id2 == 0x7F) {
|
if (id2 == 0x7F) {
|
||||||
largeid2 <<= 8;
|
largeid2 <<= 8;
|
||||||
id2 = *(volatile uint8_t *)(bios + 0x101);
|
id2 = readb(bios + 0x101);
|
||||||
largeid2 |= id2;
|
largeid2 |= id2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Issue JEDEC Product ID Exit command */
|
/* Issue JEDEC Product ID Exit command */
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xAA;
|
writeb(0xAA, bios + 0x5555);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
*(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
|
writeb(0x55, bios + 0x2AAA);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xF0;
|
writeb(0xF0, bios + 0x5555);
|
||||||
myusec_delay(40);
|
myusec_delay(40);
|
||||||
|
|
||||||
printf_debug("%s: id1 0x%02x, id2 0x%02x", __FUNCTION__, largeid1, largeid2);
|
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)
|
int erase_sector_jedec(volatile uint8_t *bios, unsigned int page)
|
||||||
{
|
{
|
||||||
/* Issue the Sector Erase command */
|
/* Issue the Sector Erase command */
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xAA;
|
writeb(0xAA, bios + 0x5555);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
*(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
|
writeb(0x55, bios + 0x2AAA);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0x80;
|
writeb(0x80, bios + 0x5555);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
|
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xAA;
|
writeb(0xAA, bios + 0x5555);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
*(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
|
writeb(0x55, bios + 0x2AAA);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
*(volatile uint8_t *)(bios + page) = 0x30;
|
writeb(0x30, bios + page);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
|
|
||||||
/* wait for Toggle bit ready */
|
/* 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)
|
int erase_block_jedec(volatile uint8_t *bios, unsigned int block)
|
||||||
{
|
{
|
||||||
/* Issue the Sector Erase command */
|
/* Issue the Sector Erase command */
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xAA;
|
writeb(0xAA, bios + 0x5555);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
*(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
|
writeb(0x55, bios + 0x2AAA);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0x80;
|
writeb(0x80, bios + 0x5555);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
|
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xAA;
|
writeb(0xAA, bios + 0x5555);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
*(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
|
writeb(0x55, bios + 0x2AAA);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
*(volatile uint8_t *)(bios + block) = 0x50;
|
writeb(0x50, bios + block);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
|
|
||||||
/* wait for Toggle bit ready */
|
/* wait for Toggle bit ready */
|
||||||
@ -191,18 +191,18 @@ int erase_chip_jedec(struct flashchip *flash)
|
|||||||
volatile uint8_t *bios = flash->virtual_memory;
|
volatile uint8_t *bios = flash->virtual_memory;
|
||||||
|
|
||||||
/* Issue the JEDEC Chip Erase command */
|
/* Issue the JEDEC Chip Erase command */
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xAA;
|
writeb(0xAA, bios + 0x5555);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
*(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
|
writeb(0x55, bios + 0x2AAA);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0x80;
|
writeb(0x80, bios + 0x5555);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
|
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xAA;
|
writeb(0xAA, bios + 0x5555);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
*(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
|
writeb(0x55, bios + 0x2AAA);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0x10;
|
writeb(0x10, bios + 0x5555);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
|
|
||||||
toggle_ready_jedec(bios);
|
toggle_ready_jedec(bios);
|
||||||
@ -219,15 +219,15 @@ int write_page_write_jedec(volatile uint8_t *bios, uint8_t *src,
|
|||||||
|
|
||||||
retry:
|
retry:
|
||||||
/* Issue JEDEC Data Unprotect comand */
|
/* Issue JEDEC Data Unprotect comand */
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xAA;
|
writeb(0xAA, bios + 0x5555);
|
||||||
*(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
|
writeb(0x55, bios + 0x2AAA);
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xA0;
|
writeb(0xA0, bios + 0x5555);
|
||||||
|
|
||||||
/* transfer data from source to destination */
|
/* transfer data from source to destination */
|
||||||
for (i = start_index; i < page_size; i++) {
|
for (i = start_index; i < page_size; i++) {
|
||||||
/* If the data is 0xFF, don't program it */
|
/* If the data is 0xFF, don't program it */
|
||||||
if (*src != 0xFF)
|
if (*src != 0xFF)
|
||||||
*dst = *src;
|
writeb(*src, dst);
|
||||||
dst++;
|
dst++;
|
||||||
src++;
|
src++;
|
||||||
}
|
}
|
||||||
@ -238,7 +238,7 @@ retry:
|
|||||||
src = s;
|
src = s;
|
||||||
ok = 1;
|
ok = 1;
|
||||||
for (i = 0; i < page_size; i++) {
|
for (i = 0; i < page_size; i++) {
|
||||||
if (*dst != *src) {
|
if (readb(dst) != *src) {
|
||||||
ok = 0;
|
ok = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -269,15 +269,15 @@ int write_byte_program_jedec(volatile uint8_t *bios, uint8_t *src,
|
|||||||
|
|
||||||
retry:
|
retry:
|
||||||
/* Issue JEDEC Byte Program command */
|
/* Issue JEDEC Byte Program command */
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xAA;
|
writeb(0xAA, bios + 0x5555);
|
||||||
*(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
|
writeb(0x55, bios + 0x2AAA);
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xA0;
|
writeb(0xA0, bios + 0x5555);
|
||||||
|
|
||||||
/* transfer data from source to destination */
|
/* transfer data from source to destination */
|
||||||
*dst = *src;
|
writeb(*src, dst);
|
||||||
toggle_ready_jedec(bios);
|
toggle_ready_jedec(bios);
|
||||||
|
|
||||||
if (*dst != *src && tried++ < MAX_REFLASH_TRIES) {
|
if (readb(dst) != *src && tried++ < MAX_REFLASH_TRIES) {
|
||||||
goto retry;
|
goto retry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,12 +22,12 @@
|
|||||||
|
|
||||||
int erase_m29f002(struct flashchip *flash) {
|
int erase_m29f002(struct flashchip *flash) {
|
||||||
volatile uint8_t *bios = flash->virtual_memory;
|
volatile uint8_t *bios = flash->virtual_memory;
|
||||||
*(volatile uint8_t *)(bios + 0x555) = 0xaa;
|
writeb(0xaa, bios + 0x555);
|
||||||
*(volatile uint8_t *)(bios + 0xaaa) = 0x55;
|
writeb(0x55, bios + 0xaaa);
|
||||||
*(volatile uint8_t *)(bios + 0x555) = 0x80;
|
writeb(0x80, bios + 0x555);
|
||||||
*(volatile uint8_t *)(bios + 0x555) = 0xaa;
|
writeb(0xaa, bios + 0x555);
|
||||||
*(volatile uint8_t *)(bios + 0xaaa) = 0x55;
|
writeb(0x55, bios + 0xaaa);
|
||||||
*(volatile uint8_t *)(bios + 0x555) = 0x10;
|
writeb(0x10, bios + 0x555);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
toggle_ready_jedec(bios);
|
toggle_ready_jedec(bios);
|
||||||
return 0;
|
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) {
|
static void rewrite_block(volatile uint8_t *bios, uint8_t *src, volatile uint8_t *dst, int size) {
|
||||||
/* erase */
|
/* erase */
|
||||||
*(volatile uint8_t *)(bios + 0x555) = 0xaa;
|
writeb(0xaa, bios + 0x555);
|
||||||
*(volatile uint8_t *)(bios + 0xaaa) = 0x55;
|
writeb(0x55, bios + 0xaaa);
|
||||||
*(volatile uint8_t *)(bios + 0x555) = 0x80;
|
writeb(0x80, bios + 0x555);
|
||||||
*(volatile uint8_t *)(bios + 0x555) = 0xaa;
|
writeb(0xaa, bios + 0x555);
|
||||||
*(volatile uint8_t *)(bios + 0xaaa) = 0x55;
|
writeb(0x55, bios + 0xaaa);
|
||||||
*dst = 0x30;
|
writeb(0x30, dst);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
toggle_ready_jedec(bios);
|
toggle_ready_jedec(bios);
|
||||||
|
|
||||||
/* program */
|
/* program */
|
||||||
while (size--) {
|
while (size--) {
|
||||||
*(volatile uint8_t *)(bios + 0x555) = 0xaa;
|
writeb(0xaa, bios + 0x555);
|
||||||
*(volatile uint8_t *)(bios + 0xaaa) = 0x55;
|
writeb(0x55, bios + 0xaaa);
|
||||||
*(volatile uint8_t *)(bios + 0x555) = 0xa0;
|
writeb(0xa0, bios + 0x555);
|
||||||
*dst = *src;
|
writeb(*src, dst);
|
||||||
toggle_ready_jedec(dst);
|
toggle_ready_jedec(dst);
|
||||||
dst++;
|
dst++;
|
||||||
src++;
|
src++;
|
||||||
|
@ -22,9 +22,9 @@
|
|||||||
|
|
||||||
void protect_m29f400bt(volatile uint8_t *bios)
|
void protect_m29f400bt(volatile uint8_t *bios)
|
||||||
{
|
{
|
||||||
*(volatile uint8_t *)(bios + 0xAAA) = 0xAA;
|
writeb(0xAA, bios + 0xAAA);
|
||||||
*(volatile uint8_t *)(bios + 0x555) = 0x55;
|
writeb(0x55, bios + 0x555);
|
||||||
*(volatile uint8_t *)(bios + 0xAAA) = 0xA0;
|
writeb(0xA0, bios + 0xAAA);
|
||||||
|
|
||||||
usleep(200);
|
usleep(200);
|
||||||
}
|
}
|
||||||
@ -35,18 +35,18 @@ void write_page_m29f400bt(volatile uint8_t *bios, uint8_t *src,
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < page_size; i++) {
|
for (i = 0; i < page_size; i++) {
|
||||||
*(volatile uint8_t *)(bios + 0xAAA) = 0xAA;
|
writeb(0xAA, bios + 0xAAA);
|
||||||
*(volatile uint8_t *)(bios + 0x555) = 0x55;
|
writeb(0x55, bios + 0x555);
|
||||||
*(volatile uint8_t *)(bios + 0xAAA) = 0xA0;
|
writeb(0xA0, bios + 0xAAA);
|
||||||
|
|
||||||
/* transfer data from source to destination */
|
/* transfer data from source to destination */
|
||||||
*dst = *src;
|
writeb(*src, dst);
|
||||||
//*(volatile char *) (bios) = 0xF0;
|
//*(volatile char *) (bios) = 0xF0;
|
||||||
//usleep(5);
|
//usleep(5);
|
||||||
toggle_ready_jedec(dst);
|
toggle_ready_jedec(dst);
|
||||||
printf
|
printf
|
||||||
("Value in the flash at address %p = %#x, want %#x\n",
|
("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++;
|
dst++;
|
||||||
src++;
|
src++;
|
||||||
}
|
}
|
||||||
@ -57,21 +57,21 @@ int probe_m29f400bt(struct flashchip *flash)
|
|||||||
volatile uint8_t *bios = flash->virtual_memory;
|
volatile uint8_t *bios = flash->virtual_memory;
|
||||||
uint8_t id1, id2;
|
uint8_t id1, id2;
|
||||||
|
|
||||||
*(volatile uint8_t *)(bios + 0xAAA) = 0xAA;
|
writeb(0xAA, bios + 0xAAA);
|
||||||
*(volatile uint8_t *)(bios + 0x555) = 0x55;
|
writeb(0x55, bios + 0x555);
|
||||||
*(volatile uint8_t *)(bios + 0xAAA) = 0x90;
|
writeb(0x90, bios + 0xAAA);
|
||||||
|
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
|
|
||||||
id1 = *(volatile uint8_t *)bios;
|
id1 = readb(bios);
|
||||||
/* The data sheet says id2 is at (bios + 0x01) and id2 listed in
|
/* 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.
|
* 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;
|
writeb(0xAA, bios + 0xAAA);
|
||||||
*(volatile uint8_t *)(bios + 0x555) = 0x55;
|
writeb(0x55, bios + 0x555);
|
||||||
*(volatile uint8_t *)(bios + 0xAAA) = 0xF0;
|
writeb(0xF0, bios + 0xAAA);
|
||||||
|
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
|
|
||||||
@ -87,13 +87,13 @@ int erase_m29f400bt(struct flashchip *flash)
|
|||||||
{
|
{
|
||||||
volatile uint8_t *bios = flash->virtual_memory;
|
volatile uint8_t *bios = flash->virtual_memory;
|
||||||
|
|
||||||
*(volatile uint8_t *)(bios + 0xAAA) = 0xAA;
|
writeb(0xAA, bios + 0xAAA);
|
||||||
*(volatile uint8_t *)(bios + 0x555) = 0x55;
|
writeb(0x55, bios + 0x555);
|
||||||
*(volatile uint8_t *)(bios + 0xAAA) = 0x80;
|
writeb(0x80, bios + 0xAAA);
|
||||||
|
|
||||||
*(volatile uint8_t *)(bios + 0xAAA) = 0xAA;
|
writeb(0xAA, bios + 0xAAA);
|
||||||
*(volatile uint8_t *)(bios + 0x555) = 0x55;
|
writeb(0x55, bios + 0x555);
|
||||||
*(volatile uint8_t *)(bios + 0xAAA) = 0x10;
|
writeb(0x10, bios + 0xAAA);
|
||||||
|
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
toggle_ready_jedec(bios);
|
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)
|
int block_erase_m29f400bt(volatile uint8_t *bios, volatile uint8_t *dst)
|
||||||
{
|
{
|
||||||
|
|
||||||
*(volatile uint8_t *)(bios + 0xAAA) = 0xAA;
|
writeb(0xAA, bios + 0xAAA);
|
||||||
*(volatile uint8_t *)(bios + 0x555) = 0x55;
|
writeb(0x55, bios + 0x555);
|
||||||
*(volatile uint8_t *)(bios + 0xAAA) = 0x80;
|
writeb(0x80, bios + 0xAAA);
|
||||||
|
|
||||||
*(volatile uint8_t *)(bios + 0xAAA) = 0xAA;
|
writeb(0xAA, bios + 0xAAA);
|
||||||
*(volatile uint8_t *)(bios + 0x555) = 0x55;
|
writeb(0x55, bios + 0x555);
|
||||||
//*(volatile uint8_t *) (bios + 0xAAA) = 0x10;
|
//*(volatile uint8_t *) (bios + 0xAAA) = 0x10;
|
||||||
*dst = 0x30;
|
writeb(0x30, dst);
|
||||||
|
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
toggle_ready_jedec(bios);
|
toggle_ready_jedec(bios);
|
||||||
|
@ -27,14 +27,14 @@ int probe_29f002(struct flashchip *flash)
|
|||||||
volatile uint8_t *bios = flash->virtual_memory;
|
volatile uint8_t *bios = flash->virtual_memory;
|
||||||
uint8_t id1, id2;
|
uint8_t id1, id2;
|
||||||
|
|
||||||
*(bios + 0x5555) = 0xAA;
|
writeb(0xAA, bios + 0x5555);
|
||||||
*(bios + 0x2AAA) = 0x55;
|
writeb(0x55, bios + 0x2AAA);
|
||||||
*(bios + 0x5555) = 0x90;
|
writeb(0x90, bios + 0x5555);
|
||||||
|
|
||||||
id1 = *(volatile uint8_t *)bios;
|
id1 = readb(bios);
|
||||||
id2 = *(volatile uint8_t *)(bios + 0x01);
|
id2 = readb(bios + 0x01);
|
||||||
|
|
||||||
*bios = 0xF0;
|
writeb(0xF0, bios);
|
||||||
|
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
|
|
||||||
@ -49,13 +49,13 @@ int erase_29f002(struct flashchip *flash)
|
|||||||
{
|
{
|
||||||
volatile uint8_t *bios = flash->virtual_memory;
|
volatile uint8_t *bios = flash->virtual_memory;
|
||||||
|
|
||||||
*(bios + 0x555) = 0xF0;
|
writeb(0xF0, bios + 0x555);
|
||||||
*(bios + 0x555) = 0xAA;
|
writeb(0xAA, bios + 0x555);
|
||||||
*(bios + 0x2AA) = 0x55;
|
writeb(0x55, bios + 0x2AA);
|
||||||
*(bios + 0x555) = 0x80;
|
writeb(0x80, bios + 0x555);
|
||||||
*(bios + 0x555) = 0xAA;
|
writeb(0xAA, bios + 0x555);
|
||||||
*(bios + 0x2AA) = 0x55;
|
writeb(0x55, bios + 0x2AA);
|
||||||
*(bios + 0x555) = 0x10;
|
writeb(0x10, bios + 0x555);
|
||||||
|
|
||||||
myusec_delay(100);
|
myusec_delay(100);
|
||||||
toggle_ready_jedec(bios);
|
toggle_ready_jedec(bios);
|
||||||
@ -65,12 +65,12 @@ int erase_29f002(struct flashchip *flash)
|
|||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
toggle_ready_jedec(bios);
|
toggle_ready_jedec(bios);
|
||||||
*(bios + 0x0ffff) = 0x30;
|
writeb(0x30, bios + 0x0ffff);
|
||||||
*(bios + 0x1ffff) = 0x30;
|
writeb(0x30, bios + 0x1ffff);
|
||||||
*(bios + 0x2ffff) = 0x30;
|
writeb(0x30, bios + 0x2ffff);
|
||||||
*(bios + 0x37fff) = 0x30;
|
writeb(0x30, bios + 0x37fff);
|
||||||
*(bios + 0x39fff) = 0x30;
|
writeb(0x30, bios + 0x39fff);
|
||||||
*(bios + 0x3bfff) = 0x30;
|
writeb(0x30, bios + 0x3bfff);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
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 *bios = flash->virtual_memory;
|
||||||
volatile uint8_t *dst = bios;
|
volatile uint8_t *dst = bios;
|
||||||
|
|
||||||
*bios = 0xF0;
|
writeb(0xF0, bios);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
erase_29f002(flash);
|
erase_29f002(flash);
|
||||||
//*bios = 0xF0;
|
//*bios = 0xF0;
|
||||||
@ -93,10 +93,10 @@ int write_29f002(struct flashchip *flash, uint8_t *buf)
|
|||||||
/* write to the sector */
|
/* write to the sector */
|
||||||
if ((i & 0xfff) == 0)
|
if ((i & 0xfff) == 0)
|
||||||
printf("address: 0x%08lx", (unsigned long)i);
|
printf("address: 0x%08lx", (unsigned long)i);
|
||||||
*(bios + 0x5555) = 0xAA;
|
writeb(0xAA, bios + 0x5555);
|
||||||
*(bios + 0x2AAA) = 0x55;
|
writeb(0x55, bios + 0x2AAA);
|
||||||
*(bios + 0x5555) = 0xA0;
|
writeb(0xA0, bios + 0x5555);
|
||||||
*dst++ = *buf++;
|
writeb(*buf++, dst++);
|
||||||
|
|
||||||
/* wait for Toggle bit ready */
|
/* wait for Toggle bit ready */
|
||||||
toggle_ready_jedec(dst);
|
toggle_ready_jedec(dst);
|
||||||
|
@ -35,7 +35,7 @@ void write_lockbits_49fl00x(volatile uint8_t *bios, int size,
|
|||||||
if (block_size == 16384 && i % 2)
|
if (block_size == 16384 && i % 2)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
*(bios + (i * block_size) + 2) = bits;
|
writeb(bits, bios + (i * block_size) + 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,23 +41,23 @@ int probe_lhf00l04(struct flashchip *flash)
|
|||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
/* Enter ID mode */
|
/* Enter ID mode */
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xAA;
|
writeb(0xAA, bios + 0x5555);
|
||||||
*(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
|
writeb(0x55, bios + 0x2AAA);
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0x90;
|
writeb(0x90, bios + 0x5555);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
*bios = 0xff;
|
writeb(0xff, bios);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
*bios = 0x90;
|
writeb(0x90, bios);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
|
|
||||||
id1 = *(volatile uint8_t *)bios;
|
id1 = readb(bios);
|
||||||
id2 = *(volatile uint8_t *)(bios + 0x01);
|
id2 = readb(bios + 0x01);
|
||||||
|
|
||||||
/* Leave ID mode */
|
/* Leave ID mode */
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xAA;
|
writeb(0xAA, bios + 0x5555);
|
||||||
*(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
|
writeb(0x55, bios + 0x2AAA);
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xF0;
|
writeb(0xF0, bios + 0x5555);
|
||||||
|
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
|
|
||||||
@ -76,25 +76,25 @@ uint8_t wait_lhf00l04(volatile uint8_t *bios)
|
|||||||
uint8_t status;
|
uint8_t status;
|
||||||
uint8_t id1, id2;
|
uint8_t id1, id2;
|
||||||
|
|
||||||
*bios = 0x70;
|
writeb(0x70, bios);
|
||||||
if ((*bios & 0x80) == 0) { // it's busy
|
if ((readb(bios) & 0x80) == 0) { // it's busy
|
||||||
while ((*bios & 0x80) == 0) ;
|
while ((readb(bios) & 0x80) == 0) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = *bios;
|
status = readb(bios);
|
||||||
|
|
||||||
// put another command to get out of status register mode
|
// put another command to get out of status register mode
|
||||||
|
|
||||||
*bios = 0x90;
|
writeb(0x90, bios);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
|
|
||||||
id1 = *(volatile uint8_t *)bios;
|
id1 = readb(bios);
|
||||||
id2 = *(volatile uint8_t *)(bios + 0x01);
|
id2 = readb(bios + 0x01);
|
||||||
|
|
||||||
// this is needed to jam it out of "read id" mode
|
// this is needed to jam it out of "read id" mode
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xAA;
|
writeb(0xAA, bios + 0x5555);
|
||||||
*(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
|
writeb(0x55, bios + 0x2AAA);
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xF0;
|
writeb(0xF0, bios + 0x5555);
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@ -106,19 +106,19 @@ int erase_lhf00l04_block(struct flashchip *flash, int offset)
|
|||||||
uint8_t status;
|
uint8_t status;
|
||||||
|
|
||||||
// clear status register
|
// clear status register
|
||||||
*bios = 0x50;
|
writeb(0x50, bios);
|
||||||
printf("Erase at %p\n", bios);
|
printf("Erase at %p\n", bios);
|
||||||
status = wait_lhf00l04(flash->virtual_memory);
|
status = wait_lhf00l04(flash->virtual_memory);
|
||||||
print_lhf00l04_status(status);
|
print_lhf00l04_status(status);
|
||||||
// clear write protect
|
// clear write protect
|
||||||
printf("write protect is at %p\n", (wrprotect));
|
printf("write protect is at %p\n", (wrprotect));
|
||||||
printf("write protect is 0x%x\n", *(wrprotect));
|
printf("write protect is 0x%x\n", readb(wrprotect));
|
||||||
*(wrprotect) = 0;
|
writeb(0, wrprotect);
|
||||||
printf("write protect is 0x%x\n", *(wrprotect));
|
printf("write protect is 0x%x\n", readb(wrprotect));
|
||||||
|
|
||||||
// now start it
|
// now start it
|
||||||
*(volatile uint8_t *)(bios) = 0x20;
|
writeb(0x20, bios);
|
||||||
*(volatile uint8_t *)(bios) = 0xd0;
|
writeb(0xd0, bios);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
// now let's see what the register is
|
// now let's see what the register is
|
||||||
status = wait_lhf00l04(flash->virtual_memory);
|
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++) {
|
for (i = 0; i < page_size; i++) {
|
||||||
/* transfer data from source to destination */
|
/* transfer data from source to destination */
|
||||||
*dst = 0x40;
|
writeb(0x40, dst);
|
||||||
*dst++ = *src++;
|
writeb(*src++, dst++);
|
||||||
wait_lhf00l04(bios);
|
wait_lhf00l04(bios);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -163,7 +163,7 @@ int write_lhf00l04(struct flashchip *flash, uint8_t *buf)
|
|||||||
volatile uint8_t *bios = flash->virtual_memory;
|
volatile uint8_t *bios = flash->virtual_memory;
|
||||||
|
|
||||||
erase_lhf00l04(flash);
|
erase_lhf00l04(flash);
|
||||||
if (*bios != 0xff) {
|
if (readb(bios) != 0xff) {
|
||||||
printf("ERASE FAILED!\n");
|
printf("ERASE FAILED!\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -35,13 +35,13 @@ static __inline__ void protect_28sf040(volatile uint8_t *bios)
|
|||||||
/* ask compiler not to optimize this */
|
/* ask compiler not to optimize this */
|
||||||
volatile uint8_t tmp;
|
volatile uint8_t tmp;
|
||||||
|
|
||||||
tmp = *(volatile uint8_t *)(bios + 0x1823);
|
tmp = readb(bios + 0x1823);
|
||||||
tmp = *(volatile uint8_t *)(bios + 0x1820);
|
tmp = readb(bios + 0x1820);
|
||||||
tmp = *(volatile uint8_t *)(bios + 0x1822);
|
tmp = readb(bios + 0x1822);
|
||||||
tmp = *(volatile uint8_t *)(bios + 0x0418);
|
tmp = readb(bios + 0x0418);
|
||||||
tmp = *(volatile uint8_t *)(bios + 0x041B);
|
tmp = readb(bios + 0x041B);
|
||||||
tmp = *(volatile uint8_t *)(bios + 0x0419);
|
tmp = readb(bios + 0x0419);
|
||||||
tmp = *(volatile uint8_t *)(bios + 0x040A);
|
tmp = readb(bios + 0x040A);
|
||||||
}
|
}
|
||||||
|
|
||||||
static __inline__ void unprotect_28sf040(volatile uint8_t *bios)
|
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 */
|
/* ask compiler not to optimize this */
|
||||||
volatile uint8_t tmp;
|
volatile uint8_t tmp;
|
||||||
|
|
||||||
tmp = *(volatile uint8_t *)(bios + 0x1823);
|
tmp = readb(bios + 0x1823);
|
||||||
tmp = *(volatile uint8_t *)(bios + 0x1820);
|
tmp = readb(bios + 0x1820);
|
||||||
tmp = *(volatile uint8_t *)(bios + 0x1822);
|
tmp = readb(bios + 0x1822);
|
||||||
tmp = *(volatile uint8_t *)(bios + 0x0418);
|
tmp = readb(bios + 0x0418);
|
||||||
tmp = *(volatile uint8_t *)(bios + 0x041B);
|
tmp = readb(bios + 0x041B);
|
||||||
tmp = *(volatile uint8_t *)(bios + 0x0419);
|
tmp = readb(bios + 0x0419);
|
||||||
tmp = *(volatile uint8_t *)(bios + 0x041A);
|
tmp = readb(bios + 0x041A);
|
||||||
}
|
}
|
||||||
|
|
||||||
static __inline__ int erase_sector_28sf040(volatile uint8_t *bios,
|
static __inline__ int erase_sector_28sf040(volatile uint8_t *bios,
|
||||||
unsigned long address)
|
unsigned long address)
|
||||||
{
|
{
|
||||||
*bios = AUTO_PG_ERASE1;
|
writeb(AUTO_PG_ERASE1, bios);
|
||||||
*(bios + address) = AUTO_PG_ERASE2;
|
writeb(AUTO_PG_ERASE2, bios + address);
|
||||||
|
|
||||||
/* wait for Toggle bit ready */
|
/* wait for Toggle bit ready */
|
||||||
toggle_ready_jedec(bios);
|
toggle_ready_jedec(bios);
|
||||||
@ -85,8 +85,8 @@ static __inline__ int write_sector_28sf040(volatile uint8_t *bios,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/*issue AUTO PROGRAM command */
|
/*issue AUTO PROGRAM command */
|
||||||
*dst = AUTO_PGRM;
|
writeb(AUTO_PGRM, dst);
|
||||||
*dst++ = *src++;
|
writeb(*src++, dst++);
|
||||||
|
|
||||||
/* wait for Toggle bit ready */
|
/* wait for Toggle bit ready */
|
||||||
toggle_ready_jedec(bios);
|
toggle_ready_jedec(bios);
|
||||||
@ -100,16 +100,16 @@ int probe_28sf040(struct flashchip *flash)
|
|||||||
volatile uint8_t *bios = flash->virtual_memory;
|
volatile uint8_t *bios = flash->virtual_memory;
|
||||||
uint8_t id1, id2;
|
uint8_t id1, id2;
|
||||||
|
|
||||||
*bios = RESET;
|
writeb(RESET, bios);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
|
|
||||||
*bios = READ_ID;
|
writeb(READ_ID, bios);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
id1 = *(volatile uint8_t *)bios;
|
id1 = readb(bios);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
id2 = *(volatile uint8_t *)(bios + 0x01);
|
id2 = readb(bios + 0x01);
|
||||||
|
|
||||||
*bios = RESET;
|
writeb(RESET, bios);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
|
|
||||||
printf_debug("%s: id1 0x%02x, id2 0x%02x\n", __FUNCTION__, id1, id2);
|
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;
|
volatile uint8_t *bios = flash->virtual_memory;
|
||||||
|
|
||||||
unprotect_28sf040(bios);
|
unprotect_28sf040(bios);
|
||||||
*bios = CHIP_ERASE;
|
writeb(CHIP_ERASE, bios);
|
||||||
*bios = CHIP_ERASE;
|
writeb(CHIP_ERASE, bios);
|
||||||
protect_28sf040(bios);
|
protect_28sf040(bios);
|
||||||
|
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
|
@ -50,20 +50,20 @@ static __inline__ int write_lockbits_49lfxxxc(volatile uint8_t *bios, int size,
|
|||||||
//printf("bios=0x%08lx\n", (unsigned long)bios);
|
//printf("bios=0x%08lx\n", (unsigned long)bios);
|
||||||
for (i = 0; left > 65536; i++, left -= 65536) {
|
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) );
|
//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;
|
address = i * 65536;
|
||||||
//printf("lockbits at address=0x%08lx is 0x%01x\n", (unsigned long)0xFFc00000 - size + address + 2, *(bios + address + 2) );
|
//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;
|
address += 32768;
|
||||||
//printf("lockbits at address=0x%08lx is 0x%01x\n", (unsigned long)0xFFc00000 - size + address + 2, *(bios + address + 2) );
|
//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;
|
address += 8192;
|
||||||
//printf("lockbits at address=0x%08lx is 0x%01x\n", (unsigned long)0xFFc00000 - size + address + 2, *(bios + address + 2) );
|
//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;
|
address += 8192;
|
||||||
//printf("lockbits at address=0x%08lx is 0x%01x\n", (unsigned long)0xFFc00000 - size + address + 2, *(bios + address + 2) );
|
//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;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -73,14 +73,14 @@ static __inline__ int erase_sector_49lfxxxc(volatile uint8_t *bios,
|
|||||||
{
|
{
|
||||||
unsigned char status;
|
unsigned char status;
|
||||||
|
|
||||||
*bios = SECTOR_ERASE;
|
writeb(SECTOR_ERASE, bios);
|
||||||
*(bios + address) = ERASE;
|
writeb(ERASE, bios + address);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
status = *bios;
|
status = readb(bios);
|
||||||
if (status & (STATUS_ESS | STATUS_BPS)) {
|
if (status & (STATUS_ESS | STATUS_BPS)) {
|
||||||
printf("sector erase FAILED at address=0x%08lx status=0x%01x\n", (unsigned long)bios + address, status);
|
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);
|
return (-1);
|
||||||
}
|
}
|
||||||
} while (!(status & STATUS_WSMS));
|
} while (!(status & STATUS_WSMS));
|
||||||
@ -96,7 +96,7 @@ static __inline__ int write_sector_49lfxxxc(volatile uint8_t *bios,
|
|||||||
int i;
|
int i;
|
||||||
unsigned char status;
|
unsigned char status;
|
||||||
|
|
||||||
*bios = CLEAR_STATUS;
|
writeb(CLEAR_STATUS, bios);
|
||||||
for (i = 0; i < page_size; i++) {
|
for (i = 0; i < page_size; i++) {
|
||||||
/* transfer data from source to destination */
|
/* transfer data from source to destination */
|
||||||
if (*src == 0xFF) {
|
if (*src == 0xFF) {
|
||||||
@ -105,14 +105,14 @@ static __inline__ int write_sector_49lfxxxc(volatile uint8_t *bios,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/*issue AUTO PROGRAM command */
|
/*issue AUTO PROGRAM command */
|
||||||
*bios = AUTO_PGRM;
|
writeb(AUTO_PGRM, bios);
|
||||||
*dst++ = *src++;
|
writeb(*src++, dst++);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
status = *bios;
|
status = readb(bios);
|
||||||
if (status & (STATUS_ESS | STATUS_BPS)) {
|
if (status & (STATUS_ESS | STATUS_BPS)) {
|
||||||
printf("sector write FAILED at address=0x%08lx status=0x%01x\n", (unsigned long)dst, status);
|
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);
|
return (-1);
|
||||||
}
|
}
|
||||||
} while (!(status & STATUS_WSMS));
|
} while (!(status & STATUS_WSMS));
|
||||||
@ -127,13 +127,13 @@ int probe_49lfxxxc(struct flashchip *flash)
|
|||||||
|
|
||||||
uint8_t id1, id2;
|
uint8_t id1, id2;
|
||||||
|
|
||||||
*bios = RESET;
|
writeb(RESET, bios);
|
||||||
|
|
||||||
*bios = READ_ID;
|
writeb(READ_ID, bios);
|
||||||
id1 = *(volatile uint8_t *)bios;
|
id1 = readb(bios);
|
||||||
id2 = *(volatile uint8_t *)(bios + 0x01);
|
id2 = readb(bios + 0x01);
|
||||||
|
|
||||||
*bios = RESET;
|
writeb(RESET, bios);
|
||||||
|
|
||||||
printf_debug("%s: id1 0x%02x, id2 0x%02x\n", __FUNCTION__, id1, id2);
|
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)
|
if (erase_sector_49lfxxxc(bios, i) != 0)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
||||||
*bios = RESET;
|
writeb(RESET, bios);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -183,7 +183,7 @@ int write_49lfxxxc(struct flashchip *flash, uint8_t *buf)
|
|||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
*bios = RESET;
|
writeb(RESET, bios);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ int erase_sst_fwhub_block(struct flashchip *flash, int offset)
|
|||||||
volatile uint8_t *wrprotect = flash->virtual_registers + offset + 2;
|
volatile uint8_t *wrprotect = flash->virtual_registers + offset + 2;
|
||||||
|
|
||||||
// clear write protect
|
// clear write protect
|
||||||
*(wrprotect) = 0;
|
writeb(0, wrprotect);
|
||||||
|
|
||||||
erase_block_jedec(flash->virtual_memory, offset);
|
erase_block_jedec(flash->virtual_memory, offset);
|
||||||
toggle_ready_jedec(flash->virtual_memory);
|
toggle_ready_jedec(flash->virtual_memory);
|
||||||
|
@ -33,9 +33,9 @@
|
|||||||
|
|
||||||
void protect_stm50flw0x0x(volatile uint8_t *bios)
|
void protect_stm50flw0x0x(volatile uint8_t *bios)
|
||||||
{
|
{
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xAA;
|
writeb(0xAA, bios + 0x5555);
|
||||||
*(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
|
writeb(0x55, bios + 0x2AAA);
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xA0;
|
writeb(0xA0, bios + 0x5555);
|
||||||
|
|
||||||
usleep(200);
|
usleep(200);
|
||||||
}
|
}
|
||||||
@ -47,37 +47,37 @@ int probe_stm50flw0x0x(struct flashchip *flash)
|
|||||||
uint32_t largeid1, largeid2;
|
uint32_t largeid1, largeid2;
|
||||||
|
|
||||||
/* Issue JEDEC Product ID Entry command */
|
/* Issue JEDEC Product ID Entry command */
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xAA;
|
writeb(0xAA, bios + 0x5555);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
*(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
|
writeb(0x55, bios + 0x2AAA);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0x90;
|
writeb(0x90, bios + 0x5555);
|
||||||
myusec_delay(40);
|
myusec_delay(40);
|
||||||
|
|
||||||
/* Read product ID */
|
/* Read product ID */
|
||||||
id1 = *(volatile uint8_t *)bios;
|
id1 = readb(bios);
|
||||||
id2 = *(volatile uint8_t *)(bios + 0x01);
|
id2 = readb(bios + 0x01);
|
||||||
largeid1 = id1;
|
largeid1 = id1;
|
||||||
largeid2 = id2;
|
largeid2 = id2;
|
||||||
|
|
||||||
/* Check if it is a continuation ID, this should be a while loop. */
|
/* Check if it is a continuation ID, this should be a while loop. */
|
||||||
if (id1 == 0x7F) {
|
if (id1 == 0x7F) {
|
||||||
largeid1 <<= 8;
|
largeid1 <<= 8;
|
||||||
id1 = *(volatile uint8_t *)(bios + 0x100);
|
id1 = readb(bios + 0x100);
|
||||||
largeid1 |= id1;
|
largeid1 |= id1;
|
||||||
}
|
}
|
||||||
if (id2 == 0x7F) {
|
if (id2 == 0x7F) {
|
||||||
largeid2 <<= 8;
|
largeid2 <<= 8;
|
||||||
id2 = *(volatile uint8_t *)(bios + 0x101);
|
id2 = readb(bios + 0x101);
|
||||||
largeid2 |= id2;
|
largeid2 |= id2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Issue JEDEC Product ID Exit command */
|
/* Issue JEDEC Product ID Exit command */
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xAA;
|
writeb(0xAA, bios + 0x5555);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
*(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
|
writeb(0x55, bios + 0x2AAA);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xF0;
|
writeb(0xF0, bios + 0x5555);
|
||||||
myusec_delay(40);
|
myusec_delay(40);
|
||||||
|
|
||||||
printf_debug("%s: id1 0x%02x, id2 0x%02x\n", __FUNCTION__, largeid1,
|
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;
|
uint8_t id1;
|
||||||
// id2;
|
// id2;
|
||||||
|
|
||||||
*bios = 0x70;
|
writeb(0x70, bios);
|
||||||
if ((*bios & 0x80) == 0) { // it's busy
|
if ((readb(bios) & 0x80) == 0) { // it's busy
|
||||||
while ((*bios & 0x80) == 0) ;
|
while ((readb(bios) & 0x80) == 0) ;
|
||||||
}
|
}
|
||||||
// put another command to get out of status register mode
|
// put another command to get out of status register mode
|
||||||
|
|
||||||
*bios = 0x90;
|
writeb(0x90, bios);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
|
|
||||||
id1 = *(volatile uint8_t *)bios;
|
id1 = readb(bios);
|
||||||
|
|
||||||
// this is needed to jam it out of "read id" mode
|
// this is needed to jam it out of "read id" mode
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xAA;
|
writeb(0xAA, bios + 0x5555);
|
||||||
*(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
|
writeb(0x55, bios + 0x2AAA);
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xF0;
|
writeb(0xF0, bios + 0x5555);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -142,8 +142,8 @@ int unlock_block_stm50flw0x0x(struct flashchip *flash, int offset)
|
|||||||
// unlock each 4k-sector
|
// unlock each 4k-sector
|
||||||
for (j = 0; j < 0x10000; j += 0x1000) {
|
for (j = 0; j < 0x10000; j += 0x1000) {
|
||||||
printf_debug("unlocking at 0x%x\n", offset + j);
|
printf_debug("unlocking at 0x%x\n", offset + j);
|
||||||
*(flash_addr + offset + j) = unlock_sector;
|
writeb(unlock_sector, flash_addr + offset + j);
|
||||||
if (*(flash_addr + offset + j) != unlock_sector) {
|
if (readb(flash_addr + offset + j) != unlock_sector) {
|
||||||
printf("Cannot unlock sector @ 0x%x\n",
|
printf("Cannot unlock sector @ 0x%x\n",
|
||||||
offset + j);
|
offset + j);
|
||||||
return -1;
|
return -1;
|
||||||
@ -151,8 +151,8 @@ int unlock_block_stm50flw0x0x(struct flashchip *flash, int offset)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
printf_debug("unlocking at 0x%x\n", offset);
|
printf_debug("unlocking at 0x%x\n", offset);
|
||||||
*(flash_addr + offset) = unlock_sector;
|
writeb(unlock_sector, flash_addr + offset);
|
||||||
if (*(flash_addr + offset) != unlock_sector) {
|
if (readb(flash_addr + offset) != unlock_sector) {
|
||||||
printf("Cannot unlock sector @ 0x%x\n", offset);
|
printf("Cannot unlock sector @ 0x%x\n", offset);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -167,17 +167,17 @@ int erase_block_stm50flw0x0x(struct flashchip *flash, int offset)
|
|||||||
int j;
|
int j;
|
||||||
|
|
||||||
// clear status register
|
// clear status register
|
||||||
*bios = 0x50;
|
writeb(0x50, bios);
|
||||||
printf_debug("Erase at %p\n", bios);
|
printf_debug("Erase at %p\n", bios);
|
||||||
// now start it
|
// now start it
|
||||||
*(volatile uint8_t *)(bios) = 0x20;
|
writeb(0x20, bios);
|
||||||
*(volatile uint8_t *)(bios) = 0xd0;
|
writeb(0xd0, bios);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
|
|
||||||
wait_stm50flw0x0x(flash->virtual_memory);
|
wait_stm50flw0x0x(flash->virtual_memory);
|
||||||
|
|
||||||
for (j = 0; j < flash->page_size; j++) {
|
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);
|
printf("Erase failed at 0x%x\n", offset + j);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -197,8 +197,8 @@ int write_page_stm50flw0x0x(volatile uint8_t *bios, uint8_t *src,
|
|||||||
|
|
||||||
/* transfer data from source to destination */
|
/* transfer data from source to destination */
|
||||||
for (i = 0; i < page_size; i++) {
|
for (i = 0; i < page_size; i++) {
|
||||||
*dst = 0x40;
|
writeb(0x40, dst);
|
||||||
*dst++ = *src++;
|
writeb(*src++, dst++);
|
||||||
wait_stm50flw0x0x(bios);
|
wait_stm50flw0x0x(bios);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,7 +210,7 @@ int write_page_stm50flw0x0x(volatile uint8_t *bios, uint8_t *src,
|
|||||||
dst = d;
|
dst = d;
|
||||||
src = s;
|
src = s;
|
||||||
for (i = 0; i < page_size; i++) {
|
for (i = 0; i < page_size; i++) {
|
||||||
if (*dst != *src) {
|
if (readb(dst) != *src) {
|
||||||
rc = -1;
|
rc = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -37,29 +37,29 @@ int probe_w29ee011(struct flashchip *flash)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Issue JEDEC Product ID Entry command */
|
/* Issue JEDEC Product ID Entry command */
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xAA;
|
writeb(0xAA, bios + 0x5555);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
*(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
|
writeb(0x55, bios + 0x2AAA);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0x80;
|
writeb(0x80, bios + 0x5555);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xAA;
|
writeb(0xAA, bios + 0x5555);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
*(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
|
writeb(0x55, bios + 0x2AAA);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0x60;
|
writeb(0x60, bios + 0x5555);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
|
|
||||||
/* Read product ID */
|
/* Read product ID */
|
||||||
id1 = *(volatile uint8_t *)bios;
|
id1 = readb(bios);
|
||||||
id2 = *(volatile uint8_t *)(bios + 0x01);
|
id2 = readb(bios + 0x01);
|
||||||
|
|
||||||
/* Issue JEDEC Product ID Exit command */
|
/* Issue JEDEC Product ID Exit command */
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xAA;
|
writeb(0xAA, bios + 0x5555);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
*(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
|
writeb(0x55, bios + 0x2AAA);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xF0;
|
writeb(0xF0, bios + 0x5555);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
|
|
||||||
printf_debug("%s: id1 0x%02x, id2 0x%02x\n", __FUNCTION__, id1, id2);
|
printf_debug("%s: id1 0x%02x, id2 0x%02x\n", __FUNCTION__, id1, id2);
|
||||||
|
@ -26,22 +26,22 @@ int probe_w39v040c(struct flashchip *flash)
|
|||||||
volatile uint8_t *bios = flash->virtual_memory;
|
volatile uint8_t *bios = flash->virtual_memory;
|
||||||
uint8_t id1, id2, lock;
|
uint8_t id1, id2, lock;
|
||||||
|
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xAA;
|
writeb(0xAA, bios + 0x5555);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
*(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
|
writeb(0x55, bios + 0x2AAA);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0x90;
|
writeb(0x90, bios + 0x5555);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
|
|
||||||
id1 = *(volatile uint8_t *)bios;
|
id1 = readb(bios);
|
||||||
id2 = *(volatile uint8_t *)(bios + 1);
|
id2 = readb(bios + 1);
|
||||||
lock = *(volatile uint8_t *)(bios + 0xfff2);
|
lock = readb(bios + 0xfff2);
|
||||||
|
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xAA;
|
writeb(0xAA, bios + 0x5555);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
*(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
|
writeb(0x55, bios + 0x2AAA);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xF0;
|
writeb(0xF0, bios + 0x5555);
|
||||||
myusec_delay(40);
|
myusec_delay(40);
|
||||||
|
|
||||||
printf_debug("%s: id1 0x%02x, id2 0x%02x", __func__, id1, id2);
|
printf_debug("%s: id1 0x%02x, id2 0x%02x", __func__, id1, id2);
|
||||||
|
@ -27,19 +27,19 @@ int probe_winbond_fwhub(struct flashchip *flash)
|
|||||||
uint8_t vid, did;
|
uint8_t vid, did;
|
||||||
|
|
||||||
/* Product Identification Entry */
|
/* Product Identification Entry */
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xAA;
|
writeb(0xAA, bios + 0x5555);
|
||||||
*(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
|
writeb(0x55, bios + 0x2AAA);
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0x90;
|
writeb(0x90, bios + 0x5555);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
|
|
||||||
/* Read product ID */
|
/* Read product ID */
|
||||||
vid = *(volatile uint8_t *)bios;
|
vid = readb(bios);
|
||||||
did = *(volatile uint8_t *)(bios + 0x01);
|
did = readb(bios + 0x01);
|
||||||
|
|
||||||
/* Product Identifixation Exit */
|
/* Product Identifixation Exit */
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xAA;
|
writeb(0xAA, bios + 0x5555);
|
||||||
*(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
|
writeb(0x55, bios + 0x2AAA);
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xF0;
|
writeb(0xF0, bios + 0x5555);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
|
|
||||||
printf_debug("%s: vid 0x%x, did 0x%x\n", __FUNCTION__, vid, did);
|
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;
|
uint8_t locking;
|
||||||
|
|
||||||
printf_debug("Trying to unlock block @0x%08x = 0x%02x\n", offset,
|
printf_debug("Trying to unlock block @0x%08x = 0x%02x\n", offset,
|
||||||
*wrprotect);
|
readb(wrprotect));
|
||||||
|
|
||||||
locking = *wrprotect;
|
locking = readb(wrprotect);
|
||||||
switch (locking & 0x7) {
|
switch (locking & 0x7) {
|
||||||
case 0:
|
case 0:
|
||||||
printf_debug("Full Access.\n");
|
printf_debug("Full Access.\n");
|
||||||
return 0;
|
return 0;
|
||||||
case 1:
|
case 1:
|
||||||
printf_debug("Write Lock (Default State).\n");
|
printf_debug("Write Lock (Default State).\n");
|
||||||
*wrprotect = 0;
|
writeb(0, wrprotect);
|
||||||
return 0;
|
return 0;
|
||||||
case 2:
|
case 2:
|
||||||
printf_debug("Locked Open (Full Access, Lock Down).\n");
|
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;
|
return -1;
|
||||||
case 4:
|
case 4:
|
||||||
printf_debug("Read Lock.\n");
|
printf_debug("Read Lock.\n");
|
||||||
*wrprotect = 0;
|
writeb(0, wrprotect);
|
||||||
return 0;
|
return 0;
|
||||||
case 5:
|
case 5:
|
||||||
printf_debug("Read/Write Lock.\n");
|
printf_debug("Read/Write Lock.\n");
|
||||||
*wrprotect = 0;
|
writeb(0, wrprotect);
|
||||||
return 0;
|
return 0;
|
||||||
case 6:
|
case 6:
|
||||||
fprintf(stderr, "Error: Read Lock, Locked Down.\n");
|
fprintf(stderr, "Error: Read Lock, Locked Down.\n");
|
||||||
@ -106,18 +106,18 @@ int unlock_winbond_fwhub(struct flashchip *flash)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* Product Identification Entry */
|
/* Product Identification Entry */
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xAA;
|
writeb(0xAA, bios + 0x5555);
|
||||||
*(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
|
writeb(0x55, bios + 0x2AAA);
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0x90;
|
writeb(0x90, bios + 0x5555);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
|
|
||||||
/* Read Hardware Lock Bits */
|
/* Read Hardware Lock Bits */
|
||||||
locking = *(volatile uint8_t *)(bios + 0xffff2);
|
locking = readb(bios + 0xffff2);
|
||||||
|
|
||||||
/* Product Identification Exit */
|
/* Product Identification Exit */
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xAA;
|
writeb(0xAA, bios + 0x5555);
|
||||||
*(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
|
writeb(0x55, bios + 0x2AAA);
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xF0;
|
writeb(0xF0, bios + 0x5555);
|
||||||
myusec_delay(10);
|
myusec_delay(10);
|
||||||
|
|
||||||
printf_debug("Lockout bits:\n");
|
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);
|
printf("0x%08x\b\b\b\b\b\b\b\b\b\b", sector);
|
||||||
|
|
||||||
/* Sector Erase */
|
/* Sector Erase */
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xAA;
|
writeb(0xAA, bios + 0x5555);
|
||||||
*(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
|
writeb(0x55, bios + 0x2AAA);
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0x80;
|
writeb(0x80, bios + 0x5555);
|
||||||
|
|
||||||
*(volatile uint8_t *)(bios + 0x5555) = 0xAA;
|
writeb(0xAA, bios + 0x5555);
|
||||||
*(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
|
writeb(0x55, bios + 0x2AAA);
|
||||||
*(volatile uint8_t *)(bios + sector) = 0x30;
|
writeb(0x30, bios + sector);
|
||||||
|
|
||||||
/* wait for Toggle bit ready */
|
/* wait for Toggle bit ready */
|
||||||
toggle_ready_jedec(bios);
|
toggle_ready_jedec(bios);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user