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);
|
Line 175... |
Line 176... |
|
|
dp = &data[base-addr];
|
dp = &data[base-addr];
|
for(unsigned i=0; i<ln; i++) {
|
for(unsigned i=0; i<ln; i++) {
|
if ((sbuf[i]&dp[i]) != dp[i]) {
|
if ((sbuf[i]&dp[i]) != dp[i]) {
|
printf("\nNEED-ERASE @0x%08x ... %08x != %08x (Goal)\n",
|
printf("\nNEED-ERASE @0x%08x ... %08x != %08x (Goal)\n",
|
i+base-addr, sbuf[i], dp[i]);
|
i+base, sbuf[i], dp[i]);
|
need_erase = true;
|
need_erase = true;
|
newv = i+base;
|
newv = i+base;
|
break;
|
break;
|
} else if ((sbuf[i] != dp[i])&&(newv == 0)) {
|
} else if ((sbuf[i] != dp[i])&&(newv == 0)) {
|
// if (newv == 0)
|
// if (newv == 0)
|
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;
|
}
|
}
|