Line 38... |
Line 38... |
#include <ctype.h>
|
#include <ctype.h>
|
#include <string.h>
|
#include <string.h>
|
#include <signal.h>
|
#include <signal.h>
|
#include <assert.h>
|
#include <assert.h>
|
|
|
#include "port.h"
|
#include "devbus.h"
|
#include "regdefs.h"
|
#include "regdefs.h"
|
#include "flashdrvr.h"
|
#include "flashdrvr.h"
|
|
|
const bool HIGH_SPEED = false;
|
const bool HIGH_SPEED = false;
|
|
|
Line 131... |
Line 131... |
// If we're in high speed mode and we want to verify the write, then
|
// If we're in high speed mode and we want to verify the write, then
|
// we can skip waiting for the write to complete by issueing a read
|
// we can skip waiting for the write to complete by issueing a read
|
// command immediately. As soon as the write completes the read will
|
// command immediately. As soon as the write completes the read will
|
// begin sending commands back. This allows us to recover the lost
|
// begin sending commands back. This allows us to recover the lost
|
// time between the interrupt and the next command being received.
|
// time between the interrupt and the next command being received.
|
if ((!HIGH_SPEED)||(!verify_write)) {
|
|
flwait();
|
flwait();
|
} if (verify_write) {
|
// if ((!HIGH_SPEED)||(!verify_write)) { }
|
|
if (verify_write) {
|
|
// printf("Attempting to verify page\n");
|
// NOW VERIFY THE PAGE
|
// NOW VERIFY THE PAGE
|
m_fpga->readi(addr, len, buf);
|
m_fpga->readi(addr, len, buf);
|
for(unsigned i=0; i<len; i++) {
|
for(unsigned i=0; i<len; i++) {
|
if (buf[i] != data[i]) {
|
if (buf[i] != data[i]) {
|
printf("\nVERIFY FAILS[%d]: %08x\n", i, i+addr);
|
printf("\nVERIFY FAILS[%d]: %08x\n", i, i+addr);
|
printf("\t(Flash[%d]) %08x != %08x (Goal[%08x])\n",
|
printf("\t(Flash[%d]) %08x != %08x (Goal[%08x])\n",
|
i, buf[i], data[i], i+addr);
|
i, buf[i], data[i], i+addr);
|
return false;
|
return false;
|
}
|
}
|
}
|
} // printf("\nVerify success\n");
|
} return true;
|
} return true;
|
}
|
}
|
|
|
bool FLASHDRVR::write(const unsigned addr, const unsigned len,
|
bool FLASHDRVR::write(const unsigned addr, const unsigned len,
|
const unsigned *data, const bool verify) {
|
const unsigned *data, const bool verify) {
|
Line 192... |
Line 193... |
|
|
if (newv == 0)
|
if (newv == 0)
|
continue; // This sector already matches
|
continue; // This sector already matches
|
|
|
// Just erase anyway
|
// Just erase anyway
|
if ((need_erase)&&(!erase_sector(s, verify))) {
|
if (!need_erase)
|
printf("SECTOR ERASE FAILED!\n");
|
|
return false;
|
|
} else if (!need_erase)
|
|
printf("NO ERASE NEEDED\n");
|
printf("NO ERASE NEEDED\n");
|
else {
|
else {
|
printf("ERASING SECTOR %08x\n", s);
|
printf("ERASING SECTOR %08x\n", s);
|
newv = (s<addr) ? addr : s;
|
if (!erase_sector(s, verify)) {
|
|
printf("SECTOR ERASE FAILED!\n");
|
|
return false;
|
|
} newv = (s<addr) ? addr : s;
|
}
|
}
|
for(unsigned p=newv; (p<s+SECTORSZ)&&(p<addr+len); p=PAGEOF(p+PGLEN))
|
for(unsigned p=newv; (p<s+SECTORSZ)&&(p<addr+len); p=PAGEOF(p+PGLEN)) {
|
if (!write_page(p, (p+PGLEN<addr+len)
|
unsigned start = p, len = addr+len-start;
|
?((PAGEOF(p)!=PAGEOF(p+PGLEN-1))?(PAGEOF(p+PGLEN-1)-p):PGLEN)
|
|
:(addr+len-p), &data[p-addr]), verify) {
|
// BUT! if we cross page boundaries, we need to clip
|
|
// our results to the page boundary
|
|
if (PAGEOF(start+len-1)!=PAGEOF(start))
|
|
len = PAGEOF(start+PGLEN)-start;
|
|
if (!write_page(start, len, &data[p-addr], verify)) {
|
printf("WRITE-PAGE FAILED!\n");
|
printf("WRITE-PAGE FAILED!\n");
|
return false;
|
return false;
|
}
|
}
|
}
|
}
|
|
}
|
|
|
m_fpga->writeio(R_QSPI_EREG, 0); // Re-enable write protection
|
m_fpga->writeio(R_QSPI_EREG, 0); // Re-enable write protection
|
|
|
return true;
|
return true;
|
}
|
}
|